Loading core/java/android/app/INotificationManager.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -270,8 +270,8 @@ interface INotificationManager int[] getAllowedAdjustmentKeyTypes(); void setAssistantAdjustmentKeyTypeState(int type, boolean enabled); String[] getTypeAdjustmentDeniedPackages(); void setTypeAdjustmentForPackageState(String pkg, boolean enabled); boolean isAdjustmentSupportedForPackage(String key, String pkg); void setAdjustmentSupportedForPackage(String key, String pkg, boolean enabled); // TODO: b/389918945 - Remove once nm_binder_perf flags are going to Nextfood. void incrementCounter(String metricId); Loading core/java/android/app/NotificationManager.java +0 −13 Original line number Diff line number Diff line Loading @@ -2168,19 +2168,6 @@ public class NotificationManager { } } /** * @hide */ @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(@NonNull String pkg, boolean enabled) { INotificationManager service = service(); try { service.setTypeAdjustmentForPackageState(pkg, enabled); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @hide */ Loading core/java/android/service/notification/Adjustment.java +3 −2 Original line number Diff line number Diff line Loading @@ -66,7 +66,8 @@ public final class Adjustment implements Parcelable { KEY_SENSITIVE_CONTENT, KEY_RANKING_SCORE, KEY_NOT_CONVERSATION, KEY_TYPE KEY_TYPE, KEY_SUMMARIZATION }) @Retention(RetentionPolicy.SOURCE) public @interface Keys {} Loading Loading @@ -189,7 +190,7 @@ public final class Adjustment implements Parcelable { TYPE_PROMOTION, TYPE_SOCIAL_MEDIA, TYPE_NEWS, TYPE_CONTENT_RECOMMENDATION TYPE_CONTENT_RECOMMENDATION, }) @Retention(RetentionPolicy.SOURCE) public @interface Types {} Loading services/core/java/com/android/server/notification/NotificationManagerService.java +72 −68 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.OP_RECEIVE_SENSITIVE_NOTIFICATIONS; import static android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR; import static android.app.Flags.lifetimeExtensionRefactor; import static android.app.Flags.nmSummarization; import static android.app.Flags.nmSummarizationUi; import static android.app.Flags.notificationClassificationUi; import static android.app.Flags.redactSensitiveContentNotificationsOnLockscreen; import static android.app.Flags.sortSectionByTime; Loading Loading @@ -106,6 +108,7 @@ import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROU import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_SYSTEM; import static android.service.notification.Adjustment.KEY_SUMMARIZATION; import static android.service.notification.Adjustment.KEY_TYPE; import static android.service.notification.Adjustment.TYPE_CONTENT_RECOMMENDATION; import static android.service.notification.Adjustment.TYPE_PROMOTION; Loading Loading @@ -4535,7 +4538,7 @@ public class NotificationManagerService extends SystemService { @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) public @NonNull int[] getAllowedAdjustmentKeyTypes() { checkCallerIsSystemOrSystemUiOrShell(); return mAssistants.getAllowedAdjustmentKeyTypes(); return mAssistants.getAllowedClassificationTypes(); } @Override Loading @@ -4556,18 +4559,18 @@ public class NotificationManagerService extends SystemService { } @Override @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public @NonNull String[] getTypeAdjustmentDeniedPackages() { public boolean isAdjustmentSupportedForPackage(String key, String pkg) { checkCallerIsSystemOrSystemUiOrShell(); return mAssistants.getTypeAdjustmentDeniedPackages(); return mAssistants.isAdjustmentAllowedForPackage(key, pkg); } @Override @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) { public void setAdjustmentSupportedForPackage(@Adjustment.Keys String key, String pkg, boolean enabled) { checkCallerIsSystemOrSystemUiOrShell(); mAssistants.setTypeAdjustmentForPackageState(pkg, enabled); if ((notificationClassificationUi() && notificationRegroupOnClassification())) { mAssistants.setAdjustmentSupportedForPackage(key, pkg, enabled); if (notificationClassificationUi() && notificationRegroupOnClassification() && key.equals(KEY_TYPE)) { if (enabled) { reclassifyNotificationsForUid(UserHandle.getUserId(Binder.getCallingUid()), pkg); Loading Loading @@ -7387,7 +7390,14 @@ public class NotificationManagerService extends SystemService { if (!mAssistants.isAdjustmentKeyTypeAllowed(adjustments.getInt(KEY_TYPE))) { toRemove.add(potentialKey); } else if (notificationClassificationUi() && !mAssistants.isTypeAdjustmentAllowedForPackage( && !mAssistants.isAdjustmentAllowedForPackage(KEY_TYPE, r.getSbn().getPackageName())) { toRemove.add(potentialKey); } } if ((nmSummarization() || nmSummarizationUi()) && potentialKey.equals(KEY_SUMMARIZATION)) { if (!mAssistants.isAdjustmentAllowedForPackage(KEY_SUMMARIZATION, r.getSbn().getPackageName())) { toRemove.add(potentialKey); } Loading Loading @@ -12040,15 +12050,17 @@ public class NotificationManagerService extends SystemService { static final String TAG_ENABLED_NOTIFICATION_ASSISTANTS = "enabled_assistants"; private static final String ATT_TYPES = "types"; private static final String ATT_DENIED = "user_denied_adjustments"; private static final String ATT_ENABLED_TYPES = "enabled_key_types"; private static final String TAG_DENIED = "user_denied_adjustments"; private static final String TAG_DENIED_KEY = "adjustment"; private static final String ATT_DENIED_KEY = "key"; private static final String ATT_DENIED_KEY_APPS = "denied_apps"; private static final String TAG_ENABLED_TYPES = "enabled_key_types"; private static final String ATT_NAS_UNSUPPORTED = "nas_unsupported_adjustments"; private static final String ATT_TYPES_DENIED_APPS = "types_denied_apps"; private final Object mLock = new Object(); @GuardedBy("mLock") private Set<Integer> mAllowedAdjustmentKeyTypes = new ArraySet<>(); private Set<Integer> mAllowedClassificationTypes = new ArraySet<>(); @GuardedBy("mLock") private Set<String> mAllowedAdjustments = new ArraySet<>(); Loading @@ -12059,8 +12071,10 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mLock") private Map<Integer, HashSet<String>> mNasUnsupported = new ArrayMap<>(); // key: Adjustment key. value - list of pkgs that we shouldn't apply adjustments with that // key to @GuardedBy("mLock") private Set<String> mClassificationTypeDeniedPackages = new ArraySet<>(); private Map<String, Set<String>> mAdjustmentKeyDeniedPackages = new ArrayMap<>(); protected ComponentName mDefaultFromConfig = null; Loading Loading @@ -12137,7 +12151,7 @@ public class NotificationManagerService extends SystemService { mAllowedAdjustments.add(DEFAULT_ALLOWED_ADJUSTMENTS[i]); } } else { mAllowedAdjustmentKeyTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES)); mAllowedClassificationTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES)); } } Loading Loading @@ -12229,17 +12243,17 @@ public class NotificationManagerService extends SystemService { protected @NonNull boolean isAdjustmentKeyTypeAllowed(@Adjustment.Types int type) { synchronized (mLock) { if (notificationClassification()) { return mAllowedAdjustmentKeyTypes.contains(type); return mAllowedClassificationTypes.contains(type); } } return false; } @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) protected @NonNull int[] getAllowedAdjustmentKeyTypes() { protected @NonNull int[] getAllowedClassificationTypes() { synchronized (mLock) { if (notificationClassification()) { return mAllowedAdjustmentKeyTypes.stream() return mAllowedClassificationTypes.stream() .mapToInt(Integer::intValue).toArray(); } } Loading @@ -12254,47 +12268,35 @@ public class NotificationManagerService extends SystemService { } synchronized (mLock) { if (enabled) { mAllowedAdjustmentKeyTypes.add(type); mAllowedClassificationTypes.add(type); } else { mAllowedAdjustmentKeyTypes.remove(type); mAllowedClassificationTypes.remove(type); } } } @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) protected @NonNull boolean isTypeAdjustmentAllowedForPackage(String pkg) { protected @NonNull boolean isAdjustmentAllowedForPackage(@Adjustment.Keys String key, String pkg) { synchronized (mLock) { if (notificationClassificationUi()) { return !mClassificationTypeDeniedPackages.contains(pkg); if (notificationClassificationUi() || nmSummarization() | nmSummarizationUi()) { return !mAdjustmentKeyDeniedPackages.getOrDefault( key, new ArraySet<>()).contains(pkg); } } return true; } @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) protected @NonNull String[] getTypeAdjustmentDeniedPackages() { synchronized (mLock) { if (notificationClassificationUi()) { return mClassificationTypeDeniedPackages.toArray(new String[0]); } } return new String[]{}; } /** * Set whether a particular package can have its notification channels adjusted to have a * different type by NotificationAssistants. */ @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) { if (!notificationClassificationUi()) { public void setAdjustmentSupportedForPackage(@Adjustment.Keys String key, String pkg, boolean enabled) { if (!(notificationClassificationUi() || nmSummarization() | nmSummarizationUi())) { return; } synchronized (mLock) { mAdjustmentKeyDeniedPackages.putIfAbsent(key, new ArraySet<>()); if (enabled) { mClassificationTypeDeniedPackages.remove(pkg); mAdjustmentKeyDeniedPackages.get(key).remove(pkg); } else { mClassificationTypeDeniedPackages.add(pkg); mAdjustmentKeyDeniedPackages.get(key).add(pkg); } } } Loading Loading @@ -12758,32 +12760,35 @@ public class NotificationManagerService extends SystemService { @Override protected void writeExtraXmlTags(TypedXmlSerializer out) throws IOException { if (!notificationClassification()) { if (!(notificationClassificationUi() || nmSummarization() || nmSummarizationUi())) { return; } synchronized (mLock) { out.startTag(null, ATT_DENIED); out.startTag(null, TAG_DENIED); out.attribute(null, ATT_TYPES, TextUtils.join(",", mDeniedAdjustments)); out.endTag(null, ATT_DENIED); out.startTag(null, ATT_ENABLED_TYPES); out.attribute(null, ATT_TYPES, TextUtils.join(",", mAllowedAdjustmentKeyTypes)); out.endTag(null, ATT_ENABLED_TYPES); if (notificationClassificationUi()) { out.startTag(null, ATT_TYPES_DENIED_APPS); out.attribute(null, ATT_TYPES, TextUtils.join(",", mClassificationTypeDeniedPackages)); out.endTag(null, ATT_TYPES_DENIED_APPS); for (String key : mAdjustmentKeyDeniedPackages.keySet()) { Set<String> pkgs = mAdjustmentKeyDeniedPackages.get(key); if (pkgs != null && !pkgs.isEmpty()) { out.startTag(null, TAG_DENIED_KEY); out.attribute(null, ATT_DENIED_KEY, key); out.attribute(null, ATT_DENIED_KEY_APPS, TextUtils.join(",", pkgs)); out.endTag(null, TAG_DENIED_KEY); } } out.endTag(null, TAG_DENIED); out.startTag(null, TAG_ENABLED_TYPES); out.attribute(null, ATT_TYPES, TextUtils.join(",", mAllowedClassificationTypes)); out.endTag(null, TAG_ENABLED_TYPES); } } @Override protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException { if (!notificationClassification()) { if (!(notificationClassificationUi() || nmSummarization() || nmSummarizationUi())) { return; } if (ATT_DENIED.equals(tag)) { if (TAG_DENIED.equals(tag)) { final String keys = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mDeniedAdjustments.clear(); Loading @@ -12791,28 +12796,27 @@ public class NotificationManagerService extends SystemService { mDeniedAdjustments.addAll(Arrays.asList(keys.split(","))); } } } else if (ATT_ENABLED_TYPES.equals(tag)) { } else if (TAG_ENABLED_TYPES.equals(tag)) { final String types = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mAllowedAdjustmentKeyTypes.clear(); mAllowedClassificationTypes.clear(); if (!TextUtils.isEmpty(types)) { List<String> typeList = Arrays.asList(types.split(",")); for (String type : typeList) { try { mAllowedAdjustmentKeyTypes.add(Integer.parseInt(type)); mAllowedClassificationTypes.add(Integer.parseInt(type)); } catch (NumberFormatException e) { Slog.wtf(TAG, "Bad type specified", e); } } } } } else if (notificationClassificationUi() && ATT_TYPES_DENIED_APPS.equals(tag)) { final String apps = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mClassificationTypeDeniedPackages.clear(); if (!TextUtils.isEmpty(apps)) { mClassificationTypeDeniedPackages.addAll(Arrays.asList(apps.split(","))); } } else if (TAG_DENIED_KEY.equals(tag)) { final String key = XmlUtils.readStringAttribute(parser, ATT_DENIED_KEY); final String pkgs = XmlUtils.readStringAttribute(parser, ATT_DENIED_KEY_APPS); if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(pkgs)) { List<String> pkgList = Arrays.asList(pkgs.split(",")); mAdjustmentKeyDeniedPackages.put(key, new ArraySet<>(pkgList)); } } } Loading Loading @@ -12841,7 +12845,7 @@ public class NotificationManagerService extends SystemService { bundlesAllowed = !unsupportedAdjustments.contains(Adjustment.KEY_TYPE); } int[] allowedBundleTypes = getAllowedAdjustmentKeyTypes(); int[] allowedBundleTypes = getAllowedClassificationTypes(); events.add(FrameworkStatsLog.buildStatsEvent( NOTIFICATION_BUNDLE_PREFERENCES, services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +68 −66 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/app/INotificationManager.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -270,8 +270,8 @@ interface INotificationManager int[] getAllowedAdjustmentKeyTypes(); void setAssistantAdjustmentKeyTypeState(int type, boolean enabled); String[] getTypeAdjustmentDeniedPackages(); void setTypeAdjustmentForPackageState(String pkg, boolean enabled); boolean isAdjustmentSupportedForPackage(String key, String pkg); void setAdjustmentSupportedForPackage(String key, String pkg, boolean enabled); // TODO: b/389918945 - Remove once nm_binder_perf flags are going to Nextfood. void incrementCounter(String metricId); Loading
core/java/android/app/NotificationManager.java +0 −13 Original line number Diff line number Diff line Loading @@ -2168,19 +2168,6 @@ public class NotificationManager { } } /** * @hide */ @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(@NonNull String pkg, boolean enabled) { INotificationManager service = service(); try { service.setTypeAdjustmentForPackageState(pkg, enabled); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @hide */ Loading
core/java/android/service/notification/Adjustment.java +3 −2 Original line number Diff line number Diff line Loading @@ -66,7 +66,8 @@ public final class Adjustment implements Parcelable { KEY_SENSITIVE_CONTENT, KEY_RANKING_SCORE, KEY_NOT_CONVERSATION, KEY_TYPE KEY_TYPE, KEY_SUMMARIZATION }) @Retention(RetentionPolicy.SOURCE) public @interface Keys {} Loading Loading @@ -189,7 +190,7 @@ public final class Adjustment implements Parcelable { TYPE_PROMOTION, TYPE_SOCIAL_MEDIA, TYPE_NEWS, TYPE_CONTENT_RECOMMENDATION TYPE_CONTENT_RECOMMENDATION, }) @Retention(RetentionPolicy.SOURCE) public @interface Types {} Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +72 −68 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.OP_RECEIVE_SENSITIVE_NOTIFICATIONS; import static android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR; import static android.app.Flags.lifetimeExtensionRefactor; import static android.app.Flags.nmSummarization; import static android.app.Flags.nmSummarizationUi; import static android.app.Flags.notificationClassificationUi; import static android.app.Flags.redactSensitiveContentNotificationsOnLockscreen; import static android.app.Flags.sortSectionByTime; Loading Loading @@ -106,6 +108,7 @@ import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROU import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_SYSTEM; import static android.service.notification.Adjustment.KEY_SUMMARIZATION; import static android.service.notification.Adjustment.KEY_TYPE; import static android.service.notification.Adjustment.TYPE_CONTENT_RECOMMENDATION; import static android.service.notification.Adjustment.TYPE_PROMOTION; Loading Loading @@ -4535,7 +4538,7 @@ public class NotificationManagerService extends SystemService { @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) public @NonNull int[] getAllowedAdjustmentKeyTypes() { checkCallerIsSystemOrSystemUiOrShell(); return mAssistants.getAllowedAdjustmentKeyTypes(); return mAssistants.getAllowedClassificationTypes(); } @Override Loading @@ -4556,18 +4559,18 @@ public class NotificationManagerService extends SystemService { } @Override @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public @NonNull String[] getTypeAdjustmentDeniedPackages() { public boolean isAdjustmentSupportedForPackage(String key, String pkg) { checkCallerIsSystemOrSystemUiOrShell(); return mAssistants.getTypeAdjustmentDeniedPackages(); return mAssistants.isAdjustmentAllowedForPackage(key, pkg); } @Override @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) { public void setAdjustmentSupportedForPackage(@Adjustment.Keys String key, String pkg, boolean enabled) { checkCallerIsSystemOrSystemUiOrShell(); mAssistants.setTypeAdjustmentForPackageState(pkg, enabled); if ((notificationClassificationUi() && notificationRegroupOnClassification())) { mAssistants.setAdjustmentSupportedForPackage(key, pkg, enabled); if (notificationClassificationUi() && notificationRegroupOnClassification() && key.equals(KEY_TYPE)) { if (enabled) { reclassifyNotificationsForUid(UserHandle.getUserId(Binder.getCallingUid()), pkg); Loading Loading @@ -7387,7 +7390,14 @@ public class NotificationManagerService extends SystemService { if (!mAssistants.isAdjustmentKeyTypeAllowed(adjustments.getInt(KEY_TYPE))) { toRemove.add(potentialKey); } else if (notificationClassificationUi() && !mAssistants.isTypeAdjustmentAllowedForPackage( && !mAssistants.isAdjustmentAllowedForPackage(KEY_TYPE, r.getSbn().getPackageName())) { toRemove.add(potentialKey); } } if ((nmSummarization() || nmSummarizationUi()) && potentialKey.equals(KEY_SUMMARIZATION)) { if (!mAssistants.isAdjustmentAllowedForPackage(KEY_SUMMARIZATION, r.getSbn().getPackageName())) { toRemove.add(potentialKey); } Loading Loading @@ -12040,15 +12050,17 @@ public class NotificationManagerService extends SystemService { static final String TAG_ENABLED_NOTIFICATION_ASSISTANTS = "enabled_assistants"; private static final String ATT_TYPES = "types"; private static final String ATT_DENIED = "user_denied_adjustments"; private static final String ATT_ENABLED_TYPES = "enabled_key_types"; private static final String TAG_DENIED = "user_denied_adjustments"; private static final String TAG_DENIED_KEY = "adjustment"; private static final String ATT_DENIED_KEY = "key"; private static final String ATT_DENIED_KEY_APPS = "denied_apps"; private static final String TAG_ENABLED_TYPES = "enabled_key_types"; private static final String ATT_NAS_UNSUPPORTED = "nas_unsupported_adjustments"; private static final String ATT_TYPES_DENIED_APPS = "types_denied_apps"; private final Object mLock = new Object(); @GuardedBy("mLock") private Set<Integer> mAllowedAdjustmentKeyTypes = new ArraySet<>(); private Set<Integer> mAllowedClassificationTypes = new ArraySet<>(); @GuardedBy("mLock") private Set<String> mAllowedAdjustments = new ArraySet<>(); Loading @@ -12059,8 +12071,10 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mLock") private Map<Integer, HashSet<String>> mNasUnsupported = new ArrayMap<>(); // key: Adjustment key. value - list of pkgs that we shouldn't apply adjustments with that // key to @GuardedBy("mLock") private Set<String> mClassificationTypeDeniedPackages = new ArraySet<>(); private Map<String, Set<String>> mAdjustmentKeyDeniedPackages = new ArrayMap<>(); protected ComponentName mDefaultFromConfig = null; Loading Loading @@ -12137,7 +12151,7 @@ public class NotificationManagerService extends SystemService { mAllowedAdjustments.add(DEFAULT_ALLOWED_ADJUSTMENTS[i]); } } else { mAllowedAdjustmentKeyTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES)); mAllowedClassificationTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES)); } } Loading Loading @@ -12229,17 +12243,17 @@ public class NotificationManagerService extends SystemService { protected @NonNull boolean isAdjustmentKeyTypeAllowed(@Adjustment.Types int type) { synchronized (mLock) { if (notificationClassification()) { return mAllowedAdjustmentKeyTypes.contains(type); return mAllowedClassificationTypes.contains(type); } } return false; } @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) protected @NonNull int[] getAllowedAdjustmentKeyTypes() { protected @NonNull int[] getAllowedClassificationTypes() { synchronized (mLock) { if (notificationClassification()) { return mAllowedAdjustmentKeyTypes.stream() return mAllowedClassificationTypes.stream() .mapToInt(Integer::intValue).toArray(); } } Loading @@ -12254,47 +12268,35 @@ public class NotificationManagerService extends SystemService { } synchronized (mLock) { if (enabled) { mAllowedAdjustmentKeyTypes.add(type); mAllowedClassificationTypes.add(type); } else { mAllowedAdjustmentKeyTypes.remove(type); mAllowedClassificationTypes.remove(type); } } } @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) protected @NonNull boolean isTypeAdjustmentAllowedForPackage(String pkg) { protected @NonNull boolean isAdjustmentAllowedForPackage(@Adjustment.Keys String key, String pkg) { synchronized (mLock) { if (notificationClassificationUi()) { return !mClassificationTypeDeniedPackages.contains(pkg); if (notificationClassificationUi() || nmSummarization() | nmSummarizationUi()) { return !mAdjustmentKeyDeniedPackages.getOrDefault( key, new ArraySet<>()).contains(pkg); } } return true; } @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) protected @NonNull String[] getTypeAdjustmentDeniedPackages() { synchronized (mLock) { if (notificationClassificationUi()) { return mClassificationTypeDeniedPackages.toArray(new String[0]); } } return new String[]{}; } /** * Set whether a particular package can have its notification channels adjusted to have a * different type by NotificationAssistants. */ @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) { if (!notificationClassificationUi()) { public void setAdjustmentSupportedForPackage(@Adjustment.Keys String key, String pkg, boolean enabled) { if (!(notificationClassificationUi() || nmSummarization() | nmSummarizationUi())) { return; } synchronized (mLock) { mAdjustmentKeyDeniedPackages.putIfAbsent(key, new ArraySet<>()); if (enabled) { mClassificationTypeDeniedPackages.remove(pkg); mAdjustmentKeyDeniedPackages.get(key).remove(pkg); } else { mClassificationTypeDeniedPackages.add(pkg); mAdjustmentKeyDeniedPackages.get(key).add(pkg); } } } Loading Loading @@ -12758,32 +12760,35 @@ public class NotificationManagerService extends SystemService { @Override protected void writeExtraXmlTags(TypedXmlSerializer out) throws IOException { if (!notificationClassification()) { if (!(notificationClassificationUi() || nmSummarization() || nmSummarizationUi())) { return; } synchronized (mLock) { out.startTag(null, ATT_DENIED); out.startTag(null, TAG_DENIED); out.attribute(null, ATT_TYPES, TextUtils.join(",", mDeniedAdjustments)); out.endTag(null, ATT_DENIED); out.startTag(null, ATT_ENABLED_TYPES); out.attribute(null, ATT_TYPES, TextUtils.join(",", mAllowedAdjustmentKeyTypes)); out.endTag(null, ATT_ENABLED_TYPES); if (notificationClassificationUi()) { out.startTag(null, ATT_TYPES_DENIED_APPS); out.attribute(null, ATT_TYPES, TextUtils.join(",", mClassificationTypeDeniedPackages)); out.endTag(null, ATT_TYPES_DENIED_APPS); for (String key : mAdjustmentKeyDeniedPackages.keySet()) { Set<String> pkgs = mAdjustmentKeyDeniedPackages.get(key); if (pkgs != null && !pkgs.isEmpty()) { out.startTag(null, TAG_DENIED_KEY); out.attribute(null, ATT_DENIED_KEY, key); out.attribute(null, ATT_DENIED_KEY_APPS, TextUtils.join(",", pkgs)); out.endTag(null, TAG_DENIED_KEY); } } out.endTag(null, TAG_DENIED); out.startTag(null, TAG_ENABLED_TYPES); out.attribute(null, ATT_TYPES, TextUtils.join(",", mAllowedClassificationTypes)); out.endTag(null, TAG_ENABLED_TYPES); } } @Override protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException { if (!notificationClassification()) { if (!(notificationClassificationUi() || nmSummarization() || nmSummarizationUi())) { return; } if (ATT_DENIED.equals(tag)) { if (TAG_DENIED.equals(tag)) { final String keys = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mDeniedAdjustments.clear(); Loading @@ -12791,28 +12796,27 @@ public class NotificationManagerService extends SystemService { mDeniedAdjustments.addAll(Arrays.asList(keys.split(","))); } } } else if (ATT_ENABLED_TYPES.equals(tag)) { } else if (TAG_ENABLED_TYPES.equals(tag)) { final String types = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mAllowedAdjustmentKeyTypes.clear(); mAllowedClassificationTypes.clear(); if (!TextUtils.isEmpty(types)) { List<String> typeList = Arrays.asList(types.split(",")); for (String type : typeList) { try { mAllowedAdjustmentKeyTypes.add(Integer.parseInt(type)); mAllowedClassificationTypes.add(Integer.parseInt(type)); } catch (NumberFormatException e) { Slog.wtf(TAG, "Bad type specified", e); } } } } } else if (notificationClassificationUi() && ATT_TYPES_DENIED_APPS.equals(tag)) { final String apps = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mClassificationTypeDeniedPackages.clear(); if (!TextUtils.isEmpty(apps)) { mClassificationTypeDeniedPackages.addAll(Arrays.asList(apps.split(","))); } } else if (TAG_DENIED_KEY.equals(tag)) { final String key = XmlUtils.readStringAttribute(parser, ATT_DENIED_KEY); final String pkgs = XmlUtils.readStringAttribute(parser, ATT_DENIED_KEY_APPS); if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(pkgs)) { List<String> pkgList = Arrays.asList(pkgs.split(",")); mAdjustmentKeyDeniedPackages.put(key, new ArraySet<>(pkgList)); } } } Loading Loading @@ -12841,7 +12845,7 @@ public class NotificationManagerService extends SystemService { bundlesAllowed = !unsupportedAdjustments.contains(Adjustment.KEY_TYPE); } int[] allowedBundleTypes = getAllowedAdjustmentKeyTypes(); int[] allowedBundleTypes = getAllowedClassificationTypes(); events.add(FrameworkStatsLog.buildStatsEvent( NOTIFICATION_BUNDLE_PREFERENCES,
services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +68 −66 File changed.Preview size limit exceeded, changes collapsed. Show changes