-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Migration from phone to phone #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a407386
chore: Change backup configuration to include and exclude what we need
tevincent f4fbadc
chore: Utils method to manipulate files on each platforms
tevincent 173aca5
feat: Implements migration of accounts from backup
tevincent 393cb2d
fix: Delete the old passkey when we successfully get a new token with…
tevincent 6815822
chore: Avoid having tokenBridge as parameter of MigrationManager
tevincent 6c29915
fix: Put methods to internal
tevincent 91d93f3
chore: Create a new Account status to migrate accounts and avoid crea…
tevincent dbecbc8
chore: Remove unused method
tevincent fcc49d3
chore: Clean code
tevincent bb96889
fix: Use the right token when persistUser is called
tevincent c519179
chore: Improve how we update accounts when restoring from backup
tevincent cde660f
chore: Do not include the file created on iOS in the backup
tevincent bf32d72
chore: Move getApplicationSupportDirectory to FileUtils.apple.kt
LouisCAD fab136e
fix: Handle NSError in FileUtils.apple.kt
LouisCAD 802ed84
chore: Put arguments on separate lines with names
LouisCAD c19d738
chore: Rename parameter name for clarity
LouisCAD 70291e3
chore: Add optional userId to KeyNotFound
LouisCAD e92e68b
chore: Remove unused returned value warning
LouisCAD f3e4171
chore: Replace NPEs with ISEs with error messages
LouisCAD 3d81831
chore: Replace unnecessary Xor wrapping with nullable String
LouisCAD 68e48b9
chore: Make FileUtils contents internal
LouisCAD 65c4261
chore: Rename createFile to createBackupExcludedFile
LouisCAD f05611d
refactor: Introduce RestoreFromBackupDetector
LouisCAD e4beccc
chore: Put arguments on separate lines
LouisCAD 4441b2c
fix: Handle exceptions and retries for restoration from backup
LouisCAD 8277189
perf: Use Dispatchers.IO for keychain operations
LouisCAD 3018388
chore: Add BackupExclusionGotcha opt-in requirement annotation
LouisCAD d7c4974
chore: Rename BackupExclusionGotcha to BackupExclusionOnlyApplePlatforms
LouisCAD 887245d
chore: Remove unused userId
tevincent 9376168
chore: Rename method to avoid an unnecessary val
tevincent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?><!-- | ||
| Sample backup rules file; uncomment and customize as necessary. | ||
| See https://developer.android.com/guide/topics/data/autobackup | ||
| for details. | ||
| Note: This file is ignored for devices older than API 31 | ||
| See https://developer.android.com/about/versions/12/backup-restore | ||
| --> | ||
| ~ Infomaniak Authenticator - Android | ||
| ~ Copyright (C) 2026 Infomaniak Network SA | ||
| ~ | ||
| ~ This program is free software: you can redistribute it and/or modify | ||
| ~ it under the terms of the GNU General Public License as published by | ||
| ~ the Free Software Foundation, either version 3 of the License, or | ||
| ~ (at your option) any later version. | ||
| ~ | ||
| ~ This program is distributed in the hope that it will be useful, | ||
| ~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ~ GNU General Public License for more details. | ||
| ~ | ||
| ~ You should have received a copy of the GNU General Public License | ||
| ~ along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| --> | ||
| <full-backup-content> | ||
| <!-- | ||
| <include domain="sharedpref" path="."/> | ||
| <exclude domain="sharedpref" path="device.xml"/> | ||
| --> | ||
| </full-backup-content> | ||
| <include | ||
| domain="file" | ||
| path="." /> | ||
| <include | ||
| domain="database" | ||
| path="." /> | ||
| <exclude | ||
| domain="file" | ||
| path="Quoi ?" /> | ||
| </full-backup-content> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?><!-- | ||
| Sample data extraction rules file; uncomment and customize as necessary. | ||
| See https://developer.android.com/about/versions/12/backup-restore#xml-changes | ||
| for details. | ||
| --> | ||
| ~ Infomaniak Authenticator - Android | ||
| ~ Copyright (C) 2026 Infomaniak Network SA | ||
| ~ | ||
| ~ This program is free software: you can redistribute it and/or modify | ||
| ~ it under the terms of the GNU General Public License as published by | ||
| ~ the Free Software Foundation, either version 3 of the License, or | ||
| ~ (at your option) any later version. | ||
| ~ | ||
| ~ This program is distributed in the hope that it will be useful, | ||
| ~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ~ GNU General Public License for more details. | ||
| ~ | ||
| ~ You should have received a copy of the GNU General Public License | ||
| ~ along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| --> | ||
| <data-extraction-rules> | ||
| <cloud-backup> | ||
| <!-- TODO: Use <include> and <exclude> to control what is backed up. | ||
| <include .../> | ||
| <exclude .../> | ||
| --> | ||
| </cloud-backup> | ||
| <!-- | ||
|
|
||
| <device-transfer> | ||
| <include .../> | ||
| <exclude .../> | ||
| <include | ||
| domain="file" | ||
| path="." /> | ||
| <include | ||
| domain="database" | ||
| path="." /> | ||
| <exclude | ||
| domain="file" | ||
| path="Quoi ?" /> | ||
| </device-transfer> | ||
| --> | ||
| </data-extraction-rules> | ||
|
|
||
| </data-extraction-rules> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
multiplatform-lib/src/androidMain/kotlin/internal/utils/FileUtils.android.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Infomaniak Authenticator - Android | ||
| * Copyright (C) 2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.auth.lib.internal.utils | ||
|
|
||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.invoke | ||
| import splitties.init.appCtx | ||
| import java.io.File | ||
|
|
||
| internal actual suspend fun checkFileExists(name: String): Boolean = Dispatchers.IO { | ||
| File(appCtx.filesDir, name).exists() | ||
| } | ||
|
|
||
| /** | ||
| * **WARNING:** The backup exclusion is Apple/iOS only. On Android, you need to configure the backup rules, | ||
| * or implement a BackupAgent to have the backup exclusion work. | ||
| */ | ||
| internal actual suspend fun createBackupExcludedFile(name: String, content: String) { | ||
| File(appCtx.filesDir, name).apply { | ||
| createNewFile() | ||
| writeText(content) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
multiplatform-lib/src/appleMain/kotlin/internal/utils/FileUtils.apple.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Infomaniak Authenticator - Android | ||
| * Copyright (C) 2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.auth.lib.internal.utils | ||
|
|
||
| import com.infomaniak.auth.lib.internal.extensions.firstOrElse | ||
| import com.infomaniak.auth.lib.internal.extensions.toNsData | ||
| import com.infomaniak.auth.lib.internal.extensions.tryIt2 | ||
| import kotlinx.cinterop.ExperimentalForeignApi | ||
| import platform.Foundation.NSApplicationSupportDirectory | ||
| import platform.Foundation.NSFileManager | ||
| import platform.Foundation.NSURL | ||
| import platform.Foundation.NSURLIsExcludedFromBackupKey | ||
| import platform.Foundation.NSUserDomainMask | ||
|
|
||
| internal actual suspend fun checkFileExists(name: String): Boolean { | ||
| return NSFileManager.defaultManager.fileExistsAtPath("${getApplicationSupportDirectory()}/$name") | ||
| } | ||
|
|
||
| @OptIn(ExperimentalForeignApi::class) | ||
| internal actual suspend fun createBackupExcludedFile(name: String, content: String) { | ||
| val path = "${getApplicationSupportDirectory()}/$name" | ||
| NSFileManager.defaultManager.createFileAtPath( | ||
| path = path, | ||
| contents = content.toNsData(), | ||
| attributes = null | ||
| ) | ||
| val url = NSURL.fileURLWithPath(path) | ||
| val _ = tryIt2 { | ||
| url.setResourceValue( | ||
| value = true, | ||
| forKey = NSURLIsExcludedFromBackupKey, | ||
| error = it | ||
| ) | ||
| }.firstOrElse { error(it) } | ||
| } | ||
|
|
||
| @OptIn(ExperimentalForeignApi::class) | ||
| private fun getApplicationSupportDirectory(): String { | ||
| val directory = tryIt2 { | ||
| NSFileManager.defaultManager.URLForDirectory( | ||
| directory = NSApplicationSupportDirectory, | ||
| inDomain = NSUserDomainMask, | ||
| appropriateForURL = null, | ||
| create = true, | ||
| error = it, | ||
| ) | ||
| }.firstOrElse { error(it) } | ||
| return requireNotNull(directory.path) // No reason for it to be null given the code above. | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.