Loading services/core/java/com/android/server/StorageManagerService.java +10 −8 Original line number Diff line number Diff line Loading @@ -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; Loading services/core/java/com/android/server/storage/StorageSessionController.java +22 −6 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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; } } Loading
services/core/java/com/android/server/StorageManagerService.java +10 −8 Original line number Diff line number Diff line Loading @@ -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; Loading
services/core/java/com/android/server/storage/StorageSessionController.java +22 −6 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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; } }