Change setPrimaryStorageUuid to handle it for the current user
- It used hard coded user 0 and that breaks it for
secondary users. Current user should be enough if this move is
triggered from settings which is run from the current user.
- For device with no user switching from user 0, this should
not make any differences.
- This change also fixes failure of CTS
android.appsecurity.cts.AdoptableHostTest#testPrimaryStorage.
- In longer term, we need separate setPrimaryStorageUuidAsUser API
to control it per each user.
Bug: 174593750
Test: atest android.appsecurity.cts.AdoptableHostTest#testPrimaryStorage
Change-Id: I87c821903987d22e8d26ade92120b99a33897168
Merged-In: I87c821903987d22e8d26ade92120b99a33897168
(cherry picked from commit 9aa55f0168)
This commit is contained in:
committed by
Keun-young Park
parent
34b2197e34
commit
1c0e5ce8cf
@@ -48,6 +48,7 @@ import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.UserIdInt;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityManagerInternal;
|
import android.app.ActivityManagerInternal;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
@@ -482,14 +483,21 @@ class StorageManagerService extends IStorageManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable VolumeInfo findStorageForUuid(String volumeUuid) {
|
private @Nullable VolumeInfo findStorageForUuidAsUser(String volumeUuid,
|
||||||
|
@UserIdInt int userId) {
|
||||||
final StorageManager storage = mContext.getSystemService(StorageManager.class);
|
final StorageManager storage = mContext.getSystemService(StorageManager.class);
|
||||||
if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) {
|
if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) {
|
||||||
return storage.findVolumeById(VolumeInfo.ID_EMULATED_INTERNAL + ";" + 0);
|
return storage.findVolumeById(VolumeInfo.ID_EMULATED_INTERNAL + ";" + userId);
|
||||||
} else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) {
|
} else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) {
|
||||||
return storage.getPrimaryPhysicalVolume();
|
return storage.getPrimaryPhysicalVolume();
|
||||||
} else {
|
} else {
|
||||||
return storage.findEmulatedForPrivate(storage.findVolumeByUuid(volumeUuid));
|
VolumeInfo info = storage.findVolumeByUuid(volumeUuid);
|
||||||
|
if (info == null) {
|
||||||
|
Slog.w(TAG, "findStorageForUuidAsUser cannot find volumeUuid:" + volumeUuid);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String emulatedUuid = info.getId().replace("private", "emulated") + ";" + userId;
|
||||||
|
return storage.findVolumeById(emulatedUuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2605,8 +2613,9 @@ class StorageManagerService extends IStorageManager.Stub
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
from = findStorageForUuid(mPrimaryStorageUuid);
|
int currentUserId = mCurrentUserId;
|
||||||
to = findStorageForUuid(volumeUuid);
|
from = findStorageForUuidAsUser(mPrimaryStorageUuid, currentUserId);
|
||||||
|
to = findStorageForUuidAsUser(volumeUuid, currentUserId);
|
||||||
|
|
||||||
if (from == null) {
|
if (from == null) {
|
||||||
Slog.w(TAG, "Failing move due to missing from volume " + mPrimaryStorageUuid);
|
Slog.w(TAG, "Failing move due to missing from volume " + mPrimaryStorageUuid);
|
||||||
|
|||||||
Reference in New Issue
Block a user