apsun / NekoSMS

A pattern-based text message blocker for Android.
GNU General Public License v3.0
417 stars 44 forks source link

[Bug] Crashed when restoring the blocked SMS #76

Closed entr0pia closed 3 years ago

entr0pia commented 3 years ago

When restoring the blocked SMS, NekoSMS would be crashed. The crash log is shown as follow:

AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.crossbowffs.nekosms, PID: 22338
AndroidRuntime: java.lang.ExceptionInInitializerError
AndroidRuntime:     at androidx.core.app.AppOpsManagerCompat.writeMessage(AppOpsManagerCompat.java:1)
AndroidRuntime:     at com.crossbowffs.nekosms.app.BlockedMessagesFragment.restoreSms(BlockedMessagesFragment.java:10)
AndroidRuntime:     at com.crossbowffs.nekosms.app.BlockedMessagesFragment$3.onClick(BlockedMessagesFragment.java:2)
AndroidRuntime:     at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:3)
AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:106)
AndroidRuntime:     at android.os.Looper.loop(Looper.java:368)
AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:7710)
AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
AndroidRuntime:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
AndroidRuntime: Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: android.app.AppOpsManager.noteOpNoThrow [int, int, class java.lang.String]
AndroidRuntime:     at androidx.core.app.AppOpsManagerCompat.getDeclaredMethod(AppOpsManagerCompat.java:3)
AndroidRuntime:     at com.crossbowffs.nekosms.utils.AppOpsUtils.<clinit>(AppOpsUtils.java:3)
AndroidRuntime:     ... 10 more
AndroidRuntime: Caused by: java.lang.NoSuchMethodException: android.app.AppOpsManager.noteOpNoThrow [int, int, class java.lang.String]
AndroidRuntime:     at java.lang.Class.getMethod(Class.java:2072)
AndroidRuntime:     at java.lang.Class.getDeclaredMethod(Class.java:2050)
AndroidRuntime:     at androidx.core.app.AppOpsManagerCompat.getDeclaredMethod(AppOpsManagerCompat.java:1)
AndroidRuntime:     ... 11 more

The method, noteOpNoThrow(java.lang.String, int, java.lang.String), was deprecated in API level 30, and use noteOpNoThrow(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String) instead.

apsun commented 3 years ago

Hmm, I think this is more due to the addition of @UnsupportedAppUsage on the API. In any case I don't know why we even call this since it's running in the app context anyways, I think it should be safe to just get rid of it altogether.

entr0pia commented 3 years ago

Fortunately, I found that NekoSMS does not require SMS permissions and it can also work.

image image

silverzhaojr commented 3 years ago

I meet the same issue on Andorid 11. I saw there's a PR to fix it, can I know when the fix will be merged? Thanks!

apsun commented 3 years ago

Depends on when the issues with the PR are addressed ;-)

I can also take a stab at it if @entr0pia wants to drop it

entr0pia commented 3 years ago

Depends on when the issues with the PR are addressed ;-)

I can also take a stab at it if @entr0pia wants to drop it

If you have your own solution, you can decline it.

apsun commented 3 years ago

Fixed in a6dadca7315dc837a869a2885760356aef9500ed