1 /* 2 * Copyright (C) 2019 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.server.power; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.SystemProperties; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 25 /** 26 * Wrapper interface to access {@link SystemProperties}. 27 * 28 * @hide 29 */ 30 @VisibleForTesting 31 interface SystemPropertiesWrapper { 32 /** 33 * Get the String value for the given {@code key}. 34 * 35 * @param key the key to lookup 36 * @param def the default value in case the property is not set or empty 37 * @return if the {@code key} isn't found, return {@code def} if it isn't null, or an empty 38 * string otherwise 39 */ 40 @NonNull get(@onNull String key, @Nullable String def)41 String get(@NonNull String key, @Nullable String def); 42 43 /** 44 * Set the value for the given {@code key} to {@code val}. 45 * 46 * @throws IllegalArgumentException if the {@code val} exceeds 91 characters 47 * @throws RuntimeException if the property cannot be set, for example, if it was blocked by 48 * SELinux. libc will log the underlying reason. 49 */ set(@onNull String key, @Nullable String val)50 void set(@NonNull String key, @Nullable String val); 51 } 52