|
43 | 43 | import android.os.UserHandle; |
44 | 44 | import android.provider.Settings; |
45 | 45 | import android.util.Log; |
46 | | -import java.util.ArrayList; |
47 | | -import java.util.List; |
48 | 46 | class BluetoothManagerService extends IBluetoothManager.Stub { |
49 | 47 | private static final String TAG = "BluetoothManagerService"; |
50 | 48 | private static final boolean DBG = true; |
@@ -330,9 +328,12 @@ public boolean enableNoAutoConnect() |
330 | 328 | Log.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth + |
331 | 329 | " mBinding = " + mBinding); |
332 | 330 | } |
333 | | - if (Binder.getCallingUid() != Process.NFC_UID) { |
| 331 | + int callingAppId = UserHandle.getAppId(Binder.getCallingUid()); |
| 332 | + |
| 333 | + if (callingAppId != Process.NFC_UID) { |
334 | 334 | throw new SecurityException("no permission to enable Bluetooth quietly"); |
335 | 335 | } |
| 336 | + |
336 | 337 | Message msg = mHandler.obtainMessage(MESSAGE_ENABLE); |
337 | 338 | msg.arg1=0; //No persist |
338 | 339 | msg.arg2=1; //Quiet mode |
@@ -968,11 +969,14 @@ private void handleDisable(boolean persist) { |
968 | 969 | private boolean checkIfCallerIsForegroundUser() { |
969 | 970 | int foregroundUser; |
970 | 971 | int callingUser = UserHandle.getCallingUserId(); |
| 972 | + int callingUid = Binder.getCallingUid(); |
971 | 973 | long callingIdentity = Binder.clearCallingIdentity(); |
| 974 | + int callingAppId = UserHandle.getAppId(callingUid); |
972 | 975 | boolean valid = false; |
973 | 976 | try { |
974 | 977 | foregroundUser = ActivityManager.getCurrentUser(); |
975 | | - valid = (callingUser == foregroundUser); |
| 978 | + valid = (callingUser == foregroundUser) || |
| 979 | + callingAppId == Process.NFC_UID; |
976 | 980 | if (DBG) { |
977 | 981 | Log.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid |
978 | 982 | + " callingUser=" + callingUser |
|
0 commit comments