From e0c8481d80cadddb0886e87eef424f7bfa988667 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 19 Mar 2024 18:00:12 +0100 Subject: [PATCH] catch exception when checking phone lock state --- .../services/XmppConnectionService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 8dd5f74d8..f2a55b49a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1543,19 +1543,23 @@ public class XmppConnectionService extends Service { } public boolean isScreenLocked() { - final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); - final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); + final KeyguardManager keyguardManager = getSystemService(KeyguardManager.class); + final PowerManager powerManager = getSystemService(PowerManager.class); final boolean locked = keyguardManager != null && keyguardManager.isKeyguardLocked(); - final boolean interactive = powerManager != null && powerManager.isInteractive(); + final boolean interactive; + try { + interactive = powerManager != null && powerManager.isInteractive(); + } catch (final Exception e) { + return false; + } return locked || !interactive; } private boolean isPhoneSilenced() { - final boolean notificationDnd; final NotificationManager notificationManager = getSystemService(NotificationManager.class); final int filter = notificationManager == null ? NotificationManager.INTERRUPTION_FILTER_UNKNOWN : notificationManager.getCurrentInterruptionFilter(); - notificationDnd = filter >= NotificationManager.INTERRUPTION_FILTER_PRIORITY; - final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); + final boolean notificationDnd = filter >= NotificationManager.INTERRUPTION_FILTER_PRIORITY; + final AudioManager audioManager = getSystemService(AudioManager.class); final int ringerMode = audioManager == null ? AudioManager.RINGER_MODE_NORMAL : audioManager.getRingerMode(); try { if (treatVibrateAsSilent()) { @@ -1563,7 +1567,7 @@ public class XmppConnectionService extends Service { } else { return notificationDnd || ringerMode == AudioManager.RINGER_MODE_SILENT; } - } catch (Throwable throwable) { + } catch (final Throwable throwable) { Log.d(Config.LOGTAG, "platform bug in isPhoneSilenced (" + throwable.getMessage() + ")"); return notificationDnd; }