Merge "Refactor RankingMap building methods to reduce code duplication."
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 09255da..98da569 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -1880,23 +1880,41 @@
Collections.addAll(mIntercepted, dndInterceptedKeys);
}
+ private ArrayMap<String, Integer> buildIntMapFromBundle(Bundle bundle) {
+ ArrayMap<String, Integer> newMap = new ArrayMap<>(bundle.size());
+ for (String key : bundle.keySet()) {
+ newMap.put(key, bundle.getInt(key));
+ }
+ return newMap;
+ }
+
+ private ArrayMap<String, String> buildStringMapFromBundle(Bundle bundle) {
+ ArrayMap<String, String> newMap = new ArrayMap<>(bundle.size());
+ for (String key : bundle.keySet()) {
+ newMap.put(key, bundle.getString(key));
+ }
+ return newMap;
+ }
+
+ private ArrayMap<String, Boolean> buildBooleanMapFromBundle(Bundle bundle) {
+ ArrayMap<String, Boolean> newMap = new ArrayMap<>(bundle.size());
+ for (String key : bundle.keySet()) {
+ newMap.put(key, bundle.getBoolean(key));
+ }
+ return newMap;
+ }
+
// Locked by 'this'
private void buildVisibilityOverridesLocked() {
- Bundle visibilityBundle = mRankingUpdate.getVisibilityOverrides();
- mVisibilityOverrides = new ArrayMap<>(visibilityBundle.size());
- for (String key: visibilityBundle.keySet()) {
- mVisibilityOverrides.put(key, visibilityBundle.getInt(key));
- }
+ mVisibilityOverrides = buildIntMapFromBundle(mRankingUpdate.getVisibilityOverrides());
}
// Locked by 'this'
private void buildSuppressedVisualEffectsLocked() {
- Bundle suppressedBundle = mRankingUpdate.getSuppressedVisualEffects();
- mSuppressedVisualEffects = new ArrayMap<>(suppressedBundle.size());
- for (String key: suppressedBundle.keySet()) {
- mSuppressedVisualEffects.put(key, suppressedBundle.getInt(key));
- }
+ mSuppressedVisualEffects =
+ buildIntMapFromBundle(mRankingUpdate.getSuppressedVisualEffects());
}
+
// Locked by 'this'
private void buildImportanceLocked() {
String[] orderedKeys = mRankingUpdate.getOrderedKeys();
@@ -1910,20 +1928,13 @@
// Locked by 'this'
private void buildImportanceExplanationLocked() {
- Bundle explanationBundle = mRankingUpdate.getImportanceExplanation();
- mImportanceExplanation = new ArrayMap<>(explanationBundle.size());
- for (String key: explanationBundle.keySet()) {
- mImportanceExplanation.put(key, explanationBundle.getString(key));
- }
+ mImportanceExplanation =
+ buildStringMapFromBundle(mRankingUpdate.getImportanceExplanation());
}
// Locked by 'this'
private void buildOverrideGroupKeys() {
- Bundle overrideGroupKeys = mRankingUpdate.getOverrideGroupKeys();
- mOverrideGroupKeys = new ArrayMap<>(overrideGroupKeys.size());
- for (String key: overrideGroupKeys.keySet()) {
- mOverrideGroupKeys.put(key, overrideGroupKeys.getString(key));
- }
+ mOverrideGroupKeys = buildStringMapFromBundle(mRankingUpdate.getOverrideGroupKeys());
}
// Locked by 'this'
@@ -1955,29 +1966,17 @@
// Locked by 'this'
private void buildShowBadgeLocked() {
- Bundle showBadge = mRankingUpdate.getShowBadge();
- mShowBadge = new ArrayMap<>(showBadge.size());
- for (String key : showBadge.keySet()) {
- mShowBadge.put(key, showBadge.getBoolean(key));
- }
+ mShowBadge = buildBooleanMapFromBundle(mRankingUpdate.getShowBadge());
}
// Locked by 'this'
private void buildUserSentimentLocked() {
- Bundle userSentiment = mRankingUpdate.getUserSentiment();
- mUserSentiment = new ArrayMap<>(userSentiment.size());
- for (String key : userSentiment.keySet()) {
- mUserSentiment.put(key, userSentiment.getInt(key));
- }
+ mUserSentiment = buildIntMapFromBundle(mRankingUpdate.getUserSentiment());
}
// Locked by 'this'
private void buildHiddenLocked() {
- Bundle hidden = mRankingUpdate.getHidden();
- mHidden = new ArrayMap<>(hidden.size());
- for (String key : hidden.keySet()) {
- mHidden.put(key, hidden.getBoolean(key));
- }
+ mHidden = buildBooleanMapFromBundle(mRankingUpdate.getHidden());
}
// Locked by 'this'