Skip to content

Commit bcd639d

Browse files
Google 2FA: prevent infinite request loop if registration fails (#3222)
Co-authored-by: Marvin W <git@larma.de>
1 parent 527a0cd commit bcd639d

5 files changed

Lines changed: 18 additions & 11 deletions

File tree

play-services-core/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
android:exported="false"
369369
android:process=":persistent">
370370
<intent-filter>
371-
<action android:name="org.microg.gms.gcm.REGISTERED" />
371+
<action android:name="org.microg.gms.gcm.CONNECTED" />
372372
<action android:name="org.microg.gms.gcm.REGISTER_ACCOUNT" />
373373
<action android:name="org.microg.gms.gcm.NOTIFY_COMPLETE" />
374374

play-services-core/src/main/java/org/microg/gms/gcm/McsService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP;
8282
import static android.os.Build.VERSION.SDK_INT;
8383
import static org.microg.gms.common.PackageUtils.warnIfNotPersistentProcess;
84+
import static org.microg.gms.gcm.ExtensionsKt.ACTION_GCM_CONNECTED;
8485
import static org.microg.gms.gcm.GcmConstants.*;
85-
import static org.microg.gms.gcm.ExtensionsKt.ACTION_GCM_REGISTERED;
8686
import static org.microg.gms.gcm.McsConstants.*;
8787

8888
@ForegroundServiceInfo(value = "Cloud messaging", resName = "service_name_mcs", resPackage = "com.google.android.gms")
@@ -497,15 +497,15 @@ private void handleLoginResponse(LoginResponse loginResponse) {
497497
if (loginResponse.error == null) {
498498
GcmPrefs.clearLastPersistedId(this);
499499
logd(this, "Logged in");
500-
notifyGcmRegistered();
500+
notifyGcmConnected();
501501
wakeLock.release();
502502
} else {
503503
throw new RuntimeException("Could not login: " + loginResponse.error);
504504
}
505505
}
506506

507-
private void notifyGcmRegistered() {
508-
Intent intent = new Intent(ACTION_GCM_REGISTERED);
507+
private void notifyGcmConnected() {
508+
Intent intent = new Intent(ACTION_GCM_CONNECTED);
509509
intent.setPackage(Constants.GMS_PACKAGE_NAME);
510510
sendBroadcast(intent);
511511
}

play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class GcmInGmsService : LifecycleService() {
155155
Log.d(TAG, "start handle gcm message")
156156
intent.extras?.let { notifyVerificationInfo(it) }
157157
}
158-
ACTION_GCM_REGISTERED -> {
158+
ACTION_GCM_REGISTER_ALL_ACCOUNTS,
159+
ACTION_GCM_CONNECTED -> {
159160
updateLocalAccountGroups()
160161
}
161162
ACTION_GCM_REGISTER_ACCOUNT -> {
@@ -370,6 +371,10 @@ class GcmInGmsService : LifecycleService() {
370371
completeRegisterRequest(context, gcmDatabase, request).getString(GcmConstants.EXTRA_REGISTRATION_ID)
371372
}
372373
Log.d(TAG, "GCM IN GMS regId: $regId")
374+
if (regId == null) {
375+
Log.w(TAG, "registerGcmInGms reg id is null")
376+
return
377+
}
373378
val sharedPreferencesEditor = sp?.edit()
374379
sharedPreferencesEditor?.putLong(KEY_GCM_ANDROID_ID, LastCheckinInfo.read(context).androidId)
375380
sharedPreferencesEditor?.putString(KEY_GCM_REG_ID, regId)
@@ -510,4 +515,4 @@ class GcmRegistrationReceiver : WakefulBroadcastReceiver() {
510515
}
511516
ForegroundServiceContext(context).startService(callIntent)
512517
}
513-
}
518+
}

play-services-core/src/main/kotlin/org/microg/gms/gcm/extensions.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import okhttp3.OkHttpClient
1212
import okhttp3.Response
1313

1414
const val ACTION_GCM_RECONNECT = "org.microg.gms.gcm.RECONNECT"
15-
const val ACTION_GCM_REGISTERED = "org.microg.gms.gcm.REGISTERED"
15+
const val ACTION_GCM_CONNECTED = "org.microg.gms.gcm.CONNECTED"
1616
const val ACTION_GCM_REGISTER_ACCOUNT = "org.microg.gms.gcm.REGISTER_ACCOUNT"
17+
const val ACTION_GCM_REGISTER_ALL_ACCOUNTS = "org.microg.gms.gcm.REGISTER_ALL_ACCOUNTS"
1718
const val ACTION_GCM_NOTIFY_COMPLETE = "org.microg.gms.gcm.NOTIFY_COMPLETE"
1819
const val KEY_GCM_REGISTER_ACCOUNT_NAME = "register_account_name"
1920
const val EXTRA_NOTIFICATION_ACCOUNT = "notification_account"
@@ -44,4 +45,4 @@ inline fun <reified S : Service> createGrpcClient(
4445
.minMessageToCompress(minMessageToCompress)
4546
.build()
4647
return grpcClient.create(S::class)
47-
}
48+
}

play-services-core/src/main/kotlin/org/microg/gms/ui/AccountsFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import kotlinx.coroutines.Dispatchers
2626
import kotlinx.coroutines.withContext
2727
import org.microg.gms.auth.AuthConstants
2828
import org.microg.gms.common.Constants
29-
import org.microg.gms.gcm.ACTION_GCM_REGISTERED
29+
import org.microg.gms.gcm.ACTION_GCM_CONNECTED
30+
import org.microg.gms.gcm.ACTION_GCM_REGISTER_ALL_ACCOUNTS
3031
import org.microg.gms.people.DatabaseHelper
3132
import org.microg.gms.people.PeopleManager
3233
import org.microg.gms.settings.SettingsContract
@@ -65,7 +66,7 @@ class AccountsFragment : PreferenceFragmentCompat() {
6566
}).also { it.isCircular = true } else null
6667

6768
private fun registerGcmInGms() {
68-
Intent(ACTION_GCM_REGISTERED).apply {
69+
Intent(ACTION_GCM_REGISTER_ALL_ACCOUNTS).apply {
6970
`package` = Constants.GMS_PACKAGE_NAME
7071
}.let { requireContext().sendBroadcast(it) }
7172
}

0 commit comments

Comments
 (0)