cmsdk: add keys which to intercept from SettingsProvider

Change-Id: Id5d86cc97eb2411322af5686e6d79fa5fb190891
Signed-off-by: Roman Birg <roman@cyngn.com>
This commit is contained in:
Roman Birg 2015-12-18 12:01:07 -08:00
parent cb4a990216
commit 20bfdd7e3f
2 changed files with 61 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import android.os.UserManager;
import android.provider.Settings;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
import cyanogenmod.providers.CMSettings;
import org.cyanogenmod.cmsettings.CMSettingsProvider;
@ -79,6 +80,45 @@ import java.util.Map;
testMigrateSettingsForUser(mGuest.id);
}
/**
* make sure that queries to SettingsProvider are forwarded to CMSettingsProvider as needed
* See {@link cyanogenmod.providers.CMSettings.System#shouldInterceptSystemProvider(String)}
*
* Currently this test only checks that
* {@link cyanogenmod.providers.CMSettings.System#SYSTEM_PROFILES_ENABLED} is expected to
* be forwarded, and is forwarded.
*/
@SmallTest
public void testSettingsProviderKeyForwarding() {
String forwardedKey = CMSettings.System.SYSTEM_PROFILES_ENABLED;
// make sure the key should be forwarded
assertTrue(CMSettings.System.shouldInterceptSystemProvider(forwardedKey));
// put value 1 into Settings provider:
// let's try to disable the profiles via the Settings provider
Settings.System.putStringForUser(mContentResolver,
forwardedKey, "0", UserHandle.USER_CURRENT);
// assert this is what we just put in there
assertEquals("0", Settings.System.getStringForUser(getContext().getContentResolver(),
forwardedKey, UserHandle.USER_CURRENT));
// put value 2 into CMSettings provider
CMSettings.System.putStringForUser(mContentResolver,
forwardedKey, "1", UserHandle.USER_CURRENT);
assertEquals("1", CMSettings.System.getStringForUser(getContext().getContentResolver(),
forwardedKey, UserHandle.USER_CURRENT));
// assert reading from both returns value 2
final String cmProviderValue = CMSettings.System.getStringForUser(
getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT);
final String settingsProviderValue = Settings.System.getStringForUser(
getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT);
assertEquals(cmProviderValue, settingsProviderValue);
}
private void testMigrateSettingsForUser(int userId) {
// Setup values in Settings
/*final String expectedPullDownValue = "testQuickPullDownValue";

View File

@ -1880,6 +1880,13 @@ public final class CMSettings {
return ArrayUtils.contains(LEGACY_SYSTEM_SETTINGS, key);
}
/**
* @hide
*/
public static boolean shouldInterceptSystemProvider(String key) {
return key.equals(System.SYSTEM_PROFILES_ENABLED);
}
/**
* Mapping of validators for all system settings. This map is used to validate both valid
* keys as well as validating the values for those keys.
@ -2699,6 +2706,13 @@ public final class CMSettings {
static {
VALIDATORS.put(PROTECTED_COMPONENTS, PROTECTED_COMPONENTS_VALIDATOR);
}
/**
* @hide
*/
public static boolean shouldInterceptSystemProvider(String key) {
return false;
}
}
/**
@ -3123,5 +3137,12 @@ public final class CMSettings {
public static boolean isLegacySetting(String key) {
return ArrayUtils.contains(LEGACY_GLOBAL_SETTINGS, key);
}
/**
* @hide
*/
public static boolean shouldInterceptSystemProvider(String key) {
return false;
}
}
}