diff options
4 files changed, 31 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 9fcb83aa5..7c5d2b64d 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -957,15 +957,18 @@ public class XmppConnectionService extends Service { @SuppressLint("NewApi") @SuppressWarnings("deprecation") public boolean isInteractive() { - final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); - - final boolean isScreenOn; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - isScreenOn = pm.isScreenOn(); - } else { - isScreenOn = pm.isInteractive(); + try { + final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + final boolean isScreenOn; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + isScreenOn = pm.isScreenOn(); + } else { + isScreenOn = pm.isInteractive(); + } + return isScreenOn; + } catch (RuntimeException e) { + return false; } - return isScreenOn; } private boolean isPhoneSilenced() { diff --git a/src/main/java/de/pixart/messenger/utils/Compatibility.java b/src/main/java/de/pixart/messenger/utils/Compatibility.java index f178f17c7..38f9db378 100644 --- a/src/main/java/de/pixart/messenger/utils/Compatibility.java +++ b/src/main/java/de/pixart/messenger/utils/Compatibility.java @@ -56,6 +56,8 @@ public class Compatibility { return applicationInfo == null || applicationInfo.targetSdkVersion >= 26; } catch (PackageManager.NameNotFoundException e) { return true; //when in doubt… + } catch (RuntimeException e) { + return true; //when in doubt… } } diff --git a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java index 465f974e6..9a3309be4 100644 --- a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java +++ b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java @@ -15,11 +15,15 @@ public class InstanceIdService extends FirebaseInstanceIdService { public void onTokenRefresh() { final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH); - if (Compatibility.runsAndTargetsTwentySix(this)) { - intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); - ContextCompat.startForegroundService(this, intent); - } else { - startService(intent); + try { + if (Compatibility.runsAndTargetsTwentySix(this)) { + intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); + ContextCompat.startForegroundService(this, intent); + } else { + startService(intent); + } + } catch (IllegalStateException e) { + Log.e(Config.LOGTAG, "InstanceIdService is not allowed to start service"); } } }
\ No newline at end of file diff --git a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java index 88b60e348..f07167f8d 100644 --- a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java +++ b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java @@ -24,11 +24,15 @@ public class PushMessageReceiver extends FirebaseMessagingService { final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED); intent.putExtra("account", data.get("account")); - if (Compatibility.runsAndTargetsTwentySix(this)) { - intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); - ContextCompat.startForegroundService(this, intent); - } else { - startService(intent); + try { + if (Compatibility.runsAndTargetsTwentySix(this)) { + intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); + ContextCompat.startForegroundService(this, intent); + } else { + startService(intent); + } + } catch (IllegalStateException e) { + Log.e(Config.LOGTAG, "PushMessageReceiver is not allowed to start service"); } } }
\ No newline at end of file |