Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +10 −0 Original line number Diff line number Diff line Loading @@ -163,6 +163,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mUnpairing = false; } /** Clears any pending messages in the message queue. */ public void release() { mHandler.removeCallbacksAndMessages(null); } private void initDrawableCache() { int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 8; Loading Loading @@ -1441,11 +1446,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> final boolean tmpJustDiscovered = mJustDiscovered; final HearingAidInfo tmpHearingAidInfo = mHearingAidInfo; // Set main device from sub device release(); mDevice = mSubDevice.mDevice; mRssi = mSubDevice.mRssi; mJustDiscovered = mSubDevice.mJustDiscovered; mHearingAidInfo = mSubDevice.mHearingAidInfo; // Set sub device from backup mSubDevice.release(); mSubDevice.mDevice = tmpDevice; mSubDevice.mRssi = tmpRssi; mSubDevice.mJustDiscovered = tmpJustDiscovered; Loading @@ -1471,6 +1478,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> * Remove a device from the member device sets. */ public void removeMemberDevice(CachedBluetoothDevice memberDevice) { memberDevice.release(); mMemberDevices.remove(memberDevice); } Loading @@ -1488,11 +1496,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> final short tmpRssi = mRssi; final boolean tmpJustDiscovered = mJustDiscovered; // Set main device from sub device release(); mDevice = newMainDevice.mDevice; mRssi = newMainDevice.mRssi; mJustDiscovered = newMainDevice.mJustDiscovered; // Set sub device from backup newMainDevice.release(); newMainDevice.mDevice = tmpDevice; newMainDevice.mRssi = tmpRssi; newMainDevice.mJustDiscovered = tmpJustDiscovered; Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +10 −2 Original line number Diff line number Diff line Loading @@ -223,8 +223,14 @@ public class CachedBluetoothDeviceManager { public synchronized void clearNonBondedDevices() { clearNonBondedSubDevices(); mCachedDevices.removeIf(cachedDevice -> cachedDevice.getBondState() == BluetoothDevice.BOND_NONE); final List<CachedBluetoothDevice> removedCachedDevice = new ArrayList<>(); mCachedDevices.stream() .filter(cachedDevice -> cachedDevice.getBondState() == BluetoothDevice.BOND_NONE) .forEach(cachedDevice -> { cachedDevice.release(); removedCachedDevice.add(cachedDevice); }); mCachedDevices.removeAll(removedCachedDevice); } private void clearNonBondedSubDevices() { Loading @@ -245,6 +251,7 @@ public class CachedBluetoothDeviceManager { if (subDevice != null && subDevice.getDevice().getBondState() == BluetoothDevice.BOND_NONE) { // Sub device exists and it is not bonded subDevice.release(); cachedDevice.setSubDevice(null); } } Loading Loading @@ -294,6 +301,7 @@ public class CachedBluetoothDeviceManager { } if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) { cachedDevice.setJustDiscovered(false); cachedDevice.release(); mCachedDevices.remove(i); } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -998,10 +998,12 @@ public class CachedBluetoothDeviceTest { mCachedDevice.switchSubDeviceContent(); verify(mCachedDevice).release(); assertThat(mCachedDevice.mRssi).isEqualTo(RSSI_2); assertThat(mCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2); assertThat(mCachedDevice.mDevice).isEqualTo(mSubDevice); assertThat(mCachedDevice.getDeviceSide()).isEqualTo(HearingAidInfo.DeviceSide.SIDE_RIGHT); verify(mSubCachedDevice).release(); assertThat(mSubCachedDevice.mRssi).isEqualTo(RSSI_1); assertThat(mSubCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1); assertThat(mSubCachedDevice.mDevice).isEqualTo(mDevice); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +10 −0 Original line number Diff line number Diff line Loading @@ -163,6 +163,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mUnpairing = false; } /** Clears any pending messages in the message queue. */ public void release() { mHandler.removeCallbacksAndMessages(null); } private void initDrawableCache() { int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 8; Loading Loading @@ -1441,11 +1446,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> final boolean tmpJustDiscovered = mJustDiscovered; final HearingAidInfo tmpHearingAidInfo = mHearingAidInfo; // Set main device from sub device release(); mDevice = mSubDevice.mDevice; mRssi = mSubDevice.mRssi; mJustDiscovered = mSubDevice.mJustDiscovered; mHearingAidInfo = mSubDevice.mHearingAidInfo; // Set sub device from backup mSubDevice.release(); mSubDevice.mDevice = tmpDevice; mSubDevice.mRssi = tmpRssi; mSubDevice.mJustDiscovered = tmpJustDiscovered; Loading @@ -1471,6 +1478,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> * Remove a device from the member device sets. */ public void removeMemberDevice(CachedBluetoothDevice memberDevice) { memberDevice.release(); mMemberDevices.remove(memberDevice); } Loading @@ -1488,11 +1496,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> final short tmpRssi = mRssi; final boolean tmpJustDiscovered = mJustDiscovered; // Set main device from sub device release(); mDevice = newMainDevice.mDevice; mRssi = newMainDevice.mRssi; mJustDiscovered = newMainDevice.mJustDiscovered; // Set sub device from backup newMainDevice.release(); newMainDevice.mDevice = tmpDevice; newMainDevice.mRssi = tmpRssi; newMainDevice.mJustDiscovered = tmpJustDiscovered; Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +10 −2 Original line number Diff line number Diff line Loading @@ -223,8 +223,14 @@ public class CachedBluetoothDeviceManager { public synchronized void clearNonBondedDevices() { clearNonBondedSubDevices(); mCachedDevices.removeIf(cachedDevice -> cachedDevice.getBondState() == BluetoothDevice.BOND_NONE); final List<CachedBluetoothDevice> removedCachedDevice = new ArrayList<>(); mCachedDevices.stream() .filter(cachedDevice -> cachedDevice.getBondState() == BluetoothDevice.BOND_NONE) .forEach(cachedDevice -> { cachedDevice.release(); removedCachedDevice.add(cachedDevice); }); mCachedDevices.removeAll(removedCachedDevice); } private void clearNonBondedSubDevices() { Loading @@ -245,6 +251,7 @@ public class CachedBluetoothDeviceManager { if (subDevice != null && subDevice.getDevice().getBondState() == BluetoothDevice.BOND_NONE) { // Sub device exists and it is not bonded subDevice.release(); cachedDevice.setSubDevice(null); } } Loading Loading @@ -294,6 +301,7 @@ public class CachedBluetoothDeviceManager { } if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) { cachedDevice.setJustDiscovered(false); cachedDevice.release(); mCachedDevices.remove(i); } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -998,10 +998,12 @@ public class CachedBluetoothDeviceTest { mCachedDevice.switchSubDeviceContent(); verify(mCachedDevice).release(); assertThat(mCachedDevice.mRssi).isEqualTo(RSSI_2); assertThat(mCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2); assertThat(mCachedDevice.mDevice).isEqualTo(mSubDevice); assertThat(mCachedDevice.getDeviceSide()).isEqualTo(HearingAidInfo.DeviceSide.SIDE_RIGHT); verify(mSubCachedDevice).release(); assertThat(mSubCachedDevice.mRssi).isEqualTo(RSSI_1); assertThat(mSubCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1); assertThat(mSubCachedDevice.mDevice).isEqualTo(mDevice); Loading