Merge "Remove SystemUIFactory#shouldInitializeComponents" into tm-qpr-dev am: 6abc4e067d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19279481

Change-Id: I1eecf5830714b69bc39a38331941a9300a461a08
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Dave Mankoff
2022-07-14 00:11:16 +00:00
committed by Automerger Merge Worker
5 changed files with 100 additions and 26 deletions

View File

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

View File

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

View File

@@ -0,0 +1,34 @@
/*
* 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 {
}

View File

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

View File

@@ -0,0 +1,38 @@
/*
* 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()
}