Skip to content

Commit

Permalink
Minor improvements for app restore
Browse files Browse the repository at this point in the history
* activity now can be launched from notification
* better logging
* app data restore continues even after activity died
  • Loading branch information
grote committed Oct 7, 2024
1 parent eb2baf3 commit f3f710c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ internal class AppDataRestoreManager(
context.stopService(foregroundServiceIntent)
}

fun closeSession() {
private fun closeSession() {
session?.endRestoreSession()
session = null
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -317,6 +319,7 @@ internal class AppDataRestoreManager(
return
}

Log.d(TAG, "onRestoreComplete()")
// Restore finished, time to get the result.
onRestoreComplete(getRestoreResult(), restorableBackup)
closeSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class RestoreService : Service() {

override fun onDestroy() {
Log.i(TAG, "onDestroy")
super.onDestroy()
nm.cancelRestoreNotification()
super.onDestroy()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ internal class RestoreViewModel(
super.onCleared()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(ioDispatcher) { iconManager.removeIcons() }
appDataRestoreManager.closeSession()
}

@UiThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f3f710c

Please sign in to comment.