import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
-import android.os.Looper;
import android.provider.Settings;
import com.android.systemui.statusbar.policy.BatteryController;
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
updateShowPercent();
- mBatteryController.addStateChangedCallback(this);
+ mBatteryController.addCallback(this);
}
public void stopListening() {
mListening = false;
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
- mBatteryController.removeStateChangedCallback(this);
+ mBatteryController.removeCallback(this);
}
public void disableShowPercent() {
import android.content.Context;
import android.content.res.TypedArray;
-import android.os.Handler;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.view.View;
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
- mBatteryController.addStateChangedCallback(this);
+ mBatteryController.addCallback(this);
mDrawable.startListening();
TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
- mBatteryController.removeStateChangedCallback(this);
+ mBatteryController.removeCallback(this);
mDrawable.stopListening();
TunerService.get(getContext()).removeTunable(this);
}
}
public void handleDestroy() {
+ setBindAllowed(false);
mServices.getContext().unregisterReceiver(mUninstallReceiver);
mStateManager.handleDestroy();
}
}
}
+ public void destroy() {
+ mServices.values().forEach(service -> service.handleDestroy());
+ mContext.unregisterReceiver(mRequestListeningReceiver);
+ }
+
private final BroadcastReceiver mRequestListeningReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@Override
public void setListening(boolean listening) {
if (listening) {
- mBatteryController.addStateChangedCallback(this);
+ mBatteryController.addCallback(this);
} else {
- mBatteryController.removeStateChangedCallback(this);
+ mBatteryController.removeCallback(this);
}
}
@Override
public void setListening(boolean listening) {
if (listening) {
- mController.addStateChangedCallback(mCallback);
+ mController.addCallback(mCallback);
} else {
- mController.removeStateChangedCallback(mCallback);
+ mController.removeCallback(mCallback);
}
}
@Override
public void setListening(boolean listening) {
if (listening) {
- mController.addSignalCallback(mSignalCallback);
+ mController.addCallback(mSignalCallback);
} else {
- mController.removeSignalCallback(mSignalCallback);
+ mController.removeCallback(mSignalCallback);
}
}
@Override
public void setListening(boolean listening) {
if (listening) {
- mDataSaverController.addListener(this);
+ mDataSaverController.addCallback(this);
} else {
- mDataSaverController.remListener(this);
+ mDataSaverController.removeCallback(this);
}
}
public FlashlightTile(Host host) {
super(host);
mFlashlightController = host.getFlashlightController();
- mFlashlightController.addListener(this);
+ mFlashlightController.addCallback(this);
}
@Override
protected void handleDestroy() {
super.handleDestroy();
- mFlashlightController.removeListener(this);
+ mFlashlightController.removeCallback(this);
}
@Override
package com.android.systemui.qs.tiles;
-import android.content.BroadcastReceiver;
-import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.UserManager;
@Override
public void setListening(boolean listening) {
if (listening) {
- mController.addSettingsChangedCallback(mCallback);
+ mController.addCallback(mCallback);
mKeyguard.addCallback(mCallback);
} else {
- mController.removeSettingsChangedCallback(mCallback);
+ mController.removeCallback(mCallback);
mKeyguard.removeCallback(mCallback);
}
}
public void setListening(boolean listening) {
if (mController == null) return;
if (listening) {
- mController.addRotationLockControllerCallback(mCallback);
+ mController.addCallback(mCallback);
} else {
- mController.removeRotationLockControllerCallback(mCallback);
+ mController.removeCallback(mCallback);
}
}
@Override
public void setListening(boolean listening) {
if (listening) {
- mUserInfoController.addListener(this);
+ mUserInfoController.addCallback(this);
} else {
- mUserInfoController.remListener(this);
+ mUserInfoController.removeCallback(this);
}
}
@Override
public void setListening(boolean listening) {
if (listening) {
- mController.addSignalCallback(mSignalCallback);
+ mController.addCallback(mSignalCallback);
} else {
- mController.removeSignalCallback(mSignalCallback);
+ mController.removeCallback(mSignalCallback);
}
}
mBlockEthernet = blockEthernet;
mBlockWifi = blockWifi;
// Re-register to get new callbacks.
- mNC.removeSignalCallback(this);
- mNC.addSignalCallback(this);
+ mNC.removeCallback(this);
+ mNC.addCallback(this);
}
}
apply();
applyIconTint();
- mNC.addSignalCallback(this);
+ mNC.addCallback(this);
}
@Override
mMobileSignalGroup.removeAllViews();
TunerService.get(mContext).removeTunable(this);
mSC.removeCallback(this);
- mNC.removeSignalCallback(this);
+ mNC.removeCallback(this);
super.onDetachedFromWindow();
}
}
@Override
- public void addStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) {
+ public void addCallback(BatteryController.BatteryStateChangeCallback cb) {
mChangeCallbacks.add(cb);
// There is no way to know if the phone is plugged in or charging via bluetooth, so pass
}
@Override
- public void removeStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) {
+ public void removeCallback(BatteryController.BatteryStateChangeCallback cb) {
mChangeCallbacks.remove(cb);
}
filter.addAction(BluetoothHeadsetClient.ACTION_AG_EVENT);
mContext.registerReceiver(this, filter);
- mController.addStateChangedCallback(this);
+ mController.addCallback(this);
}
public void stopListening() {
mContext.unregisterReceiver(this);
- mController.removeStateChangedCallback(this);
+ mController.removeCallback(this);
}
@Override
host.getHotspotController().addCallback(mHotspotCallback);
}
if (!Prefs.getBoolean(context, Key.QS_DATA_SAVER_ADDED, false)) {
- host.getNetworkController().getDataSaverController().addListener(mDataSaverListener);
+ host.getNetworkController().getDataSaverController().addCallback(mDataSaverListener);
}
if (!Prefs.getBoolean(context, Key.QS_INVERT_COLORS_ADDED, false)) {
mColorsSetting = new SecureSetting(mContext, mHandler,
}
public void destroy() {
- // TODO: Remove any registered listeners.
+ mColorsSetting.setListening(false);
+ mHost.getHotspotController().removeCallback(mHotspotCallback);
+ mHost.getNetworkController().getDataSaverController().removeCallback(mDataSaverListener);
+ mHost.getManagedProfileController().removeCallback(mProfileCallback);
}
private final ManagedProfileController.Callback mProfileCallback =
mHandler.post(new Runnable() {
@Override
public void run() {
- mHost.getNetworkController().getDataSaverController().remListener(
+ mHost.getNetworkController().getDataSaverController().removeCallback(
mDataSaverListener);
}
});
}
mBatteryListening = listening;
if (mBatteryListening) {
- mBatteryController.addStateChangedCallback(this);
+ mBatteryController.addCallback(this);
} else {
- mBatteryController.removeStateChangedCallback(this);
+ mBatteryController.removeCallback(this);
}
}
}
public void setUserInfoController(UserInfoController userInfoController) {
- userInfoController.addListener(new UserInfoController.OnUserInfoChangedListener() {
+ userInfoController.addCallback(new UserInfoController.OnUserInfoChangedListener() {
@Override
public void onUserInfoChanged(String name, Drawable picture, String userAccount) {
mMultiUserAvatar.setImageDrawable(picture);
BatteryController batteryController) {
mIconController = iconController;
mBatteryController = batteryController;
- batteryController.addStateChangedCallback(this);
+ batteryController.addCallback(this);
}
public void setFingerprintUnlockController(
import android.os.UserHandle;
import android.os.UserManager;
+import com.android.systemui.statusbar.phone.ManagedProfileController.Callback;
+import com.android.systemui.statusbar.policy.CallbackController;
+
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
-public class ManagedProfileController {
+public class ManagedProfileController implements CallbackController<Callback> {
private final List<Callback> mCallbacks = new ArrayList<>();
mLocationController = new LocationControllerImpl(mContext,
mHandlerThread.getLooper()); // will post a notification
mBatteryController = createBatteryController();
- mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() {
+ mBatteryController.addCallback(new BatteryStateChangeCallback() {
@Override
public void onPowerSaveChanged(boolean isPowerSave) {
mHandler.post(mCheckBarModes);
if (emergencyViewStub != null) {
((ViewStub) emergencyViewStub).inflate();
}
- mNetworkController.addSignalCallback(new NetworkController.SignalCallback() {
+ mNetworkController.addCallback(new NetworkController.SignalCallback() {
@Override
public void setIsAirplaneMode(NetworkController.IconState icon) {
recomputeDisableFlags(true /* animate */);
(SignalClusterView) mKeyguardStatusBar.findViewById(R.id.signal_cluster);
final SignalClusterView signalClusterQs =
(SignalClusterView) mHeader.findViewById(R.id.signal_cluster);
- mNetworkController.removeSignalCallback(signalCluster);
- mNetworkController.removeSignalCallback(signalClusterKeyguard);
- mNetworkController.removeSignalCallback(signalClusterQs);
+ mNetworkController.removeCallback(signalCluster);
+ mNetworkController.removeCallback(signalClusterKeyguard);
+ mNetworkController.removeCallback(signalClusterQs);
if (mQSPanel != null && mQSPanel.getHost() != null) {
mQSPanel.getHost().destroy();
}
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.NextAlarmController;
-import com.android.systemui.statusbar.policy.NextAlarmController.NextAlarmChangeCallback;
import com.android.systemui.statusbar.policy.RotationLockController;
import com.android.systemui.statusbar.policy.UserInfoController;
mCast = cast;
mHotspot = hotspot;
mBluetooth = bluetooth;
- mBluetooth.addStateChangedCallback(this);
+ mBluetooth.addCallback(this);
mNextAlarm = nextAlarm;
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mUserInfoController = userInfoController;
mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver);
- mRotationLockController.addRotationLockControllerCallback(this);
+ mRotationLockController.addCallback(this);
// listen for broadcasts
IntentFilter filter = new IntentFilter();
// Alarm clock
mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null);
mIconController.setIconVisibility(mSlotAlarmClock, false);
- mNextAlarm.addStateChangedCallback(mNextAlarmCallback);
+ mNextAlarm.addCallback(mNextAlarmCallback);
// zen
mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null);
mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver,
context.getString(R.string.accessibility_data_saver_on));
mIconController.setIconVisibility(mSlotDataSaver, false);
- mDataSaver.addListener(this);
+ mDataSaver.addCallback(this);
}
public void setStatusBarKeyguardViewManager(
private final AutoTileManager mAutoTiles;
private final ManagedProfileController mProfileController;
private final NextAlarmController mNextAlarmController;
+ private final HandlerThread mHandlerThread;
private View mHeader;
private int mCurrentUser;
mNextAlarmController = nextAlarmController;
mProfileController = new ManagedProfileController(this);
- final HandlerThread ht = new HandlerThread(QSTileHost.class.getSimpleName(),
+ mHandlerThread = new HandlerThread(QSTileHost.class.getSimpleName(),
Process.THREAD_PRIORITY_BACKGROUND);
- ht.start();
- mLooper = ht.getLooper();
+ mHandlerThread.start();
+ mLooper = mHandlerThread.getLooper();
mServices = new TileServices(this, mLooper);
}
public void destroy() {
+ mHandlerThread.quitSafely();
+ mTiles.values().forEach(tile -> tile.destroy());
mAutoTiles.destroy();
TunerService.get(mContext).removeTunable(this);
+ mServices.destroy();
}
@Override
final List<String> tileSpecs = loadTileSpecs(mContext, newValue);
int currentUser = ActivityManager.getCurrentUser();
if (tileSpecs.equals(mTileSpecs) && currentUser == mCurrentUser) return;
- for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) {
- if (!tileSpecs.contains(tile.getKey())) {
- if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey());
- tile.getValue().destroy();
- }
- }
+ mTiles.entrySet().stream().filter(tile -> !tileSpecs.contains(tile.getKey())).forEach(
+ tile -> {
+ if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey());
+ tile.getValue().destroy();
+ });
final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>();
for (String tileSpec : tileSpecs) {
QSTile<?> tile = mTiles.get(tileSpec);
if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
try {
tile = createTile(tileSpec);
- if (tile != null && tile.isAvailable()) {
- tile.setTileSpec(tileSpec);
- newTiles.put(tileSpec, tile);
+ if (tile != null) {
+ if (tile.isAvailable()) {
+ tile.setTileSpec(tileSpec);
+ newTiles.put(tileSpec, tile);
+ } else {
+ tile.destroy();
+ }
}
} catch (Throwable t) {
Log.w(TAG, "Error creating tile for spec: " + tileSpec, t);
@Override
protected void onDetachedFromWindow() {
setListening(false);
- mHost.getUserInfoController().remListener(this);
+ mHost.getUserInfoController().removeCallback(this);
mHost.getNetworkController().removeEmergencyListener(this);
super.onDetachedFromWindow();
}
private void updateListeners() {
if (mListening) {
- mNextAlarmController.addStateChangedCallback(this);
+ mNextAlarmController.addCallback(this);
} else {
- mNextAlarmController.removeStateChangedCallback(this);
+ mNextAlarmController.removeCallback(this);
}
}
}
public void setUserInfoController(UserInfoController userInfoController) {
- userInfoController.addListener(this);
+ userInfoController.addCallback(this);
}
@Override
package com.android.systemui.statusbar.policy;
import com.android.systemui.DemoMode;
+import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
import java.io.FileDescriptor;
import java.io.PrintWriter;
-public interface BatteryController extends DemoMode {
+public interface BatteryController extends DemoMode,
+ CallbackController<BatteryStateChangeCallback> {
/**
* Prints the current state of the {@link BatteryController} to the given {@link PrintWriter}.
*/
*/
boolean isPowerSave();
- void addStateChangedCallback(BatteryStateChangeCallback cb);
- void removeStateChangedCallback(BatteryStateChangeCallback cb);
-
/**
* A listener that will be notified whenever a change in battery level or power save mode
* has occurred.
}
@Override
- public void addStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) {
+ public void addCallback(BatteryController.BatteryStateChangeCallback cb) {
synchronized (mChangeCallbacks) {
mChangeCallbacks.add(cb);
}
}
@Override
- public void removeStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) {
+ public void removeCallback(BatteryController.BatteryStateChangeCallback cb) {
synchronized (mChangeCallbacks) {
mChangeCallbacks.remove(cb);
}
package com.android.systemui.statusbar.policy;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.systemui.statusbar.policy.BluetoothController.Callback;
import java.util.Collection;
-public interface BluetoothController {
- void addStateChangedCallback(Callback callback);
- void removeStateChangedCallback(Callback callback);
-
+public interface BluetoothController extends CallbackController<Callback> {
boolean isBluetoothSupported();
boolean isBluetoothEnabled();
}
@Override
- public void addStateChangedCallback(Callback cb) {
+ public void addCallback(Callback cb) {
mHandler.obtainMessage(H.MSG_ADD_CALLBACK, cb).sendToTarget();
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
}
@Override
- public void removeStateChangedCallback(Callback cb) {
+ public void removeCallback(Callback cb) {
mHandler.obtainMessage(H.MSG_REMOVE_CALLBACK, cb).sendToTarget();
}
--- /dev/null
+/*
+ * Copyright (C) 2016 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.statusbar.policy;
+
+public interface CallbackController<T> {
+ void addCallback(T listener);
+ void removeCallback(T listener);
+}
package com.android.systemui.statusbar.policy;
+import com.android.systemui.statusbar.policy.CastController.Callback;
+
import java.util.Set;
-public interface CastController {
- void addCallback(Callback callback);
- void removeCallback(Callback callback);
+public interface CastController extends CallbackController<Callback> {
void setDiscovering(boolean request);
void setCurrentUserId(int currentUserId);
Set<CastDevice> getCastDevices();
import android.os.Looper;
import android.os.RemoteException;
+import com.android.systemui.statusbar.policy.DataSaverController.Listener;
+
import java.util.ArrayList;
-public class DataSaverController {
+public class DataSaverController implements CallbackController<Listener> {
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final ArrayList<Listener> mListeners = new ArrayList<>();
}
}
- public void addListener(Listener listener) {
+ public void addCallback(Listener listener) {
synchronized (mListeners) {
mListeners.add(listener);
if (mListeners.size() == 1) {
listener.onDataSaverChanged(isDataSaverEnabled());
}
- public void remListener(Listener listener) {
+ public void removeCallback(Listener listener) {
synchronized (mListeners) {
mListeners.remove(listener);
if (mListeners.size() == 0) {
import android.text.TextUtils;
import android.util.Log;
+import com.android.systemui.statusbar.policy.FlashlightController.FlashlightListener;
+
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
/**
* Manages the flashlight.
*/
-public class FlashlightController {
+public class FlashlightController implements CallbackController<FlashlightListener> {
private static final String TAG = "FlashlightController";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
return mTorchAvailable;
}
- public void addListener(FlashlightListener l) {
+ public void addCallback(FlashlightListener l) {
synchronized (mListeners) {
if (mCameraId == null) {
tryInitCamera();
}
}
- public void removeListener(FlashlightListener l) {
+ public void removeCallback(FlashlightListener l) {
synchronized (mListeners) {
cleanUpListenersLocked(l);
}
package com.android.systemui.statusbar.policy;
-public interface HotspotController {
- void addCallback(Callback callback);
- void removeCallback(Callback callback);
+import com.android.systemui.statusbar.policy.HotspotController.Callback;
+
+public interface HotspotController extends CallbackController<Callback> {
boolean isHotspotEnabled();
void setHotspotEnabled(boolean enabled);
boolean isHotspotSupported();
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.settings.CurrentUserTracker;
+import com.android.systemui.statusbar.policy.KeyguardMonitor.Callback;
import java.util.ArrayList;
-public final class KeyguardMonitor extends KeyguardUpdateMonitorCallback {
+public class KeyguardMonitor extends KeyguardUpdateMonitorCallback
+ implements CallbackController<Callback> {
private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
package com.android.systemui.statusbar.policy;
-public interface LocationController {
+import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback;
+
+public interface LocationController extends CallbackController<LocationSettingsChangeCallback> {
boolean isLocationEnabled();
boolean setLocationEnabled(boolean enabled);
- void addSettingsChangedCallback(LocationSettingsChangeCallback cb);
- void removeSettingsChangedCallback(LocationSettingsChangeCallback cb);
/**
* A callback for change in location settings (the user has enabled/disabled location).
/**
* Add a callback to listen for changes in location settings.
*/
- public void addSettingsChangedCallback(LocationSettingsChangeCallback cb) {
+ public void addCallback(LocationSettingsChangeCallback cb) {
mSettingsChangeCallbacks.add(cb);
mHandler.sendEmptyMessage(H.MSG_LOCATION_SETTINGS_CHANGED);
}
- public void removeSettingsChangedCallback(LocationSettingsChangeCallback cb) {
+ public void removeCallback(LocationSettingsChangeCallback cb) {
mSettingsChangeCallbacks.remove(cb);
}
import android.telephony.SubscriptionInfo;
import com.android.settingslib.net.DataUsageController;
import com.android.settingslib.wifi.AccessPoint;
+import com.android.systemui.statusbar.policy.NetworkController.SignalCallback;
import java.util.List;
-public interface NetworkController {
+public interface NetworkController extends CallbackController<SignalCallback> {
boolean hasMobileDataFeature();
- void addSignalCallback(SignalCallback cb);
- void removeSignalCallback(SignalCallback cb);
+ void addCallback(SignalCallback cb);
+ void removeCallback(SignalCallback cb);
void setWifiEnabled(boolean enabled);
void onUserSwitched(int newUserId);
AccessPointController getAccessPointController();
mCallbackHandler.setEmergencyCallsOnly(mIsEmergency);
}
- public void addSignalCallback(SignalCallback cb) {
+ public void addCallback(SignalCallback cb) {
cb.setSubs(mCurrentSubscriptions);
cb.setIsAirplaneMode(new IconState(mAirplaneMode,
TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext));
}
@Override
- public void removeSignalCallback(SignalCallback cb) {
+ public void removeCallback(SignalCallback cb) {
mCallbackHandler.setListening(cb, false);
}
import android.content.IntentFilter;
import android.os.UserHandle;
+import com.android.systemui.statusbar.policy.NextAlarmController.NextAlarmChangeCallback;
+
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
-public class NextAlarmController extends BroadcastReceiver {
+public class NextAlarmController extends BroadcastReceiver
+ implements CallbackController<NextAlarmChangeCallback> {
private final ArrayList<NextAlarmChangeCallback> mChangeCallbacks = new ArrayList<>();
pw.print(" mNextAlarm="); pw.println(mNextAlarm);
}
- public void addStateChangedCallback(NextAlarmChangeCallback cb) {
+ public void addCallback(NextAlarmChangeCallback cb) {
mChangeCallbacks.add(cb);
cb.onNextAlarmChanged(mNextAlarm);
}
- public void removeStateChangedCallback(NextAlarmChangeCallback cb) {
+ public void removeCallback(NextAlarmChangeCallback cb) {
mChangeCallbacks.remove(cb);
}
package com.android.systemui.statusbar.policy;
-public interface RotationLockController extends Listenable {
+import com.android.systemui.statusbar.policy.RotationLockController.RotationLockControllerCallback;
+
+public interface RotationLockController extends Listenable,
+ CallbackController<RotationLockControllerCallback> {
int getRotationLockOrientation();
boolean isRotationLockAffordanceVisible();
boolean isRotationLocked();
void setRotationLocked(boolean locked);
- void addRotationLockControllerCallback(RotationLockControllerCallback callback);
- void removeRotationLockControllerCallback(RotationLockControllerCallback callback);
public interface RotationLockControllerCallback {
void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible);
setListening(true);
}
- public void addRotationLockControllerCallback(RotationLockControllerCallback callback) {
+ public void addCallback(RotationLockControllerCallback callback) {
mCallbacks.add(callback);
notifyChanged(callback);
}
- public void removeRotationLockControllerCallback(RotationLockControllerCallback callback) {
+ public void removeCallback(RotationLockControllerCallback callback) {
mCallbacks.remove(callback);
}
*/
package com.android.systemui.statusbar.policy;
-public interface SecurityController {
+import com.android.systemui.statusbar.policy.SecurityController.SecurityControllerCallback;
+
+public interface SecurityController extends CallbackController<SecurityControllerCallback> {
/** Whether the device has device owner, even if not on this user. */
boolean isDeviceManaged();
boolean hasProfileOwner();
String getProfileVpnName();
void onUserSwitched(int newUserId);
- void addCallback(SecurityControllerCallback callback);
- void removeCallback(SecurityControllerCallback callback);
-
public interface SecurityControllerCallback {
void onStateChanged();
}
package com.android.systemui.statusbar.policy;
-import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.content.BroadcastReceiver;
import android.content.Context;
import com.android.internal.util.UserIcons;
import com.android.settingslib.drawable.UserIconDrawable;
import com.android.systemui.R;
+import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener;
import java.util.ArrayList;
-public final class UserInfoController {
+public class UserInfoController implements CallbackController<OnUserInfoChangedListener> {
private static final String TAG = "UserInfoController";
null, null);
}
- public void addListener(OnUserInfoChangedListener callback) {
+ public void addCallback(OnUserInfoChangedListener callback) {
mCallbacks.add(callback);
callback.onUserInfoChanged(mUserName, mUserDrawable, mUserAccount);
}
- public void remListener(OnUserInfoChangedListener callback) {
+ public void removeCallback(OnUserInfoChangedListener callback) {
mCallbacks.remove(callback);
}
import android.widget.BaseAdapter;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.UserIcons;
import com.android.settingslib.RestrictedLockUtils;
import com.android.systemui.GuestResumeSessionReceiver;
refreshUsers(UserHandle.USER_ALL);
}
+ @VisibleForTesting
+ public void addAdapter(WeakReference<BaseUserAdapter> adapter) {
+ mAdapters.add(adapter);
+ }
+
+ @VisibleForTesting
+ public KeyguardMonitor getKeyguardMonitor() {
+ return mKeyguardMonitor;
+ }
+
+ @VisibleForTesting
+ public ArrayList<UserRecord> getUsers() {
+ return mUsers;
+ }
+
public static abstract class BaseUserAdapter extends BaseAdapter {
final UserSwitcherController mController;
protected BaseUserAdapter(UserSwitcherController controller) {
mController = controller;
- controller.mAdapters.add(new WeakReference<>(this));
+ controller.addAdapter(new WeakReference<>(this));
}
@Override
public int getCount() {
- boolean secureKeyguardShowing = mController.mKeyguardMonitor.isShowing()
- && mController.mKeyguardMonitor.isSecure()
- && !mController.mKeyguardMonitor.canSkipBouncer();
+ boolean secureKeyguardShowing = mController.getKeyguardMonitor().isShowing()
+ && mController.getKeyguardMonitor().isSecure()
+ && !mController.getKeyguardMonitor().canSkipBouncer();
if (!secureKeyguardShowing) {
- return mController.mUsers.size();
+ return mController.getUsers().size();
}
// The lock screen is secure and showing. Filter out restricted records.
- final int N = mController.mUsers.size();
+ final int N = mController.getUsers().size();
int count = 0;
for (int i = 0; i < N; i++) {
- if (mController.mUsers.get(i).isRestricted) {
+ if (mController.getUsers().get(i).isRestricted) {
break;
} else {
count++;
@Override
public UserRecord getItem(int position) {
- return mController.mUsers.get(position);
+ return mController.getUsers().get(position);
}
@Override
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ZenRule;
-public interface ZenModeController {
- void addCallback(Callback callback);
- void removeCallback(Callback callback);
+import com.android.systemui.statusbar.policy.ZenModeController.Callback;
+
+public interface ZenModeController extends CallbackController<Callback> {
void setZen(int zen, Uri conditionId, String reason);
int getZen();
ZenRule getManualRule();
<uses-permission android:name="android.permission.MANAGE_USERS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.BIND_QUICK_SETTINGS_TILE" />
<application>
<uses-library android:name="android.test.runner" />
--- /dev/null
+/*
+ * Copyright (C) 2016 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.annotation.Nullable;
+import android.app.Fragment;
+import android.app.FragmentController;
+import android.app.FragmentHostCallback;
+import android.app.FragmentManagerNonConfig;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Parcelable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * Base class for fragment class tests. Just adding one for any fragment will push it through
+ * general lifecycle events and ensure no basic leaks are happening. This class also implements
+ * the host for subclasses, so they can push it into desired states and do any unit testing
+ * required.
+ */
+public abstract class FragmentTestCase extends LeakCheckedTest {
+
+ private static final int VIEW_ID = 42;
+ private final Class<? extends Fragment> mCls;
+ private HandlerThread mHandlerThread;
+ private Handler mHandler;
+ private FrameLayout mView;
+ protected FragmentController mFragments;
+ protected Fragment mFragment;
+
+ public FragmentTestCase(Class<? extends Fragment> cls) {
+ mCls = cls;
+ }
+
+ @Before
+ public void setupFragment() throws IllegalAccessException, InstantiationException {
+ mView = new FrameLayout(mContext);
+ mView.setId(VIEW_ID);
+ mHandlerThread = new HandlerThread("FragmentTestThread");
+ mHandlerThread.start();
+ mHandler = new Handler(mHandlerThread.getLooper());
+ mFragment = mCls.newInstance();
+ postAndWait(() -> {
+ mFragments = FragmentController.createController(new HostCallbacks());
+ mFragments.attachHost(null);
+ mFragments.getFragmentManager().beginTransaction()
+ .replace(VIEW_ID, mFragment)
+ .commit();
+ });
+ }
+
+ @After
+ public void tearDown() {
+ if (mFragments != null) {
+ // Set mFragments to null to let it know not to destroy.
+ postAndWait(() -> mFragments.dispatchDestroy());
+ }
+ mHandlerThread.quit();
+ }
+
+ @Test
+ public void testCreateDestroy() {
+ postAndWait(() -> mFragments.dispatchCreate());
+ destroyFragments();
+ }
+
+ @Test
+ public void testStartStop() {
+ postAndWait(() -> mFragments.dispatchStart());
+ postAndWait(() -> mFragments.dispatchStop());
+ }
+
+ @Test
+ public void testResumePause() {
+ postAndWait(() -> mFragments.dispatchResume());
+ postAndWait(() -> mFragments.dispatchPause());
+ }
+
+ @Test
+ public void testRecreate() {
+ postAndWait(() -> mFragments.dispatchResume());
+ postAndWait(() -> {
+ mFragments.dispatchPause();
+ Parcelable p = mFragments.saveAllState();
+ mFragments.dispatchDestroy();
+
+ mFragments = FragmentController.createController(new HostCallbacks());
+ mFragments.attachHost(null);
+ mFragments.restoreAllState(p, (FragmentManagerNonConfig) null);
+ mFragments.dispatchResume();
+ });
+ }
+
+ @Test
+ public void testMultipleResumes() {
+ postAndWait(() -> mFragments.dispatchResume());
+ postAndWait(() -> mFragments.dispatchStop());
+ postAndWait(() -> mFragments.dispatchResume());
+ }
+
+ protected void destroyFragments() {
+ postAndWait(() -> mFragments.dispatchDestroy());
+ mFragments = null;
+ }
+
+ protected void postAndWait(Runnable r) {
+ mHandler.post(r);
+ waitForFragments();
+ }
+
+ protected void waitForFragments() {
+ waitForIdleSync(mHandler);
+ }
+
+ private View findViewById(int id) {
+ return mView.findViewById(id);
+ }
+
+ private class HostCallbacks extends FragmentHostCallback<FragmentTestCase> {
+ public HostCallbacks() {
+ super(getTrackedContext(), FragmentTestCase.this.mHandler, 0);
+ }
+
+ @Override
+ public FragmentTestCase onGetHost() {
+ return FragmentTestCase.this;
+ }
+
+ @Override
+ public void onDump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
+ }
+
+ @Override
+ public boolean onShouldSaveFragmentState(Fragment fragment) {
+ return true; // True for now.
+ }
+
+ @Override
+ public LayoutInflater onGetLayoutInflater() {
+ return LayoutInflater.from(mContext);
+ }
+
+ @Override
+ public boolean onUseFragmentManagerInflaterFactory() {
+ return true;
+ }
+
+ @Override
+ public boolean onHasWindowAnimations() {
+ return false;
+ }
+
+ @Override
+ public int onGetWindowAnimations() {
+ return 0;
+ }
+
+ @Override
+ public void onAttachFragment(Fragment fragment) {
+ }
+
+ @Nullable
+ @Override
+ public View onFindViewById(int id) {
+ return FragmentTestCase.this.findViewById(id);
+ }
+
+ @Override
+ public boolean onHasView() {
+ return true;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 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 static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentCallbacks;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.Log;
+
+import com.android.systemui.statusbar.phone.ManagedProfileController;
+import com.android.systemui.statusbar.policy.BatteryController;
+import com.android.systemui.statusbar.policy.BluetoothController;
+import com.android.systemui.statusbar.policy.CastController;
+import com.android.systemui.statusbar.policy.DataSaverController;
+import com.android.systemui.statusbar.policy.FlashlightController;
+import com.android.systemui.statusbar.policy.HotspotController;
+import com.android.systemui.statusbar.policy.KeyguardMonitor;
+import com.android.systemui.statusbar.policy.LocationController;
+import com.android.systemui.statusbar.policy.NetworkController;
+import com.android.systemui.statusbar.policy.NextAlarmController;
+import com.android.systemui.statusbar.policy.RotationLockController;
+import com.android.systemui.statusbar.policy.SecurityController;
+import com.android.systemui.statusbar.policy.CallbackController;
+import com.android.systemui.statusbar.policy.UserInfoController;
+import com.android.systemui.statusbar.policy.ZenModeController;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Base class for tests to check if receivers are left registered, services bound, or other
+ * listeners listening.
+ */
+public class LeakCheckedTest extends SysuiTestCase {
+ private static final String TAG = "LeakCheckedTest";
+
+ private final Map<String, Tracker> mTrackers = new HashMap<>();
+ private final Map<Class, Object> mLeakCheckers = new ArrayMap<>();
+ private TrackingContext mTrackedContext;
+
+ @Rule
+ public TestWatcher successWatcher = new TestWatcher() {
+ @Override
+ protected void succeeded(Description description) {
+ verify();
+ }
+ };
+
+ @Before
+ public void setup() {
+ mTrackedContext = new TrackingContext(mContext);
+ addSupportedLeakCheckers();
+ }
+
+ public <T> T getLeakChecker(Class<T> cls) {
+ T obj = (T) mLeakCheckers.get(cls);
+ if (obj == null) {
+ Assert.fail(cls.getName() + " is not supported by LeakCheckedTest yet");
+ }
+ return obj;
+ }
+
+ public Context getTrackedContext() {
+ return mTrackedContext;
+ }
+
+ private Tracker getTracker(String tag) {
+ Tracker t = mTrackers.get(tag);
+ if (t == null) {
+ t = new Tracker();
+ mTrackers.put(tag, t);
+ }
+ return t;
+ }
+
+ public void verify() {
+ mTrackers.values().forEach(Tracker::verify);
+ }
+
+ public static class Tracker {
+ private Map<Object, LeakInfo> mObjects = new ArrayMap<>();
+
+ LeakInfo getLeakInfo(Object object) {
+ LeakInfo leakInfo = mObjects.get(object);
+ if (leakInfo == null) {
+ leakInfo = new LeakInfo();
+ mObjects.put(object, leakInfo);
+ }
+ return leakInfo;
+ }
+
+ private void verify() {
+ mObjects.values().forEach(LeakInfo::verify);
+ }
+ }
+
+ public static class LeakInfo {
+ private List<Throwable> mThrowables = new ArrayList<>();
+
+ private LeakInfo() {
+ }
+
+ private void addAllocation(Throwable t) {
+ // TODO: Drop off the first element in the stack trace here to have a cleaner stack.
+ mThrowables.add(t);
+ }
+
+ private void clearAllocations() {
+ mThrowables.clear();
+ }
+
+ public void verify() {
+ if (mThrowables.size() == 0) return;
+ Log.e(TAG, "Listener or binding not properly released");
+ for (Throwable t : mThrowables) {
+ Log.e(TAG, "Allocation found", t);
+ }
+ StringWriter writer = new StringWriter();
+ mThrowables.get(0).printStackTrace(new PrintWriter(writer));
+ Assert.fail("Listener or binding not properly released\n"
+ + writer.toString());
+ }
+ }
+
+ private void addSupportedLeakCheckers() {
+ addListening("bluetooth", BluetoothController.class);
+ addListening("location", LocationController.class);
+ addListening("rotation", RotationLockController.class);
+ addListening("zen", ZenModeController.class);
+ addListening("cast", CastController.class);
+ addListening("hotspot", HotspotController.class);
+ addListening("flashlight", FlashlightController.class);
+ addListening("user", UserInfoController.class);
+ addListening("keyguard", KeyguardMonitor.class);
+ addListening("battery", BatteryController.class);
+ addListening("security", SecurityController.class);
+ addListening("profile", ManagedProfileController.class);
+ addListening("alarm", NextAlarmController.class);
+ NetworkController network = addListening("network", NetworkController.class);
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ getTracker("emergency").getLeakInfo(invocation.getArguments()[0])
+ .addAllocation(new Throwable());
+ return null;
+ }
+ }).when(network).addEmergencyListener(any());
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ getTracker("emergency").getLeakInfo(invocation.getArguments()[0]).clearAllocations();
+ return null;
+ }
+ }).when(network).removeEmergencyListener(any());
+ DataSaverController datasaver = addListening("datasaver", DataSaverController.class);
+ when(network.getDataSaverController()).thenReturn(datasaver);
+ }
+
+ private <T extends CallbackController> T addListening(final String tag, Class<T> cls) {
+ T mock = mock(cls);
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ getTracker(tag).getLeakInfo(invocation.getArguments()[0])
+ .addAllocation(new Throwable());
+ return null;
+ }
+ }).when(mock).addCallback(any());
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ getTracker(tag).getLeakInfo(invocation.getArguments()[0]).clearAllocations();
+ return null;
+ }
+ }).when(mock).removeCallback(any());
+ mLeakCheckers.put(cls, mock);
+ return mock;
+ }
+
+ class TrackingContext extends ContextWrapper {
+ public TrackingContext(Context base) {
+ super(base);
+ }
+
+ @Override
+ public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
+ getTracker("receiver").getLeakInfo(receiver).addAllocation(new Throwable());
+ return super.registerReceiver(receiver, filter);
+ }
+
+ @Override
+ public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
+ String broadcastPermission, Handler scheduler) {
+ getTracker("receiver").getLeakInfo(receiver).addAllocation(new Throwable());
+ return super.registerReceiver(receiver, filter, broadcastPermission, scheduler);
+ }
+
+ @Override
+ public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
+ IntentFilter filter, String broadcastPermission, Handler scheduler) {
+ getTracker("receiver").getLeakInfo(receiver).addAllocation(new Throwable());
+ return super.registerReceiverAsUser(receiver, user, filter, broadcastPermission,
+ scheduler);
+ }
+
+ @Override
+ public void unregisterReceiver(BroadcastReceiver receiver) {
+ getTracker("receiver").getLeakInfo(receiver).clearAllocations();
+ super.unregisterReceiver(receiver);
+ }
+
+ @Override
+ public boolean bindService(Intent service, ServiceConnection conn, int flags) {
+ getTracker("service").getLeakInfo(conn).addAllocation(new Throwable());
+ return super.bindService(service, conn, flags);
+ }
+
+ @Override
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
+ Handler handler, UserHandle user) {
+ getTracker("service").getLeakInfo(conn).addAllocation(new Throwable());
+ return super.bindServiceAsUser(service, conn, flags, handler, user);
+ }
+
+ @Override
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
+ UserHandle user) {
+ getTracker("service").getLeakInfo(conn).addAllocation(new Throwable());
+ return super.bindServiceAsUser(service, conn, flags, user);
+ }
+
+ @Override
+ public void unbindService(ServiceConnection conn) {
+ getTracker("service").getLeakInfo(conn).clearAllocations();
+ super.unbindService(conn);
+ }
+
+ @Override
+ public void registerComponentCallbacks(ComponentCallbacks callback) {
+ getTracker("component").getLeakInfo(callback).addAllocation(new Throwable());
+ super.registerComponentCallbacks(callback);
+ }
+
+ @Override
+ public void unregisterComponentCallbacks(ComponentCallbacks callback) {
+ getTracker("component").getLeakInfo(callback).clearAllocations();
+ super.unregisterComponentCallbacks(callback);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 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.qs;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.os.Handler;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.systemui.FragmentTestCase;
+import com.android.systemui.statusbar.phone.PhoneStatusBar;
+import com.android.systemui.statusbar.phone.QSTileHost;
+import com.android.systemui.statusbar.phone.StatusBarIconController;
+import com.android.systemui.statusbar.policy.BatteryController;
+import com.android.systemui.statusbar.policy.BluetoothController;
+import com.android.systemui.statusbar.policy.CastController;
+import com.android.systemui.statusbar.policy.FlashlightController;
+import com.android.systemui.statusbar.policy.HotspotController;
+import com.android.systemui.statusbar.policy.KeyguardMonitor;
+import com.android.systemui.statusbar.policy.LocationController;
+import com.android.systemui.statusbar.policy.NetworkController;
+import com.android.systemui.statusbar.policy.NextAlarmController;
+import com.android.systemui.statusbar.policy.RotationLockController;
+import com.android.systemui.statusbar.policy.SecurityController;
+import com.android.systemui.statusbar.policy.UserInfoController;
+import com.android.systemui.statusbar.policy.UserSwitcherController;
+import com.android.systemui.statusbar.policy.ZenModeController;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+
+@RunWith(AndroidJUnit4.class)
+public class QSFragmentTest extends FragmentTestCase {
+
+ public QSFragmentTest() {
+ super(QSFragment.class);
+ }
+
+ @Test
+ public void testListening() {
+ QSFragment qs = (QSFragment) mFragment;
+ postAndWait(() -> mFragments.dispatchResume());
+ UserSwitcherController userSwitcher = mock(UserSwitcherController.class);
+ KeyguardMonitor keyguardMonitor = getLeakChecker(KeyguardMonitor.class);
+ when(userSwitcher.getKeyguardMonitor()).thenReturn(keyguardMonitor);
+ when(userSwitcher.getUsers()).thenReturn(new ArrayList<>());
+ QSTileHost host = new QSTileHost(getTrackedContext(),
+ mock(PhoneStatusBar.class),
+ getLeakChecker(BluetoothController.class),
+ getLeakChecker(LocationController.class),
+ getLeakChecker(RotationLockController.class),
+ getLeakChecker(NetworkController.class),
+ getLeakChecker(ZenModeController.class),
+ getLeakChecker(HotspotController.class),
+ getLeakChecker(CastController.class),
+ getLeakChecker(FlashlightController.class),
+ userSwitcher,
+ getLeakChecker(UserInfoController.class),
+ keyguardMonitor,
+ getLeakChecker(SecurityController.class),
+ getLeakChecker(BatteryController.class),
+ mock(StatusBarIconController.class),
+ getLeakChecker(NextAlarmController.class));
+ qs.setHost(host);
+ Handler h = new Handler(host.getLooper());
+
+ qs.setListening(true);
+ waitForIdleSync(h);
+
+ qs.setListening(false);
+ waitForIdleSync(h);
+
+ host.destroy();
+ }
+}
import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config;
import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults;
import com.android.systemui.SysuiTestCase;
-import org.junit.After;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestWatcher;
// Trigger blank callbacks to always get the current state (some tests don't trigger
// changes from default state).
- mNetworkController.addSignalCallback(mock(SignalCallback.class));
+ mNetworkController.addCallback(mock(SignalCallback.class));
mNetworkController.addEmergencyListener(null);
}