summaryrefslogtreecommitdiff
path: root/service/java/com/android/server/bluetooth/BluetoothManagerService.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-10-16 18:18:52 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-10-16 18:18:52 +0000
commit21faba04a5889f5b7a87f7341b6211cfac6dcf1d (patch)
tree94eb412c687267e805ae5c04bd6c66bc20bf925b /service/java/com/android/server/bluetooth/BluetoothManagerService.java
parent132375e71f4f9695a79d5b8419994659dcf7de54 (diff)
parent6bdddb9eb88fb5d5ccce25e134600181d5103bcf (diff)
Merge changes I93fa880a,Ib036852a,Ic5ab3c04,I4452eacf am: 20909a93b0 am: afedf5268f am: 6bdddb9eb8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1462704 Change-Id: I87ac274a0c1a61a9211af85965c188ac4b30965a
Diffstat (limited to 'service/java/com/android/server/bluetooth/BluetoothManagerService.java')
-rw-r--r--service/java/com/android/server/bluetooth/BluetoothManagerService.java65
1 files changed, 35 insertions, 30 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
index 63b77167a2..0b8b352640 100644
--- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@@ -23,7 +23,9 @@ import android.Manifest;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.AppOpsManager;
+import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.IBluetooth;
@@ -63,7 +65,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.os.UserManagerInternal.UserRestrictionsListener;
-import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
@@ -118,6 +119,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// Delay for retrying enable and disable in msec
private static final int ENABLE_DISABLE_DELAY_MS = 300;
private static final int DELAY_BEFORE_RESTART_DUE_TO_INIT_FLAGS_CHANGED_MS = 300;
+ private static final int DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS = 86400;
private static final int MESSAGE_ENABLE = 1;
private static final int MESSAGE_DISABLE = 2;
@@ -177,8 +179,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private int mWaitForEnableRetry;
private int mWaitForDisableRetry;
+ private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
+
private BluetoothAirplaneModeListener mBluetoothAirplaneModeListener;
+ private BluetoothDeviceConfigListener mBluetoothDeviceConfigListener;
+
// used inside handler thread
private boolean mQuietEnable = false;
private boolean mEnable;
@@ -283,29 +289,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
};
- private final DeviceConfig.OnPropertiesChangedListener mDeviceConfigChangedListener =
- new DeviceConfig.OnPropertiesChangedListener() {
- @Override
- public void onPropertiesChanged(DeviceConfig.Properties properties) {
- if (!properties.getNamespace().equals(DeviceConfig.NAMESPACE_BLUETOOTH)) {
- return;
- }
- boolean foundInit = false;
- for (String name : properties.getKeyset()) {
- if (name.startsWith("INIT_")) {
- foundInit = true;
- break;
- }
- }
- if (!foundInit) {
- return;
- }
- mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
- mHandler.sendEmptyMessageDelayed(
- MESSAGE_INIT_FLAGS_CHANGED,
- DELAY_BEFORE_RESTART_DUE_TO_INIT_FLAGS_CHANGED_MS);
- }
- };
+ @VisibleForTesting
+ public void onInitFlagsChanged() {
+ mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
+ mHandler.sendEmptyMessageDelayed(
+ MESSAGE_INIT_FLAGS_CHANGED,
+ DELAY_BEFORE_RESTART_DUE_TO_INIT_FLAGS_CHANGED_MS);
+ }
public boolean onFactoryReset() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
@@ -456,6 +446,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mHandler.sendMessage(msg);
}
}
+ } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(action)
+ || BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+ final int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
+ BluetoothProfile.STATE_CONNECTED);
+ if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
+ && state == BluetoothProfile.STATE_DISCONNECTED
+ && !mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
+ onInitFlagsChanged();
+ }
}
}
};
@@ -506,6 +505,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
filter.addAction(BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED);
filter.addAction(Intent.ACTION_SETTING_RESTORED);
+ filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
+ filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
mContext.registerReceiver(mReceiver, filter);
@@ -540,10 +541,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
Slog.w(TAG, "Unable to resolve SystemUI's UID.");
}
mSystemUiUid = systemUiUid;
- DeviceConfig.addOnPropertiesChangedListener(
- DeviceConfig.NAMESPACE_BLUETOOTH,
- (Runnable r) -> r.run(),
- mDeviceConfigChangedListener);
}
/**
@@ -1373,10 +1370,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
Message getMsg = mHandler.obtainMessage(MESSAGE_GET_NAME_AND_ADDRESS);
mHandler.sendMessage(getMsg);
}
+
+ mBluetoothModeChangeHelper = new BluetoothModeChangeHelper(mContext);
if (mBluetoothAirplaneModeListener != null) {
- mBluetoothAirplaneModeListener.start(
- new BluetoothAirplaneModeListener.AirplaneModeHelper(mContext));
+ mBluetoothAirplaneModeListener.start(mBluetoothModeChangeHelper);
}
+ mBluetoothDeviceConfigListener = new BluetoothDeviceConfigListener(this);
}
/**
@@ -2219,6 +2218,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
Slog.d(TAG, "MESSAGE_INIT_FLAGS_CHANGED");
}
mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
+ if (mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
+ mHandler.sendEmptyMessageDelayed(
+ MESSAGE_INIT_FLAGS_CHANGED,
+ DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS);
+ break;
+ }
if (mBluetooth != null && isEnabled()) {
restartForReason(
BluetoothProtoEnums.ENABLE_DISABLE_REASON_INIT_FLAGS_CHANGED);