am cd18678b: Merge "Bluetooth multi-user updates: change bluetooth service to reject background user access." into jb-mr1-dev
* commit 'cd18678b1e100052023706746d2578ebfd433958':
Bluetooth multi-user updates: change bluetooth service to reject background user access.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e576d22..783c53d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -46,6 +46,9 @@
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.BLUETOOTH_STACK" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
+ <uses-permission android:name="android.permission.MANAGE_USERS"/>
+
<!-- For PBAP Owner Vcard Info -->
<uses-permission android:name="android.permission.READ_PROFILE"/>
<application
diff --git a/src/com/android/bluetooth/Utils.java b/src/com/android/bluetooth/Utils.java
index 6e0e23a..b06fcb6 100644
--- a/src/com/android/bluetooth/Utils.java
+++ b/src/com/android/bluetooth/Utils.java
@@ -4,9 +4,12 @@
package com.android.bluetooth;
+import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.os.Binder;
import android.os.ParcelUuid;
+import android.os.UserHandle;
import android.util.Log;
import java.io.IOException;
@@ -162,4 +165,24 @@
}
}
}
+
+ public static boolean checkCaller() {
+ boolean ok;
+ // Get the caller's user id then clear the calling identity
+ // which will be restored in the finally clause.
+ int callingUser = UserHandle.getCallingUserId();
+ long ident = Binder.clearCallingIdentity();
+
+ try {
+ // With calling identity cleared the current user is the foreground user.
+ int foregroundUser = ActivityManager.getCurrentUser();
+ ok = (foregroundUser == callingUser);
+ } catch (Exception ex) {
+ Log.e(TAG,"checkIfCallerIsSelfOrForegroundUser: Exception ex=" + ex);
+ ok = false;
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ return ok;
+ }
}
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java
index 26503b6..da30597 100755
--- a/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -10,11 +10,12 @@
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Map;
import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.Utils;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
* Provides Bluetooth A2DP profile, as a service in the Bluetooth application.
@@ -168,7 +169,12 @@
private A2dpService mService;
private A2dpService getService() {
- if (mService != null && mService.isAvailable()) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"A2dp call not allowed for non-active user");
+ return null;
+ }
+
+ if (mService != null && mService.isAvailable()) {
return mService;
}
return null;
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java
index 35ca310..55b83be 100755
--- a/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/src/com/android/bluetooth/btservice/AdapterService.java
@@ -29,6 +29,7 @@
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.ParcelUuid;
+import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.provider.Settings;
@@ -482,191 +483,358 @@
return null;
}
public boolean isEnabled() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"isEnabled(): not allowed for non-active user and non system user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.isEnabled();
}
public int getState() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"getState(): not allowed for non-active user and non system user");
+ return BluetoothAdapter.STATE_OFF;
+ }
+
AdapterService service = getService();
if (service == null) return BluetoothAdapter.STATE_OFF;
return service.getState();
}
public boolean enable() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"enable(): not allowed for non-active user and non system user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.enable();
}
public boolean enableNoAutoConnect() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"enableNoAuto(): not allowed for non-active user and non system user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.enableNoAutoConnect();
}
public boolean disable() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"disable(): not allowed for non-active user and non system user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.disable();
}
public String getAddress() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"getAddress(): not allowed for non-active user and non system user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.getAddress();
}
public ParcelUuid[] getUuids() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getUuids(): not allowed for non-active user");
+ return new ParcelUuid[0];
+ }
+
AdapterService service = getService();
if (service == null) return new ParcelUuid[0];
return service.getUuids();
}
public String getName() {
+ if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+ (!Utils.checkCaller())) {
+ Log.w(TAG,"getName(): not allowed for non-active user and non system user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.getName();
}
public boolean setName(String name) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setName(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setName(name);
}
public int getScanMode() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getScanMode(): not allowed for non-active user");
+ return BluetoothAdapter.SCAN_MODE_NONE;
+ }
+
AdapterService service = getService();
if (service == null) return BluetoothAdapter.SCAN_MODE_NONE;
return service.getScanMode();
}
public boolean setScanMode(int mode, int duration) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setScanMode(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setScanMode(mode,duration);
}
public int getDiscoverableTimeout() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getDiscoverableTimeout(): not allowed for non-active user");
+ return 0;
+ }
+
AdapterService service = getService();
if (service == null) return 0;
return service.getDiscoverableTimeout();
}
public boolean setDiscoverableTimeout(int timeout) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setDiscoverableTimeout(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setDiscoverableTimeout(timeout);
}
public boolean startDiscovery() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"startDiscovery(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.startDiscovery();
}
public boolean cancelDiscovery() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"cancelDiscovery(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.cancelDiscovery();
}
public boolean isDiscovering() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"isDiscovering(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.isDiscovering();
}
public BluetoothDevice[] getBondedDevices() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getBondedDevices: not allowed for non-active user");
+ return new BluetoothDevice[0];
+ }
+
AdapterService service = getService();
if (service == null) return new BluetoothDevice[0];
return service.getBondedDevices();
}
public int getAdapterConnectionState() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getAdapterConnectionState: not allowed for non-active user");
+ return BluetoothAdapter.STATE_DISCONNECTED;
+ }
+
AdapterService service = getService();
if (service == null) return BluetoothAdapter.STATE_DISCONNECTED;
return service.getAdapterConnectionState();
}
public int getProfileConnectionState(int profile) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getProfileConnectionState: not allowed for non-active user");
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+
AdapterService service = getService();
if (service == null) return BluetoothProfile.STATE_DISCONNECTED;
return service.getProfileConnectionState(profile);
}
public boolean createBond(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"createBond(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.createBond(device);
}
public boolean cancelBondProcess(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"cancelBondProcess(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.cancelBondProcess(device);
}
public boolean removeBond(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"removeBond(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.removeBond(device);
}
public int getBondState(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getBondState(): not allowed for non-active user");
+ return BluetoothDevice.BOND_NONE;
+ }
+
AdapterService service = getService();
if (service == null) return BluetoothDevice.BOND_NONE;
return service.getBondState(device);
}
public String getRemoteName(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getRemoteName(): not allowed for non-active user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.getRemoteName(device);
}
public String getRemoteAlias(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getRemoteAlias(): not allowed for non-active user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.getRemoteAlias(device);
}
public boolean setRemoteAlias(BluetoothDevice device, String name) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setRemoteAlias(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setRemoteAlias(device, name);
}
public int getRemoteClass(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getRemoteClass(): not allowed for non-active user");
+ return 0;
+ }
+
AdapterService service = getService();
if (service == null) return 0;
return service.getRemoteClass(device);
}
public ParcelUuid[] getRemoteUuids(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getRemoteUuids(): not allowed for non-active user");
+ return new ParcelUuid[0];
+ }
+
AdapterService service = getService();
- if (service == null) return null;
+ if (service == null) return new ParcelUuid[0];
return service.getRemoteUuids(device);
}
public boolean fetchRemoteUuids(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"fetchRemoteUuids(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.fetchRemoteUuids(device);
}
public boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setPin(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setPin(device, accept, len, pinCode);
}
public boolean setPasskey(BluetoothDevice device, boolean accept, int len, byte[] passkey) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setPasskey(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setPasskey(device, accept, len, passkey);
}
public boolean setPairingConfirmation(BluetoothDevice device, boolean accept) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"setPairingConfirmation(): not allowed for non-active user");
+ return false;
+ }
+
AdapterService service = getService();
if (service == null) return false;
return service.setPairingConfirmation(device, accept);
@@ -681,6 +849,11 @@
public ParcelFileDescriptor connectSocket(BluetoothDevice device, int type,
ParcelUuid uuid, int port, int flag) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"connectSocket(): not allowed for non-active user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.connectSocket(device, type, uuid, port, flag);
@@ -688,6 +861,11 @@
public ParcelFileDescriptor createSocketChannel(int type, String serviceName,
ParcelUuid uuid, int port, int flag) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"createSocketChannel(): not allowed for non-active user");
+ return null;
+ }
+
AdapterService service = getService();
if (service == null) return null;
return service.createSocketChannel(type, serviceName, uuid, port, flag);
@@ -710,11 +888,13 @@
//----API Methods--------
boolean isEnabled() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getState() == BluetoothAdapter.STATE_ON;
}
int getState() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
if (mAdapterProperties == null){
return BluetoothAdapter.STATE_OFF;
}
@@ -746,6 +926,7 @@
boolean disable() {
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
+
if (DBG) debugLog("disable() called...");
Message m =
mAdapterStateMachine.obtainMessage(AdapterState.USER_TURN_OFF);
@@ -755,6 +936,7 @@
String getAddress() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
String addrString = null;
byte[] address = mAdapterProperties.getAddress();
return Utils.getAddressStringFromByte(address);
@@ -762,12 +944,14 @@
ParcelUuid[] getUuids() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getUuids();
}
String getName() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM,
"Need BLUETOOTH permission");
+
try {
return mAdapterProperties.getName();
} catch (Throwable t) {
@@ -779,16 +963,19 @@
boolean setName(String name) {
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
+
return mAdapterProperties.setName(name);
}
int getScanMode() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getScanMode();
}
boolean setScanMode(int mode, int duration) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
setDiscoverableTimeout(duration);
int newMode = convertScanModeToHal(mode);
@@ -797,28 +984,33 @@
int getDiscoverableTimeout() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getDiscoverableTimeout();
}
boolean setDiscoverableTimeout(int timeout) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.setDiscoverableTimeout(timeout);
}
boolean startDiscovery() {
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
+
return startDiscoveryNative();
}
boolean cancelDiscovery() {
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
+
return cancelDiscoveryNative();
}
boolean isDiscovering() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.isDiscovering();
}
@@ -830,11 +1022,13 @@
int getAdapterConnectionState() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getConnectionState();
}
int getProfileConnectionState(int profile) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
return mAdapterProperties.getProfileConnectionState(profile);
}
diff --git a/src/com/android/bluetooth/hdp/HealthService.java b/src/com/android/bluetooth/hdp/HealthService.java
index f689cfc..75a6cf8 100755
--- a/src/com/android/bluetooth/hdp/HealthService.java
+++ b/src/com/android/bluetooth/hdp/HealthService.java
@@ -12,17 +12,20 @@
import android.bluetooth.IBluetoothHealth;
import android.bluetooth.IBluetoothHealthCallback;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Message;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
+import android.os.Looper;
+import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
-import java.util.NoSuchElementException;
import android.os.ServiceManager;
import android.util.Log;
+import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.btservice.ProfileService.IProfileServiceBinder;
+import com.android.bluetooth.Utils;
import java.io.FileDescriptor;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,10 +34,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import com.android.bluetooth.Utils;
-import android.content.pm.PackageManager;
-import com.android.bluetooth.btservice.ProfileService;
-import com.android.bluetooth.btservice.ProfileService.IProfileServiceBinder;
+import java.util.NoSuchElementException;
+
/**
* Provides Bluetooth Health Device profile, as a service in
@@ -302,6 +303,11 @@
}
private HealthService getService() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"Health call not allowed for non-active user");
+ return null;
+ }
+
if (mService != null && mService.isAvailable()) {
return mService;
}
diff --git a/src/com/android/bluetooth/hfp/HeadsetService.java b/src/com/android/bluetooth/hfp/HeadsetService.java
index 0920be4..a7e5cb0 100755
--- a/src/com/android/bluetooth/hfp/HeadsetService.java
+++ b/src/com/android/bluetooth/hfp/HeadsetService.java
@@ -12,18 +12,18 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
-
+import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
-import android.content.pm.PackageManager;
-import com.android.bluetooth.btservice.ProfileService;
/**
* Provides Bluetooth Headset and Handsfree profile, as a service in
@@ -113,6 +113,11 @@
}
private HeadsetService getService() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"Headset call not allowed for non-active user");
+ return null;
+ }
+
if (mService != null && mService.isAvailable()) {
return mService;
}
diff --git a/src/com/android/bluetooth/hid/HidService.java b/src/com/android/bluetooth/hid/HidService.java
index f15692c..ade3aff 100755
--- a/src/com/android/bluetooth/hid/HidService.java
+++ b/src/com/android/bluetooth/hid/HidService.java
@@ -10,6 +10,7 @@
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothInputDevice;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Handler;
@@ -18,15 +19,15 @@
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
+import com.android.bluetooth.btservice.AdapterService;
+import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.Utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.android.bluetooth.Utils;
-import android.content.pm.PackageManager;
-import com.android.bluetooth.btservice.ProfileService;
-import com.android.bluetooth.btservice.AdapterService;
+
/**
* Provides Bluetooth Hid Host profile, as a service in
@@ -274,6 +275,11 @@
}
private HidService getService() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"InputDevice call not allowed for non-active user");
+ return null;
+ }
+
if (mService != null && mService.isAvailable()) {
return mService;
}
diff --git a/src/com/android/bluetooth/pan/PanService.java b/src/com/android/bluetooth/pan/PanService.java
index f5d5ff2..a7d6817 100755
--- a/src/com/android/bluetooth/pan/PanService.java
+++ b/src/com/android/bluetooth/pan/PanService.java
@@ -19,23 +19,23 @@
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.NetworkUtils;
+import android.os.Handler;
import android.os.IBinder;
import android.os.INetworkManagementService;
-import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
-
+import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.Utils;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.android.bluetooth.Utils;
-import com.android.bluetooth.btservice.ProfileService;
+
/**
* Provides Bluetooth Pan Device profile, as a service in
@@ -167,6 +167,11 @@
return true;
}
private PanService getService() {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"Pan call not allowed for non-active user");
+ return null;
+ }
+
if (mService != null && mService.isAvailable()) {
return mService;
}
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
index 53810aa..21fbee3 100755
--- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
@@ -56,7 +56,7 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
-
+import com.android.bluetooth.Utils;
import com.android.bluetooth.R;
@@ -721,6 +721,11 @@
public int getState() {
if (DEBUG) Log.d(TAG, "getState " + mState);
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getState(): not allowed for non-active user");
+ return BluetoothPbap.STATE_DISCONNECTED;
+ }
+
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
return mState;
}
@@ -728,6 +733,11 @@
public BluetoothDevice getClient() {
if (DEBUG) Log.d(TAG, "getClient" + mRemoteDevice);
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"getClient(): not allowed for non-active user");
+ return null;
+ }
+
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (mState == BluetoothPbap.STATE_DISCONNECTED) {
return null;
@@ -736,11 +746,21 @@
}
public boolean isConnected(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"isConnected(): not allowed for non-active user");
+ return false;
+ }
+
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
return mState == BluetoothPbap.STATE_CONNECTED && mRemoteDevice.equals(device);
}
public boolean connect(BluetoothDevice device) {
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"connect(): not allowed for non-active user");
+ return false;
+ }
+
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
return false;
@@ -749,6 +769,11 @@
public void disconnect() {
if (DEBUG) Log.d(TAG, "disconnect");
+ if (!Utils.checkCaller()) {
+ Log.w(TAG,"disconnect(): not allowed for non-active user");
+ return;
+ }
+
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
synchronized (BluetoothPbapService.this) {