Merge "Skip storage sessions for users without ExternalStorageService"

This commit is contained in:
Robert Horvath
2021-07-12 08:25:16 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 14 deletions

View File

@@ -1541,17 +1541,19 @@ class StorageManagerService extends IStorageManager.Stub
}
if (vol.type == VolumeInfo.TYPE_EMULATED) {
if (!mStorageSessionController.supportsExternalStorage(vol.mountUserId)) {
Slog.d(TAG, "Ignoring volume " + vol.getId() + " because user "
+ Integer.toString(vol.mountUserId)
+ " does not support external storage.");
return;
}
final StorageManager storage = mContext.getSystemService(StorageManager.class);
final VolumeInfo privateVol = storage.findPrivateForEmulated(vol);
if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid)
&& VolumeInfo.ID_PRIVATE_INTERNAL.equals(privateVol.id)) {
Slog.v(TAG, "Found primary storage at " + vol);
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else if (Objects.equals(privateVol.fsUuid, mPrimaryStorageUuid)) {
if ((Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid)
&& VolumeInfo.ID_PRIVATE_INTERNAL.equals(privateVol.id))
|| Objects.equals(privateVol.fsUuid, mPrimaryStorageUuid)) {
Slog.v(TAG, "Found primary storage at " + vol);
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;

View File

@@ -368,16 +368,12 @@ public final class StorageSessionController {
mExternalStorageServicePackageName = provider.applicationInfo.packageName;
mExternalStorageServiceAppId = UserHandle.getAppId(provider.applicationInfo.uid);
Intent intent = new Intent(ExternalStorageService.SERVICE_INTERFACE);
intent.setPackage(mExternalStorageServicePackageName);
ResolveInfo resolveInfo = mContext.getPackageManager().resolveService(intent,
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
if (resolveInfo == null || resolveInfo.serviceInfo == null) {
ServiceInfo serviceInfo = resolveExternalStorageServiceAsUser(UserHandle.USER_SYSTEM);
if (serviceInfo == null) {
throw new ExternalStorageServiceException(
"No valid ExternalStorageService component found");
}
ServiceInfo serviceInfo = resolveInfo.serviceInfo;
ComponentName name = new ComponentName(serviceInfo.packageName, serviceInfo.name);
if (!Manifest.permission.BIND_EXTERNAL_STORAGE_SERVICE
.equals(serviceInfo.permission)) {
@@ -490,4 +486,24 @@ public final class StorageSessionController {
private boolean shouldHandle(@Nullable VolumeInfo vol) {
return !mIsResetting && (vol == null || isSupportedVolume(vol));
}
/**
* Returns {@code true} if the given user supports external storage,
* {@code false} otherwise.
*/
public boolean supportsExternalStorage(int userId) {
return resolveExternalStorageServiceAsUser(userId) != null;
}
private ServiceInfo resolveExternalStorageServiceAsUser(int userId) {
Intent intent = new Intent(ExternalStorageService.SERVICE_INTERFACE);
intent.setPackage(mExternalStorageServicePackageName);
ResolveInfo resolveInfo = mContext.getPackageManager().resolveServiceAsUser(intent,
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId);
if (resolveInfo == null) {
return null;
}
return resolveInfo.serviceInfo;
}
}