|
35 | 35 | import android.os.UserHandle;
|
36 | 36 | import android.os.UserManager;
|
37 | 37 | import android.os.storage.StorageManager;
|
38 |
| -import android.os.storage.StorageVolume; |
39 | 38 | import android.util.Log;
|
40 | 39 | import android.view.LayoutInflater;
|
41 | 40 | import android.view.View;
|
@@ -64,29 +63,18 @@ public class UninstallAlertDialogFragment extends DialogFragment implements
|
64 | 63 | * @return The number of bytes.
|
65 | 64 | */
|
66 | 65 | private long getAppDataSizeForUser(@NonNull String pkg, @NonNull UserHandle user) {
|
67 |
| - StorageManager storageManager = getContext().getSystemService(StorageManager.class); |
| 66 | + PackageManager packageManager = getContext().getPackageManager(); |
68 | 67 | StorageStatsManager storageStatsManager =
|
69 | 68 | getContext().getSystemService(StorageStatsManager.class);
|
70 | 69 |
|
71 |
| - List<StorageVolume> volumes = storageManager.getStorageVolumes(); |
72 |
| - long appDataSize = 0; |
73 |
| - |
74 |
| - int numVolumes = volumes.size(); |
75 |
| - for (int i = 0; i < numVolumes; i++) { |
76 |
| - StorageStats stats; |
77 |
| - try { |
78 |
| - stats = storageStatsManager.queryStatsForPackage(convert(volumes.get(i).getUuid()), |
79 |
| - pkg, user); |
80 |
| - } catch (PackageManager.NameNotFoundException | IOException e) { |
81 |
| - Log.e(LOG_TAG, "Cannot determine amount of app data for " + pkg + " on " |
82 |
| - + volumes.get(i) + " (user " + user + ")", e); |
83 |
| - continue; |
84 |
| - } |
85 |
| - |
86 |
| - appDataSize += stats.getDataBytes(); |
| 70 | + try { |
| 71 | + ApplicationInfo info = packageManager.getApplicationInfo(pkg, 0); |
| 72 | + return storageStatsManager.queryStatsForPackage( |
| 73 | + info.storageUuid, pkg, user).getDataBytes(); |
| 74 | + } catch (PackageManager.NameNotFoundException | IOException e) { |
| 75 | + Log.e(LOG_TAG, "Cannot determine amount of app data for " + pkg, e); |
| 76 | + return 0; |
87 | 77 | }
|
88 |
| - |
89 |
| - return appDataSize; |
90 | 78 | }
|
91 | 79 |
|
92 | 80 | /**
|
|
0 commit comments