Skip to content

Commit 7924512

Browse files
author
Dianne Hackborn
committed
Add new READ_EXTERNAL_STORAGE permission.
Also adds some initial compatibility code for dealing with it. Change-Id: I104bff11798349e4aaa6da9b7be787b257daa1bb
1 parent 05f692e commit 7924512

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ package android {
7676
field public static final java.lang.String PROCESS_OUTGOING_CALLS = "android.permission.PROCESS_OUTGOING_CALLS";
7777
field public static final java.lang.String READ_CALENDAR = "android.permission.READ_CALENDAR";
7878
field public static final java.lang.String READ_CONTACTS = "android.permission.READ_CONTACTS";
79+
field public static final java.lang.String READ_EXTERNAL_STORAGE = "android.permission.READ_EXTERNAL_STORAGE";
7980
field public static final java.lang.String READ_FRAME_BUFFER = "android.permission.READ_FRAME_BUFFER";
8081
field public static final java.lang.String READ_HISTORY_BOOKMARKS = "com.android.browser.permission.READ_HISTORY_BOOKMARKS";
8182
field public static final java.lang.String READ_INPUT_STATE = "android.permission.READ_INPUT_STATE";

core/java/android/content/pm/PackageParser.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,25 @@ public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
8989
this.fileVersion = fileVersion;
9090
}
9191
}
92-
92+
93+
/** @hide */
94+
public static class SplitPermissionInfo {
95+
public final String rootPerm;
96+
public final String[] newPerms;
97+
98+
public SplitPermissionInfo(String rootPerm, String[] newPerms) {
99+
this.rootPerm = rootPerm;
100+
this.newPerms = newPerms;
101+
}
102+
}
103+
93104
/**
94105
* List of new permissions that have been added since 1.0.
95106
* NOTE: These must be declared in SDK version order, with permissions
96107
* added to older SDKs appearing before those added to newer SDKs.
108+
* If sdkVersion is 0, then this is not a permission that we want to
109+
* automatically add to older apps, but we do want to allow it to be
110+
* granted during a platform update.
97111
* @hide
98112
*/
99113
public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
@@ -104,6 +118,17 @@ public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
104118
android.os.Build.VERSION_CODES.DONUT, 0)
105119
};
106120

121+
/**
122+
* List of permissions that have been split into more granular or dependent
123+
* permissions.
124+
* @hide
125+
*/
126+
public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
127+
new PackageParser.SplitPermissionInfo[] {
128+
new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
129+
new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE })
130+
};
131+
107132
private String mArchiveSourcePath;
108133
private String[] mSeparateProcesses;
109134
private boolean mOnlyCoreApps;
@@ -1245,7 +1270,23 @@ private Package parsePackage(
12451270
if (implicitPerms != null) {
12461271
Slog.i(TAG, implicitPerms.toString());
12471272
}
1248-
1273+
1274+
final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1275+
for (int is=0; is<NS; is++) {
1276+
final PackageParser.SplitPermissionInfo spi
1277+
= PackageParser.SPLIT_PERMISSIONS[is];
1278+
if (!pkg.requestedPermissions.contains(spi.rootPerm)) {
1279+
break;
1280+
}
1281+
for (int in=0; in<spi.newPerms.length; in++) {
1282+
final String perm = spi.newPerms[in];
1283+
if (!pkg.requestedPermissions.contains(perm)) {
1284+
pkg.requestedPermissions.add(perm);
1285+
pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1286+
}
1287+
}
1288+
}
1289+
12491290
if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
12501291
&& pkg.applicationInfo.targetSdkVersion
12511292
>= android.os.Build.VERSION_CODES.DONUT)) {

core/res/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@
639639
android:label="@string/permgrouplab_storage"
640640
android:description="@string/permgroupdesc_storage" />
641641

642+
<!-- Allows an application to read from external storage -->
643+
<permission android:name="android.permission.READ_EXTERNAL_STORAGE"
644+
android:permissionGroup="android.permission-group.STORAGE"
645+
android:label="@string/permlab_sdcardRead"
646+
android:description="@string/permdesc_sdcardRead"
647+
android:protectionLevel="dangerous" />
648+
642649
<!-- Allows an application to write to external storage -->
643650
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
644651
android:permissionGroup="android.permission-group.STORAGE"

core/res/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,15 @@
14281428
<string name="permdesc_writeDictionary">Allows the app to write new words into the
14291429
user dictionary.</string>
14301430

1431+
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=30] -->
1432+
<string name="permlab_sdcardRead" product="nosdcard">read USB storage contents</string>
1433+
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
1434+
<string name="permlab_sdcardRead" product="default">read SD card contents</string>
1435+
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=30] -->
1436+
<string name="permdesc_sdcardRead" product="nosdcard">Allows the app to read contents of USB storage.</string>
1437+
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
1438+
<string name="permdesc_sdcardRead" product="default">Allows the app to read contents of SD card.</string>
1439+
14311440
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=30] -->
14321441
<string name="permlab_sdcardWrite" product="nosdcard">modify/delete USB storage contents</string>
14331442
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->

data/etc/platform.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<group gid="log" />
5555
</permission>
5656

57+
<permission name="android.permission.READ_EXTERNAL_STORAGE" >
58+
<group gid="sdcard_r" />
59+
</permission>
60+
5761
<permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
5862
<group gid="sdcard_rw" />
5963
</permission>

tools/aapt/Command.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ int doDump(Bundle* bundle)
636636
bool hasWriteExternalStoragePermission = false;
637637
bool hasReadPhoneStatePermission = false;
638638

639+
// If an app requests write storage, they will also get read storage.
640+
bool hasReadExternalStoragePermission = false;
641+
639642
// This next group of variables is used to implement a group of
640643
// backward-compatibility heuristics necessitated by the addition of
641644
// some new uses-feature constants in 2.1 and 2.2. In most cases, the
@@ -999,6 +1002,8 @@ int doDump(Bundle* bundle)
9991002
hasTelephonyPermission = true;
10001003
} else if (name == "android.permission.WRITE_EXTERNAL_STORAGE") {
10011004
hasWriteExternalStoragePermission = true;
1005+
} else if (name == "android.permission.READ_EXTERNAL_STORAGE") {
1006+
hasReadExternalStoragePermission = true;
10021007
} else if (name == "android.permission.READ_PHONE_STATE") {
10031008
hasReadPhoneStatePermission = true;
10041009
}
@@ -1163,12 +1168,19 @@ int doDump(Bundle* bundle)
11631168
if (targetSdk < 4) {
11641169
if (!hasWriteExternalStoragePermission) {
11651170
printf("uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'\n");
1171+
hasWriteExternalStoragePermission = true;
11661172
}
11671173
if (!hasReadPhoneStatePermission) {
11681174
printf("uses-permission:'android.permission.READ_PHONE_STATE'\n");
11691175
}
11701176
}
11711177

1178+
// If the application has requested WRITE_EXTERNAL_STORAGE, we will
1179+
// force them to always take READ_EXTERNAL_STORAGE as well.
1180+
if (!hasReadExternalStoragePermission && hasWriteExternalStoragePermission) {
1181+
printf("uses-permission:'android.permission.READ_EXTERNAL_STORAGE'\n");
1182+
}
1183+
11721184
/* The following blocks handle printing "inferred" uses-features, based
11731185
* on whether related features or permissions are used by the app.
11741186
* Note that the various spec*Feature variables denote whether the

0 commit comments

Comments
 (0)