diff options
author | Michael W <baddaemon87@gmail.com> | 2019-01-06 19:36:00 +0100 |
---|---|---|
committer | Michael W <baddaemon87@gmail.com> | 2019-01-06 19:36:06 +0100 |
commit | 034c3c79dc788173929492f98ae36d1c78269c9c (patch) | |
tree | c0d8728b28efce880a2193da0bffdb1bcf286fdd /packages/LineageSettingsProvider | |
parent | 915e52eda2602558843fa5355861e79e993c65d9 (diff) | |
download | lineage-sdk-034c3c79dc788173929492f98ae36d1c78269c9c.tar.gz lineage-sdk-034c3c79dc788173929492f98ae36d1c78269c9c.tar.bz2 lineage-sdk-034c3c79dc788173929492f98ae36d1c78269c9c.zip |
Revert "Automatic translation import"
This reverts commit 5f06011a755307465238b04a6ce933472a7d9321.
Change-Id: I1b951cb63fd0b6628d87243a068ab4c083075f5a
Diffstat (limited to 'packages/LineageSettingsProvider')
12 files changed, 1125 insertions, 9 deletions
diff --git a/packages/LineageSettingsProvider/res/values-ar/strings.xml b/packages/LineageSettingsProvider/res/values-ar/strings.xml index 233a8314..0647eaf6 100644 --- a/packages/LineageSettingsProvider/res/values-ar/strings.xml +++ b/packages/LineageSettingsProvider/res/values-ar/strings.xml @@ -15,6 +15,4 @@ See the License for the specific language governing permissions and limitations under the License. --> -<resources> - <string name="app_name">اعدادت تخزين Lineage</string> -</resources> +<resources></resources> diff --git a/packages/LineageSettingsProvider/res/values-cy/strings.xml b/packages/LineageSettingsProvider/res/values-cy/strings.xml index ef925ae2..0647eaf6 100644 --- a/packages/LineageSettingsProvider/res/values-cy/strings.xml +++ b/packages/LineageSettingsProvider/res/values-cy/strings.xml @@ -15,6 +15,4 @@ See the License for the specific language governing permissions and limitations under the License. --> -<resources> - <string name="app_name">Storfa Gosodiadau Lineage</string> -</resources> +<resources></resources> diff --git a/packages/LineageSettingsProvider/res/values-sc-rIT/strings.xml b/packages/LineageSettingsProvider/res/values-sc-rIT/strings.xml index 4b7acd94..0647eaf6 100644 --- a/packages/LineageSettingsProvider/res/values-sc-rIT/strings.xml +++ b/packages/LineageSettingsProvider/res/values-sc-rIT/strings.xml @@ -15,6 +15,4 @@ See the License for the specific language governing permissions and limitations under the License. --> -<resources> - <string name="app_name">Archìviu de impostatziones de Lineage</string> -</resources> +<resources></resources> diff --git a/packages/LineageSettingsProvider/tests/Android.mk b/packages/LineageSettingsProvider/tests/Android.mk new file mode 100644 index 00000000..31c3aa38 --- /dev/null +++ b/packages/LineageSettingsProvider/tests/Android.mk @@ -0,0 +1,56 @@ +# +# 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. +# +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_PACKAGE_NAME := LineageSettingsProviderTests +LOCAL_INSTRUMENTATION_FOR := LineageSettingsProvider + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_CERTIFICATE := platform +LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_PROGUARD_ENABLED := optimization shrinktests +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +LOCAL_STATIC_JAVA_LIBRARIES := \ + org.lineageos.platform.internal + +include $(BUILD_PACKAGE) + +# Register as LineageTS +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_PACKAGE_NAME := CmtsLineageSettingsProviderTests +LOCAL_INSTRUMENTATION_FOR := LineageSettingsProvider + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_CERTIFICATE := platform +LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_PROGUARD_ENABLED := optimization shrinktests +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +LOCAL_STATIC_JAVA_LIBRARIES := \ + org.lineageos.platform.internal + +include $(BUILD_LineageTS_PACKAGE) + diff --git a/packages/LineageSettingsProvider/tests/AndroidManifest.xml b/packages/LineageSettingsProvider/tests/AndroidManifest.xml new file mode 100644 index 00000000..ec333a69 --- /dev/null +++ b/packages/LineageSettingsProvider/tests/AndroidManifest.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.lineageos.lineagesettings.tests"> + + <uses-permission android:name="lineageos.permission.WRITE_SETTINGS"/> + <uses-permission android:name="lineageos.permission.WRITE_SECURE_SETTINGS"/> + <uses-permission android:name="android.permission.WRITE_SETTINGS"/> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> + <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> + <uses-permission android:name="android.permission.MANAGE_USERS" /> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="org.lineageos.lineagesettings.tests" + android:label="Lineage Settings Provider Tests" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> +</manifest> diff --git a/packages/LineageSettingsProvider/tests/README.md b/packages/LineageSettingsProvider/tests/README.md new file mode 100644 index 00000000..5b91285e --- /dev/null +++ b/packages/LineageSettingsProvider/tests/README.md @@ -0,0 +1,7 @@ +## Lineage Settings Provider Tests +The tests package contains coverage for the Lineage Settings provider as well as +its public interfaces. + +To run the tests (on a live device): + + ```adb shell am instrument -w org.lineageos.lineagesettings.tests/android.test.InstrumentationTestRunner``` diff --git a/packages/LineageSettingsProvider/tests/proguard.flags b/packages/LineageSettingsProvider/tests/proguard.flags new file mode 100644 index 00000000..d9e855cb --- /dev/null +++ b/packages/LineageSettingsProvider/tests/proguard.flags @@ -0,0 +1,50 @@ +# 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. + +# Don't skip non public library classes, make sure we're not keeping anything which will get mapped against api verification. +-dontskipnonpubliclibraryclasses + +# Do the same with class members +-dontskipnonpubliclibraryclassmembers + +# Keep test packages +-keep class android.support.** { *; } +-keep class android.test.** { *; } +-keep public class * extends android.support.** { *; } +-keep public class * extends android.test.** { *; } +-keep interface android.support.** { *; } +-keep interface android.test.** { *; } + +# Keep all junit classes +-keep class junit.** { *; } +-keep class org.junit.** { *; } +-keep interface junit.** { *; } +-keep interface org.junit.** { *; } + +# Keep compiled java classes from declared aidl's within the test package +-keep public class * extends android.os.IInterface { *; } + +# Don't warn about the Android Support Test JUnit Runner +-dontwarn android.support.** +-dontwarn android.test.** + +# Don't warn about junit +-dontwarn junit.** +-dontwarn org.junit.** + +# Always process +-forceprocessing + +# Make sure not to obfuscate the output +-dontobfuscate 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..619580bb --- /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.lineageos.lineagesettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import lineageos.providers.LineageSettings; + +public class LineageSettingsGlobalTests 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; + LineageSettings.Global.putFloat(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = LineageSettings.Global.getFloat(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = LineageSettings.Global.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + LineageSettings.Global.putInt(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = LineageSettings.Global.getInt(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = LineageSettings.Global.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + LineageSettings.Global.putLong(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = LineageSettings.Global.getLong(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = LineageSettings.Global.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + LineageSettings.Global.putString(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = LineageSettings.Global.getString(mContentResolver, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(LineageSettings.Global.CONTENT_URI, + LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = LineageSettings.Global.getUriFor( + LineageSettings.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..f5c7ba37 --- /dev/null +++ b/packages/LineageSettingsProvider/tests/src/org/lineageos/lineagesettings/tests/LineageSettingsProviderDefaultsTest.java @@ -0,0 +1,272 @@ +/** + * 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.lineageos.lineagesettings.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 lineageos.providers.LineageSettings; +import org.lineageos.lineagesettings.LineageDatabaseHelper; +import org.lineageos.lineagesettings.LineageSettingsProvider; +import org.lineageos.lineagesettings.R; + +/** + * Created by adnan on 1/25/16. + */ +public class LineageSettingsProviderDefaultsTest 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( + LineageSettings.System.STATUS_BAR_QUICK_QS_PULLDOWN, + "R.integer.def_qs_quick_pulldown")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + "R.integer.def_notification_brightness_level")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.ENABLE_FORWARD_LOOKUP, + "R.integer.def_forward_lookup")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.ENABLE_PEOPLE_LOOKUP, + "R.integer.def_people_lookup")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.ENABLE_REVERSE_LOOKUP, + "R.integer.def_reverse_lookup")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.SYSTEM_PROFILES_ENABLED, + "R.bool.def_profiles_enabled")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE, + "R.bool.def_notification_pulse_custom_enable")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, + "R.bool.def_swap_volume_keys_on_rotation")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_VALUES, + "R.string.def_notification_pulse_custom_value")); + SYSTEM_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.System.STATUS_BAR_BATTERY_STYLE, + "R.integer.def_battery_style")); + } + + //SECURE + static { + SECURE_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Secure.ADVANCED_MODE, + "R.bool.def_advanced_mode")); + SECURE_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Secure.QS_USE_MAIN_TILES, + "R.bool.def_sysui_qs_main_tiles")); + SECURE_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Secure.STATS_COLLECTION, + "R.bool.def_stats_collection")); + SECURE_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Secure.LOCKSCREEN_VISUALIZER_ENABLED, + "R.bool.def_lockscreen_visualizer")); + SECURE_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Secure.PROTECTED_COMPONENT_MANAGERS, + "R.string.def_protected_component_managers")); + } + + //GLOBAL + static { + GLOBAL_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Global.POWER_NOTIFICATIONS_ENABLED, + "R.bool.def_power_notifications_enabled")); + GLOBAL_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Global.POWER_NOTIFICATIONS_VIBRATE, + "R.bool.def_power_notifications_vibrate")); + GLOBAL_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Global.POWER_NOTIFICATIONS_RINGTONE, + "R.string.def_power_notifications_ringtone")); + GLOBAL_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.Global.WEATHER_TEMPERATURE_UNIT, + "R.integer.def_temperature_unit")); + GLOBAL_SETTINGS_DEFAULTS.add(new Setting( + LineageSettings.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(LineageSettingsProvider.TAG, + Context.MODE_PRIVATE).getBoolean(LineageSettingsProvider.PREF_HAS_MIGRATED_LINEAGE_SETTINGS, + false); + mRemoteResources = getRemoteResources("org.lineageos.lineagesettings"); + } + + @SmallTest + public void testVerifySystemSettingsDefault() { + if (verifyNotMigratedSettings()) { + for (Setting setting : SYSTEM_SETTINGS_DEFAULTS) { + verifyDefaultSettingForTable(setting, LineageDatabaseHelper.LineageTableNames.TABLE_SYSTEM); + } + } + } + + @SmallTest + public void testVerifySecureSettingsDefaults() { + if (verifyNotMigratedSettings()) { + for (Setting setting : SECURE_SETTINGS_DEFAULTS) { + verifyDefaultSettingForTable(setting, LineageDatabaseHelper.LineageTableNames.TABLE_SECURE); + } + } + } + + @SmallTest + public void testVerifyGlobalSettingsDefaults() { + if (verifyNotMigratedSettings()) { + for (Setting setting : GLOBAL_SETTINGS_DEFAULTS) { + verifyDefaultSettingForTable(setting, LineageDatabaseHelper.LineageTableNames.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.lineageos.lineagesettings"); + 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 (LineageSettings.LineageSettingNotFoundException e) { + e.printStackTrace(); + throw new AssertionError("Setting " + setting.mKey + " not found!"); + } + } + + private int getIntForTable(Setting setting, String table) + throws LineageSettings.LineageSettingNotFoundException { + switch (table) { + case LineageDatabaseHelper.LineageTableNames.TABLE_SYSTEM: + return LineageSettings.System.getIntForUser(mContentResolver, setting.mKey, + UserHandle.USER_OWNER); + case LineageDatabaseHelper.LineageTableNames.TABLE_SECURE: + return LineageSettings.Secure.getIntForUser(mContentResolver, setting.mKey, + UserHandle.USER_OWNER); + case LineageDatabaseHelper.LineageTableNames.TABLE_GLOBAL: + return LineageSettings.Global.getIntForUser(mContentResolver, setting.mKey, + UserHandle.USER_OWNER); + default: + throw new AssertionError("Invalid or empty table!"); + } + } + + private String getStringForTable(Setting setting, String table) + throws LineageSettings.LineageSettingNotFoundException { + switch (table) { + case LineageDatabaseHelper.LineageTableNames.TABLE_SYSTEM: + return LineageSettings.System.getStringForUser(mContentResolver, setting.mKey, + UserHandle.USER_OWNER); + case LineageDatabaseHelper.LineageTableNames.TABLE_SECURE: + return LineageSettings.Secure.getStringForUser(mContentResolver, setting.mKey, + UserHandle.USER_OWNER); + case LineageDatabaseHelper.LineageTableNames.TABLE_GLOBAL: + return LineageSettings.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..17908ffe --- /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.lineageos.lineagesettings.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 lineageos.providers.LineageSettings; +import org.lineageos.lineagesettings.LineageSettingsProvider; + +import java.util.LinkedHashMap; +import java.util.Map; + + public class LineageSettingsProviderTest extends AndroidTestCase { + private static final String TAG = "LineageSettingsProviderTest"; + + 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 testMigrateLineageSettingsForOtherUser() { + // 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 LineageSettingsProvider as needed + * See {@link lineageos.providers.LineageSettings.System#shouldInterceptSystemProvider(String)} + * + * Currently this test only checks that + * {@link lineageos.providers.LineageSettings.System#SYSTEM_PROFILES_ENABLED} is expected to + * be forwarded, and is forwarded. + */ + @SmallTest + public void testSettingsProviderKeyForwarding() { + String forwardedKey = LineageSettings.System.SYSTEM_PROFILES_ENABLED; + + // make sure the key should be forwarded + assertTrue(LineageSettings.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 LineageSettings provider + LineageSettings.System.putStringForUser(mContentResolver, + forwardedKey, "1", UserHandle.USER_CURRENT); + + assertEquals("1", LineageSettings.System.getStringForUser(getContext().getContentResolver(), + forwardedKey, UserHandle.USER_CURRENT)); + + // assert reading from both returns value 2 + final String lineageProviderValue = LineageSettings.System.getStringForUser( + getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT); + final String settingsProviderValue = Settings.System.getStringForUser( + getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT); + assertEquals(lineageProviderValue, settingsProviderValue); + } + + /** + * The new {@link LineageSettings.Secure#LINEAGE_SETUP_WIZARD_COMPLETED} lineage 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 testLineageProvisionedFlagFallbackSet() { + final String newLineageFlag = LineageSettings.Secure.getStringForUser( + getContext().getContentResolver(), LineageSettings.Secure.LINEAGE_SETUP_WIZARD_COMPLETED, + UserHandle.USER_OWNER); + assertNotNull(newLineageFlag); + + final String previousFlag = Settings.Global.getStringForUser( + getContext().getContentResolver(), Settings.Global.DEVICE_PROVISIONED, + UserHandle.USER_OWNER); + assertEquals(previousFlag, newLineageFlag); + } + + private void testMigrateSettingsForUser(int userId) { + // Setup values in Settings + /*final String expectedPullDownValue = "testQuickPullDownValue"; + Settings.System.putStringForUser(mContentResolver, + LineageSettingsProvider.LegacyLineageSettings.STATUS_BAR_QUICK_QS_PULLDOWN, + expectedPullDownValue, userId); + + final int expectedKeyboardBrightness = 4; + Settings.Secure.putIntForUser(mContentResolver, + LineageSettingsProvider.LegacyLineageSettings.KEYBOARD_BRIGHTNESS, + expectedKeyboardBrightness, userId); + + Bundle arg = new Bundle(); + arg.putInt(LineageSettings.CALL_METHOD_USER_KEY, userId); + IContentProvider contentProvider = mContentResolver.acquireProvider( + LineageSettings.AUTHORITY); + + try{ + // Trigger migrate settings for guest + contentProvider.call(mContentResolver.getPackageName(), + LineageSettings.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 = LineageSettings.System.getStringForUser(mContentResolver, + LineageSettings.System.QS_QUICK_PULLDOWN, userId); + assertEquals(expectedPullDownValue, actualPullDownValue); + + final int actualKeyboardBrightness = LineageSettings.Secure.getIntForUser(mContentResolver, + LineageSettings.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(LineageSettings.System.CONTENT_URI, contentValues, keyValues); + testBulkInsertForUri(LineageSettings.Secure.CONTENT_URI, contentValues, keyValues); + testBulkInsertForUri(LineageSettings.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(LineageSettings.System.CONTENT_URI); + testInsertUpdateDeleteForUri(LineageSettings.Secure.CONTENT_URI); + testInsertUpdateDeleteForUri(LineageSettings.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..b27accad --- /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.lineageos.lineagesettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import lineageos.providers.LineageSettings; + +public class LineageSettingsSecureTests 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; + LineageSettings.Secure.putFloat(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = LineageSettings.Secure.getFloat(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = LineageSettings.Secure.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + LineageSettings.Secure.putInt(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = LineageSettings.Secure.getInt(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = LineageSettings.Secure.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + LineageSettings.Secure.putLong(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = LineageSettings.Secure.getLong(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = LineageSettings.Secure.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + LineageSettings.Secure.putString(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = LineageSettings.Secure.getString(mContentResolver, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(LineageSettings.Secure.CONTENT_URI, + LineageSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = LineageSettings.Secure.getUriFor( + LineageSettings.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..101a60f4 --- /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.lineageos.lineagesettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import lineageos.providers.LineageSettings; + +public class LineageSettingsSystemTests 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; + LineageSettings.System.putFloat(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = LineageSettings.System.getFloat(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = LineageSettings.System.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + LineageSettings.System.putInt(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = LineageSettings.System.getInt(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = LineageSettings.System.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + LineageSettings.System.putLong(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = LineageSettings.System.getLong(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (LineageSettings.LineageSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = LineageSettings.System.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + LineageSettings.System.putString(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = LineageSettings.System.getString(mContentResolver, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(LineageSettings.System.CONTENT_URI, + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = LineageSettings.System.getUriFor( + LineageSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + + assertEquals(expectedUri, actualUri); + } +} |