Loading packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +16 −19 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui; package com.android.systemui; import android.app.ActivityThread; import android.content.Context; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import android.os.Handler; import android.os.Handler; Loading @@ -28,6 +27,7 @@ import com.android.systemui.dagger.DaggerGlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.util.InitializationChecker; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.transition.ShellTransitions; import com.android.wm.shell.transition.ShellTransitions; Loading @@ -47,7 +47,7 @@ public class SystemUIFactory { private GlobalRootComponent mRootComponent; private GlobalRootComponent mRootComponent; private WMComponent mWMComponent; private WMComponent mWMComponent; private SysUIComponent mSysUIComponent; private SysUIComponent mSysUIComponent; private boolean mInitializeComponents; private InitializationChecker mInitializationChecker; public static <T extends SystemUIFactory> T getInstance() { public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; return (T) mFactory; Loading Loading @@ -89,15 +89,17 @@ public class SystemUIFactory { @VisibleForTesting @VisibleForTesting public void init(Context context, boolean fromTest) public void init(Context context, boolean fromTest) throws ExecutionException, InterruptedException { throws ExecutionException, InterruptedException { // Only initialize components for the main system ui process running as the primary user mRootComponent = getGlobalRootComponentBuilder() mInitializeComponents = !fromTest .context(context) && android.os.Process.myUserHandle().isSystem() .instrumentationTest(fromTest) && ActivityThread.currentProcessName().equals(ActivityThread.currentPackageName()); .build(); mRootComponent = buildGlobalRootComponent(context); mInitializationChecker = mRootComponent.getInitializationChecker(); boolean initializeComponents = mInitializationChecker.initializeComponents(); // Stand up WMComponent // Stand up WMComponent setupWmComponent(context); setupWmComponent(context); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment // components that shouldn't be run in the test environment mWMComponent.init(); mWMComponent.init(); Loading @@ -105,7 +107,7 @@ public class SystemUIFactory { // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment // components that shouldn't be run in the test environment builder = prepareSysUIComponentBuilder(builder, mWMComponent) builder = prepareSysUIComponentBuilder(builder, mWMComponent) Loading Loading @@ -145,7 +147,7 @@ public class SystemUIFactory { .setBackAnimation(Optional.ofNullable(null)); .setBackAnimation(Optional.ofNullable(null)); } } mSysUIComponent = builder.build(); mSysUIComponent = builder.build(); if (mInitializeComponents) { if (initializeComponents) { mSysUIComponent.init(); mSysUIComponent.init(); } } Loading @@ -163,7 +165,8 @@ public class SystemUIFactory { */ */ private void setupWmComponent(Context context) { private void setupWmComponent(Context context) { WMComponent.Builder wmBuilder = mRootComponent.getWMComponentBuilder(); WMComponent.Builder wmBuilder = mRootComponent.getWMComponentBuilder(); if (!mInitializeComponents || !WMShellConcurrencyModule.enableShellMainThread(context)) { if (!mInitializationChecker.initializeComponents() || !WMShellConcurrencyModule.enableShellMainThread(context)) { // If running under tests or shell thread is not enabled, we don't need anything special // If running under tests or shell thread is not enabled, we don't need anything special mWMComponent = wmBuilder.build(); mWMComponent = wmBuilder.build(); return; return; Loading Loading @@ -195,14 +198,8 @@ public class SystemUIFactory { return sysUIBuilder; return sysUIBuilder; } } protected GlobalRootComponent buildGlobalRootComponent(Context context) { protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerGlobalRootComponent.builder() return DaggerGlobalRootComponent.builder(); .context(context) .build(); } protected boolean shouldInitializeComponents() { return mInitializeComponents; } } public GlobalRootComponent getRootComponent() { public GlobalRootComponent getRootComponent() { Loading packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java +10 −1 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.dagger; import android.content.Context; import android.content.Context; import com.android.systemui.dagger.qualifiers.InstrumentationTest; import com.android.systemui.util.InitializationChecker; import javax.inject.Singleton; import javax.inject.Singleton; import dagger.BindsInstance; import dagger.BindsInstance; Loading @@ -37,7 +40,8 @@ public interface GlobalRootComponent { interface Builder { interface Builder { @BindsInstance @BindsInstance Builder context(Context context); Builder context(Context context); @BindsInstance Builder instrumentationTest(@InstrumentationTest boolean test); GlobalRootComponent build(); GlobalRootComponent build(); } } Loading @@ -50,4 +54,9 @@ public interface GlobalRootComponent { * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. */ */ SysUIComponent.Builder getSysUIComponent(); SysUIComponent.Builder getSysUIComponent(); /** * Returns an {@link InitializationChecker}. */ InitializationChecker getInitializationChecker(); } } packages/SystemUI/src/com/android/systemui/dagger/qualifiers/InstrumentationTest.java 0 → 100644 +34 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.dagger.qualifiers; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import javax.inject.Qualifier; /** * An annotation for injecting whether or not we are running in a test environment. */ @Qualifier @Documented @Retention(RUNTIME) public @interface InstrumentationTest { } packages/SystemUI/src/com/android/systemui/tv/TvSystemUIFactory.java +2 −6 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.tv; package com.android.systemui.tv; import android.content.Context; import com.android.systemui.SystemUIFactory; import com.android.systemui.SystemUIFactory; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; Loading @@ -27,9 +25,7 @@ import com.android.systemui.dagger.GlobalRootComponent; */ */ public class TvSystemUIFactory extends SystemUIFactory { public class TvSystemUIFactory extends SystemUIFactory { @Override @Override protected GlobalRootComponent buildGlobalRootComponent(Context context) { protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerTvGlobalRootComponent.builder() return DaggerTvGlobalRootComponent.builder(); .context(context) .build(); } } } } packages/SystemUI/src/com/android/systemui/util/InitializationChecker.kt 0 → 100644 +38 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.util import android.app.ActivityThread import android.os.Process import com.android.systemui.dagger.qualifiers.InstrumentationTest import javax.inject.Inject /** * Used to check whether SystemUI should be fully initialized. */ class InitializationChecker @Inject constructor( @InstrumentationTest private val instrumentationTest: Boolean ) { /** * Only initialize components for the main system ui process running as the primary user */ fun initializeComponents(): Boolean = !instrumentationTest && Process.myUserHandle().isSystem && ActivityThread.currentProcessName() == ActivityThread.currentPackageName() } Loading
packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +16 −19 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui; package com.android.systemui; import android.app.ActivityThread; import android.content.Context; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import android.os.Handler; import android.os.Handler; Loading @@ -28,6 +27,7 @@ import com.android.systemui.dagger.DaggerGlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.util.InitializationChecker; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.transition.ShellTransitions; import com.android.wm.shell.transition.ShellTransitions; Loading @@ -47,7 +47,7 @@ public class SystemUIFactory { private GlobalRootComponent mRootComponent; private GlobalRootComponent mRootComponent; private WMComponent mWMComponent; private WMComponent mWMComponent; private SysUIComponent mSysUIComponent; private SysUIComponent mSysUIComponent; private boolean mInitializeComponents; private InitializationChecker mInitializationChecker; public static <T extends SystemUIFactory> T getInstance() { public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; return (T) mFactory; Loading Loading @@ -89,15 +89,17 @@ public class SystemUIFactory { @VisibleForTesting @VisibleForTesting public void init(Context context, boolean fromTest) public void init(Context context, boolean fromTest) throws ExecutionException, InterruptedException { throws ExecutionException, InterruptedException { // Only initialize components for the main system ui process running as the primary user mRootComponent = getGlobalRootComponentBuilder() mInitializeComponents = !fromTest .context(context) && android.os.Process.myUserHandle().isSystem() .instrumentationTest(fromTest) && ActivityThread.currentProcessName().equals(ActivityThread.currentPackageName()); .build(); mRootComponent = buildGlobalRootComponent(context); mInitializationChecker = mRootComponent.getInitializationChecker(); boolean initializeComponents = mInitializationChecker.initializeComponents(); // Stand up WMComponent // Stand up WMComponent setupWmComponent(context); setupWmComponent(context); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment // components that shouldn't be run in the test environment mWMComponent.init(); mWMComponent.init(); Loading @@ -105,7 +107,7 @@ public class SystemUIFactory { // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment // components that shouldn't be run in the test environment builder = prepareSysUIComponentBuilder(builder, mWMComponent) builder = prepareSysUIComponentBuilder(builder, mWMComponent) Loading Loading @@ -145,7 +147,7 @@ public class SystemUIFactory { .setBackAnimation(Optional.ofNullable(null)); .setBackAnimation(Optional.ofNullable(null)); } } mSysUIComponent = builder.build(); mSysUIComponent = builder.build(); if (mInitializeComponents) { if (initializeComponents) { mSysUIComponent.init(); mSysUIComponent.init(); } } Loading @@ -163,7 +165,8 @@ public class SystemUIFactory { */ */ private void setupWmComponent(Context context) { private void setupWmComponent(Context context) { WMComponent.Builder wmBuilder = mRootComponent.getWMComponentBuilder(); WMComponent.Builder wmBuilder = mRootComponent.getWMComponentBuilder(); if (!mInitializeComponents || !WMShellConcurrencyModule.enableShellMainThread(context)) { if (!mInitializationChecker.initializeComponents() || !WMShellConcurrencyModule.enableShellMainThread(context)) { // If running under tests or shell thread is not enabled, we don't need anything special // If running under tests or shell thread is not enabled, we don't need anything special mWMComponent = wmBuilder.build(); mWMComponent = wmBuilder.build(); return; return; Loading Loading @@ -195,14 +198,8 @@ public class SystemUIFactory { return sysUIBuilder; return sysUIBuilder; } } protected GlobalRootComponent buildGlobalRootComponent(Context context) { protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerGlobalRootComponent.builder() return DaggerGlobalRootComponent.builder(); .context(context) .build(); } protected boolean shouldInitializeComponents() { return mInitializeComponents; } } public GlobalRootComponent getRootComponent() { public GlobalRootComponent getRootComponent() { Loading
packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java +10 −1 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.dagger; import android.content.Context; import android.content.Context; import com.android.systemui.dagger.qualifiers.InstrumentationTest; import com.android.systemui.util.InitializationChecker; import javax.inject.Singleton; import javax.inject.Singleton; import dagger.BindsInstance; import dagger.BindsInstance; Loading @@ -37,7 +40,8 @@ public interface GlobalRootComponent { interface Builder { interface Builder { @BindsInstance @BindsInstance Builder context(Context context); Builder context(Context context); @BindsInstance Builder instrumentationTest(@InstrumentationTest boolean test); GlobalRootComponent build(); GlobalRootComponent build(); } } Loading @@ -50,4 +54,9 @@ public interface GlobalRootComponent { * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. */ */ SysUIComponent.Builder getSysUIComponent(); SysUIComponent.Builder getSysUIComponent(); /** * Returns an {@link InitializationChecker}. */ InitializationChecker getInitializationChecker(); } }
packages/SystemUI/src/com/android/systemui/dagger/qualifiers/InstrumentationTest.java 0 → 100644 +34 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.dagger.qualifiers; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import javax.inject.Qualifier; /** * An annotation for injecting whether or not we are running in a test environment. */ @Qualifier @Documented @Retention(RUNTIME) public @interface InstrumentationTest { }
packages/SystemUI/src/com/android/systemui/tv/TvSystemUIFactory.java +2 −6 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.tv; package com.android.systemui.tv; import android.content.Context; import com.android.systemui.SystemUIFactory; import com.android.systemui.SystemUIFactory; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.GlobalRootComponent; Loading @@ -27,9 +25,7 @@ import com.android.systemui.dagger.GlobalRootComponent; */ */ public class TvSystemUIFactory extends SystemUIFactory { public class TvSystemUIFactory extends SystemUIFactory { @Override @Override protected GlobalRootComponent buildGlobalRootComponent(Context context) { protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerTvGlobalRootComponent.builder() return DaggerTvGlobalRootComponent.builder(); .context(context) .build(); } } } }
packages/SystemUI/src/com/android/systemui/util/InitializationChecker.kt 0 → 100644 +38 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.util import android.app.ActivityThread import android.os.Process import com.android.systemui.dagger.qualifiers.InstrumentationTest import javax.inject.Inject /** * Used to check whether SystemUI should be fully initialized. */ class InitializationChecker @Inject constructor( @InstrumentationTest private val instrumentationTest: Boolean ) { /** * Only initialize components for the main system ui process running as the primary user */ fun initializeComponents(): Boolean = !instrumentationTest && Process.myUserHandle().isSystem && ActivityThread.currentProcessName() == ActivityThread.currentPackageName() }