0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2024-12-05 01:07:27 +00:00

When check-in fails due to missing internet access, try again as soon as access is restored

This commit is contained in:
Torsten Grote 2021-06-03 15:26:28 -03:00 committed by Marvin W
parent 1367649a18
commit f806e1bcdb

View file

@ -16,16 +16,21 @@
package org.microg.gms.checkin;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.util.Log;
import androidx.legacy.content.WakefulBroadcastReceiver;
import org.microg.gms.common.ForegroundServiceContext;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.os.Build.VERSION.SDK_INT;
import static org.microg.gms.checkin.CheckinService.EXTRA_FORCE_CHECKIN;
import static org.microg.gms.checkin.CheckinService.REGULAR_CHECKIN_INTERVAL;
@ -50,6 +55,14 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
Intent subIntent = new Intent(context, CheckinService.class);
subIntent.putExtra(EXTRA_FORCE_CHECKIN, force);
startWakefulService(new ForegroundServiceContext(context), subIntent);
} else if (SDK_INT >= 23) {
// no network, register a network callback to retry when we have internet
NetworkRequest networkRequest = new NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_INTERNET)
.build();
Intent i = new Intent(context, TriggerReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, i, FLAG_UPDATE_CURRENT);
cm.registerNetworkCallback(networkRequest, pendingIntent);
}
} else {
Log.d(TAG, "Ignoring " + intent + ": checkin is disabled");