summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2024-10-10 14:49:53 -0400
committer Julia Reynolds <juliacr@google.com> 2024-10-11 12:17:20 -0400
commit42a13f29088992a07e07acf1e58891a6985dccd2 (patch)
tree199f988ca7382143a6201ed4d856f49734a63cc9
parentf613f7feab069e913b0c1465c50774f02347954a (diff)
Undeprecate allowed adjustments methods
Test: NotificationAssistantsTest Test: NotificationAssistantServiceTest Fixes: 372697063 Flag: android.service.notification.notification_classification Change-Id: I9759a2a2b8cab694126479b458cb1518d0145630
-rw-r--r--core/api/system-current.txt2
-rw-r--r--core/api/test-current.txt2
-rw-r--r--core/java/android/app/INotificationManager.aidl2
-rw-r--r--core/java/android/app/NotificationManager.java28
-rw-r--r--core/java/android/service/notification/INotificationListener.aidl1
-rw-r--r--core/java/android/service/notification/NotificationAssistantService.java3
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java117
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java49
8 files changed, 189 insertions, 15 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 7781f881b86f..4d3ac7512b01 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -13104,7 +13104,7 @@ package android.service.notification {
method public final void adjustNotification(@NonNull android.service.notification.Adjustment);
method public final void adjustNotifications(@NonNull java.util.List<android.service.notification.Adjustment>);
method public void onActionInvoked(@NonNull String, @NonNull android.app.Notification.Action, int);
- method @Deprecated public void onAllowedAdjustmentsChanged();
+ method public void onAllowedAdjustmentsChanged();
method @NonNull public final android.os.IBinder onBind(@Nullable android.content.Intent);
method public void onNotificationClicked(@NonNull String);
method public void onNotificationDirectReplied(@NonNull String);
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 5e4485c33233..c79fc510c25a 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -393,7 +393,9 @@ package android.app {
public class NotificationManager {
method @FlaggedApi("android.app.modes_api") @NonNull public String addAutomaticZenRule(@NonNull android.app.AutomaticZenRule, boolean);
+ method @FlaggedApi("android.service.notification.notification_classification") public void allowAssistantAdjustment(@NonNull String);
method public void cleanUpCallersAfter(long);
+ method @FlaggedApi("android.service.notification.notification_classification") public void disallowAssistantAdjustment(@NonNull String);
method @FlaggedApi("android.app.modes_api") @NonNull public android.service.notification.ZenPolicy getDefaultZenPolicy();
method public android.content.ComponentName getEffectsSuppressor();
method @FlaggedApi("android.service.notification.notification_classification") @NonNull public java.util.Set<java.lang.String> getUnsupportedAdjustmentTypes();
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 3b2aab4591a5..a7597b4d566d 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -84,6 +84,8 @@ interface INotificationManager
boolean isImportanceLocked(String pkg, int uid);
List<String> getAllowedAssistantAdjustments(String pkg);
+ void allowAssistantAdjustment(String adjustmentType);
+ void disallowAssistantAdjustment(String adjustmentType);
boolean shouldHideSilentStatusIcons(String callingPkg);
void setHideSilentStatusIcons(boolean hide);
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 41abd68c9924..06bf67c1e86f 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -1790,6 +1790,34 @@ public class NotificationManager {
}
}
+ /**
+ * @hide
+ */
+ @TestApi
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void allowAssistantAdjustment(@NonNull String capability) {
+ INotificationManager service = getService();
+ try {
+ service.allowAssistantAdjustment(capability);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * @hide
+ */
+ @TestApi
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void disallowAssistantAdjustment(@NonNull String capability) {
+ INotificationManager service = getService();
+ try {
+ service.disallowAssistantAdjustment(capability);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
/** @hide */
@TestApi
public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String pkg) {
diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl
index 37a91e720aad..b384b66bf680 100644
--- a/core/java/android/service/notification/INotificationListener.aidl
+++ b/core/java/android/service/notification/INotificationListener.aidl
@@ -58,7 +58,6 @@ oneway interface INotificationListener
void onSuggestedReplySent(String key, in CharSequence reply, int source);
void onActionClicked(String key, in Notification.Action action, int source);
void onNotificationClicked(String key);
- // @deprecated changing allowed adjustments is no longer supported.
void onAllowedAdjustmentsChanged();
void onNotificationFeedbackReceived(String key, in NotificationRankingUpdate update, in Bundle feedback);
}
diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java
index 7b7058e83acc..091b25ab77ce 100644
--- a/core/java/android/service/notification/NotificationAssistantService.java
+++ b/core/java/android/service/notification/NotificationAssistantService.java
@@ -319,10 +319,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS
* their notifications the assistant can modify.
* <p> Query {@link NotificationManager#getAllowedAssistantAdjustments()} to see what
* {@link Adjustment adjustments} you are currently allowed to make.</p>
- *
- * @deprecated changing allowed adjustments is no longer supported.
*/
- @Deprecated
public void onAllowedAdjustmentsChanged() {
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 88334ebe2abb..5c9cf6826eed 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -462,7 +462,7 @@ public class NotificationManagerService extends SystemService {
static final int INVALID_UID = -1;
static final String ROOT_PKG = "root";
- static final String[] ALLOWED_ADJUSTMENTS = new String[] {
+ static final String[] DEFAULT_ALLOWED_ADJUSTMENTS = new String[] {
Adjustment.KEY_PEOPLE,
Adjustment.KEY_SNOOZE_CRITERIA,
Adjustment.KEY_USER_SENTIMENT,
@@ -4119,6 +4119,24 @@ public class NotificationManagerService extends SystemService {
@Override
@FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void allowAssistantAdjustment(String adjustmentType) {
+ checkCallerIsSystemOrSystemUiOrShell();
+ mAssistants.allowAdjustmentType(adjustmentType);
+
+ handleSavePolicyFile();
+ }
+
+ @Override
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void disallowAssistantAdjustment(String adjustmentType) {
+ checkCallerIsSystemOrSystemUiOrShell();
+ mAssistants.disallowAdjustmentType(adjustmentType);
+
+ handleSavePolicyFile();
+ }
+
+ @Override
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
public void setAdjustmentTypeSupportedState(INotificationListener token,
@Adjustment.Keys String key, boolean supported) {
final long identity = Binder.clearCallingIdentity();
@@ -4133,6 +4151,7 @@ public class NotificationManagerService extends SystemService {
} finally {
Binder.restoreCallingIdentity(identity);
}
+ handleSavePolicyFile();
}
@Override
@@ -4891,7 +4910,7 @@ public class NotificationManagerService extends SystemService {
throw new SecurityException("Not currently an assistant");
}
- return mAssistants.getAllowedAssistantAdjustments();
+ return new ArrayList<>(mAssistants.getAllowedAssistantAdjustments());
}
/**
@@ -11395,6 +11414,7 @@ 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 = "denied_adjustments";
private static final String ATT_NAS_UNSUPPORTED = "unsupported_adjustments";
private final Object mLock = new Object();
@@ -11403,6 +11423,9 @@ public class NotificationManagerService extends SystemService {
private Set<String> mAllowedAdjustments = new ArraySet<>();
@GuardedBy("mLock")
+ private Set<String> mDeniedAdjustments = new ArraySet<>();
+
+ @GuardedBy("mLock")
private Map<Integer, HashSet<String>> mNasUnsupported = new ArrayMap<>();
protected ComponentName mDefaultFromConfig = null;
@@ -11474,9 +11497,11 @@ public class NotificationManagerService extends SystemService {
IPackageManager pm) {
super(context, lock, up, pm);
- // Add all default allowed adjustment types.
- for (int i = 0; i < ALLOWED_ADJUSTMENTS.length; i++) {
- mAllowedAdjustments.add(ALLOWED_ADJUSTMENTS[i]);
+ if (!notificationClassification()) {
+ // Add all default allowed adjustment types.
+ for (int i = 0; i < DEFAULT_ALLOWED_ADJUSTMENTS.length; i++) {
+ mAllowedAdjustments.add(DEFAULT_ALLOWED_ADJUSTMENTS[i]);
+ }
}
}
@@ -11539,17 +11564,28 @@ public class NotificationManagerService extends SystemService {
return android.Manifest.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE;
}
- protected List<String> getAllowedAssistantAdjustments() {
+ protected Set<String> getAllowedAssistantAdjustments() {
synchronized (mLock) {
- List<String> types = new ArrayList<>();
- types.addAll(mAllowedAdjustments);
- return types;
+ if (notificationClassification()) {
+ Set<String> types = new HashSet<>(Set.of(DEFAULT_ALLOWED_ADJUSTMENTS));
+ types.removeAll(mDeniedAdjustments);
+ return types;
+ } else {
+ Set<String> types = new HashSet<>();
+ types.addAll(mAllowedAdjustments);
+ return types;
+ }
}
}
protected boolean isAdjustmentAllowed(String type) {
synchronized (mLock) {
- return mAllowedAdjustments.contains(type);
+ if (notificationClassification()) {
+ return List.of(DEFAULT_ALLOWED_ADJUSTMENTS).contains(type)
+ && !mDeniedAdjustments.contains(type);
+ } else {
+ return mAllowedAdjustments.contains(type);
+ }
}
}
@@ -11911,6 +11947,30 @@ public class NotificationManagerService extends SystemService {
@FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
@GuardedBy("mNotificationLock")
+ public void allowAdjustmentType(@Adjustment.Keys String key) {
+ if (!android.service.notification.Flags.notificationClassification()) {
+ return;
+ }
+ mDeniedAdjustments.remove(key);
+ for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) {
+ mHandler.post(() -> notifyCapabilitiesChanged(info));
+ }
+ }
+
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ @GuardedBy("mNotificationLock")
+ public void disallowAdjustmentType(@Adjustment.Keys String key) {
+ if (!android.service.notification.Flags.notificationClassification()) {
+ return;
+ }
+ mDeniedAdjustments.add(key);
+ for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) {
+ mHandler.post(() -> notifyCapabilitiesChanged(info));
+ }
+ }
+
+ @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ @GuardedBy("mNotificationLock")
public void setAdjustmentTypeSupportedState(ManagedServiceInfo info,
@Adjustment.Keys String key, boolean supported) {
if (!android.service.notification.Flags.notificationClassification()) {
@@ -11965,6 +12025,43 @@ public class NotificationManagerService extends SystemService {
}
}
}
+
+ @Override
+ protected void writeExtraXmlTags(TypedXmlSerializer out) throws IOException {
+ if (!android.service.notification.Flags.notificationClassification()) {
+ return;
+ }
+ synchronized (mLock) {
+ out.startTag(null, ATT_DENIED);
+ out.attribute(null, ATT_TYPES, TextUtils.join(",", mDeniedAdjustments));
+ out.endTag(null, ATT_DENIED);
+ }
+ }
+
+ @Override
+ protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException {
+ if (!android.service.notification.Flags.notificationClassification()) {
+ return;
+ }
+ if (ATT_DENIED.equals(tag)) {
+ final String types = XmlUtils.readStringAttribute(parser, ATT_TYPES);
+ synchronized (mLock) {
+ mDeniedAdjustments.clear();
+ if (!TextUtils.isEmpty(types)) {
+ mDeniedAdjustments.addAll(Arrays.asList(types.split(",")));
+ }
+ }
+ }
+ }
+
+ private void notifyCapabilitiesChanged(final ManagedServiceInfo info) {
+ final INotificationListener assistant = (INotificationListener) info.service;
+ try {
+ assistant.onAllowedAdjustmentsChanged();
+ } catch (RemoteException ex) {
+ Slog.e(TAG, "unable to notify assistant (capabilities): " + info, ex);
+ }
+ }
}
/**
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
index 797b95b5dbe9..2018abea6654 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
@@ -16,6 +16,9 @@
package com.android.server.notification;
import static android.os.UserHandle.USER_ALL;
+import static android.service.notification.Adjustment.KEY_IMPORTANCE;
+
+import static com.android.server.notification.NotificationManagerService.DEFAULT_ALLOWED_ADJUSTMENTS;
import static com.google.common.truth.Truth.assertThat;
@@ -600,4 +603,50 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
assertThat(mAssistants.getUnsupportedAdjustments(userId).size()).isEqualTo(0);
}
+
+ @Test
+ @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void testDisallowAdjustmentType() {
+ mAssistants.disallowAdjustmentType(Adjustment.KEY_RANKING_SCORE);
+ assertThat(mAssistants.getAllowedAssistantAdjustments())
+ .doesNotContain(Adjustment.KEY_RANKING_SCORE);
+ assertThat(mAssistants.getAllowedAssistantAdjustments()).contains(Adjustment.KEY_TYPE);
+ }
+
+ @Test
+ @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void testAllowAdjustmentType() {
+ mAssistants.disallowAdjustmentType(Adjustment.KEY_RANKING_SCORE);
+ assertThat(mAssistants.getAllowedAssistantAdjustments())
+ .doesNotContain(Adjustment.KEY_RANKING_SCORE);
+ mAssistants.allowAdjustmentType(Adjustment.KEY_RANKING_SCORE);
+ assertThat(mAssistants.getAllowedAssistantAdjustments())
+ .contains(Adjustment.KEY_RANKING_SCORE);
+ }
+
+ @Test
+ @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
+ public void testDisallowAdjustmentType_readWriteXml_entries() throws Exception {
+ int userId = ActivityManager.getCurrentUser();
+
+ mAssistants.loadDefaultsFromConfig(true);
+ mAssistants.disallowAdjustmentType(KEY_IMPORTANCE);
+
+ writeXmlAndReload(USER_ALL);
+
+ assertThat(mAssistants.getAllowedAssistantAdjustments()).contains(
+ Adjustment.KEY_NOT_CONVERSATION);
+ assertThat(mAssistants.getAllowedAssistantAdjustments()).doesNotContain(
+ KEY_IMPORTANCE);
+ }
+
+ @Test
+ public void testDefaultAllowedAdjustments_readWriteXml_entries() throws Exception {
+ mAssistants.loadDefaultsFromConfig(true);
+
+ writeXmlAndReload(USER_ALL);
+
+ assertThat(mAssistants.getAllowedAssistantAdjustments())
+ .containsExactlyElementsIn(DEFAULT_ALLOWED_ADJUSTMENTS);
+ }
} \ No newline at end of file