diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e5f2003a95..3b63cf3b66 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,11 +14,12 @@ - + + + android:label="@string/app_name" + android:permission="android.permission.BIND_AUTOFILL_SERVICE" + tools:ignore="MissingClass"> diff --git a/app/src/main/java/com/x8bit/bitwarden/BitwardenAppComponentFactory.kt b/app/src/main/java/com/x8bit/bitwarden/BitwardenAppComponentFactory.kt new file mode 100644 index 0000000000..b1b5358f2d --- /dev/null +++ b/app/src/main/java/com/x8bit/bitwarden/BitwardenAppComponentFactory.kt @@ -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) + } +}