Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f67d1aa authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Automatically checkin after 12 hours

parent 40ca65bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
language: android
sudo: false
git:
  submodules: false
before_install:
+3 −0
Original line number Diff line number Diff line
@@ -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"/>

+10 −5
Original line number Diff line number Diff line
@@ -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,16 +52,19 @@ 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);
                }
                McsService.scheduleReconnect(this);
            }
        } catch (Exception e) {
            Log.w(TAG, e);
        }
        } finally {
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
            stopSelf();
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }
}
+23 −7
Original line number Diff line number Diff line
@@ -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);

        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);
        if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
            subIntent.putExtra("force", true);
                subIntent.putExtra("force", force);
                startWakefulService(context, subIntent);
            }
        } else {
            Log.d(TAG, "Ignoring " + intent + ": checkin is disabled");
        }
        context.startService(subIntent);
    }
}
Loading