Merge changes I602b1fa8,I006ca18d into udc-dev

* changes:
  [Bluetooth] Add NEW_BLUETOOTH_REPOSITORY flag.
  [Bluetooth] Remove unused methods from BluetoothController interface.
This commit is contained in:
Caitlin Shkuratov
2023-05-03 17:26:38 +00:00
committed by Android (Google) Code Review
5 changed files with 9 additions and 164 deletions

View File

@@ -331,6 +331,11 @@ object Flags {
// TODO(b/265892345): Tracking Bug
val PLUG_IN_STATUS_BAR_CHIP = releasedFlag(265892345, "plug_in_status_bar_chip")
// TODO(b/280426085): Tracking Bug
@JvmField
val NEW_BLUETOOTH_REPOSITORY =
unreleasedFlag(612, "new_bluetooth_repository", teamfood = true)
// 700 - dialer/calls
// TODO(b/254512734): Tracking Bug
val ONGOING_CALL_STATUS_BAR_CHIP = releasedFlag(700, "ongoing_call_status_bar_chip")

View File

@@ -22,7 +22,6 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.policy.BluetoothController.Callback;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
@@ -38,13 +37,9 @@ public interface BluetoothController extends CallbackController<Callback>, Dumpa
boolean isBluetoothAudioActive();
String getConnectedDeviceName();
void setBluetoothEnabled(boolean enabled);
Collection<CachedBluetoothDevice> getDevices();
void connect(CachedBluetoothDevice device);
void disconnect(CachedBluetoothDevice device);
boolean canConfigBluetooth();
int getMaxConnectionState(CachedBluetoothDevice device);
int getBondState(CachedBluetoothDevice device);
List<CachedBluetoothDevice> getConnectedDevices();
void addOnMetadataChangedListener(CachedBluetoothDevice device, Executor executor,

View File

@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.policy;
import android.annotation.Nullable;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Handler;
@@ -37,17 +36,15 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfile;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.systemui.bluetooth.BluetoothLogger;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.settings.UserTracker;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.WeakHashMap;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -64,9 +61,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
private final LocalBluetoothManager mLocalBluetoothManager;
private final UserManager mUserManager;
private final int mCurrentUser;
private final WeakHashMap<CachedBluetoothDevice, ActuallyCachedState> mCachedState =
new WeakHashMap<>();
private final Handler mBgHandler;
@GuardedBy("mConnectedDevices")
private final List<CachedBluetoothDevice> mConnectedDevices = new ArrayList<>();
@@ -88,14 +82,12 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
UserTracker userTracker,
DumpManager dumpManager,
BluetoothLogger logger,
@Background Looper bgLooper,
@Main Looper mainLooper,
@Nullable LocalBluetoothManager localBluetoothManager,
@Nullable BluetoothAdapter bluetoothAdapter) {
mDumpManager = dumpManager;
mLogger = logger;
mLocalBluetoothManager = localBluetoothManager;
mBgHandler = new Handler(bgLooper);
mHandler = new H(mainLooper);
if (mLocalBluetoothManager != null) {
mLocalBluetoothManager.getEventManager().registerCallback(this);
@@ -151,7 +143,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
private String getDeviceString(CachedBluetoothDevice device) {
return device.getName()
+ " bondState=" + device.getBondState()
+ " connected=" + device.isConnected()
+ " active[A2DP]=" + device.isActiveDevice(BluetoothProfile.A2DP)
+ " active[HEADSET]=" + device.isActiveDevice(BluetoothProfile.HEADSET)
@@ -159,11 +150,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
+ " active[LE_AUDIO]=" + device.isActiveDevice(BluetoothProfile.LE_AUDIO);
}
@Override
public int getBondState(CachedBluetoothDevice device) {
return getCachedState(device).mBondState;
}
@Override
public List<CachedBluetoothDevice> getConnectedDevices() {
List<CachedBluetoothDevice> out;
@@ -173,11 +159,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
return out;
}
@Override
public int getMaxConnectionState(CachedBluetoothDevice device) {
return getCachedState(device).mMaxConnectionState;
}
@Override
public void addCallback(@NonNull Callback cb) {
mHandler.obtainMessage(H.MSG_ADD_CALLBACK, cb).sendToTarget();
@@ -231,18 +212,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
return mLocalBluetoothManager != null;
}
@Override
public void connect(final CachedBluetoothDevice device) {
if (mLocalBluetoothManager == null || device == null) return;
device.connect(true);
}
@Override
public void disconnect(CachedBluetoothDevice device) {
if (mLocalBluetoothManager == null || device == null) return;
device.disconnect();
}
@Override
public String getConnectedDeviceName() {
synchronized (mConnectedDevices) {
@@ -253,11 +222,10 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
return null;
}
@Override
public Collection<CachedBluetoothDevice> getDevices() {
private Collection<CachedBluetoothDevice> getDevices() {
return mLocalBluetoothManager != null
? mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()
: null;
: Collections.emptyList();
}
private void updateConnected() {
@@ -354,7 +322,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
@Override
public void onDeviceDeleted(@NonNull CachedBluetoothDevice cachedDevice) {
mLogger.logDeviceDeleted(cachedDevice.getAddress());
mCachedState.remove(cachedDevice);
updateConnected();
mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED);
}
@@ -363,7 +330,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
public void onDeviceBondStateChanged(
@NonNull CachedBluetoothDevice cachedDevice, int bondState) {
mLogger.logBondStateChange(cachedDevice.getAddress(), bondState);
mCachedState.remove(cachedDevice);
updateConnected();
mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED);
}
@@ -381,7 +347,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
@ConnectionState int state) {
mLogger.logDeviceConnectionStateChanged(
getAddressOrNull(cachedDevice), connectionStateToString(state));
mCachedState.remove(cachedDevice);
updateConnected();
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
}
@@ -393,7 +358,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
int bluetoothProfile) {
mLogger.logProfileConnectionStateChanged(
cachedDevice.getAddress(), connectionStateToString(state), bluetoothProfile);
mCachedState.remove(cachedDevice);
updateConnected();
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
}
@@ -411,7 +375,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
@NonNull CachedBluetoothDevice cachedDevice, int state) {
mLogger.logAclConnectionStateChanged(
cachedDevice.getAddress(), connectionStateToString(state));
mCachedState.remove(cachedDevice);
updateConnected();
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
}
@@ -440,17 +403,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
);
}
private ActuallyCachedState getCachedState(CachedBluetoothDevice device) {
ActuallyCachedState state = mCachedState.get(device);
if (state == null) {
state = new ActuallyCachedState(device, mHandler);
mBgHandler.post(state);
mCachedState.put(device, state);
return state;
}
return state;
}
@Nullable
private String getAddressOrNull(@Nullable CachedBluetoothDevice device) {
return device == null ? null : device.getAddress();
@@ -465,30 +417,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
@Override
public void onServiceDisconnected() {}
private static class ActuallyCachedState implements Runnable {
private final WeakReference<CachedBluetoothDevice> mDevice;
private final Handler mUiHandler;
private int mBondState = BluetoothDevice.BOND_NONE;
private int mMaxConnectionState = BluetoothProfile.STATE_DISCONNECTED;
private ActuallyCachedState(CachedBluetoothDevice device, Handler uiHandler) {
mDevice = new WeakReference<>(device);
mUiHandler = uiHandler;
}
@Override
public void run() {
CachedBluetoothDevice device = mDevice.get();
if (device != null) {
mBondState = device.getBondState();
mMaxConnectionState = device.getMaxConnectionState();
mUiHandler.removeMessages(H.MSG_PAIRED_DEVICES_CHANGED);
mUiHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED);
}
}
}
private final class H extends Handler {
private final ArrayList<BluetoothController.Callback> mCallbacks = new ArrayList<>();

View File

@@ -94,7 +94,6 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
mMockDumpManager,
mock(BluetoothLogger.class),
mTestableLooper.getLooper(),
mTestableLooper.getLooper(),
mMockBluetoothManager,
mMockAdapter);
}
@@ -113,62 +112,6 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
assertTrue(mBluetoothControllerImpl.isBluetoothConnected());
}
@Test
public void testDefaultConnectionState() {
CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
assertEquals(BluetoothDevice.BOND_NONE, mBluetoothControllerImpl.getBondState(device));
assertEquals(BluetoothProfile.STATE_DISCONNECTED,
mBluetoothControllerImpl.getMaxConnectionState(device));
}
@Test
public void testAsyncBondState() throws Exception {
CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
when(device.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
mBluetoothControllerImpl.addCallback(callback);
// Trigger the state getting.
assertEquals(BluetoothDevice.BOND_NONE, mBluetoothControllerImpl.getBondState(device));
mTestableLooper.processAllMessages();
assertEquals(BluetoothDevice.BOND_BONDED, mBluetoothControllerImpl.getBondState(device));
verify(callback).onBluetoothDevicesChanged();
}
@Test
public void testAsyncConnectionState() throws Exception {
CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED);
BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
mBluetoothControllerImpl.addCallback(callback);
// Trigger the state getting.
assertEquals(BluetoothProfile.STATE_DISCONNECTED,
mBluetoothControllerImpl.getMaxConnectionState(device));
mTestableLooper.processAllMessages();
assertEquals(BluetoothProfile.STATE_CONNECTED,
mBluetoothControllerImpl.getMaxConnectionState(device));
verify(callback).onBluetoothDevicesChanged();
}
@Test
public void testNullAsync_DoesNotCrash() throws Exception {
CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED);
BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
mBluetoothControllerImpl.addCallback(callback);
// Trigger the state getting.
assertEquals(BluetoothProfile.STATE_DISCONNECTED,
mBluetoothControllerImpl.getMaxConnectionState(null));
mTestableLooper.processAllMessages();
}
@Test
public void testOnServiceConnected_updatesConnectionState() {
when(mMockLocalAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING);

View File

@@ -21,7 +21,6 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.BluetoothController.Callback;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
@@ -78,36 +77,11 @@ public class FakeBluetoothController extends BaseLeakChecker<Callback> implement
}
@Override
public Collection<CachedBluetoothDevice> getDevices() {
return null;
}
@Override
public void connect(CachedBluetoothDevice device) {
}
@Override
public void disconnect(CachedBluetoothDevice device) {
}
@Override
public boolean canConfigBluetooth() {
return false;
}
@Override
public int getMaxConnectionState(CachedBluetoothDevice device) {
return 0;
}
@Override
public int getBondState(CachedBluetoothDevice device) {
return 0;
}
@Override
public List<CachedBluetoothDevice> getConnectedDevices() {
return Collections.emptyList();