Loading packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +16 −19 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui; import android.app.ActivityThread; import android.content.Context; import android.content.res.Resources; 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.SysUIComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.util.InitializationChecker; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.transition.ShellTransitions; Loading @@ -47,7 +47,7 @@ public class SystemUIFactory { private GlobalRootComponent mRootComponent; private WMComponent mWMComponent; private SysUIComponent mSysUIComponent; private boolean mInitializeComponents; private InitializationChecker mInitializationChecker; public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; Loading Loading @@ -89,15 +89,17 @@ public class SystemUIFactory { @VisibleForTesting public void init(Context context, boolean fromTest) throws ExecutionException, InterruptedException { // Only initialize components for the main system ui process running as the primary user mInitializeComponents = !fromTest && android.os.Process.myUserHandle().isSystem() && ActivityThread.currentProcessName().equals(ActivityThread.currentPackageName()); mRootComponent = buildGlobalRootComponent(context); mRootComponent = getGlobalRootComponentBuilder() .context(context) .instrumentationTest(fromTest) .build(); mInitializationChecker = mRootComponent.getInitializationChecker(); boolean initializeComponents = mInitializationChecker.initializeComponents(); // Stand up WMComponent setupWmComponent(context); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment mWMComponent.init(); Loading @@ -105,7 +107,7 @@ public class SystemUIFactory { // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment builder = prepareSysUIComponentBuilder(builder, mWMComponent) Loading Loading @@ -145,7 +147,7 @@ public class SystemUIFactory { .setBackAnimation(Optional.ofNullable(null)); } mSysUIComponent = builder.build(); if (mInitializeComponents) { if (initializeComponents) { mSysUIComponent.init(); } Loading @@ -163,7 +165,8 @@ public class SystemUIFactory { */ private void setupWmComponent(Context context) { 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 mWMComponent = wmBuilder.build(); return; Loading Loading @@ -195,14 +198,8 @@ public class SystemUIFactory { return sysUIBuilder; } protected GlobalRootComponent buildGlobalRootComponent(Context context) { return DaggerGlobalRootComponent.builder() .context(context) .build(); } protected boolean shouldInitializeComponents() { return mInitializeComponents; protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerGlobalRootComponent.builder(); } public GlobalRootComponent getRootComponent() { Loading packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java +10 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.dagger; import android.content.Context; import com.android.systemui.dagger.qualifiers.InstrumentationTest; import com.android.systemui.util.InitializationChecker; import javax.inject.Singleton; import dagger.BindsInstance; Loading @@ -37,7 +40,8 @@ public interface GlobalRootComponent { interface Builder { @BindsInstance Builder context(Context context); @BindsInstance Builder instrumentationTest(@InstrumentationTest boolean test); GlobalRootComponent build(); } Loading @@ -50,4 +54,9 @@ public interface GlobalRootComponent { * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. */ 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 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 Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.tv; import android.content.Context; import com.android.systemui.SystemUIFactory; import com.android.systemui.dagger.GlobalRootComponent; Loading @@ -27,9 +25,7 @@ import com.android.systemui.dagger.GlobalRootComponent; */ public class TvSystemUIFactory extends SystemUIFactory { @Override protected GlobalRootComponent buildGlobalRootComponent(Context context) { return DaggerTvGlobalRootComponent.builder() .context(context) .build(); protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerTvGlobalRootComponent.builder(); } } packages/SystemUI/src/com/android/systemui/util/InitializationChecker.kt 0 → 100644 +38 −0 Original line number 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 Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui; import android.app.ActivityThread; import android.content.Context; import android.content.res.Resources; 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.SysUIComponent; import com.android.systemui.dagger.WMComponent; import com.android.systemui.util.InitializationChecker; import com.android.wm.shell.dagger.WMShellConcurrencyModule; import com.android.wm.shell.transition.ShellTransitions; Loading @@ -47,7 +47,7 @@ public class SystemUIFactory { private GlobalRootComponent mRootComponent; private WMComponent mWMComponent; private SysUIComponent mSysUIComponent; private boolean mInitializeComponents; private InitializationChecker mInitializationChecker; public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; Loading Loading @@ -89,15 +89,17 @@ public class SystemUIFactory { @VisibleForTesting public void init(Context context, boolean fromTest) throws ExecutionException, InterruptedException { // Only initialize components for the main system ui process running as the primary user mInitializeComponents = !fromTest && android.os.Process.myUserHandle().isSystem() && ActivityThread.currentProcessName().equals(ActivityThread.currentPackageName()); mRootComponent = buildGlobalRootComponent(context); mRootComponent = getGlobalRootComponentBuilder() .context(context) .instrumentationTest(fromTest) .build(); mInitializationChecker = mRootComponent.getInitializationChecker(); boolean initializeComponents = mInitializationChecker.initializeComponents(); // Stand up WMComponent setupWmComponent(context); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment mWMComponent.init(); Loading @@ -105,7 +107,7 @@ public class SystemUIFactory { // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. SysUIComponent.Builder builder = mRootComponent.getSysUIComponent(); if (mInitializeComponents) { if (initializeComponents) { // Only initialize when not starting from tests since this currently initializes some // components that shouldn't be run in the test environment builder = prepareSysUIComponentBuilder(builder, mWMComponent) Loading Loading @@ -145,7 +147,7 @@ public class SystemUIFactory { .setBackAnimation(Optional.ofNullable(null)); } mSysUIComponent = builder.build(); if (mInitializeComponents) { if (initializeComponents) { mSysUIComponent.init(); } Loading @@ -163,7 +165,8 @@ public class SystemUIFactory { */ private void setupWmComponent(Context context) { 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 mWMComponent = wmBuilder.build(); return; Loading Loading @@ -195,14 +198,8 @@ public class SystemUIFactory { return sysUIBuilder; } protected GlobalRootComponent buildGlobalRootComponent(Context context) { return DaggerGlobalRootComponent.builder() .context(context) .build(); } protected boolean shouldInitializeComponents() { return mInitializeComponents; protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerGlobalRootComponent.builder(); } public GlobalRootComponent getRootComponent() { Loading
packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java +10 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.dagger; import android.content.Context; import com.android.systemui.dagger.qualifiers.InstrumentationTest; import com.android.systemui.util.InitializationChecker; import javax.inject.Singleton; import dagger.BindsInstance; Loading @@ -37,7 +40,8 @@ public interface GlobalRootComponent { interface Builder { @BindsInstance Builder context(Context context); @BindsInstance Builder instrumentationTest(@InstrumentationTest boolean test); GlobalRootComponent build(); } Loading @@ -50,4 +54,9 @@ public interface GlobalRootComponent { * Builder for a {@link SysUIComponent}, which makes it a subcomponent of this class. */ 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 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 Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.tv; import android.content.Context; import com.android.systemui.SystemUIFactory; import com.android.systemui.dagger.GlobalRootComponent; Loading @@ -27,9 +25,7 @@ import com.android.systemui.dagger.GlobalRootComponent; */ public class TvSystemUIFactory extends SystemUIFactory { @Override protected GlobalRootComponent buildGlobalRootComponent(Context context) { return DaggerTvGlobalRootComponent.builder() .context(context) .build(); protected GlobalRootComponent.Builder getGlobalRootComponentBuilder() { return DaggerTvGlobalRootComponent.builder(); } }
packages/SystemUI/src/com/android/systemui/util/InitializationChecker.kt 0 → 100644 +38 −0 Original line number 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() }