Merge "Remove SystemUIFactory#shouldInitializeComponents" into tm-qpr-dev

This commit is contained in:
Dave Mankoff
2022-07-13 23:44:38 +00:00
committed by Android (Google) Code Review
5 changed files with 100 additions and 26 deletions

View File

@@ -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;
@@ -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;
@@ -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;
@@ -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();
@@ -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)
@@ -145,7 +147,7 @@ public class SystemUIFactory {
.setBackAnimation(Optional.ofNullable(null));
}
mSysUIComponent = builder.build();
if (mInitializeComponents) {
if (initializeComponents) {
mSysUIComponent.init();
}
@@ -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;
@@ -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() {

View File

@@ -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;
@@ -37,7 +40,8 @@ public interface GlobalRootComponent {
interface Builder {
@BindsInstance
Builder context(Context context);
@BindsInstance
Builder instrumentationTest(@InstrumentationTest boolean test);
GlobalRootComponent build();
}
@@ -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();
}

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;
import android.content.Context;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.dagger.GlobalRootComponent;
@@ -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();
}
}

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