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

Commit 8c50dc11 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use updated DeviceConfig API's new getters to simplify invocations."

parents d7a8ca26 3353c116
Loading
Loading
Loading
Loading
+4 −33
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.net.Uri;
import android.os.Handler;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -128,17 +127,17 @@ final class AssistantSettings extends ContentObserver {
    }

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

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

        mMaxMessagesToExtract = DeviceConfigHelper.getInteger(
        mMaxMessagesToExtract = DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT,
                DEFAULT_MAX_MESSAGES_TO_EXTRACT);

        mMaxSuggestions = DeviceConfigHelper.getInteger(
        mMaxSuggestions = DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS, DEFAULT_MAX_SUGGESTIONS);

        mOnUpdateRunnable.run();
@@ -170,34 +169,6 @@ final class AssistantSettings extends ContentObserver {
        mOnUpdateRunnable.run();
    }

    static class DeviceConfigHelper {

        static int getInteger(String key, int defaultValue) {
            String value = getValue(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException ex) {
                return defaultValue;
            }
        }

        static boolean getBoolean(String key, boolean defaultValue) {
            String value = getValue(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return Boolean.parseBoolean(value);
        }

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

    public interface Factory {
        AssistantSettings createAndRegister(Handler handler, ContentResolver resolver, int userId,
                Runnable onUpdateRunnable);
+6 −6
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class AssistantSettingsTest {
    }

    @Test
    public void testGenerateRepliesEmptyFlag() {
    public void testGenerateRepliesNullFlag() {
        runWithShellPermissionIdentity(() -> setProperty(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
@@ -136,12 +136,12 @@ public class AssistantSettingsTest {
        runWithShellPermissionIdentity(() -> setProperty(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "",
                null,
                false /* makeDefault */));
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES,
                "");
                null);

        // Go back to the default value.
        assertTrue(mAssistantSettings.mGenerateReplies);
@@ -178,7 +178,7 @@ public class AssistantSettingsTest {
    }

    @Test
    public void testGenerateActionsEmptyFlag() {
    public void testGenerateActionsNullFlag() {
        runWithShellPermissionIdentity(() -> setProperty(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
@@ -194,12 +194,12 @@ public class AssistantSettingsTest {
        runWithShellPermissionIdentity(() -> setProperty(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "",
                null,
                false /* makeDefault */));
        mAssistantSettings.onDeviceConfigPropertyChanged(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS,
                "");
                null);

        // Go back to the default value.
        assertTrue(mAssistantSettings.mGenerateActions);