Skip to content

Commit 8385c5a

Browse files
author
Martijn Coenen
committed
Allow the NFC process to call Bluetooth APIs.
The NFC process used to be only running as user 0, and it may be calling into Bluetooth. Most of the handover code has now moved to a separate process running as the current user. Fix the existing checks to take into account the correct NFC UID, whatever user it is running as. Bug: 7309141 Change-Id: I953cfb263a28aef7fe1be5880b053425dc359a29
1 parent 02053d1 commit 8385c5a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

services/java/com/android/server/BluetoothManagerService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import android.os.UserHandle;
4444
import android.provider.Settings;
4545
import android.util.Log;
46-
import java.util.ArrayList;
47-
import java.util.List;
4846
class BluetoothManagerService extends IBluetoothManager.Stub {
4947
private static final String TAG = "BluetoothManagerService";
5048
private static final boolean DBG = true;
@@ -334,9 +332,12 @@ public boolean enableNoAutoConnect()
334332
Log.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth +
335333
" mBinding = " + mBinding);
336334
}
337-
if (Binder.getCallingUid() != Process.NFC_UID) {
335+
int callingAppId = UserHandle.getAppId(Binder.getCallingUid());
336+
337+
if (callingAppId != Process.NFC_UID) {
338338
throw new SecurityException("no permission to enable Bluetooth quietly");
339339
}
340+
340341
Message msg = mHandler.obtainMessage(MESSAGE_ENABLE);
341342
msg.arg1=0; //No persist
342343
msg.arg2=1; //Quiet mode
@@ -943,11 +944,14 @@ private void handleDisable(boolean persist) {
943944
private boolean checkIfCallerIsForegroundUser() {
944945
int foregroundUser;
945946
int callingUser = UserHandle.getCallingUserId();
947+
int callingUid = Binder.getCallingUid();
946948
long callingIdentity = Binder.clearCallingIdentity();
949+
int callingAppId = UserHandle.getAppId(callingUid);
947950
boolean valid = false;
948951
try {
949952
foregroundUser = ActivityManager.getCurrentUser();
950-
valid = (callingUser == foregroundUser);
953+
valid = (callingUser == foregroundUser) ||
954+
callingAppId == Process.NFC_UID;
951955
if (DBG) {
952956
Log.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
953957
+ " callingUser=" + callingUser

0 commit comments

Comments
 (0)