150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher/* 250f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * Copyright (C) 2014 The Android Open Source Project 350f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * 450f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * Licensed under the Apache License, Version 2.0 (the "License"); 550f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * you may not use this file except in compliance with the License. 650f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * You may obtain a copy of the License at 750f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * 850f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * http://www.apache.org/licenses/LICENSE-2.0 950f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * 1050f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * Unless required by applicable law or agreed to in writing, software 1150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * distributed under the License is distributed on an "AS IS" BASIS, 1250f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1350f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * See the License for the specific language governing permissions and 1450f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * limitations under the License. 1550f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher */ 1650f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 1750f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucherpackage com.android.ex.camera2.portability.util; 1850f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 1950f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucherimport com.android.ex.camera2.portability.debug.Log; 2050f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 2150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucherimport java.lang.reflect.Method; 2250f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 2350f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher/** 2450f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * Mirrors hidden class {@link android.os.SystemProperties} (available since API Level 1). 2550f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher */ 2650f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucherpublic final class SystemProperties { 2750f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher private static final Log.Tag TAG = new Log.Tag("SysProps"); 2850f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 2950f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher /** 3050f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * Gets system properties set by <code>adb shell setprop <em>key</em> <em>value</em></code> 3150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * 3250f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * @param key the property key. 3350f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * @param defaultValue the value to return if the property is undefined or empty (this parameter 3450f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * may be {@code null}). 3550f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher * @return the system property value or the default value. 3650f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher */ 3750f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher public static String get(String key, String defaultValue) { 3850f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher try { 3950f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher final Class<?> systemProperties = Class.forName("android.os.SystemProperties"); 4050f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher final Method get = systemProperties.getMethod("get", String.class, String.class); 4150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher return (String) get.invoke(null, key, defaultValue); 4250f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher } catch (Exception e) { 4350f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher // This should never happen 4450f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher Log.e(TAG, "Exception while getting system property: ", e); 4550f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher return defaultValue; 4650f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher } 4750f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher } 4850f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher 4950f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher private SystemProperties() { 5050f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher } 5150f5b019ba3f333a09a1beb9667fd7290082dc31Sol Boucher} 52