Skip to content

Commit d9f8054

Browse files
committed
feat: disable auto-update when custom version update is detected
1 parent 176b7d2 commit d9f8054

File tree

15 files changed

+40
-0
lines changed

15 files changed

+40
-0
lines changed

internal/ota/ota.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ func (s *State) doUpdate(ctx context.Context, params UpdateParams) error {
186186
}
187187

188188
if s.rebootNeeded {
189+
if appUpdate.customVersionUpdate || systemUpdate.customVersionUpdate {
190+
scopedLogger.Info().Msg("disabling auto-update due to custom version update")
191+
if _, err := s.setAutoUpdate(false); err != nil {
192+
scopedLogger.Warn().Err(err).Msg("Failed to disable auto-update")
193+
}
194+
return nil
195+
}
196+
189197
scopedLogger.Info().Msg("System Rebooting due to OTA update")
190198

191199
redirectUrl := fmt.Sprintf("/settings/general/update?version=%s", systemUpdate.version)

internal/ota/rpc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func remoteMetadataToComponentStatus(
156156
componentStatus.available = componentStatus.version != componentStatus.localVersion
157157
if componentStatus.available {
158158
componentStatus.availableReason = fmt.Sprintf("custom version %s is not equal to local version %s", constraint, componentStatus.localVersion)
159+
componentStatus.customVersionUpdate = true
159160
}
160161
} else if !componentExists {
161162
componentStatus.available = false

internal/ota/state.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type UpdateStatus struct {
3838
Remote *UpdateMetadata `json:"remote"`
3939
SystemUpdateAvailable bool `json:"systemUpdateAvailable"`
4040
AppUpdateAvailable bool `json:"appUpdateAvailable"`
41+
WillDisableAutoUpdate bool `json:"willDisableAutoUpdate"`
4142

4243
// only available for debugging and won't be exported
4344
SystemUpdateAvailableReason string `json:"-"`
@@ -59,6 +60,7 @@ type componentUpdateStatus struct {
5960
pending bool
6061
available bool
6162
availableReason string // why the component is available or not available
63+
customVersionUpdate bool
6264
version string
6365
localVersion string
6466
url string
@@ -98,6 +100,9 @@ type HwRebootFunc func(force bool, postRebootAction *PostRebootAction, delay tim
98100
// ResetConfigFunc is a function that resets the config
99101
type ResetConfigFunc func() error
100102

103+
// SetAutoUpdateFunc is a function that sets the auto-update state
104+
type SetAutoUpdateFunc func(enabled bool) (bool, error)
105+
101106
// GetHTTPClientFunc is a function that returns the HTTP client
102107
type GetHTTPClientFunc func() HttpClient
103108

@@ -125,6 +130,7 @@ type State struct {
125130
getLocalVersion GetLocalVersionFunc
126131
onStateUpdate OnStateUpdateFunc
127132
resetConfig ResetConfigFunc
133+
setAutoUpdate SetAutoUpdateFunc
128134
}
129135

130136
func toUpdateStatus(appUpdate *componentUpdateStatus, systemUpdate *componentUpdateStatus, error string) *UpdateStatus {
@@ -145,6 +151,7 @@ func toUpdateStatus(appUpdate *componentUpdateStatus, systemUpdate *componentUpd
145151
SystemUpdateAvailableReason: systemUpdate.availableReason,
146152
AppUpdateAvailable: appUpdate.available,
147153
AppUpdateAvailableReason: appUpdate.availableReason,
154+
WillDisableAutoUpdate: appUpdate.customVersionUpdate || systemUpdate.customVersionUpdate,
148155
Error: error,
149156
}
150157
}
@@ -180,6 +187,7 @@ type Options struct {
180187
ReleaseAPIEndpoint string
181188
ResetConfig ResetConfigFunc
182189
SkipConfirmSystem bool
190+
SetAutoUpdate SetAutoUpdateFunc
183191
}
184192

185193
// NewState creates a new OTA state
@@ -198,6 +206,7 @@ func NewState(opts Options) *State {
198206
componentUpdateStatuses: components,
199207
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
200208
resetConfig: opts.ResetConfig,
209+
setAutoUpdate: opts.SetAutoUpdate,
201210
}
202211
if !opts.SkipConfirmSystem {
203212
go s.confirmCurrentSystem()

ota.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func initOta() {
3131
GetLocalVersion: GetLocalVersion,
3232
HwReboot: hwReboot,
3333
ResetConfig: rpcResetConfig,
34+
SetAutoUpdate: rpcSetAutoUpdateState,
3435
OnStateUpdate: func(state *ota.RPCState) {
3536
triggerOTAStateUpdate(state)
3637
},
@@ -82,6 +83,7 @@ func getUpdateStatus(includePreRelease bool) (*ota.UpdateStatus, error) {
8283
DeviceID: GetDeviceID(),
8384
IncludePreRelease: includePreRelease,
8485
})
86+
8587
// to ensure backwards compatibility,
8688
// if there's an error, we won't return an error, but we will set the error field
8789
if err != nil {
@@ -91,6 +93,11 @@ func getUpdateStatus(includePreRelease bool) (*ota.UpdateStatus, error) {
9193
updateStatus.Error = err.Error()
9294
}
9395

96+
// otaState doesn't have the current auto-update state, so we need to get it from the config
97+
if updateStatus.WillDisableAutoUpdate {
98+
updateStatus.WillDisableAutoUpdate = config.AutoUpdateEnabled
99+
}
100+
94101
otaLogger.Info().Interface("updateStatus", updateStatus).Msg("Update status")
95102

96103
return updateStatus, nil

ui/localization/messages/da.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "Systemet er opdateret",
303303
"general_update_updating_description": "Sluk ikke enheden. Denne proces kan tage et par minutter.",
304304
"general_update_updating_title": "Opdatering af din enhed",
305+
"general_update_will_disable_auto_update_description": "Du nedgraderer i øjeblikket til en tidligere version. Automatisk opdatering vil blive deaktiveret, når opdateringen er fuldført, for at forhindre utilsigtede opdateringer.",
305306
"getting_remote_session_description": "Henter beskrivelse af fjernsessionsforsøg {attempt}",
306307
"hardware_backlight_settings_error": "Kunne ikke indstille baggrundsbelysningsindstillinger: {error}",
307308
"hardware_backlight_settings_get_error": "Kunne ikke hente indstillinger for baggrundsbelysning: {error}",

ui/localization/messages/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "Das System ist auf dem neuesten Stand",
303303
"general_update_updating_description": "Bitte schalten Sie Ihr Gerät nicht aus. Dieser Vorgang kann einige Minuten dauern.",
304304
"general_update_updating_title": "Aktualisieren Ihres Geräts",
305+
"general_update_will_disable_auto_update_description": "Sie führen derzeit ein Downgrade auf eine ältere Version durch. Die automatische Aktualisierung wird nach Abschluss des Updates deaktiviert, um versehentliche Aktualisierungen zu verhindern.",
305306
"getting_remote_session_description": "Versuch, eine Beschreibung der Remote-Sitzung abzurufen {attempt}",
306307
"hardware_backlight_settings_error": "Fehler beim Festlegen der Hintergrundbeleuchtungseinstellungen: {error}",
307308
"hardware_backlight_settings_get_error": "Die Einstellungen für die Hintergrundbeleuchtung konnten nicht abgerufen werden: {error}",

ui/localization/messages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "System is up to date",
303303
"general_update_updating_description": "Please don't turn off your device. This process may take a few minutes.",
304304
"general_update_updating_title": "Updating your device",
305+
"general_update_will_disable_auto_update_description": "You're currently downgrading to a previous version. Auto-update will be disabled after the update is completed to prevent accidental updates.",
305306
"getting_remote_session_description": "Getting remote session description attempt {attempt}",
306307
"hardware_backlight_settings_error": "Failed to set backlight settings: {error}",
307308
"hardware_backlight_settings_get_error": "Failed to get backlight settings: {error}",

ui/localization/messages/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "El sistema está actualizado",
303303
"general_update_updating_description": "No apagues tu dispositivo. Este proceso puede tardar unos minutos.",
304304
"general_update_updating_title": "Actualizar su dispositivo",
305+
"general_update_will_disable_auto_update_description": "Estás instalando una versión anterior. La actualización automática se desactivará una vez finalizada la actualización para evitar actualizaciones accidentales.",
305306
"getting_remote_session_description": "Obtener un intento de descripción de sesión remota {attempt}",
306307
"hardware_backlight_settings_error": "No se pudieron configurar los ajustes de la retroiluminación: {error}",
307308
"hardware_backlight_settings_get_error": "No se pudieron obtener los ajustes de la retroiluminación: {error}",

ui/localization/messages/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "Le système est à jour",
303303
"general_update_updating_description": "Veuillez ne pas éteindre votre appareil. Ce processus peut prendre quelques minutes.",
304304
"general_update_updating_title": "Mise à jour de votre appareil",
305+
"general_update_will_disable_auto_update_description": "Vous allez revenir à une version antérieure. La mise à jour automatique sera désactivée une fois l'opération terminée afin d'éviter toute mise à jour accidentelle.",
305306
"getting_remote_session_description": "Obtention d'{attempt} description de session à distance",
306307
"hardware_backlight_settings_error": "Échec de la définition des paramètres de rétroéclairage : {error}",
307308
"hardware_backlight_settings_get_error": "Échec de l'obtention des paramètres de rétroéclairage : {error}",

ui/localization/messages/it.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"general_update_up_to_date_title": "Il sistema è aggiornato",
303303
"general_update_updating_description": "Non spegnere il dispositivo. Questo processo potrebbe richiedere alcuni minuti.",
304304
"general_update_updating_title": "Aggiornamento del dispositivo",
305+
"general_update_will_disable_auto_update_description": "Stai eseguendo il downgrade a una versione precedente. L'aggiornamento automatico verrà disattivato al termine dell'aggiornamento per evitare aggiornamenti accidentali.",
305306
"getting_remote_session_description": "Tentativo di ottenimento della descrizione della sessione remota {attempt}",
306307
"hardware_backlight_settings_error": "Impossibile impostare le impostazioni della retroilluminazione: {error}",
307308
"hardware_backlight_settings_get_error": "Impossibile ottenere le impostazioni della retroilluminazione: {error}",

0 commit comments

Comments
 (0)