From 508e1ac1bd22d16503a1d05150317d783ac83c0b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 9 Aug 2022 19:42:57 +0200 Subject: [PATCH] add immutable flag to pending alarm intents --- .../conversations/http/HttpUploadConnection.java | 1 + .../services/XmppConnectionService.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index f1bae9956..20db7bfbd 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -144,6 +144,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan @Override public void onFailure(@NotNull final Throwable throwable) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to request slot", throwable); + // TODO consider fall back to jingle in 1-on-1 chats with exactly one online presence fail(throwable.getMessage()); } }, MoreExecutors.directExecutor()); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b15d9bccb..43d0e769f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.services; +import static eu.siacs.conversations.utils.Compatibility.s; + import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; @@ -1384,8 +1386,9 @@ public class XmppConnectionService extends Service { final Intent intent = new Intent(this, EventReceiver.class); intent.setAction(ACTION_POST_CONNECTIVITY_CHANGE); try { - //TODO add immutable flag - final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0); + final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, s() + ? PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT + : PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, pendingIntent); } else { @@ -1397,7 +1400,7 @@ public class XmppConnectionService extends Service { } public void scheduleWakeUpCall(int seconds, int requestCode) { - final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000; + final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000L; final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarmManager == null) { return; @@ -1431,8 +1434,9 @@ public class XmppConnectionService extends Service { final Intent intent = new Intent(this, EventReceiver.class); intent.setAction(ACTION_IDLE_PING); try { - //TODO add immutable flag - final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); + final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, s() + ? PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT + : PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, timeToWake, pendingIntent); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "unable to schedule alarm for idle ping", e);