From: luozheng <1732036298@qq.com> Date: Fri, 23 May 2025 09:20:25 +0000 (+0800) Subject: 1.恢复出厂添加删除支付宝相关文件 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a82c67258650315f0e871aa1d4af17c99a93fdab;p=mirrors%2FFD230.git 1.恢复出厂添加删除支付宝相关文件 2.天气model添加判断提高代码建筑性 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index c3343153e..28d097afd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -89,6 +89,7 @@ namespace OHOS public: static WeatherModel &GetInstance(void); void InitFutureWeatherItem(); + bool IsValidDateIndex(int date); void TimestampToMonthDayString(time_t timestamp, char *buffer); std::string GetWeatherCurTime(); std::string GetWeatherImage(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index 71a1a5cf4..e2e37f9ea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -36,9 +36,9 @@ namespace OHOS { Weather_data_t_now.humidity = humidity; memset((void *)Weather_data_t_now.windScale, 0, weather_short_len); - strcpy_s(Weather_data_t_now.windScale, weather_short_len,windScale); + strcpy_s(Weather_data_t_now.windScale, weather_short_len, windScale); memset((void *)Weather_data_t_now.textNight, 0, weather_short_len); - strcpy_s(Weather_data_t_now.textNight,weather_short_len, textNight); + strcpy_s(Weather_data_t_now.textNight, weather_short_len, textNight); Weather_data_t_now.uvIndex = uvIndex; Weather_data_t_now.temp = temp; Weather_data_t_now.iconNight = iconNight; @@ -59,11 +59,11 @@ namespace OHOS Weather_data_t_address.lat = lat; Weather_data_t_address.lon = lon; memset((void *)Weather_data_t_address.atm, 0, weather_short_len); - strcpy_s(Weather_data_t_address.atm,weather_short_len, atm); + strcpy_s(Weather_data_t_address.atm, weather_short_len, atm); memset((void *)Weather_data_t_address.city, 0, weather_long_len); - strcpy_s(Weather_data_t_address.city, weather_long_len,city); + strcpy_s(Weather_data_t_address.city, weather_long_len, city); memset((void *)Weather_data_t_address.subLocality, 0, weather_long_len); - strcpy_s(Weather_data_t_address.subLocality, weather_long_len,subLocality); + strcpy_s(Weather_data_t_address.subLocality, weather_long_len, subLocality); } /* @@ -85,7 +85,7 @@ namespace OHOS Weather_data_seven_data[count].tempMin = t.tempMin; Weather_data_seven_data[count].fxDate = t.fxDate; memset((void *)Weather_data_seven_data[count].textDay, 0, weather_short_len); - strcpy_s(Weather_data_seven_data[count].textDay,weather_short_len, t.textDay); + strcpy_s(Weather_data_seven_data[count].textDay, weather_short_len, t.textDay); Weather_data_seven_count++; } @@ -127,6 +127,16 @@ namespace OHOS } } + bool WeatherModel::IsValidDateIndex(int date) + { + const bool isValid = (date >= 0 && date < DAYS_OF_THE_WEEK); + if (!isValid) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid date index: %d (valid range: 0-6)", date); + } + return isValid; + } + void WeatherModel::TimestampToMonthDayString(time_t timestamp, char *buffer) { // 将时间戳转换成tm结构 @@ -147,11 +157,11 @@ namespace OHOS localtime_r(&seconds, &pTM); int hour = pTM.tm_hour; - //需要判断显示的格式 - if (uapi_dev_runtime_get_time_hour_show_model() == 12) + // 需要判断显示的格式 + if (uapi_dev_runtime_get_time_hour_show_model() == 12) { if (pTM.tm_hour > 12) - hour = pTM.tm_hour - 12 ; + hour = pTM.tm_hour - 12; } int minute = pTM.tm_min; @@ -161,7 +171,7 @@ namespace OHOS return weatherTime; } - //判断当前时间是否在晚上 + // 判断当前时间是否在晚上 bool WeatherModel::IsNightTime() { struct tm pTM; @@ -189,7 +199,13 @@ namespace OHOS // index = Weather_data_seven_data[0].iconDay; // 白天天气图标 // } index = Weather_data_seven_data[0].iconDay; // 白天天气图标 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_t_now.iconNight = %d", index); + const size_t iconCount = sizeof(weather65x65) / sizeof(weather65x65[0]); + if (index <= 0 || static_cast(index) >= iconCount) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid iconDay index: %d (max allowed: %zu)", index, iconCount - 1); + return weather65x65[12]; // 返回"未知"图标 + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_t_now.iconNight = %d", index); return weather65x65[index]; } @@ -246,8 +262,16 @@ namespace OHOS /*获取未来七天中某一天白天天气图标*/ std::string WeatherModel::GetWeather_data_seven_data_iconDay(int date) { + // 获取图标索引并验证其有效性 int index = Weather_data_seven_data[date].iconDay; + const size_t iconCount = sizeof(weather65x65) / sizeof(weather65x65[0]); + if (index <= 0 || static_cast(index) >= iconCount) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid iconDay index: %d (max allowed: %zu)", index, iconCount - 1); + return weather65x65[12]; // 返回"未知"图标 + } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].iconDay = %d", date, index); + return weather65x65[index]; } @@ -255,21 +279,36 @@ namespace OHOS std::string WeatherModel::GetWeather_data_seven_data_textDay(int date) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].textDay = %s", date, Weather_data_seven_data[date].textDay); + if (!IsValidDateIndex(date)) + { + return "Invalid"; + } return Weather_data_seven_data[date].textDay; } /*获取未来七天某一天日期*/ std::string WeatherModel::GetWeather_data_seven_data_fxDate(int date) { + // 验证输入日期是否在有效范围内 + if (!IsValidDateIndex(date)) + { + return "Invalid"; + } static char formattedDate[6]; // 5字符加上终结符'\0' + // 转换时间戳并确保字符串终止 TimestampToMonthDayString(Weather_data_seven_data[date].fxDate, formattedDate); + formattedDate[5] = '\0'; // 显式确保字符串终止 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].fxDate = %s", date, formattedDate); - return formattedDate; + return std::string(formattedDate); // 复制字符串内容确保安全 } /*获取未来七天某一天最高和最低气温*/ std::string WeatherModel::GetWeather_data_seven_data_tempMinAndtempMax(int date) { + if (!IsValidDateIndex(date)) + { + return "Invalid"; + } int maxTemp = Weather_data_seven_data[date].tempMax; int minTemp = Weather_data_seven_data[date].tempMin; std::string maxandminTemperature = (std::to_string(minTemp) + "°") + "/" + std::to_string(maxTemp) + "°"; @@ -280,6 +319,10 @@ namespace OHOS /*获取未来七天某一天最低气温*/ std::string WeatherModel::GetWeather_data_seven_data_tempMin(int date) { + if (!IsValidDateIndex(date)) + { + return "Invalid"; + } int minTemp = Weather_data_seven_data[date].tempMin; std::string minTemperature = std::to_string(minTemp) + "°"; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].tempMin = %s", date, minTemperature.c_str()); @@ -289,6 +332,10 @@ namespace OHOS /*获取未来七天某一天最高气温*/ std::string WeatherModel::GetWeather_data_seven_data_tempMax(int date) { + if (!IsValidDateIndex(date)) + { + return "Invalid"; + } int maxTemp = Weather_data_seven_data[date].tempMax; std::string maxTemperature = "/" + std::to_string(maxTemp) + "°"; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " Weather_data_seven_data[%d].tempMax = %s", date, maxTemperature.c_str()); @@ -366,7 +413,7 @@ namespace OHOS // { // index = Weather_data_seven_data[0].iconDay; //白天天气图标 // } - index = Weather_data_seven_data[0].iconDay; //白天天气图标 + index = Weather_data_seven_data[0].iconDay; // 白天天气图标 DialModelWeather::GetInstance()->UpdateWeather(index); // 更新主界面天气图标 // const std::string str = GetWeatherTemperature() + " "+GetWeatherDescription(); const std::string str = GetWeatherTemperature(); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index ace51dfeb..b5fa55f8e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -2283,6 +2283,7 @@ void uapi_restore_factory_setting(void) "/user/dial/offline_dial/",//离线表盘 // EXC_TAR_PATH, //死机文件 "/user/log/",//离线日志 + "/user/alipay/",//支付宝文件 }; #else @@ -2291,6 +2292,7 @@ void uapi_restore_factory_setting(void) "/system/kvstore", // EXC_TAR_PATH,//死机文件 "/user/log/",//离线日志 + "/user/alipay/",//支付宝文件 }; #endif for(int i = 0; i < (sizeof(filebuf)/sizeof(filebuf[0])); i++)