From 70bbc16b146ce3075ab306e4d7e709de0c024d18 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Fri, 2 Mar 2018 17:44:46 -0800 Subject: [PATCH] Add an app-ops check when registering for location In TelephonyRegistry, check to make sure that the user hasn't turned off the app-ops bit when an app tries to register for location-based updates Change-Id: I51360fe772d9c3f8c2c9628dba28acc009ee6173 Fixes: 73558651 Test: manual, using testapp --- .../com/android/server/TelephonyRegistry.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index e202618df575e..3927ebd593bd0 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -203,6 +203,10 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private PreciseDataConnectionState mPreciseDataConnectionState = new PreciseDataConnectionState(); + static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = + PhoneStateListener.LISTEN_CELL_LOCATION + | PhoneStateListener.LISTEN_CELL_INFO; + static final int ENFORCE_PHONE_STATE_PERMISSION_MASK = PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR | @@ -1721,16 +1725,13 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } private boolean checkListenerPermission(int events, String callingPackage, String message) { - if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { + if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.ACCESS_COARSE_LOCATION, null); - - } - - if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.ACCESS_COARSE_LOCATION, null); - + if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(), + callingPackage) != AppOpsManager.MODE_ALLOWED) { + return false; + } } if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {