| 5 | import nota.reflect.ReflectionCache; |
| 6 | |
| 7 | public class SystemProperties { |
| 8 | |
| 9 | /** |
| 10 | * Get the value for the given key. |
| 11 | * |
| 12 | * @return an empty string if the key isn't found |
| 13 | * @throws IllegalArgumentException if the key exceeds 32 characters |
| 14 | */ |
| 15 | public static String get(String key) throws IllegalArgumentException { |
| 16 | |
| 17 | String ret; |
| 18 | |
| 19 | try { |
| 20 | @SuppressWarnings("rawtypes") Class systemProperties = ReflectionCache.build().forName("android.os.SystemProperties"); |
| 21 | |
| 22 | //Parameters Types |
| 23 | @SuppressWarnings("rawtypes") Class[] paramTypes = new Class[1]; |
| 24 | paramTypes[0] = String.class; |
| 25 | |
| 26 | Method get = ReflectionCache.build().getMethod(systemProperties, "get", paramTypes); |
| 27 | |
| 28 | //Parameters |
| 29 | Object[] params = new Object[1]; |
| 30 | params[0] = key; |
| 31 | |
| 32 | ret = (String) get.invoke(systemProperties, params); |
| 33 | |
| 34 | } catch (IllegalArgumentException iAE) { |
| 35 | throw iAE; |
| 36 | } catch (Exception e) { |
| 37 | ret = ""; |
| 38 | } |
| 39 | |
| 40 | return ret; |
| 41 | |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get the value for the given key. |
| 46 | * |
| 47 | * @return if the key isn't found, return def if it isn't null, or an empty string otherwise |
| 48 | * @throws IllegalArgumentException if the key exceeds 32 characters |
| 49 | */ |
| 50 | public static String get(String key, String def) throws IllegalArgumentException { |
| 51 | |
| 52 | String ret; |
| 53 | |
| 54 | try { |
| 55 | |
| 56 | @SuppressWarnings("rawtypes") Class systemProperties = ReflectionCache.build().forName("android.os.SystemProperties"); |
| 57 | |
| 58 | //Parameters Types |
| 59 | @SuppressWarnings("rawtypes") Class[] paramTypes = new Class[2]; |
| 60 | paramTypes[0] = String.class; |
| 61 | paramTypes[1] = String.class; |
| 62 | |
| 63 | Method get = ReflectionCache.build().getMethod(systemProperties, "get", paramTypes); |
| 64 |
nothing calls this directly
no outgoing calls
no test coverage detected