Bluetooth: log message improvements
Some log improvements: - Reduce logspam - Use names for states in logs instead of numbers - Be more consistent with messages Also remove some commented out dead code. Test: run on phone, observe more useful logs Change-Id: I32163278e148be144c03d4e8aaf0eb761226c94c
This commit is contained in:
@@ -200,6 +200,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
|
||||
@@ -662,15 +679,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -835,10 +845,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;
|
||||
}
|
||||
|
||||
@@ -875,12 +885,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)
|
||||
@@ -918,8 +928,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 {
|
||||
@@ -1540,8 +1550,9 @@ public final class BluetoothAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RemoteException e) {Log.e(TAG, "getSupportedProfiles:", e);}
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "getSupportedProfiles:", e);
|
||||
}
|
||||
return supportedProfiles;
|
||||
}
|
||||
|
||||
@@ -1892,34 +1903,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;
|
||||
}
|
||||
|
||||
@@ -2066,7 +2049,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);
|
||||
@@ -2094,7 +2077,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);
|
||||
@@ -2104,7 +2087,7 @@ public final class BluetoothAdapter {
|
||||
}
|
||||
|
||||
public void onBrEdrDown() {
|
||||
if (DBG) Log.i(TAG, "onBrEdrDown:");
|
||||
if (VDBG) Log.i(TAG, "onBrEdrDown: " + mService);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2115,7 +2098,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 {
|
||||
@@ -2155,22 +2138,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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user