1 /* 2 * Copyright (C) 2015 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 package com.android.messaging.sms; 17 18 import java.lang.reflect.InvocationTargetException; 19 import java.lang.reflect.Method; 20 21 /** 22 * Hacky way to call the hidden SystemProperties class API 23 */ 24 class SystemProperties { 25 private static Method sSystemPropertiesGetMethod = null; 26 get(final String name)27 public static String get(final String name) { 28 if (sSystemPropertiesGetMethod == null) { 29 try { 30 final Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); 31 if (systemPropertiesClass != null) { 32 sSystemPropertiesGetMethod = 33 systemPropertiesClass.getMethod("get", String.class); 34 } 35 } catch (final ClassNotFoundException e) { 36 // Nothing to do 37 } catch (final NoSuchMethodException e) { 38 // Nothing to do 39 } 40 } 41 if (sSystemPropertiesGetMethod != null) { 42 try { 43 return (String) sSystemPropertiesGetMethod.invoke(null, name); 44 } catch (final IllegalArgumentException e) { 45 // Nothing to do 46 } catch (final IllegalAccessException e) { 47 // Nothing to do 48 } catch (final InvocationTargetException e) { 49 // Nothing to do 50 } 51 } 52 return null; 53 } 54 } 55