Skip to content

Commit b1a01ab

Browse files
Martijn CoenenAndroid (Google) Code Review
authored andcommitted
Merge "Allow the NFC process to call Bluetooth APIs." into jb-mr1.1-dev
2 parents 675814d + 8385c5a commit b1a01ab

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;
@@ -330,9 +328,12 @@ public boolean enableNoAutoConnect()
330328
Log.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth +
331329
" mBinding = " + mBinding);
332330
}
333-
if (Binder.getCallingUid() != Process.NFC_UID) {
331+
int callingAppId = UserHandle.getAppId(Binder.getCallingUid());
332+
333+
if (callingAppId != Process.NFC_UID) {
334334
throw new SecurityException("no permission to enable Bluetooth quietly");
335335
}
336+
336337
Message msg = mHandler.obtainMessage(MESSAGE_ENABLE);
337338
msg.arg1=0; //No persist
338339
msg.arg2=1; //Quiet mode
@@ -968,11 +969,14 @@ private void handleDisable(boolean persist) {
968969
private boolean checkIfCallerIsForegroundUser() {
969970
int foregroundUser;
970971
int callingUser = UserHandle.getCallingUserId();
972+
int callingUid = Binder.getCallingUid();
971973
long callingIdentity = Binder.clearCallingIdentity();
974+
int callingAppId = UserHandle.getAppId(callingUid);
972975
boolean valid = false;
973976
try {
974977
foregroundUser = ActivityManager.getCurrentUser();
975-
valid = (callingUser == foregroundUser);
978+
valid = (callingUser == foregroundUser) ||
979+
callingAppId == Process.NFC_UID;
976980
if (DBG) {
977981
Log.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
978982
+ " callingUser=" + callingUser

0 commit comments

Comments
 (0)