diff options
| author | Marie Janssen <jamuraa@google.com> | 2016-12-14 13:44:28 -0800 |
|---|---|---|
| committer | Marie Janssen <jamuraa@google.com> | 2016-12-14 13:44:28 -0800 |
| commit | 3d4aa65046178ff4f3070faf72f974b7dda7a46b (patch) | |
| tree | fed126e627296e8236403843af48a8a2a54704c7 /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | 5f4cb9393777c30ae3b9517ddcb693ce67d9102d (diff) | |
| parent | 23228c67633e81e1713dcfc14e3a3652d05e30ee (diff) | |
resolve merge conflicts of 23228c6 to nyc-mr1-dev-plus-aosp
Change-Id: I903680717ed121a93fee3b7c2ed358cb29726d71
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 97 |
1 files changed, 32 insertions, 65 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index b0e27a4ab5..6c1e2a9327 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -201,6 +201,23 @@ public final class BluetoothAdapter { public static final int STATE_BLE_TURNING_OFF = 16; /** + * Human-readable string helper for AdapterState + * @hide + */ + public static String nameForState(@AdapterState int state) { + switch(state) { + case STATE_OFF: return "OFF"; + case STATE_TURNING_ON: return "TURNING_ON"; + case STATE_ON: return "ON"; + case STATE_TURNING_OFF: return "TURNING_OFF"; + case STATE_BLE_TURNING_ON: return "BLE_TURNING_ON"; + case STATE_BLE_ON: return "BLE_ON"; + case STATE_BLE_TURNING_OFF: return "BLE_TURNING_OFF"; + default: return "?!?!? (" + state + ")"; + } + } + + /** * Activity Action: Show a system activity that requests discoverable mode. * This activity will also request the user to turn on Bluetooth if it * is not currently enabled. @@ -658,15 +675,8 @@ public final class BluetoothAdapter { @SystemApi public boolean isLeEnabled() { final int state = getLeState(); - if (state == BluetoothAdapter.STATE_ON) { - if (DBG) Log.d (TAG, "STATE_ON"); - } else if (state == BluetoothAdapter.STATE_BLE_ON) { - if (DBG) Log.d (TAG, "STATE_BLE_ON"); - } else { - if (DBG) Log.d (TAG, "STATE_OFF"); - return false; - } - return true; + if (DBG) Log.d(TAG, "isLeEnabled(): " + BluetoothAdapter.nameForState(state)); + return (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON); } /** @@ -831,10 +841,10 @@ public final class BluetoothAdapter { if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) { - if (VDBG) Log.d(TAG, "Consider internal state as OFF"); + if (VDBG) Log.d(TAG, "Consider " + BluetoothAdapter.nameForState(state) + " state as OFF"); state = BluetoothAdapter.STATE_OFF; } - if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + state); + if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + BluetoothAdapter.nameForState(state)); return state; } @@ -871,12 +881,12 @@ public final class BluetoothAdapter { mServiceLock.readLock().unlock(); } - if (VDBG) Log.d(TAG,"getLeState() returning " + state); + if (VDBG) Log.d(TAG,"getLeState() returning " + BluetoothAdapter.nameForState(state)); return state; } boolean getLeAccess() { - if(getLeState() == STATE_ON) + if (getLeState() == STATE_ON) return true; else if (getLeState() == STATE_BLE_ON) @@ -914,8 +924,8 @@ public final class BluetoothAdapter { */ @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean enable() { - if (isEnabled() == true) { - if (DBG) Log.d(TAG, "enable(): BT is already enabled..!"); + if (isEnabled()) { + if (DBG) Log.d(TAG, "enable(): BT already enabled!"); return true; } try { @@ -1518,8 +1528,9 @@ public final class BluetoothAdapter { } } } - } catch (RemoteException e) {Log.e(TAG, "getSupportedProfiles:", e);} - + } catch (RemoteException e) { + Log.e(TAG, "getSupportedProfiles:", e); + } return supportedProfiles; } @@ -1870,34 +1881,6 @@ public final class BluetoothAdapter { * @hide */ public Pair<byte[], byte[]> readOutOfBandData() { - if (getState() != STATE_ON) return null; - //TODO(BT - /* - try { - byte[] hash; - byte[] randomizer; - - byte[] ret = null; - mServiceLock.readLock().lock(); - if (mService != null) mService.readOutOfBandData(); - - if (ret == null || ret.length != 32) return null; - - hash = Arrays.copyOfRange(ret, 0, 16); - randomizer = Arrays.copyOfRange(ret, 16, 32); - - if (DBG) { - Log.d(TAG, "readOutOfBandData:" + Arrays.toString(hash) + - ":" + Arrays.toString(randomizer)); - } - return new Pair<byte[], byte[]>(hash, randomizer); - - } catch (RemoteException e) { - Log.e(TAG, "", e); - } finally { - mServiceLock.readLock().unlock(); - } - */ return null; } @@ -2051,7 +2034,7 @@ public final class BluetoothAdapter { if (cb != null) { cb.onBluetoothServiceUp(bluetoothService); } else { - Log.d(TAG, "onBluetoothServiceUp: cb is null!!!"); + Log.d(TAG, "onBluetoothServiceUp: cb is null!"); } } catch (Exception e) { Log.e(TAG,"",e); @@ -2079,7 +2062,7 @@ public final class BluetoothAdapter { if (cb != null) { cb.onBluetoothServiceDown(); } else { - Log.d(TAG, "onBluetoothServiceDown: cb is null!!!"); + Log.d(TAG, "onBluetoothServiceDown: cb is null!"); } } catch (Exception e) { Log.e(TAG,"",e); @@ -2089,7 +2072,7 @@ public final class BluetoothAdapter { } public void onBrEdrDown() { - if (DBG) Log.i(TAG, "onBrEdrDown:"); + if (VDBG) Log.i(TAG, "onBrEdrDown: " + mService); } }; @@ -2100,7 +2083,7 @@ public final class BluetoothAdapter { */ public boolean enableNoAutoConnect() { if (isEnabled() == true){ - if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT is already enabled..!"); + if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT already enabled!"); return true; } try { @@ -2140,22 +2123,6 @@ public final class BluetoothAdapter { */ public boolean changeApplicationBluetoothState(boolean on, BluetoothStateChangeCallback callback) { - if (callback == null) return false; - - //TODO(BT) - /* - try { - mServiceLock.readLock().lock(); - if (mService != null) { - return mService.changeApplicationBluetoothState(on, new - StateChangeCallbackWrapper(callback), new Binder()); - } - } catch (RemoteException e) { - Log.e(TAG, "changeBluetoothState", e); - } finally { - mServiceLock.readLock().unlock(); - } - */ return false; } |
