diff options
| author | 2020-02-28 17:04:21 -0500 | |
|---|---|---|
| committer | 2020-03-02 18:37:45 +0000 | |
| commit | 4e7dd9a9d8a2e9bff92690bfc7982ebbf24b2cbb (patch) | |
| tree | 977bb1ddd6d639339cf0fda797c0ba34b5d37e84 | |
| parent | ee540c32457f6228a6eef47ec1fb6828a9d84126 (diff) | |
Unregister listeners after running KeyguardUpdateMonitorTest
Fixes: 150592614
Test: atest KeyguardUpdateMonitorTest
Change-Id: I83d22fb75d3798d0cdeaf4d67885af01d9102b08
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java | 64 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java | 6 |
2 files changed, 54 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 97b21135d661..6a6255f616a3 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -263,6 +263,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private final IDreamManager mDreamManager; private boolean mIsDreaming; private final DevicePolicyManager mDevicePolicyManager; + private final BroadcastDispatcher mBroadcastDispatcher; private boolean mLogoutEnabled; // If the user long pressed the lock icon, disabling face auth for the current session. private boolean mLockIconPressed; @@ -1482,6 +1483,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); mStrongAuthTracker = new StrongAuthTracker(context, this::notifyStrongAuthStateChanged); mBackgroundExecutor = backgroundExecutor; + mBroadcastDispatcher = broadcastDispatcher; dumpManager.registerDumpable(getClass().getName(), this); mHandler = new Handler(mainLooper) { @@ -1617,7 +1619,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); - broadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, mHandler); + mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, mHandler); final IntentFilter allUserFilter = new IntentFilter(); allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); @@ -1628,25 +1630,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab allUserFilter.addAction(ACTION_USER_UNLOCKED); allUserFilter.addAction(ACTION_USER_STOPPED); allUserFilter.addAction(ACTION_USER_REMOVED); - broadcastDispatcher.registerReceiverWithHandler(mBroadcastAllReceiver, allUserFilter, + mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastAllReceiver, allUserFilter, mHandler, UserHandle.ALL); mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); try { - ActivityManager.getService().registerUserSwitchObserver( - new UserSwitchObserver() { - @Override - public void onUserSwitching(int newUserId, IRemoteCallback reply) { - mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, - newUserId, 0, reply)); - } - - @Override - public void onUserSwitchComplete(int newUserId) throws RemoteException { - mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, - newUserId, 0)); - } - }, TAG); + ActivityManager.getService().registerUserSwitchObserver(mUserSwitchObserver, TAG); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } @@ -1701,6 +1690,20 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } + private final UserSwitchObserver mUserSwitchObserver = new UserSwitchObserver() { + @Override + public void onUserSwitching(int newUserId, IRemoteCallback reply) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, + newUserId, 0, reply)); + } + + @Override + public void onUserSwitchComplete(int newUserId) throws RemoteException { + mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, + newUserId, 0)); + } + }; + private void updateAirplaneModeState() { // ACTION_AIRPLANE_MODE_CHANGED do not broadcast if device set AirplaneMode ON and boot if (!WirelessUtils.isAirplaneModeOn(mContext) @@ -2711,6 +2714,35 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } + /** + * Unregister all listeners. + */ + public void destroy() { + // TODO: inject these dependencies: + TelephonyManager telephony = + (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + if (telephony != null) { + telephony.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); + } + + mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionListener); + + if (mDeviceProvisionedObserver != null) { + mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); + } + + try { + ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver); + } catch (RemoteException e) { + Log.d(TAG, "RemoteException onDestroy. cannot unregister userSwitchObserver"); + } + + ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); + + mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); + mBroadcastDispatcher.unregisterReceiver(mBroadcastAllReceiver); + } + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("KeyguardUpdateMonitor state:"); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index 6d614af95bac..eead1204aa11 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -67,6 +67,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dump.DumpManager; import com.android.systemui.statusbar.phone.KeyguardBypassController; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -157,6 +158,11 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(context); } + @After + public void tearDown() { + mKeyguardUpdateMonitor.destroy(); + } + @Test public void testReceiversRegistered() { verify(mBroadcastDispatcher, atLeastOnce()).registerReceiverWithHandler( |