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

Test: atest AssistantSettingsTest
Change-Id: Ia147b184838af0294653947072147f30eb5aece1
This commit is contained in:
Stanislav Zholnin
2019-03-07 16:09:20 +00:00
parent 94904dcb12
commit 3353c1161f
2 changed files with 10 additions and 39 deletions

View File

@@ -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);

View File

@@ -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);