Merge "Remove Dependency.staticOnConfigurationChanged" into qt-qpr1-dev

This commit is contained in:
Dave Mankoff
2020-03-03 22:30:59 +00:00
committed by Android (Google) Code Review
11 changed files with 84 additions and 98 deletions

View File

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

View File

@@ -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> T getDependency(Class<T> cls) {
return getDependencyInner(cls);
}

View File

@@ -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) {

View File

@@ -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.
*/

View File

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

View File

@@ -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<String, Method> 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:");

View File

@@ -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<ConfigurationController.ConfigurationListener> = ArrayList()
private val lastConfig = Configuration()

View File

@@ -24,7 +24,11 @@ import com.android.systemui.statusbar.policy.ConfigurationController.Configurati
*/
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) {}

View File

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

View File

@@ -36,8 +36,6 @@ import java.io.PrintWriter;
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() {
@@ -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();

View File

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