0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2024-11-30 23:23:01 +00:00

Checkin: Ensure we recheckin regularly

This commit is contained in:
Marvin W 2020-10-14 10:57:55 +02:00
parent 31a8a3308b
commit e20a6c3a3c
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
3 changed files with 22 additions and 3 deletions

View file

@ -196,8 +196,15 @@
<receiver android:name="org.microg.gms.checkin.TriggerReceiver">
<intent-filter>
<action android:name="android.server.checkin.CHECKIN" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.AIRPLANE_MODE" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED" />
<action android:name="android.server.checkin.CHECKIN" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />

View file

@ -18,7 +18,10 @@ package org.microg.gms.checkin;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
@ -36,6 +39,8 @@ import org.microg.gms.people.PeopleManager;
public class CheckinService extends IntentService {
private static final String TAG = "GmsCheckinSvc";
public static final long REGULAR_CHECKIN_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
public static final long BACKUP_CHECKIN_DELAY = 3 * 60 * 60 * 1000; // 3 hours
public static final String BIND_ACTION = "com.google.android.gms.checkin.BIND_TO_SERVICE";
public static final String EXTRA_FORCE_CHECKIN = "force";
public static final String EXTRA_CALLBACK_INTENT = "callback";
@ -74,6 +79,7 @@ public class CheckinService extends IntentService {
Log.w(TAG, e);
} finally {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
schedule(this);
stopSelf();
}
}
@ -86,4 +92,10 @@ public class CheckinService extends IntentService {
return super.onBind(intent);
}
}
static void schedule(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(context, TriggerReceiver.class.getName().hashCode(), new Intent(context, TriggerReceiver.class), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC, Math.max(LastCheckinInfo.read(context).lastCheckin + REGULAR_CHECKIN_INTERVAL, System.currentTimeMillis() + BACKUP_CHECKIN_DELAY), pendingIntent);
}
}

View file

@ -20,7 +20,6 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import android.util.Log;
import androidx.legacy.content.WakefulBroadcastReceiver;
@ -28,10 +27,10 @@ import androidx.legacy.content.WakefulBroadcastReceiver;
import org.microg.gms.common.ForegroundServiceContext;
import static org.microg.gms.checkin.CheckinService.EXTRA_FORCE_CHECKIN;
import static org.microg.gms.checkin.CheckinService.REGULAR_CHECKIN_INTERVAL;
public class TriggerReceiver extends WakefulBroadcastReceiver {
private static final String TAG = "GmsCheckinTrigger";
private static final long REGULAR_CHECKIN_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
@Override
public void onReceive(Context context, Intent intent) {
@ -42,6 +41,7 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
if (CheckinPrefs.get(context).isEnabled() || force) {
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()) &&
LastCheckinInfo.read(context).lastCheckin > System.currentTimeMillis() - REGULAR_CHECKIN_INTERVAL) {
CheckinService.schedule(context);
return;
}