Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +19 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.internal.annotations.GuardedBy; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading Loading @@ -66,6 +67,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private final WeakHashMap<CachedBluetoothDevice, ActuallyCachedState> mCachedState = new WeakHashMap<>(); private final Handler mBgHandler; @GuardedBy("mConnectedDevices") private final List<CachedBluetoothDevice> mConnectedDevices = new ArrayList<>(); private boolean mEnabled; Loading Loading @@ -118,7 +120,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa pw.print(" mConnectionState="); pw.println(stateToString(mConnectionState)); pw.print(" mAudioProfileOnly="); pw.println(mAudioProfileOnly); pw.print(" mIsActive="); pw.println(mIsActive); pw.print(" mConnectedDevices="); pw.println(mConnectedDevices); pw.print(" mConnectedDevices="); pw.println(getConnectedDevices()); pw.print(" mCallbacks.size="); pw.println(mHandler.mCallbacks.size()); pw.println(" Bluetooth Devices:"); for (CachedBluetoothDevice device : getDevices()) { Loading Loading @@ -151,7 +153,11 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public List<CachedBluetoothDevice> getConnectedDevices() { return mConnectedDevices; List<CachedBluetoothDevice> out; synchronized (mConnectedDevices) { out = new ArrayList<>(mConnectedDevices); } return out; } @Override Loading Loading @@ -226,9 +232,11 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public String getConnectedDeviceName() { synchronized (mConnectedDevices) { if (mConnectedDevices.size() == 1) { return mConnectedDevices.get(0).getName(); } } return null; } Loading @@ -242,7 +250,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private void updateConnected() { // Make sure our connection state is up to date. int state = mLocalBluetoothManager.getBluetoothAdapter().getConnectionState(); mConnectedDevices.clear(); List<CachedBluetoothDevice> newList = new ArrayList<>(); // If any of the devices are in a higher state than the adapter, move the adapter into // that state. for (CachedBluetoothDevice device : getDevices()) { Loading @@ -251,15 +259,19 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa state = maxDeviceState; } if (device.isConnected()) { mConnectedDevices.add(device); newList.add(device); } } if (mConnectedDevices.isEmpty() && state == BluetoothAdapter.STATE_CONNECTED) { if (newList.isEmpty() && state == BluetoothAdapter.STATE_CONNECTED) { // If somehow we think we are connected, but have no connected devices, we aren't // connected. state = BluetoothAdapter.STATE_DISCONNECTED; } synchronized (mConnectedDevices) { mConnectedDevices.clear(); mConnectedDevices.addAll(newList); } if (state != mConnectionState) { mConnectionState = state; mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +19 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.internal.annotations.GuardedBy; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading Loading @@ -66,6 +67,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private final WeakHashMap<CachedBluetoothDevice, ActuallyCachedState> mCachedState = new WeakHashMap<>(); private final Handler mBgHandler; @GuardedBy("mConnectedDevices") private final List<CachedBluetoothDevice> mConnectedDevices = new ArrayList<>(); private boolean mEnabled; Loading Loading @@ -118,7 +120,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa pw.print(" mConnectionState="); pw.println(stateToString(mConnectionState)); pw.print(" mAudioProfileOnly="); pw.println(mAudioProfileOnly); pw.print(" mIsActive="); pw.println(mIsActive); pw.print(" mConnectedDevices="); pw.println(mConnectedDevices); pw.print(" mConnectedDevices="); pw.println(getConnectedDevices()); pw.print(" mCallbacks.size="); pw.println(mHandler.mCallbacks.size()); pw.println(" Bluetooth Devices:"); for (CachedBluetoothDevice device : getDevices()) { Loading Loading @@ -151,7 +153,11 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public List<CachedBluetoothDevice> getConnectedDevices() { return mConnectedDevices; List<CachedBluetoothDevice> out; synchronized (mConnectedDevices) { out = new ArrayList<>(mConnectedDevices); } return out; } @Override Loading Loading @@ -226,9 +232,11 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public String getConnectedDeviceName() { synchronized (mConnectedDevices) { if (mConnectedDevices.size() == 1) { return mConnectedDevices.get(0).getName(); } } return null; } Loading @@ -242,7 +250,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private void updateConnected() { // Make sure our connection state is up to date. int state = mLocalBluetoothManager.getBluetoothAdapter().getConnectionState(); mConnectedDevices.clear(); List<CachedBluetoothDevice> newList = new ArrayList<>(); // If any of the devices are in a higher state than the adapter, move the adapter into // that state. for (CachedBluetoothDevice device : getDevices()) { Loading @@ -251,15 +259,19 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa state = maxDeviceState; } if (device.isConnected()) { mConnectedDevices.add(device); newList.add(device); } } if (mConnectedDevices.isEmpty() && state == BluetoothAdapter.STATE_CONNECTED) { if (newList.isEmpty() && state == BluetoothAdapter.STATE_CONNECTED) { // If somehow we think we are connected, but have no connected devices, we aren't // connected. state = BluetoothAdapter.STATE_DISCONNECTED; } synchronized (mConnectedDevices) { mConnectedDevices.clear(); mConnectedDevices.addAll(newList); } if (state != mConnectionState) { mConnectionState = state; mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); Loading