-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start a foreground service during restore
so the system won't kill us, even if the user navigates away.
- Loading branch information
Showing
8 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/stevesoltys/seedvault/restore/RestoreService.kt
This file contains 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,46 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The Calyx Institute | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.stevesoltys.seedvault.restore | ||
|
||
import android.app.Service | ||
import android.content.Intent | ||
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST | ||
import android.os.IBinder | ||
import android.util.Log | ||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager | ||
import com.stevesoltys.seedvault.ui.notification.NOTIFICATION_ID_RESTORE | ||
import org.koin.android.ext.android.inject | ||
|
||
class RestoreService : Service() { | ||
|
||
companion object { | ||
private const val TAG = "RestoreService" | ||
} | ||
|
||
private val nm: BackupNotificationManager by inject() | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
Log.i(TAG, "onStartCommand $intent $flags $startId") | ||
|
||
startForeground( | ||
NOTIFICATION_ID_RESTORE, | ||
nm.getRestoreNotification(), | ||
FOREGROUND_SERVICE_TYPE_MANIFEST, | ||
) | ||
return START_STICKY_COMPATIBILITY | ||
} | ||
|
||
override fun onBind(intent: Intent?): IBinder? { | ||
return null | ||
} | ||
|
||
override fun onDestroy() { | ||
Log.i(TAG, "onDestroy") | ||
super.onDestroy() | ||
nm.cancelRestoreNotification() | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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