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 17package com.android.settings.fuelgauge.anomaly; 18 19import android.util.KeyValueListParser; 20 21/** 22 * This interface replicates a subset of the {@link KeyValueListParser}. The interface 23 * exists so that we can use a thin wrapper around the PM in production code and a mock in tests. 24 * We cannot directly mock or shadow the {@link KeyValueListParser}, because some of the methods 25 * we rely on are newer than the API version supported by Robolectric. 26 */ 27public interface KeyValueListParserWrapper { 28 29 /** 30 * Get real {@link KeyValueListParser} 31 */ 32 KeyValueListParser getKeyValueListParser(); 33 34 /** 35 * Resets the parser with a new string to parse. The string is expected to be in the following 36 * format: 37 * <pre>key1=value,key2=value,key3=value</pre> 38 * 39 * where the delimiter is a comma. 40 * 41 * @param str the string to parse. 42 * @throws IllegalArgumentException if the string is malformed. 43 */ 44 void setString(String str) throws IllegalArgumentException; 45 46 /** 47 * Get the value for key as a string. 48 * @param key The key to lookup. 49 * @param defaultValue The value to return if the key was not found. 50 * @return the string value associated with the key. 51 */ 52 String getString(String key, String defaultValue); 53 54 /** 55 * Get the value for key as a boolean. 56 * @param key The key to lookup. 57 * @param defaultValue The value to return if the key was not found. 58 * @return the string value associated with the key. 59 */ 60 boolean getBoolean(String key, boolean defaultValue); 61 62 /** 63 * Get the value for key as a long. 64 * @param key The key to lookup. 65 * @param defaultValue The value to return if the key was not found, or the value was not a 66 * long. 67 * @return the long value associated with the key. 68 */ 69 long getLong(String key, long defaultValue); 70} 71