diff --git a/.travis.yml b/.travis.yml
index 1b3be818..032be339 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,5 @@
language: android
+sudo: false
git:
submodules: false
before_install:
diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml
index 9bc9ddeb..3e286607 100644
--- a/play-services-core/src/main/AndroidManifest.xml
+++ b/play-services-core/src/main/AndroidManifest.xml
@@ -135,6 +135,9 @@
+
+
+
diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinService.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinService.java
index e71623b9..80876c32 100644
--- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinService.java
+++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinService.java
@@ -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
diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/LastCheckinInfo.java b/play-services-core/src/main/java/org/microg/gms/checkin/LastCheckinInfo.java
index 113f6b1c..5e5b848a 100644
--- a/play-services-core/src/main/java/org/microg/gms/checkin/LastCheckinInfo.java
+++ b/play-services-core/src/main/java/org/microg/gms/checkin/LastCheckinInfo.java
@@ -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();
}
}
diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/TriggerReceiver.java b/play-services-core/src/main/java/org/microg/gms/checkin/TriggerReceiver.java
index 79e14723..083c1a53 100644
--- a/play-services-core/src/main/java/org/microg/gms/checkin/TriggerReceiver.java
+++ b/play-services-core/src/main/java/org/microg/gms/checkin/TriggerReceiver.java
@@ -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);
}
}
diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java
index 7a86b265..fccf7c23 100644
--- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java
+++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java
@@ -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) {
diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/TriggerReceiver.java b/play-services-core/src/main/java/org/microg/gms/gcm/TriggerReceiver.java
index c9fbdb33..f8c78c38 100644
--- a/play-services-core/src/main/java/org/microg/gms/gcm/TriggerReceiver.java
+++ b/play-services-core/src/main/java/org/microg/gms/gcm/TriggerReceiver.java
@@ -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));
- }
}
diff --git a/play-services-core/src/main/res/values/strings.xml b/play-services-core/src/main/res/values/strings.xml
index 1ace37b4..8ba24b11 100644
--- a/play-services-core/src/main/res/values/strings.xml
+++ b/play-services-core/src/main/res/values/strings.xml
@@ -33,10 +33,10 @@
Trust Google for app permissions
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.
- checkin_enable_service
+ checkin_enable_service
Enable device checkin
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.
- gcm_enable_mcs_service
+ gcm_enable_mcs_service
Enable Google Cloud Messaging
Google Cloud Messaging is a push notification provider used by many applications. To use it you must enable device checkin.