Commit 0bf3f75f authored by MozLando's avatar MozLando
Browse files

Merge #5222

5222: Fix sample-sync-logins to work with new dataprotect requirement. r=Amejia481 a=rfk

The global sync manager now requires that you provide a secure keystore object in order to sync the logins store. This updates the sync-logins sample to do so, so that it can sync logins successfully.

(The sync-logins sample still doesn't actually *work* after this change, but I believe the remaining issues are due to a bug in appservices, ref https://github.com/mozilla/application-services/issues/2312

).



Co-authored-by: default avatarRyan Kelly <rfkelly@mozilla.com>
parents 8b788ddf 7c4677e1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ dependencies {
    implementation project(':service-sync-logins')
    implementation project(':support-rustlog')
    implementation project(':support-rusthttp')
    implementation project(':lib-dataprotect')
    implementation project(':lib-fetch-httpurlconnection')

    implementation Dependencies.kotlin_stdlib
+7 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import mozilla.components.concept.sync.DeviceType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.service.fxa.FirefoxAccount
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient
import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.service.fxa.DeviceConfig
@@ -46,6 +47,7 @@ const val CLIENT_ID = "3c49430b43dfba77"
const val REDIRECT_URL = "https://accounts.firefox.com/oauth/success/$CLIENT_ID"

class MainActivity : AppCompatActivity(), LoginFragment.OnLoginCompleteListener, CoroutineScope, SyncStatusObserver {
    private lateinit var keyStorage: SecureAbove22Preferences
    private lateinit var loginsStorage: SyncableLoginsStore
    private lateinit var listView: ListView
    private lateinit var adapter: ArrayAdapter<String>
@@ -83,10 +85,14 @@ class MainActivity : AppCompatActivity(), LoginFragment.OnLoginCompleteListener,
        listView.adapter = adapter
        activityContext = this

        keyStorage = SecureAbove22Preferences(this, "secret-data-storage")
        keyStorage.putString(SyncEngine.Passwords.nativeName, "my-not-so-secret-password")
        GlobalSyncableStoreProvider.configureKeyStorage(keyStorage)

        loginsStorage = SyncableLoginsStore(
            AsyncLoginsStorageAdapter.forDatabase(File(activityContext.filesDir, "logins.sqlite").canonicalPath)
        ) {
            CompletableDeferred("my-not-so-secret-password")
            CompletableDeferred(keyStorage.getString(SyncEngine.Passwords.nativeName)!!)
        }
        GlobalSyncableStoreProvider.configureStore(SyncEngine.Passwords to loginsStorage)