From c0230afdd3b5de4257706ecb533e56eccc02cc93 Mon Sep 17 00:00:00 2001 From: "J. Yi" <93548144+jyyi1@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:50:53 -0500 Subject: [PATCH] fix: crash in work profile due to exceptions thrown by TileService (#498) I fixed a crash issue caused by: [`TileService.requestListeningState`](https://developer.android.com/reference/android/service/quicksettings/TileService#requestListeningState(android.content.Context,%20android.content.ComponentName)) throwing exceptions if the user of the context is not the current user (might be a work profile user). This is the new behavior since API level 33, so previously this issue is not found. --- .../src/main/java/app/intra/sys/IntraVpnService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Android/app/src/main/java/app/intra/sys/IntraVpnService.java b/Android/app/src/main/java/app/intra/sys/IntraVpnService.java index b7ebf0c9..976165f6 100644 --- a/Android/app/src/main/java/app/intra/sys/IntraVpnService.java +++ b/Android/app/src/main/java/app/intra/sys/IntraVpnService.java @@ -336,8 +336,14 @@ private void stopVpnAdapter() { private void updateQuickSettingsTile() { if (VERSION.SDK_INT >= VERSION_CODES.N) { - TileService.requestListeningState(this, - new ComponentName(this, IntraTileService.class)); + try { + TileService.requestListeningState(this, + new ComponentName(this, IntraTileService.class)); + } catch (SecurityException ignored) { + } catch (IllegalArgumentException ignored) { + // Starting from API level 33, TileService will throw exceptions from apps in Work Profile + // See: https://developer.android.com/reference/android/service/quicksettings/TileService + } } }