1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| public void updateUi(Context context) { if (mLastResult == null) { ... } else { long codeSize = mLastResult.getCodeBytes(); long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes() - mLastResult.getCacheBytes(); if (mLastCodeSize != codeSize) { mLastCodeSize = codeSize; mAppSize.setSummary(getSizeStr(context, codeSize)); } if (mLastDataSize != dataSize) { mLastDataSize = dataSize; mDataSize.setSummary(getSizeStr(context, dataSize)); } long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes(); if (mLastCacheSize != cacheSize) { mLastCacheSize = cacheSize; mCacheSize.setSummary(getSizeStr(context, cacheSize)); } long totalSize = codeSize + dataSize + cacheSize; if (mLastTotalSize != totalSize) { mLastTotalSize = totalSize; mTotalSize.setSummary(getSizeStr(context, totalSize)); } } }
updateUiWithSize(mSizeController.getLastResult());
@Override public void onLoadFinished(Loader<AppStorageStats> loader, AppStorageStats result) { mSizeController.setResult(result); updateUiWithSize(result); }
@Override public AppStorageStats loadInBackground() { AppStorageStats result = null; try { result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser); } catch (NameNotFoundException | IOException e) { Log.w(TAG, "Package may have been removed during query, failing gracefully", e); } return result; }
mInfo = packageManager.getApplicationInfo(mPackageName, 0);
public StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage) { ...
final ApplicationInfo appInfo; try { appInfo = mPackage.getApplicationInfoAsUser(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId); }
if (defeatNullable(mPackage.getPackagesForUid(appInfo.uid)).length == 1) { return queryStatsForUid(volumeUuid, appInfo.uid, callingPackage); } else { final int appId = UserHandle.getUserId(appInfo.uid); final String[] packageNames = new String[] { packageName }; final long[] ceDataInodes = new long[1]; String[] codePaths = new String[0];
if (appInfo.isSystemApp() && !appInfo.isUpdatedSystemApp()) { } else { codePaths = ArrayUtils.appendElement(String.class, codePaths, appInfo.getCodePath()); }
final PackageStats stats = new PackageStats(TAG); try { mInstaller.getAppSize(volumeUuid, packageNames, userId, 0, appId, ceDataInodes, codePaths, stats); } return translate(stats); } }
private static StorageStats translate(PackageStats stats) { final StorageStats res = new StorageStats(); res.codeBytes = stats.codeSize + stats.externalCodeSize; res.dataBytes = stats.dataSize + stats.externalDataSize; res.cacheBytes = stats.cacheSize + stats.externalCacheSize; return res; }
|