use of android.app.usage.StorageStatsManager in project android_packages_apps_Settings by SudaMod.
the class MigrateEstimateTask method doInBackground.
@Override
protected Long doInBackground(Void... params) {
if (mSizeBytes != -1) {
return mSizeBytes;
}
final UserManager user = mContext.getSystemService(UserManager.class);
final StorageManager storage = mContext.getSystemService(StorageManager.class);
final StorageStatsManager stats = mContext.getSystemService(StorageStatsManager.class);
final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume();
final VolumeInfo emulatedVol = storage.findEmulatedForPrivate(privateVol);
if (emulatedVol == null) {
Log.w(TAG, "Failed to find current primary storage");
return -1L;
}
try {
final UUID emulatedUuid = storage.getUuidForPath(emulatedVol.getPath());
Log.d(TAG, "Measuring size of " + emulatedUuid);
long size = 0;
for (UserInfo u : user.getUsers()) {
final ExternalStorageStats s = stats.queryExternalStatsForUser(emulatedUuid, UserHandle.of(u.id));
size += s.getTotalBytes();
if (u.id == UserHandle.USER_SYSTEM) {
size += s.getObbBytes();
}
}
return size;
} catch (IOException e) {
Log.w(TAG, "Failed to measure", e);
return -1L;
}
}
use of android.app.usage.StorageStatsManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MigrateEstimateTask method doInBackground.
@Override
protected Long doInBackground(Void... params) {
if (mSizeBytes != -1) {
return mSizeBytes;
}
final UserManager user = mContext.getSystemService(UserManager.class);
final StorageManager storage = mContext.getSystemService(StorageManager.class);
final StorageStatsManager stats = mContext.getSystemService(StorageStatsManager.class);
final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume();
final VolumeInfo emulatedVol = storage.findEmulatedForPrivate(privateVol);
if (emulatedVol == null) {
Log.w(TAG, "Failed to find current primary storage");
return -1L;
}
try {
final UUID emulatedUuid = storage.getUuidForPath(emulatedVol.getPath());
Log.d(TAG, "Measuring size of " + emulatedUuid);
long size = 0;
for (UserInfo u : user.getUsers()) {
final ExternalStorageStats s = stats.queryExternalStatsForUser(emulatedUuid, UserHandle.of(u.id));
size += s.getTotalBytes();
if (u.id == UserHandle.USER_SYSTEM) {
size += s.getObbBytes();
}
}
return size;
} catch (IOException e) {
Log.w(TAG, "Failed to measure", e);
return -1L;
}
}
Aggregations