Merge "Remove Dependency.staticOnConfigurationChanged"
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 4fba640..0000000
--- 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 a616484..c55b0d9 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.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 @@
.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> T getDependency(Class<T> 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 f0317b4..1b264e5 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -218,7 +218,11 @@
@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 dd00eee..256c5d5 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.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 @@
* 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 @@
}
};
+ 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 @@
AssistHandleBehaviorController handleController,
CommandQueue commandQueue,
PhoneStateMonitor phoneStateMonitor,
- OverviewProxyService overviewProxyService) {
+ OverviewProxyService overviewProxyService,
+ ConfigurationController configurationController) {
mContext = context;
mDeviceProvisionedController = controller;
mCommandQueue = commandQueue;
@@ -172,11 +200,13 @@
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 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 83d956c..3f00f41 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.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;
@@ -50,6 +51,12 @@
* Creates a ContextComponentHelper.
*/
@Singleton
+ ConfigurationController getConfigurationController();
+
+ /**
+ * Creates a ContextComponentHelper.
+ */
+ @Singleton
ContextComponentHelper getContextComponentHelper();
/**
diff --git a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java
index 1b4857e..ae20076 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.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 @@
* 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 @@
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<String, Method> getInjectionMap() {
@@ -97,13 +109,6 @@
}
@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:");
for (FragmentHostState state : mHosts.values()) {
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 424acfd..54ef623 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.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<ConfigurationController.ConfigurationListener> = 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 0e5c8c1..0a6cf7b 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 @@
*/
public interface ConfigurationController extends CallbackController<ConfigurationListener> {
- 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 12d3577..05a4b29 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.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 @@
/** 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 @@
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 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 c020514..bf2d4cd 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 @@
public class DependencyTest extends SysuiTestCase {
public static final DependencyKey<Dumpable> DUMPABLE = new DependencyKey<>("dumpable");
- public static final DependencyKey<ConfigurationChangedReceiver> CONFIGURATION_CHANGED_RECEIVER
- = new DependencyKey<>("config_changed_receiver");
@Test
public void testClassDependency() {
@@ -66,15 +64,6 @@
}
@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();
Dependency dependency = new Dependency();
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 5ddf7a2..f5ccac3 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
@@ -25,6 +27,10 @@
}
@Override
+ public void onConfigurationChanged(Configuration newConfiguration) {
+ }
+
+ @Override
public void notifyThemeChanged() {
}
}