diff options
| author | 2016-11-29 17:46:28 +0000 | |
|---|---|---|
| committer | 2016-11-29 17:46:32 +0000 | |
| commit | 6fc01e0483969c29470fc94045302be19a1c3ceb (patch) | |
| tree | db992d0dcd62d6aff64d87985c339e0074600aeb | |
| parent | 0884abb8ffbda8542585c3977dae5088155622ff (diff) | |
| parent | 0d8f4b75a5f41a3455a28839f0cff481bb6be53f (diff) | |
Merge "Create actions for permission and log revokations"
| -rw-r--r-- | proto/src/metrics_constants.proto | 416 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageManagerService.java | 98 |
2 files changed, 514 insertions, 0 deletions
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index 45f2ec76588a..fc8c67507bf5 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -2659,6 +2659,422 @@ message MetricsEvent { // OS: O TEXT_LONGPRESS = 629; + // ACTION: An app requested an unknown permission + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_UNKNOWN = 630; + + // ACTION: An app was granted an unknown permission + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_UNKNOWN = 631; + + // ACTION: An app requested an unknown permission and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_UNKNOWN = 632; + + // ACTION: An unknown permission was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_UNKNOWN = 633; + + // ACTION: An app requested the permission READ_CALENDAR + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_CALENDAR = 634; + + // ACTION: An app was granted the permission READ_CALENDAR + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_CALENDAR = 635; + + // ACTION: An app requested the permission READ_CALENDAR and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_CALENDAR = 636; + + // ACTION: The permission READ_CALENDAR was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_CALENDAR = 637; + + // ACTION: An app requested the permission WRITE_CALENDAR + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_WRITE_CALENDAR = 638; + + // ACTION: An app was granted the permission WRITE_CALENDAR + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_WRITE_CALENDAR = 639; + + // ACTION: An app requested the permission WRITE_CALENDAR and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_WRITE_CALENDAR = 640; + + // ACTION: The permission WRITE_CALENDAR was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_WRITE_CALENDAR = 641; + + // ACTION: An app requested the permission CAMERA + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_CAMERA = 642; + + // ACTION: An app was granted the permission CAMERA + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_CAMERA = 643; + + // ACTION: An app requested the permission CAMERA and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_CAMERA = 644; + + // ACTION: The permission CAMERA was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_CAMERA = 645; + + // ACTION: An app requested the permission READ_CONTACTS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_CONTACTS = 646; + + // ACTION: An app was granted the permission READ_CONTACTS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_CONTACTS = 647; + + // ACTION: An app requested the permission READ_CONTACTS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_CONTACTS = 648; + + // ACTION: The permission READ_CONTACTS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_CONTACTS = 649; + + // ACTION: An app requested the permission WRITE_CONTACTS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_WRITE_CONTACTS = 650; + + // ACTION: An app was granted the permission WRITE_CONTACTS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_WRITE_CONTACTS = 651; + + // ACTION: An app requested the permission WRITE_CONTACTS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_WRITE_CONTACTS = 652; + + // ACTION: The permission WRITE_CONTACTS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_WRITE_CONTACTS = 653; + + // ACTION: An app requested the permission GET_ACCOUNTS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_GET_ACCOUNTS = 654; + + // ACTION: An app was granted the permission GET_ACCOUNTS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_GET_ACCOUNTS = 655; + + // ACTION: An app requested the permission GET_ACCOUNTS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_GET_ACCOUNTS = 656; + + // ACTION: The permission GET_ACCOUNTS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_GET_ACCOUNTS = 657; + + // ACTION: An app requested the permission ACCESS_FINE_LOCATION + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 658; + + // ACTION: An app was granted the permission ACCESS_FINE_LOCATION + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_ACCESS_FINE_LOCATION = 659; + + // ACTION: An app requested the permission ACCESS_FINE_LOCATION and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_ACCESS_FINE_LOCATION = 660; + + // ACTION: The permission ACCESS_FINE_LOCATION was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_ACCESS_FINE_LOCATION = 661; + + // ACTION: An app requested the permission ACCESS_COARSE_LOCATION + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_ACCESS_COARSE_LOCATION = 662; + + // ACTION: An app was granted the permission ACCESS_COARSE_LOCATION + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_ACCESS_COARSE_LOCATION = 663; + + // ACTION: An app requested the permission ACCESS_COARSE_LOCATION and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_ACCESS_COARSE_LOCATION = 664; + + // ACTION: The permission ACCESS_COARSE_LOCATION was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_ACCESS_COARSE_LOCATION = 665; + + // ACTION: An app requested the permission RECORD_AUDIO + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_RECORD_AUDIO = 666; + + // ACTION: An app was granted the permission RECORD_AUDIO + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_RECORD_AUDIO = 667; + + // ACTION: An app requested the permission RECORD_AUDIO and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_RECORD_AUDIO = 668; + + // ACTION: The permission RECORD_AUDIO was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_RECORD_AUDIO = 669; + + // ACTION: An app requested the permission READ_PHONE_STATE + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_PHONE_STATE = 670; + + // ACTION: An app was granted the permission READ_PHONE_STATE + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_PHONE_STATE = 671; + + // ACTION: An app requested the permission READ_PHONE_STATE and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_PHONE_STATE = 672; + + // ACTION: The permission READ_PHONE_STATE was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_PHONE_STATE = 673; + + // ACTION: An app requested the permission CALL_PHONE + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_CALL_PHONE = 674; + + // ACTION: An app was granted the permission CALL_PHONE + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_CALL_PHONE = 675; + + // ACTION: An app requested the permission CALL_PHONE and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_CALL_PHONE = 676; + + // ACTION: The permission CALL_PHONE was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_CALL_PHONE = 677; + + // ACTION: An app requested the permission READ_CALL_LOG + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_CALL_LOG = 678; + + // ACTION: An app was granted the permission READ_CALL_LOG + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_CALL_LOG = 679; + + // ACTION: An app requested the permission READ_CALL_LOG and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_CALL_LOG = 680; + + // ACTION: The permission READ_CALL_LOG was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_CALL_LOG = 681; + + // ACTION: An app requested the permission WRITE_CALL_LOG + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_WRITE_CALL_LOG = 682; + + // ACTION: An app was granted the permission WRITE_CALL_LOG + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_WRITE_CALL_LOG = 683; + + // ACTION: An app requested the permission WRITE_CALL_LOG and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_WRITE_CALL_LOG = 684; + + // ACTION: The permission WRITE_CALL_LOG was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_WRITE_CALL_LOG = 685; + + // ACTION: An app requested the permission ADD_VOICEMAIL + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_ADD_VOICEMAIL = 686; + + // ACTION: An app was granted the permission ADD_VOICEMAIL + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_ADD_VOICEMAIL = 687; + + // ACTION: An app requested the permission ADD_VOICEMAIL and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_ADD_VOICEMAIL = 688; + + // ACTION: The permission ADD_VOICEMAIL was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_ADD_VOICEMAIL = 689; + + // ACTION: An app requested the permission USE_SIP + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_USE_SIP = 690; + + // ACTION: An app was granted the permission USE_SIP + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_USE_SIP = 691; + + // ACTION: An app requested the permission USE_SIP and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_USE_SIP = 692; + + // ACTION: The permission USE_SIP was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_USE_SIP = 693; + + // ACTION: An app requested the permission PROCESS_OUTGOING_CALLS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_PROCESS_OUTGOING_CALLS = 694; + + // ACTION: An app was granted the permission PROCESS_OUTGOING_CALLS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_PROCESS_OUTGOING_CALLS = 695; + + // ACTION: An app requested the permission PROCESS_OUTGOING_CALLS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_PROCESS_OUTGOING_CALLS = 696; + + // ACTION: The permission PROCESS_OUTGOING_CALLS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_PROCESS_OUTGOING_CALLS = 697; + + // ACTION: An app requested the permission READ_CELL_BROADCASTS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_CELL_BROADCASTS = 698; + + // ACTION: An app was granted the permission READ_CELL_BROADCASTS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_CELL_BROADCASTS = 699; + + // ACTION: An app requested the permission READ_CELL_BROADCASTS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_CELL_BROADCASTS = 700; + + // ACTION: The permission READ_CELL_BROADCASTS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_CELL_BROADCASTS = 701; + + // ACTION: An app requested the permission BODY_SENSORS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_BODY_SENSORS = 702; + + // ACTION: An app was granted the permission BODY_SENSORS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_BODY_SENSORS = 703; + + // ACTION: An app requested the permission BODY_SENSORS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_BODY_SENSORS = 704; + + // ACTION: The permission BODY_SENSORS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_BODY_SENSORS = 705; + + // ACTION: An app requested the permission SEND_SMS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_SEND_SMS = 706; + + // ACTION: An app was granted the permission SEND_SMS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_SEND_SMS = 707; + + // ACTION: An app requested the permission SEND_SMS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_SEND_SMS = 708; + + // ACTION: The permission SEND_SMS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_SEND_SMS = 709; + + // ACTION: An app requested the permission RECEIVE_SMS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_RECEIVE_SMS = 710; + + // ACTION: An app was granted the permission RECEIVE_SMS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_RECEIVE_SMS = 711; + + // ACTION: An app requested the permission RECEIVE_SMS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_RECEIVE_SMS = 712; + + // ACTION: The permission RECEIVE_SMS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_RECEIVE_SMS = 713; + + // ACTION: An app requested the permission READ_SMS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_SMS = 714; + + // ACTION: An app was granted the permission READ_SMS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_SMS = 715; + + // ACTION: An app requested the permission READ_SMS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_SMS = 716; + + // ACTION: The permission READ_SMS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_SMS = 717; + + // ACTION: An app requested the permission RECEIVE_WAP_PUSH + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_RECEIVE_WAP_PUSH = 718; + + // ACTION: An app was granted the permission RECEIVE_WAP_PUSH + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_RECEIVE_WAP_PUSH = 719; + + // ACTION: An app requested the permission RECEIVE_WAP_PUSH and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_RECEIVE_WAP_PUSH = 720; + + // ACTION: The permission RECEIVE_WAP_PUSH was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_RECEIVE_WAP_PUSH = 721; + + // ACTION: An app requested the permission RECEIVE_MMS + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_RECEIVE_MMS = 722; + + // ACTION: An app was granted the permission RECEIVE_MMS + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_RECEIVE_MMS = 723; + + // ACTION: An app requested the permission RECEIVE_MMS and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_RECEIVE_MMS = 724; + + // ACTION: The permission RECEIVE_MMS was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_RECEIVE_MMS = 725; + + // ACTION: An app requested the permission READ_EXTERNAL_STORAGE + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 726; + + // ACTION: An app was granted the permission READ_EXTERNAL_STORAGE + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_READ_EXTERNAL_STORAGE = 727; + + // ACTION: An app requested the permission READ_EXTERNAL_STORAGE and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_READ_EXTERNAL_STORAGE = 728; + + // ACTION: The permission READ_EXTERNAL_STORAGE was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_READ_EXTERNAL_STORAGE = 729; + + // ACTION: An app requested the permission WRITE_EXTERNAL_STORAGE + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 730; + + // ACTION: An app was granted the permission WRITE_EXTERNAL_STORAGE + // PACKAGE: The package name of the app that was granted the permission + ACTION_PERMISSION_GRANT_WRITE_EXTERNAL_STORAGE = 731; + + // ACTION: An app requested the permission WRITE_EXTERNAL_STORAGE and the request was denied + // PACKAGE: The package name of the app requesting the permission + ACTION_PERMISSION_DENIED_WRITE_EXTERNAL_STORAGE = 732; + + // ACTION: The permission WRITE_EXTERNAL_STORAGE was revoked for an app + // PACKAGE: The package name of the app the permission was revoked for + ACTION_PERMISSION_REVOKE_WRITE_EXTERNAL_STORAGE = 733; + // ---- End O Constants, all O constants go above this line ---- // Add new aosp constants above this line. diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index f5b4b9b400f3..e31df52d8e0a 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -101,6 +101,7 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; +import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.ResourcesManager; import android.app.admin.IDevicePolicyManager; @@ -231,6 +232,7 @@ import com.android.internal.app.ResolverActivity; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.content.PackageHelper; import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.IParcelFileDescriptorFactory; import com.android.internal.os.InstallerConnection.InstallerException; import com.android.internal.os.RoSystemProperties; @@ -527,6 +529,34 @@ public class PackageManagerService extends IPackageManager.Stub { /** Special library name that skips shared libraries check during compilation. */ private static final String SKIP_SHARED_LIBRARY_CHECK = "&"; + /** All dangerous permission names in the same order as the events in MetricsEvent */ + private static final List<String> ALL_DANGEROUS_PERMISSIONS = Arrays.asList( + Manifest.permission.READ_CALENDAR, + Manifest.permission.WRITE_CALENDAR, + Manifest.permission.CAMERA, + Manifest.permission.READ_CONTACTS, + Manifest.permission.WRITE_CONTACTS, + Manifest.permission.GET_ACCOUNTS, + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.RECORD_AUDIO, + Manifest.permission.READ_PHONE_STATE, + Manifest.permission.CALL_PHONE, + Manifest.permission.READ_CALL_LOG, + Manifest.permission.WRITE_CALL_LOG, + Manifest.permission.ADD_VOICEMAIL, + Manifest.permission.USE_SIP, + Manifest.permission.PROCESS_OUTGOING_CALLS, + Manifest.permission.READ_CELL_BROADCASTS, + Manifest.permission.BODY_SENSORS, + Manifest.permission.SEND_SMS, + Manifest.permission.RECEIVE_SMS, + Manifest.permission.READ_SMS, + Manifest.permission.RECEIVE_WAP_PUSH, + Manifest.permission.RECEIVE_MMS, + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE); + final ServiceThread mHandlerThread; final PackageHandler mHandler; @@ -4136,6 +4166,10 @@ public class PackageManagerService extends IPackageManager.Stub { break; } + if (bp.isRuntime()) { + logPermissionGranted(mContext, name, packageName); + } + mOnPermissionChangeListeners.onPermissionsChanged(uid); // Not critical if that is lost - app has to request again. @@ -4237,6 +4271,10 @@ public class PackageManagerService extends IPackageManager.Stub { return; } + if (bp.isRuntime()) { + logPermissionRevoked(mContext, name, packageName); + } + mOnPermissionChangeListeners.onPermissionsChanged(pkg.applicationInfo.uid); // Critical, after this call app should never have the permission. @@ -4248,6 +4286,66 @@ public class PackageManagerService extends IPackageManager.Stub { killUid(appId, userId, KILL_APP_REASON_PERMISSIONS_REVOKED); } + /** + * Get the first event id for the permission. + * + * <p>There are four events for each permission: <ul> + * <li>Request permission: first id + 0</li> + * <li>Grant permission: first id + 1</li> + * <li>Request for permission denied: first id + 2</li> + * <li>Revoke permission: first id + 3</li> + * </ul></p> + * + * @param name name of the permission + * + * @return The first event id for the permission + */ + private static int getBaseEventId(@NonNull String name) { + int eventIdIndex = ALL_DANGEROUS_PERMISSIONS.indexOf(name); + + if (eventIdIndex == -1) { + if (AppOpsManager.permissionToOpCode(name) == AppOpsManager.OP_NONE + || "user".equals(Build.TYPE)) { + Log.i(TAG, "Unknown permission " + name); + + return MetricsEvent.ACTION_PERMISSION_REQUEST_UNKNOWN; + } else { + // Most likely #ALL_DANGEROUS_PERMISSIONS needs to be updated. + // + // Also update + // - EventLogger#ALL_DANGEROUS_PERMISSIONS + // - metrics_constants.proto + throw new IllegalStateException("Unknown permission " + name); + } + } + + return MetricsEvent.ACTION_PERMISSION_REQUEST_READ_CALENDAR + eventIdIndex * 4; + } + + /** + * Log that a permission was revoked. + * + * @param context Context of the caller + * @param name name of the permission + * @param packageName package permission if for + */ + private static void logPermissionRevoked(@NonNull Context context, @NonNull String name, + @NonNull String packageName) { + MetricsLogger.action(context, getBaseEventId(name) + 3, packageName); + } + + /** + * Log that a permission request was granted. + * + * @param context Context of the caller + * @param name name of the permission + * @param packageName package permission if for + */ + private static void logPermissionGranted(@NonNull Context context, @NonNull String name, + @NonNull String packageName) { + MetricsLogger.action(context, getBaseEventId(name) + 1, packageName); + } + @Override public void resetRuntimePermissions() { mContext.enforceCallingOrSelfPermission( |