Change summary
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 18
src/main/java/eu/siacs/conversations/utils/Compatibility.java | 2
src/playstore/java/eu/siacs/conversations/services/InstanceIdService.java | 16
src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java | 14
4 files changed, 32 insertions(+), 18 deletions(-)
Detailed changes
@@ -864,15 +864,19 @@ public class XmppConnectionService extends Service {
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public boolean isInteractive() {
- final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ 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();
+ 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() {
@@ -54,7 +54,7 @@ public class Compatibility {
final PackageManager packageManager = context.getPackageManager();
final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
return applicationInfo == null || applicationInfo.targetSdkVersion >= 26;
- } catch (PackageManager.NameNotFoundException e) {
+ } catch (PackageManager.NameNotFoundException | RuntimeException e) {
return true; //when in doubt…
}
}
@@ -2,9 +2,11 @@ package eu.siacs.conversations.services;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
+import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceIdService;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.Compatibility;
public class InstanceIdService extends FirebaseInstanceIdService {
@@ -13,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");
}
}
}
@@ -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");
}
}