diff options
| author | 2017-02-23 03:21:42 +0000 | |
|---|---|---|
| committer | 2017-02-23 03:21:47 +0000 | |
| commit | 6f2c1ea250f957b35c76bcc301d3513433de911f (patch) | |
| tree | 0fb9ab8bcdad6fcce6fdf003928265ab767ff6c6 /services/usage/java | |
| parent | 415da7d2458e8b1819a42ebb8729ea6fe240c770 (diff) | |
| parent | 373d01766f27476e81a174727dcfeee406742417 (diff) | |
Merge "Add queryStatsForPackage() API."
Diffstat (limited to 'services/usage/java')
| -rw-r--r-- | services/usage/java/com/android/server/usage/StorageStatsService.java | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/services/usage/java/com/android/server/usage/StorageStatsService.java b/services/usage/java/com/android/server/usage/StorageStatsService.java index 632c045e2111..ed1530a4eddb 100644 --- a/services/usage/java/com/android/server/usage/StorageStatsService.java +++ b/services/usage/java/com/android/server/usage/StorageStatsService.java @@ -30,6 +30,7 @@ import android.content.pm.PackageStats; import android.content.pm.UserInfo; import android.os.Binder; import android.os.Environment; +import android.os.FileUtils; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -148,11 +149,10 @@ public class StorageStatsService extends IStorageStatsManager.Stub { enforcePermission(Binder.getCallingUid(), callingPackage); if (volumeUuid == StorageManager.UUID_PRIVATE_INTERNAL) { - // TODO: round total size to nearest power of two - return mStorage.getPrimaryStorageSize(); + return FileUtils.roundStorageSize(mStorage.getPrimaryStorageSize()); } else { final VolumeInfo vol = mStorage.findVolumeByUuid(volumeUuid); - return vol.disk.size; + return FileUtils.roundStorageSize(vol.disk.size); } } @@ -175,6 +175,43 @@ public class StorageStatsService extends IStorageStatsManager.Stub { } @Override + public StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, + String callingPackage) { + enforcePermission(Binder.getCallingUid(), callingPackage); + if (userId != UserHandle.getCallingUserId()) { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.INTERACT_ACROSS_USERS, TAG); + } + + final ApplicationInfo appInfo; + try { + appInfo = mPackage.getApplicationInfoAsUser(packageName, 0, userId); + } catch (NameNotFoundException e) { + throw new IllegalStateException(e); + } + + if (mPackage.getPackagesForUid(appInfo.uid).length == 1) { + // Only one package inside UID means we can fast-path + return queryStatsForUid(volumeUuid, appInfo.uid, callingPackage); + } else { + // Multiple packages means we need to go manual + final int appId = UserHandle.getUserId(appInfo.uid); + final String[] packageNames = new String[] { packageName }; + final long[] ceDataInodes = new long[1]; + final String[] codePaths = new String[] { appInfo.getCodePath() }; + + final PackageStats stats = new PackageStats(TAG); + try { + mInstaller.getAppSize(volumeUuid, packageNames, userId, 0, + appId, ceDataInodes, codePaths, stats); + } catch (InstallerException e) { + throw new IllegalStateException(e); + } + return translate(stats); + } + } + + @Override public StorageStats queryStatsForUid(String volumeUuid, int uid, String callingPackage) { enforcePermission(Binder.getCallingUid(), callingPackage); if (UserHandle.getUserId(uid) != UserHandle.getCallingUserId()) { |