From 19e63a79e52440192aed01267ddffd7862f50911 Mon Sep 17 00:00:00 2001 From: Govinda Wasserman Date: Wed, 7 Dec 2022 11:58:03 -0500 Subject: [PATCH] Add option to return a null Dagger graph This allows processes that do not utilize the SysUI Dagger graph to avoid having to subclass and instantiate it. This change also makes the Screenshot cross-profile service take advantage of this change. Test: Turn on "Enable RequestProcessor" and "Enable Work Profile Screenshots Policy" SysUI flags Test: Take a screenshot of a work profile app Test: Observe successful work profile screenshot BUG: 259469497 Change-Id: I1a8c62ba079d90e575cab2a0e14b3f1466e1952c --- packages/SystemUI/AndroidManifest.xml | 1 + .../com/android/systemui/SystemUIInitializer.java | 9 +++++++++ .../android/systemui/SystemUIInitializerImpl.kt | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 844e88a09b05c..2923cd24b446b 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -416,6 +416,7 @@ diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java b/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java index 632fcdc162592..0fc9ef96f6e9a 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java @@ -22,6 +22,8 @@ import android.os.Handler; import android.os.HandlerThread; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dagger.WMComponent; @@ -53,6 +55,7 @@ public abstract class SystemUIInitializer { mContext = context; } + @Nullable protected abstract GlobalRootComponent.Builder getGlobalRootComponentBuilder(); /** @@ -69,6 +72,11 @@ public abstract class SystemUIInitializer { * Starts the initialization process. This stands up the Dagger graph. */ public void init(boolean fromTest) throws ExecutionException, InterruptedException { + GlobalRootComponent.Builder globalBuilder = getGlobalRootComponentBuilder(); + if (globalBuilder == null) { + return; + } + mRootComponent = getGlobalRootComponentBuilder() .context(mContext) .instrumentationTest(fromTest) @@ -119,6 +127,7 @@ public abstract class SystemUIInitializer { .setBackAnimation(Optional.ofNullable(null)) .setDesktopMode(Optional.ofNullable(null)); } + mSysUIComponent = builder.build(); if (initializeComponents) { mSysUIComponent.init(); diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt b/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt index 8aa3040c6015c..55c095b0be257 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt @@ -16,6 +16,7 @@ package com.android.systemui +import android.app.Application import android.content.Context import com.android.systemui.dagger.DaggerReferenceGlobalRootComponent import com.android.systemui.dagger.GlobalRootComponent @@ -24,7 +25,17 @@ import com.android.systemui.dagger.GlobalRootComponent * {@link SystemUIInitializer} that stands up AOSP SystemUI. */ class SystemUIInitializerImpl(context: Context) : SystemUIInitializer(context) { - override fun getGlobalRootComponentBuilder(): GlobalRootComponent.Builder { - return DaggerReferenceGlobalRootComponent.builder() + + override fun getGlobalRootComponentBuilder(): GlobalRootComponent.Builder? { + return when (Application.getProcessName()) { + SCREENSHOT_CROSS_PROFILE_PROCESS -> null + else -> DaggerReferenceGlobalRootComponent.builder() + } + } + + companion object { + private const val SYSTEMUI_PROCESS = "com.android.systemui" + private const val SCREENSHOT_CROSS_PROFILE_PROCESS = + "$SYSTEMUI_PROCESS:screenshot_cross_profile" } }