Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75f5cbea authored by Dave Mankoff's avatar Dave Mankoff
Browse files

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
parent 7593029a
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.BroadcastReceiver
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 @@ abstract class SystemUIAppComponentFactoryBase : AppComponentFactory() {
        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 @@ abstract class SystemUIAppComponentFactoryBase : AppComponentFactory() {
                        .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
            }