From be885c832f23b32aa11d44d234adffeedc6a90a7 Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Wed, 20 Nov 2019 13:04:54 -0500 Subject: [PATCH] Remove Dependency.staticOnConfigurationChanged ConfigurationChangedReceiver is removed. Classes that want to be notified of configuration changes should implement ConfigurationController.ConfigurationListener instead and register themselves with the ConfigurationController. This CPs http://ag/9762349 Change-Id: I00c08a30b6d8dcac7e26230cb4354bc1fda74b10 Merged-In: Id2c3fe5ae2729b181769fb31b8050da264299d72 Bug: 150541820 Test: atest SystemUITests --- .../ConfigurationChangedReceiver.java | 21 ------- .../src/com/android/systemui/Dependency.java | 10 --- .../android/systemui/SystemUIApplication.java | 6 +- .../systemui/SystemUIRootComponent.java | 9 +++ .../systemui/assist/AssistManager.java | 61 +++++++++++-------- .../systemui/fragments/FragmentService.java | 25 +++++--- .../phone/ConfigurationControllerImpl.kt | 5 +- .../policy/ConfigurationController.java | 6 +- .../policy/NetworkControllerImpl.java | 22 +++---- .../com/android/systemui/DependencyTest.java | 11 ---- .../leaks/FakeConfigurationController.java | 6 ++ 11 files changed, 84 insertions(+), 98 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/ConfigurationChangedReceiver.java diff --git a/packages/SystemUI/src/com/android/systemui/ConfigurationChangedReceiver.java b/packages/SystemUI/src/com/android/systemui/ConfigurationChangedReceiver.java deleted file mode 100644 index 4fba6404f370f..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/ConfigurationChangedReceiver.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2017 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; - -import android.content.res.Configuration; - -public interface ConfigurationChangedReceiver { - void onConfigurationChanged(Configuration newConfiguration); -} diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index 15bea2484d7f3..c09c7673d376c 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -16,7 +16,6 @@ package com.android.systemui; import android.annotation.Nullable; import android.app.INotificationManager; -import android.content.res.Configuration; import android.hardware.SensorPrivacyManager; import android.hardware.display.NightDisplayListener; import android.os.Handler; @@ -521,15 +520,6 @@ public class Dependency { .forEach(o -> ((Dumpable) o).dump(fd, pw, args)); } - protected static void staticOnConfigurationChanged(Configuration newConfig) { - sDependency.onConfigurationChanged(newConfig); - } - - protected synchronized void onConfigurationChanged(Configuration newConfig) { - mDependencies.values().stream().filter(obj -> obj instanceof ConfigurationChangedReceiver) - .forEach(o -> ((ConfigurationChangedReceiver) o).onConfigurationChanged(newConfig)); - } - protected final T getDependency(Class cls) { return getDependencyInner(cls); } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 9252e57679962..0d1bd6bae2b37 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -286,7 +286,11 @@ public class SystemUIApplication extends Application implements SysUiServiceProv @Override public void onConfigurationChanged(Configuration newConfig) { if (mServicesStarted) { - Dependency.staticOnConfigurationChanged(newConfig); + SystemUIFactory + .getInstance() + .getRootComponent() + .getConfigurationController() + .onConfigurationChanged(newConfig); int len = mServices.length; for (int i = 0; i < len; i++) { if (mServices[i] != null) { diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIRootComponent.java b/packages/SystemUI/src/com/android/systemui/SystemUIRootComponent.java index f18c8b2c3da62..a5b386eddd34b 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIRootComponent.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIRootComponent.java @@ -20,6 +20,7 @@ import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME import com.android.systemui.fragments.FragmentService; import com.android.systemui.statusbar.phone.StatusBar; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.InjectionInflationController; import com.android.systemui.util.leak.GarbageMonitor; @@ -40,12 +41,20 @@ import dagger.Component; SystemUIModule.class, SystemUIDefaultModule.class}) public interface SystemUIRootComponent { + /** * Main dependency providing module. */ @Singleton Dependency.DependencyInjector createDependency(); + + /** + * Creates a ConfigurationController. + */ + @Singleton + ConfigurationController getConfigurationController(); + /** * Injects the StatusBar. */ diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java index 1a2d062f1b807..74b4f9537b87e 100644 --- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java @@ -39,13 +39,13 @@ import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.settingslib.applications.InterestingConfigChanges; -import com.android.systemui.ConfigurationChangedReceiver; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.SysUiServiceProvider; import com.android.systemui.assist.ui.DefaultUiController; import com.android.systemui.recents.OverviewProxyService; import com.android.systemui.statusbar.CommandQueue; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import javax.inject.Inject; @@ -55,7 +55,7 @@ import javax.inject.Singleton; * Class to manage everything related to assist in SystemUI. */ @Singleton -public class AssistManager implements ConfigurationChangedReceiver { +public class AssistManager { /** * Controls the UI for showing Assistant invocation progress. @@ -153,12 +153,40 @@ public class AssistManager implements ConfigurationChangedReceiver { } }; + private ConfigurationController.ConfigurationListener mConfigurationListener = + new ConfigurationController.ConfigurationListener() { + @Override + public void onConfigChanged(Configuration newConfig) { + if (!mInterestingConfigChanges.applyNewConfig(mContext.getResources())) { + return; + } + boolean visible = false; + if (mView != null) { + visible = mView.isShowing(); + mWindowManager.removeView(mView); + } + + mView = (AssistOrbContainer) LayoutInflater.from(mContext).inflate( + R.layout.assist_orb, null); + mView.setVisibility(View.GONE); + mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + WindowManager.LayoutParams lp = getLayoutParams(); + mWindowManager.addView(mView, lp); + if (visible) { + mView.show(true /* show */, false /* animate */); + } + } + }; + @Inject public AssistManager( DeviceProvisionedController controller, Context context, AssistUtils assistUtils, - AssistHandleBehaviorController handleController) { + AssistHandleBehaviorController handleController, + ConfigurationController configurationController) { mContext = context; mDeviceProvisionedController = controller; mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); @@ -167,11 +195,13 @@ public class AssistManager implements ConfigurationChangedReceiver { mPhoneStateMonitor = new PhoneStateMonitor(context); mHandleController = handleController; + configurationController.addCallback(mConfigurationListener); + registerVoiceInteractionSessionListener(); mInterestingConfigChanges = new InterestingConfigChanges(ActivityInfo.CONFIG_ORIENTATION | ActivityInfo.CONFIG_LOCALE | ActivityInfo.CONFIG_UI_MODE | ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_ASSETS_PATHS); - onConfigurationChanged(context.getResources().getConfiguration()); + mConfigurationListener.onConfigChanged(context.getResources().getConfiguration()); mShouldEnableOrb = !ActivityManager.isLowRamDeviceStatic(); mUiController = new DefaultUiController(mContext); @@ -221,29 +251,6 @@ public class AssistManager implements ConfigurationChangedReceiver { }); } - public void onConfigurationChanged(Configuration newConfiguration) { - if (!mInterestingConfigChanges.applyNewConfig(mContext.getResources())) { - return; - } - boolean visible = false; - if (mView != null) { - visible = mView.isShowing(); - mWindowManager.removeView(mView); - } - - mView = (AssistOrbContainer) LayoutInflater.from(mContext).inflate( - R.layout.assist_orb, null); - mView.setVisibility(View.GONE); - mView.setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); - WindowManager.LayoutParams lp = getLayoutParams(); - mWindowManager.addView(mView, lp); - if (visible) { - mView.show(true /* show */, false /* animate */); - } - } - protected boolean shouldShowOrb() { return false; } diff --git a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java index b4cc571be0610..bbf49e3d13d29 100644 --- a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java +++ b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java @@ -20,11 +20,11 @@ import android.os.Handler; import android.util.ArrayMap; import android.view.View; -import com.android.systemui.ConfigurationChangedReceiver; import com.android.systemui.Dumpable; import com.android.systemui.SystemUIRootComponent; import com.android.systemui.qs.QSFragment; import com.android.systemui.statusbar.phone.NavigationBarFragment; +import com.android.systemui.statusbar.policy.ConfigurationController; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -41,7 +41,7 @@ import dagger.Subcomponent; * Also dispatches the configuration changes to all current FragmentHostStates. */ @Singleton -public class FragmentService implements ConfigurationChangedReceiver, Dumpable { +public class FragmentService implements Dumpable { private static final String TAG = "FragmentService"; @@ -50,10 +50,22 @@ public class FragmentService implements ConfigurationChangedReceiver, Dumpable { private final Handler mHandler = new Handler(); private final FragmentCreator mFragmentCreator; + private ConfigurationController.ConfigurationListener mConfigurationListener = + new ConfigurationController.ConfigurationListener() { + @Override + public void onConfigChanged(Configuration newConfig) { + for (FragmentHostState state : mHosts.values()) { + state.sendConfigurationChange(newConfig); + } + } + }; + @Inject - public FragmentService(SystemUIRootComponent rootComponent) { + public FragmentService(SystemUIRootComponent rootComponent, + ConfigurationController configurationController) { mFragmentCreator = rootComponent.createFragmentCreator(); initInjectionMap(); + configurationController.addCallback(mConfigurationListener); } ArrayMap getInjectionMap() { @@ -96,13 +108,6 @@ public class FragmentService implements ConfigurationChangedReceiver, Dumpable { } } - @Override - public void onConfigurationChanged(Configuration newConfig) { - for (FragmentHostState state : mHosts.values()) { - state.sendConfigurationChange(newConfig); - } - } - @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("Dumping fragments:"); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt index 424acfd9916b3..54ef623e95ab8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt @@ -18,14 +18,11 @@ import android.content.Context import android.content.pm.ActivityInfo import android.content.res.Configuration import android.os.LocaleList - -import com.android.systemui.ConfigurationChangedReceiver import com.android.systemui.statusbar.policy.ConfigurationController import java.util.ArrayList -class ConfigurationControllerImpl(context: Context) - : ConfigurationController, ConfigurationChangedReceiver { +class ConfigurationControllerImpl(context: Context) : ConfigurationController { private val listeners: MutableList = ArrayList() private val lastConfig = Configuration() diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ConfigurationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ConfigurationController.java index 0e5c8c105df83..0a6cf7be736f9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ConfigurationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ConfigurationController.java @@ -24,7 +24,11 @@ import com.android.systemui.statusbar.policy.ConfigurationController.Configurati */ public interface ConfigurationController extends CallbackController { - public void notifyThemeChanged(); + /** Alert controller of a change in the configuration. */ + void onConfigurationChanged(Configuration newConfiguration); + + /** Alert controller of a change in between light and dark themes. */ + void notifyThemeChanged(); interface ConfigurationListener { default void onConfigChanged(Configuration newConfig) {} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java index 7a09455017dd9..2ad5a8aa7fe52 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java @@ -61,7 +61,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.TelephonyIntents; import com.android.settingslib.net.DataUsageController; -import com.android.systemui.ConfigurationChangedReceiver; import com.android.systemui.DemoMode; import com.android.systemui.Dumpable; import com.android.systemui.R; @@ -87,8 +86,7 @@ import javax.inject.Singleton; /** Platform implementation of the network controller. **/ @Singleton public class NetworkControllerImpl extends BroadcastReceiver - implements NetworkController, DemoMode, DataUsageController.NetworkNameProvider, - ConfigurationChangedReceiver, Dumpable { + implements NetworkController, DemoMode, DataUsageController.NetworkNameProvider, Dumpable { // debug static final String TAG = "NetworkController"; static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @@ -166,6 +164,14 @@ public class NetworkControllerImpl extends BroadcastReceiver private boolean mUserSetup; private boolean mSimDetected; + private ConfigurationController.ConfigurationListener mConfigurationListener = + new ConfigurationController.ConfigurationListener() { + @Override + public void onConfigChanged(Configuration newConfig) { + mConfig = Config.readConfig(mContext); + mReceiverHandler.post(() -> handleConfigurationChanged()); + } + }; /** * Construct this controller object and register for updates. */ @@ -553,16 +559,6 @@ public class NetworkControllerImpl extends BroadcastReceiver } } - public void onConfigurationChanged(Configuration newConfig) { - mConfig = Config.readConfig(mContext); - mReceiverHandler.post(new Runnable() { - @Override - public void run() { - handleConfigurationChanged(); - } - }); - } - @VisibleForTesting void handleConfigurationChanged() { updateMobileControllers(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java b/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java index b9d09ce91c1a1..420acc507f197 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java @@ -36,8 +36,6 @@ import java.io.PrintWriter; public class DependencyTest extends SysuiTestCase { public static final DependencyKey DUMPABLE = new DependencyKey<>("dumpable"); - public static final DependencyKey CONFIGURATION_CHANGED_RECEIVER - = new DependencyKey<>("config_changed_receiver"); @Test public void testClassDependency() { @@ -62,15 +60,6 @@ public class DependencyTest extends SysuiTestCase { verify(d).dump(eq(null), any(), eq(null)); } - @Test - public void testConfigurationChanged() { - ConfigurationChangedReceiver d = mock(ConfigurationChangedReceiver.class); - mDependency.injectTestDependency(CONFIGURATION_CHANGED_RECEIVER, d); - Dependency.get(CONFIGURATION_CHANGED_RECEIVER); - mDependency.onConfigurationChanged(null); - verify(d).onConfigurationChanged(eq(null)); - } - @Test public void testInitDependency() { Dependency.clearDependencies(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeConfigurationController.java b/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeConfigurationController.java index 5ddf7a208379c..f5ccac39ed203 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeConfigurationController.java +++ b/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeConfigurationController.java @@ -14,6 +14,8 @@ package com.android.systemui.utils.leaks; +import android.content.res.Configuration; + import com.android.systemui.statusbar.policy.ConfigurationController; public class FakeConfigurationController @@ -24,6 +26,10 @@ public class FakeConfigurationController super(sysuiLeakCheck, "config"); } + @Override + public void onConfigurationChanged(Configuration newConfiguration) { + } + @Override public void notifyThemeChanged() { }