Commit dac4d861 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch 'microg-upstream' into 'master'

Fix Device registration

See merge request e/apps/GmsCore!36
parents 0be19728 346d0617
Pipeline #152335 passed with stage
in 9 minutes
......@@ -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");
......
......@@ -25,6 +25,7 @@ import android.util.Log;
import androidx.legacy.content.WakefulBroadcastReceiver;
import org.microg.gms.checkin.CheckinPrefs;
import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.common.ForegroundServiceContext;
......@@ -67,6 +68,14 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
if (LastCheckinInfo.read(context).getAndroidId() == 0) {
Log.d(TAG, "Ignoring " + intent + ": need to checkin first.");
if (CheckinPrefs.isEnabled(context)) {
// Do a check-in if we are not actually checked in,
// but should be, e.g. cleared app data
Log.d(TAG, "Requesting check-in...");
String action = "android.server.checkin.CHECKIN";
Class<?> clazz = org.microg.gms.checkin.TriggerReceiver.class;
context.sendBroadcast(new Intent(action, null, context, clazz));
}
return;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment