Merge "Hide v1 conn. display illust. and Use toggles" into main
diff --git a/aconfig/settings_connecteddevice_flag_declarations.aconfig b/aconfig/settings_connecteddevice_flag_declarations.aconfig
index f10c019..b008c20 100644
--- a/aconfig/settings_connecteddevice_flag_declarations.aconfig
+++ b/aconfig/settings_connecteddevice_flag_declarations.aconfig
@@ -48,3 +48,10 @@
purpose: PURPOSE_BUGFIX
}
}
+
+flag {
+ name: "display_size_connected_display_setting"
+ namespace: "lse_desktop_experience"
+ description: "Allow changing display size of the connected display."
+ bug: "392853666"
+}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index df82f3e..4e770ee 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5508,13 +5508,13 @@
<!-- Summary for the accessibility preference to high contrast text. [CHAR LIMIT=NONE] -->
<string name="accessibility_toggle_high_text_contrast_preference_summary">Change text color to black or white. Maximizes contrast with the background.</string>
<!-- Title for the notification that high contrast text has been replaced. [CHAR LIMIT=NONE] -->
- <string name="accessibility_notification_high_contrast_text_title">High contrast text has been replaced</string>
+ <string name="accessibility_notification_high_contrast_text_title">Improve text contrast</string>
<!-- Text content for the notification that high contrast text has been replaced. [CHAR LIMIT=NONE] -->
- <string name="accessibility_notification_high_contrast_text_content">Try Text outlines instead. Find it in Settings.</string>
+ <string name="accessibility_notification_high_contrast_text_body"><xliff:g example="Outline text" id="outline_text">%1$s</xliff:g> has replaced <xliff:g example="high contrast text" id="high_contrast_text">%2$s</xliff:g>. You can turn it on in <xliff:g example="Settings" id="settings">%3$s</xliff:g>.</string>
<!-- Action for the notification to high contrast text. [CHAR LIMIT=35] -->
- <string name="accessibility_notification_high_contrast_text_action">Open Settings</string>
+ <string name="accessibility_notification_high_contrast_text_action">Go to <xliff:g example="Settings" id="settings">%1$s</xliff:g></string>
<!-- Title for the accessibility preference that adds an outline behind text to increase contrast and legibility. [CHAR LIMIT=35] -->
- <string name="accessibility_toggle_maximize_text_contrast_preference_title">Text outlines</string>
+ <string name="accessibility_toggle_maximize_text_contrast_preference_title">Outline text</string>
<!-- Summary for the accessibility preference to high contrast text. [CHAR LIMIT=NONE] -->
<string name="accessibility_toggle_maximize_text_contrast_preference_summary">Add a black or white background around text to increase contrast</string>
<!-- Title for the accessibility preference to auto update screen magnification. [CHAR LIMIT=35] -->
@@ -8858,7 +8858,13 @@
<string name="notification_summarization_on">On</string>
<string name="notification_summarization_off">Off</string>
<string name="notification_summarization_main_control_title">Use notification summaries</string>
- <string name="notification_summarization_description">Automatically summarize conversation notifications from any app</string>
+ <string name="notification_summarization_description">Automatically summarize conversation notifications from apps</string>
+ <string name="notification_summarization_excluded_description">Conversation notifications from these apps will not be summarized</string>
+ <string name="notification_summarization_manage_excluded_apps">Manage apps</string>
+ <string name="notification_summarization_manage_excluded_apps_title">Allow notification summaries for apps</string>
+ <string name="notification_excluded_apps">App exceptions</string>
+ <string name="notification_app_level_summarize_title">Summarize notifications</string>
+ <string name="notification_app_level_summarize_subtext">Summarize conversation notifications from this app</string>
<!-- App Info > Notifications: Title for section controlling whether this app may show notifications in a promoted format [CHAR LIMIT=80] -->
<string name="live_notifications">Live notifications</string>
@@ -9282,6 +9288,11 @@
<string name="notification_bundle_main_control_title">Use notification bundling</string>
<string name="notification_bundle_description">Notifications with similar themes will be silenced and grouped together for a quieter experience. Bundling will override an app\'s own notification settings.</string>
+ <string name="notification_app_level_bundle_title">Bundle notifications</string>
+ <string name="notification_app_level_bundle_subtext">Notifications with similar themes will be silenced and grouped together for a quieter experience</string>
+ <string name="notification_bundle_excluded_description">Notifications from these apps will not be bundled</string>
+ <string name="notification_bundle_manage_excluded_apps_title">Allow notification bundling for apps</string>
+
<!-- Title for managing VR (virtual reality) helper services. [CHAR LIMIT=50] -->
<string name="vr_listeners_title">VR helper services</string>
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
index b91aea9..901a0c9 100644
--- a/res/xml/app_notification_settings.xml
+++ b/res/xml/app_notification_settings.xml
@@ -90,6 +90,16 @@
android:summary="@string/live_notifications_desc" />
<com.android.settingslib.RestrictedSwitchPreference
+ android:key="key_summarization"
+ android:title="@string/notification_app_level_summarize_title"
+ android:summary="@string/notification_app_level_summarize_subtext" />
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="key_type"
+ android:title="@string/notification_app_level_bundle_title"
+ android:summary="@string/notification_app_level_bundle_subtext" />
+
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="invalid_conversation_switch"
android:title="@string/conversation_section_switch_title" />
<Preference
diff --git a/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java b/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java
index fbe1921..bf5b887 100644
--- a/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java
+++ b/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java
@@ -43,6 +43,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Locale;
/**
* Handling smooth migration to the new high contrast text appearance
@@ -132,14 +133,25 @@
}
}
+ private String getNotificationContentText(Context context) {
+ final String newName = context.getString(
+ R.string.accessibility_toggle_maximize_text_contrast_preference_title);
+ final String oldName = context.getString(
+ R.string.accessibility_toggle_high_text_contrast_preference_title)
+ .toLowerCase(Locale.getDefault());
+ final String settingsAppName = context.getString(R.string.settings_label);
+ return context.getString(
+ R.string.accessibility_notification_high_contrast_text_body,
+ newName, oldName, settingsAppName);
+ }
+
private void showNotification(Context context) {
Notification.Builder notificationBuilder = new Notification.Builder(context,
NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.ic_settings_24dp)
.setContentTitle(context.getString(
R.string.accessibility_notification_high_contrast_text_title))
- .setContentText(context.getString(
- R.string.accessibility_notification_high_contrast_text_content))
+ .setContentText(getNotificationContentText(context))
.setFlag(Notification.FLAG_NO_CLEAR, true);
Intent settingsIntent = createHighContrastTextSettingsIntent(context);
@@ -153,8 +165,8 @@
actionIntent, PendingIntent.FLAG_IMMUTABLE);
Notification.Action settingsAction = new Notification.Action.Builder(
/* icon= */ null,
- context.getString(
- R.string.accessibility_notification_high_contrast_text_action),
+ context.getString(R.string.accessibility_notification_high_contrast_text_action,
+ context.getString(R.string.settings_label)),
actionPendingIntent
).build();
diff --git a/src/com/android/settings/notification/LockScreenNotificationShowSeenController.java b/src/com/android/settings/notification/LockScreenNotificationShowSeenController.java
index 2c5a71e..826b728 100644
--- a/src/com/android/settings/notification/LockScreenNotificationShowSeenController.java
+++ b/src/com/android/settings/notification/LockScreenNotificationShowSeenController.java
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS;
+
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -42,7 +44,8 @@
public class LockScreenNotificationShowSeenController extends TogglePreferenceController
implements LifecycleEventObserver {
- private static final int UNSET = 0;
+ // 0 is the default value for phones, we treat 0 as off as usage
+ private static final int UNSET_OFF = 0;
static final int ON = 1;
static final int OFF = 2;
@Nullable private Preference mPreference;
@@ -96,13 +99,23 @@
@Override
public int getAvailabilityStatus() {
- if (!Flags.notificationMinimalism()) {
- return CONDITIONALLY_UNAVAILABLE;
+ if (Flags.notificationMinimalism()) {
+ if (!lockScreenShowNotification()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ // We want to show the switch when the lock screen notification minimalism flag is on.
+ return AVAILABLE;
}
- if (!lockScreenShowNotification()) {
+
+ int setting = Settings.Secure.getInt(mContext.getContentResolver(),
+ LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_OFF);
+ if (setting == UNSET_OFF) {
+ // hide the setting if the minimalism flag is off, and the device is phone
+ // UNSET_OFF is the default value for phones
return CONDITIONALLY_UNAVAILABLE;
+ } else {
+ return AVAILABLE;
}
- return AVAILABLE;
}
/**
@@ -118,9 +131,14 @@
return lockScreenShowSeenNotifications();
}
+ /**
+ * @return whether to show seen notifications on lockscreen
+ */
private boolean lockScreenShowSeenNotifications() {
+ // UNSET_OFF is the default value for phone, which is equivalent to off in effect
+ // (show seen notification)
return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == OFF;
+ Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_OFF) != ON;
}
@Override
diff --git a/src/com/android/settings/notification/LockScreenNotificationShowSensitiveController.java b/src/com/android/settings/notification/LockScreenNotificationShowSensitiveController.java
index 038cedd..3231862 100644
--- a/src/com/android/settings/notification/LockScreenNotificationShowSensitiveController.java
+++ b/src/com/android/settings/notification/LockScreenNotificationShowSensitiveController.java
@@ -81,6 +81,13 @@
public LockScreenNotificationShowSensitiveController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
+
+ // This prevents unexpected controller usages.
+ if (!KEY_SHOW_SENSITIVE.equals(preferenceKey)
+ && !KEY_SHOW_SENSITIVE_WORK_PROFILE.equals(preferenceKey)) {
+ throw new IllegalArgumentException("Invalid preference key: " + preferenceKey);
+ }
+
mContentResolver = context.getContentResolver();
mUserManager = context.getSystemService(UserManager.class);
@@ -138,13 +145,18 @@
}
private int getUserId() {
- return KEY_SHOW_SENSITIVE.equals(getPreferenceKey())
- ? UserHandle.myUserId() : mWorkProfileUserId;
+ return switch (getPreferenceKey()) {
+ case KEY_SHOW_SENSITIVE -> UserHandle.myUserId();
+ case KEY_SHOW_SENSITIVE_WORK_PROFILE -> mWorkProfileUserId;
+ default -> throw new IllegalArgumentException(
+ "Invalid preference key: " + getPreferenceKey());
+ };
}
@Override
public void updateState(@Nullable Preference preference) {
if (preference == null) return;
+ super.updateState(preference);
setChecked(showSensitiveContentWhenLocked());
preference.setVisible(isAvailable());
}
@@ -195,7 +207,7 @@
if (!isLockScreenSecure()) return true;
if (getEnforcedAdmin(userId) != null) return false;
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, ON, userId) == ON;
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, ON, userId) != OFF;
}
@Override
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index d7a747c..3ce377e 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -54,6 +54,7 @@
import android.util.IconDrawableFactory;
import android.util.Log;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.internal.util.CollectionUtils;
@@ -436,7 +437,7 @@
}
}
- public List<String> getAssistantAdjustments(String pkg) {
+ public List<String> getAllowedAssistantAdjustments(String pkg) {
try {
return sINM.getAllowedAssistantAdjustments(pkg);
} catch (Exception e) {
@@ -769,6 +770,23 @@
}
}
+ public @NonNull String[] getAdjustmentDeniedPackages(String key) {
+ try {
+ return sINM.getAdjustmentDeniedPackages(key);
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return new String[]{};
+ }
+ }
+
+ public @NonNull void setAdjustmentSupportedForPackage(String key, String pkg, boolean enabled) {
+ try {
+ sINM.setAdjustmentSupportedForPackage(key, pkg, enabled);
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ }
+ }
+
@VisibleForTesting
void setNm(INotificationManager inm) {
sINM = inm;
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index 83d5a01..92c9e2e 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -112,6 +112,7 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.redaction_interstitial, container, false);
}
diff --git a/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java b/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java
index 225fc7c..f113556 100644
--- a/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java
+++ b/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java
@@ -31,7 +31,9 @@
public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
extends TogglePreferenceController {
- private static final int UNSET = 0;
+ // This is the default value for phones, before notification minimalism, this setting is
+ // unavailable to phones, we use this value to hide the toggle on phones.
+ private static final int UNSET_UNAVAILABLE = 0;
@VisibleForTesting
static final int ON = 1;
@VisibleForTesting
@@ -46,7 +48,7 @@
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
- LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == ON;
+ LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_UNAVAILABLE) == ON;
}
@Override
@@ -69,8 +71,8 @@
return AVAILABLE;
}
int setting = Settings.Secure.getInt(mContext.getContentResolver(),
- LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET);
- if (setting == UNSET) {
+ LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_UNAVAILABLE);
+ if (setting == UNSET_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
} else {
return AVAILABLE;
diff --git a/src/com/android/settings/notification/app/AdjustmentKeyPreferenceController.java b/src/com/android/settings/notification/app/AdjustmentKeyPreferenceController.java
new file mode 100644
index 0000000..acde2da
--- /dev/null
+++ b/src/com/android/settings/notification/app/AdjustmentKeyPreferenceController.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.notification.app;
+
+import android.app.Flags;
+import android.content.Context;
+import android.service.notification.Adjustment;
+
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+
+import com.android.settings.notification.NotificationBackend;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+/**
+ * Used for the app-level preference screen to opt the app in or out of a provided Adjustment key.
+ * E.g. to say an app can or cannot be classified by the NotificationAssistantService.
+ */
+public class AdjustmentKeyPreferenceController extends
+ NotificationPreferenceController implements Preference.OnPreferenceChangeListener {
+ private String mKey;
+
+ public AdjustmentKeyPreferenceController(@NonNull Context context,
+ @NonNull NotificationBackend backend, String key) {
+ super(context, backend);
+ mKey = key;
+ }
+
+ @Override
+ @NonNull
+ public String getPreferenceKey() {
+ return mKey;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!(Flags.notificationClassificationUi() || Flags.nmSummarizationUi()
+ || Flags.nmSummarization())) {
+ return false;
+ }
+ boolean isBundlePref = Adjustment.KEY_TYPE.equals(mKey);
+ boolean isSummarizePref = Adjustment.KEY_SUMMARIZATION.equals(mKey);
+ if (!Flags.notificationClassificationUi() && isBundlePref) {
+ return false;
+ }
+ if (!(Flags.nmSummarizationUi() || Flags.nmSummarization()) && isSummarizePref) {
+ return false;
+ }
+ if (!isSummarizePref && !isBundlePref) {
+ return false;
+ }
+ if (isSummarizePref && !(mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid)
+ || mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid))) {
+ return false;
+ }
+ return super.isAvailable();
+ }
+
+ @Override
+ boolean isIncludedInFilter() {
+ // not a channel-specific preference; only at the app level
+ return false;
+ }
+
+ public void updateState(@NonNull Preference preference) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ if (pref.getParent() != null) {
+ pref.getParent().setVisible(true);
+ }
+
+ if (pref != null && mAppRow != null) {
+ pref.setDisabledByAdmin(mAdmin);
+ pref.setEnabled(!pref.isDisabledByAdmin());
+ pref.setChecked(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg).contains(mKey));
+ pref.setOnPreferenceChangeListener(this);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(@NonNull Preference preference, @NonNull Object newValue) {
+ final boolean allowedForPkg = (Boolean) newValue;
+ mBackend.setAdjustmentSupportedForPackage(mKey, mAppRow.pkg, allowedForPkg);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/notification/app/AppNotificationSettings.java b/src/com/android/settings/notification/app/AppNotificationSettings.java
index e0bcad3..1fde8fa 100644
--- a/src/com/android/settings/notification/app/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/app/AppNotificationSettings.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
+import android.service.notification.Adjustment;
import android.text.TextUtils;
import android.util.Log;
@@ -132,6 +133,10 @@
context, mDependentFieldListener, mBackend));
mControllers.add(new BundleListPreferenceController(context, mBackend));
mControllers.add(new PromotedNotificationsPreferenceController(context, mBackend));
+ mControllers.add(new AdjustmentKeyPreferenceController(context, mBackend,
+ Adjustment.KEY_SUMMARIZATION));
+ mControllers.add(new AdjustmentKeyPreferenceController(context, mBackend,
+ Adjustment.KEY_TYPE));
return new ArrayList<>(mControllers);
}
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java b/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java
index b0864aa..98c2c23 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java
@@ -46,9 +46,10 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.graphics.hwui.flags.Flags;
-import com.android.settings.R;
import com.android.settings.Utils;
+import com.google.common.truth.Expect;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -65,7 +66,8 @@
/** Tests for {@link HighContrastTextMigrationReceiver}. */
@RunWith(RobolectricTestRunner.class)
public class HighContrastTextMigrationReceiverTest {
-
+ @Rule
+ public final Expect expect = Expect.create();
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private final Context mContext = ApplicationProvider.getApplicationContext();
@@ -230,14 +232,12 @@
assertThat(notification).isNotNull();
ShadowNotification shadowNotification = Shadows.shadowOf(notification);
- assertThat(shadowNotification.getContentTitle()).isEqualTo(mContext.getString(
- R.string.accessibility_notification_high_contrast_text_title));
- assertThat(shadowNotification.getContentText()).isEqualTo(
- mContext.getString(R.string.accessibility_notification_high_contrast_text_content));
+ expect.that(shadowNotification.getContentTitle()).isEqualTo("Improve text contrast");
+ expect.that(shadowNotification.getContentText()).isEqualTo(
+ "Outline text has replaced high contrast text. You can turn it on in Settings.");
- assertThat(notification.actions.length).isEqualTo(1);
- assertThat(notification.actions[0].title.toString()).isEqualTo(
- mContext.getString(R.string.accessibility_notification_high_contrast_text_action));
+ expect.that(notification.actions.length).isEqualTo(1);
+ expect.that(notification.actions[0].title.toString()).isEqualTo("Go to Settings");
}
private void assertPromptStateAndHctState(
diff --git a/tests/robotests/src/com/android/settings/notification/LockScreenNotificationShowSensitiveControllerTest.java b/tests/robotests/src/com/android/settings/notification/LockScreenNotificationShowSensitiveControllerTest.java
index 9a29de2..1cc6290 100644
--- a/tests/robotests/src/com/android/settings/notification/LockScreenNotificationShowSensitiveControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/LockScreenNotificationShowSensitiveControllerTest.java
@@ -131,6 +131,14 @@
assertThat(mWorkController.mWorkProfileUserId).isEqualTo(10);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void validatePreferenceId() {
+ new LockScreenNotificationShowSensitiveController(
+ mMockContext,
+ "Illegal Key"
+ );
+ }
+
@Test
public void getAvailabilityStatus_noSecureLockscreen() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
@@ -266,34 +274,58 @@
@Test
public void isChecked() {
+ // Given: screen is secure
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+
+ // When: disable LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
+ // then updateState, this mocks the mWorkController.mContentObserver.onChange()
Settings.Secure.putIntForUser(mContext.getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
0, 0);
+ mController.updateState(mPreference);
+ // Then: the toggle is unchecked
assertThat(mController.isChecked()).isFalse();
+ assertThat(mPreference.isChecked()).isFalse();
+ // When: enable LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
+ // then updateState, this mocks the mWorkController.mContentObserver.onChange()
Settings.Secure.putIntForUser(mContext.getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
1, 0);
+ mController.updateState(mPreference);
+ // Then: the toggle is checked
assertThat(mController.isChecked()).isTrue();
+ assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void isChecked_work() {
+ // Given: screen is secure
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+
+ // When: disable LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS for work profile
+ // then updateState, this mocks the mWorkController.mContentObserver.onChange()
Settings.Secure.putIntForUser(mContext.getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
0, 10);
+ mWorkController.updateState(mWorkPreference);
+ // Then: the toggle is unchecked
assertThat(mWorkController.isChecked()).isFalse();
+ assertThat(mWorkPreference.isChecked()).isFalse();
+ // When: enable LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS for work profile
+ // then updateState, this mocks the mWorkController.mContentObserver.onChange()
Settings.Secure.putIntForUser(mContext.getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
1, 10);
+ mWorkController.updateState(mWorkPreference);
+ // Then: the toggle is checked
assertThat(mWorkController.isChecked()).isTrue();
+ assertThat(mWorkPreference.isChecked()).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/app/AdjustmentKeyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AdjustmentKeyPreferenceControllerTest.java
new file mode 100644
index 0000000..f458769
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/app/AdjustmentKeyPreferenceControllerTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.notification.app;
+
+import static android.service.notification.Adjustment.KEY_IMPORTANCE;
+import static android.service.notification.Adjustment.KEY_SUMMARIZATION;
+import static android.service.notification.Adjustment.KEY_TYPE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Flags;
+import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import androidx.preference.PreferenceManager;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.notification.NotificationBackend;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class AdjustmentKeyPreferenceControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ private Context mContext;
+ private NotificationBackend.AppRow mAppRow;
+ @Mock
+ private NotificationBackend mBackend;
+ private RestrictedSwitchPreference mSwitch;
+
+ private AdjustmentKeyPreferenceController mPrefController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
+ mSwitch = new RestrictedSwitchPreference(mContext);
+ new PreferenceManager(mContext).createPreferenceScreen(mContext).addPreference(mSwitch);
+ when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(true);
+
+ mPrefController = new AdjustmentKeyPreferenceController(mContext, mBackend, KEY_TYPE);
+
+ mAppRow = new NotificationBackend.AppRow();
+ mAppRow.pkg = "pkg.name";
+ mAppRow.uid = 12345;
+ mPrefController.onResume(mAppRow, null, null, null, null, null, null);
+ }
+
+ @Test
+ @DisableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
+ Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+ public void testIsAvailable_flagOff() {
+ assertThat(mPrefController.isAvailable()).isFalse();
+ }
+
+ @Test
+ @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
+ Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+ public void testIsAvailable_flagOn() {
+ assertThat(mPrefController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
+ Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+ public void testIsAvailable_summarization_notMsgApp() {
+ when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
+
+ mPrefController = new AdjustmentKeyPreferenceController(
+ mContext, mBackend, KEY_SUMMARIZATION);
+ mPrefController.onResume(mAppRow, null, null, null, null, null, null);
+
+ assertThat(mPrefController.isAvailable()).isFalse();
+ }
+
+ @Test
+ @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
+ Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+ public void testChecked_adjustmentAllowed() {
+ when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
+ List.of(KEY_TYPE, KEY_IMPORTANCE));
+ mPrefController.onResume(mAppRow, null, null, null, null, null, null);
+
+ mPrefController.updateState(mSwitch);
+ assertThat(mSwitch.isChecked()).isTrue();
+
+ when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
+ List.of(KEY_SUMMARIZATION, KEY_IMPORTANCE));
+ mPrefController.onResume(mAppRow, null, null, null, null, null, null);
+ mPrefController.updateState(mSwitch);
+ assertThat(mSwitch.isChecked()).isFalse();
+ }
+
+ @Test
+ @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
+ Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+ public void testOnPreferenceChange_changeOnAndOff() {
+ when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
+ List.of(KEY_TYPE, KEY_IMPORTANCE));
+ mPrefController.onResume(mAppRow, null, null, null, null, null, null);
+
+ // when the switch value changes to false
+ mPrefController.onPreferenceChange(mSwitch, false);
+
+ verify(mBackend, times(1))
+ .setAdjustmentSupportedForPackage(eq(KEY_TYPE), eq(mAppRow.pkg), eq(false));
+
+ // same as above but now from false -> true
+ mPrefController.onPreferenceChange(mSwitch, true);
+ verify(mBackend, times(1))
+ .setAdjustmentSupportedForPackage(eq(KEY_TYPE), eq(mAppRow.pkg), eq(true));
+ }
+}