BIT-2306: Use legacy autofill service name to enforce compatibility after migration (#1328)

This commit is contained in:
David Perez 2024-05-02 10:13:29 -05:00 committed by Álison Fernandes
parent 859b4c247d
commit fd08f39fd9
2 changed files with 45 additions and 4 deletions

View file

@ -14,11 +14,12 @@
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:name=".BitwardenApplication"
android:allowBackup="false"
android:appComponentFactory=".BitwardenAppComponentFactory"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
@ -27,6 +28,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/LaunchTheme"
tools:replace="appComponentFactory"
tools:targetApi="33">
<activity
android:name=".MainActivity"
@ -120,11 +122,16 @@
android:resource="@xml/file_paths" />
</provider>
<!--
The AutofillService name below refers to the legacy Xamarin app's service name. This must
always match in order for the app to properly query if it is providing autofill services.
-->
<service
android:name=".data.autofill.BitwardenAutofillService"
android:name="com.x8bit.bitwarden.Autofill.AutofillService"
android:exported="true"
android:label="Bitwarden"
android:permission="android.permission.BIND_AUTOFILL_SERVICE">
android:label="@string/app_name"
android:permission="android.permission.BIND_AUTOFILL_SERVICE"
tools:ignore="MissingClass">
<meta-data
android:name="android.autofill"
android:resource="@xml/autofill_service_configuration" />

View file

@ -0,0 +1,34 @@
package com.x8bit.bitwarden
import android.app.AppComponentFactory
import android.app.Service
import android.content.Intent
import com.x8bit.bitwarden.data.autofill.BitwardenAutofillService
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
private const val LEGACY_AUTOFILL_SERVICE_NAME = "com.x8bit.bitwarden.Autofill.AutofillService"
/**
* A factory class that allows us to intercept when a manifest element is being instantiated
* and modify various characteristics before initialization.
*/
@Suppress("unused")
@OmitFromCoverage
class BitwardenAppComponentFactory : AppComponentFactory() {
/**
* Used to intercept when the [BitwardenAutofillService] is being instantiated and modify which
* service is created. This is required because the [className] used in the manifest must match
* the legacy Xamarin app service name but the service name in this app is different.
*/
override fun instantiateService(
cl: ClassLoader,
className: String,
intent: Intent?,
): Service = when (className) {
LEGACY_AUTOFILL_SERVICE_NAME -> {
super.instantiateService(cl, BitwardenAutofillService::class.java.name, intent)
}
else -> super.instantiateService(cl, className, intent)
}
}