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

Unverified Commit bcd639d5 authored by DaVinci9196's avatar DaVinci9196 Committed by GitHub
Browse files

Google 2FA: prevent infinite request loop if registration fails (#3222)



Co-authored-by: default avatarMarvin W <git@larma.de>
parent 527a0cd7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -368,7 +368,7 @@
            android:exported="false"
            android:process=":persistent">
            <intent-filter>
                <action android:name="org.microg.gms.gcm.REGISTERED" />
                <action android:name="org.microg.gms.gcm.CONNECTED" />
                <action android:name="org.microg.gms.gcm.REGISTER_ACCOUNT" />
                <action android:name="org.microg.gms.gcm.NOTIFY_COMPLETE" />

+4 −4
Original line number Diff line number Diff line
@@ -81,8 +81,8 @@ import okio.ByteString;
import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP;
import static android.os.Build.VERSION.SDK_INT;
import static org.microg.gms.common.PackageUtils.warnIfNotPersistentProcess;
import static org.microg.gms.gcm.ExtensionsKt.ACTION_GCM_CONNECTED;
import static org.microg.gms.gcm.GcmConstants.*;
import static org.microg.gms.gcm.ExtensionsKt.ACTION_GCM_REGISTERED;
import static org.microg.gms.gcm.McsConstants.*;

@ForegroundServiceInfo(value = "Cloud messaging", resName = "service_name_mcs", resPackage = "com.google.android.gms")
@@ -497,15 +497,15 @@ public class McsService extends Service implements Handler.Callback {
        if (loginResponse.error == null) {
            GcmPrefs.clearLastPersistedId(this);
            logd(this, "Logged in");
            notifyGcmRegistered();
            notifyGcmConnected();
            wakeLock.release();
        } else {
            throw new RuntimeException("Could not login: " + loginResponse.error);
        }
    }

    private void notifyGcmRegistered() {
        Intent intent = new Intent(ACTION_GCM_REGISTERED);
    private void notifyGcmConnected() {
        Intent intent = new Intent(ACTION_GCM_CONNECTED);
        intent.setPackage(Constants.GMS_PACKAGE_NAME);
        sendBroadcast(intent);
    }
+7 −2
Original line number Diff line number Diff line
@@ -155,7 +155,8 @@ class GcmInGmsService : LifecycleService() {
                Log.d(TAG, "start handle gcm message")
                intent.extras?.let { notifyVerificationInfo(it) }
            }
            ACTION_GCM_REGISTERED -> {
            ACTION_GCM_REGISTER_ALL_ACCOUNTS,
            ACTION_GCM_CONNECTED -> {
                updateLocalAccountGroups()
            }
            ACTION_GCM_REGISTER_ACCOUNT -> {
@@ -370,6 +371,10 @@ class GcmInGmsService : LifecycleService() {
            completeRegisterRequest(context, gcmDatabase, request).getString(GcmConstants.EXTRA_REGISTRATION_ID)
        }
        Log.d(TAG, "GCM IN GMS regId: $regId")
        if (regId == null) {
            Log.w(TAG, "registerGcmInGms reg id is null")
            return
        }
        val sharedPreferencesEditor = sp?.edit()
        sharedPreferencesEditor?.putLong(KEY_GCM_ANDROID_ID, LastCheckinInfo.read(context).androidId)
        sharedPreferencesEditor?.putString(KEY_GCM_REG_ID, regId)
+3 −2
Original line number Diff line number Diff line
@@ -12,8 +12,9 @@ import okhttp3.OkHttpClient
import okhttp3.Response

const val ACTION_GCM_RECONNECT = "org.microg.gms.gcm.RECONNECT"
const val ACTION_GCM_REGISTERED = "org.microg.gms.gcm.REGISTERED"
const val ACTION_GCM_CONNECTED = "org.microg.gms.gcm.CONNECTED"
const val ACTION_GCM_REGISTER_ACCOUNT = "org.microg.gms.gcm.REGISTER_ACCOUNT"
const val ACTION_GCM_REGISTER_ALL_ACCOUNTS = "org.microg.gms.gcm.REGISTER_ALL_ACCOUNTS"
const val ACTION_GCM_NOTIFY_COMPLETE = "org.microg.gms.gcm.NOTIFY_COMPLETE"
const val KEY_GCM_REGISTER_ACCOUNT_NAME = "register_account_name"
const val EXTRA_NOTIFICATION_ACCOUNT = "notification_account"
+3 −2
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.microg.gms.auth.AuthConstants
import org.microg.gms.common.Constants
import org.microg.gms.gcm.ACTION_GCM_REGISTERED
import org.microg.gms.gcm.ACTION_GCM_CONNECTED
import org.microg.gms.gcm.ACTION_GCM_REGISTER_ALL_ACCOUNTS
import org.microg.gms.people.DatabaseHelper
import org.microg.gms.people.PeopleManager
import org.microg.gms.settings.SettingsContract
@@ -65,7 +66,7 @@ class AccountsFragment : PreferenceFragmentCompat() {
        }).also { it.isCircular = true } else null

    private fun registerGcmInGms() {
        Intent(ACTION_GCM_REGISTERED).apply {
        Intent(ACTION_GCM_REGISTER_ALL_ACCOUNTS).apply {
            `package` = Constants.GMS_PACKAGE_NAME
        }.let { requireContext().sendBroadcast(it) }
    }