Commit 02b613a0 authored by Chirayu Desai's avatar Chirayu Desai

Handle API 29 split-permissions v3

* Re-do the logic completely, and make it much more clearer.
* Also, Read external storage implies access media location
  *ONLY* on apps not targetting API 29 or above, i.e <= 28
parent 881a7e59
......@@ -503,17 +503,6 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
* another permission, for example:
* {@link Manifest.permission#WRITE_EXTERNAL_STORAGE} implies
* {@link Manifest.permission#READ_EXTERNAL_STORAGE}.
* Staring with API 29 / Android 10 / Q,
* Apps targetting API 28 or lower automatically get
* {@link Manifest.permission#ACCESS_BACKGROUND_LOCATION} when they ask for either of
* {@link Manifest.permission#ACCESS_COARSE_LOCATION} or
* {@link Manifest.permission#ACCESS_FINE_LOCATION}.
* Also,
* {@link Manifest.permission#ACCESS_FINE_LOCATION} implies
* {@link Manifest.permission#ACCESS_COARSE_LOCATION}.
* And,
* {@link Manifest.permission#READ_EXTERNAL_STORAGE} implies
* {@link Manifest.permission#ACCESS_MEDIA_LOCATION}
* Many of these rules are for quite old Android versions,
* so they are not included here.
*
......@@ -536,20 +525,27 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
if (Build.VERSION.SDK_INT >= 16 && set.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
set.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (targetSdkVersion <= 28) {
if (Build.VERSION.SDK_INT >= 29 && (set.contains(Manifest.permission.ACCESS_COARSE_LOCATION) ||
set.contains(Manifest.permission.ACCESS_FINE_LOCATION))) {
// TODO: Change the below to Manifest.permission once we target SDK 29.
set.add("android.permission.ACCESS_BACKGROUND_LOCATION");
if (Build.VERSION.SDK_INT >= 29) {
if (set.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
set.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (targetSdkVersion >= 29) {
// Do nothing. The targetSdk for the below split-permissions is set to 29,
// so we don't make any changes for apps targetting 29 or above
} else {
// TODO: Change the strings below to Manifest.permission once we target SDK 29.
if (set.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
set.add("android.permission.ACCESS_BACKGROUND_LOCATION");
}
if (set.contains(Manifest.permission.ACCESS_COARSE_LOCATION)) {
set.add("android.permission.ACCESS_BACKGROUND_LOCATION");
}
if (set.contains(Manifest.permission.READ_EXTERNAL_STORAGE)) {
set.add("android.permission.ACCESS_MEDIA_LOCATION");
}
}
}
if (Build.VERSION.SDK_INT >= 29 && set.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
set.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (Build.VERSION.SDK_INT >= 29 && set.contains(Manifest.permission.READ_EXTERNAL_STORAGE)) {
// TODO: Change the below to Manifest.permission once we target SDK 29.
set.add("android.permission.ACCESS_MEDIA_LOCATION");
}
requestedPermissions = set.toArray(new String[set.size()]);
}
......
......@@ -103,22 +103,25 @@ public class RepoXMLHandler extends DefaultHandler {
requestedPermissionsSet.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
requestedPermissionsSet.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (curapk.targetSdkVersion <= 28) {
if (Build.VERSION.SDK_INT >= 29 &&
(requestedPermissionsSet.contains(Manifest.permission.ACCESS_COARSE_LOCATION) ||
requestedPermissionsSet.contains(Manifest.permission.ACCESS_FINE_LOCATION))) {
// TODO: Change the below to Manifest.permission once we target SDK 29.
requestedPermissionsSet.add("android.permission.ACCESS_BACKGROUND_LOCATION");
if (Build.VERSION.SDK_INT >= 29) {
if (requestedPermissionsSet.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
requestedPermissionsSet.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (curapk.targetSdkVersion >= 29) {
// Do nothing. The targetSdk for the below split-permissions is set to 29,
// so we don't make any changes for apps targetting 29 or above
} else {
// TODO: Change the strings below to Manifest.permission once we target SDK 29.
if (requestedPermissionsSet.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
requestedPermissionsSet.add("android.permission.ACCESS_BACKGROUND_LOCATION");
}
if (requestedPermissionsSet.contains(Manifest.permission.ACCESS_COARSE_LOCATION)) {
requestedPermissionsSet.add("android.permission.ACCESS_BACKGROUND_LOCATION");
}
if (requestedPermissionsSet.contains(Manifest.permission.READ_EXTERNAL_STORAGE)) {
requestedPermissionsSet.add("android.permission.ACCESS_MEDIA_LOCATION");
}
}
}
if (Build.VERSION.SDK_INT >= 29 &&
requestedPermissionsSet.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
requestedPermissionsSet.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (Build.VERSION.SDK_INT >= 29 &&
requestedPermissionsSet.contains(Manifest.permission.READ_EXTERNAL_STORAGE)) {
// TODO: Change the below to Manifest.permission once we target SDK 29.
requestedPermissionsSet.add("android.permission.ACCESS_MEDIA_LOCATION");
}
int size = requestedPermissionsSet.size();
curapk.requestedPermissions = requestedPermissionsSet.toArray(new String[size]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment