From fd29cec6581b39f16f77b16b06172cc0999b4152 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Fri, 20 Oct 2023 15:50:42 +0800 Subject: [PATCH 01/15] New requirement: The reminder action button title supports multiple languages. Signed-off-by: gaojiaqi --- bundle.json | 6 +- frameworks/ans/src/reminder_request.cpp | 56 ++++++++++-- .../napi/include/reminder/reminder_common.h | 1 + .../js/napi/src/reminder/reminder_common.cpp | 11 ++- interfaces/inner_api/reminder_request.h | 29 +++++- services/ans/BUILD.gn | 11 ++- services/ans/include/bundle_manager_helper.h | 12 +++ .../include/reminder_config_change_observer.h | 39 ++++++++ services/ans/include/reminder_data_manager.h | 30 +++++++ services/ans/src/bundle_manager_helper.cpp | 18 ++++ .../src/reminder_config_change_observer.cpp | 36 ++++++++ services/ans/src/reminder_data_manager.cpp | 89 +++++++++++++++++++ 12 files changed, 322 insertions(+), 16 deletions(-) create mode 100644 services/ans/include/reminder_config_change_observer.h create mode 100644 services/ans/src/reminder_config_change_observer.cpp diff --git a/bundle.json b/bundle.json index e0e66a09e..ce3574c6a 100644 --- a/bundle.json +++ b/bundle.json @@ -78,10 +78,12 @@ "device_manager", "kv_store", "ffrt", - "device_standby" + "device_standby", + "resource_management" ], "third_party": [ - "libuv" + "libuv", + "icu" ] }, "build": { diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 7563cbaf3..2c6c57fae 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -32,12 +32,13 @@ namespace OHOS { namespace Notification { namespace { const int32_t BASE_YEAR = 1900; -const int32_t SINGLE_BUTTON_MIN_LEN = 2; -const int32_t SINGLE_BUTTON_MAX_LEN = 4; +const int32_t SINGLE_BUTTON_MIN_LEN = 3; +const int32_t SINGLE_BUTTON_MAX_LEN = 5; const int32_t BUTTON_TYPE_INDEX = 0; const int32_t BUTTON_TITLE_INDEX = 1; -const int32_t BUTTON_PKG_INDEX = 2; -const int32_t BUTTON_ABILITY_INDEX = 3; +const int32_t BUTTON_RESOURCE_INDEX = 2; +const int32_t BUTTON_PKG_INDEX = 3; +const int32_t BUTTON_ABILITY_INDEX = 4; } int32_t ReminderRequest::GLOBAL_ID = 0; @@ -185,7 +186,7 @@ std::string ReminderRequest::Dump() const } ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type, - const std::shared_ptr &buttonWantAgent) + const std::string &resource, const std::shared_ptr &buttonWantAgent) { if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) { ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type)); @@ -194,6 +195,7 @@ ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, cons ActionButtonInfo actionButtonInfo; actionButtonInfo.type = type; actionButtonInfo.title = title; + actionButtonInfo.resource = resource; actionButtonInfo.wantAgent = buttonWantAgent; actionButtonMap_.insert(std::pair(type, actionButtonInfo)); @@ -238,6 +240,11 @@ void ReminderRequest::InitUid(const int32_t &uid) uid_ = uid; } +void ReminderRequest::InitBundleName(const std::string &bundleName) +{ + bundleName_ = bundleName; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -605,10 +612,11 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptrabilityName = singleButton.at(BUTTON_ABILITY_INDEX); } SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), - ActionButtonType(std::stoi(singleButton.at(BUTTON_TYPE_INDEX), nullptr)), buttonWantAgent); - ANSR_LOGI("RecoverButton title:%{public}s, pkgName:%{public}s, abilityName:%{public}s", - singleButton.at(BUTTON_TITLE_INDEX).c_str(), buttonWantAgent->pkgName.c_str(), - buttonWantAgent->abilityName.c_str()); + ActionButtonType(std::stoi(singleButton.at(BUTTON_TYPE_INDEX), nullptr)), + singleButton.at(BUTTON_RESOURCE_INDEX), buttonWantAgent); + ANSR_LOGI("RecoverButton title:%{public}s, resource:%{public}s, pkgName:%{public}s, abilityName:%{public}s", + singleButton.at(BUTTON_TITLE_INDEX).c_str(), singleButton.at(BUTTON_RESOURCE_INDEX).c_str(), + buttonWantAgent->pkgName.c_str(), buttonWantAgent->abilityName.c_str()); } } @@ -864,6 +872,11 @@ int32_t ReminderRequest::GetUid() const return uid_; } +std::string ReminderRequest::GetBundleName() const +{ + return bundleName_; +} + void ReminderRequest::SetSystemApp(bool isSystem) { isSystemApp_ = isSystem; @@ -1092,6 +1105,10 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write action button title"); return false; } + if (!parcel.WriteString(static_cast(button.second.resource))) { + ANSR_LOGE("Failed to write action button resource"); + return false; + } if (button.second.wantAgent == nullptr) { ANSR_LOGE("button wantAgent is null"); return false; @@ -1256,11 +1273,13 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) } ActionButtonType type = static_cast(buttonType); std::string title = parcel.ReadString(); + std::string resource = parcel.ReadString(); std::string pkgName = parcel.ReadString(); std::string abilityName = parcel.ReadString(); ActionButtonInfo info; info.type = type; info.title = title; + info.resource = resource; info.wantAgent = std::make_shared(); info.wantAgent->pkgName = pkgName; info.wantAgent->abilityName = abilityName; @@ -1324,6 +1343,7 @@ std::string ReminderRequest::GetButtonInfo() const } ActionButtonInfo buttonInfo = button.second; info += std::to_string(static_cast(button.first)) + SEP_BUTTON_SINGLE + buttonInfo.title; + info += SEP_BUTTON_SINGLE + buttonInfo.resource; if (buttonInfo.wantAgent == nullptr) { continue; } @@ -1838,5 +1858,23 @@ void ReminderRequest::AddColumn( sqlOfAddColumns += name + " " + type; } } + +void ReminderRequest::OnLanguageChange(const std::shared_ptr &resMgr) +{ + if (resMgr == nullptr) { + return; + } + // update title + for (auto &button : actionButtonMap_) { + std::string title; + resMgr->GetStringByName(button.second.resource.c_str(), title); + if (title.empty()) { + continue; + } + button.second.title = title; + } + // update action button + UpdateActionButtons(false); +} } } \ No newline at end of file diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index a25febc7b..e7ddd389b 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -30,6 +30,7 @@ namespace { const char* ACTION_BUTTON = "actionButton"; const char* ACTION_BUTTON_TITLE = "title"; const char* ACTION_BUTTON_TYPE = "type"; +const char* ACTION_BUTTON_RESOURCE = "resource"; const char* ALARM_HOUR = "hour"; const char* ALARM_DAYS_OF_WEEK = "daysOfWeek"; const char* ALARM_MINUTE = "minute"; diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 69f6c869c..c7f11f166 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -49,6 +49,7 @@ bool ReminderCommon::GenActionButtons( const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp) { char str[NotificationNapi::STR_MAX_SIZE] = {0}; + char res[NotificationNapi::STR_MAX_SIZE] = {0}; napi_valuetype valuetype = napi_undefined; napi_value actionButtons = nullptr; if (!GetObject(env, value, ReminderAgentNapi::ACTION_BUTTON, actionButtons)) { @@ -75,7 +76,9 @@ bool ReminderCommon::GenActionButtons( int32_t buttonType = static_cast(ReminderRequest::ActionButtonType::INVALID); if (GetStringUtf8(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TITLE, str, NotificationNapi::STR_MAX_SIZE) && - GetInt32(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TYPE, buttonType, false)) { + GetInt32(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TYPE, buttonType, false) && + GetStringUtf8(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_RESOURCE, res, + NotificationNapi::STR_MAX_SIZE)) { if (!(ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CLOSE || ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::SNOOZE || (ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CUSTOM && @@ -84,13 +87,15 @@ bool ReminderCommon::GenActionButtons( return false; } std::string title(str); + std::string resource(res); auto buttonWantAgent = std::make_shared(); if (ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CUSTOM) { GetButtonWantAgent(env, actionButton, reminder, buttonWantAgent); } reminder->SetActionButton(title, static_cast(buttonType), - buttonWantAgent); - ANSR_LOGD("button title=%{public}s, type=%{public}d", title.c_str(), buttonType); + resource, buttonWantAgent); + ANSR_LOGD("button title=%{public}s, type=%{public}d, resource=%{public}s", + title.c_str(), buttonType, resource.c_str()); } else { ANSR_LOGW("Parse action button error."); return false; diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 3cec37b15..8284a1ee4 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -124,6 +124,11 @@ public: */ std::string title = ""; + /** + * resource key(for language) + */ + std::string resource = ""; + /** * The ability that is redirected to when the button is clicked. */ @@ -288,6 +293,13 @@ public: int32_t GetUserId() const; int32_t GetUid() const; + /** + * @brief Obtains bundle name + * + * @return bundle name + */ + std::string GetBundleName() const; + /** * @brief Set the app system. * @@ -335,6 +347,13 @@ public: */ void InitUid(const int32_t &uid); + /** + * @brief Inites reminder bundle name when publish reminder success. + * + * @param bundleName Indicates the bundle name which the reminder belong to + */ + void InitBundleName(const std::string &bundleName); + /** * @brief Check the reminder is alerting or not. * @@ -447,10 +466,11 @@ public: * * @param title Indicates the title of the button. * @param type Indicates the type of the button. + * @param resource Indicates the resource of the button. * @return Current reminder self. */ ReminderRequest& SetActionButton(const std::string &title, const ActionButtonType &type, - const std::shared_ptr &buttonWantAgent = nullptr); + const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr); /** * @brief Sets reminder content. @@ -633,6 +653,13 @@ public: */ void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); + /** + * @brief When system language change, will call this function. + * need load resource to update button title + * @param resMgr Indicates the resource manager for get button title + */ + void OnLanguageChange(const std::shared_ptr &resMgr); + static int32_t GetActualTime(const TimeTransferType &type, int32_t cTime); static int32_t GetCTime(const TimeTransferType &type, int32_t actualTime); static uint64_t GetDurationSinceEpochInMilli(const time_t target); diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a836f95b8..fcd72b76a 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("libans") { "src/notification_subscriber_manager.cpp", "src/notification_timer_info.cpp", "src/permission_filter.cpp", + "src/reminder_config_change_observer.cpp", "src/reminder_data_manager.cpp", "src/reminder_event_manager.cpp", "src/reminder_timer_info.cpp", @@ -69,7 +70,10 @@ ohos_shared_library("libans") { defines = [] cflags = [] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "//third_party/icu/icu4c:shared_icuuc", + ] if (is_double_framework) { cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] @@ -83,17 +87,22 @@ ohos_shared_library("libans") { external_deps = [ "ability_runtime:ability_manager", + "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "device_manager:devicemanagersdk", "ffrt:libffrt", "hitrace:hitrace_meter", + "i18n:intl_util", "image_framework:image_native", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "relational_store:native_rdb", + "resource_management::global_resmgr", "time_service:time_client", ] external_deps += component_external_deps diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 2bde977c3..e22250d08 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -86,6 +86,18 @@ public: bool GetDistributedNotificationEnabled(const std::string &bundleName, const int32_t userId); #endif + /** + * @brief get bundle info by bundle name. + * + * @param bundleName Indicates the bundle name. + * @param flag Indicates the bundle flag. + * @param bundleInfo Indicates the bundle info. + * @param userId Indicates the user id. + * @return Returns the check result. + */ + bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, + int32_t userId, AppExecFwk::BundleInfo &bundleInfo); + private: void Connect(); void Disconnect(); diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h new file mode 100644 index 000000000..bce1c2eda --- /dev/null +++ b/services/ans/include/reminder_config_change_observer.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H + +#include "configuration_observer_stub.h" + +namespace OHOS { +namespace Notification { + +/** + * @brief Listening system language change, when the system language changes, + * notify ReminderDataManager. +*/ +class ReminderConfigChangeObserver final : public AppExecFwk::ConfigurationObserverStub { +public: + ReminderConfigChangeObserver() = default; + ~ReminderConfigChangeObserver() = default; + +public: + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; +}; +} // namespace Notification +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 7b37c57a9..056f56dbd 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -24,9 +24,11 @@ #ifdef PLAYER_FRAMEWORK_ENABLE #include "player.h" #endif +#include "app_mgr_client.h" #include "reminder_request.h" #include "reminder_store.h" #include "reminder_timer_info.h" +#include "reminder_config_change_observer.h" namespace OHOS { namespace Notification { @@ -102,6 +104,11 @@ public: void InitUserId(); + /** + * @brief Register configuration observer, the listening system language is changed. + */ + bool RegisterConfigurationObserver(); + void OnUserRemove(const int32_t& userId); void OnServiceStart(); @@ -182,6 +189,24 @@ public: */ void TerminateAlerting(const OHOS::EventFwk::Want &want); + /** + * @brief Get resource manager by handle info. + */ + std::shared_ptr GetBundleResMgr( + const AppExecFwk::BundleInfo &bundleInfo); + + /** + * @brief Update reminders based on the system language. + * + * Update action button title. + */ + void UpdateReminderLanguage(const sptr &reminder); + + /** + * @brief System language change + */ + void OnConfigurationChanged(const AppExecFwk::Configuration &configuration); + static const uint8_t TIME_ZONE_CHANGE; static const uint8_t DATE_TIME_CHANGE; @@ -516,6 +541,11 @@ private: int currentUserId_ {0}; sptr advancedNotificationService_ = nullptr; std::shared_ptr store_ = nullptr; + + /** + * Indicates config change observer for language + */ + sptr configChangeObserver_ = nullptr; }; } // namespace OHOS } // namespace Notification diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index c12f076ef..0c7af675b 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -180,5 +180,23 @@ bool BundleManagerHelper::GetDistributedNotificationEnabled(const std::string &b return DEFAULT_DISTRIBUTED_ENABLE_IN_APPLICATION_INFO; } #endif + +bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, + int32_t userId, AppExecFwk::BundleInfo &bundleInfo) +{ + std::lock_guard lock(connectionMutex_); + + Connect(); + + if (bundleMgr_ == nullptr) { + return false; + } + int32_t callingUserId; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(userId, callingUserId); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + bool ret = bundleMgr_->GetBundleInfo(bundleName, flag, bundleInfo, callingUserId); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/ans/src/reminder_config_change_observer.cpp new file mode 100644 index 000000000..54f368a0b --- /dev/null +++ b/services/ans/src/reminder_config_change_observer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "reminder_config_change_observer.h" + +#include "ans_log_wrapper.h" +#include "reminder_data_manager.h" + +namespace OHOS { +namespace Notification { + +void ReminderConfigChangeObserver::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) +{ + ANSR_LOGD("OnConfigurationUpdated."); + auto reminderDataMgr = ReminderDataManager::GetInstance(); + if (reminderDataMgr == nullptr) { + ANSR_LOGW("Reminder data manager is nullptr"); + return; + } + reminderDataMgr->OnConfigurationChanged(configuration); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index a2c646ab5..9f7b97388 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -30,6 +30,8 @@ #include "reminder_event_manager.h" #include "time_service_client.h" #include "singleton.h" +#include "locale_config.h" +#include "bundle_manager_helper.h" namespace OHOS { namespace Notification { @@ -584,6 +586,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( reminder->InitReminderId(); reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); reminder->InitUid(bundleOption->GetUid()); + reminder->InitBundleName(bundleOption->GetBundleName()); if (reminder->GetTriggerTimeInMilli() == ReminderRequest::INVALID_LONG_LONG_VALUE) { ANSR_LOGW("now publish reminder is expired. reminder is =%{public}s", @@ -599,6 +602,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( return; } ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); + UpdateReminderLanguage(reminder); reminderVector_.push_back(reminder); totalCount_++; store_->UpdateOrInsert(reminder, bundleOption); @@ -1061,6 +1065,11 @@ void ReminderDataManager::Init(bool isFromBootComplete) if (IsReminderAgentReady()) { return; } + // Register config observer for language change + if (!RegisterConfigurationObserver()) { + ANSR_LOGW("Register configuration observer failed."); + return; + } if (store_ == nullptr) { store_ = std::make_shared(); } @@ -1087,6 +1096,27 @@ void ReminderDataManager::InitUserId() } } +bool ReminderDataManager::RegisterConfigurationObserver() +{ + if (configChangeObserver_ != nullptr) { + return true; + } + + auto appMgrClient = std::make_shared(); + if (appMgrClient->ConnectAppMgrServer() != ERR_OK) { + ANSR_LOGW("Connect to app mgr service failed."); + return false; + } + + configChangeObserver_ = sptr( + new (std::nothrow) ReminderConfigChangeObserver()); + if (appMgrClient->RegisterConfigurationObserver(configChangeObserver_) != ERR_OK) { + ANSR_LOGE("Register configuration observer failed."); + return false; + } + return true; +} + void ReminderDataManager::GetImmediatelyShowRemindersLocked(std::vector> &reminders) const { std::lock_guard lock(ReminderDataManager::MUTEX); @@ -1444,5 +1474,64 @@ void ReminderDataManager::HandleCustomButtonClick(const OHOS::EventFwk::Want &wa return; } } + +std::shared_ptr ReminderDataManager::GetBundleResMgr( + const AppExecFwk::BundleInfo &bundleInfo) +{ + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + if (!resourceManager) { + ANSR_LOGE("create resourceManager failed."); + return nullptr; + } + // obtains the resource path. + for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { + std::string moduleResPath = hapModuleInfo.hapPath.empty() ? hapModuleInfo.resourcePath : hapModuleInfo.hapPath; + if (moduleResPath.empty()) { + continue; + } + ANSR_LOGD("GetBundleResMgr, moduleResPath: %{private}s", moduleResPath.c_str()); + if (!resourceManager->AddResource(moduleResPath.c_str())) { + ANSR_LOGW("GetBundleResMgr AddResource failed"); + } + } + // obtains the current system language. + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + UErrorCode status = U_ZERO_ERROR; + icu::Locale locale = icu::Locale::forLanguageTag(Global::I18n::LocaleConfig::GetSystemLanguage(), status); + resConfig->SetLocaleInfo(locale); + resourceManager->UpdateResConfig(*resConfig); + return resourceManager; +} + +void ReminderDataManager::UpdateReminderLanguage(const sptr &reminder) +{ + // obtains the bundle info by bundle name + const std::string bundleName = reminder->GetBundleName(); + AppExecFwk::BundleInfo bundleInfo; + if (!BundleManagerHelper::GetInstance()->GetBundleInfo(bundleName, + AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, reminder->GetUid(), bundleInfo)) { + ANSR_LOGE("Get reminder request[%{public}d][%{public}s] bundle info failed.", + reminder->GetReminderId(), bundleName.c_str()); + return; + } + // obtains the resource manager + auto resourceMgr = GetBundleResMgr(bundleInfo); + if (resourceMgr == nullptr) { + ANSR_LOGE("Get reminder request[%{public}d][%{public}s] resource manager failed.", + reminder->GetReminderId(), bundleName.c_str()); + return; + } + // update action button title + reminder->OnLanguageChange(resourceMgr); +} + +void ReminderDataManager::OnConfigurationChanged(const AppExecFwk::Configuration &configuration) +{ + ANSR_LOGI("System language config changed."); + std::lock_guard lock(ReminderDataManager::MUTEX); + for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { + UpdateReminderLanguage(*it); + } +} } } -- Gitee From f5e9dd1e4e44828e6435644379a88ecd90b77f09 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 14:38:11 +0800 Subject: [PATCH 02/15] update reminder test Signed-off-by: gaojiaqi --- frameworks/ans/test/unittest/BUILD.gn | 2 + .../mock/include/mock_resource_manager_impl_h | 530 ++++++++++++++++++ .../unittest/mock/mock_resource_manager.cpp | 341 +++++++++++ services/ans/BUILD.gn | 2 +- services/ans/src/bundle_manager_helper.cpp | 2 +- services/ans/src/reminder_data_manager.cpp | 2 +- .../reminderrequest_fuzzer.cpp | 2 +- 7 files changed, 877 insertions(+), 4 deletions(-) create mode 100644 frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h create mode 100644 frameworks/ans/test/unittest/mock/mock_resource_manager.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 80f902f98..c9eb5eeb7 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -95,10 +95,12 @@ ohos_unittest("reminder_request_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", + "${frameworks_module_ans_path}/test/unittest/mock/include", ] sources = [ "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", + "${frameworks_module_ans_path}/test/unittest/mock/mock_resource_manager.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", ] diff --git a/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h new file mode 100644 index 000000000..5197c3c7c --- /dev/null +++ b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_MOCK_RESOURCE_MANAGER_IMPL_H +#define OHOS_MOCK_RESOURCE_MANAGER_IMPL_H + +#include +#include +#include +#include "resource_manager.h" + +namespace OHOS { +namespace Global { +namespace Resource { +class ResourceManagerImpl : public ResourceManager { +public: + ResourceManagerImpl(); + ~ResourceManagerImpl(); + +public: + bool Init(bool en = true); + + /** + * Add resource path to hap paths + * @param path the resource path + * @return true if add resource path success, else false + */ + virtual bool AddResource(const char *path); + + /** + * Add resource path to overlay paths + * @param path the resource path + * @param overlayPaths the exist overlay resource path + * @return true if add resource path success, else false + */ + virtual bool AddResource(const std::string &path, const std::vector &overlayPaths); + + /** + * Remove resource path to overlay paths + * @param path the resource path + * @param overlayPaths the exist overlay resource path + * @return true if add resource path success, else false + */ + virtual bool RemoveResource(const std::string &path, const std::vector &overlayPaths); + + /** + * Update the resConfig + * @param resConfig the resource config + * @return SUCCESS if the resConfig updated success, else HAP_INIT_FAILED + */ + virtual RState UpdateResConfig(ResConfig &resConfig); + + /** + * Get the resConfig + * @param resConfig the resource config + */ + virtual void GetResConfig(ResConfig &resConfig); + + /** + * Get string resource by Id + * @param id the resource Id + * @param outValue the string resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringById(uint32_t id, std::string &outValue); + + /** + * Get string by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringByName(const char *name, std::string &outValue); + + /** + * Get string format by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...); + + /** + * Get string format by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringFormatByName(std::string &outValue, const char *name, ...); + + /** + * Get the STRINGARRAY resource by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringArrayById(uint32_t id, std::vector &outValue); + + /** + * Get the STRINGARRAY resource by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetStringArrayByName(const char *name, std::vector &outValue); + + /** + * Get the PATTERN resource by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPatternById(uint32_t id, std::map &outValue); + + /** + * Get the PATTERN resource by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPatternByName(const char *name, std::map &outValue); + + /** + * Get the plural string by resource id + * @param id the resource id + * @param quantity the language quantity + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue); + + /** + * Get the plural string by resource name + * @param name the resource name + * @param quantity the language quantity + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPluralStringByName(const char *name, int quantity, std::string &outValue); + + /** + * Get the plural format string by resource id + * @param outValue the resource write to + * @param id the resource id + * @param quantity the language quantity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...); + + /** + * Get the plural format string by resource name + * @param outValue the resource write to + * @param id the resource id + * @param quantity the language quantity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...); + + /** + * Get the THEME resource by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetThemeById(uint32_t id, std::map &outValue); + + /** + * Get the THEME resource by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetThemeByName(const char *name, std::map &outValue); + + /** + * Get the BOOLEAN resource by resource id + * @param id the resource id + * @param outValue the obtain boolean value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetBooleanById(uint32_t id, bool &outValue); + + /** + * Get the BOOLEAN resource by resource name + * @param name the resource name + * @param outValue the obtain boolean value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetBooleanByName(const char *name, bool &outValue); + + /** + * Get the INTEGER resource by resource id + * @param id the resource id + * @param outValue the obtain Integer value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetIntegerById(uint32_t id, int &outValue); + + /** + * Get the INTEGER resource by resource name + * @param name the resource name + * @param outValue the obtain Integer value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetIntegerByName(const char *name, int &outValue); + + /** + * Get the FLOAT resource by resource id + * @param id the resource id + * @param outValue the obtain float value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetFloatById(uint32_t id, float &outValue); + + /** + * Get the FLOAT resource by resource id + * @param id the resource id + * @param outValue the obtain float value write to + * @param unit the unit do not in parsing + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetFloatById(uint32_t id, float &outValue, std::string &unit); + + /** + * Get the FLOAT resource by resource name + * @param name the resource name + * @param outValue the obtain float value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetFloatByName(const char *name, float &outValue); + + /** + * Get the FLOAT resource by resource id + * @param id the resource id + * @param outValue the obtain float value write to + * @param unit the string do not in parsing + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetFloatByName(const char *name, float &outValue, std::string &unit); + + /** + * Get the INTARRAY resource by resource id + * @param id the resource id + * @param outValue the obtain resource value convert to vector write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetIntArrayById(uint32_t id, std::vector &outValue); + + /** + * Get the INTARRAY resource by resource name + * @param name the resource name + * @param outValue the obtain resource value convert to vector write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetIntArrayByName(const char *name, std::vector &outValue); + + /** + * Get the COLOR resource by resource id + * @param id the resource id + * @param outValue the obtain resource value convert to uint32_t write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetColorById(uint32_t id, uint32_t &outValue); + + /** + * Get the COLOR resource by resource name + * @param name the resource name + * @param outValue the obtain resource value convert to uint32_t write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetColorByName(const char *name, uint32_t &outValue); + + /** + * Get the PROF resource by resource id + * @param id the resource id + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetProfileById(uint32_t id, std::string &outValue); + + /** + * Get the PROF resource by resource name + * @param name the resource name + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetProfileByName(const char *name, std::string &outValue); + + /** + * Get the MEDIA resource by resource id + * @param id the resource id + * @param outValue the obtain resource path write to + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaById(uint32_t id, std::string &outValue, uint32_t density = 0); + + /** + * Get the MEDIA resource by resource name + * @param name the resource name + * @param outValue the obtain resource path write to + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaByName(const char *name, std::string &outValue, uint32_t density = 0); + + /** + * Get the raw file path by resource name + * @param name the resource name + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetRawFilePathByName(const std::string &name, std::string &outValue); + + /** + * Get the rawFile descriptor by resource name + * @param name the resource name + * @param descriptor the obtain raw file member fd, length, offet write to + * @return SUCCESS if resource exist, else ERROR + */ + virtual RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor); + + /** + * Close rawFile descriptor by resource name + * @param name the resource name + * @return SUCCESS if close the rawFile descriptor, else ERROR + */ + virtual RState CloseRawFileDescriptor(const std::string &name); + + /** + * Get all resource paths + * @return The vector of resource paths + */ + std::vector GetResourcePaths(); + + /** + * Get the MEDIA data by resource id + * @param id the resource id + * @param len the data len write to + * @param outValue the obtain resource path write to + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr &outValue, + uint32_t density = 0); + + /** + * Get the MEDIA data by resource name + * @param name the resource name + * @param len the data len write to + * @param outValue the obtain resource path write to + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaDataByName(const char *name, size_t &len, std::unique_ptr &outValue, + uint32_t density = 0); + + /** + * Get the MEDIA base64 data resource by resource id + * @param id the resource id + * @param outValue the media base64 data + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaBase64DataById(uint32_t id, std::string &outValue, uint32_t density = 0); + + /** + * Get the MEDIA base64 data resource by resource id + * @param name the resource name + * @param outValue the media base64 data + * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetMediaBase64DataByName(const char *name, std::string &outValue, uint32_t density = 0); + + /** + * Get the PROF resource by resource id + * @param name the resource id + * @param len the data len write to + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr &outValue); + + /** + * Get the PROF resource by resource name + * @param name the resource name + * @param len the data len write to + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetProfileDataByName(const char *name, size_t &len, std::unique_ptr &outValue); + + /** + * Get the rawFile base64 from hap by rawFile name + * @param rawFileName the rawFile name + * @param len the data len write to + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetRawFileFromHap(const std::string &rawFileName, size_t &len, + std::unique_ptr &outValue); + + /** + * Get the rawFile Descriptor from hap by rawFile name + * @param rawFileName the rawFile name + * @param descriptor the raw file member fd, length, offet write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor); + + /** + * Is load hap + * @param hapPath the hap path + */ + virtual RState IsLoadHap(std::string &hapPath); + + /** + * Get the raw file list + * @param rawDirPath the rawfile directory path + * @param rawfileList the rawfile list write to + * @return SUCCESS if resource exist, else not found + */ + virtual RState GetRawFileList(const std::string &rawDirPath, std::vector& rawfileList); + + /** + * Get the drawable information for given resId, mainly about type, len, buffer + * @param id the resource id + * @param type the drawable type + * @param len the drawable buffer length + * @param outValue the drawable buffer write to + * @param density the drawable density + * @return SUCCESS if resource exist, else not found + */ + virtual RState GetDrawableInfoById(uint32_t id, std::string &type, size_t &len, + std::unique_ptr &outValue, uint32_t density = 0); + + /** + * Get the drawable information for given resName, mainly about type, len, buffer + * @param name the resource Name + * @param type the drawable type + * @param len the drawable buffer length + * @param outValue the drawable buffer write to + * @param density the drawable density + * @return SUCCESS if resource exist, else not found + */ + virtual RState GetDrawableInfoByName(const char *name, std::string &type, size_t &len, + std::unique_ptr &outValue, uint32_t density = 0); + + /** + * Get string format by resource id + * @param id the resource id + * @param outValue the resource write to + * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, + * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, + * the tuple second parameter represents the value + * @return SUCCESS if resource exists and was formatted successfully, else ERROR + */ + virtual RState GetStringFormatById(uint32_t id, std::string &outValue, + std::vector> &jsParams); + + /** + * Get string format by resource name + * @param name the resource name + * @param outValue the resource write to + * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, + * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, + * the tuple second parameter represents the value + * @return SUCCESS if resource exists and was formatted successfully, else ERROR + */ + virtual RState GetStringFormatByName(const char *name, std::string &outValue, + std::vector> &jsParams); + + /** + * Get the resource limit keys value which every binary bit corresponds to existing limit key {@link KeyType} + * + * @return the resource limit keys + */ + virtual uint32_t GetResourceLimitKeys(); + + /** + * Add the overlay resource for current application + * @param path the overlay resource path + * @return true if add resource path success, else false + */ + virtual bool AddAppOverlay(const std::string &path); + + /** + * Remove the overlay resource for current application + * @param path the overlay resource path + * @return true if add resource path success, else false + */ + virtual bool RemoveAppOverlay(const std::string &path); + + /** + * Get the rawFile descriptor from resource name + * + * @param name the resource name + * @param descriptor the obtain raw file member fd, length, offet write to + * @return SUCCESS if resource exist, else ERROR + */ + virtual RState GetRawFdNdkFromHap(const std::string &name, RawFileDescriptor &descriptor); + + /** + * Get the resource id by resType and resName + * + * @param resTypeName the resType and resName + * @param resId the resId write to + * @return SUCCESS if resource exist, else ERROR + */ + virtual RState GetResId(const std::string &resTypeName, uint32_t &resId); + +private: + std::map resources_; +}; +} // namespace Resource +} // namespace Global +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp new file mode 100644 index 000000000..d384083fc --- /dev/null +++ b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mock_resource_manager_impl.h" + +namespace OHOS { +namespace Global { +namespace Resource { +ResourceManager *CreateResourceManager() +{ + ResourceManagerImpl *impl = new (std::nothrow) ResourceManagerImpl; + return impl; +} + +ResourceManager::~ResourceManager() {} + +ResourceManagerImpl::ResourceManagerImpl() {} + +ResourceManagerImpl::~ResourceManagerImpl() {} + +void ResourceManagerImpl::Init(bool en) +{ + if (en) { + resources_.insert("snooze", "SNOOZE"); + resources_.insert("close", "CLOSE"); + } else { + resources_.insert("snooze", "延时"); + resources_.insert("close", "关闭"); + } +} + +bool ResourceManagerImpl::AddResource(const char *path) +{ + return true; +} + +bool ResourceManagerImpl::AddResource(const std::string &path, const std::vector &overlayPaths) +{ + return true; +} + +bool ResourceManagerImpl::RemoveResource(const std::string &path, const std::vector &overlayPaths) +{ + return true; +} + +RState ResourceManagerImpl::UpdateResConfig(ResConfig &resConfig) +{ + return SUCCESS; +} + +void ResourceManagerImpl::GetResConfig(ResConfig &resConfig) {} + +RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue) +{ + outValue = "ENTRY"; + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outValue) +{ + std::string key(name); + auto iter = resources_.find(key); + if (iter == resources_.end()) { + return NOT_FOUND; + } + outValue = iter->second; + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringFormatById(std::string &outValue, uint32_t id, ...) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringFormatByName(std::string &outValue, const char *name, ...) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringArrayById(uint32_t id, std::vector &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringArrayByName(const char *name, std::vector &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPatternById(uint32_t id, std::map &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPatternByName(const char *name, std::map &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPluralStringById(uint32_t id, int32_t quantity, std::string &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPluralStringByName(const char *name, int32_t quantity, std::string &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int32_t quantity, ...) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, const char *name, int32_t quantity, ...) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetThemeByName(const char *name, std::map &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetBooleanByName(const char *name, bool &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetIntegerById(uint32_t id, int32_t &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetIntegerByName(const char *name, int32_t &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue, std::string &unit) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue, std::string &unit) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetIntArrayById(uint32_t id, std::vector &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetIntArrayByName(const char *name, std::vector &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetColorById(uint32_t id, uint32_t &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetColorByName(const char *name, uint32_t &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetProfileById(uint32_t id, std::string &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetProfileByName(const char *name, std::string &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaById(uint32_t id, std::string &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaByName(const char *name, std::string &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetRawFilePathByName(const std::string &name, std::string &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::CloseRawFileDescriptor(const std::string &name) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr &outValue, + uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaDataByName(const char *name, size_t &len, std::unique_ptr &outValue, + uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaBase64DataById(uint32_t id, std::string &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetMediaBase64DataByName(const char *name, std::string &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetProfileDataByName(const char *name, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetRawFileFromHap(const std::string &rawFileName, size_t &len, + std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::IsLoadHap(std::string &hapPath) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetRawFileList(const std::string &rawDirPath, std::vector& rawfileList) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetDrawableInfoById(uint32_t id, std::string &type, size_t &len, + std::unique_ptr &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetDrawableInfoByName(const char *name, std::string &type, size_t &len, + std::unique_ptr &outValue, uint32_t density) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringFormatById(uint32_t id, std::string &outValue, + std::vector> &jsParams) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetStringFormatByName(const char *name, std::string &outValue, + std::vector> &jsParams) +{ + return SUCCESS; +} + +uint32_t ResourceManagerImpl::GetResourceLimitKeys() +{ + return 0; +} + +bool ResourceManagerImpl::AddAppOverlay(const std::string &path) +{ + return true; +} + +bool ResourceManagerImpl::RemoveAppOverlay(const std::string &path) +{ + return true; +} + +RState ResourceManagerImpl::GetRawFdNdkFromHap(const std::string &name, ResourceManager::RawFileDescriptor &descriptor) +{ + return SUCCESS; +} + +RState ResourceManagerImpl::GetResId(const std::string &resTypeName, uint32_t &resId) +{ + return SUCCESS; +} +} // namespace Resource +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index fcd72b76a..9cde185be 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -102,7 +102,7 @@ ohos_shared_library("libans") { "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "relational_store:native_rdb", - "resource_management::global_resmgr", + "resource_management:global_resmgr", "time_service:time_client", ] external_deps += component_external_deps diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index 0c7af675b..4c47705ca 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -181,7 +181,7 @@ bool BundleManagerHelper::GetDistributedNotificationEnabled(const std::string &b } #endif -bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, +bool BundleManagerHelper::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, int32_t userId, AppExecFwk::BundleInfo &bundleInfo) { std::lock_guard lock(connectionMutex_); diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 9f7b97388..f56281caf 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1103,7 +1103,7 @@ bool ReminderDataManager::RegisterConfigurationObserver() } auto appMgrClient = std::make_shared(); - if (appMgrClient->ConnectAppMgrServer() != ERR_OK) { + if (appMgrClient->ConnectAppMgrService() != ERR_OK) { ANSR_LOGW("Connect to app mgr service failed."); return false; } diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp index c5ab30198..1b5cd73e9 100644 --- a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -38,7 +38,7 @@ namespace OHOS { uint8_t types = *data % ACTION_BUTTON_TYPE; Notification::ReminderRequest::ActionButtonType type = Notification::ReminderRequest::ActionButtonType(types); - reminderRequest.SetActionButton(stringData, type); + reminderRequest.SetActionButton(stringData, type, stringData); reminderRequest.SetContent(stringData); reminderRequest.SetExpiredContent(stringData); bool enabled = *data % ENABLE; -- Gitee From 29d12846e17826a2dbf372cb72f43bc5128561b6 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 14:38:52 +0800 Subject: [PATCH 03/15] update reminder test Signed-off-by: gaojiaqi --- .../test/unittest/reminder_request_test.cpp | 114 +++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index d909f07a8..981309605 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -18,6 +18,7 @@ #define private public #define protected public #include "reminder_request.h" +#include "mock_resource_manager_impl.h" #undef private #undef protected @@ -1047,9 +1048,10 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00001, Function | SmallTest | Leve std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); std::string title = "this is title"; + std::string resource = "invalid"; Notification::ReminderRequest::ActionButtonType type = Notification::ReminderRequest::ActionButtonType::INVALID; - reminderRequestChild->SetActionButton(title, type); + reminderRequestChild->SetActionButton(title, type, resource); } /** @@ -1063,9 +1065,10 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00002, Function | SmallTest | Leve std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); std::string title = "this is title"; + std::string resource = "close"; Notification::ReminderRequest::ActionButtonType type2 = Notification::ReminderRequest::ActionButtonType::CLOSE; - reminderRequestChild->SetActionButton(title, type2); + reminderRequestChild->SetActionButton(title, type2, resource); } /** @@ -1079,9 +1082,10 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00003, Function | SmallTest | Leve std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); std::string title = "this is title"; + std::string resource = "snooze"; Notification::ReminderRequest::ActionButtonType type3 = Notification::ReminderRequest::ActionButtonType::SNOOZE; - reminderRequestChild->SetActionButton(title, type3); + reminderRequestChild->SetActionButton(title, type3, resource); } /** @@ -1753,5 +1757,109 @@ HWTEST_F(ReminderRequestTest, SetCustomButtonUri_00001, Function | SmallTest | L std::string ret = "test"; EXPECT_EQ(result, ret); } + +/** + * @tc.name: InitBundleName_00001 + * @tc.desc: Test InitBundleName with normal parameters. + * @tc.type: FUNC + * @tc.require: issueI89858 + */ +HWTEST_F(ReminderRequestTest, InitBundleName_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string bundleName = "com.example.myapplication"; + rrc->InitBundleName(bundleName); + EXPECT_EQ(rrc->GetBundleName(), bundleName); +} + +/** + * @tc.name: InitBundleName_00002 + * @tc.desc: Test InitBundleName with special parameters. + * @tc.type: FUNC + * @tc.require: issueI89858 + */ +HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string bundleName = "com.example.myapplication.~!@#$%^&*()"; + rrc->InitBundleName(bundleName); + EXPECT_EQ(rrc->GetBundleName(), bundleName); +} + +/** + * @tc.name: OnLanguageChange_00001 + * @tc.desc: Test OnLanguageChange with zh_CN. + * @tc.type: FUNC + * @tc.require: issueI89858 + */ +HWTEST_F(ReminderRequestTest, OnLanguageChange_00001, Function | SmallTest | Level1) +{ + // Given + auto rrc = std::make_shared(); + // add button snooze + std::string title = "this is title snooze"; + std::string resource = "snooze"; + Notification::ReminderRequest::ActionButtonType type = + Notification::ReminderRequest::ActionButtonType::SNOOZE; + rrc->SetActionButton(title, type, resource); + // add button close + title = "this is title close" + resource = "close"; + type = Notification::ReminderRequest::ActionButtonType::CLOSE; + rrc->SetActionButton(title, type, resource); + + // When + auto resMgr = std::make_shared(); + resMgr->Init(); + rrc->OnLanguageChange(resMgr); + + // Then + auto iter = rrc->actionButtonMap_.find(type); + EXPECT_NE(iter, rrc->actionButtonMap_.end()); + EXPECT_STREQ(iter->second.title, "关闭"); + + type = Notification::ReminderRequest::ActionButtonType::SNOOZE; + iter = rrc->actionButtonMap_.find(type); + EXPECT_NE(iter, rrc->actionButtonMap_.end()); + EXPECT_STREQ(iter->second.title, "延时"); +} + +/** + * @tc.name: OnLanguageChange_00002 + * @tc.desc: Test OnLanguageChange with en_US. + * @tc.type: FUNC + * @tc.require: issueI89858 + */ +HWTEST_F(ReminderRequestTest, OnLanguageChange_00002, Function | SmallTest | Level1) +{ + // Given + auto rrc = std::make_shared(); + // add button snooze + std::string title = "this is title snooze"; + std::string resource = "snooze"; + Notification::ReminderRequest::ActionButtonType type = + Notification::ReminderRequest::ActionButtonType::SNOOZE; + rrc->SetActionButton(title, type, resource); + // add button close + title = "this is title close" + resource = "close"; + type = Notification::ReminderRequest::ActionButtonType::CLOSE; + rrc->SetActionButton(title, type, resource); + + // When + auto resMgr = std::make_shared(); + resMgr->Init(); + rrc->OnLanguageChange(resMgr); + + // Then + auto iter = rrc->actionButtonMap_.find(type); + EXPECT_NE(iter, rrc->actionButtonMap_.end()); + EXPECT_STREQ(iter->second.title, "CLOSE"); + + type = Notification::ReminderRequest::ActionButtonType::SNOOZE; + iter = rrc->actionButtonMap_.find(type); + EXPECT_NE(iter, rrc->actionButtonMap_.end()); + EXPECT_STREQ(iter->second.title, "SNOOZE"); +} } } -- Gitee From d093d4bec6dba7eaa75db154a185249369afba5e Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 15:00:38 +0800 Subject: [PATCH 04/15] fix reminder test build bug Signed-off-by: gaojiaqi --- ...source_manager_impl_h => mock_resource_manager_impl.h} | 2 +- frameworks/ans/test/unittest/reminder_request_test.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename frameworks/ans/test/unittest/mock/include/{mock_resource_manager_impl_h => mock_resource_manager_impl.h} (99%) diff --git a/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h similarity index 99% rename from frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h rename to frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h index 5197c3c7c..a8f279880 100644 --- a/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl_h +++ b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h @@ -29,7 +29,7 @@ public: ~ResourceManagerImpl(); public: - bool Init(bool en = true); + void Init(bool en = true); /** * Add resource path to hap paths diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 981309605..22ff049ea 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1803,25 +1803,25 @@ HWTEST_F(ReminderRequestTest, OnLanguageChange_00001, Function | SmallTest | Lev Notification::ReminderRequest::ActionButtonType::SNOOZE; rrc->SetActionButton(title, type, resource); // add button close - title = "this is title close" + title = "this is title close"; resource = "close"; type = Notification::ReminderRequest::ActionButtonType::CLOSE; rrc->SetActionButton(title, type, resource); // When - auto resMgr = std::make_shared(); + auto resMgr = std::make_shared(); resMgr->Init(); rrc->OnLanguageChange(resMgr); // Then auto iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_STREQ(iter->second.title, "关闭"); + EXPECT_EQ(iter->second.title, "关闭"); type = Notification::ReminderRequest::ActionButtonType::SNOOZE; iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_STREQ(iter->second.title, "延时"); + EXPECT_EQ(iter->second.title, "延时"); } /** -- Gitee From 4aa39947d184e9a63690901500ed40dc530224b8 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 15:08:54 +0800 Subject: [PATCH 05/15] fix reminder test build bug Signed-off-by: gaojiaqi --- .../ans/test/unittest/mock/mock_resource_manager.cpp | 8 ++++---- frameworks/ans/test/unittest/reminder_request_test.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp index d384083fc..08e102815 100644 --- a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp +++ b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp @@ -33,11 +33,11 @@ ResourceManagerImpl::~ResourceManagerImpl() {} void ResourceManagerImpl::Init(bool en) { if (en) { - resources_.insert("snooze", "SNOOZE"); - resources_.insert("close", "CLOSE"); + resources_.emplace("snooze", "SNOOZE"); + resources_.emplace("close", "CLOSE"); } else { - resources_.insert("snooze", "延时"); - resources_.insert("close", "关闭"); + resources_.emplace("snooze", "延时"); + resources_.emplace("close", "关闭"); } } diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 22ff049ea..dfb70de32 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1841,25 +1841,25 @@ HWTEST_F(ReminderRequestTest, OnLanguageChange_00002, Function | SmallTest | Lev Notification::ReminderRequest::ActionButtonType::SNOOZE; rrc->SetActionButton(title, type, resource); // add button close - title = "this is title close" + title = "this is title close"; resource = "close"; type = Notification::ReminderRequest::ActionButtonType::CLOSE; rrc->SetActionButton(title, type, resource); // When - auto resMgr = std::make_shared(); + auto resMgr = std::make_shared(); resMgr->Init(); rrc->OnLanguageChange(resMgr); // Then auto iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_STREQ(iter->second.title, "CLOSE"); + EXPECT_EQ(iter->second.title, "CLOSE"); type = Notification::ReminderRequest::ActionButtonType::SNOOZE; iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_STREQ(iter->second.title, "SNOOZE"); + EXPECT_EQ(iter->second.title, "SNOOZE"); } } } -- Gitee From 142eba72eff8d78f29219bf638716bf6c24c846f Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 15:26:59 +0800 Subject: [PATCH 06/15] fix bugs Signed-off-by: gaojiaqi --- frameworks/ans/test/unittest/reminder_request_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index dfb70de32..40ccfb7c0 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1810,7 +1810,7 @@ HWTEST_F(ReminderRequestTest, OnLanguageChange_00001, Function | SmallTest | Lev // When auto resMgr = std::make_shared(); - resMgr->Init(); + resMgr->Init(false); rrc->OnLanguageChange(resMgr); // Then -- Gitee From c1af954066e494c92bd5965f1bcb8963dc06cc4e Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 16:25:50 +0800 Subject: [PATCH 07/15] fix format_check problem Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 2 +- frameworks/ans/test/unittest/BUILD.gn | 2 +- frameworks/ans/test/unittest/reminder_request_test.cpp | 2 +- interfaces/inner_api/reminder_request.h | 4 ++-- services/ans/include/bundle_manager_helper.h | 2 +- services/ans/include/reminder_config_change_observer.h | 2 +- services/ans/include/reminder_data_manager.h | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 2c6c57fae..32db0d31a 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -612,7 +612,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptrabilityName = singleButton.at(BUTTON_ABILITY_INDEX); } SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), - ActionButtonType(std::stoi(singleButton.at(BUTTON_TYPE_INDEX), nullptr)), + ActionButtonType(std::stoi(singleButton.at(BUTTON_TYPE_INDEX), nullptr)), singleButton.at(BUTTON_RESOURCE_INDEX), buttonWantAgent); ANSR_LOGI("RecoverButton title:%{public}s, resource:%{public}s, pkgName:%{public}s, abilityName:%{public}s", singleButton.at(BUTTON_TITLE_INDEX).c_str(), singleButton.at(BUTTON_RESOURCE_INDEX).c_str(), diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index c9eb5eeb7..3011f8586 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -99,8 +99,8 @@ ohos_unittest("reminder_request_test") { ] sources = [ - "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", "${frameworks_module_ans_path}/test/unittest/mock/mock_resource_manager.cpp", + "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", ] diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 40ccfb7c0..e4aaa21b0 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1769,7 +1769,7 @@ HWTEST_F(ReminderRequestTest, InitBundleName_00001, Function | SmallTest | Level auto rrc = std::make_shared(); std::string bundleName = "com.example.myapplication"; rrc->InitBundleName(bundleName); - EXPECT_EQ(rrc->GetBundleName(), bundleName); + EXPECT_EQ(rrc->GetBundleName(), bundleName); } /** diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 8284a1ee4..d07dc7320 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -295,7 +295,7 @@ public: /** * @brief Obtains bundle name - * + * * @return bundle name */ std::string GetBundleName() const; @@ -349,7 +349,7 @@ public: /** * @brief Inites reminder bundle name when publish reminder success. - * + * * @param bundleName Indicates the bundle name which the reminder belong to */ void InitBundleName(const std::string &bundleName); diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 265af65c8..ea71a8b83 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -88,7 +88,7 @@ public: /** * @brief Obtains bundle info by bundle name. - * + * * @param bundleName Indicates the bundle name. * @param flag Indicates the bundle flag. * @param bundleInfo Indicates the bundle info. diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h index bce1c2eda..e66cfe692 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/ans/include/reminder_config_change_observer.h @@ -33,7 +33,7 @@ public: public: void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; }; -} // namespace Notification +} // namespace Notification } // namespace OHOS #endif \ No newline at end of file diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 056f56dbd..3d5d407ad 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -197,7 +197,7 @@ public: /** * @brief Update reminders based on the system language. - * + * * Update action button title. */ void UpdateReminderLanguage(const sptr &reminder); -- Gitee From 22118e8f094faa314acff3329bfa2a305db484b3 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 23 Oct 2023 16:57:40 +0800 Subject: [PATCH 08/15] format build.gn by tools Signed-off-by: gaojiaqi --- services/ans/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 9cde185be..1d03a2e60 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -70,7 +70,7 @@ ohos_shared_library("libans") { defines = [] cflags = [] - deps = [ + deps = [ "${frameworks_module_ans_path}:ans_innerkits", "//third_party/icu/icu4c:shared_icuuc", ] -- Gitee From b5219c22f766a46772d85f220f92b4ecd2e6ba03 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 25 Oct 2023 08:47:52 +0800 Subject: [PATCH 09/15] update reminder request test Signed-off-by: gaojiaqi --- .../mock/include/mock_resource_manager_impl.h | 2 +- .../unittest/mock/mock_resource_manager.cpp | 13 ++---- .../test/unittest/reminder_request_test.cpp | 44 ++----------------- .../include/reminder_config_change_observer.h | 4 +- 4 files changed, 10 insertions(+), 53 deletions(-) diff --git a/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h index a8f279880..add8c7226 100644 --- a/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h +++ b/frameworks/ans/test/unittest/mock/include/mock_resource_manager_impl.h @@ -29,7 +29,7 @@ public: ~ResourceManagerImpl(); public: - void Init(bool en = true); + void Init(); /** * Add resource path to hap paths diff --git a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp index 08e102815..6081d0389 100644 --- a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp +++ b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp @@ -30,15 +30,10 @@ ResourceManagerImpl::ResourceManagerImpl() {} ResourceManagerImpl::~ResourceManagerImpl() {} -void ResourceManagerImpl::Init(bool en) -{ - if (en) { - resources_.emplace("snooze", "SNOOZE"); - resources_.emplace("close", "CLOSE"); - } else { - resources_.emplace("snooze", "延时"); - resources_.emplace("close", "关闭"); - } +void ResourceManagerImpl::Init() +{ + resources_.emplace("snooze", "SNOOZE_TEST"); + resources_.emplace("close", "CLOSE_TEST"); } bool ResourceManagerImpl::AddResource(const char *path) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index e4aaa21b0..1b40854fc 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1788,7 +1788,7 @@ HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level /** * @tc.name: OnLanguageChange_00001 - * @tc.desc: Test OnLanguageChange with zh_CN. + * @tc.desc: Test OnLanguageChange. * @tc.type: FUNC * @tc.require: issueI89858 */ @@ -1808,44 +1808,6 @@ HWTEST_F(ReminderRequestTest, OnLanguageChange_00001, Function | SmallTest | Lev type = Notification::ReminderRequest::ActionButtonType::CLOSE; rrc->SetActionButton(title, type, resource); - // When - auto resMgr = std::make_shared(); - resMgr->Init(false); - rrc->OnLanguageChange(resMgr); - - // Then - auto iter = rrc->actionButtonMap_.find(type); - EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_EQ(iter->second.title, "关闭"); - - type = Notification::ReminderRequest::ActionButtonType::SNOOZE; - iter = rrc->actionButtonMap_.find(type); - EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_EQ(iter->second.title, "延时"); -} - -/** - * @tc.name: OnLanguageChange_00002 - * @tc.desc: Test OnLanguageChange with en_US. - * @tc.type: FUNC - * @tc.require: issueI89858 - */ -HWTEST_F(ReminderRequestTest, OnLanguageChange_00002, Function | SmallTest | Level1) -{ - // Given - auto rrc = std::make_shared(); - // add button snooze - std::string title = "this is title snooze"; - std::string resource = "snooze"; - Notification::ReminderRequest::ActionButtonType type = - Notification::ReminderRequest::ActionButtonType::SNOOZE; - rrc->SetActionButton(title, type, resource); - // add button close - title = "this is title close"; - resource = "close"; - type = Notification::ReminderRequest::ActionButtonType::CLOSE; - rrc->SetActionButton(title, type, resource); - // When auto resMgr = std::make_shared(); resMgr->Init(); @@ -1854,12 +1816,12 @@ HWTEST_F(ReminderRequestTest, OnLanguageChange_00002, Function | SmallTest | Lev // Then auto iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_EQ(iter->second.title, "CLOSE"); + EXPECT_EQ(iter->second.title, "CLOSE_TEST"); type = Notification::ReminderRequest::ActionButtonType::SNOOZE; iter = rrc->actionButtonMap_.find(type); EXPECT_NE(iter, rrc->actionButtonMap_.end()); - EXPECT_EQ(iter->second.title, "SNOOZE"); + EXPECT_EQ(iter->second.title, "SNOOZE_TEST"); } } } diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h index e66cfe692..26affb54f 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/ans/include/reminder_config_change_observer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H #include "configuration_observer_stub.h" -- Gitee From b8e36603a40d1fd77eef3fd4deab4c2a91a8728f Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 25 Oct 2023 09:22:52 +0800 Subject: [PATCH 10/15] update reminder request test Signed-off-by: gaojiaqi --- frameworks/ans/test/unittest/reminder_request_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index ee5790058..04d39f2bc 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1099,13 +1099,14 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00004, Function | SmallTest | Leve std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); std::string title = "this is title"; + std::string resource = "CLOSE"; Notification::ReminderRequest::ActionButtonType type2 = Notification::ReminderRequest::ActionButtonType::CLOSE; std::shared_ptr buttonWantAgent = std::make_shared(); std::shared_ptr buttonDataShareUpdate = std::make_shared(); - reminderRequestChild->SetActionButton(title, type2, buttonWantAgent, buttonDataShareUpdate); + reminderRequestChild->SetActionButton(title, type2, resource, buttonWantAgent, buttonDataShareUpdate); } /** @@ -1119,13 +1120,14 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00005, Function | SmallTest | Leve std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); std::string title = "this is title"; + std::string resource = "SNOOZE"; Notification::ReminderRequest::ActionButtonType type3 = Notification::ReminderRequest::ActionButtonType::SNOOZE; std::shared_ptr buttonWantAgent = std::make_shared(); std::shared_ptr buttonDataShareUpdate = std::make_shared(); - reminderRequestChild->SetActionButton(title, type3, buttonWantAgent, buttonDataShareUpdate); + reminderRequestChild->SetActionButton(title, type3, resource, buttonWantAgent, buttonDataShareUpdate); } /** -- Gitee From 75e25f4992306d9127b63061389d4078533f05cc Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 25 Oct 2023 11:58:47 +0800 Subject: [PATCH 11/15] update resource name -> titleResource Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 2 +- frameworks/js/napi/include/reminder/reminder_common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index a29ff798d..15d192aed 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -632,7 +632,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptrvaluesBucket = dataShareUpdate.at("valuesBucket").get(); } SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), - buttonWantAgent, buttonDataShareUpdate); + resource, buttonWantAgent, buttonDataShareUpdate); continue; } // old method Soon to be deleted diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index f8b1350cd..509ac456f 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -30,7 +30,7 @@ namespace { const char* ACTION_BUTTON = "actionButton"; const char* ACTION_BUTTON_TITLE = "title"; const char* ACTION_BUTTON_TYPE = "type"; -const char* ACTION_BUTTON_RESOURCE = "resource"; +const char* ACTION_BUTTON_RESOURCE = "titleResource"; const char* ALARM_HOUR = "hour"; const char* ALARM_DAYS_OF_WEEK = "daysOfWeek"; const char* ALARM_MINUTE = "minute"; -- Gitee From 2a914db0d4cdb702f24571ca50d8ff6d9afb8ed6 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 26 Oct 2023 09:17:11 +0800 Subject: [PATCH 12/15] The resource attribute of the action button is changed to optional Signed-off-by: gaojiaqi --- frameworks/js/napi/src/reminder/reminder_common.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 0f658b9fe..8aabb69c1 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -77,9 +77,7 @@ bool ReminderCommon::GenActionButtons( int32_t buttonType = static_cast(ReminderRequest::ActionButtonType::INVALID); if (GetStringUtf8(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TITLE, str, NotificationNapi::STR_MAX_SIZE) && - GetInt32(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TYPE, buttonType, false) && - GetStringUtf8(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_RESOURCE, res, - NotificationNapi::STR_MAX_SIZE)) { + GetInt32(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_TYPE, buttonType, false)) { if (!(ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CLOSE || ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::SNOOZE || (ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CUSTOM && @@ -87,8 +85,14 @@ bool ReminderCommon::GenActionButtons( ANSR_LOGW("Wrong argument type:%{public}s. buttonType not support.", ACTION_BUTTON); return false; } + + std::string resource = ""; + if (GetStringUtf8(env, actionButton, ReminderAgentNapi::ACTION_BUTTON_RESOURCE, res, + NotificationNapi::STR_MAX_SIZE)) { + resource = std::string(res); + } + std::string title(str); - std::string resource(res); auto buttonWantAgent = std::make_shared(); if (ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CUSTOM) { GetButtonWantAgent(env, actionButton, reminder, buttonWantAgent); -- Gitee From 4d21e2936299826f2ff43974500bc3eae048aa5d Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 26 Oct 2023 10:49:04 +0800 Subject: [PATCH 13/15] update reminder test Signed-off-by: gaojiaqi --- frameworks/ans/test/unittest/mock/mock_resource_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp index 6081d0389..6daa84e0e 100644 --- a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp +++ b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp @@ -66,6 +66,9 @@ RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue) RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outValue) { + if (name == nullptr) { + return NOT_FOUND; + } std::string key(name); auto iter = resources_.find(key); if (iter == resources_.end()) { -- Gitee From 9cf931186f0b6603ea94f23a8018e6edd484b7b2 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 26 Oct 2023 15:20:14 +0800 Subject: [PATCH 14/15] update copyright Signed-off-by: gaojiaqi --- frameworks/ans/test/unittest/mock/mock_resource_manager.cpp | 2 +- services/ans/include/reminder_config_change_observer.h | 2 +- services/ans/src/reminder_config_change_observer.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp index 6daa84e0e..fc7ed534c 100644 --- a/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp +++ b/frameworks/ans/test/unittest/mock/mock_resource_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h index 26affb54f..0495cf430 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/ans/include/reminder_config_change_observer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/ans/src/reminder_config_change_observer.cpp index 54f368a0b..5b68423c8 100644 --- a/services/ans/src/reminder_config_change_observer.cpp +++ b/services/ans/src/reminder_config_change_observer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From e257284e4ba1953241dcc2f356fe71bdbf47d4be Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 26 Oct 2023 07:34:37 +0000 Subject: [PATCH 15/15] update services/ans/src/reminder_data_manager.cpp. Signed-off-by: gaojiaqi --- services/ans/src/reminder_data_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 2bf3ac5ec..f00636145 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1638,7 +1638,7 @@ std::shared_ptr ReminderDataManager::GetBundl return nullptr; } // obtains the resource path. - for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { + for (const auto &hapModuleInfo : bundleInfo.hapModuleInfos) { std::string moduleResPath = hapModuleInfo.hapPath.empty() ? hapModuleInfo.resourcePath : hapModuleInfo.hapPath; if (moduleResPath.empty()) { continue; -- Gitee