- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSystemPropertiesUtils.java
More file actions
Latest commit
78 lines (73 loc) · 2.65 KB
/
Copy pathSystemPropertiesUtils.java
File metadata and controls
78 lines (73 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
packagecom.hht.oem.quicksetting.utils;
importjava.lang.reflect.InvocationTargetException;
importjava.lang.reflect.Method;
importjava.util.logging.Logger;
publicclassSystemPropertiesUtils {
publicstaticvoidsetProperty(Stringkey, Stringvalue) {
try {
Class<?> clazz = Class.forName("android.os.SystemProperties");
Methodmethod = clazz.getMethod("set", String.class, String.class);
method.invoke(clazz, key, value);
} catch (ClassNotFoundExceptione) {
e.printStackTrace();
} catch (NoSuchMethodExceptione) {
e.printStackTrace();
} catch (IllegalAccessExceptione) {
e.printStackTrace();
} catch (InvocationTargetExceptione) {
e.printStackTrace();
}
}
/**
*
* @param key 关键字
* @param def 根据默认字 获取
* @return
*/
publicstaticObjectgetProperty(Stringkey, Objectdef) {
try {
Class<?> clazz = Class.forName("android.os.SystemProperties");
if (definstanceofString) {
Stringvalue = (String) def;
Methodmethod = clazz.getMethod("get", String.class, String.class);
returnmethod.invoke(clazz, key, value);
}
elseif (definstanceofBoolean) {
Booleanvalue = (Boolean) def;
Methodmethod = clazz.getMethod("getBoolean", String.class, boolean.class);
returnmethod.invoke(clazz, key, value);
}
elseif (definstanceofInteger) {
Integervalue = (Integer) def;
Methodmethod = clazz.getMethod("getInt", String.class, int.class);
returnmethod.invoke(clazz, key, value);
}
elseif (definstanceofLong) {
Longvalue = (Long) def;
Methodmethod = clazz.getMethod("getLong", String.class, long.class);
returnmethod.invoke(clazz, key, value);
}
} catch (ClassNotFoundExceptione) {
e.printStackTrace();
} catch (NoSuchMethodExceptione) {
e.printStackTrace();
} catch (IllegalAccessExceptione) {
e.printStackTrace();
} catch (InvocationTargetExceptione) {
e.printStackTrace();
}
if (definstanceofString) {
return"";
}
elseif (definstanceofBoolean) {
returnfalse;
}
elseif (definstanceofLong) {
return -1L;
}
elseif (definstanceofInteger) {
return -1;
}
returnnewObject();
}
}