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

Commit ddd78b2d authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Move NotificationAssistant flags into SystemUi namespace.

Create SystemUi DeviceConfig namespace and add a class to store all its
flags in. These flags will be shared between the SystemUi package and
other Notification packages - like ExtServices and
NotificationManagerService.

Performing experiments across different packages is much more involved
than performed single-package experiments. Therefore, we put flags
related to Notifications into the System UI experiment flag package.

Bug: 120792826
Test: atest AssistantSettingsTest
Change-Id: I83992291e660ab092bed8d22d1abaaa2bd9d6f9a
parent c0c7f756
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -5791,6 +5791,7 @@ 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_SYSTEMUI = "systemui";
  }
  public static interface DeviceConfig.ActivityManager {
@@ -5833,14 +5834,6 @@ package android.provider {
    field public static final String NAMESPACE = "media_native";
  }
  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 MAX_MESSAGES_TO_EXTRACT = "max_messages_to_extract";
    field public static final String MAX_SUGGESTIONS = "max_suggestions";
    field public static final String NAMESPACE = "notification_assistant";
  }
  public static interface DeviceConfig.OnPropertyChangedListener {
    method public void onPropertyChanged(String, String, String);
  }
+2 −17
Original line number Diff line number Diff line
@@ -100,27 +100,12 @@ public final class DeviceConfig {
    public static final String NAMESPACE_NETD_NATIVE = "netd_native";

    /**
     * Namespace for features related to the ExtServices Notification Assistant.
     * These features are applied immediately.
     * Namespace for System UI related features.
     *
     * @hide
     */
    @SystemApi
    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";

        String MAX_MESSAGES_TO_EXTRACT = "max_messages_to_extract";

        String MAX_SUGGESTIONS = "max_suggestions";
    }
    public static final String NAMESPACE_SYSTEMUI = "systemui";

    /**
     * Namespace for all runtime related features.
+49 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2019 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.internal.config.sysui;

/**
 * Keeps the flags related to the SystemUI namespace in {@link DeviceConfig}.
 *
 * @hide
 */
public final class SystemUiDeviceConfigFlags {

    /**
     * Whether the Notification Assistant should generate replies for notifications.
     */
    public static final String NAS_GENERATE_REPLIES = "nas_generate_replies";

    /**
     * Whether the Notification Assistant should generate contextual actions for notifications.
     */
    public static final String NAS_GENERATE_ACTIONS = "nas_generate_actions";

    /**
     * The maximum number of messages the Notification Assistant should extract from a
     * conversation when constructing responses for that conversation.
     */
    public static final String NAS_MAX_MESSAGES_TO_EXTRACT = "nas_max_messages_to_extract";

    /**
     * The maximum number of suggestions the Notification Assistant should provide for a
     * messaging conversation.
     */
    public static final String NAS_MAX_SUGGESTIONS = "nas_max_suggestions";

    private SystemUiDeviceConfigFlags() { }
}
+9 −9
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;

