Loading core/java/android/app/AppOpsManager.java +38 −0 Original line number Diff line number Diff line Loading @@ -2585,6 +2585,44 @@ public class AppOpsManager { return !sOpDisableReset[op]; } /** * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. * * This is intended for use client side, when the receiver id must be created before the * associated call is made to the system server. If using {@link PendingIntent} as the receiver, * avoid using this method as it will include a pointless additional x-process call. Instead * prefer passing the PendingIntent to the system server, and then invoking * {@link #toReceiverId(PendingIntent)}. * * @param obj the receiver in use * @return a string representation of the receiver suitable for app ops use * @hide */ // TODO: this should probably be @SystemApi as well public static @NonNull String toReceiverId(@NonNull Object obj) { if (obj instanceof PendingIntent) { return toReceiverId((PendingIntent) obj); } else { return obj.getClass().getName() + "@" + System.identityHashCode(obj); } } /** * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. * * This is intended for use server side, where ActivityManagerService can be referenced without * an additional x-process call. * * @param pendingIntent the pendingIntent in use * @return a string representation of the pending intent suitable for app ops use * @see #toReceiverId(Object) * @hide */ // TODO: this should probably be @SystemApi as well public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) { return pendingIntent.getTag(""); } /** * When to not enforce {@link #setUserRestriction restrictions}. * Loading location/java/android/location/LocationManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; import android.app.AlarmManager; import android.app.AppOpsManager; import android.app.PendingIntent; import android.app.PropertyInvalidatedCache; import android.compat.Compatibility; Loading Loading @@ -2534,7 +2535,7 @@ public class LocationManager { } public String getListenerId() { return mConsumer.getClass().getName() + "@" + System.identityHashCode(mConsumer); return AppOpsManager.toReceiverId(mConsumer); } public synchronized void register(AlarmManager alarmManager, Loading Loading @@ -2663,7 +2664,7 @@ public class LocationManager { } public String getListenerId() { return mListener.getClass().getName() + "@" + System.identityHashCode(mListener); return AppOpsManager.toReceiverId(mListener); } public void register(@NonNull Executor executor) { Loading services/core/java/com/android/server/location/LocationManagerService.java +6 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -1833,6 +1834,9 @@ public class LocationManagerService extends ILocationManager.Stub { if (request == null) { request = DEFAULT_LOCATION_REQUEST; } if (listenerId == null && intent != null) { listenerId = AppOpsManager.toReceiverId(intent); } CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag, listenerId); Loading Loading @@ -2102,7 +2106,8 @@ public class LocationManagerService extends ILocationManager.Stub { request = DEFAULT_LOCATION_REQUEST; } CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag); CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag, AppOpsManager.toReceiverId(intent)); identity.enforceLocationPermission(PERMISSION_COARSE); Objects.requireNonNull(intent); Loading Loading
core/java/android/app/AppOpsManager.java +38 −0 Original line number Diff line number Diff line Loading @@ -2585,6 +2585,44 @@ public class AppOpsManager { return !sOpDisableReset[op]; } /** * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. * * This is intended for use client side, when the receiver id must be created before the * associated call is made to the system server. If using {@link PendingIntent} as the receiver, * avoid using this method as it will include a pointless additional x-process call. Instead * prefer passing the PendingIntent to the system server, and then invoking * {@link #toReceiverId(PendingIntent)}. * * @param obj the receiver in use * @return a string representation of the receiver suitable for app ops use * @hide */ // TODO: this should probably be @SystemApi as well public static @NonNull String toReceiverId(@NonNull Object obj) { if (obj instanceof PendingIntent) { return toReceiverId((PendingIntent) obj); } else { return obj.getClass().getName() + "@" + System.identityHashCode(obj); } } /** * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. * * This is intended for use server side, where ActivityManagerService can be referenced without * an additional x-process call. * * @param pendingIntent the pendingIntent in use * @return a string representation of the pending intent suitable for app ops use * @see #toReceiverId(Object) * @hide */ // TODO: this should probably be @SystemApi as well public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) { return pendingIntent.getTag(""); } /** * When to not enforce {@link #setUserRestriction restrictions}. * Loading
location/java/android/location/LocationManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; import android.app.AlarmManager; import android.app.AppOpsManager; import android.app.PendingIntent; import android.app.PropertyInvalidatedCache; import android.compat.Compatibility; Loading Loading @@ -2534,7 +2535,7 @@ public class LocationManager { } public String getListenerId() { return mConsumer.getClass().getName() + "@" + System.identityHashCode(mConsumer); return AppOpsManager.toReceiverId(mConsumer); } public synchronized void register(AlarmManager alarmManager, Loading Loading @@ -2663,7 +2664,7 @@ public class LocationManager { } public String getListenerId() { return mListener.getClass().getName() + "@" + System.identityHashCode(mListener); return AppOpsManager.toReceiverId(mListener); } public void register(@NonNull Executor executor) { Loading
services/core/java/com/android/server/location/LocationManagerService.java +6 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -1833,6 +1834,9 @@ public class LocationManagerService extends ILocationManager.Stub { if (request == null) { request = DEFAULT_LOCATION_REQUEST; } if (listenerId == null && intent != null) { listenerId = AppOpsManager.toReceiverId(intent); } CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag, listenerId); Loading Loading @@ -2102,7 +2106,8 @@ public class LocationManagerService extends ILocationManager.Stub { request = DEFAULT_LOCATION_REQUEST; } CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag); CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag, AppOpsManager.toReceiverId(intent)); identity.enforceLocationPermission(PERMISSION_COARSE); Objects.requireNonNull(intent); Loading