am 4fea2919: am 660282dc: Merge change I706fe6b0 into eclair

Merge commit '4fea2919abeba149376fed98a14e3ffc8464eadf' into eclair-mr2-plus-aosp

* commit '4fea2919abeba149376fed98a14e3ffc8464eadf':
  Check if Bluetooth is enabled before making any calls down.
This commit is contained in:
Jaikumar Ganesh
2009-11-17 17:40:45 -08:00
committed by Android Git Automerger

View File

@@ -172,6 +172,10 @@ public class BluetoothService extends IBluetooth.Stub {
public boolean isEnabled() { public boolean isEnabled() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
return isEnabledInternal();
}
private boolean isEnabledInternal() {
return mBluetoothState == BluetoothAdapter.STATE_ON; return mBluetoothState == BluetoothAdapter.STATE_ON;
} }
@@ -328,7 +332,7 @@ public class BluetoothService extends IBluetooth.Stub {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS: case MESSAGE_REGISTER_SDP_RECORDS:
if (!isEnabled()) { if (!isEnabledInternal()) {
return; return;
} }
// SystemService.start() forks sdptool to register service // SystemService.start() forks sdptool to register service
@@ -375,7 +379,7 @@ public class BluetoothService extends IBluetooth.Stub {
break; break;
case MESSAGE_DISCOVERABLE_TIMEOUT: case MESSAGE_DISCOVERABLE_TIMEOUT:
int mode = msg.arg1; int mode = msg.arg1;
if (isEnabled()) { if (isEnabledInternal()) {
// TODO: Switch back to the previous scan mode // TODO: Switch back to the previous scan mode
// This is ok for now, because we only use // This is ok for now, because we only use
// CONNECTABLE and CONNECTABLE_DISCOVERABLE // CONNECTABLE and CONNECTABLE_DISCOVERABLE
@@ -675,7 +679,9 @@ public class BluetoothService extends IBluetooth.Stub {
} }
/*package*/synchronized void getAllProperties() { /*package*/synchronized void getAllProperties() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return;
mAdapterProperties.clear(); mAdapterProperties.clear();
String properties[] = (String [])getAdapterPropertiesNative(); String properties[] = (String [])getAdapterPropertiesNative();
@@ -734,16 +740,19 @@ public class BluetoothService extends IBluetooth.Stub {
// The following looks dirty. // The following looks dirty.
private boolean setPropertyString(String key, String value) { private boolean setPropertyString(String key, String value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return false;
return setAdapterPropertyStringNative(key, value); return setAdapterPropertyStringNative(key, value);
} }
private boolean setPropertyInteger(String key, int value) { private boolean setPropertyInteger(String key, int value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return false;
return setAdapterPropertyIntegerNative(key, value); return setAdapterPropertyIntegerNative(key, value);
} }
private boolean setPropertyBoolean(String key, boolean value) { private boolean setPropertyBoolean(String key, boolean value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return false;
return setAdapterPropertyBooleanNative(key, value ? 1 : 0); return setAdapterPropertyBooleanNative(key, value ? 1 : 0);
} }
@@ -852,7 +861,7 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized int getScanMode() { public synchronized int getScanMode() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabled()) if (!isEnabledInternal())
return BluetoothAdapter.SCAN_MODE_NONE; return BluetoothAdapter.SCAN_MODE_NONE;
boolean pairable = getProperty("Pairable").equals("true"); boolean pairable = getProperty("Pairable").equals("true");
@@ -863,15 +872,16 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean startDiscovery() { public synchronized boolean startDiscovery() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabled()) { if (!isEnabledInternal()) return false;
return false;
}
return startDiscoveryNative(); return startDiscoveryNative();
} }
public synchronized boolean cancelDiscovery() { public synchronized boolean cancelDiscovery() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
return stopDiscoveryNative(); return stopDiscoveryNative();
} }
@@ -887,6 +897,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean createBond(String address) { public synchronized boolean createBond(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -919,6 +931,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean cancelBondProcess(String address) { public synchronized boolean cancelBondProcess(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -936,6 +950,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean removeBond(String address) { public synchronized boolean removeBond(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -960,6 +976,8 @@ public class BluetoothService extends IBluetooth.Stub {
} }
/*package*/ String[] getRemoteDeviceProperties(String address) { /*package*/ String[] getRemoteDeviceProperties(String address) {
if (!isEnabledInternal()) return null;
String objectPath = getObjectPathFromAddress(address); String objectPath = getObjectPathFromAddress(address);
return (String [])getDevicePropertiesNative(objectPath); return (String [])getDevicePropertiesNative(objectPath);
} }
@@ -1055,6 +1073,8 @@ public class BluetoothService extends IBluetooth.Stub {
return false; return false;
} }
if (!isEnabledInternal()) return false;
return setDevicePropertyBooleanNative(getObjectPathFromAddress(address), "Trusted", return setDevicePropertyBooleanNative(getObjectPathFromAddress(address), "Trusted",
value ? 1 : 0); value ? 1 : 0);
} }
@@ -1144,6 +1164,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean fetchRemoteUuids(String address, ParcelUuid uuid, public synchronized boolean fetchRemoteUuids(String address, ParcelUuid uuid,
IBluetoothCallback callback) { IBluetoothCallback callback) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return false;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -1198,6 +1220,8 @@ public class BluetoothService extends IBluetooth.Stub {
*/ */
public int getRemoteServiceChannel(String address, ParcelUuid uuid) { public int getRemoteServiceChannel(String address, ParcelUuid uuid) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabledInternal()) return -1;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return BluetoothDevice.ERROR; return BluetoothDevice.ERROR;
} }
@@ -1216,6 +1240,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean setPin(String address, byte[] pin) { public synchronized boolean setPin(String address, byte[] pin) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (pin == null || pin.length <= 0 || pin.length > 16 || if (pin == null || pin.length <= 0 || pin.length > 16 ||
!BluetoothAdapter.checkBluetoothAddress(address)) { !BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
@@ -1242,6 +1268,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean setPasskey(String address, int passkey) { public synchronized boolean setPasskey(String address, int passkey) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (passkey < 0 || passkey > 999999 || !BluetoothAdapter.checkBluetoothAddress(address)) { if (passkey < 0 || passkey > 999999 || !BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -1259,6 +1287,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean setPairingConfirmation(String address, boolean confirm) { public synchronized boolean setPairingConfirmation(String address, boolean confirm) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
address = address.toUpperCase(); address = address.toUpperCase();
Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address);
if (data == null) { if (data == null) {
@@ -1273,6 +1303,8 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean cancelPairingUserInput(String address) { public synchronized boolean cancelPairingUserInput(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission"); "Need BLUETOOTH_ADMIN permission");
if (!isEnabledInternal()) return false;
if (!BluetoothAdapter.checkBluetoothAddress(address)) { if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false; return false;
} }
@@ -1289,7 +1321,7 @@ public class BluetoothService extends IBluetooth.Stub {
return cancelPairingUserInputNative(address, data.intValue()); return cancelPairingUserInputNative(address, data.intValue());
} }
public void updateDeviceServiceChannelCache(String address) { /*package*/ void updateDeviceServiceChannelCache(String address) {
ParcelUuid[] deviceUuids = getRemoteUuids(address); ParcelUuid[] deviceUuids = getRemoteUuids(address);
// We are storing the rfcomm channel numbers only for the uuids // We are storing the rfcomm channel numbers only for the uuids
// we are interested in. // we are interested in.
@@ -1364,8 +1396,9 @@ public class BluetoothService extends IBluetooth.Stub {
*/ */
public synchronized int addRfcommServiceRecord(String serviceName, ParcelUuid uuid, public synchronized int addRfcommServiceRecord(String serviceName, ParcelUuid uuid,
int channel, IBinder b) { int channel, IBinder b) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
"Need BLUETOOTH permission"); if (!isEnabledInternal()) return -1;
if (serviceName == null || uuid == null || channel < 1 || if (serviceName == null || uuid == null || channel < 1 ||
channel > BluetoothSocket.MAX_RFCOMM_CHANNEL) { channel > BluetoothSocket.MAX_RFCOMM_CHANNEL) {
return -1; return -1;