Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ffe58d7 authored by Tim Peng's avatar Tim Peng
Browse files

[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
parent 99692410
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Typeface;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.text.TextUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
@@ -41,6 +42,7 @@ import androidx.recyclerview.widget.RecyclerView;


import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.animation.Interpolators;


@@ -116,6 +118,7 @@ public abstract class MediaOutputBaseAdapter extends
        final View mDivider;
        final View mDivider;
        final View mBottomDivider;
        final View mBottomDivider;
        final CheckBox mCheckBox;
        final CheckBox mCheckBox;
        private String mDeviceId;


        MediaDeviceBaseViewHolder(View view) {
        MediaDeviceBaseViewHolder(View view) {
            super(view);
            super(view);
@@ -134,8 +137,17 @@ public abstract class MediaOutputBaseAdapter extends
        }
        }


        void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
        void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
            mTitleIcon.setImageIcon(mController.getDeviceIconCompat(device).toIcon(mContext));
            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);
                    setMargin(topMargin, bottomMargin);
                });
            });
        }
        }


        void onBind(int customizedItem, boolean topMargin, boolean bottomMargin) {
        void onBind(int customizedItem, boolean topMargin, boolean bottomMargin) {