Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73a8c1b0 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Update the notification_assistant DeviceConfig namespace.

To adhere to new API guidelines we here update the
notification_assistant namespace in DeviceConfig.

Bug: 120792826
Test: make ExtServices
    && adb install -r $OUT/system/priv-app/ExtServices/ExtServices.apk
    && atest ExtServicesUnitTests
Change-Id: I85f714931c28c7a35c64b1394992afcd7aa68490
parent 9b23e4f4
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -5728,7 +5728,6 @@ package android.provider {
    field public static final String NAMESPACE_GAME_DRIVER = "game_driver";
    field public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
    field public static final String NAMESPACE_NETD_NATIVE = "netd_native";
    field public static final String NAMESPACE_NOTIFICATION_ASSISTANT = "notification_assistant";
  }
  public static interface DeviceConfig.ActivityManager {
@@ -5761,6 +5760,12 @@ package android.provider {
    field public static final String PROPERTY_ATTENTION_SETTINGS = "attention_settings";
  }
  public static interface DeviceConfig.NotificationAssistant {
    field public static final String GENERATE_ACTIONS = "generate_actions";
    field public static final String GENERATE_REPLIES = "generate_replies";
    field public static final String NAMESPACE = "notification_assistant";
  }
  public static interface DeviceConfig.OnPropertyChangedListener {
    method public void onPropertyChanged(String, String, String);
  }
+11 −1
Original line number Diff line number Diff line
@@ -102,7 +102,17 @@ public final class DeviceConfig {
     * @hide
     */
    @SystemApi
    public static final String NAMESPACE_NOTIFICATION_ASSISTANT = "notification_assistant";
    public interface NotificationAssistant {
        String NAMESPACE = "notification_assistant";
        /**
         * Whether the Notification Assistant should generate replies for notifications.
         */
        String GENERATE_REPLIES = "generate_replies";
        /**
         * Whether the Notification Assistant should generate contextual actions for notifications.
         */
        String GENERATE_ACTIONS = "generate_actions";
    }

    /**
     * Namespace for attention-based features provided by on-device machine intelligence.
+6 −24
Original line number Diff line number Diff line
@@ -46,24 +46,6 @@ final class AssistantSettings extends ContentObserver {
    private static final Uri NOTIFICATION_NEW_INTERRUPTION_MODEL_URI =
            Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL);

    /**
     * Flag determining whether the Notification Assistant should generate replies for
     * notifications.
     * <p>
     * This flag belongs to the namespace: {@link DeviceConfig#NAMESPACE_NOTIFICATION_ASSISTANT}.
     */
    @VisibleForTesting
    static final String KEY_GENERATE_REPLIES = "notification_assistant_generate_replies";

    /**
     * Flag determining whether the Notification Assistant should generate contextual actions in
     * notifications.
     * <p>
     * This flag belongs to the namespace: {@link DeviceConfig#NAMESPACE_NOTIFICATION_ASSISTANT}.
     */
    @VisibleForTesting
    static final String KEY_GENERATE_ACTIONS = "notification_assistant_generate_actions";

    private final KeyValueListParser mParser = new KeyValueListParser(',');
    private final ContentResolver mResolver;
    private final int mUserId;
@@ -118,7 +100,7 @@ final class AssistantSettings extends ContentObserver {

    private void registerDeviceConfigs() {
        DeviceConfig.addOnPropertyChangedListener(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                this::postToHandler,
                this::onDeviceConfigPropertyChanged);

@@ -132,7 +114,7 @@ final class AssistantSettings extends ContentObserver {

    @VisibleForTesting
    void onDeviceConfigPropertyChanged(String namespace, String name, String value) {
        if (!DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT.equals(namespace)) {
        if (!DeviceConfig.NotificationAssistant.NAMESPACE.equals(namespace)) {
            Log.e(LOG_TAG, "Received update from DeviceConfig for unrelated namespace: "
                    + namespace + " " + name + "=" + value);
            return;
@@ -143,8 +125,8 @@ final class AssistantSettings extends ContentObserver {

    private void updateFromDeviceConfigFlags() {
        String generateRepliesFlag = DeviceConfig.getProperty(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                KEY_GENERATE_REPLIES);
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES);
        if (TextUtils.isEmpty(generateRepliesFlag)) {
            mGenerateReplies = DEFAULT_GENERATE_REPLIES;
        } else {
@@ -154,8 +136,8 @@ final class AssistantSettings extends ContentObserver {
        }

        String generateActionsFlag = DeviceConfig.getProperty(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                KEY_GENERATE_ACTIONS);
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS);
        if (TextUtils.isEmpty(generateActionsFlag)) {
            mGenerateActions = DEFAULT_GENERATE_ACTIONS;
        } else {
+56 −16
Original line number Diff line number Diff line
@@ -71,9 +71,14 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateRepliesDisabled() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_REPLIES,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "false");

        assertFalse(mAssistantSettings.mGenerateReplies);
@@ -81,9 +86,14 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateRepliesEnabled() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "true",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_REPLIES,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "true");

        assertTrue(mAssistantSettings.mGenerateReplies);
@@ -91,16 +101,26 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateRepliesEmptyFlag() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_REPLIES,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "false");

        assertFalse(mAssistantSettings.mGenerateReplies);

        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_REPLIES,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES,
                "");

        // Go back to the default value.
@@ -109,9 +129,14 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateActionsDisabled() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_ACTIONS,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "false");

        assertFalse(mAssistantSettings.mGenerateActions);
@@ -119,9 +144,14 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateActionsEnabled() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "true",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_ACTIONS,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "true");

        assertTrue(mAssistantSettings.mGenerateActions);
@@ -129,16 +159,26 @@ public class AssistantSettingsTest {

    @Test
    public void testGenerateActionsEmptyFlag() {
        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_ACTIONS,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "false");

        assertFalse(mAssistantSettings.mGenerateActions);

        DeviceConfig.setProperty(
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_NOTIFICATION_ASSISTANT,
                AssistantSettings.KEY_GENERATE_ACTIONS,
                DeviceConfig.NotificationAssistant.NAMESPACE,
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS,
                "");

        // Go back to the default value.