BluetoothManagerService: Separate DeviceConfigListener
Use its own class instead. Test: FrameworksServicesTests Test: Push bluetooth INIT_ flags Change-Id: I4452eacffd11020b6c8fa1cb2854fb91c11cac69
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server;
|
||||
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
/**
|
||||
* The BluetoothDeviceConfigListener handles system device config change callback and checks
|
||||
* whether we need to inform BluetoothManagerService on this change.
|
||||
*
|
||||
* The information of device config change would not be passed to the BluetoothManagerService
|
||||
* when Bluetooth is on and Bluetooth is in one of the following situations:
|
||||
* 1. Bluetooth A2DP is connected.
|
||||
* 2. Bluetooth Hearing Aid profile is connected.
|
||||
*/
|
||||
class BluetoothDeviceConfigListener {
|
||||
private static final String TAG = "BluetoothDeviceConfigListener";
|
||||
|
||||
BluetoothManagerService mService;
|
||||
|
||||
BluetoothDeviceConfigListener(BluetoothManagerService service) {
|
||||
mService = service;
|
||||
DeviceConfig.addOnPropertiesChangedListener(
|
||||
DeviceConfig.NAMESPACE_BLUETOOTH,
|
||||
(Runnable r) -> r.run(),
|
||||
mDeviceConfigChangedListener);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
mService.onInitFlagsChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -63,7 +63,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;
|
||||
@@ -177,6 +176,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
||||
|
||||
private BluetoothAirplaneModeListener mBluetoothAirplaneModeListener;
|
||||
|
||||
private BluetoothDeviceConfigListener mBluetoothDeviceConfigListener;
|
||||
|
||||
// used inside handler thread
|
||||
private boolean mQuietEnable = false;
|
||||
private boolean mEnable;
|
||||
@@ -281,29 +282,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() {
|
||||
// Wait for stable state if bluetooth is temporary state.
|
||||
@@ -535,10 +520,7 @@ 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);
|
||||
mBluetoothDeviceConfigListener = new BluetoothDeviceConfigListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user