Skip to content

Commit

Permalink
UpdaterThread: Add new MONITOR action
Browse files Browse the repository at this point in the history
We only want to monitor update_engine's status immediate after boot so
that we can show a notification during the snapuserd merge operation. We
don't want to annoy the user with update check notifications.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Aug 23, 2024
1 parent fac6242 commit c51a761
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class UpdaterBootReceiver : BroadcastReceiver() {
}

// This will monitor the cleanup process on the reboot immediately following an OTA.
UpdaterJob.scheduleImmediate(context, UpdaterThread.Action.CHECK)
UpdaterJob.scheduleImmediate(context, UpdaterThread.Action.MONITOR)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class UpdaterService : Service(), UpdaterThread.UpdaterThreadListener {
val showReboot: Boolean

when (result) {
is UpdaterThread.UpdateCleanedUp -> {
is UpdaterThread.NothingToMonitor, is UpdaterThread.UpdateCleanedUp -> {
// No need to bug the user about this since it's automatic and not directly caused
// in response to a user action.
return
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/chiller3/custota/updater/UpdaterThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ class UpdaterThread(
try {
wakeLock.acquire()

Log.d(TAG, "Action: $action")

Log.d(TAG, "Waiting for initial engine status")
val status = waitForStatus { it != -1 }
val statusStr = UpdateEngineStatus.toString(status)
Expand Down Expand Up @@ -676,18 +678,24 @@ class UpdaterThread(
listener.onUpdateResult(this, UpdateNeedReboot)
} else {
if (status == UpdateEngineStatus.IDLE) {
if (action == Action.MONITOR) {
// Nothing to do.
listener.onUpdateResult(this, NothingToMonitor)
return
}

Log.d(TAG, "Starting new update because engine is idle")

listener.onUpdateProgress(this, ProgressType.CHECK, 0, 0)

val checkUpdateResult = checkForUpdates()

if (!checkUpdateResult.updateAvailable) {
// Update not needed
// Update not needed.
listener.onUpdateResult(this, UpdateUnnecessary)
return
} else if (action == Action.CHECK) {
// Just alert that an update is available
// Just alert that an update is available.
listener.onUpdateResult(this,
UpdateAvailable(checkUpdateResult.fingerprint))
return
Expand Down Expand Up @@ -787,6 +795,7 @@ class UpdaterThread(

@Parcelize
enum class Action : Parcelable {
MONITOR,
CHECK,
INSTALL,
REVERT,
Expand All @@ -796,6 +805,10 @@ class UpdaterThread(
val isError : Boolean
}

data object NothingToMonitor : Result {
override val isError = false
}

data class UpdateAvailable(val fingerprint: String) : Result {
override val isError = false
}
Expand Down

0 comments on commit c51a761

Please sign in to comment.