当前位置: 首页 > 工具软件 > 变色龙SDK > 使用案例 >

Xpose实例分析-变色龙

赖渊
2023-12-01

主要分析状态背景变色那块

ColourChangerMod.java

WindowDecorActionBarHooks.java

ActionBarHooks.java

StatusBarViewHook.java

1.先看看Xposed各个回调具体执行,之前讲了是在XposedBridge的loadModules中执行。

private static void loadModule(String apk, String startClassName) {
......
// call the init(String) method of the module
	final Object moduleInstance = moduleClass.newInstance();
	if (startClassName == null) {//1 initZygote 2 hookLoadPackage 3 hookInitPackageResources
	if (moduleInstance instanceof IXposedHookZygoteInit) {
               //IXposedHookZygoteInit
	       IXposedHookZygoteInit.StartupParam param = new IXposedHookZygoteInit.StartupParam();
		param.modulePath = apk;
		((IXposedHookZygoteInit) moduleInstance).initZygote(param); 
	}
       if (moduleInstance instanceof IXposedHookLoadPackage)
                //IXposedHookLoadPackage
		hookLoadPackage(new IXposedHookLoadPackage.Wrapper((IXposedHookLoadPackage) moduleInstance));
        if (moduleInstance instanceof IXposedHookInitPackageResources)
               //IXposedHookInitPackageResources
		hookInitPackageResources(new IXposedHookInitPackageResources.Wrapper((IXposedHookInitPackageResources) moduleInstance));
	} else {
		if (moduleInstance instanceof IXposedHookCmdInit) {
                        //IXposedHookCmdInit
			IXposedHookCmdInit.StartupParam param = new IXposedHookCmdInit.StartupParam();
			param.modulePath = apk;
			param.startClassName = startClassName;
			((IXposedHookCmdInit) moduleInstance).initCmdApp(param);
			}
		}
......
}
ColourChangerMod.java

@Override
public void initZygote(StartupParam startupParam) throws Throwable {
......
      if (Utils.hasActionBar())
	new ActionBarHooks(mSettingsHelper);
}

@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
......
        //hook actionbar here
	if (!lpparam.packageName.equals("com.android.systemui")) {
		new WindowDecorActionBarHooks(mSettingsHelper, lpparam);
			return;
	}
}
WindowDecorActionBarHooks.javat和ActionBarHooks.java差不多

public WindowDecorActionBarHooks(SettingsHelper settingsHelper, XC_LoadPackage.LoadPackageParam lpparam) {
......
         findAndHookMethod(WindowDecorActionBar, "setBackgroundDrawable", Drawable.class, new XC_MethodHook() {
......
                   Drawable drawable = (Drawable) param.args[0];//获得Drawable 
                   int color = Utils.getMainColorFromActionBarDrawable(drawable);//获得颜色
                  ColourChangerMod.sendColorChangeIntent(color, Utils.getIconColorForColor(color, defaultNormal, nvertedIconTint, mSettingsHelper.getHsvMax()), actionBar.getContext());//发送广播变色
}
}
ColourChangerMod.java收到广播后调用setStatusBarTint进行变色,ColourChangerMod类中之前提到的handleLoadPackage中对StatusBarView也进行了hook,StatusBarViewHook.java

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
	mInstance.setStatusBarView((View) param.thisObject);
}
//ColourChangerMod.java
public void setStatusBarView(View view) {
	mStatusBarView = view;
	Utils.setViewBackground(mStatusBarView, mGradientDrawable);
}
//最后
public static void setViewBackground(View view, Drawable drawable) {
	if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
		view.setBackground(drawable);
	} else {
		view.setBackgroundDrawable(drawable);
	}
}








 类似资料: