1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.testutils.shadow; 18 19 import android.content.ContentResolver; 20 import android.provider.Settings; 21 22 import org.robolectric.annotation.Implementation; 23 import org.robolectric.annotation.Implements; 24 25 import java.util.HashMap; 26 import java.util.Map; 27 28 @Implements(Settings.Secure.class) 29 public class ShadowSecureSettings { 30 31 private static final Map<String, Object> mValueMap = new HashMap<>(); 32 33 @Implementation putInt(ContentResolver resolver, String name, int value)34 public static boolean putInt(ContentResolver resolver, String name, int value) { 35 mValueMap.put(name, value); 36 return true; 37 } 38 39 @Implementation putString(ContentResolver resolver, String name, String value)40 public static boolean putString(ContentResolver resolver, String name, String value) { 41 mValueMap.put(name, value); 42 return true; 43 } 44 45 @Implementation getString(ContentResolver resolver, String name)46 public static String getString(ContentResolver resolver, String name) { 47 return (String) mValueMap.get(name); 48 } 49 50 @Implementation getStringForUser(ContentResolver resolver, String name, int userHandle)51 public static String getStringForUser(ContentResolver resolver, String name, int userHandle) { 52 return getString(resolver, name); 53 } 54 55 @Implementation putIntForUser(ContentResolver cr, String name, int value, int userHandle)56 public static boolean putIntForUser(ContentResolver cr, String name, int value, 57 int userHandle) { 58 return putInt(cr, name, value); 59 } 60 61 @Implementation getIntForUser(ContentResolver cr, String name, int def, int userHandle)62 public static int getIntForUser(ContentResolver cr, String name, int def, int userHandle) { 63 return getInt(cr, name, def); 64 } 65 66 @Implementation getInt(ContentResolver resolver, String name, int defaultValue)67 public static int getInt(ContentResolver resolver, String name, int defaultValue) { 68 Integer value = (Integer) mValueMap.get(name); 69 return value == null ? defaultValue : value; 70 } 71 clear()72 public static void clear() { 73 mValueMap.clear(); 74 } 75 } 76