From 49323a52a210d21753477bf6d24d869782dab3c5 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sat, 14 Sep 2024 17:30:04 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E8=AF=9D=E8=AE=B0?= =?utf8?q?=E5=BD=95=E5=AD=98=E5=9C=A8=E7=9A=84=E5=86=85=E5=AD=98=E6=B3=84?= =?utf8?q?=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/phone/include/MainPhoneView.h | 2 +- .../nativeui/phone/src/MainPhoneView.cpp | 26 +++++++----- .../phoneservice/src/PhoneService.cpp | 40 ++++++++++++++++++- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhoneView.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhoneView.h index 3f5657656..d75c6144b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhoneView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhoneView.h @@ -60,7 +60,7 @@ namespace OHOS UIImageView *TelephoneLineImageView{nullptr}; // 线 UILabelExt *NoCallsLabel{nullptr}; // 暂无通话 UILabelExt *hintCallsLabel{nullptr}; // 提示 - CallLogInfo *info{nullptr}; + CallLogInfo *info[20]{nullptr}; UILabelButtonExt *button_calllog[CALL_LOG_MAX_NUM]{nullptr}; UILabelExt *button_calllog_time[CALL_LOG_MAX_NUM]{nullptr}; //"时间" UILabelExt *button_calllog_status[CALL_LOG_MAX_NUM]{nullptr}; //"通话状态" diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/MainPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/MainPhoneView.cpp index 89ed3a113..eaf329c7e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/MainPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/MainPhoneView.cpp @@ -112,12 +112,16 @@ namespace OHOS button_calllog_status[i] = nullptr; } } - if(info) + for(int i=0;i<20;i++) { - delete info; - info=nullptr; - } + if(info[i]) + { + UIFree(info[i]); + info[i]=nullptr; + } + } + if(hintCallsLabel) { delete hintCallsLabel; @@ -265,8 +269,8 @@ namespace OHOS /* ------------------------------ NoCallsLabel ------------------------------ */ - info = new CallLogInfo[sizeof(CallLogInfo) * CALL_LOG_MAX_NUM]; - if (GetCallLog(&info, &num) == -1) { + // info = new CallLogInfo[sizeof(CallLogInfo) * CALL_LOG_MAX_NUM]; + if (GetCallLog(info, &num) == -1) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallerLogModel::GetInstance()->ListIsEmpty"); return; } @@ -298,7 +302,7 @@ namespace OHOS //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",(info + i - 1)->tel); char buf[20]={0}; - sprintf_s(buf,20,"%s",(const char*)(info + i - 1)->tel); + sprintf_s(buf,20,"%s",(const char*)(info[i-1])->tel); char name[30]={0}; if(get_phone_addrss_name(name,buf,NULL)) { @@ -307,7 +311,7 @@ namespace OHOS { buttonconfig.str=buf; } - buttonconfig.ViewId=(const char*)(info + i - 1)->tel; + buttonconfig.ViewId=(const char*)(info[i-1])->tel; button_calllog[i]=SetTheButton_ext(buttonconfig,ButtonOnclickListen); if(button_calllog[i]==nullptr) { @@ -319,7 +323,7 @@ namespace OHOS time_t currtime; struct tm *timeinfo; - currtime=(info + i - 1)->creationTime; + currtime=(info[i-1])->creationTime; timeinfo = localtime(&currtime); char time_buf[20]={0}; @@ -350,13 +354,13 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::MainPhoneViewTitleLabel new fail!"); } - if((info + i - 1)->status==CALL_MISSED) + if((info [i-1])->status==CALL_MISSED) { //labelParam.text="未接来电"; button_calllog_status[i]->SetTextId(STR_MISSED_CALLS); button_calllog_status[i]->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); } - else if((info + i - 1)->status==CALL_INCOMING) + else if((info[i-1])->status==CALL_INCOMING) { //labelParam.text="拨入电话"; button_calllog_status[i]->SetTextId(STR_RECEIVED_CALLS); diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp index c0bdf7d77..e654b8d20 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -36,6 +36,7 @@ #include "ConfigModel.h" #include "custom_runtime.h" #include "vibrator_service.h" +#include "gfx_utils/mem_api.h" #ifdef __cplusplus extern "C" { #endif @@ -974,7 +975,7 @@ int GetCallLog(CallLogInfo **info, int *num) int number = fileSize / sizeof(CallLogInfo); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fileSize:%d, number:%d", fileSize, number); - CallLogInfo *callInfo = (CallLogInfo *)malloc(fileSize); + CallLogInfo *callInfo = (CallLogInfo *)OHOS::UIMalloc(fileSize); if (callInfo == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] malloc callInfo fail!"); *info = nullptr; @@ -999,6 +1000,43 @@ int GetCallLog(CallLogInfo **info, int *num) return OHOS_SUCCESS; } + +// int SaveCallLog(CallLogInfo **info) +// { +// FILE *fp = fopen(CALL_LOG_PATH, "wb+"); +// if (fp == nullptr) { +// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen %s failed!", CALL_LOG_PATH); +// return OHOS_FAILURE; +// } + + +// int number = fileSize / sizeof(CallLogInfo); +// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fileSize:%d, number:%d", fileSize, number); +// CallLogInfo *callInfo = (CallLogInfo *)malloc(fileSize); +// if (callInfo == nullptr) { +// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] malloc callInfo fail!"); +// *info = nullptr; +// *num = 0; +// fclose(fp); +// return OHOS_FAILURE; +// } +// (void)memset_s(callInfo, fileSize, 0, fileSize); + +// int ret = fread(callInfo, sizeof(CallLogInfo), number, fp); +// if (ret != number) { +// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fread fp fail ret:%d", ret); +// *info = nullptr; +// *num = 0; +// fclose(fp); +// return OHOS_FAILURE; +// } + +// *info = callInfo; +// *num = number; +// fclose(fp); +// return OHOS_SUCCESS; +// } + // 清空通话记录 int ClearCallLogFile(void) { -- 2.17.1