aboutsummaryrefslogtreecommitdiffstats
path: root/packages/LineageSettingsProvider/tests/src
diff options
context:
space:
mode:
authorSam Mortimer <sam@mortimer.me.uk>2017-09-18 19:42:34 -0700
committerSam Mortimer <sam@mortimer.me.uk>2017-09-22 17:19:40 -0700
commit5ede05bdca6e034d84ff77224e5ce8d6b8029ef6 (patch)
tree014521d2ee282f31f9513dec9c62d0c66466f036 /packages/LineageSettingsProvider/tests/src
parent088ddf5aafbb578ae5566bec3fab580d1372f76f (diff)
downloadlineage-sdk-5ede05bdca6e034d84ff77224e5ce8d6b8029ef6.tar.gz
lineage-sdk-5ede05bdca6e034d84ff77224e5ce8d6b8029ef6.tar.bz2
lineage-sdk-5ede05bdca6e034d84ff77224e5ce8d6b8029ef6.zip
lineage-sdk: rebrand step 1: update paths
Change-Id: I4c2135d03d730a313a0638d0f857afa48fb220d3
Diffstat (limited to 'packages/LineageSettingsProvider/tests/src')
-rw-r--r--packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsGlobalTests.java126
-rw-r--r--packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderDefaultsTest.java281
-rw-r--r--packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderTest.java325
-rw-r--r--packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSecureTests.java126
-rw-r--r--packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSystemTests.java126
5 files changed, 984 insertions, 0 deletions
diff --git a/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsGlobalTests.java b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsGlobalTests.java
new file mode 100644
index 00000000..28669257
--- /dev/null
+++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsGlobalTests.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod 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 org.cyanogenmod.cmsettings.tests;
+
+import android.content.ContentResolver;
+import android.net.Uri;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import cyanogenmod.providers.CMSettings;
+
+public class CMSettingsGlobalTests extends AndroidTestCase {
+ private ContentResolver mContentResolver;
+
+ private static final String UNREALISTIC_SETTING = "_______UNREAL_______";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContentResolver = mContext.getContentResolver();
+ }
+
+ @SmallTest
+ public void testFloat() {
+ final float expectedFloatValue = 1.0f;
+ CMSettings.Global.putFloat(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue);
+
+ try {
+ float actualValue = CMSettings.Global.getFloat(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedFloatValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testFloatWithDefault() {
+ final float expectedDefaultFloatValue = 1.5f;
+ float actualValue = CMSettings.Global.getFloat(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultFloatValue);
+ assertEquals(expectedDefaultFloatValue, actualValue);
+ }
+
+ @SmallTest
+ public void testInt() {
+ final int expectedIntValue = 2;
+ CMSettings.Global.putInt(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue);
+
+ try {
+ int actualValue = CMSettings.Global.getInt(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedIntValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testIntWithDefault() {
+ final int expectedDefaultIntValue = 11;
+ int actualValue = CMSettings.Global.getInt(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultIntValue);
+ assertEquals(expectedDefaultIntValue, actualValue);
+ }
+
+ @SmallTest
+ public void testLong() {
+ final long expectedLongValue = 3l;
+ CMSettings.Global.putLong(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue);
+
+ try {
+ long actualValue = CMSettings.Global.getLong(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedLongValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testLongWithDefault() {
+ final long expectedDefaultLongValue = 17l;
+ long actualValue = CMSettings.Global.getLong(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultLongValue);
+ assertEquals(expectedDefaultLongValue, actualValue);
+ }
+
+ @SmallTest
+ public void testString() {
+ final String expectedStringValue = "4";
+ CMSettings.Global.putString(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue);
+
+ String actualValue = CMSettings.Global.getString(mContentResolver,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedStringValue, actualValue);
+ }
+
+ @SmallTest
+ public void testGetUri() {
+ final Uri expectedUri = Uri.withAppendedPath(CMSettings.Global.CONTENT_URI,
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+
+ final Uri actualUri = CMSettings.Global.getUriFor(
+ CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
+
+ assertEquals(expectedUri, actualUri);
+ }
+}
diff --git a/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderDefaultsTest.java b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderDefaultsTest.java
new file mode 100644
index 00000000..2ea0bf8e
--- /dev/null
+++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderDefaultsTest.java
@@ -0,0 +1,281 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod 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 org.cyanogenmod.cmsettings.tests;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.os.UserHandle;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.util.ArrayList;
+
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.TypedValue;
+import cyanogenmod.providers.CMSettings;
+import org.cyanogenmod.cmsettings.CMDatabaseHelper;
+import org.cyanogenmod.cmsettings.CMSettingsProvider;
+import org.cyanogenmod.cmsettings.R;
+
+/**
+ * Created by adnan on 1/25/16.
+ */
+public class CMSettingsProviderDefaultsTest extends AndroidTestCase {
+ private ContentResolver mContentResolver;
+ private boolean mHasMigratedSettings;
+ private Resources mRemoteResources;
+
+ // These data structures are set up in a way that is easier for manual input of new defaults
+ private static ArrayList<Setting> SYSTEM_SETTINGS_DEFAULTS = new ArrayList<Setting>();
+ private static ArrayList<Setting> SECURE_SETTINGS_DEFAULTS = new ArrayList<Setting>();
+ private static ArrayList<Setting> GLOBAL_SETTINGS_DEFAULTS = new ArrayList<Setting>();
+
+ //SYSTEM
+ static {
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.STATUS_BAR_QUICK_QS_PULLDOWN,
+ "R.integer.def_qs_quick_pulldown"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
+ "R.integer.def_notification_brightness_level"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.ENABLE_FORWARD_LOOKUP,
+ "R.integer.def_forward_lookup"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.ENABLE_PEOPLE_LOOKUP,
+ "R.integer.def_people_lookup"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.ENABLE_REVERSE_LOOKUP,
+ "R.integer.def_reverse_lookup"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.NOTIFICATION_LIGHT_MULTIPLE_LEDS_ENABLE,
+ "R.bool.def_notification_multiple_leds"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.SYSTEM_PROFILES_ENABLED,
+ "R.bool.def_profiles_enabled"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE,
+ "R.bool.def_notification_pulse_custom_enable"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION,
+ "R.bool.def_swap_volume_keys_on_rotation"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_VALUES,
+ "R.string.def_notification_pulse_custom_value"));
+ SYSTEM_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.System.STATUS_BAR_BATTERY_STYLE,
+ "R.integer.def_battery_style"));
+ }
+
+ //SECURE
+ static {
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.ADVANCED_MODE,
+ "R.bool.def_advanced_mode"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.QS_USE_MAIN_TILES,
+ "R.bool.def_sysui_qs_main_tiles"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.STATS_COLLECTION,
+ "R.bool.def_stats_collection"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.LOCKSCREEN_VISUALIZER_ENABLED,
+ "R.bool.def_lockscreen_visualizer"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.DEFAULT_THEME_COMPONENTS,
+ "R.string.def_theme_components"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.DEFAULT_THEME_PACKAGE,
+ "R.string.def_theme_package"));
+ SECURE_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Secure.PROTECTED_COMPONENT_MANAGERS,
+ "R.string.def_protected_component_managers"));
+ }
+
+ //GLOBAL
+ static {
+ GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Global.POWER_NOTIFICATIONS_ENABLED,
+ "R.bool.def_power_notifications_enabled"));
+ GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Global.POWER_NOTIFICATIONS_VIBRATE,
+ "R.bool.def_power_notifications_vibrate"));
+ GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE,
+ "R.string.def_power_notifications_ringtone"));
+ GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Global.WEATHER_TEMPERATURE_UNIT,
+ "R.integer.def_temperature_unit"));
+ GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
+ CMSettings.Global.DEV_FORCE_SHOW_NAVBAR,
+ "R.integer.def_force_show_navbar"));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContentResolver = getContext().getContentResolver();
+ mHasMigratedSettings = getContext().getSharedPreferences(CMSettingsProvider.TAG,
+ Context.MODE_PRIVATE).getBoolean(CMSettingsProvider.PREF_HAS_MIGRATED_CM_SETTINGS,
+ false);
+ mRemoteResources = getRemoteResources("org.cyanogenmod.cmsettings");
+ }
+
+ @SmallTest
+ public void testVerifySystemSettingsDefault() {
+ if (verifyNotMigratedSettings()) {
+ for (Setting setting : SYSTEM_SETTINGS_DEFAULTS) {
+ verifyDefaultSettingForTable(setting, CMDatabaseHelper.CMTableNames.TABLE_SYSTEM);
+ }
+ }
+ }
+
+ @SmallTest
+ public void testVerifySecureSettingsDefaults() {
+ if (verifyNotMigratedSettings()) {
+ for (Setting setting : SECURE_SETTINGS_DEFAULTS) {
+ verifyDefaultSettingForTable(setting, CMDatabaseHelper.CMTableNames.TABLE_SECURE);
+ }
+ }
+ }
+
+ @SmallTest
+ public void testVerifyGlobalSettingsDefaults() {
+ if (verifyNotMigratedSettings()) {
+ for (Setting setting : GLOBAL_SETTINGS_DEFAULTS) {
+ verifyDefaultSettingForTable(setting, CMDatabaseHelper.CMTableNames.TABLE_GLOBAL);
+ }
+ }
+ }
+
+ private boolean verifyNotMigratedSettings() {
+ return !mHasMigratedSettings;
+ }
+
+ private void verifyDefaultSettingForTable(Setting setting, String table) {
+ TypedValue value = new TypedValue();
+ try {
+ int identifier = mRemoteResources.getIdentifier(
+ setting.mDefResName, setting.mType, "org.cyanogenmod.cmsettings");
+ mRemoteResources.getValue(identifier, value, true);
+ } catch (Resources.NotFoundException e) {
+ // Resource not found, can't verify because it probably wasn't loaded in
+ throw new AssertionError("Unable to find resource for " + setting.mKey);
+ }
+
+ try {
+ switch (value.type) {
+ case TypedValue.TYPE_INT_DEC:
+ int actualValue = getIntForTable(setting, table);
+ try {
+ assertEquals(value.data, actualValue);
+ } catch (AssertionError e) {
+ throw new AssertionError("Compared value of " + setting.mKey + " expected "
+ + value.data + " got " + actualValue);
+ }
+ break;
+ case TypedValue.TYPE_INT_BOOLEAN:
+ int actualBooleanValue = getIntForTable(setting, table);
+ try {
+ //This is gross
+ //Boolean can be "true" as long as it isn't 0
+ if (value.data != 0) {
+ value.data = 1;
+ }
+ assertEquals(value.data, actualBooleanValue);
+ } catch (AssertionError e) {
+ throw new AssertionError("Compared value of " + setting.mKey + " expected "
+ + value.data + " got " + actualBooleanValue);
+ }
+ break;
+ case TypedValue.TYPE_STRING:
+ if (!TextUtils.isEmpty(value.string)) {
+ //This should really be done as a parameterized test
+ String actualStringValue = getStringForTable(setting, table);
+ try {
+ assertEquals(value.string, actualStringValue);
+ } catch (AssertionError e) {
+ throw new AssertionError("Compared value of " + setting.mKey
+ + " expected " + value.string + " got " + actualStringValue);
+ }
+ }
+ break;
+ case TypedValue.TYPE_NULL:
+ break;
+ }
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ e.printStackTrace();
+ throw new AssertionError("Setting " + setting.mKey + " not found!");
+ }
+ }
+
+ private int getIntForTable(Setting setting, String table)
+ throws CMSettings.CMSettingNotFoundException {
+ switch (table) {
+ case CMDatabaseHelper.CMTableNames.TABLE_SYSTEM:
+ return CMSettings.System.getIntForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ case CMDatabaseHelper.CMTableNames.TABLE_SECURE:
+ return CMSettings.Secure.getIntForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ case CMDatabaseHelper.CMTableNames.TABLE_GLOBAL:
+ return CMSettings.Global.getIntForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ default:
+ throw new AssertionError("Invalid or empty table!");
+ }
+ }
+
+ private String getStringForTable(Setting setting, String table)
+ throws CMSettings.CMSettingNotFoundException {
+ switch (table) {
+ case CMDatabaseHelper.CMTableNames.TABLE_SYSTEM:
+ return CMSettings.System.getStringForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ case CMDatabaseHelper.CMTableNames.TABLE_SECURE:
+ return CMSettings.Secure.getStringForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ case CMDatabaseHelper.CMTableNames.TABLE_GLOBAL:
+ return CMSettings.Global.getStringForUser(mContentResolver, setting.mKey,
+ UserHandle.USER_OWNER);
+ default:
+ throw new AssertionError("Invalid or empty table!");
+ }
+ }
+
+ private static class Setting {
+ public String mKey;
+ public String mDefResName;
+ public String mType;
+
+ public Setting(String key, String defResId) {
+ mKey = key;
+ String[] parts = defResId.split("\\.");
+ mType = parts[1];
+ mDefResName = parts[2];
+ }
+ }
+
+ private Resources getRemoteResources(String packageName)
+ throws PackageManager.NameNotFoundException {
+ PackageManager packageManager = mContext.getPackageManager();
+ return packageManager.getResourcesForApplication(packageName);
+ }
+}
diff --git a/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderTest.java b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderTest.java
new file mode 100644
index 00000000..c4db088a
--- /dev/null
+++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderTest.java
@@ -0,0 +1,325 @@
+ /**
+ * Copyright (c) 2015, The CyanogenMod 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 org.cyanogenmod.cmsettings.tests;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.IContentProvider;
+import android.content.pm.UserInfo;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.UserHandle;
+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;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+ public class CMSettingsProviderTest extends AndroidTestCase {
+ private static final String TAG = "CMSettingsProviderTest";
+
+ private static final LinkedHashMap<String, String> sMap = new LinkedHashMap<String, String>();
+
+ static {
+ sMap.put("testKey1", "value1");
+ sMap.put("testKey2", "value2");
+ sMap.put("testKey3", "value3");
+ }
+
+ private static final String[] PROJECTIONS = new String[] { Settings.NameValueTable.NAME,
+ Settings.NameValueTable.VALUE };
+
+ private ContentResolver mContentResolver;
+ private UserManager mUserManager;
+ private UserInfo mGuest;
+
+ @Override
+ public void setUp() {
+ mContentResolver = mContext.getContentResolver();
+ mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ }
+
+ @Override
+ public void tearDown() {
+ if (mGuest != null) {
+ mUserManager.removeUser(mGuest.id);
+ }
+ }
+
+ @MediumTest
+ public void testMigrateCMSettingsForOtherUser() {
+ // Make sure there's an owner
+ assertTrue(findUser(mUserManager, UserHandle.USER_OWNER));
+
+ mGuest = mUserManager.createGuest(mContext, "GuestUser1");
+ assertNotNull(mGuest);
+
+ 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);
+ }
+
+ /**
+ * The new {@link CMSettings.Secure#CM_SETUP_WIZARD_COMPLETED} cm specific provisioned flag
+ * should be equal to the old {@link Settings.Global#DEVICE_PROVISIONED} flag on boot, or on
+ * upgrade. These flags will almost always be equal, except during the provisioning process,
+ * they may change at slightly different times.
+ *
+ * Test whether the setting was properly set and is not null.
+ *
+ * @deprecated Replaced by {@link Settings.Global#DEVICE_PROVISIONED}
+ * or {@link Settings.Secure#USER_SETUP_COMPLETE}
+ */
+ @Deprecated
+ @SmallTest
+ public void testCMProvisionedFlagFallbackSet() {
+ final String newCmFlag = CMSettings.Secure.getStringForUser(
+ getContext().getContentResolver(), CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED,
+ UserHandle.USER_OWNER);
+ assertNotNull(newCmFlag);
+
+ final String previousFlag = Settings.Global.getStringForUser(
+ getContext().getContentResolver(), Settings.Global.DEVICE_PROVISIONED,
+ UserHandle.USER_OWNER);
+ assertEquals(previousFlag, newCmFlag);
+ }
+
+ private void testMigrateSettingsForUser(int userId) {
+ // Setup values in Settings
+ /*final String expectedPullDownValue = "testQuickPullDownValue";
+ Settings.System.putStringForUser(mContentResolver,
+ CMSettingsProvider.LegacyCMSettings.STATUS_BAR_QUICK_QS_PULLDOWN,
+ expectedPullDownValue, userId);
+
+ final int expectedKeyboardBrightness = 4;
+ Settings.Secure.putIntForUser(mContentResolver,
+ CMSettingsProvider.LegacyCMSettings.KEYBOARD_BRIGHTNESS,
+ expectedKeyboardBrightness, userId);
+
+ Bundle arg = new Bundle();
+ arg.putInt(CMSettings.CALL_METHOD_USER_KEY, userId);
+ IContentProvider contentProvider = mContentResolver.acquireProvider(
+ CMSettings.AUTHORITY);
+
+ try{
+ // Trigger migrate settings for guest
+ contentProvider.call(mContentResolver.getPackageName(),
+ CMSettings.CALL_METHOD_MIGRATE_SETTINGS_FOR_USER, null, arg);
+ } catch (RemoteException ex) {
+ fail("Failed to trigger settings migration due to RemoteException");
+ }
+
+ // Check values
+ final String actualPullDownValue = CMSettings.System.getStringForUser(mContentResolver,
+ CMSettings.System.QS_QUICK_PULLDOWN, userId);
+ assertEquals(expectedPullDownValue, actualPullDownValue);
+
+ final int actualKeyboardBrightness = CMSettings.Secure.getIntForUser(mContentResolver,
+ CMSettings.Secure.KEYBOARD_BRIGHTNESS, -1, userId);
+ assertEquals(expectedKeyboardBrightness, actualKeyboardBrightness);*/
+ }
+
+ private boolean findUser(UserManager userManager, int userHandle) {
+ for (UserInfo user : userManager.getUsers()) {
+ if (user.id == userHandle) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @MediumTest
+ public void testBulkInsertSuccess() {
+ ContentValues[] contentValues = new ContentValues[sMap.size()];
+ String[] keyValues = new String[sMap.size()];
+ int count = 0;
+ for (Map.Entry<String, String> kVPair : sMap.entrySet()) {
+ ContentValues contentValue = new ContentValues();
+
+ final String key = kVPair.getKey();
+ contentValue.put(Settings.NameValueTable.NAME, key);
+ keyValues[count] = key;
+
+ contentValue.put(Settings.NameValueTable.VALUE, kVPair.getValue());
+ contentValues[count++] = contentValue;
+ }
+
+ testBulkInsertForUri(CMSettings.System.CONTENT_URI, contentValues, keyValues);
+ testBulkInsertForUri(CMSettings.Secure.CONTENT_URI, contentValues, keyValues);
+ testBulkInsertForUri(CMSettings.Global.CONTENT_URI, contentValues, keyValues);
+ }
+
+ private void testBulkInsertForUri(Uri uri, ContentValues[] contentValues, String[] keyValues) {
+ int rowsInserted = mContentResolver.bulkInsert(uri, contentValues);
+ assertEquals(sMap.size(), rowsInserted);
+
+ final String placeholderSymbol = "?";
+ String[] placeholders = new String[contentValues.length];
+ for (int i = 0; i < placeholders.length; i++) {
+ placeholders[i] = placeholderSymbol;
+ }
+
+ final String placeholdersString = TextUtils.join(",", placeholders);
+
+ Cursor queryCursor = mContentResolver.query(uri, PROJECTIONS,
+ Settings.NameValueTable.NAME + " IN (" + placeholdersString + ")", keyValues,
+ null);
+ assertEquals(contentValues.length, queryCursor.getCount());
+ try {
+ while (queryCursor.moveToNext()) {
+ assertEquals(PROJECTIONS.length, queryCursor.getColumnCount());
+
+ String actualKey = queryCursor.getString(0);
+ assertTrue(sMap.containsKey(actualKey));
+
+ assertEquals(sMap.get(actualKey), queryCursor.getString(1));
+ }
+ }
+ finally {
+ queryCursor.close();
+ }
+
+ // TODO: Find a better way to cleanup database/use ProviderTestCase2 without process crash
+ for (String key : sMap.keySet()) {
+ mContentResolver.delete(uri, Settings.NameValueTable.NAME + " = ?",
+ new String[]{ key });
+ }
+ }
+
+ @MediumTest
+ public void testInsertUpdateDeleteSuccess() {
+ //testInsertUpdateDeleteForUri(CMSettings.System.CONTENT_URI);
+ testInsertUpdateDeleteForUri(CMSettings.Secure.CONTENT_URI);
+ testInsertUpdateDeleteForUri(CMSettings.Global.CONTENT_URI);
+ }
+
+ private void testInsertUpdateDeleteForUri(Uri uri) {
+ String key = "key";
+ String value1 = "value1";
+ String value2 = "value2";
+
+ // test insert
+ ContentValues contentValue = new ContentValues();
+ contentValue.put(Settings.NameValueTable.NAME, key);
+ contentValue.put(Settings.NameValueTable.VALUE, value1);
+
+ Uri expectedUri = uri.withAppendedPath(uri, key);
+ Uri returnUri = mContentResolver.insert(uri, contentValue);
+ assertEquals(expectedUri, returnUri);
+
+ Cursor queryCursor = null;
+ try {
+ // check insert
+ queryCursor = mContentResolver.query(uri, PROJECTIONS, Settings.NameValueTable.NAME +
+ " = ?", new String[]{ key }, null);
+ assertEquals(1, queryCursor.getCount());
+
+ assertExpectedKeyValuePair(queryCursor, key, value1);
+
+ // check insert with returned uri
+ queryCursor = mContentResolver.query(returnUri, PROJECTIONS, null, null, null);
+ assertEquals(1, queryCursor.getCount());
+
+ assertExpectedKeyValuePair(queryCursor, key, value1);
+
+ // test update
+ contentValue.clear();
+ contentValue.put(Settings.NameValueTable.VALUE, value2);
+
+ int rowsAffected = mContentResolver.update(uri, contentValue,
+ Settings.NameValueTable.NAME + " = ?", new String[]{ key });
+ assertEquals(1, rowsAffected);
+
+ // check update
+ queryCursor = mContentResolver.query(uri, PROJECTIONS, Settings.NameValueTable.NAME +
+ " = ?", new String[]{ key }, null);
+ assertEquals(1, queryCursor.getCount());
+
+ assertExpectedKeyValuePair(queryCursor, key, value2);
+
+ // test delete
+ rowsAffected = mContentResolver.delete(uri, Settings.NameValueTable.NAME + " = ?",
+ new String[]{ key });
+ assertEquals(1, rowsAffected);
+
+ // check delete
+ queryCursor = mContentResolver.query(uri, PROJECTIONS, Settings.NameValueTable.NAME +
+ " = ?", new String[]{ key }, null);
+ assertEquals(0, queryCursor.getCount());
+ } finally {
+ if (queryCursor != null) {
+ queryCursor.close();
+ }
+ }
+ }
+
+ private void assertExpectedKeyValuePair(Cursor cursor, String expectedKey,
+ String expectedValue) {
+ cursor.moveToNext();
+ assertEquals(PROJECTIONS.length, cursor.getColumnCount());
+
+ String actualKey = cursor.getString(0);
+ assertEquals(expectedKey, actualKey);
+ assertEquals(expectedValue, cursor.getString(1));
+ }
+ }
diff --git a/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSecureTests.java b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSecureTests.java
new file mode 100644
index 00000000..434b95df
--- /dev/null
+++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSecureTests.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod 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 org.cyanogenmod.cmsettings.tests;
+
+import android.content.ContentResolver;
+import android.net.Uri;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import cyanogenmod.providers.CMSettings;
+
+public class CMSettingsSecureTests extends AndroidTestCase {
+ private ContentResolver mContentResolver;
+
+ private static final String UNREALISTIC_SETTING = "_______UNREAL_______";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContentResolver = mContext.getContentResolver();
+ }
+
+ @SmallTest
+ public void testFloat() {
+ final float expectedFloatValue = 1.0f;
+ CMSettings.Secure.putFloat(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue);
+
+ try {
+ float actualValue = CMSettings.Secure.getFloat(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedFloatValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testFloatWithDefault() {
+ final float expectedDefaultFloatValue = 1.5f;
+ float actualValue = CMSettings.Secure.getFloat(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultFloatValue);
+ assertEquals(expectedDefaultFloatValue, actualValue);
+ }
+
+ @SmallTest
+ public void testInt() {
+ final int expectedIntValue = 2;
+ CMSettings.Secure.putInt(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue);
+
+ try {
+ int actualValue = CMSettings.Secure.getInt(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedIntValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testIntWithDefault() {
+ final int expectedDefaultIntValue = 11;
+ int actualValue = CMSettings.Secure.getInt(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultIntValue);
+ assertEquals(expectedDefaultIntValue, actualValue);
+ }
+
+ @SmallTest
+ public void testLong() {
+ final long expectedLongValue = 3l;
+ CMSettings.Secure.putLong(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue);
+
+ try {
+ long actualValue = CMSettings.Secure.getLong(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedLongValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testLongWithDefault() {
+ final long expectedDefaultLongValue = 17l;
+ long actualValue = CMSettings.Secure.getLong(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultLongValue);
+ assertEquals(expectedDefaultLongValue, actualValue);
+ }
+
+ @SmallTest
+ public void testString() {
+ final String expectedStringValue = "4";
+ CMSettings.Secure.putString(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue);
+
+ String actualValue = CMSettings.Secure.getString(mContentResolver,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedStringValue, actualValue);
+ }
+
+ @SmallTest
+ public void testGetUri() {
+ final Uri expectedUri = Uri.withAppendedPath(CMSettings.Secure.CONTENT_URI,
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+
+ final Uri actualUri = CMSettings.Secure.getUriFor(
+ CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER);
+
+ assertEquals(expectedUri, actualUri);
+ }
+}
diff --git a/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSystemTests.java b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSystemTests.java
new file mode 100644
index 00000000..da968bd7
--- /dev/null
+++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsSystemTests.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod 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 org.cyanogenmod.cmsettings.tests;
+
+import android.content.ContentResolver;
+import android.net.Uri;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import cyanogenmod.providers.CMSettings;
+
+public class CMSettingsSystemTests extends AndroidTestCase {
+ private ContentResolver mContentResolver;
+
+ private static final String UNREALISTIC_SETTING = "_______UNREAL_______";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContentResolver = mContext.getContentResolver();
+ }
+
+ @SmallTest
+ public void testFloat() {
+ final float expectedFloatValue = 1.0f;
+ CMSettings.System.putFloat(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue);
+
+ try {
+ float actualValue = CMSettings.System.getFloat(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedFloatValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testFloatWithDefault() {
+ final float expectedDefaultFloatValue = 1.5f;
+ float actualValue = CMSettings.System.getFloat(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultFloatValue);
+ assertEquals(expectedDefaultFloatValue, actualValue);
+ }
+
+ @SmallTest
+ public void testInt() {
+ final int expectedIntValue = 2;
+ CMSettings.System.putInt(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue);
+
+ try {
+ int actualValue = CMSettings.System.getInt(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedIntValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testIntWithDefault() {
+ final int expectedDefaultIntValue = 11;
+ int actualValue = CMSettings.System.getInt(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultIntValue);
+ assertEquals(expectedDefaultIntValue, actualValue);
+ }
+
+ @SmallTest
+ public void testLong() {
+ final long expectedLongValue = 3l;
+ CMSettings.System.putLong(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue);
+
+ try {
+ long actualValue = CMSettings.System.getLong(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedLongValue, actualValue);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @SmallTest
+ public void testLongWithDefault() {
+ final long expectedDefaultLongValue = 17l;
+ long actualValue = CMSettings.System.getLong(mContentResolver,
+ UNREALISTIC_SETTING, expectedDefaultLongValue);
+ assertEquals(expectedDefaultLongValue, actualValue);
+ }
+
+ @SmallTest
+ public void testString() {
+ final String expectedStringValue = "4";
+ CMSettings.System.putString(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue);
+
+ String actualValue = CMSettings.System.getString(mContentResolver,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+ assertEquals(expectedStringValue, actualValue);
+ }
+
+ @SmallTest
+ public void testGetUri() {
+ final Uri expectedUri = Uri.withAppendedPath(CMSettings.System.CONTENT_URI,
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+
+ final Uri actualUri = CMSettings.System.getUriFor(
+ CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER);
+
+ assertEquals(expectedUri, actualUri);
+ }
+}