From fd65813157e4dd7fa9f0b7c5dd4c8f536cc6316a Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 3 May 2017 11:38:01 -0600 Subject: Offer to wait until broadcasts have drained. We've seen evidence of lab devices racing with other apps that are using cache space immediately after tests wipe it clean, which can cause test failures. To mitigate this, try our best to wait for the device to go "idle" by watching for broadcast queues to fully drain. Also improve javadocs along the way. Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest Bug: 37486230, 37566983, 37913442, 37914374 Change-Id: I4d430db443b6fa6d33a625fe07b90279b5d51c12 --- .../com/android/server/usage/StorageStatsService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'services/usage/java') diff --git a/services/usage/java/com/android/server/usage/StorageStatsService.java b/services/usage/java/com/android/server/usage/StorageStatsService.java index e13665bed275..935128b1aa36 100644 --- a/services/usage/java/com/android/server/usage/StorageStatsService.java +++ b/services/usage/java/com/android/server/usage/StorageStatsService.java @@ -112,9 +112,12 @@ public class StorageStatsService extends IStorageStatsManager.Stub { mStorage.registerListener(new StorageEventListener() { @Override public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) { - if ((vol.type == VolumeInfo.TYPE_PRIVATE) - && (newState == VolumeInfo.STATE_MOUNTED)) { - invalidateMounts(); + switch (vol.type) { + case VolumeInfo.TYPE_PRIVATE: + case VolumeInfo.TYPE_EMULATED: + if (newState == VolumeInfo.STATE_MOUNTED) { + invalidateMounts(); + } } } }); @@ -178,9 +181,11 @@ public class StorageStatsService extends IStorageStatsManager.Stub { long cacheBytes = 0; final long token = Binder.clearCallingIdentity(); try { - for (UserInfo user : mUser.getUsers()) { - final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null); - cacheBytes += stats.cacheBytes; + if (isQuotaSupported(volumeUuid, callingPackage)) { + for (UserInfo user : mUser.getUsers()) { + final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null); + cacheBytes += stats.cacheBytes; + } } } finally { Binder.restoreCallingIdentity(token); -- cgit v1.2.3-59-g8ed1b