Skip to content

Commit 31b0e0e

Browse files
author
Dianne Hackborn
committed
Implement call log permission compatibility.
If a pre-JellyBean application requests read/write contacts, it will implicitly be given read/write call log. Change-Id: I029db4b09fda737bb8fba4e1611355ebdbbfd34f
1 parent 9828830 commit 31b0e0e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
9494
public static class SplitPermissionInfo {
9595
public final String rootPerm;
9696
public final String[] newPerms;
97+
public final int targetSdk;
9798

98-
public SplitPermissionInfo(String rootPerm, String[] newPerms) {
99+
public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
99100
this.rootPerm = rootPerm;
100101
this.newPerms = newPerms;
102+
this.targetSdk = targetSdk;
101103
}
102104
}
103105

@@ -126,7 +128,14 @@ public SplitPermissionInfo(String rootPerm, String[] newPerms) {
126128
public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
127129
new PackageParser.SplitPermissionInfo[] {
128130
new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
129-
new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE })
131+
new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
132+
android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
133+
new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
134+
new String[] { android.Manifest.permission.READ_CALL_LOG },
135+
android.os.Build.VERSION_CODES.JELLY_BEAN),
136+
new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
137+
new String[] { android.Manifest.permission.WRITE_CALL_LOG },
138+
android.os.Build.VERSION_CODES.JELLY_BEAN)
130139
};
131140

132141
private String mArchiveSourcePath;
@@ -1293,7 +1302,8 @@ private Package parsePackage(
12931302
for (int is=0; is<NS; is++) {
12941303
final PackageParser.SplitPermissionInfo spi
12951304
= PackageParser.SPLIT_PERMISSIONS[is];
1296-
if (!pkg.requestedPermissions.contains(spi.rootPerm)) {
1305+
if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1306+
|| !pkg.requestedPermissions.contains(spi.rootPerm)) {
12971307
break;
12981308
}
12991309
for (int in=0; in<spi.newPerms.length; in++) {

tools/aapt/Command.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ int doDump(Bundle* bundle)
639639
// If an app requests write storage, they will also get read storage.
640640
bool hasReadExternalStoragePermission = false;
641641

642+
// Implement transition to read and write call log.
643+
bool hasReadContactsPermission = false;
644+
bool hasWriteContactsPermission = false;
645+
bool hasReadCallLogPermission = false;
646+
bool hasWriteCallLogPermission = false;
647+
642648
// This next group of variables is used to implement a group of
643649
// backward-compatibility heuristics necessitated by the addition of
644650
// some new uses-feature constants in 2.1 and 2.2. In most cases, the
@@ -1006,6 +1012,14 @@ int doDump(Bundle* bundle)
10061012
hasReadExternalStoragePermission = true;
10071013
} else if (name == "android.permission.READ_PHONE_STATE") {
10081014
hasReadPhoneStatePermission = true;
1015+
} else if (name == "android.permission.READ_CONTACTS") {
1016+
hasReadContactsPermission = true;
1017+
} else if (name == "android.permission.WRITE_CONTACTS") {
1018+
hasWriteContactsPermission = true;
1019+
} else if (name == "android.permission.READ_CALL_LOG") {
1020+
hasReadCallLogPermission = true;
1021+
} else if (name == "android.permission.WRITE_CALL_LOG") {
1022+
hasWriteCallLogPermission = true;
10091023
}
10101024
printf("uses-permission:'%s'\n", name.string());
10111025
} else {
@@ -1181,6 +1195,16 @@ int doDump(Bundle* bundle)
11811195
printf("uses-permission:'android.permission.READ_EXTERNAL_STORAGE'\n");
11821196
}
11831197

1198+
// Pre-JellyBean call log permission compatibility.
1199+
if (targetSdk < 16) {
1200+
if (!hasReadCallLogPermission && hasReadContactsPermission) {
1201+
printf("uses-permission:'android.permission.READ_CALL_LOG'\n");
1202+
}
1203+
if (!hasWriteCallLogPermission && hasWriteContactsPermission) {
1204+
printf("uses-permission:'android.permission.WRITE_CALL_LOG'\n");
1205+
}
1206+
}
1207+
11841208
/* The following blocks handle printing "inferred" uses-features, based
11851209
* on whether related features or permissions are used by the app.
11861210
* Note that the various spec*Feature variables denote whether the

0 commit comments

Comments
 (0)