aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/Config.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java32
2 files changed, 31 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java
index 6bbf2b1d0..b2581f8dc 100644
--- a/src/main/java/de/pixart/messenger/Config.java
+++ b/src/main/java/de/pixart/messenger/Config.java
@@ -18,6 +18,7 @@ public final class Config {
private static final int OMEMO = 8;
private static final int ENCRYPTION_MASK = UNENCRYPTED | OPENPGP | OTR | OMEMO;
+
public static boolean supportUnencrypted() {
return (ENCRYPTION_MASK & UNENCRYPTED) != 0;
}
@@ -75,6 +76,7 @@ public final class Config {
public static final int PING_TIMEOUT = 15;
public static final int SOCKET_TIMEOUT = 15;
public static final int CONNECT_TIMEOUT = 60;
+ public static final int POST_CONNECTIVITY_CHANGE_PING_INTERVAL = 30;
public static final int CONNECT_DISCO_TIMEOUT = 30;
public static final int MINI_GRACE_PERIOD = 750;
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index ec3256b46..12d163203 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -177,6 +177,7 @@ public class XmppConnectionService extends Service {
public static final String ACTION_IDLE_PING = "idle_ping";
public static final String ACTION_FCM_TOKEN_REFRESH = "fcm_token_refresh";
public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received";
+ private static final String ACTION_POST_CONNECTIVITY_CHANGE = "de.pixart.messenger.POST_CONNECTIVITY_CHANGE";
public static final String FDroid = "org.fdroid.fdroid";
public static final String PlayStore = "com.android.vending";
private static final String SETTING_LAST_ACTIVITY_TS = "last_activity_timestamp";
@@ -594,8 +595,13 @@ public class XmppConnectionService extends Service {
final String uuid = intent.getStringExtra("uuid");
switch (action) {
case ConnectivityManager.CONNECTIVITY_ACTION:
- if (hasInternetConnection() && Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
- resetAllAttemptCounts(true, false);
+ if (hasInternetConnection()) {
+ if (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL > 0) {
+ schedulePostConnectivityChange();
+ }
+ if (Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
+ resetAllAttemptCounts(true, false);
+ }
}
break;
case Intent.ACTION_SHUTDOWN:
@@ -708,7 +714,7 @@ public class XmppConnectionService extends Service {
}
synchronized (this) {
WakeLockHelper.acquire(wakeLock);
- boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action);
+ boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action) || (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL > 0 && ACTION_POST_CONNECTIVITY_CHANGE.equals(action));
HashSet<Account> pingCandidates = new HashSet<>();
for (Account account : accounts) {
pingNow |= processAccountState(account,
@@ -1341,6 +1347,26 @@ public class XmppConnectionService extends Service {
}
}
+ private void schedulePostConnectivityChange() {
+ final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+ if (alarmManager == null) {
+ return;
+ }
+ final long triggerAtMillis = SystemClock.elapsedRealtime() + (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL * 1000);
+ final Intent intent = new Intent(this, EventReceiver.class);
+ intent.setAction(ACTION_POST_CONNECTIVITY_CHANGE);
+ try {
+ final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, pendingIntent);
+ } else {
+ alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, pendingIntent);
+ }
+ } catch (RuntimeException e) {
+ Log.e(Config.LOGTAG, "unable to schedule alarm for post connectivity change", e);
+ }
+ }
+
public void scheduleWakeUpCall(int seconds, int requestCode) {
final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000;
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);