Remove functionality to change allowed NAS adjustments in NMS.
Bug: 268604587 Test: NotificationAssistantServiceTest (in cts repo in same topic) Test: NotificationManagerServiceTest Test: NotificationAssistantsTest Change-Id: If92c88d89a4a70709822fe149f2f60ae6c9b5fcb
This commit is contained in:
@@ -12381,7 +12381,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 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -80,8 +80,6 @@ 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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,10 @@ 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() {
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
@@ -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[] {
|
||||
@@ -2569,27 +2574,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<String> getAllowedAssistantAdjustments() {
|
||||
synchronized (mLock) {
|
||||
List<String> 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<String> keys) {
|
||||
final INotificationListener assistant = (INotificationListener) info.service;
|
||||
|
||||
@@ -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 = "<q_allowed_adjustments types=\"adj_1\"/>";
|
||||
|
||||
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 = "<s_allowed_adjustments types=\"adj_2\"/>";
|
||||
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");
|
||||
|
||||
@@ -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<String> 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<String> currentCapabilities = mBinderService.getAllowedAssistantAdjustments(null);
|
||||
assertNotNull(currentCapabilities);
|
||||
assertFalse(currentCapabilities.contains(capability));
|
||||
}
|
||||
List<String> adjustments = mBinderService.getAllowedAssistantAdjustments(null);
|
||||
assertNotNull(adjustments);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user