android权限 READ_DEVICE_CONFIG 与 WRITE_DEVICE_CONFIG
测试GTS的时候遇到GtsDeviceConfigTestCases failed 提示"android.permission.READ_DEVICE_CONFIG" 不能赋给未予置的应用 研究了下此权限 成果如下:
READ_DEVICE_CONFIG_PERMISSION
“android.permission.READ_DEVICE_CONFIG”
WRITE_DEVICE_CONFIG_PERMISSION
“android.permission.WRITE_DEVICE_CONFIG”
DeviceConfig API 使用
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.OnPropertiesChangedListener;
import android.provider.DeviceConfig.Properties;
DeviceConfig.setProperty(NAMESPACE1, KEY1, VALUE1, false);
String result = DeviceConfig.getProperty(NAMESPACE1, KEY1);
final String result = DeviceConfig.getString(NAMESPACE1, KEY1, DEFAULT_VALUE);
final boolean result = DeviceConfig.getBoolean(NAMESPACE1, KEY1, DEFAULT_BOOLEAN_TRUE);
final int result = DeviceConfig.getInt(NAMESPACE1, KEY1, DEFAULT_INT);
final float result = DeviceConfig.getFloat(NAMESPACE1, KEY1, DEFAULT_FLOAT);
final long result = DeviceConfig.getLong(NAMESPACE1, KEY1, DEFAULT_LONG);
private Properties setPropertiesAndAssertSuccessfulChange(String setNamespace, String setName,
String setValue) {
final List<PropertyUpdate> receivedUpdates = new ArrayList<>();
OnPropertiesChangedListener changeListener = createOnPropertiesChangedListener(receivedUpdates);
DeviceConfig.addOnPropertiesChangedListener(setNamespace, EXECUTOR, changeListener);
DeviceConfig.setProperty(setNamespace, setName, setValue, false);
waitForListenerUpdateOrTimeout(receivedUpdates, 1);
DeviceConfig.removeOnPropertiesChangedListener(changeListener);
assertEquals("Failed to receive update to OnPropertiesChangedListener",
receivedUpdates.size(), 1);
PropertyUpdate propertiesUpdate = receivedUpdates.get(0);
propertiesUpdate.assertEqual(setNamespace, setName, setValue);
return propertiesUpdate.properties;
}
private static class PropertyUpdate {
String namespace;
String name;
String value;
Properties properties;
PropertyUpdate(String namespace, String name, String value) {
this.name = name;
this.namespace = namespace;
this.value = value;
this.properties = null;
}
PropertyUpdate(Properties properties) {
if (properties.getKeyset().size() != 1) {
fail("Unexpected properties size.");
}
this.namespace = properties.getNamespace();
this.name = properties.getKeyset().iterator().next();
this.value = properties.getString(this.name, null);
this.properties = properties;
}
void assertEqual(String namespace, String name, String value) {
assertEquals("Listener received update for unexpected namespace",
namespace, this.namespace);
assertEquals("Listener received update for unexpected property",
this.name, name);
assertEquals("Listener received update with unexpected value",
this.value, value);
}
}
总结
可使用此权限获取系统属性
|