mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-11-19 02:29:25 +01:00
Checkin before registering for push
This commit is contained in:
parent
dae13b16bb
commit
16142899fc
2
extern/UnifiedNlp
vendored
2
extern/UnifiedNlp
vendored
@ -1 +1 @@
|
||||
Subproject commit bcf1cff35ef8c111c8c0570ccb803ec3edd44eed
|
||||
Subproject commit 6942a05db781aa1f2e71eadbe4cbb07b6c4f8a5c
|
@ -34,6 +34,8 @@ import org.microg.gms.people.PeopleManager;
|
||||
public class CheckinService extends IntentService {
|
||||
private static final String TAG = "GmsCheckinSvc";
|
||||
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";
|
||||
|
||||
private ICheckinService iface = new ICheckinService.Stub() {
|
||||
@Override
|
||||
@ -49,7 +51,7 @@ public class CheckinService extends IntentService {
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
try {
|
||||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra("force", false));
|
||||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
||||
String accountType = getString(R.string.google_account_type);
|
||||
@ -57,6 +59,9 @@ public class CheckinService extends IntentService {
|
||||
PeopleManager.loadUserInfo(this, account);
|
||||
}
|
||||
McsService.scheduleReconnect(this);
|
||||
if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
|
||||
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
|
@ -43,7 +43,7 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
if (networkInfo != null && networkInfo.isConnected() || force) {
|
||||
Intent subIntent = new Intent(context, CheckinService.class);
|
||||
subIntent.putExtra("force", force);
|
||||
subIntent.putExtra(CheckinService.EXTRA_FORCE_CHECKIN, force);
|
||||
startWakefulService(context, subIntent);
|
||||
}
|
||||
} else {
|
||||
|
@ -26,6 +26,7 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.util.Log;
|
||||
|
||||
import org.microg.gms.checkin.CheckinService;
|
||||
import org.microg.gms.checkin.LastCheckinInfo;
|
||||
import org.microg.gms.common.PackageUtils;
|
||||
import org.microg.gms.common.Utils;
|
||||
@ -37,6 +38,7 @@ import static org.microg.gms.gcm.GcmConstants.ACTION_C2DM_REGISTRATION;
|
||||
import static org.microg.gms.gcm.GcmConstants.ACTION_C2DM_UNREGISTER;
|
||||
import static org.microg.gms.gcm.GcmConstants.ERROR_SERVICE_NOT_AVAILABLE;
|
||||
import static org.microg.gms.gcm.GcmConstants.EXTRA_APP;
|
||||
import static org.microg.gms.gcm.GcmConstants.EXTRA_DELETE;
|
||||
import static org.microg.gms.gcm.GcmConstants.EXTRA_ERROR;
|
||||
import static org.microg.gms.gcm.GcmConstants.EXTRA_MESSENGER;
|
||||
import static org.microg.gms.gcm.GcmConstants.EXTRA_REGISTRATION_ID;
|
||||
@ -51,6 +53,8 @@ public class PushRegisterService extends IntentService {
|
||||
private static final String ERROR = "%%ERROR%%";
|
||||
private static final String GCM_REGISTRATION_PREF = "gcm_registrations";
|
||||
|
||||
private static final String EXTRA_SKIP_TRY_CHECKIN = "skip_checkin";
|
||||
|
||||
public PushRegisterService() {
|
||||
super(TAG);
|
||||
setIntentRedelivery(false);
|
||||
@ -63,15 +67,24 @@ public class PushRegisterService extends IntentService {
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
Log.d(TAG, "onHandleIntent: " + intent);
|
||||
try {
|
||||
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
||||
(ACTION_C2DM_REGISTER.equals(intent.getAction()) && "1".equals(intent.getStringExtra("delete")))) {
|
||||
unregister(intent);
|
||||
} else if (ACTION_C2DM_REGISTER.equals(intent.getAction())) {
|
||||
register(intent);
|
||||
if (LastCheckinInfo.read(this).lastCheckin > 0) {
|
||||
try {
|
||||
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
||||
(ACTION_C2DM_REGISTER.equals(intent.getAction()) && "1".equals(intent.getStringExtra(EXTRA_DELETE)))) {
|
||||
unregister(intent);
|
||||
} else if (ACTION_C2DM_REGISTER.equals(intent.getAction())) {
|
||||
register(intent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
} else if (!intent.getBooleanExtra(EXTRA_SKIP_TRY_CHECKIN, false)) {
|
||||
Log.d(TAG, "No checkin yet, trying to checkin");
|
||||
intent.putExtra(EXTRA_SKIP_TRY_CHECKIN, true);
|
||||
Intent subIntent = new Intent(this, CheckinService.class);
|
||||
subIntent.putExtra(CheckinService.EXTRA_FORCE_CHECKIN, true);
|
||||
subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
|
||||
startService(subIntent);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user