Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit e20a6c3a authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Checkin: Ensure we recheckin regularly

parent 31a8a330
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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" />
+12 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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;
                }