diff options
| author | 2020-08-03 17:23:04 +0000 | |
|---|---|---|
| committer | 2020-08-03 17:23:04 +0000 | |
| commit | 570fc4b20af81c7a99808fcf07655fd739e4887d (patch) | |
| tree | c4c7ad2b227ff7f4e6a1e4fd4981632aab8d18b5 | |
| parent | 512a6b3089563fd4e3ae34aac128d70afae7fd8f (diff) | |
| parent | 9b421ee9dad252456e092121092eff5760f72c38 (diff) | |
Merge "Cache Feedback Enabled Setting in Controller"
7 files changed, 47 insertions, 21 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 7ee41b9fe418..5acc11a868bf 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -8728,16 +8728,6 @@ public final class Settings { = "bubble_important_conversations"; /** - * When enabled, notifications the notification assistant service has modified will show an - * indicator. When tapped, this indicator will describe the adjustment made and solicit - * feedback. This flag will also add a "automatic" option to the long press menu. - * - * The value 1 - enable, 0 - disable - * @hide - */ - public static final String NOTIFICATION_FEEDBACK_ENABLED = "notification_feedback_enabled"; - - /** * Whether notifications are dismissed by a right-to-left swipe (instead of a left-to-right * swipe). * @@ -14047,6 +14037,16 @@ public final class Settings { "notification_snooze_options"; /** + * When enabled, notifications the notification assistant service has modified will show an + * indicator. When tapped, this indicator will describe the adjustment made and solicit + * feedback. This flag will also add a "automatic" option to the long press menu. + * + * The value 1 - enable, 0 - disable + * @hide + */ + public static final String NOTIFICATION_FEEDBACK_ENABLED = "notification_feedback_enabled"; + + /** * Settings key for the ratio of notification dismissals to notification views - one of the * criteria for showing the notification blocking helper. * diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index 18c2957b1adc..4eea8ad92e61 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -112,7 +112,6 @@ public class SecureSettings { Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, Settings.Secure.VR_DISPLAY_MODE, Settings.Secure.NOTIFICATION_BADGING, - Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED, Settings.Secure.NOTIFICATION_DISMISS_RTL, Settings.Secure.QS_AUTO_ADDED_TILES, Settings.Secure.SCREENSAVER_ENABLED, diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java index dd94d2eb8fe0..a02d67fd7bca 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java @@ -149,5 +149,6 @@ public class GlobalSettingsValidators { VALIDATORS.put(Global.CUSTOM_BUGREPORT_HANDLER_APP, ANY_STRING_VALIDATOR); VALIDATORS.put(Global.CUSTOM_BUGREPORT_HANDLER_USER, ANY_INTEGER_VALIDATOR); VALIDATORS.put(Global.DEVELOPMENT_SETTINGS_ENABLED, BOOLEAN_VALIDATOR); + VALIDATORS.put(Global.NOTIFICATION_FEEDBACK_ENABLED, BOOLEAN_VALIDATOR); } } diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index 91f3f4af0566..c68ddbdcb5ad 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -189,7 +189,6 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.SHOW_NOTIFICATION_SNOOZE, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.NOTIFICATION_HISTORY_ENABLED, BOOLEAN_VALIDATOR); - VALIDATORS.put(Secure.NOTIFICATION_FEEDBACK_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.ZEN_DURATION, ANY_INTEGER_VALIDATOR); VALIDATORS.put(Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.SHOW_ZEN_SETTINGS_SUGGESTION, BOOLEAN_VALIDATOR); diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index 24f8104570db..4bb8f45f331f 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -389,6 +389,7 @@ public class SettingsBackupTest { Settings.Global.NITZ_UPDATE_DIFF, Settings.Global.NITZ_UPDATE_SPACING, Settings.Global.NOTIFICATION_SNOOZE_OPTIONS, + Settings.Global.NOTIFICATION_FEEDBACK_ENABLED, Settings.Global.NR_NSA_TRACKING_SCREEN_OFF_MODE, Settings.Global.NSD_ON, Settings.Global.NTP_SERVER, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/AssistantFeedbackController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/AssistantFeedbackController.java index ca0f62ea7538..b813b6280c12 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/AssistantFeedbackController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/AssistantFeedbackController.java @@ -20,9 +20,16 @@ import static android.service.notification.NotificationListenerService.Ranking; import android.content.ContentResolver; import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import android.os.UserHandle; import android.provider.Settings; +import androidx.annotation.Nullable; + +import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import javax.inject.Inject; @@ -35,23 +42,42 @@ import javax.inject.Singleton; * should show an indicator. */ @Singleton -public class AssistantFeedbackController { +public class AssistantFeedbackController extends ContentObserver { + private final Uri FEEDBACK_URI + = Settings.Global.getUriFor(Settings.Global.NOTIFICATION_FEEDBACK_ENABLED); private ContentResolver mResolver; + private boolean mFeedbackEnabled; + /** Injected constructor */ @Inject public AssistantFeedbackController(Context context) { + super(new Handler(Looper.getMainLooper())); mResolver = context.getContentResolver(); + mResolver.registerContentObserver(FEEDBACK_URI, false, this, UserHandle.USER_ALL); + update(null); + } + + @Override + public void onChange(boolean selfChange, @Nullable Uri uri, int flags) { + update(uri); + } + + @VisibleForTesting + public void update(@Nullable Uri uri) { + if (uri == null || FEEDBACK_URI.equals(uri)) { + mFeedbackEnabled = Settings.Global.getInt(mResolver, + Settings.Global.NOTIFICATION_FEEDBACK_ENABLED, 0) + != 0; + } } /** * Determines whether to show any user controls related to the assistant. This is based on the - * settings flag {@link Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED} + * settings flag {@link Settings.Global.NOTIFICATION_FEEDBACK_ENABLED} */ public boolean isFeedbackEnabled() { - return Settings.Secure.getIntForUser(mResolver, - Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED, 0, - UserHandle.USER_CURRENT) == 1; + return mFeedbackEnabled; } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AssistantFeedbackControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AssistantFeedbackControllerTest.java index 619d2444b4dd..fb8c3d9af05c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AssistantFeedbackControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AssistantFeedbackControllerTest.java @@ -57,8 +57,8 @@ public class AssistantFeedbackControllerTest extends SysuiTestCase { @Before public void setUp() { - switchSetting(ON); mAssistantFeedbackController = new AssistantFeedbackController(mContext); + switchSetting(ON); mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, new Notification(), UserHandle.CURRENT, null, 0); @@ -72,7 +72,6 @@ public class AssistantFeedbackControllerTest extends SysuiTestCase { @Test public void testUserControls_settingEnabled() { - switchSetting(ON); assertTrue(mAssistantFeedbackController.isFeedbackEnabled()); } @@ -113,7 +112,8 @@ public class AssistantFeedbackControllerTest extends SysuiTestCase { } private void switchSetting(int setting) { - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED, setting, UserHandle.USER_CURRENT); + Settings.Global.putInt(mContext.getContentResolver(), + Settings.Global.NOTIFICATION_FEEDBACK_ENABLED, setting); + mAssistantFeedbackController.update(null); } } |