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

@@ -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)
}
}