void InitButtons(void);
void InitBasicdata(void);
void UpdateView(int date);
+ void UpdateSginandOperate(void);
private:
UIScrollView *scrollView_{nullptr};
void UpdateCheckView(int date);
/* ---------------------------------- 文件修复
* ---------------------------------- */
+ //获取信号值
+ uint8_t GetSignal() const;
+ //获取运营商
+ std::string GetOperator() const;
//获取版本号
std::string GetVersion() const;
+ //获取下载地址
+ std::string GetRepairUrl() const;
+ //唤醒Cat1
+ void uapi_cat1_wakeup_cat1(bool wakeupstate);
//进行修复开始
bool RepairStart();
// 进行修复结束
bool RepairEnd();
//更新修复界面
void UpdateRepairView(int date);
+ //更新信号与运营商
+ void UpdateSginOperate();
+ //获取下载数
+ uint16_t GetRepairCount() const;
+ //设置下载数
+ void SetRepairCount(uint16_t count);
+ //增加下载数
+ void AddRepairCount();
+
/* ---------------------------------- map管理
* --------------------------------- */
// 设置状态
ResourceCheckItem Filenames[MAX_RESOURCE_CHECK_FILE_NUM] = {0,
nullptr}; // 列表
bool resource_check_state{false}; // 资源检查状态
+ uint16_t repair_count{0}; //下载数
};
} // namespace OHOS
static constexpr const char *RE_START = "restart";
static constexpr const char *CHECK_FILE_LIST = "check_file_list";
static constexpr const char *WAKE_UP = "wake_up";
-static constexpr const char *REPAIR_FILE = "REPAIR_FILE";
+static constexpr const char *REPAIR_FILE_START = "repair_file";
class SafeModeManagerView;
class SafeModeManagerPresenter : public Presenter<SafeModeManagerView>,
downingLabel_->SetViewId("label11");
downingLabel_->SetStyle(STYLE_TEXT_FONT, 26);
downingLabel_->SetText("downing...");
- downingLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ downingLabel_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
downingLabel_->SetTextColor(
Color::GetColorFromRGBA(0xef, 0x0e, 0x0e, 0xff));
downingLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- downingLabel_->SetRollSpeed(0);
+ downingLabel_->SetRollSpeed(70);
downingLabel_->SetFont(GILROY_BOLD_FONT, 26);
scrollView_->Add(downingLabel_);
downingLabel_->SetVisible(false);
repairButton_ = new UILabelButtonExt();
repairButton_->SetPosition(265, 245);
repairButton_->Resize(160, 80); // Updated size
- repairButton_->SetViewId("repairButton");
+ repairButton_->SetViewId(REPAIR_FILE_START);
repairButton_->SetText("Repair File");
repairButton_->SetFont(GILROY_BOLD_FONT,
26); // Updated font size
repairButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff14ff00);
scrollView_->Add(repairButton_);
repairButton_->SetVisible(true);
+ // 设置点击事件监听器
+ UIView::OnClickListener *repairclickListener = (UIView::OnClickListener *)
+ OHOS::SafeModeManagerPresenter::GetInstance();
+ if (repairclickListener == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "repairclickListener is null");
+ return;
+ }
+ repairButton_->SetOnClickListener(repairclickListener);
}
// Wake Up Button
wakeUpButton_ = new UILabelButtonExt();
wakeUpButton_->SetPosition(45, 245);
wakeUpButton_->Resize(160, 80); // Updated size
- wakeUpButton_->SetViewId("wakeUpButton");
+ wakeUpButton_->SetViewId(WAKE_UP);
wakeUpButton_->SetText("Wake Up");
wakeUpButton_->SetFont(GILROY_BOLD_FONT,
26); // Updated font size
wakeUpButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0c77e6);
scrollView_->Add(wakeUpButton_);
wakeUpButton_->SetVisible(true);
+ // 设置点击事件监听器
+ UIView::OnClickListener *wakeclickListener = (UIView::OnClickListener *)
+ OHOS::SafeModeManagerPresenter::GetInstance();
+ if (wakeclickListener == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wakeclickListener is null");
+ return;
+ }
+ wakeUpButton_->SetOnClickListener(wakeclickListener);
}
}
UIScrollView *RepairView::RepairViewInit() {
// 初始化基本数据
InitBasicdata();
-
+
return scrollView_;
}
-//初始化版本号与运营商
+//初始化版本号与下载总数
void RepairView::InitBasicdata() {
if (versionLabel_ != nullptr) {
+ // 获取版本号
+ std::string version = SafeModeManagerModel::GetInstance()->GetVersion();
+ versionLabel_->SetText(version.c_str());
}
if (downLabel_ != nullptr) {
+ // 获取文件总数
int totalcount = SafeModeManagerModel::GetInstance()->GetFilenamesCount();
std::string total = "total: " + std::to_string(totalcount);
totalLabel_->SetText(total.c_str());
}
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "versionstr: %s, totalstr:%s",
+ versionLabel_->GetText(), totalLabel_->GetText());
+}
+
+//更新信号值与运营商
+void RepairView::UpdateSginandOperate(void) {
+
+ if (signalLabel_ != nullptr) {
+ //获取信号值
+ uint8_t signal = SafeModeManagerModel::GetInstance()->GetSignal();
+ std::string signalStr = "Signal: " + std::to_string(signal);
+ signalLabel_->SetText(signalStr.c_str());
+ }
+ if (operationLabel_ != nullptr) {
+ //获取运营商
+ std::string operate =
+ "Operation" + SafeModeManagerModel::GetInstance()->GetOperator();
+ operationLabel_->SetText(operate.c_str());
+ }
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "signalstr: %s, operate:%s",
+ signalLabel_->GetText(), operationLabel_->GetText());
}
-//æ\9b´æ\96°ä¿¡å\8f·å\80¼ä¸\8eä¸\8bè½½è¿\9b度
+//更新下载进度
void RepairView::UpdateView(int date) {
if (downingLabel_ == nullptr) {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
downingLabel_->SetVisible(true);
}
std::string display = "downing";
+ //下载文件数
+ uint16_t count = SafeModeManagerModel::GetInstance()->GetRepairCount();
+ std::string downcount = "down: " + std::to_string(count);
+ if (downLabel_ != nullptr)
+ downLabel_->SetText(downcount.c_str());
// 检查状态并更新提示文本
if (date >= 0 && date <= 60) {
int progress = date % 4;
#include "broadcast_feature.h"
#include "broadcast_service.h"
+#include "cat1_ctl.h"
+#include "cat1_server.h"
+#include "custom_runtime.h"
#include "custom_utils.h"
#include "graphic_service.h"
+#include "lwip/apps/http_client.h"
+#include "tcxo.h"
#include "thread_adapter.h"
+#include "thread_init.h"
#include "wearable_log.h"
extern "C" bool resfile_checksum_thread(void);
+extern "C" {
+#include "build_version.h"
+const char *get_version_string(void);
+}
static const char *CHECK_DIFFERENTIAL_FILE = "/system/check_differential.txt";
-
-// snicker.com.cn 8089
-// http://snicker.com.cn:8089/FD230/V1.1.14_20240706_182936_CT/update.fwpkg
-// /user/update.fwpkg get_version_string mgdataTimerCallBack
-
namespace OHOS {
SafeModeManagerModel *SafeModeManagerModel::GetInstance(void) {
static SafeModeManagerModel instance;
return &instance;
}
+
+extern "C" {
+
+#include "custom_http_download.h"
+errcode_t http_single_download_stop(void);
+static bool download_repair_file(const char *uristr);
+
+static uint32_t file_total_len = 0;
+static void httpc_download_result(void *arg, httpc_result_t httpc_result,
+ u32_t rx_content_len, u32_t srv_res,
+ err_t err) {
+ printf("httpc_download_result , httpc_result_t %d, rx_content_len %d , "
+ "srv_res %d, err %d\n",
+ httpc_result, rx_content_len, srv_res, err);
+ if (httpc_result == HTTPC_RESULT_OK) {
+ http_single_download_stop();
+ OHOS::SafeModeManagerModel::GetInstance()->AddRepairCount();
+ //开始下一个文件
+ OHOS::SafeModeManagerModel::GetInstance()->RepairStart();
+ } else {
+ //结束
+ OHOS::SafeModeManagerModel::GetInstance()->RepairEnd();
+ }
+ file_total_len = 0;
+ return;
+}
+static err_t httpc_download_headers_done(httpc_state_t *connection, void *arg,
+ struct pbuf *hdr, u16_t hdr_len,
+ u32_t content_len) {
+ printf("httpc_download_headers_done , hdr_len %d ,content_len %d\n", hdr_len,
+ content_len);
+ file_total_len = content_len;
+ return 0;
+}
+static err_t httpc_download_file_recv_ui(httpc_state_t *connection,
+ u32_t rx_len, u32_t rx_total_len) {
+ printf("httpc_download_file_recv_ui recv %d bytes total received %d "
+ "filelen %d\r\n",
+ rx_len, rx_total_len, file_total_len);
+ return 0;
+}
+
+// uir:
+// http://snicker.com.cn:8089/FD230/V1.1.49/user/res/font_bin/ja.bin
+// 服务器:snicker.com.cn:8089
+// 端口:8089
+// 保存路径:/user/res/settings/SETTINGS_SAVEELE.bin
+// 下载文件
+static char *my_strndup(const char *s, size_t n) {
+ char *p = new char[n + 1];
+ if (p) {
+ strncpy(p, s, n);
+ p[n] = '\0';
+ }
+ return p;
+}
+
+static bool download_repair_file(const char *uristr) {
+ if (!uristr) {
+ printf("Error: No repair URL provided.\r\n");
+ return false;
+ }
+
+ char *server = NULL;
+ uint16_t port = 0;
+ char *uri = NULL;
+ char *filepath = NULL;
+
+ // 解析 uristr
+ const char *pos = strstr(uristr, "://");
+ if (pos == NULL) {
+ printf("Error: Invalid URL format.\r\n");
+ return false;
+ }
+
+ pos += 3; // 跳过 "://"
+ const char *port_pos = strchr(pos, ':');
+ const char *uri_pos = strchr(pos, '/');
+
+ if (port_pos && uri_pos) {
+ server = my_strndup(pos, port_pos - pos);
+ port = (uint16_t)atoi(port_pos + 1);
+ uri = strdup(uristr);
+ } else {
+ printf("Error: Missing URI in the URL.\r\n");
+ return false;
+ }
+
+ if (!server || !uri) {
+ printf("Error: Failed to allocate memory for server or uri.\r\n");
+ delete[] server;
+ delete[] uri;
+ return false;
+ }
+
+ // 查找以 'V' 开头的版本号
+ const char *version_pos = strstr(uri, "/V");
+ if (version_pos) {
+ const char *first_slash_after_v = strchr(version_pos + 2, '/');
+ if (first_slash_after_v) {
+ filepath =
+ my_strndup(first_slash_after_v + 1, strlen(first_slash_after_v + 1));
+ } else {
+ filepath = strdup("");
+ }
+ } else {
+ filepath = strdup("");
+ }
+
+ // 打印解析结果
+ printf("download_repair_file called with parameters:\n");
+ printf(" Server: %s\n", server);
+ printf(" Port: %d\n", port);
+ printf(" URI: %s\n", uri);
+ printf(" Filepath: %s\n", filepath);
+
+ // // 拼接服务器域名
+ // size_t server_with_port_len = strlen(server) + 6; //
+ // 考虑端口号长度加上分隔符长度 char *server_with_port = new
+ // char[server_with_port_len]; snprintf(server_with_port,
+ // server_with_port_len, "%s:%d", server, port);
+
+ // 通讯开始,唤醒 cat1
+ uapi_cat1_keep_wakeup(1);
+ // 开始下载
+ errcode_t rett = http_single_download_start(
+ (uint8_t *)server, port, (uint8_t *)uri, (uint8_t *)filepath,
+ httpc_download_result, httpc_download_headers_done,
+ httpc_download_file_recv_ui);
+ printf("download_repair_file: %d \r\n", rett);
+
+ // 释放内存
+ delete[] server;
+ delete[] uri;
+ delete[] filepath;
+ if (rett != ERRCODE_SUCC) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "download_repair_file: %d \r\n",
+ rett);
+ return false;
+ }
+
+ return true;
+}
+}
/* ---------------------------------- map修改 ---------------------------------
*/
/*显示状态map*/
/* ---------------------------------- 下载修复文件
* ---------------------------------- */
+//下载数
+uint16_t SafeModeManagerModel::GetRepairCount() const { return repair_count; }
+void SafeModeManagerModel::SetRepairCount(uint16_t count) {
+ repair_count = count;
+}
+//获取版本号
+std::string SafeModeManagerModel::GetVersion() const {
+ std::string version = std::string("V") + get_version_string();
+ return version;
+}
+//增加下载数
+void SafeModeManagerModel::AddRepairCount() { repair_count++; }
+//获取信号值sign
+uint8_t SafeModeManagerModel::GetSignal() const {
+ return uapi_dev_runtime_get_cat1_signal();
+}
+//获取运营商
+std::string SafeModeManagerModel::GetOperator() const {
+ std::string operator_name = uapi_dev_runtime_get_cat1_operator();
+ return operator_name;
+}
+/*获取下载http地址
+ http://snicker.com.cn:8089/FD230/V1.1.14_20240706_182936_CT/filename
+*/
+std::string SafeModeManagerModel::GetRepairUrl() const {
+ std::string filename = GetFilenamesListItems()[repair_count].filename;
+ std::string url =
+ "http://snicker.com.cn:8089/FD230/" + GetVersion() + filename;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetRepairUrl url: %s", url.c_str());
+ return url;
+}
+//控制cat1
+void SafeModeManagerModel::uapi_cat1_wakeup_cat1(bool wakeupstate) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wakeupstate: %d", wakeupstate);
+ uapi_set4GCapability(wakeupstate);
+ return;
+}
+//开始修复
bool SafeModeManagerModel::RepairStart() {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Repair");
+ if (download_repair_file(GetRepairUrl().c_str()) == false) {
+ RepairEnd();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RepairEnd");
+ return false;
+ }
+ return true;
+}
+// 0.下载失败
+// 1.下载成功
+bool SafeModeManagerModel::RepairEnd() {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RepairEnd");
+ if (GetRepairCount() != GetFilenamesCount()) {
+ //下载失败
+ SetState(Safe_State::REPAIR_FILE, false);
+ http_single_download_stop();
+ uapi_dev_runtime_set_repair_download_status(3);
+ return false;
+ } else {
+ //下载成功
+ SetState(Safe_State::REPAIR_FILE, true);
+ uapi_dev_runtime_set_repair_download_status(2);
+ }
+ repair_count = 0;
return true;
}
// 更新文件下载
void SafeModeManagerModel::UpdateRepairView(int date) {
auto safeModeView = SafeModeManagerView::GetInstance();
if (safeModeView != nullptr) {
- auto RepairView = ResourceCheckView::GetInstance();
- if (safeModeView->GetSafeScrollView(VIEW_RESOURCE_CHECK) != nullptr) {
+ auto RepairView = RepairView::GetInstance();
+ if (safeModeView->GetSafeScrollView(VIEW_REPAIR_FILE) != nullptr) {
RepairView->UpdateView(date);
}
}
}
+//更新信号与运营商
+void SafeModeManagerModel::UpdateSginOperate() {
+ auto safeModeView = SafeModeManagerView::GetInstance();
+ if (safeModeView != nullptr) {
+ auto RepairView = RepairView::GetInstance();
+ if (safeModeView->GetSafeScrollView(VIEW_REPAIR_FILE) != nullptr) {
+ RepairView->UpdateSginandOperate();
+ }
+ }
+}
} // namespace OHOS
\ No newline at end of file
}
bool SafeModeManagerPresenter::OnDrag(UIView &view, const DragEvent &event) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::OnClick");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::OnDrag");
SafeModeManagerView *p_SafeModeManagerView =
SafeModeManagerView::GetInstance();
if (p_SafeModeManagerView == nullptr) {
}
bool SafeModeManagerPresenter::OnClick(UIView &view, const ClickEvent &event) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,
- "SafeModeManagerPresenter::OnClick %s" view.GetViewId());
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::OnClick %s",
+ view.GetViewId());
SafeModeManagerView *p_SafeModeManagerView =
SafeModeManagerView::GetInstance();
if (p_SafeModeManagerView == nullptr) {
/*修复 */
p_SafeModeManagerView->ChangeView(VIEW_RESOURCE_CHECK, VIEW_REPAIR_FILE);
}
- if (strcmp(view.GetViewId(), REPAIR_FILE) == 0) {
+ //点击下载修复文件
+ if (strcmp(view.GetViewId(), REPAIR_FILE_START) == 0) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ "SafeModeManagerPresenter::OnClick REPAIR_FILE_START");
if (SafeModeManagerModel::GetInstance()->IsState(Safe_State::REPAIR_FILE) ==
false &&
uapi_dev_runtime_get_repair_download_status() == 0) {
SafeModeManagerModel::GetInstance()->RepairStart();
}
}
+ //点击唤醒cat1
+ if (strcmp(view.GetViewId(), WAKE_UP) == 0) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ "SafeModeManagerPresenter::OnClick WAKE_CAT1");
+ // 唤醒cat1
+ SafeModeManagerModel::GetInstance()->uapi_cat1_wakeup_cat1(true);
+ }
return true;
}
void SafeModeManagerPresenter::OnTickEvent() {
// 开始校验文件
uint8_t check_state = uapi_dev_runtime_get_checkres_status();
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,
+ "SafeModeManagerPresenter::OnTickEvent %d", check_state);
switch (check_state) {
case CHECKING: {
// 处理正在校验的状态
default:
break;
}
+
//下载状态
uint8_t download_state = uapi_dev_runtime_get_repair_download_status();
+
+ //如果下载数等于总数 -> 下载成功
+ if (SafeModeManagerModel::GetInstance()->GetRepairCount() ==
+ SafeModeManagerModel::GetInstance()->GetCheckFileCount() &&
+ download_state == 1) {
+ // 下载完成 标志位设置为 2
+ download_state = 2;
+ SafeModeManagerModel::GetInstance()->RepairEnd();
+ }
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "download state %d", download_state);
switch (download_state) {
case 1:
//下载中
case 2:
//下载成功
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "download success");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "download success");
GraphicService::GetInstance()->PostGraphicEvent(
std::bind(&OHOS::SafeModeManagerModel::UpdateRepairView,
OHOS::SafeModeManagerModel::GetInstance(), 61));
case 3:
//下载失败
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "download failed");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "download failed");
GraphicService::GetInstance()->PostGraphicEvent(
std::bind(&OHOS::SafeModeManagerModel::UpdateRepairView,
OHOS::SafeModeManagerModel::GetInstance(), -1));
default:
break;
}
+ //处于修复界面,更新信号
+ SafeModeManagerView *p_SafeModeManagerView =
+ SafeModeManagerView::GetInstance();
+ if (p_SafeModeManagerView == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ " SafeModeManagerView::GetInstance fail!");
+ return;
+ }
+ if (p_SafeModeManagerView->GetSafeScrollView(VIEW_REPAIR_FILE)->IsVisible()) {
+ GraphicService::GetInstance()->PostGraphicEvent(
+ std::bind(&OHOS::SafeModeManagerModel::UpdateSginOperate,
+ OHOS::SafeModeManagerModel::GetInstance()));
+ }
}
bool SafeModeManagerPresenter::OnKeyAct(UIView &view, const KeyEvent &event) {
unsigned short keyID = event.GetKeyId();
static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
SafeModeManagerView::SafeModeManagerView() {
- /*开启省电模式*/
- uapi_enter_power_saving_mode();
+ // /*开启省电模式*/
+ // uapi_enter_power_saving_mode();
g_pSafeModeManagerView = this;
}
* httpc_headers_done_fn callback_headers_done_fn,
* httpc_file_rx_fn callback_file_rx_fn
*/
+// static httpc_connection_t settings = {0};
errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *uri, uint8_t *otadatapath, httpc_result_fn callback_result_fn, httpc_headers_done_fn callback_headers_done_fn, httpc_file_rx_fn callback_file_rx_fn)
{
settings.use_post = 0 ;
httpc_state_t* connection=NULL;
+ printf(" http_single_download_start Server: %s\n", server);
+ printf(" http_single_download_start Port: %d\n", port);
+ printf(" http_single_download_start URI: %s\n", uri);
+ printf(" http_single_download_start Filepath: %s\n", otadatapath);
+
err_t rett = httpc_get_file_dns_to_disk(
(const char*) server,
port,