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 a616484a3b216..c55b0d92f86d3 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -18,7 +18,6 @@ import android.annotation.Nullable; import android.app.AlarmManager; import android.app.INotificationManager; import android.app.IWallpaperManager; -import android.content.res.Configuration; import android.hardware.SensorPrivacyManager; import android.hardware.display.NightDisplayListener; import android.os.Handler; @@ -555,15 +554,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 f0317b4a02d07..1b264e5f45159 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -218,7 +218,11 @@ public class SystemUIApplication extends Application implements @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/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java index dd00eee9b87f3..256c5d51c4215 100644 --- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java @@ -41,11 +41,11 @@ 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.R; 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. @@ -154,6 +154,33 @@ 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, @@ -162,7 +189,8 @@ public class AssistManager implements ConfigurationChangedReceiver { AssistHandleBehaviorController handleController, CommandQueue commandQueue, PhoneStateMonitor phoneStateMonitor, - OverviewProxyService overviewProxyService) { + OverviewProxyService overviewProxyService, + ConfigurationController configurationController) { mContext = context; mDeviceProvisionedController = controller; mCommandQueue = commandQueue; @@ -172,11 +200,13 @@ public class AssistManager implements ConfigurationChangedReceiver { mPhoneStateMonitor = phoneStateMonitor; 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); @@ -225,29 +255,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/dagger/SystemUIRootComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java index 83d956c22fb82..3f00f41b0717d 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java @@ -25,6 +25,7 @@ import com.android.systemui.SystemUIAppComponentFactory; import com.android.systemui.SystemUIFactory; 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 javax.inject.Named; @@ -46,6 +47,12 @@ import dagger.Component; SystemUIDefaultModule.class}) public interface SystemUIRootComponent { + /** + * Creates a ContextComponentHelper. + */ + @Singleton + ConfigurationController getConfigurationController(); + /** * Creates a ContextComponentHelper. */ diff --git a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java index 1b4857ebb2094..ae200763b3b0a 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.dagger.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 12d3577315602..05a4b290fb7b9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java @@ -60,7 +60,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); @@ -167,6 +165,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. */ @@ -562,16 +568,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 c020514d06a43..bf2d4cd07165f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java @@ -37,8 +37,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() { @@ -65,15 +63,6 @@ public class DependencyTest extends SysuiTestCase { verify(d).dump(eq(fd), any(), eq(args)); } - @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() { }