Merge "Bluetooth: log message improvements"
am: f34bdf7676
Change-Id: Ic89c59257559d95119829fa4157dbb763124e86f
This commit is contained in:
@ -199,6 +199,23 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
public static final int STATE_BLE_TURNING_OFF = 16;
|
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.
|
* Activity Action: Show a system activity that requests discoverable mode.
|
||||||
* This activity will also request the user to turn on Bluetooth if it
|
* This activity will also request the user to turn on Bluetooth if it
|
||||||
@ -634,15 +651,8 @@ public final class BluetoothAdapter {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
public boolean isLeEnabled() {
|
public boolean isLeEnabled() {
|
||||||
final int state = getLeState();
|
final int state = getLeState();
|
||||||
if (state == BluetoothAdapter.STATE_ON) {
|
if (DBG) Log.d(TAG, "isLeEnabled(): " + BluetoothAdapter.nameForState(state));
|
||||||
if (DBG) Log.d (TAG, "STATE_ON");
|
return (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -807,10 +817,10 @@ public final class BluetoothAdapter {
|
|||||||
if (state == BluetoothAdapter.STATE_BLE_ON
|
if (state == BluetoothAdapter.STATE_BLE_ON
|
||||||
|| state == BluetoothAdapter.STATE_BLE_TURNING_ON
|
|| state == BluetoothAdapter.STATE_BLE_TURNING_ON
|
||||||
|| state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
|
|| 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;
|
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;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,12 +857,12 @@ public final class BluetoothAdapter {
|
|||||||
mServiceLock.readLock().unlock();
|
mServiceLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VDBG) Log.d(TAG,"getLeState() returning " + state);
|
if (VDBG) Log.d(TAG,"getLeState() returning " + BluetoothAdapter.nameForState(state));
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getLeAccess() {
|
boolean getLeAccess() {
|
||||||
if(getLeState() == STATE_ON)
|
if (getLeState() == STATE_ON)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
else if (getLeState() == STATE_BLE_ON)
|
else if (getLeState() == STATE_BLE_ON)
|
||||||
@ -890,8 +900,8 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||||
public boolean enable() {
|
public boolean enable() {
|
||||||
if (isEnabled() == true) {
|
if (isEnabled()) {
|
||||||
if (DBG) Log.d(TAG, "enable(): BT is already enabled..!");
|
if (DBG) Log.d(TAG, "enable(): BT already enabled!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -1494,8 +1504,9 @@ public final class BluetoothAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {Log.e(TAG, "getSupportedProfiles:", e);}
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "getSupportedProfiles:", e);
|
||||||
|
}
|
||||||
return supportedProfiles;
|
return supportedProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1846,34 +1857,6 @@ public final class BluetoothAdapter {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public Pair<byte[], byte[]> readOutOfBandData() {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2027,7 +2010,7 @@ public final class BluetoothAdapter {
|
|||||||
if (cb != null) {
|
if (cb != null) {
|
||||||
cb.onBluetoothServiceUp(bluetoothService);
|
cb.onBluetoothServiceUp(bluetoothService);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "onBluetoothServiceUp: cb is null!!!");
|
Log.d(TAG, "onBluetoothServiceUp: cb is null!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG,"",e);
|
Log.e(TAG,"",e);
|
||||||
@ -2055,7 +2038,7 @@ public final class BluetoothAdapter {
|
|||||||
if (cb != null) {
|
if (cb != null) {
|
||||||
cb.onBluetoothServiceDown();
|
cb.onBluetoothServiceDown();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "onBluetoothServiceDown: cb is null!!!");
|
Log.d(TAG, "onBluetoothServiceDown: cb is null!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG,"",e);
|
Log.e(TAG,"",e);
|
||||||
@ -2065,7 +2048,7 @@ public final class BluetoothAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBrEdrDown() {
|
public void onBrEdrDown() {
|
||||||
if (VDBG) Log.i(TAG, "on QBrEdrDown: ");
|
if (VDBG) Log.i(TAG, "onBrEdrDown: " + mService);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2076,7 +2059,7 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
public boolean enableNoAutoConnect() {
|
public boolean enableNoAutoConnect() {
|
||||||
if (isEnabled() == true){
|
if (isEnabled() == true){
|
||||||
if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT is already enabled..!");
|
if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT already enabled!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -2116,22 +2099,6 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
public boolean changeApplicationBluetoothState(boolean on,
|
public boolean changeApplicationBluetoothState(boolean on,
|
||||||
BluetoothStateChangeCallback callback) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
private static final int MESSAGE_USER_UNLOCKED = 301;
|
private static final int MESSAGE_USER_UNLOCKED = 301;
|
||||||
private static final int MESSAGE_ADD_PROXY_DELAYED = 400;
|
private static final int MESSAGE_ADD_PROXY_DELAYED = 400;
|
||||||
private static final int MESSAGE_BIND_PROFILE_SERVICE = 401;
|
private static final int MESSAGE_BIND_PROFILE_SERVICE = 401;
|
||||||
|
|
||||||
private static final int MAX_SAVE_RETRIES = 3;
|
private static final int MAX_SAVE_RETRIES = 3;
|
||||||
private static final int MAX_ERROR_RESTART_RETRIES = 6;
|
private static final int MAX_ERROR_RESTART_RETRIES = 6;
|
||||||
|
|
||||||
@ -219,7 +220,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
} finally {
|
} finally {
|
||||||
mBluetoothLock.readLock().unlock();
|
mBluetoothLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
Slog.d(TAG, "state" + st);
|
Slog.d(TAG, "State " + BluetoothAdapter.nameForState(st));
|
||||||
|
|
||||||
if (isAirplaneModeOn()) {
|
if (isAirplaneModeOn()) {
|
||||||
// Clear registered LE apps to force shut-off
|
// Clear registered LE apps to force shut-off
|
||||||
@ -408,6 +409,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
|
||||||
"Need BLUETOOTH permission");
|
"Need BLUETOOTH permission");
|
||||||
|
if (callback == null) {
|
||||||
|
Slog.w(TAG, "registerStateChangeCallback: Callback is null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_STATE_CHANGE_CALLBACK);
|
Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_STATE_CHANGE_CALLBACK);
|
||||||
msg.obj = callback;
|
msg.obj = callback;
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
@ -416,6 +421,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
public void unregisterStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
public void unregisterStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
|
||||||
"Need BLUETOOTH permission");
|
"Need BLUETOOTH permission");
|
||||||
|
if (callback == null) {
|
||||||
|
Slog.w(TAG, "unregisterStateChangeCallback: Callback is null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK);
|
Message msg = mHandler.obtainMessage(MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK);
|
||||||
msg.obj = callback;
|
msg.obj = callback;
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
@ -442,7 +451,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
public int getState() {
|
public int getState() {
|
||||||
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
|
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
|
||||||
(!checkIfCallerIsForegroundUser())) {
|
(!checkIfCallerIsForegroundUser())) {
|
||||||
Slog.w(TAG, "getState(): not allowed for non-active and non system user");
|
Slog.w(TAG, "getState(): report OFF for non-active and non system user");
|
||||||
return BluetoothAdapter.STATE_OFF;
|
return BluetoothAdapter.STATE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,7 +692,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
"Need BLUETOOTH ADMIN permission");
|
"Need BLUETOOTH ADMIN permission");
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(TAG,"enable(): mBluetooth =" + mBluetooth +
|
Slog.d(TAG,"enable(): mBluetooth =" + mBluetooth +
|
||||||
" mBinding = " + mBinding + " mState = " + mState);
|
" mBinding = " + mBinding + " mState = " +
|
||||||
|
BluetoothAdapter.nameForState(mState));
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(mReceiver) {
|
synchronized(mReceiver) {
|
||||||
@ -727,7 +737,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
public void unbindAndFinish() {
|
public void unbindAndFinish() {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
|
Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
|
||||||
" mBinding = " + mBinding);
|
" mBinding = " + mBinding + " mUnbinding = " + mUnbinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -743,16 +753,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Slog.e(TAG, "Unable to unregister BluetoothCallback",re);
|
Slog.e(TAG, "Unable to unregister BluetoothCallback",re);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBG) Slog.d(TAG, "Sending unbind request.");
|
|
||||||
mBluetoothBinder = null;
|
mBluetoothBinder = null;
|
||||||
mBluetooth = null;
|
mBluetooth = null;
|
||||||
//Unbind
|
|
||||||
mContext.unbindService(mConnection);
|
mContext.unbindService(mConnection);
|
||||||
mUnbinding = false;
|
mUnbinding = false;
|
||||||
mBinding = false;
|
mBinding = false;
|
||||||
} else {
|
} else {
|
||||||
mUnbinding=false;
|
mUnbinding = false;
|
||||||
}
|
}
|
||||||
mBluetoothGatt = null;
|
mBluetoothGatt = null;
|
||||||
} finally {
|
} finally {
|
||||||
@ -1028,7 +1035,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
* Inform BluetoothAdapter instances that Adapter service is up
|
* Inform BluetoothAdapter instances that Adapter service is up
|
||||||
*/
|
*/
|
||||||
private void sendBluetoothServiceUpCallback() {
|
private void sendBluetoothServiceUpCallback() {
|
||||||
if (DBG) Slog.d(TAG,"Calling onBluetoothServiceUp callbacks");
|
|
||||||
try {
|
try {
|
||||||
int n = mCallbacks.beginBroadcast();
|
int n = mCallbacks.beginBroadcast();
|
||||||
Slog.d(TAG,"Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
|
Slog.d(TAG,"Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
|
||||||
@ -1047,7 +1053,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
* Inform BluetoothAdapter instances that Adapter service is down
|
* Inform BluetoothAdapter instances that Adapter service is down
|
||||||
*/
|
*/
|
||||||
private void sendBluetoothServiceDownCallback() {
|
private void sendBluetoothServiceDownCallback() {
|
||||||
if (DBG) Slog.d(TAG,"Calling onBluetoothServiceDown callbacks");
|
|
||||||
try {
|
try {
|
||||||
int n = mCallbacks.beginBroadcast();
|
int n = mCallbacks.beginBroadcast();
|
||||||
Slog.d(TAG,"Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
|
Slog.d(TAG,"Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
|
||||||
@ -1119,34 +1124,33 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class BluetoothServiceConnection implements ServiceConnection {
|
private class BluetoothServiceConnection implements ServiceConnection {
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName componentName, IBinder service) {
|
||||||
if (DBG) Slog.d(TAG, "BluetoothServiceConnection: " + className.getClassName());
|
String name = componentName.getClassName();
|
||||||
|
if (DBG) Slog.d(TAG, "BluetoothServiceConnection: " + name);
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_CONNECTED);
|
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_CONNECTED);
|
||||||
// TBD if (className.getClassName().equals(IBluetooth.class.getName())) {
|
if (name.equals("com.android.bluetooth.btservice.AdapterService")) {
|
||||||
if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
|
|
||||||
msg.arg1 = SERVICE_IBLUETOOTH;
|
msg.arg1 = SERVICE_IBLUETOOTH;
|
||||||
// } else if (className.getClassName().equals(IBluetoothGatt.class.getName())) {
|
} else if (name.equals("com.android.bluetooth.gatt.GattService")) {
|
||||||
} else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
|
|
||||||
msg.arg1 = SERVICE_IBLUETOOTHGATT;
|
msg.arg1 = SERVICE_IBLUETOOTHGATT;
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "Unknown service connected: " + className.getClassName());
|
Slog.e(TAG, "Unknown service connected: " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg.obj = service;
|
msg.obj = service;
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName className) {
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
// Called if we unexpected disconnected.
|
// Called if we unexpectedly disconnect.
|
||||||
if (DBG) Slog.d(TAG, "BluetoothServiceConnection, disconnected: " +
|
String name = componentName.getClassName();
|
||||||
className.getClassName());
|
if (DBG) Slog.d(TAG, "BluetoothServiceConnection, disconnected: " + name);
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED);
|
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED);
|
||||||
if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
|
if (name.equals("com.android.bluetooth.btservice.AdapterService")) {
|
||||||
msg.arg1 = SERVICE_IBLUETOOTH;
|
msg.arg1 = SERVICE_IBLUETOOTH;
|
||||||
} else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
|
} else if (name.equals("com.android.bluetooth.gatt.GattService")) {
|
||||||
msg.arg1 = SERVICE_IBLUETOOTHGATT;
|
msg.arg1 = SERVICE_IBLUETOOTHGATT;
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "Unknown service disconnected: " + className.getClassName());
|
Slog.e(TAG, "Unknown service disconnected: " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
@ -1164,7 +1168,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
if (DBG) Slog.d (TAG, "Message: " + msg.what);
|
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MESSAGE_GET_NAME_AND_ADDRESS:
|
case MESSAGE_GET_NAME_AND_ADDRESS:
|
||||||
if (DBG) Slog.d(TAG, "MESSAGE_GET_NAME_AND_ADDRESS");
|
if (DBG) Slog.d(TAG, "MESSAGE_GET_NAME_AND_ADDRESS");
|
||||||
@ -1202,7 +1205,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
case MESSAGE_ENABLE:
|
case MESSAGE_ENABLE:
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
|
Slog.d(TAG, "MESSAGE_ENABLE(" + msg.arg1 + "): mBluetooth = " + mBluetooth);
|
||||||
}
|
}
|
||||||
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
|
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
|
||||||
mEnable = true;
|
mEnable = true;
|
||||||
@ -1252,6 +1255,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_DISABLE:
|
case MESSAGE_DISABLE:
|
||||||
|
if (DBG) Slog.d(TAG, "MESSAGE_DISABLE: mBluetooth = " + mBluetooth);
|
||||||
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
|
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
|
||||||
if (mEnable && mBluetooth != null) {
|
if (mEnable && mBluetooth != null) {
|
||||||
waitForOnOff(true, false);
|
waitForOnOff(true, false);
|
||||||
@ -1267,31 +1271,25 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
case MESSAGE_REGISTER_ADAPTER:
|
case MESSAGE_REGISTER_ADAPTER:
|
||||||
{
|
{
|
||||||
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
||||||
boolean added = mCallbacks.register(callback);
|
mCallbacks.register(callback);
|
||||||
Slog.d(TAG,"Added callback: " + (callback == null? "null": callback) +":" +added );
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case MESSAGE_UNREGISTER_ADAPTER:
|
case MESSAGE_UNREGISTER_ADAPTER:
|
||||||
{
|
{
|
||||||
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
||||||
boolean removed = mCallbacks.unregister(callback);
|
mCallbacks.unregister(callback);
|
||||||
Slog.d(TAG,"Removed callback: " + (callback == null? "null": callback) +":" + removed);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
|
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
|
||||||
{
|
{
|
||||||
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
|
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
|
||||||
if (callback != null) {
|
mStateChangeCallbacks.register(callback);
|
||||||
mStateChangeCallbacks.register(callback);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK:
|
case MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK:
|
||||||
{
|
{
|
||||||
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
|
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
|
||||||
if (callback != null) {
|
mStateChangeCallbacks.unregister(callback);
|
||||||
mStateChangeCallbacks.unregister(callback);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_ADD_PROXY_DELAYED:
|
case MESSAGE_ADD_PROXY_DELAYED:
|
||||||
@ -1364,13 +1362,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
//Do enable request
|
//Do enable request
|
||||||
try {
|
try {
|
||||||
if (mQuietEnable == false) {
|
if (mQuietEnable == false) {
|
||||||
if(!mBluetooth.enable()) {
|
if (!mBluetooth.enable()) {
|
||||||
Slog.e(TAG,"IBluetooth.enable() returned false");
|
Slog.e(TAG,"IBluetooth.enable() returned false");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (!mBluetooth.enableNoAutoConnect()) {
|
||||||
{
|
|
||||||
if(!mBluetooth.enableNoAutoConnect()) {
|
|
||||||
Slog.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
|
Slog.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1388,19 +1384,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_TIMEOUT_BIND: {
|
|
||||||
Slog.e(TAG, "MESSAGE_TIMEOUT_BIND");
|
|
||||||
mBluetoothLock.writeLock().lock();
|
|
||||||
mBinding = false;
|
|
||||||
mBluetoothLock.writeLock().unlock();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESSAGE_BLUETOOTH_STATE_CHANGE:
|
case MESSAGE_BLUETOOTH_STATE_CHANGE:
|
||||||
{
|
{
|
||||||
int prevState = msg.arg1;
|
int prevState = msg.arg1;
|
||||||
int newState = msg.arg2;
|
int newState = msg.arg2;
|
||||||
if (DBG) Slog.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: prevState = " + prevState + ", newState=" + newState);
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: " + BluetoothAdapter.nameForState(prevState) + " > " +
|
||||||
|
BluetoothAdapter.nameForState(newState));
|
||||||
|
}
|
||||||
mState = newState;
|
mState = newState;
|
||||||
bluetoothStateChangeHandler(prevState, newState);
|
bluetoothStateChangeHandler(prevState, newState);
|
||||||
// handle error state transition case from TURNING_ON to OFF
|
// handle error state transition case from TURNING_ON to OFF
|
||||||
@ -1440,7 +1431,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED:
|
case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED:
|
||||||
{
|
{
|
||||||
Slog.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: " + msg.arg1);
|
Slog.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED(" + msg.arg1 + ")");
|
||||||
try {
|
try {
|
||||||
mBluetoothLock.writeLock().lock();
|
mBluetoothLock.writeLock().lock();
|
||||||
if (msg.arg1 == SERVICE_IBLUETOOTH) {
|
if (msg.arg1 == SERVICE_IBLUETOOTH) {
|
||||||
@ -1451,7 +1442,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
mBluetoothGatt = null;
|
mBluetoothGatt = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "Bad msg.arg1: " + msg.arg1);
|
Slog.e(TAG, "Unknown argument for service disconnect!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -1488,8 +1479,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
case MESSAGE_RESTART_BLUETOOTH_SERVICE:
|
case MESSAGE_RESTART_BLUETOOTH_SERVICE:
|
||||||
{
|
{
|
||||||
Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE:"
|
Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE");
|
||||||
+" Restart IBluetooth service");
|
|
||||||
/* Enable without persisting the setting as
|
/* Enable without persisting the setting as
|
||||||
it doesnt change when IBluetooth
|
it doesnt change when IBluetooth
|
||||||
service restarts */
|
service restarts */
|
||||||
@ -1497,7 +1487,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
handleEnable(mQuietEnable);
|
handleEnable(mQuietEnable);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MESSAGE_TIMEOUT_BIND: {
|
||||||
|
Slog.e(TAG, "MESSAGE_TIMEOUT_BIND");
|
||||||
|
mBluetoothLock.writeLock().lock();
|
||||||
|
mBinding = false;
|
||||||
|
mBluetoothLock.writeLock().unlock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MESSAGE_TIMEOUT_UNBIND:
|
case MESSAGE_TIMEOUT_UNBIND:
|
||||||
{
|
{
|
||||||
Slog.e(TAG, "MESSAGE_TIMEOUT_UNBIND");
|
Slog.e(TAG, "MESSAGE_TIMEOUT_UNBIND");
|
||||||
@ -1583,11 +1579,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
} else if (mBinding || mBluetooth != null) {
|
} else if (mBinding || mBluetooth != null) {
|
||||||
Message userMsg = mHandler.obtainMessage(MESSAGE_USER_SWITCHED);
|
Message userMsg = mHandler.obtainMessage(MESSAGE_USER_SWITCHED);
|
||||||
userMsg.arg2 = 1 + msg.arg2;
|
userMsg.arg2 = 1 + msg.arg2;
|
||||||
// if user is switched when service is being binding
|
// if user is switched when service is binding retry after a delay
|
||||||
// delay sending MESSAGE_USER_SWITCHED
|
|
||||||
mHandler.sendMessageDelayed(userMsg, USER_SWITCHED_TIME_MS);
|
mHandler.sendMessageDelayed(userMsg, USER_SWITCHED_TIME_MS);
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(TAG, "delay MESSAGE_USER_SWITCHED " + userMsg.arg2);
|
Slog.d(TAG, "Retry MESSAGE_USER_SWITCHED " + userMsg.arg2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1688,7 +1683,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
parentUser == foregroundUser ||
|
parentUser == foregroundUser ||
|
||||||
callingAppId == Process.NFC_UID ||
|
callingAppId == Process.NFC_UID ||
|
||||||
callingAppId == mSystemUiUid;
|
callingAppId == mSystemUiUid;
|
||||||
if (DBG) {
|
if (DBG && !valid) {
|
||||||
Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
|
Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
|
||||||
+ " callingUser=" + callingUser
|
+ " callingUser=" + callingUser
|
||||||
+ " parentUser=" + parentUser
|
+ " parentUser=" + parentUser
|
||||||
@ -1701,7 +1696,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendBleStateChanged(int prevState, int newState) {
|
private void sendBleStateChanged(int prevState, int newState) {
|
||||||
if (DBG) Slog.d(TAG,"BLE State Change Intent: " + prevState + " -> " + newState);
|
if (DBG) Slog.d(TAG,"Sending BLE State Change: " + BluetoothAdapter.nameForState(prevState) +
|
||||||
|
" > " + BluetoothAdapter.nameForState(newState));
|
||||||
// Send broadcast message to everyone else
|
// Send broadcast message to everyone else
|
||||||
Intent intent = new Intent(BluetoothAdapter.ACTION_BLE_STATE_CHANGED);
|
Intent intent = new Intent(BluetoothAdapter.ACTION_BLE_STATE_CHANGED);
|
||||||
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
|
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
|
||||||
@ -1712,75 +1708,76 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
private void bluetoothStateChangeHandler(int prevState, int newState) {
|
private void bluetoothStateChangeHandler(int prevState, int newState) {
|
||||||
boolean isStandardBroadcast = true;
|
boolean isStandardBroadcast = true;
|
||||||
if (prevState != newState) {
|
if (prevState == newState) { // No change. Nothing to do.
|
||||||
//Notify all proxy objects first of adapter state change
|
return;
|
||||||
if (newState == BluetoothAdapter.STATE_BLE_ON ||
|
}
|
||||||
newState == BluetoothAdapter.STATE_OFF) {
|
// Notify all proxy objects first of adapter state change
|
||||||
boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF
|
if (newState == BluetoothAdapter.STATE_BLE_ON ||
|
||||||
&& newState == BluetoothAdapter.STATE_BLE_ON);
|
newState == BluetoothAdapter.STATE_OFF) {
|
||||||
|
boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF
|
||||||
|
&& newState == BluetoothAdapter.STATE_BLE_ON);
|
||||||
|
|
||||||
if (newState == BluetoothAdapter.STATE_OFF) {
|
if (newState == BluetoothAdapter.STATE_OFF) {
|
||||||
// If Bluetooth is off, send service down event to proxy objects, and unbind
|
// If Bluetooth is off, send service down event to proxy objects, and unbind
|
||||||
if (DBG) Slog.d(TAG, "Bluetooth is complete turn off");
|
if (DBG) Slog.d(TAG, "Bluetooth is complete send Service Down");
|
||||||
sendBluetoothServiceDownCallback();
|
sendBluetoothServiceDownCallback();
|
||||||
unbindAndFinish();
|
unbindAndFinish();
|
||||||
sendBleStateChanged(prevState, newState);
|
|
||||||
// Don't broadcast as it has already been broadcast before
|
|
||||||
isStandardBroadcast = false;
|
|
||||||
|
|
||||||
} else if (!intermediate_off) {
|
|
||||||
// connect to GattService
|
|
||||||
if (DBG) Slog.d(TAG, "Bluetooth is in LE only mode");
|
|
||||||
if (mBluetoothGatt != null) {
|
|
||||||
if (DBG) Slog.d(TAG, "Calling BluetoothGattServiceUp");
|
|
||||||
onBluetoothGattServiceUp();
|
|
||||||
} else {
|
|
||||||
if (DBG) Slog.d(TAG, "Binding Bluetooth GATT service");
|
|
||||||
if (mContext.getPackageManager().hasSystemFeature(
|
|
||||||
PackageManager.FEATURE_BLUETOOTH_LE)) {
|
|
||||||
Intent i = new Intent(IBluetoothGatt.class.getName());
|
|
||||||
doBind(i, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.CURRENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendBleStateChanged(prevState, newState);
|
|
||||||
//Don't broadcase this as std intent
|
|
||||||
isStandardBroadcast = false;
|
|
||||||
|
|
||||||
} else if (intermediate_off){
|
|
||||||
if (DBG) Slog.d(TAG, "Intermediate off, back to LE only mode");
|
|
||||||
// For LE only mode, broadcast as is
|
|
||||||
sendBleStateChanged(prevState, newState);
|
|
||||||
sendBluetoothStateCallback(false); // BT is OFF for general users
|
|
||||||
// Broadcast as STATE_OFF
|
|
||||||
newState = BluetoothAdapter.STATE_OFF;
|
|
||||||
sendBrEdrDownCallback();
|
|
||||||
}
|
|
||||||
} else if (newState == BluetoothAdapter.STATE_ON) {
|
|
||||||
boolean isUp = (newState==BluetoothAdapter.STATE_ON);
|
|
||||||
sendBluetoothStateCallback(isUp);
|
|
||||||
sendBleStateChanged(prevState, newState);
|
|
||||||
|
|
||||||
} else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON ||
|
|
||||||
newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) {
|
|
||||||
sendBleStateChanged(prevState, newState);
|
sendBleStateChanged(prevState, newState);
|
||||||
|
// Don't broadcast as it has already been broadcast before
|
||||||
isStandardBroadcast = false;
|
isStandardBroadcast = false;
|
||||||
|
|
||||||
} else if (newState == BluetoothAdapter.STATE_TURNING_ON ||
|
} else if (!intermediate_off) {
|
||||||
newState == BluetoothAdapter.STATE_TURNING_OFF) {
|
// connect to GattService
|
||||||
sendBleStateChanged(prevState, newState);
|
if (DBG) Slog.d(TAG, "Bluetooth is in LE only mode");
|
||||||
}
|
if (mBluetoothGatt != null) {
|
||||||
|
if (DBG) Slog.d(TAG, "Calling BluetoothGattServiceUp");
|
||||||
if (isStandardBroadcast) {
|
onBluetoothGattServiceUp();
|
||||||
if (prevState == BluetoothAdapter.STATE_BLE_ON) {
|
} else {
|
||||||
// Show prevState of BLE_ON as OFF to standard users
|
if (DBG) Slog.d(TAG, "Binding Bluetooth GATT service");
|
||||||
prevState = BluetoothAdapter.STATE_OFF;
|
if (mContext.getPackageManager().hasSystemFeature(
|
||||||
|
PackageManager.FEATURE_BLUETOOTH_LE)) {
|
||||||
|
Intent i = new Intent(IBluetoothGatt.class.getName());
|
||||||
|
doBind(i, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.CURRENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
sendBleStateChanged(prevState, newState);
|
||||||
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
|
//Don't broadcase this as std intent
|
||||||
intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
|
isStandardBroadcast = false;
|
||||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
|
||||||
mContext.sendBroadcastAsUser(intent, UserHandle.ALL, BLUETOOTH_PERM);
|
} else if (intermediate_off) {
|
||||||
|
if (DBG) Slog.d(TAG, "Intermediate off, back to LE only mode");
|
||||||
|
// For LE only mode, broadcast as is
|
||||||
|
sendBleStateChanged(prevState, newState);
|
||||||
|
sendBluetoothStateCallback(false); // BT is OFF for general users
|
||||||
|
// Broadcast as STATE_OFF
|
||||||
|
newState = BluetoothAdapter.STATE_OFF;
|
||||||
|
sendBrEdrDownCallback();
|
||||||
}
|
}
|
||||||
|
} else if (newState == BluetoothAdapter.STATE_ON) {
|
||||||
|
boolean isUp = (newState == BluetoothAdapter.STATE_ON);
|
||||||
|
sendBluetoothStateCallback(isUp);
|
||||||
|
sendBleStateChanged(prevState, newState);
|
||||||
|
|
||||||
|
} else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON ||
|
||||||
|
newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) {
|
||||||
|
sendBleStateChanged(prevState, newState);
|
||||||
|
isStandardBroadcast = false;
|
||||||
|
|
||||||
|
} else if (newState == BluetoothAdapter.STATE_TURNING_ON ||
|
||||||
|
newState == BluetoothAdapter.STATE_TURNING_OFF) {
|
||||||
|
sendBleStateChanged(prevState, newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStandardBroadcast) {
|
||||||
|
if (prevState == BluetoothAdapter.STATE_BLE_ON) {
|
||||||
|
// Show prevState of BLE_ON as OFF to standard users
|
||||||
|
prevState = BluetoothAdapter.STATE_OFF;
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
|
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
|
||||||
|
intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
|
||||||
|
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||||
|
mContext.sendBroadcastAsUser(intent, UserHandle.ALL, BLUETOOTH_PERM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user