RikkaApps / WADB

A simple switch for adb (Android Debug Bridge) over network.
https://play.google.com/store/apps/details?id=moe.haruue.wadb
Apache License 2.0
578 stars 77 forks source link

Crash with NPE #24

Closed yujincheng08 closed 2 years ago

yujincheng08 commented 2 years ago

MIUI Android 12

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.service.quicksettings.Tile.setState(int)' on a null object reference
        at moe.haruue.wadb.go.a(WadbTileService.java:2)
        at moe.haruue.wadb.go.onStartListening(WadbTileService.java:4)
        at android.service.quicksettings.TileService$H.handleMessage(TileService.java:446)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at android.app.ActivityThread.main(ActivityThread.java:8261)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
haruue commented 2 years ago

Retraced stacktrace

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.service.quicksettings.Tile.setState(int)' on a null object reference
        at moe.haruue.wadb.service.WadbTileService.showStateOff(WadbTileService.java:106)
        at moe.haruue.wadb.service.WadbTileService.onStartListening(WadbTileService.java:55)
        at android.service.quicksettings.TileService$H.handleMessage(TileService.java:446)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at android.app.ActivityThread.main(ActivityThread.java:8261)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

We got NPE here https://github.com/RikkaApps/WADB/blob/b5b65a7fa69862c218d885439b9471fd9c2ed8eb/app/src/main/java/moe/haruue/wadb/service/WadbTileService.java#L100-L106

According to the [API reference](https://developer.android.com/reference/android/service/quicksettings/TileService#getQsTile()):

This tile may be used to get or set the current state for this tile. This tile is only valid for updates between onStartListening() and onStopListening().

And we got tile == null in the onStartListening() callback? So maybe we should fix this by just checking the tile != null before calling Tile.setState().