rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.1k forks source link

Zenfone 2 (Android 5.0.0.r7): ResourcesKey incompatibility #42

Open sorgelig opened 9 years ago

sorgelig commented 9 years ago

Constructor requested in XposedBridge is not compatible with one used in Zenfone 2 (model ZE551ML). Here is framework.jar (including de-compiled version): http://d-h.st/hnUY

according to framework, parameters look like this:

# direct methods
.method public constructor <init>(Ljava/lang/String;ILandroid/content/res/Configuration;FLandroid/os/IBinder;Z)V
    .locals 4
    .param p1, "resDir"    # Ljava/lang/String;
    .param p2, "displayId"    # I
    .param p3, "overrideConfiguration"    # Landroid/content/res/Configuration;
    .param p4, "scale"    # F
    .param p5, "token"    # Landroid/os/IBinder;
    .param p6, "isThemeable"    # Z

but after logging, i've found that XposedHelpers.findConstructorBestMatch finds constructor with following parameters:

(java.lang.String,int,android.content.res.Configuration,float,android.os.IBinder,boolean,android.content.res.ThemePack)

one more parameter added to those i've found in framework.

Finally, i've fixed issue by this code in AndroidAppHelper class (i've removed other calls for debugging purpose):

    /* For SDK 19+ */
    private static Object createResourcesKey(String resDir, int displayId, Configuration overrideConfiguration, float scale, IBinder token, boolean isThemeable) {
        try {
            return newInstance(CLASS_RESOURCES_KEY, resDir, displayId, overrideConfiguration, scale, token, isThemeable, null);
        } catch (Throwable t) {
            XposedBridge.log(t);
            return null;
        }
    }
sorgelig commented 9 years ago

ASUS again updated this function!

now correct function is:

    /* For SDK 19+ */
    private static Object createResourcesKey(String resDir, int displayId, Configuration overrideConfiguration, float scale, IBinder token, boolean isThemeable) {
        try {
            return newInstance(CLASS_RESOURCES_KEY, resDir, displayId, overrideConfiguration, scale, token, isThemeable);
        } catch (Throwable t) {
            XposedBridge.log(t);
            return null;
        }
    }
sorgelig commented 9 years ago

@rovo89, may i ask you to apply following patch to make it compatible with Zenfone 2? Currently, i have to re-compile every release with this patch:

diff --git a/src/android/app/AndroidAppHelper.java b/src/android/app/AndroidAppHelper.java
index 3467b42..5f85d7b 100644
--- a/src/android/app/AndroidAppHelper.java
+++ b/src/android/app/AndroidAppHelper.java
@@ -94,6 +94,13 @@ public class AndroidAppHelper {
            else
                return newInstance(CLASS_RESOURCES_KEY, resDir, displayId, overrideConfiguration, scale, token);
        } catch (Throwable t) {
+           try {
+               // Zenfone 2 ZE551ML version.
+               return newInstance(CLASS_RESOURCES_KEY, resDir, displayId, overrideConfiguration, scale, token, isThemeable);
+           }
+           catch(Throwable t2) {
+               XposedBridge.log(t2);
+           }
            XposedBridge.log(t);
            return null;
        } 
rovo89 commented 9 years ago

Sorry, I need to look into this a bit deeper to avoid that other ROMs are affected...

You mentioned two variants above, are both needed? Also, is there something in the ResourcesKey class (e.g. additional member that's not in AOSP/CM) to identify which variant is needed without trial and error?

sorgelig commented 9 years ago

Only last patch is needed. At least all new releases use this variant. Sorry for late reply. I was busy by real life :)

panpietrek commented 9 years ago

Hey @rovo89 Do you have any idea when will this patch be included in official xposed builds? Then one I'm using right now is an unofficial build based on v65 and doesn't play nice with latest ROM for Zenfone 5. Version 75 installs and seems to work just fine, the only trouble is that it flods the log with those findConstructorBestMatch errors sorgelig mentioned above.