Loading core/java/android/provider/Settings.java +34 −0 Original line number Diff line number Diff line Loading @@ -1779,6 +1779,12 @@ public final class Settings { return mContentProvider; } } public void clearProviderForTest() { synchronized (mLock) { mContentProvider = null; } } } // Thread-safe. Loading Loading @@ -1994,6 +2000,16 @@ public final class Settings { if (c != null) c.close(); } } public void clearGenerationTrackerForTest() { synchronized (NameValueCache.this) { if (mGenerationTracker != null) { mGenerationTracker.destroy(); } mValues.clear(); mGenerationTracker = null; } } } /** Loading Loading @@ -2182,6 +2198,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_GLOBAL); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading Loading @@ -4595,6 +4617,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_GLOBAL); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading Loading @@ -10037,6 +10065,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_SECURE); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.test.mock.MockContentResolver; import com.android.internal.util.test.FakeSettingsProvider; import com.android.server.AppOpsService; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; Loading @@ -59,7 +60,6 @@ import java.io.File; * Run: adb shell am instrument -e class com.android.server.am.CoreSettingsObserverTest -w \ * com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner */ @Ignore @SmallTest @RunWith(AndroidJUnit4.class) public class CoreSettingsObserverTest { Loading @@ -79,11 +79,17 @@ public class CoreSettingsObserverTest { @BeforeClass public static void setupOnce() { FakeSettingsProvider.clearSettingsProvider(); CoreSettingsObserver.sSecureSettingToTypeMap.put(TEST_SETTING_SECURE_INT, int.class); CoreSettingsObserver.sGlobalSettingToTypeMap.put(TEST_SETTING_GLOBAL_FLOAT, float.class); CoreSettingsObserver.sSystemSettingToTypeMap.put(TEST_SETTING_SYSTEM_STRING, String.class); } @AfterClass public static void tearDownOnce() { FakeSettingsProvider.clearSettingsProvider(); } @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading tests/utils/testutils/java/com/android/internal/util/test/FakeSettingsProvider.java +11 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ import java.util.HashMap; * Note that this class cannot be used in the same process as real settings. This is because it * works by passing an alternate ContentResolver to Settings operations. Unfortunately, the Settings * class only fetches the content provider from the passed-in ContentResolver the first time it's * used, and after that stores it in a per-process static. * used, and after that stores it in a per-process static. If this needs to be used in this case, * then call {@link #clearSettingsProvider()} before and after using this. * * TODO: evaluate implementing settings change notifications. This would require: * Loading Loading @@ -90,6 +91,15 @@ public class FakeSettingsProvider extends MockContentProvider { } } /** * This needs to be called before and after using the FakeSettingsProvider class. */ public static void clearSettingsProvider() { Settings.Secure.clearProviderForTest(); Settings.Global.clearProviderForTest(); Settings.System.clearProviderForTest(); } public Bundle call(String method, String arg, Bundle extras) { // Methods are "GET_system", "GET_global", "PUT_secure", etc. String[] commands = method.split("_", 2); Loading Loading
core/java/android/provider/Settings.java +34 −0 Original line number Diff line number Diff line Loading @@ -1779,6 +1779,12 @@ public final class Settings { return mContentProvider; } } public void clearProviderForTest() { synchronized (mLock) { mContentProvider = null; } } } // Thread-safe. Loading Loading @@ -1994,6 +2000,16 @@ public final class Settings { if (c != null) c.close(); } } public void clearGenerationTrackerForTest() { synchronized (NameValueCache.this) { if (mGenerationTracker != null) { mGenerationTracker.destroy(); } mValues.clear(); mGenerationTracker = null; } } } /** Loading Loading @@ -2182,6 +2198,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_GLOBAL); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading Loading @@ -4595,6 +4617,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_GLOBAL); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading Loading @@ -10037,6 +10065,12 @@ public final class Settings { outKeySet.addAll(MOVED_TO_SECURE); } /** @hide */ public static void clearProviderForTest() { sProviderHolder.clearProviderForTest(); sNameValueCache.clearGenerationTrackerForTest(); } /** * Look up a name in the database. * @param resolver to access the database with Loading
services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.test.mock.MockContentResolver; import com.android.internal.util.test.FakeSettingsProvider; import com.android.server.AppOpsService; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; Loading @@ -59,7 +60,6 @@ import java.io.File; * Run: adb shell am instrument -e class com.android.server.am.CoreSettingsObserverTest -w \ * com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner */ @Ignore @SmallTest @RunWith(AndroidJUnit4.class) public class CoreSettingsObserverTest { Loading @@ -79,11 +79,17 @@ public class CoreSettingsObserverTest { @BeforeClass public static void setupOnce() { FakeSettingsProvider.clearSettingsProvider(); CoreSettingsObserver.sSecureSettingToTypeMap.put(TEST_SETTING_SECURE_INT, int.class); CoreSettingsObserver.sGlobalSettingToTypeMap.put(TEST_SETTING_GLOBAL_FLOAT, float.class); CoreSettingsObserver.sSystemSettingToTypeMap.put(TEST_SETTING_SYSTEM_STRING, String.class); } @AfterClass public static void tearDownOnce() { FakeSettingsProvider.clearSettingsProvider(); } @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading
tests/utils/testutils/java/com/android/internal/util/test/FakeSettingsProvider.java +11 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ import java.util.HashMap; * Note that this class cannot be used in the same process as real settings. This is because it * works by passing an alternate ContentResolver to Settings operations. Unfortunately, the Settings * class only fetches the content provider from the passed-in ContentResolver the first time it's * used, and after that stores it in a per-process static. * used, and after that stores it in a per-process static. If this needs to be used in this case, * then call {@link #clearSettingsProvider()} before and after using this. * * TODO: evaluate implementing settings change notifications. This would require: * Loading Loading @@ -90,6 +91,15 @@ public class FakeSettingsProvider extends MockContentProvider { } } /** * This needs to be called before and after using the FakeSettingsProvider class. */ public static void clearSettingsProvider() { Settings.Secure.clearProviderForTest(); Settings.Global.clearProviderForTest(); Settings.System.clearProviderForTest(); } public Bundle call(String method, String arg, Bundle extras) { // Methods are "GET_system", "GET_global", "PUT_secure", etc. String[] commands = method.split("_", 2); Loading