-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b3b3e3
commit 5ad83c1
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
TestMiBridge/mibridge/src/main/java/com/mi/mibridge/ThermalEventCallBack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.mi.mibridge; | ||
|
||
import android.util.Log; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class ThermalEventCallBack implements InvocationHandler { | ||
private static final String TAG = "MiBridge"; | ||
private Object mObj = null; | ||
private Object mTarget = null; | ||
|
||
public void onThermalLevelChanged(int level){}; | ||
|
||
public int getProxyHashCode() { | ||
return this.hashCode(); | ||
} | ||
|
||
public Object getProxy(Class IThermalEventCallBack) { | ||
mTarget = IThermalEventCallBack.getInterfaces(); | ||
mObj = Proxy.newProxyInstance(IThermalEventCallBack.getClassLoader(), new Class[] { IThermalEventCallBack }, this); | ||
return mObj; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object o, Method method, Object[] args) throws Throwable { | ||
Object ret = null; | ||
|
||
if(mTarget == null) { | ||
Log.e(TAG, "getProxy fisrt!"); | ||
} | ||
|
||
if(method.getName() == "onThermalLevelChanged" && args != null) { | ||
int level = Integer.parseInt(String.valueOf(args[0])); | ||
onThermalLevelChanged(level); | ||
return null; | ||
} else if(method.getName() == "getProxyHashCode") { | ||
ret = getProxyHashCode(); | ||
return ret; | ||
} | ||
|
||
try { | ||
ret = method.invoke(mTarget, args); | ||
} catch (Exception e) { | ||
Log.e(TAG, "method invoke failed, e: " + e); | ||
} | ||
|
||
return ret; | ||
} | ||
} |