android: Make sure we actually have a tile when updating it
authorTobias Brunner <tobias@strongswan.org>
Fri, 6 Jul 2018 14:01:34 +0000 (16:01 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 17 Oct 2018 09:56:30 +0000 (11:56 +0200)
Not sure when this happens exactly, in particular because the reported
stack traces look like this

java.lang.NullPointerException:
  at org.strongswan.android.ui.VpnTileService.updateTile (VpnTileService.java:220)
  at org.strongswan.android.ui.VpnTileService.onStartListening (VpnTileService.java:97)
  at android.service.quicksettings.TileService$H.handleMessage (TileService.java:407)

which violates the API documentation for getQsTile(), which states:

  This tile is only valid for updates between onStartListening() and
  onStopListening().

But apparently that's not always the case. There have been two reports
of such a crash, both on Android 8.0 and on Xiaomi Mi 5/6 devices, so
maybe it's a bug in that particular image.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnTileService.java

index 6b5cca0..623a80f 100644 (file)
@@ -204,6 +204,10 @@ public class VpnTileService extends TileService implements VpnStateService.VpnSt
                }
 
                Tile tile = getQsTile();
+               if (tile == null)
+               {
+                       return;
+               }
 
                if (error != VpnStateService.ErrorState.NO_ERROR)
                {