diff options
author | 2017-02-09 21:33:16 +0000 | |
---|---|---|
committer | 2017-02-09 21:33:19 +0000 | |
commit | b09ac24c3c7097c85609b430aee1b6fe6e8db321 (patch) | |
tree | cf4f33633b33fcea7cc5bc1c74f5389da4d770e3 | |
parent | bc1d0ff0420a287a72fde53d959bd49612b19f2b (diff) | |
parent | 97b383f5a57ed7d384de60c699ca072e6d1d5e95 (diff) |
Merge "Add permission for instant apps creating foreground services"
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | api/system-current.txt | 1 | ||||
-rw-r--r-- | api/test-current.txt | 1 | ||||
-rw-r--r-- | core/java/android/app/AppOpsManager.java | 15 | ||||
-rw-r--r-- | core/res/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | services/core/java/com/android/server/am/ActiveServices.java | 33 |
6 files changed, 54 insertions, 1 deletions
diff --git a/api/current.txt b/api/current.txt index 96b96dbdaecd..6d9027a31eba 100644 --- a/api/current.txt +++ b/api/current.txt @@ -79,6 +79,7 @@ package android { field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER"; field public static final java.lang.String INSTALL_PACKAGES = "android.permission.INSTALL_PACKAGES"; field public static final java.lang.String INSTALL_SHORTCUT = "com.android.launcher.permission.INSTALL_SHORTCUT"; + field public static final java.lang.String INSTANT_APP_FOREGROUND_SERVICE = "android.permission.INSTANT_APP_FOREGROUND_SERVICE"; field public static final java.lang.String INTERNET = "android.permission.INTERNET"; field public static final java.lang.String KILL_BACKGROUND_PROCESSES = "android.permission.KILL_BACKGROUND_PROCESSES"; field public static final java.lang.String LOCATION_HARDWARE = "android.permission.LOCATION_HARDWARE"; diff --git a/api/system-current.txt b/api/system-current.txt index 3a58bf4c8d7a..7341424628f8 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -121,6 +121,7 @@ package android { field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER"; field public static final java.lang.String INSTALL_PACKAGES = "android.permission.INSTALL_PACKAGES"; field public static final java.lang.String INSTALL_SHORTCUT = "com.android.launcher.permission.INSTALL_SHORTCUT"; + field public static final java.lang.String INSTANT_APP_FOREGROUND_SERVICE = "android.permission.INSTANT_APP_FOREGROUND_SERVICE"; field public static final java.lang.String INTENT_FILTER_VERIFICATION_AGENT = "android.permission.INTENT_FILTER_VERIFICATION_AGENT"; field public static final java.lang.String INTERACT_ACROSS_USERS = "android.permission.INTERACT_ACROSS_USERS"; field public static final java.lang.String INTERACT_ACROSS_USERS_FULL = "android.permission.INTERACT_ACROSS_USERS_FULL"; diff --git a/api/test-current.txt b/api/test-current.txt index 36f5835188b3..4988ab3747a5 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -79,6 +79,7 @@ package android { field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER"; field public static final java.lang.String INSTALL_PACKAGES = "android.permission.INSTALL_PACKAGES"; field public static final java.lang.String INSTALL_SHORTCUT = "com.android.launcher.permission.INSTALL_SHORTCUT"; + field public static final java.lang.String INSTANT_APP_FOREGROUND_SERVICE = "android.permission.INSTANT_APP_FOREGROUND_SERVICE"; field public static final java.lang.String INTERNET = "android.permission.INTERNET"; field public static final java.lang.String KILL_BACKGROUND_PROCESSES = "android.permission.KILL_BACKGROUND_PROCESSES"; field public static final java.lang.String LOCATION_HARDWARE = "android.permission.LOCATION_HARDWARE"; diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 603126b3badd..fb927e96d1f5 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -247,8 +247,10 @@ public class AppOpsManager { public static final int OP_REQUEST_INSTALL_PACKAGES = 66; /** @hide Enter picture-in-picture when hidden. */ public static final int OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE = 67; + /** @hide Instant app start foreground service. */ + public static final int OP_INSTANT_APP_START_FOREGROUND = 68; /** @hide */ - public static final int _NUM_OP = 68; + public static final int _NUM_OP = 69; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -351,6 +353,9 @@ public class AppOpsManager { = "android:get_accounts"; public static final String OPSTR_READ_PHONE_NUMBER = "android:read_phone_number"; + /** @hide */ + public static final String OPSTR_INSTANT_APP_START_FOREGROUND + = "android:instant_app_start_foreground"; private static final int[] RUNTIME_PERMISSIONS_OPS = { // Contacts @@ -467,6 +472,7 @@ public class AppOpsManager { OP_READ_PHONE_NUMBER, OP_REQUEST_INSTALL_PACKAGES, OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE, + OP_INSTANT_APP_START_FOREGROUND, }; /** @@ -542,6 +548,7 @@ public class AppOpsManager { OPSTR_READ_PHONE_NUMBER, null, // OP_REQUEST_INSTALL_PACKAGES null, + OPSTR_INSTANT_APP_START_FOREGROUND, }; /** @@ -617,6 +624,7 @@ public class AppOpsManager { "READ_PHONE_NUMBER", "REQUEST_INSTALL_PACKAGES", "OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE", + "INSTANT_APP_START_FOREGROUND", }; /** @@ -692,6 +700,7 @@ public class AppOpsManager { Manifest.permission.READ_PHONE_NUMBER, Manifest.permission.REQUEST_INSTALL_PACKAGES, null, // no permission for entering picture-in-picture on hide + Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, }; /** @@ -768,6 +777,7 @@ public class AppOpsManager { null, // READ_PHONE_NUMBER null, // REQUEST_INSTALL_PACKAGES null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE + null, // INSTANT_APP_START_FOREGROUND }; /** @@ -843,6 +853,7 @@ public class AppOpsManager { false, // READ_PHONE_NUMBER false, // REQUEST_INSTALL_PACKAGES false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE + false, // INSTANT_APP_START_FOREGROUND }; /** @@ -917,6 +928,7 @@ public class AppOpsManager { AppOpsManager.MODE_ALLOWED, AppOpsManager.MODE_DEFAULT, // OP_REQUEST_INSTALL_PACKAGES AppOpsManager.MODE_ALLOWED, // OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE + AppOpsManager.MODE_DEFAULT, // OP_INSTANT_APP_START_FOREGROUND }; /** @@ -995,6 +1007,7 @@ public class AppOpsManager { false, false, // OP_REQUEST_INSTALL_PACKAGES false, // OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE + false, }; /** diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 7b800b363e65..5b5e61e6ebdc 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -3252,6 +3252,10 @@ <permission android:name="android.permission.MODIFY_THEME_OVERLAY" android:protectionLevel="signature" /> + <!-- Allows an instant app to create foreground services. --> + <permission android:name="android.permission.INSTANT_APP_FOREGROUND_SERVICE" + android:protectionLevel="signature|development|ephemeral|appop" /> + <application android:process="system" android:persistent="true" android:hasCode="false" diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 041fee2352e3..793a163300bd 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -723,6 +723,39 @@ public final class ActiveServices { if (notification == null) { throw new IllegalArgumentException("null notification"); } + // Instant apps need permission to create foreground services. + if (r.appInfo.isInstantApp()) { + final int mode = mAm.mAppOpsService.checkOperation( + AppOpsManager.OP_INSTANT_APP_START_FOREGROUND, + r.appInfo.uid, + r.appInfo.packageName); + switch (mode) { + case AppOpsManager.MODE_ALLOWED: + break; + case AppOpsManager.MODE_IGNORED: + Slog.w(TAG, "Instant app " + r.appInfo.packageName + + " does not have permission to create foreground services" + + ", ignoring."); + return; + case AppOpsManager.MODE_ERRORED: + throw new SecurityException("Instant app " + r.appInfo.packageName + + " does not have permission to create foreground services"); + default: + try { + if (AppGlobals.getPackageManager().checkPermission( + android.Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, + r.appInfo.packageName, + r.appInfo.uid) != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Instant app " + r.appInfo.packageName + + " does not have permission to create foreground" + + "services"); + } + } catch (RemoteException e) { + throw new SecurityException("Failed to check instant app permission." , + e); + } + } + } if (r.foregroundId != id) { cancelForegroudNotificationLocked(r); r.foregroundId = id; |