feat: refresh managed audio after OTA activation
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
#include "cJSON.h"
|
||||
#include "build_macro.h"
|
||||
#include "ql_log.h"
|
||||
#include "http_downfile.h"
|
||||
#include "ota_fullfota2.h"
|
||||
#include "ota_post_update.h"
|
||||
#include "ota_url_policy.h"
|
||||
|
||||
|
||||
@@ -45,6 +47,7 @@
|
||||
#define OTA_STATE_TMP_FILE "U:/ota_state.tmp"
|
||||
#define OTA_STATE_MAGIC 0x4F544131U
|
||||
#define OTA_STATE_FORMAT_VERSION 1U
|
||||
#define OTA_STATE_FLAG_AUDIO_REFRESH_PREPARED 0x0001U
|
||||
#define OTA_PROMPT_PLAY_TIMEOUT_MS 10000
|
||||
#define OTA_PROMPT_POLL_MS 50
|
||||
|
||||
@@ -110,7 +113,7 @@ int xiaoice_get_play_counter(void);
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint16_t format_version;
|
||||
uint16_t reserved;
|
||||
uint16_t flags;
|
||||
char previous_version[16];
|
||||
char target_version[16];
|
||||
uint32_t checksum;
|
||||
@@ -147,12 +150,56 @@ static uint32_t ota_state_checksum(const ota_state_t *state)
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int ota_state_write(const ota_state_t *state)
|
||||
{
|
||||
ota_state_t persisted;
|
||||
QFILE *fp;
|
||||
int ret;
|
||||
|
||||
if (state == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
persisted = *state;
|
||||
persisted.checksum = 0;
|
||||
persisted.checksum = ota_state_checksum(&persisted);
|
||||
|
||||
fp = ql_fopen(OTA_STATE_TMP_FILE, "wb+");
|
||||
if (fp == NULL) {
|
||||
RLOGE("OTA state open failed: %s", OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_fwrite(&persisted, sizeof(persisted), 1, fp);
|
||||
if (ret != (int)sizeof(persisted)) {
|
||||
RLOGE("OTA state write failed: %d", ret);
|
||||
ql_fclose(fp);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_fsync(fp);
|
||||
ql_fclose(fp);
|
||||
if (ret != 0) {
|
||||
RLOGE("OTA state sync failed: %d", ret);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_rename(OTA_STATE_TMP_FILE, OTA_STATE_FILE);
|
||||
if (ret != 0) {
|
||||
RLOGE("OTA state rename failed: %d", ret);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ota_state_save(const char *previous_version, const char *target_version)
|
||||
{
|
||||
ota_state_t state;
|
||||
QFILE *fp;
|
||||
int ret;
|
||||
|
||||
if (previous_version == NULL || target_version == NULL) {
|
||||
return -1;
|
||||
@@ -163,38 +210,7 @@ static int ota_state_save(const char *previous_version, const char *target_versi
|
||||
state.format_version = OTA_STATE_FORMAT_VERSION;
|
||||
strncpy(state.previous_version, previous_version, sizeof(state.previous_version) - 1);
|
||||
strncpy(state.target_version, target_version, sizeof(state.target_version) - 1);
|
||||
state.checksum = ota_state_checksum(&state);
|
||||
|
||||
fp = ql_fopen(OTA_STATE_TMP_FILE, "wb+");
|
||||
if (fp == NULL) {
|
||||
RLOGE("OTA state open failed: %s", OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_fwrite(&state, sizeof(state), 1, fp);
|
||||
if (ret != (int)sizeof(state)) {
|
||||
RLOGE("OTA state write failed: %d", ret);
|
||||
ql_fclose(fp);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_fsync(fp);
|
||||
ql_fclose(fp);
|
||||
if (ret != 0) {
|
||||
RLOGE("OTA state sync failed: %d", ret);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ql_rename(OTA_STATE_TMP_FILE, OTA_STATE_FILE);
|
||||
if (ret != 0) {
|
||||
RLOGE("OTA state rename failed: %d", ret);
|
||||
ql_remove(OTA_STATE_TMP_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ota_state_write(&state);
|
||||
}
|
||||
|
||||
static int ota_state_load(ota_state_t *state)
|
||||
@@ -296,6 +312,39 @@ static int ota_compare_version(const char *left, const char *right, int *result)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ota_prepare_post_update_audio_refresh(void)
|
||||
{
|
||||
ota_state_t state;
|
||||
char current_version[64] = {0};
|
||||
int compare_result;
|
||||
|
||||
if (ota_state_load(&state) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
hal_os_get_build_ver(current_version);
|
||||
if (ota_compare_version(current_version, state.target_version,
|
||||
&compare_result) != 0 ||
|
||||
compare_result != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((state.flags & OTA_STATE_FLAG_AUDIO_REFRESH_PREPARED) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("OTA target APP is running; refreshing managed audio files\r\n");
|
||||
app_file_check_del();
|
||||
|
||||
state.flags |= OTA_STATE_FLAG_AUDIO_REFRESH_PREPARED;
|
||||
if (ota_state_write(&state) != 0) {
|
||||
RLOGE("mark post-update audio refresh prepared failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ==================== 解析函数 ==================== */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user