Skip to content

Commit e217ee4

Browse files
committed
Access to all users' external storage.
System services holding this permission have external storage bound one level higher, giving them access to all users' files. Bug: 7003520 Change-Id: Ib2bcb8455740c713ebd01f71c9a2b89b4e642832
1 parent 08db9df commit e217ee4

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

core/java/android/os/Process.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ private static ProcessStartResult startViaZygote(final String processClass,
584584
}
585585
if (mountExternal == Zygote.MOUNT_EXTERNAL_MULTIUSER) {
586586
argsForZygote.add("--mount-external-multiuser");
587+
} else if (mountExternal == Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL) {
588+
argsForZygote.add("--mount-external-multiuser-all");
587589
}
588590
argsForZygote.add("--target-sdk-version=" + targetSdkVersion);
589591

core/java/com/android/internal/os/ZygoteConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ private void parseArgs(String args[])
529529
niceName = arg.substring(arg.indexOf('=') + 1);
530530
} else if (arg.equals("--mount-external-multiuser")) {
531531
mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER;
532+
} else if (arg.equals("--mount-external-multiuser-all")) {
533+
mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL;
532534
} else {
533535
break;
534536
}

core/res/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,13 @@
725725
android:description="@string/permdesc_mediaStorageWrite"
726726
android:protectionLevel="signature|system" />
727727

728+
<!-- Allows an application to access all multi-user external storage @hide -->
729+
<permission android:name="android.permission.ACCESS_ALL_EXTERNAL_STORAGE"
730+
android:permissionGroup="android.permission-group.DEVELOPMENT_TOOLS"
731+
android:label="@string/permlab_sdcardAccessAll"
732+
android:description="@string/permdesc_sdcardAccessAll"
733+
android:protectionLevel="signature" />
734+
728735
<!-- ============================================ -->
729736
<!-- Permissions for low-level system interaction -->
730737
<!-- ============================================ -->

core/res/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,11 @@
16161616
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=NONE] -->
16171617
<string name="permdesc_mediaStorageWrite" product="default">Allows the app to modify the contents of the internal media storage.</string>
16181618

1619+
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=30] -->
1620+
<string name="permlab_sdcardAccessAll">access external storage of all users</string>
1621+
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
1622+
<string name="permdesc_sdcardAccessAll">Allows the app to access external storage for all users.</string>
1623+
16191624
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
16201625
<string name="permlab_cache_filesystem">access the cache filesystem</string>
16211626
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,13 +1991,19 @@ private final void startProcessLocked(ProcessRecord app,
19911991
try {
19921992
final PackageManager pm = mContext.getPackageManager();
19931993
gids = pm.getPackageGids(app.info.packageName);
1994+
1995+
if (Environment.isExternalStorageEmulated()) {
1996+
if (pm.checkPermission(
1997+
android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
1998+
app.info.packageName) == PERMISSION_GRANTED) {
1999+
mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL;
2000+
} else {
2001+
mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER;
2002+
}
2003+
}
19942004
} catch (PackageManager.NameNotFoundException e) {
19952005
Slog.w(TAG, "Unable to retrieve gids", e);
19962006
}
1997-
1998-
if (Environment.isExternalStorageEmulated()) {
1999-
mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER;
2000-
}
20012007
}
20022008
if (mFactoryTest != SystemServer.FACTORY_TEST_OFF) {
20032009
if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL

0 commit comments

Comments
 (0)