mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Only perform subscriber id keep-alive when the user foregrounds the app.
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
package org.thoughtcrime.securesms.service;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.SubscriptionKeepAliveJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Manages the scheduling of jobs for keeping a subscription id alive.
|
||||
*/
|
||||
public class SubscriberIdKeepAliveListener extends PersistentAlarmManagerListener {
|
||||
|
||||
private static final long INTERVAL = TimeUnit.DAYS.toMillis(3);
|
||||
|
||||
@Override
|
||||
protected long getNextScheduledExecutionTime(Context context) {
|
||||
return SignalStore.donationsValues().getLastKeepAliveLaunchTime() + INTERVAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long onAlarm(Context context, long scheduledTime) {
|
||||
if (SignalStore.donationsValues().getSubscriber() != null) {
|
||||
ApplicationDependencies.getJobManager().add(new SubscriptionKeepAliveJob());
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
SignalStore.donationsValues().setLastKeepAliveLaunchTime(now);
|
||||
|
||||
return now + INTERVAL;
|
||||
}
|
||||
|
||||
public static void schedule(Context context) {
|
||||
new SubscriberIdKeepAliveListener().onReceive(context, new Intent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user