5
5
6
6
import java .lang .reflect .Constructor ;
7
7
import java .lang .reflect .Method ;
8
+ import java .lang .reflect .Proxy ;
8
9
9
10
import dalvik .system .PathClassLoader ;
10
11
@@ -17,6 +18,7 @@ public class MiBridge {
17
18
private static final String TAG = "MiBridge" ;
18
19
private static final String PERFORMANCE_JAR = "/system/framework/MiuiBooster.jar" ;
19
20
private static final String PERFORMANCE_CLASS = "com.miui.performance.MiuiBooster" ;
21
+ private static final String ITHERMALEVENTCALLBACK_CLASS = "com.miui.performance.IThermalEventCallBack" ;
20
22
21
23
private static Method mCheckPermissionFunc = null ;
22
24
private static Method mCheckDebugPermissionFunc = null ;
@@ -31,8 +33,13 @@ public class MiBridge {
31
33
private static Method mCancelDdrHighFunc = null ;
32
34
private static Method mRequestBindCoreFunc = null ;
33
35
private static Method mCancelBindCoreFunc = null ;
36
+ private static Method mGetSystemStateFunc = null ;
37
+ private static Method mRegisterThermalEventCallbackFunc = null ;
38
+ private static Method mUnRegisterThermalEventCallbackFunc = null ;
39
+
34
40
35
41
private static Class perfClass ;
42
+ private static Class IThermalEventCallBackClass = null ;
36
43
private static PathClassLoader perfClassLoader ;
37
44
38
45
private static Constructor <Class > mConstructor = null ;
@@ -43,6 +50,7 @@ public class MiBridge {
43
50
perfClassLoader = new PathClassLoader (PERFORMANCE_JAR ,
44
51
ClassLoader .getSystemClassLoader ());
45
52
perfClass = perfClassLoader .loadClass (PERFORMANCE_CLASS );
53
+ IThermalEventCallBackClass = perfClassLoader .loadClass (ITHERMALEVENTCALLBACK_CLASS );
46
54
mConstructor = perfClass .getConstructor ();
47
55
Class [] argClasses = new Class []{String .class , int .class };
48
56
try {
@@ -140,6 +148,28 @@ public class MiBridge {
140
148
} catch (Exception e ) {
141
149
Log .e (TAG , "requestIOPrefetch no exit" );
142
150
}
151
+
152
+ try {
153
+ argClasses = new Class []{int .class , Context .class , int .class };
154
+ mGetSystemStateFunc = perfClass .getDeclaredMethod ("getSystemState" , argClasses );
155
+ } catch (Exception e ) {
156
+ Log .e (TAG , "getSystemState no exit" );
157
+ }
158
+
159
+ try {
160
+ argClasses = new Class [] {int .class , IThermalEventCallBackClass };
161
+ mRegisterThermalEventCallbackFunc = perfClass .getDeclaredMethod ("registerThermalEventCallback" , argClasses );
162
+ } catch (Exception e ) {
163
+ Log .e (TAG , "registerThermalEventCallback no exit, " + e );
164
+ }
165
+
166
+ try {
167
+ argClasses = new Class []{int .class , IThermalEventCallBackClass };
168
+ mUnRegisterThermalEventCallbackFunc = perfClass .getDeclaredMethod ("unRegisterThermalEventCallback" , argClasses );
169
+ } catch (Exception e ) {
170
+ Log .e (TAG , "UnRegisterThermalEventCallback no exit" );
171
+ }
172
+
143
173
} catch (Exception e ) {
144
174
Log .e (TAG , "MiBridge() : Load Class Exception: " + e );
145
175
}
@@ -299,4 +329,54 @@ public static int requestIOPrefetch(int uid, String filePath) {
299
329
}
300
330
return ret ;
301
331
}
332
+
333
+ public static int getSystemState (int uid , Context context , int type ) {
334
+ int ret = -1 ;
335
+ try {
336
+ Object retVal = mGetSystemStateFunc .invoke (mPerf , uid , context , type );
337
+ ret = (int ) retVal ;
338
+ } catch (Exception e ) {
339
+ Log .e (TAG , "get system state failed , e:" + e .toString ());
340
+ }
341
+ return ret ;
342
+ }
343
+
344
+ public static int registerThermalEventCallback (int uid , ThermalEventCallBack cb ) {
345
+ int ret = -1 ;
346
+ Object Obj = null ;
347
+ try {
348
+ Obj = cb .getProxy (IThermalEventCallBackClass );
349
+ } catch (Exception e ) {
350
+ Log .e (TAG , "getProxy failed, e: " + e .toString ());
351
+ return ret ;
352
+ }
353
+
354
+ try {
355
+ Object retVal = mRegisterThermalEventCallbackFunc .invoke (mPerf , uid , Obj );
356
+ ret = (int ) retVal ;
357
+ } catch (Exception e ) {
358
+ Log .e (TAG , "registerThermalEventCallback failed , e:" + e .toString ());
359
+ }
360
+ return ret ;
361
+ }
362
+
363
+
364
+ public static int unRegisterThermalEventCallback (int uid , ThermalEventCallBack cb ) {
365
+ int ret = -1 ;
366
+ Object Obj = null ;
367
+ try {
368
+ Obj = cb .getProxy (IThermalEventCallBackClass );
369
+ } catch (Exception e ) {
370
+ Log .e (TAG , "getProxy failed, e: " + e .toString ());
371
+ return ret ;
372
+ }
373
+ try {
374
+ Object retVal = mUnRegisterThermalEventCallbackFunc .invoke (mPerf , uid , Obj );
375
+ ret = (int ) retVal ;
376
+ } catch (Exception e ) {
377
+ Log .e (TAG , "unRegisterThermalEventCallback failed , e:" + e .toString ());
378
+ }
379
+ return ret ;
380
+ }
381
+
302
382
}
0 commit comments