From c17d3298255357ce6e49d889cb4548e33004344c Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Sat, 30 Jan 2016 12:49:41 -0500 Subject: [PATCH] Fix rare crash in bt detail panel Since bond state is gotten directly from the bluetooth stack it is possible it could change, and therefore change the number of devices if pairing happens while the detail panel is updating. Fix this by just dropping them into a list. Bug: 26258223 Change-Id: I7703520391798fd7c9ab097b0057b7b43b877212 --- .../systemui/qs/tiles/BluetoothTile.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java index dbb7423f6e562..874fc3ec0b881 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java @@ -34,6 +34,7 @@ import com.android.systemui.qs.QSDetailItems.Item; import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.BluetoothController; +import java.util.ArrayList; import java.util.Collection; /** Quick settings tile: Bluetooth **/ @@ -217,11 +218,9 @@ public class BluetoothTile extends QSTile { private void updateItems() { if (mItems == null) return; - Item[] items = null; + ArrayList items = new ArrayList(); final Collection devices = mController.getDevices(); if (devices != null) { - items = new Item[getBondedCount(devices)]; - int i = 0; for (CachedBluetoothDevice device : devices) { if (device.getBondState() == BluetoothDevice.BOND_NONE) continue; final Item item = new Item(); @@ -237,20 +236,10 @@ public class BluetoothTile extends QSTile { item.line2 = mContext.getString(R.string.quick_settings_connecting); } item.tag = device; - items[i++] = item; + items.add(item); } } - mItems.setItems(items); - } - - private int getBondedCount(Collection devices) { - int ct = 0; - for (CachedBluetoothDevice device : devices) { - if (device.getBondState() != BluetoothDevice.BOND_NONE) { - ct++; - } - } - return ct; + mItems.setItems(items.toArray(new Item[items.size()])); } @Override