Skip to content

Commit

Permalink
MiSpeed expand Thermal
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiqiangGe-xiaomi committed Jun 17, 2022
1 parent 1b3b3e3 commit 5ad83c1
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
Binary file modified MiBridge.jar
Binary file not shown.
Binary file modified TestMiBridge/app/libs/MiBridge.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.bun.miitmdid.core.JLibrary;
import com.mi.mibridge.MiBridge;
import com.mi.mibridge.ThermalEventCallBack;

import java.util.ArrayList;
import java.util.List;

public class ApiActivity extends AppCompatActivity {

private static final String TAG = "TestMiBridge";

// 数据源
private List<MiBridgeModel> miBridgeModels = new ArrayList<>();

Expand Down Expand Up @@ -65,6 +69,15 @@ public class ApiActivity extends AppCompatActivity {
// tid
private int mBridgeTid;

// system state
private static final int QUERY_BOARD_TEMP = 1;
private static final int QUERY_POWER_MODE = 2;

// ThermalEventCallBack
ThermalEventCallBack mThermalEventCallBack = null;
Context mContext;


private MiitHelper.AppIdsUpdater appIdsUpdater = new MiitHelper.AppIdsUpdater() {
@Override
public void OnIdsAvalid(@NonNull String ids) {
Expand All @@ -89,6 +102,7 @@ protected void onCreate(Bundle savedInstanceState) {

initData();
initView();
mContext = this;
}

private void initView() {
Expand Down Expand Up @@ -239,6 +253,58 @@ public void run() {
showResult(ret, "requestThreadPriority ");
}
}));

miBridgeModels.add(new MiBridgeModel("getSystemState -> boardTemp", new Runnable() {
@Override
public void run() {
int ret = MiBridge.getSystemState(mBridgeUid, mContext, QUERY_BOARD_TEMP);
Toast.makeText(ApiActivity.this, "getSystemState: " + ret, Toast.LENGTH_SHORT).show();
}
}));

miBridgeModels.add(new MiBridgeModel("getSystemState -> powerMode", new Runnable() {
@Override
public void run() {
int ret = MiBridge.getSystemState(mBridgeUid, mContext, QUERY_POWER_MODE);
Toast.makeText(ApiActivity.this, "getSystemState: " + ret, Toast.LENGTH_SHORT).show();
}
}));

miBridgeModels.add(new MiBridgeModel("registerThermalEventCallback", new Runnable() {
@Override
public void run() {
if(mThermalEventCallBack == null) {
mThermalEventCallBack = new ThermalEventCallBack() {
@Override
public void onThermalLevelChanged(int level) {
Log.e(TAG, "onThermalLevelChanged: " + level);
//do somthing;
}
};
int ret = MiBridge.registerThermalEventCallback(mBridgeUid, mThermalEventCallBack);
Toast.makeText(ApiActivity.this, "registerThermalEventCallback: " + ret, Toast.LENGTH_SHORT).show();
} else {
Log.w(TAG, "You should unRegisterThermalEventCallback last one!");
Toast.makeText(ApiActivity.this, "To unRegisterThermalEventCallback last one!!", Toast.LENGTH_SHORT).show();
}
}
}));

miBridgeModels.add(new MiBridgeModel("unRegisterThermalEventCallback", new Runnable() {
@Override
public void run() {
if(mThermalEventCallBack != null) {
int ret = MiBridge.unRegisterThermalEventCallback(mBridgeUid, mThermalEventCallBack);
Toast.makeText(ApiActivity.this, "unRegisterThermalEventCallback: " + ret, Toast.LENGTH_SHORT).show();
mThermalEventCallBack = null;
} else {
Log.w(TAG, "You should registerThermalEventCallback first!");
Toast.makeText(ApiActivity.this, "To registerThermalEventCallback first!", Toast.LENGTH_SHORT).show();
}

}
}));

}


Expand Down
80 changes: 80 additions & 0 deletions TestMiBridge/mibridge/src/main/java/com/mi/mibridge/MiBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import dalvik.system.PathClassLoader;

Expand All @@ -17,6 +18,7 @@ public class MiBridge {
private static final String TAG = "MiBridge";
private static final String PERFORMANCE_JAR = "/system/framework/MiuiBooster.jar";
private static final String PERFORMANCE_CLASS = "com.miui.performance.MiuiBooster";
private static final String ITHERMALEVENTCALLBACK_CLASS = "com.miui.performance.IThermalEventCallBack";

private static Method mCheckPermissionFunc = null;
private static Method mCheckDebugPermissionFunc = null;
Expand All @@ -31,8 +33,13 @@ public class MiBridge {
private static Method mCancelDdrHighFunc = null;
private static Method mRequestBindCoreFunc = null;
private static Method mCancelBindCoreFunc = null;
private static Method mGetSystemStateFunc = null;
private static Method mRegisterThermalEventCallbackFunc = null;
private static Method mUnRegisterThermalEventCallbackFunc = null;


private static Class perfClass;
private static Class IThermalEventCallBackClass = null;
private static PathClassLoader perfClassLoader;

private static Constructor<Class> mConstructor = null;
Expand All @@ -43,6 +50,7 @@ public class MiBridge {
perfClassLoader = new PathClassLoader(PERFORMANCE_JAR,
ClassLoader.getSystemClassLoader());
perfClass = perfClassLoader.loadClass(PERFORMANCE_CLASS);
IThermalEventCallBackClass = perfClassLoader.loadClass(ITHERMALEVENTCALLBACK_CLASS);
mConstructor = perfClass.getConstructor();
Class[] argClasses = new Class[]{String.class, int.class};
try {
Expand Down Expand Up @@ -140,6 +148,28 @@ public class MiBridge {
} catch (Exception e) {
Log.e(TAG, "requestIOPrefetch no exit");
}

try {
argClasses = new Class[]{int.class, Context.class, int.class};
mGetSystemStateFunc = perfClass.getDeclaredMethod("getSystemState", argClasses);
} catch (Exception e) {
Log.e(TAG, "getSystemState no exit");
}

try {
argClasses = new Class[] {int.class, IThermalEventCallBackClass };
mRegisterThermalEventCallbackFunc = perfClass.getDeclaredMethod("registerThermalEventCallback", argClasses);
} catch (Exception e) {
Log.e(TAG, "registerThermalEventCallback no exit, " + e);
}

try {
argClasses = new Class[]{int.class, IThermalEventCallBackClass };
mUnRegisterThermalEventCallbackFunc = perfClass.getDeclaredMethod("unRegisterThermalEventCallback", argClasses);
} catch (Exception e) {
Log.e(TAG, "UnRegisterThermalEventCallback no exit");
}

} catch (Exception e) {
Log.e(TAG, "MiBridge() : Load Class Exception: " + e);
}
Expand Down Expand Up @@ -299,4 +329,54 @@ public static int requestIOPrefetch(int uid, String filePath) {
}
return ret;
}

public static int getSystemState(int uid, Context context, int type) {
int ret = -1;
try {
Object retVal = mGetSystemStateFunc.invoke(mPerf, uid, context, type);
ret = (int) retVal;
} catch (Exception e) {
Log.e(TAG, "get system state failed , e:" + e.toString());
}
return ret;
}

public static int registerThermalEventCallback(int uid, ThermalEventCallBack cb) {
int ret = -1;
Object Obj = null;
try {
Obj = cb.getProxy(IThermalEventCallBackClass);
} catch (Exception e) {
Log.e(TAG, "getProxy failed, e: " + e.toString());
return ret;
}

try {
Object retVal = mRegisterThermalEventCallbackFunc.invoke(mPerf, uid, Obj);
ret = (int) retVal;
} catch (Exception e) {
Log.e(TAG, "registerThermalEventCallback failed , e:" + e.toString());
}
return ret;
}


public static int unRegisterThermalEventCallback(int uid, ThermalEventCallBack cb) {
int ret = -1;
Object Obj = null;
try {
Obj = cb.getProxy(IThermalEventCallBackClass);
} catch (Exception e) {
Log.e(TAG, "getProxy failed, e: " + e.toString());
return ret;
}
try {
Object retVal = mUnRegisterThermalEventCallbackFunc.invoke(mPerf, uid, Obj);
ret = (int) retVal;
} catch (Exception e) {
Log.e(TAG, "unRegisterThermalEventCallback failed , e:" + e.toString());
}
return ret;
}

}
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;
}
}

0 comments on commit 5ad83c1

Please sign in to comment.