diff --git a/core/api/system-current.txt b/core/api/system-current.txt index b6e4bcc0bd5c8..4029f2ac32aba 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -12450,7 +12450,7 @@ package android.service.notification { method public final void adjustNotification(@NonNull android.service.notification.Adjustment); method public final void adjustNotifications(@NonNull java.util.List); method public void onActionInvoked(@NonNull String, @NonNull android.app.Notification.Action, int); - method public void onAllowedAdjustmentsChanged(); + method @Deprecated 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 c25f875dd9976..f310d8d548f53 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -349,9 +349,7 @@ package android.app { } public class NotificationManager { - method public void allowAssistantAdjustment(String); method public void cleanUpCallersAfter(long); - method public void disallowAssistantAdjustment(String); method public android.content.ComponentName getEffectsSuppressor(); method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String); method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean, boolean); diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 302d1469e1fb5..ab32f4d212375 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -80,8 +80,6 @@ interface INotificationManager boolean isImportanceLocked(String pkg, int uid); List 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 4e94a1dcf6422..82adaaf70bcbe 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -1577,32 +1577,6 @@ public class NotificationManager { } } - /** - * @hide - */ - @TestApi - public void allowAssistantAdjustment(String capability) { - INotificationManager service = getService(); - try { - service.allowAssistantAdjustment(capability); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** - * @hide - */ - @TestApi - public void disallowAssistantAdjustment(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/Adjustment.java b/core/java/android/service/notification/Adjustment.java index 38076858084c0..9696dbcc421b9 100644 --- a/core/java/android/service/notification/Adjustment.java +++ b/core/java/android/service/notification/Adjustment.java @@ -51,8 +51,17 @@ public final class Adjustment implements Parcelable { /** @hide */ @StringDef (prefix = { "KEY_" }, value = { - KEY_CONTEXTUAL_ACTIONS, KEY_GROUP_KEY, KEY_IMPORTANCE, KEY_PEOPLE, KEY_SNOOZE_CRITERIA, - KEY_TEXT_REPLIES, KEY_USER_SENTIMENT, KEY_IMPORTANCE_PROPOSAL, KEY_SENSITIVE_CONTENT + KEY_PEOPLE, + KEY_SNOOZE_CRITERIA, + KEY_GROUP_KEY, + KEY_USER_SENTIMENT, + KEY_CONTEXTUAL_ACTIONS, + KEY_TEXT_REPLIES, + KEY_IMPORTANCE, + KEY_IMPORTANCE_PROPOSAL, + KEY_SENSITIVE_CONTENT, + KEY_RANKING_SCORE, + KEY_NOT_CONVERSATION }) @Retention(RetentionPolicy.SOURCE) public @interface Keys {} @@ -65,6 +74,7 @@ public final class Adjustment implements Parcelable { */ @SystemApi public static final String KEY_PEOPLE = "key_people"; + /** * Parcelable {@code ArrayList} of {@link SnoozeCriterion}. These criteria may be visible to * users. If a user chooses to snooze a notification until one of these criterion, the @@ -72,6 +82,7 @@ public final class Adjustment implements Parcelable { * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}. */ public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria"; + /** * Data type: String. Used to change what {@link Notification#getGroup() group} a notification * belongs to. diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl index b384b66bf6807..37a91e720aad1 100644 --- a/core/java/android/service/notification/INotificationListener.aidl +++ b/core/java/android/service/notification/INotificationListener.aidl @@ -58,6 +58,7 @@ 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 a38ef96760729..76889dfc300ab 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -293,7 +293,10 @@ public abstract class NotificationAssistantService extends NotificationListenerS * their notifications the assistant can modify. *

Query {@link NotificationManager#getAllowedAssistantAdjustments()} to see what * {@link Adjustment adjustments} you are currently allowed to make.

+ * + * @deprecated changing allowed adjustments is no longer supported. */ + @Deprecated public void onAllowedAdjustmentsChanged() { } diff --git a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java index 1084c71397e4d..f42bc81229cf4 100644 --- a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java +++ b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java @@ -47,26 +47,11 @@ public final class SystemUiDeviceConfigFlags { */ public static final String NAS_MAX_SUGGESTIONS = "nas_max_suggestions"; - /** - * Whether the Notification Assistant can change ranking. - */ - public static final String ENABLE_NAS_RANKING = "enable_nas_ranking"; - - /** - * Whether the Notification Assistant can prioritize notification. - */ - public static final String ENABLE_NAS_PRIORITIZER = "enable_nas_prioritizer"; - /** * Whether to enable feedback UI for Notification Assistant */ public static final String ENABLE_NAS_FEEDBACK = "enable_nas_feedback"; - /** - * Whether the Notification Assistant can label a notification not a conversation - */ - public static final String ENABLE_NAS_NOT_CONVERSATION = "enable_nas_not_conversation"; - // Flags related to screenshot intelligence /** diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c1b3834eba706..fd9f8d113dec1 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -393,12 +393,17 @@ public class NotificationManagerService extends SystemService { static final int INVALID_UID = -1; static final String ROOT_PKG = "root"; - static final String[] DEFAULT_ALLOWED_ADJUSTMENTS = new String[] { + static final String[] ALLOWED_ADJUSTMENTS = new String[] { + Adjustment.KEY_PEOPLE, + Adjustment.KEY_SNOOZE_CRITERIA, + Adjustment.KEY_USER_SENTIMENT, Adjustment.KEY_CONTEXTUAL_ACTIONS, Adjustment.KEY_TEXT_REPLIES, - Adjustment.KEY_NOT_CONVERSATION, Adjustment.KEY_IMPORTANCE, - Adjustment.KEY_RANKING_SCORE + Adjustment.KEY_IMPORTANCE_PROPOSAL, + Adjustment.KEY_SENSITIVE_CONTENT, + Adjustment.KEY_RANKING_SCORE, + Adjustment.KEY_NOT_CONVERSATION }; static final String[] NON_BLOCKABLE_DEFAULT_ROLES = new String[] { @@ -2567,27 +2572,6 @@ public class NotificationManagerService extends SystemService { for (String name : properties.getKeyset()) { if (SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE.equals(name)) { mAssistants.resetDefaultAssistantsIfNecessary(); - } else if (SystemUiDeviceConfigFlags.ENABLE_NAS_PRIORITIZER.equals(name)) { - String value = properties.getString(name, null); - if ("true".equals(value)) { - mAssistants.allowAdjustmentType(Adjustment.KEY_IMPORTANCE); - } else if ("false".equals(value)) { - mAssistants.disallowAdjustmentType(Adjustment.KEY_IMPORTANCE); - } - } else if (SystemUiDeviceConfigFlags.ENABLE_NAS_RANKING.equals(name)) { - String value = properties.getString(name, null); - if ("true".equals(value)) { - mAssistants.allowAdjustmentType(Adjustment.KEY_RANKING_SCORE); - } else if ("false".equals(value)) { - mAssistants.disallowAdjustmentType(Adjustment.KEY_RANKING_SCORE); - } - } else if (SystemUiDeviceConfigFlags.ENABLE_NAS_NOT_CONVERSATION.equals(name)) { - String value = properties.getString(name, null); - if ("true".equals(value)) { - mAssistants.allowAdjustmentType(Adjustment.KEY_NOT_CONVERSATION); - } else if ("false".equals(value)) { - mAssistants.disallowAdjustmentType(Adjustment.KEY_NOT_CONVERSATION); - } } else if (SystemUiDeviceConfigFlags.TASK_MANAGER_ENABLED.equals(name)) { String value = properties.getString(name, null); if ("true".equals(value)) { @@ -4256,22 +4240,6 @@ public class NotificationManagerService extends SystemService { return mAssistants.getAllowedAssistantAdjustments(); } - @Override - public void allowAssistantAdjustment(String adjustmentType) { - checkCallerIsSystemOrSystemUiOrShell(); - mAssistants.allowAdjustmentType(adjustmentType); - - handleSavePolicyFile(); - } - - @Override - public void disallowAssistantAdjustment(String adjustmentType) { - checkCallerIsSystemOrSystemUiOrShell(); - mAssistants.disallowAdjustmentType(adjustmentType); - - handleSavePolicyFile(); - } - /** * @deprecated Use {@link #getActiveNotificationsWithAttribution(String, String)} instead. */ @@ -10146,8 +10114,6 @@ public class NotificationManagerService extends SystemService { public class NotificationAssistants extends ManagedServices { static final String TAG_ENABLED_NOTIFICATION_ASSISTANTS = "enabled_assistants"; - private static final String TAG_ALLOWED_ADJUSTMENT_TYPES_OLD = "q_allowed_adjustments"; - private static final String TAG_ALLOWED_ADJUSTMENT_TYPES = "s_allowed_adjustments"; private static final String ATT_TYPES = "types"; private final Object mLock = new Object(); @@ -10224,10 +10190,9 @@ public class NotificationManagerService extends SystemService { IPackageManager pm) { super(context, lock, up, pm); - // Add all default allowed adjustment types. Will be overwritten by values in xml, - // if they exist - for (int i = 0; i < DEFAULT_ALLOWED_ADJUSTMENTS.length; i++) { - mAllowedAdjustments.add(DEFAULT_ALLOWED_ADJUSTMENTS[i]); + // Add all default allowed adjustment types. + for (int i = 0; i < ALLOWED_ADJUSTMENTS.length; i++) { + mAllowedAdjustments.add(ALLOWED_ADJUSTMENTS[i]); } } @@ -10285,52 +10250,6 @@ public class NotificationManagerService extends SystemService { return android.Manifest.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE; } - @Override - protected void writeExtraXmlTags(TypedXmlSerializer out) throws IOException { - synchronized (mLock) { - out.startTag(null, TAG_ALLOWED_ADJUSTMENT_TYPES); - out.attribute(null, ATT_TYPES, TextUtils.join(",", mAllowedAdjustments)); - out.endTag(null, TAG_ALLOWED_ADJUSTMENT_TYPES); - } - } - - @Override - protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException { - if (TAG_ALLOWED_ADJUSTMENT_TYPES_OLD.equals(tag) - || TAG_ALLOWED_ADJUSTMENT_TYPES.equals(tag)) { - final String types = XmlUtils.readStringAttribute(parser, ATT_TYPES); - synchronized (mLock) { - mAllowedAdjustments.clear(); - if (!TextUtils.isEmpty(types)) { - mAllowedAdjustments.addAll(Arrays.asList(types.split(","))); - } - if (TAG_ALLOWED_ADJUSTMENT_TYPES_OLD.equals(tag)) { - if (DEBUG) Slog.d(TAG, "Migrate allowed adjustments."); - mAllowedAdjustments.addAll( - Arrays.asList(DEFAULT_ALLOWED_ADJUSTMENTS)); - } - } - } - } - - protected void allowAdjustmentType(String type) { - synchronized (mLock) { - mAllowedAdjustments.add(type); - } - for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) { - mHandler.post(() -> notifyCapabilitiesChanged(info)); - } - } - - protected void disallowAdjustmentType(String type) { - synchronized (mLock) { - mAllowedAdjustments.remove(type); - } - for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) { - mHandler.post(() -> notifyCapabilitiesChanged(info)); - } - } - protected List getAllowedAssistantAdjustments() { synchronized (mLock) { List types = new ArrayList<>(); @@ -10402,15 +10321,6 @@ public class NotificationManagerService extends SystemService { mIsUserChanged.put(userId, set); } - 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); - } - } - private void notifySeen(final ManagedServiceInfo info, final ArrayList keys) { final INotificationListener assistant = (INotificationListener) info.service; 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 9c68ddc9af6a3..33ca5c2bbe166 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java @@ -301,30 +301,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase { new ComponentName("b", "b").flattenToString(), 10, true, ""); } - @Test - public void testXmlMigratingAllowedAdjustments() throws Exception { - // Old tag, need migration - String xml = ""; - - TypedXmlPullParser parser = Xml.newFastPullParser(); - parser.setInput(new BufferedInputStream( - new ByteArrayInputStream(xml.toString().getBytes())), null); - parser.nextTag(); - mAssistants.readExtraTag("q_allowed_adjustments", parser); - assertTrue(mAssistants.isAdjustmentAllowed("adj_1")); - assertEquals(mNm.DEFAULT_ALLOWED_ADJUSTMENTS.length + 1, - mAssistants.getAllowedAssistantAdjustments().size()); - - // New TAG - xml = ""; - parser.setInput(new BufferedInputStream( - new ByteArrayInputStream(xml.toString().getBytes())), null); - parser.nextTag(); - mAssistants.readExtraTag("s_allowed_adjustments", parser); - assertTrue(mAssistants.isAdjustmentAllowed("adj_2")); - assertEquals(1, mAssistants.getAllowedAssistantAdjustments().size()); - } - @Test public void testSetPackageOrComponentEnabled_onlyOnePackage() throws Exception { ComponentName component1 = ComponentName.unflattenFromString("package/Component1"); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 69fccf2671da1..009b2591ea9dd 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -203,7 +203,6 @@ import androidx.test.InstrumentationRegistry; import com.android.internal.app.IAppOpsService; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; -import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags; import com.android.internal.logging.InstanceIdSequence; import com.android.internal.logging.InstanceIdSequenceFake; import com.android.internal.messages.nano.SystemMessageProto; @@ -7619,17 +7618,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetAllowedAssistantAdjustments() throws Exception { - List capabilities = mBinderService.getAllowedAssistantAdjustments(null); - assertNotNull(capabilities); - - for (int i = capabilities.size() - 1; i >= 0; i--) { - String capability = capabilities.get(i); - mBinderService.disallowAssistantAdjustment(capability); - assertEquals(i + 1, mBinderService.getAllowedAssistantAdjustments(null).size()); - List currentCapabilities = mBinderService.getAllowedAssistantAdjustments(null); - assertNotNull(currentCapabilities); - assertFalse(currentCapabilities.contains(capability)); - } + List adjustments = mBinderService.getAllowedAssistantAdjustments(null); + assertNotNull(adjustments); } @Test