commit 33241daf39a5c33c8a98ed08eee3f51d01901af4 parent f34d222f9942de544359cccb6f60a84ce58ad535 Author: mike a. <mavduevskiy@mozilla.com> Date: Tue, 16 Dec 2025 20:10:11 +0000 Bug 2005089 - Part 1: Fix sync logins component r=android-reviewers,gmalekpour I was looking for a component to copy the implementation of the account manager from, but I could not find a working one. The authentication mechanism changed, but the sample projects were not updated to reflect that. So the first step is to have a working example to copy in the next patch. Differential Revision: https://phabricator.services.mozilla.com/D276539 Diffstat:
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/mobile/android/android-components/samples/sync-logins/src/main/java/org/mozilla/samples/sync/logins/LoginFragment.kt b/mobile/android/android-components/samples/sync-logins/src/main/java/org/mozilla/samples/sync/logins/LoginFragment.kt @@ -48,7 +48,7 @@ class LoginFragment : Fragment() { val code = uri.getQueryParameter("code") val state = uri.getQueryParameter("state") val action = uri.getQueryParameter("action") - if (code != null && state != null && action != null) { + if (code != null && state != null) { listener?.onLoginComplete(code, state, action, this@LoginFragment) } } @@ -90,7 +90,10 @@ class LoginFragment : Fragment() { } interface OnLoginCompleteListener { - fun onLoginComplete(code: String, state: String, action: String, fragment: LoginFragment) + /** + * A callback invoked when we get a successful redirect from the auth server. + */ + fun onLoginComplete(code: String, state: String, action: String?, fragment: LoginFragment) } companion object { diff --git a/mobile/android/android-components/samples/sync-logins/src/main/java/org/mozilla/samples/sync/logins/MainActivity.kt b/mobile/android/android-components/samples/sync-logins/src/main/java/org/mozilla/samples/sync/logins/MainActivity.kt @@ -31,6 +31,8 @@ import mozilla.components.service.fxa.PeriodicSyncConfig import mozilla.components.service.fxa.SyncConfig import mozilla.components.service.fxa.SyncEngine import mozilla.components.service.fxa.manager.FxaAccountManager +import mozilla.components.service.fxa.manager.SCOPE_SESSION +import mozilla.components.service.fxa.manager.SCOPE_SYNC import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider import mozilla.components.service.fxa.sync.SyncReason import mozilla.components.service.fxa.sync.SyncStatusObserver @@ -63,6 +65,10 @@ class MainActivity : AppCompatActivity(), LoginFragment.OnLoginCompleteListener, FxaConfig(FxaServer.Release, CLIENT_ID, REDIRECT_URL), DeviceConfig("A-C Logins Sync Sample", DeviceType.MOBILE, setOf()), SyncConfig(setOf(SyncEngine.Passwords), PeriodicSyncConfig()), + setOf( + SCOPE_SYNC, + SCOPE_SESSION, + ), ) } @@ -151,11 +157,10 @@ class MainActivity : AppCompatActivity(), LoginFragment.OnLoginCompleteListener, } } - override fun onLoginComplete(code: String, state: String, action: String, fragment: LoginFragment) { + override fun onLoginComplete(code: String, state: String, action: String?, fragment: LoginFragment) { launch { - accountManager.finishAuthentication( - FxaAuthData(action.toAuthType(), code = code, state = state), - ) + val authType = action?.toAuthType() ?: AuthType.Signin + accountManager.finishAuthentication(FxaAuthData(authType, code = code, state = state)) supportFragmentManager.popBackStack() } }