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

Commit 5af689e1 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato Committed by Nicolò Mazzucato
Browse files

Make StatusBarNotification#mContextForDisplayId thread safe

The context can be get also from background threads. So it was possible that clearPackageContext was clearing the mContextForDisplayId while a new context was being created, resulting in a ConcurrentModificationException

Bug: 362719719
Bug: 390567645
Test: StatusBarNotificationTest
Flag: com.android.systemui.shade_window_goes_around
Change-Id: Iea03b2d0c42641d91589b7383c0bd5ee542433a7
parent 1d5e6a11
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ package android.service.notification;


import static android.text.TextUtils.formatSimple;
import static android.text.TextUtils.formatSimple;


import static com.android.window.flags.Flags.enablePerDisplayPackageContextCacheInStatusbarNotif;

import android.annotation.NonNull;
import android.annotation.NonNull;
import android.app.Notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.NotificationManager;
@@ -37,9 +39,9 @@ import android.util.ArrayMap;
import com.android.internal.logging.InstanceId;
import com.android.internal.logging.InstanceId;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import static com.android.window.flags.Flags.enablePerDisplayPackageContextCacheInStatusbarNotif;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Map;


/**
/**
@@ -81,7 +83,8 @@ public class StatusBarNotification implements Parcelable {
    @Deprecated
    @Deprecated
    private Context mContext; // used for inflation & icon expansion
    private Context mContext; // used for inflation & icon expansion
    // Maps display id to context used for remote view content inflation and status bar icon.
    // Maps display id to context used for remote view content inflation and status bar icon.
    private final Map<Integer, Context> mContextForDisplayId = new ArrayMap<>();
    private final Map<Integer, Context> mContextForDisplayId =
            Collections.synchronizedMap(new ArrayMap<>());


    /** @hide */
    /** @hide */
    public StatusBarNotification(String pkg, String opPkg, int id,
    public StatusBarNotification(String pkg, String opPkg, int id,