diff options
| author | 2020-08-03 18:55:23 -0700 | |
|---|---|---|
| committer | 2020-08-03 19:00:07 -0700 | |
| commit | efc0db38e4035b4a205a8e7f842fabeb6921c5cd (patch) | |
| tree | b1bae59cef742b324559c94ab03ae67594da94e1 | |
| parent | 9999b20ea633b494aa94081b5949acb97b8c9da7 (diff) | |
Fix AppOpsServiceTest flakiness.
AppOpsServiceTest creates multiple instances of AppOpsService, and
they write to the same file asynchronously, which may result in a
previous method overwriting the file being used by the current
method.
This change calls shutdown() after each test method, and removes any
pending write runnable from the handler. It also removes unnecessary
calls to readState() because state is always read in AppOpsService
constructor.
Fixes: 160785982
Test: atest AppOpsServiceTest
Change-Id: If792b61e5cae1d15601a18ef9cb0f71bc79d3d05
| -rw-r--r-- | services/core/java/com/android/server/appop/AppOpsService.java | 1 | ||||
| -rw-r--r-- | services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java | 10 |
2 files changed, 6 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 74f3daf50079..dd29304bee21 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -1892,6 +1892,7 @@ public class AppOpsService extends IAppOpsService.Stub { synchronized (this) { if (mWriteScheduled) { mWriteScheduled = false; + mHandler.removeCallbacks(mWriteRunner); doWrite = true; } } diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java index 0a61c443e0bd..7a3a9504a0b3 100644 --- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java @@ -130,7 +130,9 @@ public class AppOpsServiceTest { } @After - public void resetStaticMocks() { + public void tearDown() { + mAppOpsService.shutdown(); + mMockingSession.finishMocking(); } @@ -216,9 +218,8 @@ public class AppOpsServiceTest { false); mAppOpsService.writeState(); - // Create a new app ops service, and initialize its state from XML. + // Create a new app ops service which will initialize its state from XML. setupAppOpsService(); - mAppOpsService.readState(); // Query the state of the 2nd service. List<PackageOps> loggedOps = getLoggedOps(); @@ -233,9 +234,8 @@ public class AppOpsServiceTest { mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false); mAppOpsService.shutdown(); - // Create a new app ops service, and initialize its state from XML. + // Create a new app ops service which will initialize its state from XML. setupAppOpsService(); - mAppOpsService.readState(); // Query the state of the 2nd service. List<PackageOps> loggedOps = getLoggedOps(); |