Loading services/core/java/com/android/server/notification/RankingHelper.java +119 −99 Original line number Original line Diff line number Diff line Loading @@ -232,8 +232,10 @@ public class RankingHelper implements RankingConfig { private Record getRecord(String pkg, int uid) { private Record getRecord(String pkg, int uid) { final String key = recordKey(pkg, uid); final String key = recordKey(pkg, uid); synchronized (mRecords) { return mRecords.get(key); return mRecords.get(key); } } } private Record getOrCreateRecord(String pkg, int uid) { private Record getOrCreateRecord(String pkg, int uid) { return getOrCreateRecord(pkg, uid, return getOrCreateRecord(pkg, uid, Loading @@ -243,7 +245,9 @@ public class RankingHelper implements RankingConfig { private Record getOrCreateRecord(String pkg, int uid, int importance, int priority, private Record getOrCreateRecord(String pkg, int uid, int importance, int priority, int visibility, boolean showBadge) { int visibility, boolean showBadge) { final String key = recordKey(pkg, uid); 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) { if (r == null) { r = new Record(); r = new Record(); r.pkg = pkg; r.pkg = pkg; Loading @@ -267,6 +271,7 @@ public class RankingHelper implements RankingConfig { } } return r; return r; } } } private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException { private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException { final int userId = UserHandle.getUserId(r.uid); final int userId = UserHandle.getUserId(r.uid); Loading Loading @@ -346,6 +351,7 @@ public class RankingHelper implements RankingConfig { out.startTag(null, TAG_RANKING); out.startTag(null, TAG_RANKING); out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION)); out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION)); synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); Loading Loading @@ -388,6 +394,7 @@ public class RankingHelper implements RankingConfig { out.endTag(null, TAG_PACKAGE); out.endTag(null, TAG_PACKAGE); } } } } } out.endTag(null, TAG_RANKING); out.endTag(null, TAG_RANKING); } } Loading Loading @@ -814,7 +821,9 @@ public class RankingHelper implements RankingConfig { pw.println("per-package config:"); pw.println("per-package config:"); } } pw.println("Records:"); pw.println("Records:"); synchronized (mRecords) { dumpRecords(pw, prefix, filter, mRecords); dumpRecords(pw, prefix, filter, mRecords); } pw.println("Restored without uid:"); pw.println("Restored without uid:"); dumpRecords(pw, prefix, filter, mRestoredWithoutUids); dumpRecords(pw, prefix, filter, mRestoredWithoutUids); } } Loading Loading @@ -870,6 +879,7 @@ public class RankingHelper implements RankingConfig { } catch (JSONException e) { } catch (JSONException e) { // pass // pass } } synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); Loading Loading @@ -902,6 +912,7 @@ public class RankingHelper implements RankingConfig { records.put(record); records.put(record); } } } } } try { try { ranking.put("records", records); ranking.put("records", records); } catch (JSONException e) { } catch (JSONException e) { Loading Loading @@ -940,6 +951,7 @@ public class RankingHelper implements RankingConfig { } } public Map<Integer, String> getPackageBans() { public Map<Integer, String> getPackageBans() { synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); ArrayMap<Integer, String> packageBans = new ArrayMap<>(N); ArrayMap<Integer, String> packageBans = new ArrayMap<>(N); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { Loading @@ -948,8 +960,10 @@ public class RankingHelper implements RankingConfig { packageBans.put(r.uid, r.pkg); packageBans.put(r.uid, r.pkg); } } } } return packageBans; return packageBans; } } } /** /** * Dump only the channel information as structured JSON for the stats collector. * Dump only the channel information as structured JSON for the stats collector. Loading Loading @@ -981,6 +995,7 @@ public class RankingHelper implements RankingConfig { private Map<String, Integer> getPackageChannels() { private Map<String, Integer> getPackageChannels() { ArrayMap<String, Integer> packageChannels = new ArrayMap<>(); ArrayMap<String, Integer> packageChannels = new ArrayMap<>(); synchronized (mRecords) { for (int i = 0; i < mRecords.size(); i++) { for (int i = 0; i < mRecords.size(); i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); int channelCount = 0; int channelCount = 0; Loading @@ -991,6 +1006,7 @@ public class RankingHelper implements RankingConfig { } } packageChannels.put(r.pkg, channelCount); packageChannels.put(r.pkg, channelCount); } } } return packageChannels; return packageChannels; } } Loading @@ -1006,7 +1022,9 @@ public class RankingHelper implements RankingConfig { for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) { final String pkg = pkgList[i]; final String pkg = pkgList[i]; final int uid = uidList[i]; final int uid = uidList[i]; synchronized (mRecords) { mRecords.remove(recordKey(pkg, uid)); mRecords.remove(recordKey(pkg, uid)); } mRestoredWithoutUids.remove(pkg); mRestoredWithoutUids.remove(pkg); updated = true; updated = true; } } Loading @@ -1018,7 +1036,9 @@ public class RankingHelper implements RankingConfig { try { try { r.uid = mPm.getPackageUidAsUser(r.pkg, changeUserId); r.uid = mPm.getPackageUidAsUser(r.pkg, changeUserId); mRestoredWithoutUids.remove(pkg); mRestoredWithoutUids.remove(pkg); synchronized (mRecords) { mRecords.put(recordKey(r.pkg, r.uid), r); mRecords.put(recordKey(r.pkg, r.uid), r); } updated = true; updated = true; } catch (NameNotFoundException e) { } catch (NameNotFoundException e) { // noop // noop Loading Loading
services/core/java/com/android/server/notification/RankingHelper.java +119 −99 Original line number Original line Diff line number Diff line Loading @@ -232,8 +232,10 @@ public class RankingHelper implements RankingConfig { private Record getRecord(String pkg, int uid) { private Record getRecord(String pkg, int uid) { final String key = recordKey(pkg, uid); final String key = recordKey(pkg, uid); synchronized (mRecords) { return mRecords.get(key); return mRecords.get(key); } } } private Record getOrCreateRecord(String pkg, int uid) { private Record getOrCreateRecord(String pkg, int uid) { return getOrCreateRecord(pkg, uid, return getOrCreateRecord(pkg, uid, Loading @@ -243,7 +245,9 @@ public class RankingHelper implements RankingConfig { private Record getOrCreateRecord(String pkg, int uid, int importance, int priority, private Record getOrCreateRecord(String pkg, int uid, int importance, int priority, int visibility, boolean showBadge) { int visibility, boolean showBadge) { final String key = recordKey(pkg, uid); 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) { if (r == null) { r = new Record(); r = new Record(); r.pkg = pkg; r.pkg = pkg; Loading @@ -267,6 +271,7 @@ public class RankingHelper implements RankingConfig { } } return r; return r; } } } private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException { private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException { final int userId = UserHandle.getUserId(r.uid); final int userId = UserHandle.getUserId(r.uid); Loading Loading @@ -346,6 +351,7 @@ public class RankingHelper implements RankingConfig { out.startTag(null, TAG_RANKING); out.startTag(null, TAG_RANKING); out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION)); out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION)); synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); Loading Loading @@ -388,6 +394,7 @@ public class RankingHelper implements RankingConfig { out.endTag(null, TAG_PACKAGE); out.endTag(null, TAG_PACKAGE); } } } } } out.endTag(null, TAG_RANKING); out.endTag(null, TAG_RANKING); } } Loading Loading @@ -814,7 +821,9 @@ public class RankingHelper implements RankingConfig { pw.println("per-package config:"); pw.println("per-package config:"); } } pw.println("Records:"); pw.println("Records:"); synchronized (mRecords) { dumpRecords(pw, prefix, filter, mRecords); dumpRecords(pw, prefix, filter, mRecords); } pw.println("Restored without uid:"); pw.println("Restored without uid:"); dumpRecords(pw, prefix, filter, mRestoredWithoutUids); dumpRecords(pw, prefix, filter, mRestoredWithoutUids); } } Loading Loading @@ -870,6 +879,7 @@ public class RankingHelper implements RankingConfig { } catch (JSONException e) { } catch (JSONException e) { // pass // pass } } synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); Loading Loading @@ -902,6 +912,7 @@ public class RankingHelper implements RankingConfig { records.put(record); records.put(record); } } } } } try { try { ranking.put("records", records); ranking.put("records", records); } catch (JSONException e) { } catch (JSONException e) { Loading Loading @@ -940,6 +951,7 @@ public class RankingHelper implements RankingConfig { } } public Map<Integer, String> getPackageBans() { public Map<Integer, String> getPackageBans() { synchronized (mRecords) { final int N = mRecords.size(); final int N = mRecords.size(); ArrayMap<Integer, String> packageBans = new ArrayMap<>(N); ArrayMap<Integer, String> packageBans = new ArrayMap<>(N); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { Loading @@ -948,8 +960,10 @@ public class RankingHelper implements RankingConfig { packageBans.put(r.uid, r.pkg); packageBans.put(r.uid, r.pkg); } } } } return packageBans; return packageBans; } } } /** /** * Dump only the channel information as structured JSON for the stats collector. * Dump only the channel information as structured JSON for the stats collector. Loading Loading @@ -981,6 +995,7 @@ public class RankingHelper implements RankingConfig { private Map<String, Integer> getPackageChannels() { private Map<String, Integer> getPackageChannels() { ArrayMap<String, Integer> packageChannels = new ArrayMap<>(); ArrayMap<String, Integer> packageChannels = new ArrayMap<>(); synchronized (mRecords) { for (int i = 0; i < mRecords.size(); i++) { for (int i = 0; i < mRecords.size(); i++) { final Record r = mRecords.valueAt(i); final Record r = mRecords.valueAt(i); int channelCount = 0; int channelCount = 0; Loading @@ -991,6 +1006,7 @@ public class RankingHelper implements RankingConfig { } } packageChannels.put(r.pkg, channelCount); packageChannels.put(r.pkg, channelCount); } } } return packageChannels; return packageChannels; } } Loading @@ -1006,7 +1022,9 @@ public class RankingHelper implements RankingConfig { for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) { final String pkg = pkgList[i]; final String pkg = pkgList[i]; final int uid = uidList[i]; final int uid = uidList[i]; synchronized (mRecords) { mRecords.remove(recordKey(pkg, uid)); mRecords.remove(recordKey(pkg, uid)); } mRestoredWithoutUids.remove(pkg); mRestoredWithoutUids.remove(pkg); updated = true; updated = true; } } Loading @@ -1018,7 +1036,9 @@ public class RankingHelper implements RankingConfig { try { try { r.uid = mPm.getPackageUidAsUser(r.pkg, changeUserId); r.uid = mPm.getPackageUidAsUser(r.pkg, changeUserId); mRestoredWithoutUids.remove(pkg); mRestoredWithoutUids.remove(pkg); synchronized (mRecords) { mRecords.put(recordKey(r.pkg, r.uid), r); mRecords.put(recordKey(r.pkg, r.uid), r); } updated = true; updated = true; } catch (NameNotFoundException e) { } catch (NameNotFoundException e) { // noop // noop Loading