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

Commit 00ac29e3 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Synchronize access to ranking helper records." into oc-dev

am: bf777d46

Change-Id: I36dec49a567400d1acf6e13567de3f76319f91be
parents 7e0a00e3 bf777d46
Loading
Loading
Loading
Loading
+119 −99
Original line number Diff line number Diff line
@@ -232,8 +232,10 @@ public class RankingHelper implements RankingConfig {

    private Record getRecord(String pkg, int uid) {
        final String key = recordKey(pkg, uid);
        synchronized (mRecords) {
            return mRecords.get(key);
        }
    }

    private Record getOrCreateRecord(String pkg, int uid) {
        return getOrCreateRecord(pkg, uid,
@@ -243,7 +245,9 @@ public class RankingHelper implements RankingConfig {
    private Record getOrCreateRecord(String pkg, int uid, int importance, int priority,
            int visibility, boolean showBadge) {
        final String key = recordKey(pkg, uid);
        Record r = (uid == Record.UNKNOWN_UID) ? mRestoredWithoutUids.get(pkg) : mRecords.get(key);
        synchronized (mRecords) {
            Record r = (uid == Record.UNKNOWN_UID) ? mRestoredWithoutUids.get(pkg) : mRecords.get(
                    key);
            if (r == null) {
                r = new Record();
                r.pkg = pkg;
@@ -267,6 +271,7 @@ public class RankingHelper implements RankingConfig {
            }
            return r;
        }
    }

    private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException {
        final int userId = UserHandle.getUserId(r.uid);
@@ -346,6 +351,7 @@ public class RankingHelper implements RankingConfig {
        out.startTag(null, TAG_RANKING);
        out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION));

        synchronized (mRecords) {
            final int N = mRecords.size();
            for (int i = 0; i < N; i++) {
                final Record r = mRecords.valueAt(i);
@@ -388,6 +394,7 @@ public class RankingHelper implements RankingConfig {
                    out.endTag(null, TAG_PACKAGE);
                }
            }
        }
        out.endTag(null, TAG_RANKING);
    }

@@ -814,7 +821,9 @@ public class RankingHelper implements RankingConfig {
            pw.println("per-package config:");
        }
        pw.println("Records:");
        synchronized (mRecords) {
            dumpRecords(pw, prefix, filter, mRecords);
        }
        pw.println("Restored without uid:");
        dumpRecords(pw, prefix, filter, mRestoredWithoutUids);
    }
@@ -870,6 +879,7 @@ public class RankingHelper implements RankingConfig {
        } catch (JSONException e) {
           // pass
        }
        synchronized (mRecords) {
            final int N = mRecords.size();
            for (int i = 0; i < N; i++) {
                final Record r = mRecords.valueAt(i);
@@ -902,6 +912,7 @@ public class RankingHelper implements RankingConfig {
                    records.put(record);
                }
            }
        }
        try {
            ranking.put("records", records);
        } catch (JSONException e) {
@@ -940,6 +951,7 @@ public class RankingHelper implements RankingConfig {
    }

    public Map<Integer, String> getPackageBans() {
        synchronized (mRecords) {
            final int N = mRecords.size();
            ArrayMap<Integer, String> packageBans = new ArrayMap<>(N);
            for (int i = 0; i < N; i++) {
@@ -948,8 +960,10 @@ public class RankingHelper implements RankingConfig {
                    packageBans.put(r.uid, r.pkg);
                }
            }

            return packageBans;
        }
    }

    /**
     * Dump only the channel information as structured JSON for the stats collector.
@@ -981,6 +995,7 @@ public class RankingHelper implements RankingConfig {

    private Map<String, Integer> getPackageChannels() {
        ArrayMap<String, Integer> packageChannels = new ArrayMap<>();
        synchronized (mRecords) {
            for (int i = 0; i < mRecords.size(); i++) {
                final Record r = mRecords.valueAt(i);
                int channelCount = 0;
@@ -991,6 +1006,7 @@ public class RankingHelper implements RankingConfig {
                }
                packageChannels.put(r.pkg, channelCount);
            }
        }
        return packageChannels;
    }

@@ -1006,7 +1022,9 @@ public class RankingHelper implements RankingConfig {
            for (int i = 0; i < size; i++) {
                final String pkg = pkgList[i];
                final int uid = uidList[i];
                synchronized (mRecords) {
                    mRecords.remove(recordKey(pkg, uid));
                }
                mRestoredWithoutUids.remove(pkg);
                updated = true;
            }
@@ -1018,7 +1036,9 @@ public class RankingHelper implements RankingConfig {
                    try {
                        r.uid = mPm.getPackageUidAsUser(r.pkg, changeUserId);
                        mRestoredWithoutUids.remove(pkg);
                        synchronized (mRecords) {
                            mRecords.put(recordKey(r.pkg, r.uid), r);
                        }
                        updated = true;
                    } catch (NameNotFoundException e) {
                        // noop