To refresh/register/unregister all of the devices with same groupId am: ef7a75c394
am: 64281594d1
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23308381 Change-Id: Ie19c94f9bc88263312d1e1d1ac0c6c728993b7f8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothCsipSetCoordinator;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -89,7 +88,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
mManager = manager;
|
mManager = manager;
|
||||||
mProfileManager = mManager.getProfileManager();
|
mProfileManager = mManager.getProfileManager();
|
||||||
mCachedDevice = device;
|
mCachedDevice = device;
|
||||||
mAllOfCachedDevices = getAllOfCachedBluetoothDevices();
|
mAllOfCachedDevices = Utils.getAllOfCachedBluetoothDevices(mContext, mCachedDevice);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,20 +318,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CachedBluetoothDevice> getAllOfCachedBluetoothDevices() {
|
|
||||||
List<CachedBluetoothDevice> cachedBluetoothDevices = new ArrayList<>();
|
|
||||||
if (mCachedDevice == null) {
|
|
||||||
return cachedBluetoothDevices;
|
|
||||||
}
|
|
||||||
cachedBluetoothDevices.add(mCachedDevice);
|
|
||||||
if (mCachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
|
||||||
for (CachedBluetoothDevice member : mCachedDevice.getMemberDevice()) {
|
|
||||||
cachedBluetoothDevices.add(member);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cachedBluetoothDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices.
|
* Disable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices.
|
||||||
*
|
*
|
||||||
@@ -480,7 +465,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
item.unregisterCallback(this);
|
item.unregisterCallback(this);
|
||||||
}
|
}
|
||||||
mAllOfCachedDevices = getAllOfCachedBluetoothDevices();
|
mAllOfCachedDevices = Utils.getAllOfCachedBluetoothDevices(mContext, mCachedDevice);
|
||||||
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
item.registerCallback(this);
|
item.registerCallback(this);
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothCsipSetCoordinator;
|
|
||||||
import android.bluetooth.BluetoothLeAudio;
|
import android.bluetooth.BluetoothLeAudio;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -48,7 +47,6 @@ import com.android.settingslib.core.lifecycle.events.OnStart;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +89,7 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
LayoutPreference mLayoutPreference;
|
LayoutPreference mLayoutPreference;
|
||||||
private CachedBluetoothDevice mCachedDevice;
|
private CachedBluetoothDevice mCachedDevice;
|
||||||
private List<CachedBluetoothDevice> mLeAudioDevices;
|
private List<CachedBluetoothDevice> mAllOfCachedDevices;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Handler mHandler = new Handler(Looper.getMainLooper());
|
Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -129,13 +127,9 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mIsRegisterCallback = true;
|
mIsRegisterCallback = true;
|
||||||
if (mLeAudioDevices != null && !mLeAudioDevices.isEmpty()) {
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
for (CachedBluetoothDevice item : mLeAudioDevices) {
|
|
||||||
item.registerCallback(this);
|
item.registerCallback(this);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mCachedDevice.registerCallback(this);
|
|
||||||
}
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,13 +138,10 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
if (!mIsRegisterCallback) {
|
if (!mIsRegisterCallback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mLeAudioDevices != null && !mLeAudioDevices.isEmpty()) {
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
for (CachedBluetoothDevice item : mLeAudioDevices) {
|
|
||||||
item.unregisterCallback(this);
|
item.unregisterCallback(this);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mCachedDevice.unregisterCallback(this);
|
|
||||||
}
|
|
||||||
mIsRegisterCallback = false;
|
mIsRegisterCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,8 +153,7 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
LocalBluetoothManager bluetoothManager) {
|
LocalBluetoothManager bluetoothManager) {
|
||||||
mCachedDevice = cachedBluetoothDevice;
|
mCachedDevice = cachedBluetoothDevice;
|
||||||
mProfileManager = bluetoothManager.getProfileManager();
|
mProfileManager = bluetoothManager.getProfileManager();
|
||||||
mLeAudioDevices = getAllOfLeAudioDevices();
|
mAllOfCachedDevices = Utils.getAllOfCachedBluetoothDevices(mContext, mCachedDevice);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -234,26 +224,11 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
updateBatteryLayout(R.id.bt_battery_right, BluetoothUtils.META_INT_ERROR);
|
updateBatteryLayout(R.id.bt_battery_right, BluetoothUtils.META_INT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CachedBluetoothDevice> getAllOfLeAudioDevices() {
|
|
||||||
if (mCachedDevice == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<CachedBluetoothDevice> leAudioDevices = new ArrayList<>();
|
|
||||||
leAudioDevices.add(mCachedDevice);
|
|
||||||
if (mCachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
|
||||||
for (CachedBluetoothDevice member : mCachedDevice.getMemberDevice()) {
|
|
||||||
leAudioDevices.add(member);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.d(TAG, "mLeAudioDevices is " + mLeAudioDevices);
|
|
||||||
return leAudioDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBatteryLayout() {
|
private void updateBatteryLayout() {
|
||||||
// Init the battery layouts.
|
// Init the battery layouts.
|
||||||
hideAllOfBatteryLayouts();
|
hideAllOfBatteryLayouts();
|
||||||
LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
|
LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
|
||||||
if (mLeAudioDevices == null || mLeAudioDevices.isEmpty()) {
|
if (mAllOfCachedDevices.isEmpty()) {
|
||||||
Log.e(TAG, "There is no LeAudioProfile.");
|
Log.e(TAG, "There is no LeAudioProfile.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -267,7 +242,7 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CachedBluetoothDevice cachedDevice : mLeAudioDevices) {
|
for (CachedBluetoothDevice cachedDevice : mAllOfCachedDevices) {
|
||||||
int deviceId = leAudioProfile.getAudioLocation(cachedDevice.getDevice());
|
int deviceId = leAudioProfile.getAudioLocation(cachedDevice.getDevice());
|
||||||
Log.d(TAG, "LeAudioDevices:" + cachedDevice.getDevice().getAnonymizedAddress()
|
Log.d(TAG, "LeAudioDevices:" + cachedDevice.getDevice().getAnonymizedAddress()
|
||||||
+ ", deviceId:" + deviceId);
|
+ ", deviceId:" + deviceId);
|
||||||
@@ -322,7 +297,15 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeviceAttributesChanged() {
|
public void onDeviceAttributesChanged() {
|
||||||
if (mCachedDevice != null) {
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
|
item.unregisterCallback(this);
|
||||||
|
}
|
||||||
|
mAllOfCachedDevices = Utils.getAllOfCachedBluetoothDevices(mContext, mCachedDevice);
|
||||||
|
for (CachedBluetoothDevice item : mAllOfCachedDevices) {
|
||||||
|
item.registerCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mAllOfCachedDevices.isEmpty()) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
|
|||||||
import static android.os.Process.BLUETOOTH_UID;
|
import static android.os.Process.BLUETOOTH_UID;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -39,9 +40,12 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
|
|
||||||
@@ -225,4 +229,47 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
throw new NameNotFoundException("Could not find main bluetooth package");
|
throw new NameNotFoundException("Could not find main bluetooth package");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all cachedBluetoothDevices with the same groupId.
|
||||||
|
* @param cachedBluetoothDevice The main cachedBluetoothDevice.
|
||||||
|
* @return all cachedBluetoothDevices with the same groupId.
|
||||||
|
*/
|
||||||
|
public static List<CachedBluetoothDevice> getAllOfCachedBluetoothDevices(Context context,
|
||||||
|
CachedBluetoothDevice cachedBluetoothDevice) {
|
||||||
|
List<CachedBluetoothDevice> cachedBluetoothDevices = new ArrayList<>();
|
||||||
|
if (cachedBluetoothDevice == null) {
|
||||||
|
Log.e(TAG, "getAllOfCachedBluetoothDevices: no cachedBluetoothDevice");
|
||||||
|
return cachedBluetoothDevices;
|
||||||
|
}
|
||||||
|
int deviceGroupId = cachedBluetoothDevice.getGroupId();
|
||||||
|
if (deviceGroupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
||||||
|
cachedBluetoothDevices.add(cachedBluetoothDevice);
|
||||||
|
return cachedBluetoothDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
final LocalBluetoothManager localBtMgr = Utils.getLocalBtManager(context);
|
||||||
|
if (localBtMgr == null) {
|
||||||
|
Log.e(TAG, "getAllOfCachedBluetoothDevices: no LocalBluetoothManager");
|
||||||
|
return cachedBluetoothDevices;
|
||||||
|
}
|
||||||
|
CachedBluetoothDevice mainDevice =
|
||||||
|
localBtMgr.getCachedDeviceManager().getCachedDevicesCopy().stream()
|
||||||
|
.filter(cachedDevice -> cachedDevice.getGroupId() == deviceGroupId)
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
if (mainDevice == null) {
|
||||||
|
Log.e(TAG, "getAllOfCachedBluetoothDevices: groupId = " + deviceGroupId
|
||||||
|
+ ", no main device.");
|
||||||
|
return cachedBluetoothDevices;
|
||||||
|
}
|
||||||
|
cachedBluetoothDevice = mainDevice;
|
||||||
|
cachedBluetoothDevices.add(cachedBluetoothDevice);
|
||||||
|
for (CachedBluetoothDevice member : cachedBluetoothDevice.getMemberDevice()) {
|
||||||
|
cachedBluetoothDevices.add(member);
|
||||||
|
}
|
||||||
|
Log.d(TAG, "getAllOfCachedBluetoothDevices: groupId = " + deviceGroupId
|
||||||
|
+ " , cachedBluetoothDevice = " + cachedBluetoothDevice
|
||||||
|
+ " , deviceList = " + cachedBluetoothDevices);
|
||||||
|
return cachedBluetoothDevices;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user