public boolean isEnabled() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ return isEnabledInternal();
+ }
+
+ private boolean isEnabledInternal() {
return mBluetoothState == BluetoothAdapter.STATE_ON;
}
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
- if (!isEnabled()) {
+ if (!isEnabledInternal()) {
return;
}
// SystemService.start() forks sdptool to register service
break;
case MESSAGE_DISCOVERABLE_TIMEOUT:
int mode = msg.arg1;
- if (isEnabled()) {
+ if (isEnabledInternal()) {
// TODO: Switch back to the previous scan mode
// This is ok for now, because we only use
// CONNECTABLE and CONNECTABLE_DISCOVERABLE
}
/*package*/synchronized void getAllProperties() {
+
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return;
mAdapterProperties.clear();
String properties[] = (String [])getAdapterPropertiesNative();
// The following looks dirty.
private boolean setPropertyString(String key, String value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return false;
return setAdapterPropertyStringNative(key, value);
}
private boolean setPropertyInteger(String key, int value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return false;
return setAdapterPropertyIntegerNative(key, value);
}
private boolean setPropertyBoolean(String key, boolean value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return false;
return setAdapterPropertyBooleanNative(key, value ? 1 : 0);
}
public synchronized int getScanMode() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- if (!isEnabled())
+ if (!isEnabledInternal())
return BluetoothAdapter.SCAN_MODE_NONE;
boolean pairable = getProperty("Pairable").equals("true");
public synchronized boolean startDiscovery() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
- if (!isEnabled()) {
- return false;
- }
+ if (!isEnabledInternal()) return false;
+
return startDiscoveryNative();
}
public synchronized boolean cancelDiscovery() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
return stopDiscoveryNative();
}
public synchronized boolean createBond(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
public synchronized boolean cancelBondProcess(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
public synchronized boolean removeBond(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
}
/*package*/ String[] getRemoteDeviceProperties(String address) {
+ if (!isEnabledInternal()) return null;
+
String objectPath = getObjectPathFromAddress(address);
return (String [])getDevicePropertiesNative(objectPath);
}
return false;
}
+ if (!isEnabledInternal()) return false;
+
return setDevicePropertyBooleanNative(getObjectPathFromAddress(address), "Trusted",
value ? 1 : 0);
}
public synchronized boolean fetchRemoteUuids(String address, ParcelUuid uuid,
IBluetoothCallback callback) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return false;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
*/
public int getRemoteServiceChannel(String address, ParcelUuid uuid) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return -1;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return BluetoothDevice.ERROR;
}
public synchronized boolean setPin(String address, byte[] pin) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (pin == null || pin.length <= 0 || pin.length > 16 ||
!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
public synchronized boolean setPasskey(String address, int passkey) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (passkey < 0 || passkey > 999999 || !BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
public synchronized boolean setPairingConfirmation(String address, boolean confirm) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
address = address.toUpperCase();
Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address);
if (data == null) {
public synchronized boolean cancelPairingUserInput(String address) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
+ if (!isEnabledInternal()) return false;
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return false;
}
return cancelPairingUserInputNative(address, data.intValue());
}
- public void updateDeviceServiceChannelCache(String address) {
+ /*package*/ void updateDeviceServiceChannelCache(String address) {
ParcelUuid[] deviceUuids = getRemoteUuids(address);
// We are storing the rfcomm channel numbers only for the uuids
// we are interested in.
*/
public synchronized int addRfcommServiceRecord(String serviceName, ParcelUuid uuid,
int channel, IBinder b) {
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
- "Need BLUETOOTH permission");
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!isEnabledInternal()) return -1;
+
if (serviceName == null || uuid == null || channel < 1 ||
channel > BluetoothSocket.MAX_RFCOMM_CHANNEL) {
return -1;