Merge "Bluetooth: Wait for provisioning after init flag change"
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BluetoothDeviceConfigListener handles system device config change callback and checks
|
* The BluetoothDeviceConfigListener handles system device config change callback and checks
|
||||||
@@ -30,10 +33,12 @@ import android.provider.DeviceConfig;
|
|||||||
class BluetoothDeviceConfigListener {
|
class BluetoothDeviceConfigListener {
|
||||||
private static final String TAG = "BluetoothDeviceConfigListener";
|
private static final String TAG = "BluetoothDeviceConfigListener";
|
||||||
|
|
||||||
BluetoothManagerService mService;
|
private final BluetoothManagerService mService;
|
||||||
|
private final boolean mLogDebug;
|
||||||
|
|
||||||
BluetoothDeviceConfigListener(BluetoothManagerService service) {
|
BluetoothDeviceConfigListener(BluetoothManagerService service, boolean logDebug) {
|
||||||
mService = service;
|
mService = service;
|
||||||
|
mLogDebug = logDebug;
|
||||||
DeviceConfig.addOnPropertiesChangedListener(
|
DeviceConfig.addOnPropertiesChangedListener(
|
||||||
DeviceConfig.NAMESPACE_BLUETOOTH,
|
DeviceConfig.NAMESPACE_BLUETOOTH,
|
||||||
(Runnable r) -> r.run(),
|
(Runnable r) -> r.run(),
|
||||||
@@ -47,6 +52,13 @@ class BluetoothDeviceConfigListener {
|
|||||||
if (!properties.getNamespace().equals(DeviceConfig.NAMESPACE_BLUETOOTH)) {
|
if (!properties.getNamespace().equals(DeviceConfig.NAMESPACE_BLUETOOTH)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (mLogDebug) {
|
||||||
|
ArrayList<String> flags = new ArrayList<>();
|
||||||
|
for (String name : properties.getKeyset()) {
|
||||||
|
flags.add(name + "='" + properties.getString(name, "") + "'");
|
||||||
|
}
|
||||||
|
Slog.d(TAG, "onPropertiesChanged: " + String.join(",", flags));
|
||||||
|
}
|
||||||
boolean foundInit = false;
|
boolean foundInit = false;
|
||||||
for (String name : properties.getKeyset()) {
|
for (String name : properties.getKeyset()) {
|
||||||
if (name.startsWith("INIT_")) {
|
if (name.startsWith("INIT_")) {
|
||||||
|
|||||||
@@ -453,6 +453,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
|
if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
|
||||||
&& state == BluetoothProfile.STATE_DISCONNECTED
|
&& state == BluetoothProfile.STATE_DISCONNECTED
|
||||||
&& !mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
|
&& !mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
|
||||||
|
Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
|
||||||
onInitFlagsChanged();
|
onInitFlagsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -810,6 +811,35 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
return enabledProfiles;
|
return enabledProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDeviceProvisioned() {
|
||||||
|
return Settings.Global.getInt(mContentResolver, Settings.Global.DEVICE_PROVISIONED,
|
||||||
|
0) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Monitor change of BLE scan only mode settings.
|
||||||
|
private void registerForProvisioningStateChange() {
|
||||||
|
ContentObserver contentObserver = new ContentObserver(null) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
if (!isDeviceProvisioned()) {
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "DEVICE_PROVISIONED setting changed, but device is not "
|
||||||
|
+ "provisioned");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)) {
|
||||||
|
Slog.i(TAG, "Device provisioned, reactivating pending flag changes");
|
||||||
|
onInitFlagsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mContentResolver.registerContentObserver(
|
||||||
|
Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), false,
|
||||||
|
contentObserver);
|
||||||
|
}
|
||||||
|
|
||||||
// Monitor change of BLE scan only mode settings.
|
// Monitor change of BLE scan only mode settings.
|
||||||
private void registerForBleScanModeChange() {
|
private void registerForBleScanModeChange() {
|
||||||
ContentObserver contentObserver = new ContentObserver(null) {
|
ContentObserver contentObserver = new ContentObserver(null) {
|
||||||
@@ -1375,7 +1405,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
if (mBluetoothAirplaneModeListener != null) {
|
if (mBluetoothAirplaneModeListener != null) {
|
||||||
mBluetoothAirplaneModeListener.start(mBluetoothModeChangeHelper);
|
mBluetoothAirplaneModeListener.start(mBluetoothModeChangeHelper);
|
||||||
}
|
}
|
||||||
mBluetoothDeviceConfigListener = new BluetoothDeviceConfigListener(this);
|
registerForProvisioningStateChange();
|
||||||
|
mBluetoothDeviceConfigListener = new BluetoothDeviceConfigListener(this, DBG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2219,12 +2250,25 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
|
mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
|
||||||
if (mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
|
if (mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
|
||||||
|
Slog.i(TAG, "Delaying MESSAGE_INIT_FLAGS_CHANGED by "
|
||||||
|
+ DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS
|
||||||
|
+ " ms due to existing connections");
|
||||||
|
mHandler.sendEmptyMessageDelayed(
|
||||||
|
MESSAGE_INIT_FLAGS_CHANGED,
|
||||||
|
DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!isDeviceProvisioned()) {
|
||||||
|
Slog.i(TAG, "Delaying MESSAGE_INIT_FLAGS_CHANGED by "
|
||||||
|
+ DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS
|
||||||
|
+ "ms because device is not provisioned");
|
||||||
mHandler.sendEmptyMessageDelayed(
|
mHandler.sendEmptyMessageDelayed(
|
||||||
MESSAGE_INIT_FLAGS_CHANGED,
|
MESSAGE_INIT_FLAGS_CHANGED,
|
||||||
DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS);
|
DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mBluetooth != null && isEnabled()) {
|
if (mBluetooth != null && isEnabled()) {
|
||||||
|
Slog.i(TAG, "Restarting Bluetooth due to init flag change");
|
||||||
restartForReason(
|
restartForReason(
|
||||||
BluetoothProtoEnums.ENABLE_DISABLE_REASON_INIT_FLAGS_CHANGED);
|
BluetoothProtoEnums.ENABLE_DISABLE_REASON_INIT_FLAGS_CHANGED);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user