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

Commit 1ecac1ab authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "[ANR] Read device icon on the main thread" into sc-dev

parents ff15f218 8ffe58d7
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -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));
            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) {