Skip to content

Commit 6d687f0

Browse files
committed
PackageInstaller: Fix crash when uninstalling apps with fragile data
* Fixes: - https://gitlab.com/LineageOS/issues/android/-/issues/2298 - https://issuetracker.google.com/issues/148573843 Change-Id: I5a27d6f02d17a52e1a1a2aff4fb46327ce5e6127
1 parent 7d16102 commit 6d687f0

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import android.os.UserHandle;
3636
import android.os.UserManager;
3737
import android.os.storage.StorageManager;
38-
import android.os.storage.StorageVolume;
3938
import android.util.Log;
4039
import android.view.LayoutInflater;
4140
import android.view.View;
@@ -64,29 +63,18 @@ public class UninstallAlertDialogFragment extends DialogFragment implements
6463
* @return The number of bytes.
6564
*/
6665
private long getAppDataSizeForUser(@NonNull String pkg, @NonNull UserHandle user) {
67-
StorageManager storageManager = getContext().getSystemService(StorageManager.class);
66+
PackageManager packageManager = getContext().getPackageManager();
6867
StorageStatsManager storageStatsManager =
6968
getContext().getSystemService(StorageStatsManager.class);
7069

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;
8777
}
88-
89-
return appDataSize;
9078
}
9179

9280
/**

0 commit comments

Comments
 (0)