Skip to content
Permalink
Browse files

Fix Compatibility with Xposed 2.6 (Reflection)

This is due to a new change which requires all fields to have
“setAccessible(true)”.

Instead, I used the XposedHelpers method which already has that called
(also a shorter code)
  • Loading branch information...
zst123 committed May 17, 2014
1 parent 7b5018b commit 20a0293d42fb9dcdd310d248ae86d88092336616
@@ -3,8 +3,8 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="lib" path="/XposedLibrary/XposedBridgeApi.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="/XposedLibrary/XposedBridgeApi-52.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -16,8 +16,6 @@

package com.zst.xposed.xuimod;

import java.lang.reflect.Field;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
@@ -242,37 +240,6 @@ public void run() {
* the hooks might retrieve the wrong value. */
}

/* Helper Methods */
public static Object getReflection(Object itemToGetObject, String objectName) {
try {
Class<?> clazz = itemToGetObject.getClass();
Field field;
field = clazz.getDeclaredField(objectName);
field.setAccessible(true);
return field.get(itemToGetObject);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/*
* @param return true when successful
*/
public static boolean setReflection(Object itemToGetObject, String objectName, Object newValue) {
try {
Class<?> clazz = itemToGetObject.getClass();
Field field;
field = clazz.getDeclaredField(objectName);
field.setAccessible(true);
field.set(itemToGetObject, newValue);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

public static int parseColorFromString(String str, String defColorWithoutSymbols) {
str.replaceAll("\\s+", "");
// Remove all spaces
@@ -178,11 +178,9 @@ private static void hookOldApplyAnimationLocked(LoadPackageParam o, final Class<
WindowManager.LayoutParams.class, int.class, boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
boolean displayFrozen = (Boolean) cls.getDeclaredField("mDisplayFrozen")
.get(param.thisObject);
boolean displayEnabled = (Boolean) cls.getDeclaredField("mDisplayEnabled")
.get(param.thisObject);
Object policy = cls.getDeclaredField("mPolicy").get(param.thisObject);
boolean displayFrozen = XposedHelpers.getBooleanField(param.thisObject, "mDisplayFrozen");
boolean displayEnabled = XposedHelpers.getBooleanField(param.thisObject, "mDisplayEnabled");
Object policy = XposedHelpers.getObjectField(param.thisObject, "mPolicy");
boolean screenOn = (Boolean) XposedHelpers.callMethod(policy, "isScreenOnFully");

if ((!displayFrozen && displayEnabled && screenOn) == false) {
@@ -195,8 +193,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
final boolean enter = (Boolean) param.args[3];

if ((Build.VERSION.SDK_INT <= 15)) { // ICS
String nextAppTransitionPackage = (String) Common.getReflection(
param.thisObject, "mNextAppTransitionPackage");
String nextAppTransitionPackage = (String) XposedHelpers
.getObjectField(param.thisObject, "mNextAppTransitionPackage");
if (nextAppTransitionPackage == null) {
Animation anim = retrieveAnimation(lp, transit, enter);
if (anim != null) {
@@ -205,15 +203,14 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
} else { // JB 4.1/4.2
int type = (Integer) Common.getReflection(param.thisObject,
int type = XposedHelpers.getIntField(param.thisObject,
"mNextAppTransitionType");
if (type == AppTransitionConstants.NEXT_TRANSIT_TYPE_CUSTOM ||
type == AppTransitionConstants.NEXT_TRANSIT_TYPE_SCALE_UP ||
type == AppTransitionConstants.NEXT_TRANSIT_TYPE_SCALE_UP)
return;
Animation result = retrieveAnimation(lp, transit, enter);
Object appAnimator = window_token.getClass().getDeclaredField("mAppAnimator")
.get(window_token);
Object appAnimator = XposedHelpers.getObjectField(window_token, "mAppAnimator");
if (result != null) {
XposedHelpers.callMethod(appAnimator, "setAnimation",
applyDuration(result), false);
@@ -230,11 +227,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
animator = param.args[0];
} else { // JB
final Object window_token = param.args[0];
animator = window_token.getClass().getDeclaredField("mAppAnimator")
.get(window_token);
animator = XposedHelpers.getObjectField(window_token, "mAppAnimator");
}
Animation anim = (Animation) animator.getClass().getDeclaredField("animation")
.get(animator);
Animation anim = (Animation) XposedHelpers.getObjectField(animator, "animation");
if (anim != null) {
if ((Build.VERSION.SDK_INT <= 15)) {
XposedHelpers.callMethod(animator, "setAnimation", applyDuration(anim));
@@ -255,7 +250,7 @@ private static void hookNewLoadAnimation(LoadPackageParam o, Class<?> cls) {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
mIsResId = false;

int type = (Integer) Common.getReflection (param.thisObject,
int type = XposedHelpers.getIntField(param.thisObject,
"mNextAppTransitionType");
if (type == AppTransitionConstants.NEXT_TRANSIT_TYPE_CUSTOM ||
type == AppTransitionConstants.NEXT_TRANSIT_TYPE_SCALE_UP ||
@@ -118,8 +118,7 @@ private static void hookNavigationBar(final LoadPackageParam lpp) {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
final LinearLayout thizz = (LinearLayout) param.thisObject;
final View[] rotated_views = (View[]) param.thisObject.getClass()
.getDeclaredField("mRotatedViews").get(thizz);
final View[] rotated_views = (View[]) XposedHelpers.getObjectField(thizz, "mRotatedViews");

final FrameLayout portrait = (FrameLayout) rotated_views[Surface.ROTATION_0];
final FrameLayout landscape = (FrameLayout) rotated_views[Surface.ROTATION_90];
@@ -31,6 +31,7 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class ClassicRecentsMod {
@@ -61,7 +62,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!pref.getBoolean(Common.KEY_CLASSIC_RECENTS, Common.DEFAULT_CLASSIC_RECENTS)) {
return;
}
final Context ctx = (Context) Common.getReflection(param.thisObject, "mContext");
final Context ctx = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
ctx.sendBroadcast(new Intent(ACTION_SHOW_RECENT_APP_DIALOG));
param.setResult(null);
}
@@ -77,6 +78,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
final Context context = (Context) param.args[0];
final Method showDialog = param.thisObject.getClass().getDeclaredMethod(
"showOrHideRecentAppsDialog", int.class);
showDialog.setAccessible(true);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -10,6 +10,7 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class EdgeEffectMod {
@@ -30,15 +31,15 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
Common.DEFAULT_SCROLLING_GLOW_ENABLE))
return;

final Drawable edge = (Drawable) Common.getReflection(param.thisObject, "mEdge");
final Drawable glow = (Drawable) Common.getReflection(param.thisObject, "mGlow");
final Drawable edge = (Drawable) XposedHelpers.getObjectField(param.thisObject, "mEdge");
final Drawable glow = (Drawable) XposedHelpers.getObjectField(param.thisObject, "mGlow");

if (mPref.getBoolean(Common.KEY_SCROLLING_GLOW_DISABLE,
Common.DEFAULT_SCROLLING_GLOW_DISABLE)) {
//Disable glow by setting transparent color
final Drawable transparent = new ColorDrawable(Color.TRANSPARENT);
Common.setReflection(param.thisObject, "mEdge", transparent);
Common.setReflection(param.thisObject, "mGlow", transparent);
XposedHelpers.setObjectField(param.thisObject, "mEdge", transparent);
XposedHelpers.setObjectField(param.thisObject, "mGlow", transparent);
return;
}

@@ -58,8 +59,8 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
* Also, "drawable.setAlpha" has no effect on the glow, it's probably the
* canvas drawing (??) */

Common.setReflection(param.thisObject, "mEdge", edge);
Common.setReflection(param.thisObject, "mGlow", glow);
XposedHelpers.setObjectField(param.thisObject, "mEdge", edge);
XposedHelpers.setObjectField(param.thisObject, "mGlow", glow);
}
});
}
@@ -27,6 +27,7 @@
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class VolumePanelMod {
@@ -54,7 +55,7 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
Handler h = (Handler) param.thisObject;

try {
Dialog mDialog = (Dialog) Common.getReflection(h, "mDialog");
Dialog mDialog = (Dialog) XposedHelpers.getObjectField(h, "mDialog");
Window window = mDialog.getWindow();
/* Set Transparency */
WindowManager.LayoutParams lp = window.getAttributes();

0 comments on commit 20a0293

Please sign in to comment.
You can’t perform that action at this time.