From 2055d51390f952b3197c73b91dc1e3981ce67437 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 5 Jul 2020 21:38:15 +0200 Subject: [PATCH] prevent crash --- .../email/ServiceTileSynchronize.java | 26 ++++++++++++++----- .../eu/faircode/email/ServiceTileUnseen.java | 20 ++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceTileSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceTileSynchronize.java index c74c43abe1..fa85840b31 100644 --- a/app/src/main/java/eu/faircode/email/ServiceTileSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceTileSynchronize.java @@ -49,12 +49,26 @@ public class ServiceTileSynchronize extends TileService implements SharedPrefere Log.i("Update tile synchronize=" + enabled); Tile tile = getQsTile(); - if (tile != null) { - tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(this, - enabled ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24)); - tile.updateTile(); - } + if (tile != null) + try { + tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); + tile.setIcon(Icon.createWithResource(this, + enabled ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24)); + tile.updateTile(); + } catch (Throwable ex) { + Log.w(ex); + /* + java.lang.IllegalArgumentException: Service not registered: com.android.systemui.qs.external.TileLifecycleManager@9b4b3b0 + at android.os.Parcel.createException(Parcel.java:1954) + at android.os.Parcel.readException(Parcel.java:1918) + at android.os.Parcel.readException(Parcel.java:1868) + at android.service.quicksettings.IQSService$Stub$Proxy.updateQsTile(IQSService.java:219) + at android.service.quicksettings.Tile.updateTile(Tile.java:182) + at eu.faircode.email.ServiceTileSynchronize.update(SourceFile:56) + at eu.faircode.email.ServiceTileSynchronize.onStartListening(SourceFile:37) + at android.service.quicksettings.TileService$H.handleMessage(TileService.java:407) + */ + } } public void onStopListening() { diff --git a/app/src/main/java/eu/faircode/email/ServiceTileUnseen.java b/app/src/main/java/eu/faircode/email/ServiceTileUnseen.java index 13c15d36bd..aada31f452 100644 --- a/app/src/main/java/eu/faircode/email/ServiceTileUnseen.java +++ b/app/src/main/java/eu/faircode/email/ServiceTileUnseen.java @@ -56,14 +56,18 @@ public class ServiceTileUnseen extends TileService { Log.i("Update tile unseen=" + unseen); Tile tile = getQsTile(); - if (tile != null) { - tile.setState(unseen > 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(ServiceTileUnseen.this, - unseen > 0 ? R.drawable.baseline_mail_24 : R.drawable.baseline_mail_outline_24)); - tile.setLabel(getResources().getQuantityString( - R.plurals.title_tile_unseen, unseen, unseen)); - tile.updateTile(); - } + if (tile != null) + try { + tile.setState(unseen > 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); + tile.setIcon(Icon.createWithResource(ServiceTileUnseen.this, + unseen > 0 ? R.drawable.baseline_mail_24 : R.drawable.baseline_mail_outline_24)); + tile.setLabel(getResources().getQuantityString( + R.plurals.title_tile_unseen, unseen, unseen)); + tile.updateTile(); + } catch (Throwable ex) { + Log.w(ex); + // See ServiceTileSynchronize + } } }); }