Merge "Avoid Bluetooth gets turned on by enableBle"
This commit is contained in:
@@ -175,8 +175,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
|
private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
|
||||||
private boolean mBinding;
|
private boolean mBinding;
|
||||||
private boolean mUnbinding;
|
private boolean mUnbinding;
|
||||||
private int mWaitForEnableRetry;
|
|
||||||
private int mWaitForDisableRetry;
|
|
||||||
|
|
||||||
private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
|
private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
|
||||||
|
|
||||||
@@ -933,14 +931,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
if (mState == BluetoothAdapter.STATE_ON
|
if (mState == BluetoothAdapter.STATE_ON
|
||||||
|| mState == BluetoothAdapter.STATE_BLE_ON
|
|| mState == BluetoothAdapter.STATE_BLE_ON
|
||||||
|| mState == BluetoothAdapter.STATE_TURNING_ON
|
|| mState == BluetoothAdapter.STATE_TURNING_ON
|
||||||
|| mState == BluetoothAdapter.STATE_TURNING_OFF) {
|
|| mState == BluetoothAdapter.STATE_TURNING_OFF
|
||||||
Log.d(TAG, "enableBLE(): Bluetooth already enabled");
|
|| mState == BluetoothAdapter.STATE_BLE_TURNING_ON) {
|
||||||
|
Log.d(TAG, "enableBLE(): Bluetooth is already enabled or is turning on");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
synchronized (mReceiver) {
|
synchronized (mReceiver) {
|
||||||
// waive WRITE_SECURE_SETTINGS permission check
|
// waive WRITE_SECURE_SETTINGS permission check
|
||||||
sendEnableMsg(false,
|
sendEnableMsg(false, BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
|
||||||
BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, packageName);
|
packageName, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1734,6 +1733,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
private class BluetoothHandler extends Handler {
|
private class BluetoothHandler extends Handler {
|
||||||
boolean mGetNameAddressOnly = false;
|
boolean mGetNameAddressOnly = false;
|
||||||
|
private int mWaitForEnableRetry;
|
||||||
|
private int mWaitForDisableRetry;
|
||||||
|
|
||||||
BluetoothHandler(Looper looper) {
|
BluetoothHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -1781,11 +1782,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
case MESSAGE_ENABLE:
|
case MESSAGE_ENABLE:
|
||||||
int quietEnable = msg.arg1;
|
int quietEnable = msg.arg1;
|
||||||
|
int isBle = msg.arg2;
|
||||||
if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
|
if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
|
||||||
|| mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
|
|| mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
|
||||||
// We are handling enable or disable right now, wait for it.
|
// We are handling enable or disable right now, wait for it.
|
||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_ENABLE,
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_ENABLE,
|
||||||
quietEnable, 0), ENABLE_DISABLE_DELAY_MS);
|
quietEnable, isBle), ENABLE_DISABLE_DELAY_MS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1800,13 +1802,28 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
try {
|
try {
|
||||||
mBluetoothLock.readLock().lock();
|
mBluetoothLock.readLock().lock();
|
||||||
if (mBluetooth != null) {
|
if (mBluetooth != null) {
|
||||||
|
boolean isHandled = true;
|
||||||
int state = mBluetooth.getState();
|
int state = mBluetooth.getState();
|
||||||
if (state == BluetoothAdapter.STATE_BLE_ON) {
|
switch (state) {
|
||||||
Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
|
case BluetoothAdapter.STATE_BLE_ON:
|
||||||
mBluetooth.onLeServiceUp();
|
if (isBle == 1) {
|
||||||
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
|
Slog.i(TAG, "Already at BLE_ON State");
|
||||||
break;
|
} else {
|
||||||
|
Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
|
||||||
|
mBluetooth.onLeServiceUp();
|
||||||
|
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BluetoothAdapter.STATE_BLE_TURNING_ON:
|
||||||
|
case BluetoothAdapter.STATE_TURNING_ON:
|
||||||
|
case BluetoothAdapter.STATE_ON:
|
||||||
|
Slog.i(TAG, "MESSAGE_ENABLE: already enabled");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
isHandled = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (isHandled) break;
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "", e);
|
Slog.e(TAG, "", e);
|
||||||
@@ -2559,7 +2576,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendEnableMsg(boolean quietMode, int reason, String packageName) {
|
private void sendEnableMsg(boolean quietMode, int reason, String packageName) {
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_ENABLE, quietMode ? 1 : 0, 0));
|
sendEnableMsg(quietMode, reason, packageName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendEnableMsg(boolean quietMode, int reason, String packageName, boolean isBle) {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_ENABLE, quietMode ? 1 : 0,
|
||||||
|
isBle ? 1 : 0));
|
||||||
addActiveLog(reason, packageName, true);
|
addActiveLog(reason, packageName, true);
|
||||||
mLastEnabledTime = SystemClock.elapsedRealtime();
|
mLastEnabledTime = SystemClock.elapsedRealtime();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user