* Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
*/
-#include "DialLabelView.h"
+#include "main/dial/DialLabelView.h"
#include "securec.h"
-namespace OHOS
+namespace OHOS {
+DialLabelView::DialLabelView(void)
{
- DialLabelView::DialLabelView(void)
- {
- }
+}
- DialLabelView::~DialLabelView(void)
- {
- if (text_ != nullptr)
- {
- UIFree(text_);
- }
+DialLabelView::~DialLabelView(void)
+{
+ if (text_ != nullptr) {
+ UIFree(text_);
}
+}
- bool DialLabelView::SetText(const char *text)
- {
- if (text == nullptr)
- {
- return false;
- }
- UILabel::SetText(text);
- return true;
+bool DialLabelView::SetText(const char* text)
+{
+ if (text == nullptr) {
+ return false;
}
+ UILabel::SetText(text);
+ return true;
+}
- void DialLabelView::SetTextWithWildcardInner(const char *text)
- {
- if (strcmp(text, dstBuf_) == 0)
- {
- return;
- }
- memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_));
- if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK)
- {
- GRAPHIC_LOGE("strcpy_s failed!\n");
- }
- UILabel::SetText(dstBuf_);
+void DialLabelView::SetTextWithWildcardInner(const char* text)
+{
+ if (strcmp(text, dstBuf_) == 0) {
+ return;
}
+ memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_));
+ if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) {
+ GRAPHIC_LOGE("strcpy_s failed!\n");
+ }
+ UILabel::SetText(dstBuf_);
+}
- bool DialLabelView::SetTextWithWildcard(const char *text)
- {
- if (text == nullptr)
- {
- return false;
- }
- if (text_ != nullptr)
- {
- if (strcmp(text, text_) == 0)
- {
- return true;
- }
- UIFree(text_);
- text_ = nullptr;
+bool DialLabelView::SetTextWithWildcard(const char* text)
+{
+ if (text == nullptr) {
+ return false;
+ }
+ if (text_ != nullptr) {
+ if (strcmp(text, text_) == 0) {
+ return true;
}
+ UIFree(text_);
+ text_ = nullptr;
+ }
- uint32_t textLen = static_cast<uint32_t>(strlen(text));
- if (textLen > (MAX_BUF_SIZE - 1))
- {
- return false;
- }
- text_ = static_cast<char *>(UIMalloc(++textLen));
- if (text_ == nullptr)
- {
- return false;
- }
- if (strcpy_s(text_, textLen, text) != EOK) {
- GRAPHIC_LOGE("strcpy_s failed");
- UIFree(text_);
- text_ = nullptr;
- return false;
- }
- return true;
+ uint32_t textLen = static_cast<uint32_t>(strlen(text));
+ if (textLen > (MAX_BUF_SIZE - 1)) {
+ return false;
+ }
+ text_ = static_cast<char*>(UIMalloc(++textLen));
+ if (text_ == nullptr) {
+ return false;
}
+ if (strcpy_s(text_, textLen, text) != EOK) {
+ GRAPHIC_LOGE("strcpy_s failed");
+ UIFree(text_);
+ text_ = nullptr;
+ return false;
+ }
+ return true;
+}
- void DialLabelView::HandleTextData(const std::string *data, uint16_t num)
- {
- if (num == 0 || data == nullptr)
- {
- // GRAPHIC_LOGE("Invalid data or num.");
+void DialLabelView::HandleTextData(const std::string* data, uint16_t num)
+{
+ char tempBuf[MAX_BUF_SIZE] = {0};
+ if (num == 1) {
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()) < 0) {
+ GRAPHIC_LOGE("snprintf_s failed.\n");
return;
}
-
- // printf("HandleTextData called with num: %d, data[0]: %s\n", num, data[0].c_str());
-
- char tempBuf[MAX_BUF_SIZE] = {0};
-
- int ret;
- switch (num)
- {
- case 1:
- ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str());
- break;
- case 2:
- ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str());
- break;
- case 3:
- ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
- data[0].c_str(), "年", data[1].c_str(), "月", data[2].c_str(), "日");
- break;
- case 4: /*8月7号 星期三*/
- ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
- data[0].c_str(), data[1].c_str(), data[2].c_str());
- break;
- default:
- GRAPHIC_LOGE("Invalid num: %d. Max size is 3.\n", num);
+ } else if (num == 2) { // 2: wildcard cnt
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()) < 0) {
+ GRAPHIC_LOGE("snprintf_s failed.\n");
return;
}
-
- if (ret < 0)
- {
- GRAPHIC_LOGE("snprintf_s failed with error code: %d\n", ret);
+ } else if (num == 3) { // 3: wildcard cnt
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
+ data[0].c_str(), data[1].c_str(), data[2].c_str()) < 0) { // 2: index
+ GRAPHIC_LOGE("snprintf_s failed.\n");
return;
}
-
- // printf("Constructed tempBuf: %s\n", tempBuf);
- SetTextWithWildcardInner(tempBuf);
+ } else {
+ GRAPHIC_LOGE("max size is 3.\n");
+ return;
}
- void DialLabelView::HandleFloatData(const float *data, uint16_t num)
- {
- char tempBuf[MAX_BUF_SIZE] = {0};
- if (num == 1)
- {
- if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0)
- {
- GRAPHIC_LOGE("snprintf_s failed.\n");
- return;
- }
- }
- else if (num == 2)
- { // 2: wildcard cnt
- if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0)
- {
- GRAPHIC_LOGE("snprintf_s failed.\n");
- return;
- }
- }
- else if (num == 3)
- { // 3: wildcard cnt
- if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0)
- { // 2: index
- GRAPHIC_LOGE("snprintf_s failed.\n");
- return;
- }
+ SetTextWithWildcardInner(tempBuf);
+}
+
+void DialLabelView::HandleFloatData(const float* data, uint16_t num)
+{
+ char tempBuf[MAX_BUF_SIZE] = {0};
+ if (num == 1) {
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) {
+ GRAPHIC_LOGE("snprintf_s failed.\n");
+ return;
}
- else
- {
- GRAPHIC_LOGE("max size is 3.\n");
+ } else if (num == 2) { // 2: wildcard cnt
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) {
+ GRAPHIC_LOGE("snprintf_s failed.\n");
return;
}
- SetTextWithWildcardInner(tempBuf);
- }
-
- void DialLabelView::HandleFloatData(float data)
- {
- char tempBuf[MAX_BUF_SIZE] = {0};
- if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0)
- {
+ } else if (num == 3) { // 3: wildcard cnt
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) { // 2: index
GRAPHIC_LOGE("snprintf_s failed.\n");
return;
}
- SetTextWithWildcardInner(tempBuf);
+ } else {
+ GRAPHIC_LOGE("max size is 3.\n");
+ return;
}
- void DialLabelView::SetLang(uint8_t lang)
- {
- language_ = lang;
- OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId());
+ SetTextWithWildcardInner(tempBuf);
+}
+
+void DialLabelView::HandleFloatData(float data)
+{
+ char tempBuf[MAX_BUF_SIZE] = {0};
+ if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) {
+ GRAPHIC_LOGE("snprintf_s failed.\n");
+ return;
}
+ SetTextWithWildcardInner(tempBuf);
+}
- void DialLabelView::OnLangChange(uint8_t langId)
- {
- if (language_ == FontGlobalManager::INVALID_LANG_ID)
- {
- SetVisible(true);
- }
- else if (language_ == langId)
- {
- SetVisible(true);
- }
- else
- {
- SetVisible(false);
- }
+void DialLabelView::SetLang(uint8_t lang)
+{
+ language_ = lang;
+ OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId());
+}
+
+void DialLabelView::OnLangChange(uint8_t langId)
+{
+ if (language_ == FontGlobalManager::INVALID_LANG_ID) {
+ SetVisible(true);
+ } else if (language_ == langId) {
+ SetVisible(true);
+ } else {
+ SetVisible(false);
}
+}
}
\ No newline at end of file
*/
#include <string>
+#include <unistd.h>
#include "dirent.h"
-#include "DialBinParser.h"
+#include "main/DialBinParser.h"
#include "UiConfig.h"
-#include "WatchInterface.h"
+#include "main/dial/WatchInterface.h"
#include "gfx_utils/vector.h"
#include "common/screen.h"
-#include "MainModel.h"
-#include "MainViewSample.h"
-#include "SetDialModel.h"
+#include "main/MainModel.h"
+#include "main/MainViewSample.h"
+#include "set_dial/SetDialModel.h"
#include "graphic_service.h"
#include "NativeAbility.h"
+#include "graphic_mutex.h"
+#include "set_dial/SetDialModel.h"
+#include "set_dial/SetDialPresenter.h"
+#include "power_display_service.h"
using namespace OHOS;
namespace {
-struct {
- Graphic::Vector<std::string> fileNames; // only for 3.0
- Graphic::Vector<watch_dial_info> watchInfo; // only for 3.0
-} g_info;
+struct WatchInfoInner {
+ std::string fileName;
+ watch_dial_info watchInfo;
+};
+
+Graphic::Vector<WatchInfoInner> g_info;
+GraphicMutex g_mutex;
+GraphicCond g_cond;
+bool g_eventFinished = true;
+const uint16_t INVALID_INFO_INDEX = 0xFFFF;
bool GetActiveWatchPath(std::string &path)
{
return false;
}
-bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview)
+bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview, bool isNeedVerify = false)
{
const std::string type(".bin");
if (!(fileName.length() > type.length() &&
FILE *file = fopen(fileName.c_str(), "rb");
bool isSuccess = false;
if (file != nullptr) {
- isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(file, &preview);
+ isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fileName, file, &preview, isNeedVerify);
fclose(file);
}
return isSuccess;
return true;
}
-#define APP_DIAL_PATH "user/dial/" //为了编译过加的
-
-bool GetAllWatchInfo()
+void RefreshAllWatchInfo()
{
- g_info.fileNames.Clear();
- g_info.watchInfo.Clear();
+ g_info.Clear();
struct dirent *direntp = nullptr;
-
- // ��Ŀ¼
+ // 打开目录
DIR *dirp = opendir(APP_DIAL_PATH);
- bool isSuccess = true;
- // �����ļ�
+ // 遍历文件
DialPreviewInfo info;
watch_dial_info watchInfo;
std::string activePath;
if (dirp != nullptr) {
while ((direntp = readdir(dirp)) != nullptr) {
std::string fileName = std::string(APP_DIAL_PATH) + std::string("/") + std::string(direntp->d_name);
- isSuccess = GetPreviewInfo(fileName, info);
- if (!isSuccess) {
+ if (!GetPreviewInfo(fileName, info)) {
continue;
}
const std::string lowestVersion("3.0");
std::string curVersion(info.protocolVersion);
if (curVersion >= lowestVersion) {
- isSuccess = ConvertPreview2WatchDialInfo(info, watchInfo);
- if (!isSuccess) {
+ if (!ConvertPreview2WatchDialInfo(info, watchInfo)) {
break;
}
watchInfo.install_state = true;
watchInfo.is_current_watch = isActiveExist ? (activePath == fileName) : false;
- g_info.fileNames.PushBack(fileName);
- g_info.watchInfo.PushBack(watchInfo);
+ g_info.PushBack({fileName, watchInfo});
}
}
}
- // �ر�Ŀ¼
+ // 关闭目录
closedir(dirp);
- return isSuccess;
}
-} // namespace
-bool GetAllWatchFaceInfo(watch_dial_info *info, uint8_t *num, uint8_t maxCnt)
+inline bool IsFileExists(const std::string &file)
+{
+ return access(file.c_str(), F_OK) == 0;
+}
+
+uint16_t FindMaxVersionIndex(uint16_t indexArray[], uint16_t num)
+{
+ if (num == 0) {
+ return INVALID_INFO_INDEX;
+ }
+
+ if (num == 0) {
+ return indexArray[0];
+ }
+ std::string version = reinterpret_cast<char *>(g_info[indexArray[0]].watchInfo.watch_version);
+ uint16_t index = 0;
+ for (uint16_t i = 1; i < num; ++i) {
+ std::string curVerion = std::string(reinterpret_cast<char *>(g_info[indexArray[i]].watchInfo.watch_version));
+ if (curVerion > version) {
+ version = curVerion;
+ index = i;
+ }
+ }
+ if (num > 1) {
+ GRAPHIC_LOGE("There are watches with the same uuid. %u", g_info[indexArray[index]].watchInfo.uuid);
+ }
+ index = indexArray[index];
+ return index;
+}
+
+void GetWatchInfo(uint32_t uuid, uint16_t &index)
+{
+ index = INVALID_INFO_INDEX;
+ if (g_info.IsEmpty()) {
+ RefreshAllWatchInfo();
+ }
+ const uint16_t MAX_INFO_NUM = 128;
+ static uint16_t indexArray[MAX_INFO_NUM];
+ uint16_t num = 0;
+ std::string activePath;
+ bool isActive = GetActiveWatchPath(activePath);
+ bool isNeedRequery = false;
+ for (uint16_t i = 0; i < g_info.Size(); ++i) {
+ if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) {
+ if (IsFileExists(g_info[i].fileName)) {
+ g_info[i].watchInfo.is_current_watch = isActive ? (g_info[i].fileName == activePath) : false;
+ indexArray[num++] = i;
+ } else {
+ RefreshAllWatchInfo();
+ isNeedRequery = true;
+ break;
+ }
+ }
+ }
+
+ if (!isNeedRequery) {
+ index = FindMaxVersionIndex(indexArray, num);
+ return;
+ }
+ num = 0;
+ for (uint16_t i = 0; i < g_info.Size(); ++i) {
+ if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) {
+ indexArray[num++] = i;
+ }
+ }
+ index = FindMaxVersionIndex(indexArray, num);
+}
+
+void TryToTurnOnScreen()
+{
+ const power_display_svr_api_t *ctx = power_display_svr_get_api();
+ if (ctx == nullptr) {
+ return;
+ }
+ if (ctx->get_screen_state != nullptr && ctx->get_screen_state() != SCREEN_ON) {
+ if (ctx->turn_on_screen != nullptr) {
+ ctx->turn_on_screen();
+ }
+ }
+}
+} // anonymous namespace
+
+bool GetAllWatchFaceInfo(watch_dial_info **info, uint8_t *num)
{
if (info == nullptr || num == nullptr) {
GRAPHIC_LOGE("para error!");
return false;
}
- if (!GetAllWatchInfo()) {
- GRAPHIC_LOGE("failed to get all watch info.");
- return false;
+ GraphicLockGuard guard(g_mutex);
+ while (!g_eventFinished) {
+ g_cond.Wait(g_mutex);
}
- if (g_info.watchInfo.Size() > maxCnt) {
- GRAPHIC_LOGE("mem is not enough.");
- return false;
- }
- *num = g_info.watchInfo.Size();
+ RefreshAllWatchInfo();
+ *num = g_info.Size();
if (*num == 0) {
- return false;
+ *info = nullptr;
+ return true;
}
- if (memcpy_s(info,
- g_info.watchInfo.Size() * sizeof(watch_dial_info),
- &g_info.watchInfo[0],
- g_info.watchInfo.Size() * sizeof(watch_dial_info)) != 0) {
- GRAPHIC_LOGE("copy info error!");
+ watch_dial_info *mem = static_cast<watch_dial_info *>(malloc(*num * sizeof(watch_dial_info)));
+ if (mem == nullptr) {
+ GRAPHIC_LOGE("failed to malloc");
return false;
}
+ for (uint16_t i = 0; i < g_info.Size(); ++i) {
+ memcpy_s(&mem[i], sizeof(watch_dial_info), &g_info[i].watchInfo, sizeof(watch_dial_info));
+ }
+ *info = mem;
return true;
}
GRAPHIC_LOGE("para error!");
return false;
}
- if (!GetAllWatchInfo()) {
- GRAPHIC_LOGE("failed to get all watch info.");
+
+ uint16_t index = INVALID_INFO_INDEX;
+ GraphicLockGuard guard(g_mutex);
+ while (!g_eventFinished) {
+ g_cond.Wait(g_mutex);
+ }
+ GetWatchInfo(uuid, index);
+ if (index == INVALID_INFO_INDEX) {
+ GRAPHIC_LOGE("uuid %u does not exist", uuid);
return false;
}
- for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
- if (g_info.watchInfo[i].uuid == uuid) {
- *watch = g_info.watchInfo[i];
- return true;
- }
- }
- return false;
+ memcpy_s(watch, sizeof(watch_dial_info), &g_info[index].watchInfo, sizeof(watch_dial_info));
+ return true;
}
bool GetWatchCapability(watch_dev_cap_info *capability)
bool SetCurrentWatchFace(uint32_t uuid)
{
- if (!GetAllWatchInfo()) {
- GRAPHIC_LOGE("failed to get all watch info.");
+ uint16_t index = INVALID_INFO_INDEX;
+ GraphicLockGuard guard(g_mutex);
+ while (!g_eventFinished) {
+ g_cond.Wait(g_mutex);
+ }
+ GetWatchInfo(uuid, index);
+ if (index == INVALID_INFO_INDEX) {
+ GRAPHIC_LOGE("uuid %u does not exist", uuid);
return false;
}
- watch_dial_info info;
- uint16_t index = 0;
- bool isExists = false;
- for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
- if (uuid == g_info.watchInfo[i].uuid) {
- isExists = true;
- info = g_info.watchInfo[i];
- index = i;
- break;
- }
- }
- if (!isExists) {
- GRAPHIC_LOGE("uuid does not exist!");
- return false;
+ DialSetting setting = MainModel::GetInstance().GetDialSetting();
+ setting.dialFlag = 1;
+ setting.dialFullName = g_info[index].fileName;
+ if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) {
+ GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+ if (SetDialPresenter::GetCurrentInstance() != nullptr) {
+ SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting);
+ }
+ });
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+ return true;
}
- if (info.is_current_watch) {
+ if (g_info[index].watchInfo.is_current_watch) {
return true;
}
-
- DialSetting setting = MainModel::GetInstance().GetDialSetting();
- setting.dialFlag = 1;
- setting.dialFullName = g_info.fileNames[index];
+ g_eventFinished = false;
GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+ GraphicLockGuard guardGraphic(g_mutex);
MainModel::GetInstance().GetDialSetting() = setting;
- #ifdef fd230_650
MainModel::GetInstance().AddDialSetting(setting);
- #endif
- if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
- #ifdef fd230_650
+ if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) {
MainViewSample::GetInstance()->ReloadWatchFace();
- #endif
}
+ g_eventFinished = true;
+ g_cond.Signal();
});
+ TryToTurnOnScreen();
return true;
}
bool UninstallWatch(uint32_t uuid)
{
- if (!GetAllWatchInfo()) {
- GRAPHIC_LOGE("failed to get all watch info.");
- return false;
- }
- watch_dial_info info;
- uint16_t index = 0;
- bool isExists = false;
- for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
- if (uuid == g_info.watchInfo[i].uuid) {
- isExists = true;
- info = g_info.watchInfo[i];
- index = i;
- break;
- }
- }
- if (!isExists) {
- GRAPHIC_LOGE("uuid does not exist!");
+ uint16_t index = INVALID_INFO_INDEX;
+ GraphicLockGuard guard(g_mutex);
+ while (!g_eventFinished) {
+ g_cond.Wait(g_mutex);
+ }
+ GetWatchInfo(uuid, index);
+ if (index == INVALID_INFO_INDEX) {
+ GRAPHIC_LOGE("uuid %u does not exist", uuid);
return false;
}
- if (info.is_current_watch) {
- DialSetting setting = MainModel::GetInstance().GetDialSetting();
+ DialSetting setting = MainModel::GetInstance().GetDialSetting();
+ if (g_info[index].watchInfo.is_current_watch) {
setting.dialFlag = 0;
setting.dialId = 0;
- std::string fileName = g_info.fileNames[index];
- GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() {
- MainModel::GetInstance().GetDialSetting() = setting;
- #ifdef fd230_650
- MainModel::GetInstance().AddDialSetting(setting,0);
- #endif
- if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
- #ifdef fd230_650
- MainViewSample::GetInstance()->ReloadWatchFace();
- #endif
- }
- if (remove(fileName.c_str()) != 0) {
- GRAPHIC_LOGE("failed to remove file %s", fileName.c_str());
+ }
+ if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) {
+ if (g_info[index].watchInfo.is_current_watch) {
+ // If it is the current watch face, set it as the default watch face. Otherwise, the configuration remains
+ // unchanged.
+ GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+ if (SetDialPresenter::GetCurrentInstance() != nullptr) {
+ SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting);
+ }
+ });
+ }
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+ g_eventFinished = false;
+ GraphicService::GetInstance()->PostGraphicEvent([index]() {
+ GraphicLockGuard guardGraphic(g_mutex);
+ ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName);
+ if (remove(g_info[index].fileName.c_str()) != 0) {
+ GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str());
+ g_eventFinished = true;
+ g_cond.Signal();
+ return;
}
+ g_info.Erase(index);
+ g_eventFinished = true;
+ g_cond.Signal();
});
- } else {
- if (remove(g_info.fileNames[index].c_str()) != 0) {
- GRAPHIC_LOGE("failed to remove file %s", g_info.fileNames[index].c_str());
- return false;
- }
+ return true;
}
+
+ g_eventFinished = false;
+ GraphicService::GetInstance()->PostGraphicEvent([index, setting]() {
+ GraphicLockGuard guardGraphic(g_mutex);
+ if (g_info[index].watchInfo.is_current_watch &&
+ NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) {
+ MainModel::GetInstance().GetDialSetting() = setting;
+ MainModel::GetInstance().AddDialSetting(setting);
+ MainViewSample::GetInstance()->ReloadWatchFace();
+ }
+ ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName);
+ if (remove(g_info[index].fileName.c_str()) != 0) {
+ GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str());
+ g_eventFinished = true;
+ g_cond.Signal();
+ return;
+ }
+ g_info.Erase(index);
+ g_eventFinished = true;
+ g_cond.Signal();
+ });
+ TryToTurnOnScreen();
return true;
}
-bool InstallWatch(const char *path, uint32_t *uuid)
+bool GetUuidByPath(const char *path, uint32_t *uuid)
{
if (path == nullptr || uuid == nullptr) {
GRAPHIC_LOGE("para error!");
}
DialPreviewInfo preview;
- if (!GetPreviewInfo(std::string(path), preview)) {
+ if (!GetPreviewInfo(std::string(path), preview, true)) {
return false;
}
if (std::string(preview.protocolVersion) < std::string("3.0")) {
return false;
}
- *uuid = preview.uuid;
- if (!GetAllWatchInfo()) {
- GRAPHIC_LOGE("failed to get all watchinfo!");
- return false;
- }
- for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
- const std::string &fileName = g_info.fileNames[i];
- const watch_dial_info &info = g_info.watchInfo[i];
- if (!(info.uuid == *uuid && std::string(path) != fileName)) {
- continue;
- }
-
- if (info.is_current_watch) {
- DialSetting setting = MainModel::GetInstance().GetDialSetting();
- setting.dialFlag = 1;
- setting.dialFullName = std::string(path);
- GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() {
- MainModel::GetInstance().GetDialSetting() = setting;
- #ifdef fd230_650
- MainModel::GetInstance().AddDialSetting(setting);
- #endif
- if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
- #ifdef fd230_650
- MainViewSample::GetInstance()->ReloadWatchFace();
- #endif
- }
- if (remove(fileName.c_str()) != 0) {
- GRAPHIC_LOGE("failed to remove file %s", fileName.c_str());
- }
- });
- } else {
- if (remove(fileName.c_str()) != 0) {
- return false;
+ watch_dial_info watchInfo;
+ if (ConvertPreview2WatchDialInfo(preview, watchInfo)) {
+ std::string activePath;
+ std::string appendPath(path);
+ bool isActiveExist = GetActiveWatchPath(activePath);
+ watchInfo.install_state = true;
+ watchInfo.is_current_watch = isActiveExist ? (activePath == appendPath) : false;
+ bool isExist = false;
+ for (uint16_t i = 0; i < g_info.Size(); ++i) {
+ if (g_info[i].fileName == appendPath) {
+ isExist = true;
+ break;
}
}
+ if (!isExist) {
+ g_info.PushBack({appendPath, watchInfo});
+ }
}
-
+ *uuid = preview.uuid;
return true;
}
\ No newline at end of file