/**
 * Observes the settings for {@link Assistant}.
@@ -103,7 +104,7 @@ final class AssistantSettings extends ContentObserver {

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

@@ -117,7 +118,7 @@ final class AssistantSettings extends ContentObserver {

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

    private void updateFromDeviceConfigFlags() {
        mGenerateReplies = DeviceConfigHelper.getBoolean(
                DeviceConfig.NotificationAssistant.GENERATE_REPLIES, DEFAULT_GENERATE_REPLIES);
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, DEFAULT_GENERATE_REPLIES);

        mGenerateActions = DeviceConfigHelper.getBoolean(
                DeviceConfig.NotificationAssistant.GENERATE_ACTIONS, DEFAULT_GENERATE_ACTIONS);
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, DEFAULT_GENERATE_ACTIONS);

        mMaxMessagesToExtract = DeviceConfigHelper.getInteger(
                DeviceConfig.NotificationAssistant.MAX_MESSAGES_TO_EXTRACT,
                SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT,
                DEFAULT_MAX_MESSAGES_TO_EXTRACT);

        mMaxSuggestions = DeviceConfigHelper.getInteger(
                DeviceConfig.NotificationAssistant.MAX_SUGGESTIONS, DEFAULT_MAX_SUGGESTIONS);
                SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS, DEFAULT_MAX_SUGGESTIONS);

        mOnUpdateRunnable.run();
    }
@@ -193,8 +194,7 @@ final class AssistantSettings extends ContentObserver {

        private static String getValue(String key) {
            return DeviceConfig.getProperty(
                    DeviceConfig.NotificationAssistant.NAMESPACE,
                    key);
                    DeviceConfig.NAMESPACE_SYSTEMUI, key);
        }
    }

+51 −48
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.ext.services.notification;

import static android.ext.services.notification.AssistantSettings.DEFAULT_MAX_SUGGESTIONS;
import static android.provider.DeviceConfig.NotificationAssistant;
import static android.provider.DeviceConfig.setProperty;

import static junit.framework.Assert.assertFalse;
@@ -30,12 +29,15 @@ import static org.mockito.Mockito.verify;
import android.content.ContentResolver;
import android.os.Handler;
import android.os.Looper;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import android.testing.TestableContext;

import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -49,7 +51,7 @@ import java.io.IOException;
@RunWith(AndroidJUnit4.class)
public class AssistantSettingsTest {
    private static final String CLEAR_DEVICE_CONFIG_KEY_CMD =
            "device_config delete " + NotificationAssistant.NAMESPACE;
            "device_config delete " + DeviceConfig.NAMESPACE_SYSTEMUI;

    private static final int USER_ID = 5;

@@ -87,13 +89,13 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateRepliesDisabled() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "false");

        assertFalse(mAssistantSettings.mGenerateReplies);
@@ -102,13 +104,13 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateRepliesEnabled() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "true",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "true");

        assertTrue(mAssistantSettings.mGenerateReplies);
@@ -117,25 +119,25 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateRepliesEmptyFlag() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "false");

        assertFalse(mAssistantSettings.mGenerateReplies);

        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_REPLIES,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "");

        // Go back to the default value.
@@ -145,13 +147,13 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateActionsDisabled() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "false");

        assertFalse(mAssistantSettings.mGenerateActions);
@@ -160,13 +162,13 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateActionsEnabled() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "true",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "true");

        assertTrue(mAssistantSettings.mGenerateActions);
@@ -175,25 +177,25 @@ public class AssistantSettingsTest {
    @Test
    public void testGenerateActionsEmptyFlag() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "false",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "false");

        assertFalse(mAssistantSettings.mGenerateActions);

        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.GENERATE_ACTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "");

        // Go back to the default value.
@@ -203,13 +205,13 @@ public class AssistantSettingsTest {
    @Test
    public void testMaxMessagesToExtract() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.MAX_MESSAGES_TO_EXTRACT,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT,
                "10",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.MAX_MESSAGES_TO_EXTRACT,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT,
                "10");

        assertEquals(10, mAssistantSettings.mMaxMessagesToExtract);
@@ -218,13 +220,13 @@ public class AssistantSettingsTest {
    @Test
    public void testMaxSuggestions() {
        setProperty(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.MAX_SUGGESTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS,
                "5",
                false /* makeDefault */);
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.MAX_SUGGESTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS,
                "5");

        assertEquals(5, mAssistantSettings.mMaxSuggestions);
@@ -233,8 +235,8 @@ public class AssistantSettingsTest {
    @Test
    public void testMaxSuggestionsEmpty() {
        mAssistantSettings.onDeviceConfigPropertyChanged(
                NotificationAssistant.NAMESPACE,
                NotificationAssistant.MAX_SUGGESTIONS,
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS,
                "");

        assertEquals(DEFAULT_MAX_SUGGESTIONS, mAssistantSettings.mMaxSuggestions);
@@ -278,13 +280,14 @@ public class AssistantSettingsTest {
    private static void clearDeviceConfig() throws IOException {
        UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        uiDevice.executeShellCommand(
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + NotificationAssistant.GENERATE_ACTIONS);
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS);
        uiDevice.executeShellCommand(
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + NotificationAssistant.GENERATE_REPLIES);
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES);
        uiDevice.executeShellCommand(
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + NotificationAssistant.MAX_MESSAGES_TO_EXTRACT);
                CLEAR_DEVICE_CONFIG_KEY_CMD + " "
                + SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT);
        uiDevice.executeShellCommand(
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + NotificationAssistant.MAX_SUGGESTIONS);
                CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS);
    }

}