Search in sources :

Example 1 with StorageStatsManager

use of android.app.usage.StorageStatsManager in project android_packages_apps_Settings by LineageOS.

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;
    }
}
Also used : StorageStatsManager(android.app.usage.StorageStatsManager) UserManager(android.os.UserManager) ExternalStorageStats(android.app.usage.ExternalStorageStats) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) UUID(java.util.UUID)

Example 2 with StorageStatsManager

use of android.app.usage.StorageStatsManager in project android_packages_apps_Settings by omnirom.

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;
    }
}
Also used : StorageStatsManager(android.app.usage.StorageStatsManager) UserManager(android.os.UserManager) ExternalStorageStats(android.app.usage.ExternalStorageStats) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) UUID(java.util.UUID)

Example 3 with StorageStatsManager

use of android.app.usage.StorageStatsManager in project android_packages_apps_Settings by crdroidandroid.

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;
    }
}
Also used : StorageStatsManager(android.app.usage.StorageStatsManager) UserManager(android.os.UserManager) ExternalStorageStats(android.app.usage.ExternalStorageStats) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) UUID(java.util.UUID)

Example 4 with StorageStatsManager

use of android.app.usage.StorageStatsManager in project platform_packages_apps_Settings by BlissRoms.

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;
    }
}
Also used : StorageStatsManager(android.app.usage.StorageStatsManager) UserManager(android.os.UserManager) ExternalStorageStats(android.app.usage.ExternalStorageStats) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) UUID(java.util.UUID)

Example 5 with StorageStatsManager

use of android.app.usage.StorageStatsManager in project android_packages_apps_Settings by DirtyUnicorns.

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;
    }
}
Also used : StorageStatsManager(android.app.usage.StorageStatsManager) UserManager(android.os.UserManager) ExternalStorageStats(android.app.usage.ExternalStorageStats) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) UUID(java.util.UUID)

Aggregations

ExternalStorageStats (android.app.usage.ExternalStorageStats)7 StorageStatsManager (android.app.usage.StorageStatsManager)7 UserInfo (android.content.pm.UserInfo)7 UserManager (android.os.UserManager)7 StorageManager (android.os.storage.StorageManager)7 VolumeInfo (android.os.storage.VolumeInfo)7 IOException (java.io.IOException)7 UUID (java.util.UUID)7