From a4b4184f237ce7dab92d5c5db7367cc75e9e39e2 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Tue, 28 May 2019 11:19:17 -0400 Subject: [PATCH] Clear AppOpsController when it stops listening If AppOpsController stops listening, the lists were not cleared and it may not receive the update to remove an active AppOp. To make sure that we do not show outdated behavior once the controller is listening again, we clear the lists on setListening(false). When the controller goes back to listening, we will not have information of anything that happened while the controller was not listening. Test: atest AppOpsControllerTest Fixes: 133263799 Change-Id: I2827b03d39d3b16c9cf6593537f7c1e30d7946f5 --- .../systemui/appops/AppOpsControllerImpl.java | 7 +++++++ .../systemui/appops/AppOpsControllerTest.java | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java index 3fc6689b2f195..49bd5bd09220e 100644 --- a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java @@ -100,6 +100,13 @@ public class AppOpsControllerImpl implements AppOpsController, } else { mAppOps.stopWatchingActive(this); mAppOps.stopWatchingNoted(this); + mBGHandler.removeCallbacksAndMessages(null); // null removes all + synchronized (mActiveItems) { + mActiveItems.clear(); + } + synchronized (mNotedItems) { + mNotedItems.clear(); + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java index b9afea155ccf9..cc31531c90a7d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java @@ -16,7 +16,10 @@ package com.android.systemui.appops; +import static junit.framework.TestCase.assertFalse; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -189,4 +192,21 @@ public class AppOpsControllerTest extends SysuiTestCase { AppOpsManager.MODE_ALLOWED); verify(mMockHandler).scheduleRemoval(any(AppOpItem.class), anyLong()); } + + @Test + public void noItemsAfterStopListening() { + mController.setBGHandler(mMockHandler); + + mController.setListening(true); + mController.onOpActiveChanged(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, + true); + mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, + AppOpsManager.MODE_ALLOWED); + assertFalse(mController.getActiveAppOps().isEmpty()); + + mController.setListening(false); + + verify(mMockHandler).removeCallbacksAndMessages(null); + assertTrue(mController.getActiveAppOps().isEmpty()); + } }