From 8ffe58d79446a498faf174d9c660d25c05a235b2 Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Fri, 7 May 2021 21:33:17 +0800 Subject: [PATCH] [ANR] Read device icon on the main thread -com.android.systemui - Main thread blockedat android.provider.MediaStore$Images$Media.getBitmapat com.android.settingslib.bluetooth.BluetoothUtils.getBtDrawableWithDescrip... -move it to background thread Bug: 184924171 Test: atest MediaOutputAdapterTest Change-Id: I50908fbd429d366ec794511046c8f62dfa80b6ac --- .../media/dialog/MediaOutputBaseAdapter.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java index c6373f5e0c5f5..bcef43c93be45 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java @@ -24,6 +24,7 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.Typeface; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -41,6 +42,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.media.MediaDevice; +import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.R; import com.android.systemui.animation.Interpolators; @@ -116,6 +118,7 @@ public abstract class MediaOutputBaseAdapter extends final View mDivider; final View mBottomDivider; final CheckBox mCheckBox; + private String mDeviceId; MediaDeviceBaseViewHolder(View view) { super(view); @@ -134,8 +137,17 @@ public abstract class MediaOutputBaseAdapter extends } void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) { - mTitleIcon.setImageIcon(mController.getDeviceIconCompat(device).toIcon(mContext)); - setMargin(topMargin, bottomMargin); + mDeviceId = device.getId(); + ThreadUtils.postOnBackgroundThread(() -> { + Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext); + ThreadUtils.postOnMainThread(() -> { + if (!TextUtils.equals(mDeviceId, device.getId())) { + return; + } + mTitleIcon.setImageIcon(icon); + setMargin(topMargin, bottomMargin); + }); + }); } void onBind(int customizedItem, boolean topMargin, boolean bottomMargin) {