Turn ContentProvider injection failures into errors.
Prior to this change, we simply logged this as a warning. This would
hide errors, in particular `InvocationTargetException` which itself
wraps any errors that happened during the call to `#inject`.
For the bug in question, ZenMode is actually failing to initialize,
which is causing the injection of the KeyguardSliceProvider to fail.
This change does not fix ZenMode, but will resurface the stack trace
appropriately.
Moreover, any process that is failing to initialize its
ContentProvider is already having a bad time, so if it didn't fail
here, it was going to fail somewhere else. That is what we see on the
bug.
Flag: NA
Bug: 323327880
Test: manually built and run
Change-Id: Ic2189b6c142eb0a7ec23ca49924a551626b8c326
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactoryBase.kt b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactoryBase.kt
index e88aaf01..aab0b1e 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactoryBase.kt
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactoryBase.kt
@@ -22,7 +22,6 @@
import android.content.ContentProvider
import android.content.Context
import android.content.Intent
-import android.util.Log
import androidx.core.app.AppComponentFactory
import com.android.systemui.dagger.ContextComponentHelper
import com.android.systemui.dagger.SysUIComponent
@@ -91,7 +90,8 @@
return app
}
- @UsesReflection(KeepTarget(instanceOfClassConstant = SysUIComponent::class, methodName = "inject"))
+ @UsesReflection(
+ KeepTarget(instanceOfClassConstant = SysUIComponent::class, methodName = "inject"))
override fun instantiateProviderCompat(cl: ClassLoader, className: String): ContentProvider {
val contentProvider = super.instantiateProviderCompat(cl, className)
if (contentProvider is ContextInitializer) {
@@ -103,11 +103,12 @@
.getMethod("inject", contentProvider.javaClass)
injectMethod.invoke(rootComponent, contentProvider)
} catch (e: NoSuchMethodException) {
- Log.w(TAG, "No injector for class: " + contentProvider.javaClass, e)
+ throw RuntimeException("No injector for class: " + contentProvider.javaClass, e)
} catch (e: IllegalAccessException) {
- Log.w(TAG, "No injector for class: " + contentProvider.javaClass, e)
+ throw RuntimeException("Injector inaccessible for class: " +
+ contentProvider.javaClass, e)
} catch (e: InvocationTargetException) {
- Log.w(TAG, "No injector for class: " + contentProvider.javaClass, e)
+ throw RuntimeException("Error while injecting: " + contentProvider.javaClass, e)
}
initializer
}