Minor improvements for app restore

* activity now can be launched from notification
* better logging
* app data restore continues even after activity died
This commit is contained in:
Torsten Grote 2024-10-02 17:19:04 -03:00
parent 11270ff694
commit f8451586df
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
6 changed files with 11 additions and 4 deletions

View file

@ -123,6 +123,7 @@
android:name=".restore.RestoreActivity"
android:exported="true"
android:label="@string/restore_title"
android:launchMode="singleTask"
android:permission="com.stevesoltys.seedvault.RESTORE_BACKUP">
<intent-filter>
<action android:name="com.stevesoltys.seedvault.RESTORE_BACKUP" />

View file

@ -210,7 +210,7 @@ internal class AppDataRestoreManager(
context.stopService(foregroundServiceIntent)
}
fun closeSession() {
private fun closeSession() {
session?.endRestoreSession()
session = null
}
@ -267,6 +267,7 @@ internal class AppDataRestoreManager(
val nextChunkIndex = (packageIndex + PACKAGES_PER_CHUNK).coerceAtMost(packages.size)
val packageChunk = packages.subList(packageIndex, nextChunkIndex).toTypedArray()
packageIndex += packageChunk.size
Log.d(TAG, "restoreNextPackages() with packageIndex=$packageIndex")
val token = restorableBackup.token
val result = session.restorePackages(token, this, packageChunk, monitor)
@ -309,6 +310,7 @@ internal class AppDataRestoreManager(
*/
override fun restoreFinished(result: Int) {
val chunkIndex = packageIndex / PACKAGES_PER_CHUNK
Log.d(TAG, "restoreFinished($result) with chunkIndex=$chunkIndex")
chunkResults[chunkIndex] = result
// Restore next chunk if successful and there are more packages to restore.
@ -317,6 +319,7 @@ internal class AppDataRestoreManager(
return
}
Log.d(TAG, "onRestoreComplete()")
// Restore finished, time to get the result.
onRestoreComplete(getRestoreResult(), restorableBackup)
closeSession()

View file

@ -39,8 +39,8 @@ class RestoreService : Service() {
override fun onDestroy() {
Log.i(TAG, "onDestroy")
super.onDestroy()
nm.cancelRestoreNotification()
super.onDestroy()
}
}

View file

@ -173,7 +173,6 @@ internal class RestoreViewModel(
super.onCleared()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(ioDispatcher) { iconManager.removeIcons() }
appDataRestoreManager.closeSession()
}
@UiThread

View file

@ -270,11 +270,11 @@ internal class RestoreCoordinator(
* or null to indicate a transport-level error.
*/
suspend fun nextRestorePackage(): RestoreDescription? {
Log.i(TAG, "Next restore package!")
val state = this.state ?: throw IllegalStateException("no state")
if (!state.packages.hasNext()) return NO_MORE_PACKAGES
val packageInfo = state.packages.next()
Log.i(TAG, "nextRestorePackage() => ${packageInfo.packageName}")
val version = state.backup.version
if (version == 0.toByte()) return nextRestorePackageV0(state, packageInfo)
if (version == 1.toByte()) return nextRestorePackageV1(state, packageInfo)

View file

@ -31,6 +31,7 @@ import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.restore.ACTION_RESTORE_ERROR_UNINSTALL
import com.stevesoltys.seedvault.restore.EXTRA_PACKAGE_NAME
import com.stevesoltys.seedvault.restore.REQUEST_CODE_UNINSTALL
import com.stevesoltys.seedvault.restore.RestoreActivity
import com.stevesoltys.seedvault.settings.ACTION_APP_STATUS_LIST
import com.stevesoltys.seedvault.settings.SettingsActivity
import kotlin.math.min
@ -265,6 +266,9 @@ internal class BackupNotificationManager(private val context: Context) {
}
fun getRestoreNotification() = Notification.Builder(context, CHANNEL_ID_RESTORE).apply {
val intent = Intent(context, RestoreActivity::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, FLAG_IMMUTABLE)
setContentIntent(pendingIntent)
setSmallIcon(R.drawable.ic_cloud_restore)
setContentTitle(context.getString(R.string.notification_restore_title))
setOngoing(true)