mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-11-10 13:05:05 +00:00
Automatically checkin after 12 hours
This commit is contained in:
parent
40ca65bbf4
commit
1f67d1aad0
8 changed files with 54 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
language: android
|
||||
sudo: false
|
||||
git:
|
||||
submodules: false
|
||||
before_install:
|
||||
|
|
|
@ -135,6 +135,9 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.server.checkin.CHECKIN"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
|
||||
|
||||
|
|
|
@ -22,11 +22,13 @@ import android.app.IntentService;
|
|||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.R;
|
||||
import com.google.android.gms.checkin.internal.ICheckinService;
|
||||
|
||||
import org.microg.gms.gcm.McsService;
|
||||
import org.microg.gms.people.PeopleManager;
|
||||
|
||||
public class CheckinService extends IntentService {
|
||||
|
@ -50,15 +52,18 @@ public class CheckinService extends IntentService {
|
|||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra("force", false));
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
||||
}
|
||||
String accountType = getString(R.string.google_account_type);
|
||||
for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
|
||||
PeopleManager.loadUserInfo(this, account);
|
||||
String accountType = getString(R.string.google_account_type);
|
||||
for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
|
||||
PeopleManager.loadUserInfo(this, account);
|
||||
}
|
||||
McsService.scheduleReconnect(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
} finally {
|
||||
WakefulBroadcastReceiver.completeWakefulIntent(intent);
|
||||
stopSelf();
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,6 +55,6 @@ public class LastCheckinInfo {
|
|||
.putLong(PREF_SECURITY_TOKEN, securityToken)
|
||||
.putString(PREF_VERSION_INFO, versionInfo)
|
||||
.putString(PREF_DEVICE_DATA_VERSION_INFO, deviceDataVersionInfo)
|
||||
.apply();
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,22 +16,38 @@
|
|||
|
||||
package org.microg.gms.checkin;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||
import android.util.Log;
|
||||
|
||||
public class TriggerReceiver extends BroadcastReceiver {
|
||||
public class TriggerReceiver extends WakefulBroadcastReceiver {
|
||||
private static final String TAG = "GmsCheckinTrigger";
|
||||
private static final String PREF_ENABLE_CHECKIN = "checkin_enable_service";
|
||||
private static final long REGULAR_CHECKIN_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Trigger checkin: " + intent);
|
||||
boolean force = "android.provider.Telephony.SECRET_CODE".equals(intent.getAction());
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
Intent subIntent = new Intent(context, CheckinService.class);
|
||||
if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
|
||||
subIntent.putExtra("force", true);
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_ENABLE_CHECKIN, false) || force) {
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()) &&
|
||||
LastCheckinInfo.read(context).lastCheckin > System.currentTimeMillis() - REGULAR_CHECKIN_INTERVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
if (networkInfo != null && networkInfo.isConnected() || force) {
|
||||
Intent subIntent = new Intent(context, CheckinService.class);
|
||||
subIntent.putExtra("force", force);
|
||||
startWakefulService(context, subIntent);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring " + intent + ": checkin is disabled");
|
||||
}
|
||||
context.startService(subIntent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,12 @@ public class McsService extends IntentService implements Handler.Callback {
|
|||
return inputStream != null && inputStream.isAlive() && outputStream != null && outputStream.isAlive();
|
||||
}
|
||||
|
||||
public static void scheduleReconnect(Context context) {
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
|
||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + getCurrentDelay(),
|
||||
PendingIntent.getBroadcast(context, 1, new Intent("org.microg.gms.gcm.RECONNECT", null, context, TriggerReceiver.class), 0));
|
||||
}
|
||||
|
||||
public synchronized static long getCurrentDelay() {
|
||||
long delay = currentDelay == 0 ? 5000 : currentDelay;
|
||||
if (currentDelay < 60000) currentDelay += 5000;
|
||||
|
@ -365,8 +371,7 @@ public class McsService extends IntentService implements Handler.Callback {
|
|||
if (currentDelay == 0) {
|
||||
sendBroadcast(new Intent("org.microg.gms.gcm.RECONNECT"), "org.microg.gms.STATUS_BROADCAST");
|
||||
} else {
|
||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + getCurrentDelay(),
|
||||
PendingIntent.getBroadcast(this, 1, new Intent("org.microg.gms.gcm.RECONNECT", null, this, TriggerReceiver.class), 0));
|
||||
scheduleReconnect(this);
|
||||
}
|
||||
alarmManager.cancel(heartbeatIntent);
|
||||
if (wakeLock != null) {
|
||||
|
|
|
@ -16,17 +16,16 @@
|
|||
|
||||
package org.microg.gms.gcm;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||
import android.util.Log;
|
||||
|
||||
import org.microg.gms.checkin.LastCheckinInfo;
|
||||
|
||||
public class TriggerReceiver extends WakefulBroadcastReceiver {
|
||||
private static final String TAG = "GmsGcmTrigger";
|
||||
private static final String PREF_ENABLE_GCM = "gcm_enable_mcs_service";
|
||||
|
@ -34,13 +33,15 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
boolean force = "android.provider.Telephony.SECRET_CODE".equals(intent.getAction());
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_ENABLE_GCM, false) || force) {
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
|
||||
McsService.resetCurrentDelay();
|
||||
}
|
||||
if (LastCheckinInfo.read(context).androidId == 0) {
|
||||
Log.d(TAG, "Ignoring " + intent + ": need to checkin first.");
|
||||
}
|
||||
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
if (networkInfo != null && networkInfo.isConnected() || force) {
|
||||
|
@ -49,7 +50,7 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
|
|||
} else {
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
|
||||
Log.d(TAG, "Ignoring " + intent + ": service is running. schedule reconnect instead.");
|
||||
scheduleReconnect(context, alarmManager);
|
||||
McsService.scheduleReconnect(context);
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring " + intent + ": service is running. heartbeat instead.");
|
||||
startWakefulService(context, new Intent(McsService.ACTION_HEARTBEAT, null, context, McsService.class));
|
||||
|
@ -57,15 +58,11 @@ public class TriggerReceiver extends WakefulBroadcastReceiver {
|
|||
}
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring " + intent + ": network is offline, scheduling new attempt.");
|
||||
scheduleReconnect(context, alarmManager);
|
||||
McsService.scheduleReconnect(context);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring " + intent + ": gcm is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleReconnect(Context context, AlarmManager alarmManager) {
|
||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + McsService.getCurrentDelay(),
|
||||
PendingIntent.getBroadcast(context, 1, new Intent("org.microg.gms.gcm.RECONNECT", null, context, TriggerReceiver.class), 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@
|
|||
<string name="pref_auth_trust_google_title">Trust Google for app permissions</string>
|
||||
<string name="pref_auth_trust_google_summary">When disabled, the user is asked before an apps authorization request is sent to Google. Some applications will fail to use the Google account if this is disabled.</string>
|
||||
|
||||
<string name="pref_checkin_enable">checkin_enable_service</string>
|
||||
<string name="pref_checkin_enable" translatable="false">checkin_enable_service</string>
|
||||
<string name="pref_checkin_enable_title">Enable device checkin</string>
|
||||
<string name="pref_checkin_enable_summary">Device checkin is a hidden process that is used to create an unique identifier for Google services. microG Services strips identifying bits other than your Google account name from this data.</string>
|
||||
<string name="pref_gcm_enable_mcs">gcm_enable_mcs_service</string>
|
||||
<string name="pref_gcm_enable_mcs" translatable="false">gcm_enable_mcs_service</string>
|
||||
<string name="pref_gcm_enable_mcs_title">Enable Google Cloud Messaging</string>
|
||||
<string name="pref_gcm_enable_mcs_summary">Google Cloud Messaging is a push notification provider used by many applications. To use it you must enable device checkin.</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue