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
This commit is contained in:
Govinda Wasserman
2022-12-07 11:58:03 -05:00
parent 5932f31d58
commit 19e63a79e5
3 changed files with 23 additions and 2 deletions

View File

@@ -416,6 +416,7 @@
<service android:name=".screenshot.ScreenshotCrossProfileService"
android:permission="com.android.systemui.permission.SELF"
android:process=":screenshot_cross_profile"
android:exported="false" />
<service android:name=".screenrecord.RecordingService" />

View File

@@ -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();

View File

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