wasdennnoch / AndroidN-ify

[Discontinued] An Xposed module to use features introduced in Android N on your LP+ Device
265 stars 93 forks source link

Crash with Notification.Builder #1307

Closed mice777 closed 7 years ago

mice777 commented 7 years ago

Description It crashes ugly on Android 6 when this construct is used. Notification.Builder is not final, so it's valid for app to inherit from it.

   private static class NotificationBuilder extends Notification.Builder{
      NotificationBuilder(Context ctx){
         super(ctx);
      }
   }

   void test(){
      Notification.Builder nb = new NotificationBuilder(this);
      nb.setSmallIcon(R.drawable.icon);
      NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
      nm.notify(1, nb.build());
   }

Module version (build version) 0.2.0 (5)

Xposed log / logcat

java.lang.NoSuchMethodError: com.xxx.test.App$NotificationBuilder#isLegacy()#bestmatch at de.robv.android.xposed.XposedHelpers.findMethodBestMatch(XposedHelpers.java:440) at de.robv.android.xposed.XposedHelpers.findMethodBestMatch(XposedHelpers.java:453) at de.robv.android.xposed.XposedHelpers.callMethod(XposedHelpers.java:1217) at tk.wasdennnoch.androidn_ify.notifications.NotificationsHooks$5.replaceHookedMethod(NotificationsHooks.java:251) at de.robv.android.xposed.XC_MethodReplacement.beforeHookedMethod(XC_MethodReplacement.java:29) at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:314) at android.app.Notification$Builder.processSmallIconAsLarge() at android.app.Notification$Builder.applyStandardTemplate(Notification.java:2979) at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334) at android.app.Notification$Builder.applyStandardTemplate() at android.app.Notification$Builder.applyStandardTemplate(Notification.java:2955) at android.app.Notification$Builder.makeContentView(Notification.java:3151) at android.app.Notification$Builder.buildUnstyled(Notification.java:3326) at android.app.Notification$Builder.build(Notification.java:3661) at com.xxx.test.App.test(App.java:20)

wasdennnoch commented 7 years ago

Fixed with 89d77ffe91084e749bbcf8646351f814c9fdda6d. Install a snapshot build, 0.2.0 is outdated.

mice777 commented 7 years ago

Why don't you better fix it this way:

legacy = (boolean)XposedHelpers.findMethodBestMatch(Notification.Builder.class, "isLegacy").invoke(builder);

You know there is still method isLegacy on inherited class, you just have to lookup it on correct class.