From e57620446bfc0c2bdca5e07a0c39f647e07ca18d Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 10 Nov 2021 16:21:25 +0100 Subject: Have getVolumeList() take a userId instead of a UID. getVolumeList() previously accepted a uid and a packagename. This approach has a few issues: 1) The uid wasn't actually checked in the implementation to match the calling UID, nor was the package name checked against the UID in all cases. 2) The implementation assumed that the UID also specificies the userId that we want to get the volumes for. This was historically true, but with the new app cloning implementation, MediaProvider running in user 0 might ask for volumes in the clone user. To fix this, explicitly pass in the userId that we're requesting volumes for, and verify that the calling UID and the passed in package name match. Bug: 206624903 Test: atest packages/providers/MediaProvider Change-Id: Idffbb4ae7740c1b9725af0974948dc55bf1f1fde --- core/java/android/os/storage/IStorageManager.aidl | 4 ++-- core/java/android/os/storage/StorageManager.java | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/os/storage/IStorageManager.aidl b/core/java/android/os/storage/IStorageManager.aidl index fbac954b0a35..bff5c62ed3f1 100644 --- a/core/java/android/os/storage/IStorageManager.aidl +++ b/core/java/android/os/storage/IStorageManager.aidl @@ -90,9 +90,9 @@ interface IStorageManager { */ int changeEncryptionPassword(int type, in String password) = 28; /** - * Returns list of all mountable volumes. + * Returns list of all mountable volumes for the specified userId */ - StorageVolume[] getVolumeList(int uid, in String packageName, int flags) = 29; + StorageVolume[] getVolumeList(int userId, in String callingPackage, int flags) = 29; /** * Determines the encryption state of the volume. * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index 77c794cd17a8..627e09eadd26 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -1391,13 +1391,7 @@ public class StorageManager { } packageName = packageNames[0]; } - final int uid = ActivityThread.getPackageManager().getPackageUid(packageName, - PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); - if (uid <= 0) { - Log.w(TAG, "Missing UID; no storage volumes available"); - return new StorageVolume[0]; - } - return storageManager.getVolumeList(uid, packageName, flags); + return storageManager.getVolumeList(userId, packageName, flags); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } -- cgit v1.2.3