diff --git a/common/BUILD.gn b/common/BUILD.gn index 8f636cb7f1f3b0832ab0a132d237a7c41b00d7b1..3508bceac594762d9c8366a85c79ebd20e1b36f3 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -18,6 +18,7 @@ config("camera_utils_config") { include_dirs = [ "utils", "utils/av_codec/include", + "utils/camera_notification/include", "utils/image_framework/include", "utils/media_manager/include", "utils/moving_photo/include", @@ -67,6 +68,7 @@ ohos_shared_library("camera_utils") { "utils/av_codec/src/av_codec_proxy.cpp", "utils/camera_dynamic_loader.cpp", "utils/camera_metadata.cpp", + "utils/camera_notification/src/camera_notification_proxy.cpp", "utils/camera_simple_timer.cpp", "utils/camera_timer.cpp", "utils/camera_xcollie.cpp", diff --git a/common/utils/camera_dynamic_loader.h b/common/utils/camera_dynamic_loader.h index 3c6e7e20f43e255a01a462186e651b6eaba09777..cd3cdd9c233d06b8e0c7683199049cf68ff2a1ea 100644 --- a/common/utils/camera_dynamic_loader.h +++ b/common/utils/camera_dynamic_loader.h @@ -28,6 +28,7 @@ const std::string AV_CODEC_SO = "libcamera_dynamic_avcodec.z.so"; const std::string MOVING_PHOTO_SO = "libcamera_dynamic_moving_photo.z.so"; const std::string MEDIA_MANAGER_SO = "libcamera_dynamic_media_manager.z.so"; const std::string NAPI_EXT_SO = "libcamera_napi_ex.z.so"; +const std::string CAMERA_NOTIFICATION_SO = "libcamera_dynamic_notification.z.so"; constexpr uint32_t LIB_DELAYED_UNLOAD_TIME = 30000; // 30 second diff --git a/common/utils/camera_notification/include/camera_notification_interface.h b/common/utils/camera_notification/include/camera_notification_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..e3ac33b2d1a81a52be5ac431549212e06fbdf6e1 --- /dev/null +++ b/common/utils/camera_notification/include/camera_notification_interface.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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_CAMERA_NOTIFICATION_INTERFACE_H +#define OHOS_CAMERA_NOTIFICATION_INTERFACE_H + +#include +#include + +/** + * @brief Internal usage only, for camera framework interacts with camera notification related interfaces. + * @since 12 + */ +namespace OHOS::CameraStandard { +static const std::string EVENT_CAMERA_BEAUTY_NOTIFICATION = "CAMERA_BEAUTY_NOTIFICATION"; +static const std::string BEAUTY_NOTIFICATION_ACTION_PARAM = "currentFlag"; +static const int32_t BEAUTY_STATUS_OFF = 0; +static const int32_t BEAUTY_STATUS_ON = 1; +static const int32_t BEAUTY_LEVEL = 100; +static const int32_t CONTROL_FLAG_LIMIT = 3; + +class CameraNotificationIntf { +public: + virtual ~CameraNotificationIntf() = default; + virtual int32_t PublishBeautyNotification(bool isRecordTimes, int32_t beautyStatus, int32_t beautyTimes) = 0; + virtual int32_t CancelBeautyNotification() = 0; +}; +} // namespace OHOS::CameraStandard +#endif // OHOS_CAMERA_NOTIFICATION_INTERFACE_H \ No newline at end of file diff --git a/common/utils/camera_notification/include/camera_notification_proxy.h b/common/utils/camera_notification/include/camera_notification_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..2456ea67d5eae07ae7f21435d7e32dedc8938c9c --- /dev/null +++ b/common/utils/camera_notification/include/camera_notification_proxy.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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 CAMERA_NOTIFICATION_PROXY_H +#define CAMERA_NOTIFICATION_PROXY_H + +#include "camera_notification_interface.h" +#include "camera_dynamic_loader.h" + +namespace OHOS { +namespace CameraStandard { +class CameraNotificationProxy : public CameraNotificationIntf { +public: + explicit CameraNotificationProxy(std::shared_ptr cameraNotificationLib, + std::shared_ptr CameraNotificationIntf); + + ~CameraNotificationProxy() override; + static std::shared_ptr CreateCameraNotificationProxy(); + int32_t PublishBeautyNotification(bool isRecordTimes, int32_t beautyStatus, int32_t beautyTimes) override; + int32_t CancelBeautyNotification() override; + +private: + // Keep the order of members in this class, the bottom member will be destroyed first + std::shared_ptr cameraNotificationLib_ = {nullptr}; + std::shared_ptr cameraNotificationIntf_ = {nullptr}; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif // CAMERA_NOTIFICATION_PROXY_H \ No newline at end of file diff --git a/common/utils/camera_notification/src/camera_notification_proxy.cpp b/common/utils/camera_notification/src/camera_notification_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef5ceecdaa6b4920a10d47a66683fc8063f29d1b --- /dev/null +++ b/common/utils/camera_notification/src/camera_notification_proxy.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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 "camera_notification_proxy.h" +#include "camera_log.h" + +namespace OHOS { +namespace CameraStandard { +CameraNotificationProxy::CameraNotificationProxy(std::shared_ptr cameraNotificationLib, + std::shared_ptr cameraNotificationIntf) : cameraNotificationLib_(cameraNotificationLib), + cameraNotificationIntf_(cameraNotificationIntf) +{ + MEDIA_DEBUG_LOG("CameraNotificationProxy constructor"); + CHECK_RETURN_ELOG(cameraNotificationLib_ == nullptr, "cameraNotificationLib_ is nullptr"); + CHECK_RETURN_ELOG(cameraNotificationIntf_ == nullptr, "cameraNotificationIntf_ is nullptr"); +} + +CameraNotificationProxy::~CameraNotificationProxy() +{ + MEDIA_DEBUG_LOG("CameraNotificationProxy destructor"); +} + +typedef CameraNotificationIntf* (*CreateCameraNotificationIntf)(); +std::shared_ptr CameraNotificationProxy::CreateCameraNotificationProxy() +{ + MEDIA_DEBUG_LOG("CreateCameraNotificationProxy start"); + auto dynamiclib = CameraDynamicLoader::GetDynamiclib(CAMERA_NOTIFICATION_SO); + CHECK_RETURN_RET_ELOG(dynamiclib == nullptr, nullptr, "get dynamiclib fail"); + CreateCameraNotificationIntf createCameraNotificationIntf = + (CreateCameraNotificationIntf)dynamiclib->GetFunction("createCameraNotificationIntf"); + CHECK_RETURN_RET_ELOG(createCameraNotificationIntf == nullptr, nullptr, "get createCameraNotificationIntf fail"); + CameraNotificationIntf* cameraNotificationIntf = createCameraNotificationIntf(); + CHECK_RETURN_RET_ELOG(cameraNotificationIntf == nullptr, nullptr, "get CameraNotificationIntf fail"); + std::shared_ptr cameraNotificationProxy = std::make_shared( + dynamiclib, std::shared_ptr(cameraNotificationIntf)); + return cameraNotificationProxy; +} + +int32_t CameraNotificationProxy::PublishBeautyNotification(bool isRecordTimes, int32_t beautyStatus, + int32_t beautyTimes) +{ + MEDIA_DEBUG_LOG("PublishBeautyNotification start"); + CHECK_RETURN_RET_ELOG(cameraNotificationIntf_ == nullptr, -1, "cameraNotificationIntf_ is nullptr"); + return cameraNotificationIntf_->PublishBeautyNotification(isRecordTimes, beautyStatus, beautyTimes); +} + +int32_t CameraNotificationProxy::CancelBeautyNotification() +{ + MEDIA_DEBUG_LOG("CreatePixelMap start"); + CHECK_RETURN_RET_ELOG(cameraNotificationIntf_ == nullptr, -1, "cameraNotificationIntf_ is nullptr"); + return cameraNotificationIntf_->CancelBeautyNotification(); +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/dynamic_libs/BUILD.gn b/dynamic_libs/BUILD.gn index 5c2697103af54d0a28c6a47fa697c0c218c0b5a3..8d8b345d49df0d698ff5383aad5cde99a470278d 100644 --- a/dynamic_libs/BUILD.gn +++ b/dynamic_libs/BUILD.gn @@ -283,6 +283,14 @@ config("camera_dynamic_media_manager_public_config") { ] } +config("camera_dynamic_notification_public_config") { + include_dirs = [ + "${multimedia_camera_framework_path}/common/utils", + "${multimedia_camera_framework_path}/common/utils/camera_notification/include", + "${multimedia_camera_framework_path}/common/utils/image_framework/include", + ] +} + ohos_shared_library("camera_dynamic_media_manager") { install_enable = true sources = [ @@ -368,3 +376,48 @@ ohos_shared_library("camera_dynamic_media_manager") { part_name = "camera_framework" subsystem_name = "multimedia" } + +ohos_shared_library("camera_dynamic_notification") { + install_enable = true + sources = [ + "${multimedia_camera_framework_path}/dynamic_libs/camera_notification/src/camera_notification.cpp", + ] + cflags = [ + "-fPIC", + "-Wall", + "-Os", + ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ + "${multimedia_camera_framework_path}/dynamic_libs/camera_notification/include", + ] + + public_configs = [":camera_dynamic_notification_public_config"] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${multimedia_camera_framework_path}/common:camera_utils", + ] + + external_deps = [ + "ability_base:base", + "ability_base:zuri", + "distributed_notification_service:ans_innerkits", + "hilog:libhilog", + "hisysevent:libhisysevent", + "i18n:intl_util", + "os_account:libaccountkits", + "os_account:os_account_innerkits", + ] + + cflags_cc = cflags + + part_name = "camera_framework" + subsystem_name = "multimedia" +} diff --git a/dynamic_libs/camera_notification/include/camera_notification.h b/dynamic_libs/camera_notification/include/camera_notification.h new file mode 100644 index 0000000000000000000000000000000000000000..b64664d43c9c6d544649e74f7f9847b480d0317d --- /dev/null +++ b/dynamic_libs/camera_notification/include/camera_notification.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025-2025 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 CAMERA_NOTIFICATION_H +#define CAMERA_NOTIFICATION_H + +#include "camera_log.h" +#include "camera_notification_interface.h" +#include "image_source.h" +#include "image_source_proxy.h" +#include "int_wrapper.h" +#include "ipc_skeleton.h" +#include "locale_config.h" +#include "notification_helper.h" +#include "notification_normal_content.h" +#include "notification_request.h" +#include "os_account_manager.h" +#include "pixel_map.h" +#include "want_agent_helper.h" +#include "want_agent_info.h" + +namespace OHOS { +namespace CameraStandard { + +class CameraNotification : public CameraNotificationIntf { +public: + int32_t PublishBeautyNotification(bool isRecordTimes, int32_t beautyStatus, int32_t beautyTimes) override; + int32_t CancelBeautyNotification() override; +private: + std::string GetSystemStringByName(std::string name); + void GetPixelMap(); + std::shared_ptr CreateNotificationNormalContent(int32_t beautyStatus); + void SetActionButton(const std::string& buttonName, Notification::NotificationRequest& request, + int32_t beautyStatus); + Global::Resource::RState GetMediaDataByName(std::string name, size_t& len, std::unique_ptr &outValue, + uint32_t density = 0); + void InitResourceManager(); + void RefreshResConfig(); + + std::shared_ptr iconPixelMap_ = nullptr; + Global::Resource::ResourceManager *resourceManager_ = nullptr; + Global::Resource::ResConfig *resConfig_ = nullptr; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif // CAMERA_NOTIFICATION_H \ No newline at end of file diff --git a/dynamic_libs/camera_notification/src/camera_notification.cpp b/dynamic_libs/camera_notification/src/camera_notification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e02b6faf021aa4093f332045675255b12601df1e --- /dev/null +++ b/dynamic_libs/camera_notification/src/camera_notification.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2025-2025 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. + */ +// LCOV_EXCL_START +#include "camera_notification.h" + +namespace OHOS { +namespace CameraStandard { + +static constexpr int32_t CAMERA_UID = 1047; +const int BEAUTY_NOTIFICATION_ID = 1047001; +const std::string BEAUTY_NOTIFICATION_TITLE = "title_adjust_beauty"; +const std::string BEAUTY_NOTIFICATION_CONTENT_ON = "summary_closed_beauty"; +const std::string BEAUTY_NOTIFICATION_CONTENT_OFF = "summary_opened_beauty"; +const std::string BEAUTY_NOTIFICATION_BUTTON_ON = "open_beauty"; +const std::string BEAUTY_NOTIFICATION_BUTTON_OFF = "close_beauty"; +const uint32_t BEAUTY_NOTIFICATION_CLOSE_SOUND_FLAG = 1 << 0; +const uint32_t BEAUTY_NOTIFICATION_CONTROL_FLAG = 1 << 9; +const uint32_t BEAUTY_NOTIFICATION_LOCKSCREEN_FLAG = 1 << 1; +const uint32_t BEAUTY_NOTIFICATION_CLOSE_VIBRATION_FLAG = 1 << 4; +const std::string BEAUTY_NOTIFICATION_ICON_NAME = "ic_public_camera_beauty"; +const std::string BEAUTY_NOTIFICATION_GROUP_NAME = "camera_beauty"; +const int32_t ICON_WIDTH = 220; +const int32_t ICON_HEIGHT = 220; + +int32_t CameraNotification::PublishBeautyNotification(bool isRecordTimes, int32_t beautyStatus, int32_t beautyTimes) +{ + std::shared_ptr content = + std::make_shared(CreateNotificationNormalContent(beautyStatus)); + + CHECK_RETURN_RET_ELOG(content == nullptr, -1, "Create notification content failed"); + + Notification::NotificationRequest request; + request.SetCreatorUid(CAMERA_UID); + request.SetCreatorPid(getpid()); + + int32_t userId; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(CAMERA_UID, userId); + + request.SetCreatorUserId(userId); + auto now = std::chrono::system_clock::now(); + auto duration = std::chrono::duration_cast(now.time_since_epoch()); + request.SetDeliveryTime(duration.count()); + request.SetAutoDeletedTime(OHOS::Notification::NotificationConstant::INVALID_AUTO_DELETE_TIME); + request.SetTapDismissed(false); + request.SetSlotType(OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + request.SetNotificationId(BEAUTY_NOTIFICATION_ID); + request.SetGroupName(BEAUTY_NOTIFICATION_GROUP_NAME); + uint32_t baseFlag = BEAUTY_NOTIFICATION_CLOSE_SOUND_FLAG | + BEAUTY_NOTIFICATION_CLOSE_VIBRATION_FLAG | BEAUTY_NOTIFICATION_LOCKSCREEN_FLAG; + + bool isBanner = beautyTimes < CONTROL_FLAG_LIMIT; + if (isBanner) { + request.SetNotificationControlFlags(baseFlag|BEAUTY_NOTIFICATION_CONTROL_FLAG); + } else { + request.SetNotificationControlFlags(baseFlag); + } + request.SetContent(content); + + GetPixelMap(); + if (iconPixelMap_ != nullptr) { + request.SetLittleIcon(iconPixelMap_); + request.SetBadgeIconStyle(Notification::NotificationRequest::BadgeStyle::LITTLE); + } + + std::string buttonName = beautyStatus == BEAUTY_STATUS_OFF ? GetSystemStringByName(BEAUTY_NOTIFICATION_BUTTON_ON) : + GetSystemStringByName(BEAUTY_NOTIFICATION_BUTTON_OFF); + SetActionButton(buttonName, request, beautyStatus); + + return Notification::NotificationHelper::PublishNotification(request); +} + +int32_t CameraNotification::CancelBeautyNotification() +{ + int32_t ret = Notification::NotificationHelper::CancelNotification(BEAUTY_NOTIFICATION_ID); + resourceManager_ = nullptr; + resConfig_ = nullptr; + return ret; +} + +std::shared_ptr CameraNotification::CreateNotificationNormalContent( + int32_t beautyStatus) +{ + std::shared_ptr normalContent = + std::make_shared(); + CHECK_RETURN_RET_ELOG(normalContent == nullptr, nullptr, "Create normalContent failed"); + normalContent->SetTitle(GetSystemStringByName(BEAUTY_NOTIFICATION_TITLE)); + normalContent->SetText(beautyStatus == BEAUTY_STATUS_OFF ? GetSystemStringByName(BEAUTY_NOTIFICATION_CONTENT_ON) : + GetSystemStringByName(BEAUTY_NOTIFICATION_CONTENT_OFF)); + return normalContent; +} + +void CameraNotification::SetActionButton(const std::string& buttonName, + Notification::NotificationRequest& request, int32_t beautyStatus) +{ + auto want = std::make_shared(); + want->SetAction(EVENT_CAMERA_BEAUTY_NOTIFICATION); + + std::shared_ptr wantParams = std::make_shared(); + sptr intIt = OHOS::AAFwk::Integer::Box(beautyStatus); + wantParams->SetParam(BEAUTY_NOTIFICATION_ACTION_PARAM, intIt); + + want->SetParams(*wantParams); + std::vector> wants; + wants.push_back(want); + + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG); + + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( + 0, AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + flags, wants, wantParams + ); + auto wantAgentDeal = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + std::shared_ptr actionButtonDeal = + Notification::NotificationActionButton::Create(nullptr, buttonName, wantAgentDeal); + CHECK_RETURN_ILOG(actionButtonDeal == nullptr, "Create actionButtonDeal failed"); + request.AddActionButton(actionButtonDeal); +} + +std::string CameraNotification::GetSystemStringByName(std::string name) +{ + InitResourceManager(); + std::string result; + std::string identity = IPCSkeleton::ResetCallingIdentity(); + resourceManager_->GetStringByName(name.c_str(), result); + IPCSkeleton::SetCallingIdentity(identity); + MEDIA_DEBUG_LOG("name: %{public}s, result: %{public}s", name.c_str(), result.c_str()); + return result; +} + +void CameraNotification::GetPixelMap() +{ + CHECK_RETURN_ELOG(iconPixelMap_ != nullptr, "Pixel map already exists."); + + size_t len = 0; + std::unique_ptr data; + Global::Resource::RState rstate = GetMediaDataByName(BEAUTY_NOTIFICATION_ICON_NAME.c_str(), len, data); + CHECK_RETURN_ELOG(rstate != Global::Resource::RState::SUCCESS, "GetMediaDataByName failed"); + + OHOS::Media::SourceOptions opts; + uint32_t errorCode = 0; + std::shared_ptr imageSourceProxy = ImageSourceProxy::CreateImageSourceProxy(); + CHECK_RETURN_ELOG(imageSourceProxy == nullptr, "CreateImageSourceProxy failed"); + auto ret = imageSourceProxy->CreateImageSource(data.get(), len, opts, errorCode); + MEDIA_INFO_LOG("CreateImageSource errorCode: %{public}d", static_cast(errorCode)); + CHECK_RETURN_ELOG(ret != 0, "CreateImageSource failed"); + OHOS::Media::DecodeOptions decodeOpts; + decodeOpts.desiredSize = {ICON_WIDTH, ICON_HEIGHT}; + decodeOpts.desiredPixelFormat = OHOS::Media::PixelFormat::BGRA_8888; + std::unique_ptr pixelMap = imageSourceProxy->CreatePixelMap(decodeOpts, errorCode); + MEDIA_INFO_LOG("CreateImageSource errorCode: %{public}d", static_cast(errorCode)); + CHECK_RETURN_ELOG(pixelMap == nullptr, "Create icon pixel map failed,pixelMap is nullptr"); + iconPixelMap_ = std::move(pixelMap); +} + +Global::Resource::RState CameraNotification::GetMediaDataByName(std::string name, size_t& len, + std::unique_ptr &outValue, uint32_t density) +{ + InitResourceManager(); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + Global::Resource::RState rstate = resourceManager_->GetMediaDataByName(name.c_str(), len, outValue); + IPCSkeleton::SetCallingIdentity(identity); + MEDIA_INFO_LOG("rstate: %{public}d", static_cast(rstate)); + return rstate; +} + +void CameraNotification::InitResourceManager() +{ + if (!resourceManager_) { + MEDIA_INFO_LOG("Init"); + resourceManager_ = Global::Resource::GetSystemResourceManagerNoSandBox(); + } + if (!resConfig_) { + resConfig_ = Global::Resource::CreateResConfig(); + } + RefreshResConfig(); +} + +void CameraNotification::RefreshResConfig() +{ + std::string language = Global::I18n::LocaleConfig::GetSystemLanguage(); + CHECK_RETURN_ILOG(language.empty(), "Get system language failed, skip RefreshResConfig"); + UErrorCode status = U_ZERO_ERROR; + icu::Locale locale = icu::Locale::forLanguageTag(language, status); + bool isSupportZero = status != U_ZERO_ERROR || locale == nullptr; + CHECK_RETURN_ILOG(isSupportZero, "forLanguageTag failed, errCode:%{public}d", status); + CHECK_RETURN_ILOG(!resConfig_, "resConfig_ is nullptr"); + std::string region = Global::I18n::LocaleConfig::GetSystemRegion(); + resConfig_->SetLocaleInfo(locale.getLanguage(), locale.getScript(), region.c_str()); + CHECK_RETURN_ILOG(!resourceManager_, "resourceManager_ is nullptr"); + resourceManager_->UpdateResConfig(*resConfig_); + MEDIA_INFO_LOG("Refresh success"); +} + +extern "C" CameraNotificationIntf *createCameraNotificationIntf() +{ + return new CameraNotification(); +} +} // namespace CameraStandard +} // namespace OHOS +// LCOV_EXCL_STOP diff --git a/frameworks/native/camera/test/unittest/camera_service/camera_service_common/src/camera_beauty_notification_unittest.cpp b/frameworks/native/camera/test/unittest/camera_service/camera_service_common/src/camera_beauty_notification_unittest.cpp index 1421417a2bf56ad06544fcbe7a73804c011b2fda..e7df8cd22f7e3d249f45820bf9c9ccc03c76f578 100644 --- a/frameworks/native/camera/test/unittest/camera_service/camera_service_common/src/camera_beauty_notification_unittest.cpp +++ b/frameworks/native/camera/test/unittest/camera_service/camera_service_common/src/camera_beauty_notification_unittest.cpp @@ -44,7 +44,7 @@ void CameraBeautyNotificationUnit::TearDown() {} *CameraBeautyNotification when the instance is set to itself and then re-obtained. The expected result is that the *instance should remain valid and not be nullptr. */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_001, TestSize.Level1) +HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_001, TestSize.Level0) { sptr test = CameraBeautyNotification::GetInstance(); ASSERT_NE(test, nullptr); @@ -64,7 +64,7 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_001, * EnvConditions: NA * CaseDescription: Test InitResourceManager abnormal branches */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_002, TestSize.Level1) +HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_002, TestSize.Level0) { sptr test = CameraBeautyNotification::GetInstance(); ASSERT_NE(test, nullptr); @@ -73,6 +73,7 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_002, test->SetBeautyStatus(beautyStatus); EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); test->PublishNotification(isRecordTimes_1); + int32_t beautyTimes_1 = 1; test->SetBeautyTimes(beautyTimes_1); EXPECT_EQ(test->GetBeautyTimes(), beautyTimes_1); @@ -80,25 +81,8 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_002, test->SetBeautyTimes(beautyTimes_2); test->PublishNotification(isRecordTimes_1); EXPECT_EQ(test->GetBeautyTimes(), beautyTimes_2); - test->iconPixelMap_ = nullptr; - test->PublishNotification(isRecordTimes_1); - test->iconPixelMap_ = std::make_shared(); - test->PublishNotification(isRecordTimes_1); - bool isRecordTimes_2 = false; - test->PublishNotification(isRecordTimes_2); - test->SetBeautyTimes(beautyTimes_1); - EXPECT_EQ(test->GetBeautyTimes(), beautyTimes_1); - test->resourceManager_ = nullptr; - test->InitResourceManager(); - test->resourceManager_ = Global::Resource::GetSystemResourceManagerNoSandBox(); - test->InitResourceManager(); - test->resConfig_ = nullptr; - test->InitResourceManager(); - test->resConfig_ = Global::Resource::CreateResConfig(); - test->InitResourceManager(); - test->SetBeautyTimes(beautyTimes_2); - test->PublishNotification(isRecordTimes_2); - EXPECT_EQ(test->GetBeautyTimes(), beautyTimes_2); + + test->CancelNotification(); } /* @@ -109,7 +93,7 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_002, * EnvConditions: NA * CaseDescription: Test GetBeautyTimesFromDataShareHelper abnormal branches */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_003, TestSize.Level1) +HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_003, TestSize.Level0) { sptr test = CameraBeautyNotification::GetInstance(); ASSERT_NE(test, nullptr); @@ -123,13 +107,6 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_003, EXPECT_EQ(test->SetBeautyTimesFromDataShareHelper(times), 1); test->cameraDataShareHelper_ = nullptr; EXPECT_EQ(test->GetBeautyTimesFromDataShareHelper(times), 0); - std::string buttonName; - Notification::NotificationRequest request; - test->SetActionButton(buttonName, request, times); - test->iconPixelMap_ = nullptr; - test->GetPixelMap(); - test->iconPixelMap_ = std::make_shared(); - test->GetPixelMap(); test->cameraDataShareHelper_ = std::make_shared(); EXPECT_EQ(test->SetBeautyStatusFromDataShareHelper(beautyStatus), 1); EXPECT_EQ(test->GetBeautyStatusFromDataShareHelper(beautyStatus), 0); @@ -137,170 +114,5 @@ HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_003, EXPECT_EQ(test->GetBeautyTimesFromDataShareHelper(times), 0); } -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test PublishNotification - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_004, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - bool isRecordTimes_1 = true; - bool isRecordTimes_2 = false; - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - test->PublishNotification(isRecordTimes_1); - test->PublishNotification(isRecordTimes_2); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test SetBeautyTimesFromDataShareHelper - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_005, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - int32_t times = 0; - test->SetBeautyTimesFromDataShareHelper(times); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test CreateNotificationNormalContent - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_006, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - - std::shared_ptr normalContent = - test->CreateNotificationNormalContent(beautyStatus); - EXPECT_NE(normalContent, nullptr); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test SetActionButton - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_007, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - - std::string buttonName; - Notification::NotificationRequest request; - int32_t times = 0; - test->SetActionButton(buttonName, request, times); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test GetSystemStringByName - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_008, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - - std::string testName = "ic_public_camera_beauty"; - std::string rseult = test->GetSystemStringByName(testName); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test GetPixelMap - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_009, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - - test->iconPixelMap_ = nullptr; - test->GetPixelMap(); - test->iconPixelMap_ = std::make_shared(); - test->GetPixelMap(); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test GetMediaDataByName - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_010, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - - size_t len = 0; - std::unique_ptr data; - std::string testName = "ic_public_camera_beauty"; - Global::Resource::RState rstate = test->GetMediaDataByName(testName.c_str(), len, data); - EXPECT_EQ(rstate, 0); -} - -/* - * Feature: Framework - * Function: CameraBeautyNotification - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test RefreshResConfig - */ -HWTEST_F(CameraBeautyNotificationUnit, camera_beauty_notification_unittest_011, TestSize.Level0) -{ - sptr test = CameraBeautyNotification::GetInstance(); - ASSERT_NE(test, nullptr); - int32_t beautyStatus = 1; - test->SetBeautyStatus(beautyStatus); - EXPECT_EQ(test->GetBeautyStatus(), beautyStatus); - test->RefreshResConfig(); -} } } \ No newline at end of file diff --git a/frameworks/native/camera/test/unittest/camera_service/hdi_camera_test/src/hcamera_service_unittest.cpp b/frameworks/native/camera/test/unittest/camera_service/hdi_camera_test/src/hcamera_service_unittest.cpp index ba9d67db492abf02a012f5fc1e1f4c23a65643ee..0e2c2e15def7dddb4501d4d42f361d4186e7fefd 100644 --- a/frameworks/native/camera/test/unittest/camera_service/hdi_camera_test/src/hcamera_service_unittest.cpp +++ b/frameworks/native/camera/test/unittest/camera_service/hdi_camera_test/src/hcamera_service_unittest.cpp @@ -22,6 +22,7 @@ #include "camera_common_event_manager.h" #include "camera_log.h" #include "camera_manager.h" +#include "camera_notification_interface.h #include "camera_util.h" #include "gmock/gmock.h" #include "control_center_status_callback_stub.h" diff --git a/services/camera_service/BUILD.gn b/services/camera_service/BUILD.gn index a523462802ca11eda82b8fe2786d3d23c13265bd..ab1de271dc1edee93d158062c0a8d6f172b06bd5 100644 --- a/services/camera_service/BUILD.gn +++ b/services/camera_service/BUILD.gn @@ -171,7 +171,6 @@ ohos_shared_library("camera_service") { ] external_deps = [ - "ability_base:base", "ability_base:want", "ability_base:zuri", "ability_runtime:ability_connect_callback_stub", @@ -213,7 +212,6 @@ ohos_shared_library("camera_service") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "i18n:intl_util", "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_single", @@ -256,7 +254,6 @@ ohos_shared_library("camera_service") { if (defined(global_parts_info) && defined( global_parts_info.notification_distributed_notification_service)) { - external_deps += [ "distributed_notification_service:ans_innerkits" ] defines += [ "NOTIFICATION_ENABLE" ] sources += [ "src/camera_beauty_notification.cpp" ] } diff --git a/services/camera_service/include/camera_beauty_notification.h b/services/camera_service/include/camera_beauty_notification.h index 15f7b05248a3fac6f10715226f8ae07410886945..c67fc6b8b6ffe0e4a1a7ca9abf1311581ffb56ac 100644 --- a/services/camera_service/include/camera_beauty_notification.h +++ b/services/camera_service/include/camera_beauty_notification.h @@ -21,18 +21,7 @@ #include "camera_datashare_helper.h" #include "camera_log.h" #include "camera_util.h" -#include "image_source.h" -#include "int_wrapper.h" -#include "ipc_skeleton.h" -#include "locale_config.h" -#include "notification_helper.h" -#include "notification_normal_content.h" -#include "notification_request.h" -#include "os_account_manager.h" -#include "pixel_map.h" #include "refbase.h" -#include "want_agent_helper.h" -#include "want_agent_info.h" namespace OHOS { namespace CameraStandard { @@ -55,15 +44,6 @@ public: private: void InitBeautyStatus(); - std::string GetSystemStringByName(std::string name); - void GetPixelMap(); - std::shared_ptr CreateNotificationNormalContent(int32_t beautyStatus); - void SetActionButton(const std::string& buttonName, Notification::NotificationRequest& request, - int32_t beautyStatus); - Global::Resource::RState GetMediaDataByName(std::string name, size_t& len, std::unique_ptr &outValue, - uint32_t density = 0); - void InitResourceManager(); - void RefreshResConfig(); static sptr instance_; static std::mutex instanceMutex_; @@ -71,13 +51,11 @@ private: std::mutex notificationMutex_; std::atomic beautyTimes_ = 0; std::atomic beautyStatus_ = 0; - std::shared_ptr iconPixelMap_ = nullptr; std::shared_ptr cameraDataShareHelper_ = nullptr; - Global::Resource::ResourceManager *resourceManager_ = nullptr; - Global::Resource::ResConfig *resConfig_ = nullptr; bool isNotificationSuccess_ = false; }; } // namespace CameraStandard } // namespace OHOS -#endif // CAMERA_BEAUTY_NOTIFICATION_H +#endif // CAMERA_BEAUTY_NOTIFICATION_H + diff --git a/services/camera_service/include/camera_util.h b/services/camera_service/include/camera_util.h index 697d5d19fcb536c044383898091e0d249cbba60f..f336746a658ee545b4ac9068f21f95663d3b0f17 100644 --- a/services/camera_service/include/camera_util.h +++ b/services/camera_service/include/camera_util.h @@ -65,14 +65,6 @@ static const std::string COMMON_EVENT_DATA_SHARE_READY = "usual.event.DATA_SHARE static const std::string COMMON_EVENT_SCREEN_LOCKED = "usual.event.SCREEN_LOCKED"; static const std::string COMMON_EVENT_SCREEN_UNLOCKED = "usual.event.SCREEN_UNLOCKED"; static const std::string COMMON_EVENT_RSS_MULTI_WINDOW_TYPE = "common.event.ressched.window.state"; -#ifdef NOTIFICATION_ENABLE -// beauty notification -static const std::string EVENT_CAMERA_BEAUTY_NOTIFICATION = "CAMERA_BEAUTY_NOTIFICATION"; -static const std::string BEAUTY_NOTIFICATION_ACTION_PARAM = "currentFlag"; -static const int32_t BEAUTY_STATUS_OFF = 0; -static const int32_t BEAUTY_STATUS_ON = 1; -static const int32_t BEAUTY_LEVEL = 100; -#endif // camera control center static const int32_t CONTROL_CENTER_DATA_SIZE = 3; static const int32_t CONTROL_CENTER_STATUS_INDEX = 0; diff --git a/services/camera_service/src/camera_beauty_notification.cpp b/services/camera_service/src/camera_beauty_notification.cpp index ccdd877e2b2d06a26940f21510b15c74ec53850e..4810c5c9afc42ea5ff041df95d6f765488ab6f4a 100644 --- a/services/camera_service/src/camera_beauty_notification.cpp +++ b/services/camera_service/src/camera_beauty_notification.cpp @@ -12,31 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// LCOV_EXCL_START #include "camera_beauty_notification.h" -#include "image_source_proxy.h" +#include "camera_dynamic_loader.h" +#include "camera_notification_proxy.h" +#include "string_ex.h" namespace OHOS { namespace CameraStandard { +typedef int32_t (*PublishBeautyNotification)(bool, int32_t, int32_t); +typedef int32_t (*CancelBeautyNotification)(); sptr CameraBeautyNotification::instance_ = nullptr; std::mutex CameraBeautyNotification::instanceMutex_; -static constexpr int32_t CAMERA_UID = 1047; -const int BEAUTY_NOTIFICATION_ID = 1047001; -const std::string BEAUTY_NOTIFICATION_TITLE = "title_adjust_beauty"; -const std::string BEAUTY_NOTIFICATION_CONTENT_ON = "summary_closed_beauty"; -const std::string BEAUTY_NOTIFICATION_CONTENT_OFF = "summary_opened_beauty"; -const std::string BEAUTY_NOTIFICATION_BUTTON_ON = "open_beauty"; -const std::string BEAUTY_NOTIFICATION_BUTTON_OFF = "close_beauty"; -const uint32_t BEAUTY_NOTIFICATION_CLOSE_SOUND_FLAG = 1 << 0; -const uint32_t BEAUTY_NOTIFICATION_CONTROL_FLAG = 1 << 9; -const uint32_t BEAUTY_NOTIFICATION_LOCKSCREEN_FLAG = 1 << 1; -const uint32_t BEAUTY_NOTIFICATION_CLOSE_VIBRATION_FLAG = 1 << 4; -const std::string BEAUTY_NOTIFICATION_ICON_NAME = "ic_public_camera_beauty"; -const std::string BEAUTY_NOTIFICATION_GROUP_NAME = "camera_beauty"; -const int32_t ICON_WIDTH = 220; -const int32_t ICON_HEIGHT = 220; -const int32_t CONTROL_FLAG_LIMIT = 3; CameraBeautyNotification::CameraBeautyNotification() { @@ -61,65 +49,28 @@ void CameraBeautyNotification::PublishNotification(bool isRecordTimes) isNotificationSuccess_ = false; int32_t beautyStatus = GetBeautyStatus(); int32_t beautyTimes = GetBeautyTimes(); - std::shared_ptr content = - std::make_shared(CreateNotificationNormalContent(beautyStatus)); - - if (content == nullptr) { - MEDIA_ERR_LOG("Create notification content failed"); - return; - } - - Notification::NotificationRequest request; - request.SetCreatorUid(CAMERA_UID); - request.SetCreatorPid(getpid()); - int32_t userId; - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(CAMERA_UID, userId); - - request.SetCreatorUserId(userId); - request.SetDeliveryTime(GetTimestamp()); - request.SetAutoDeletedTime(OHOS::Notification::NotificationConstant::INVALID_AUTO_DELETE_TIME); - request.SetTapDismissed(false); - request.SetSlotType(OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - request.SetNotificationId(BEAUTY_NOTIFICATION_ID); - request.SetGroupName(BEAUTY_NOTIFICATION_GROUP_NAME); - uint32_t baseFlag = BEAUTY_NOTIFICATION_CLOSE_SOUND_FLAG | - BEAUTY_NOTIFICATION_CLOSE_VIBRATION_FLAG | BEAUTY_NOTIFICATION_LOCKSCREEN_FLAG; - - bool isBanner = beautyTimes < CONTROL_FLAG_LIMIT; - if (isBanner) { - request.SetNotificationControlFlags(baseFlag|BEAUTY_NOTIFICATION_CONTROL_FLAG); - } else { - request.SetNotificationControlFlags(baseFlag); - } - request.SetContent(content); - - GetPixelMap(); - if (iconPixelMap_ != nullptr) { - request.SetLittleIcon(iconPixelMap_); - request.SetBadgeIconStyle(Notification::NotificationRequest::BadgeStyle::LITTLE); - } - - std::string buttonName = beautyStatus == BEAUTY_STATUS_OFF ? GetSystemStringByName(BEAUTY_NOTIFICATION_BUTTON_ON) : - GetSystemStringByName(BEAUTY_NOTIFICATION_BUTTON_OFF); - SetActionButton(buttonName, request, beautyStatus); - int ret = Notification::NotificationHelper::PublishNotification(request); + std::shared_ptr cameraNotificationProxy = + CameraNotificationProxy::CreateCameraNotificationProxy(); + int32_t ret = cameraNotificationProxy->PublishBeautyNotification(isRecordTimes, beautyStatus, beautyTimes); MEDIA_INFO_LOG("CameraBeautyNotification::PublishNotification result = %{public}d", ret); isNotificationSuccess_ = (ret == CAMERA_OK); - if (ret == CAMERA_OK && isBanner && beautyTimes <= CONTROL_FLAG_LIMIT && isRecordTimes) { - beautyTimes_.operator++(); - SetBeautyTimesFromDataShareHelper(GetBeautyTimes()); - } + bool isSetTimes = (ret == CAMERA_OK) && (beautyTimes < CONTROL_FLAG_LIMIT) && + (beautyTimes <= CONTROL_FLAG_LIMIT) && isRecordTimes; + CHECK_RETURN(!isSetTimes); + beautyTimes_.operator++(); + SetBeautyTimesFromDataShareHelper(GetBeautyTimes()); } void CameraBeautyNotification::CancelNotification() { std::lock_guard lock(notificationMutex_); - if (!isNotificationSuccess_) { - return; - } + CHECK_RETURN(!isNotificationSuccess_); isNotificationSuccess_ = false; - int ret = Notification::NotificationHelper::CancelNotification(BEAUTY_NOTIFICATION_ID); + + std::shared_ptr cameraNotificationProxy = + CameraNotificationProxy::CreateCameraNotificationProxy(); + int32_t ret = cameraNotificationProxy->CancelBeautyNotification(); MEDIA_INFO_LOG("CameraBeautyNotification::CancelNotification result = %{public}d", ret); } @@ -153,7 +104,13 @@ int32_t CameraBeautyNotification::GetBeautyStatusFromDataShareHelper(int32_t &be if (ret != CAMERA_OK) { beautyStatus = BEAUTY_STATUS_OFF; } else { - beautyStatus = std::stoi(value); + int32_t convertedValue = 0; + if (!StrToInt(value, convertedValue)) { + MEDIA_INFO_LOG("Convert value to int32_t failed"); + beautyStatus = 0; + return CAMERA_ALLOC_ERROR; + } + beautyStatus = convertedValue; } return CAMERA_OK; } @@ -164,8 +121,7 @@ int32_t CameraBeautyNotification::SetBeautyStatusFromDataShareHelper(int32_t bea cameraDataShareHelper_ = std::make_shared(); } auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_CAMERA_BEAUTY_STATUS, std::to_string(beautyStatus)); - CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, - "SetBeautyStatusFromDataShareHelper UpdateOnce fail."); + CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetBeautyStatusFromDataShareHelper UpdateOnce fail."); return CAMERA_OK; } @@ -179,7 +135,13 @@ int32_t CameraBeautyNotification::GetBeautyTimesFromDataShareHelper(int32_t &tim if (ret != CAMERA_OK) { times = 0; } else { - times = std::stoi(value); + int32_t convertedValue = 0; + if (!StrToInt(value, convertedValue)) { + MEDIA_INFO_LOG("Convert value to int32_t failed"); + times = 0; + return CAMERA_ALLOC_ERROR; + } + times = convertedValue; } return CAMERA_OK; } @@ -190,8 +152,7 @@ int32_t CameraBeautyNotification::SetBeautyTimesFromDataShareHelper(int32_t time cameraDataShareHelper_ = std::make_shared(); } auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_CAMERA_BEAUTY_TIMES, std::to_string(times)); - CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, - "SetBeautyTimesFromDataShareHelper UpdateOnce fail."); + CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetBeautyTimesFromDataShareHelper UpdateOnce fail."); return CAMERA_OK; } @@ -205,140 +166,6 @@ void CameraBeautyNotification::InitBeautyStatus() SetBeautyStatus(beautyStatus); SetBeautyTimes(times); } - -std::shared_ptr CameraBeautyNotification::CreateNotificationNormalContent( - int32_t beautyStatus) -{ - std::shared_ptr normalContent = - std::make_shared(); - CHECK_RETURN_RET_ELOG(normalContent == nullptr, nullptr, "Create normalContent failed"); - normalContent->SetTitle(GetSystemStringByName(BEAUTY_NOTIFICATION_TITLE)); - normalContent->SetText(beautyStatus == BEAUTY_STATUS_OFF ? GetSystemStringByName(BEAUTY_NOTIFICATION_CONTENT_ON) : - GetSystemStringByName(BEAUTY_NOTIFICATION_CONTENT_OFF)); - return normalContent; -} - -void CameraBeautyNotification::SetActionButton(const std::string& buttonName, - Notification::NotificationRequest& request, int32_t beautyStatus) -{ - auto want = std::make_shared(); - want->SetAction(EVENT_CAMERA_BEAUTY_NOTIFICATION); - - std::shared_ptr wantParams = std::make_shared(); - sptr intIt = OHOS::AAFwk::Integer::Box(beautyStatus); - wantParams->SetParam(BEAUTY_NOTIFICATION_ACTION_PARAM, intIt); - - want->SetParams(*wantParams); - std::vector> wants; - wants.push_back(want); - - std::vector flags; - flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG); - - AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( - 0, AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, - flags, wants, wantParams - ); - auto wantAgentDeal = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); - std::shared_ptr actionButtonDeal = - Notification::NotificationActionButton::Create(nullptr, buttonName, wantAgentDeal); - if (actionButtonDeal == nullptr) { - MEDIA_INFO_LOG("Create actionButtonDeal failed"); - return; - } - request.AddActionButton(actionButtonDeal); -} - -std::string CameraBeautyNotification::GetSystemStringByName(std::string name) -{ - InitResourceManager(); - std::string result; - std::string identity = IPCSkeleton::ResetCallingIdentity(); - resourceManager_->GetStringByName(name.c_str(), result); - IPCSkeleton::SetCallingIdentity(identity); - MEDIA_DEBUG_LOG("name: %{public}s, result: %{public}s", name.c_str(), result.c_str()); - return result; -} - -void CameraBeautyNotification::GetPixelMap() -{ - if (iconPixelMap_ != nullptr) { - MEDIA_ERR_LOG("Pixel map already exists."); - return; - } - - size_t len = 0; - std::unique_ptr data; - Global::Resource::RState rstate = GetMediaDataByName(BEAUTY_NOTIFICATION_ICON_NAME.c_str(), len, data); - if (rstate != Global::Resource::RState::SUCCESS) { - MEDIA_ERR_LOG("GetMediaDataByName failed"); - return; - } - - OHOS::Media::SourceOptions opts; - uint32_t errorCode = 0; - std::shared_ptr imageSourceProxy = ImageSourceProxy::CreateImageSourceProxy(); - CHECK_RETURN_ELOG(imageSourceProxy == nullptr, "CreateImageSourceProxy failed"); - auto ret = imageSourceProxy->CreateImageSource(data.get(), len, opts, errorCode); - CHECK_RETURN_ELOG(ret != 0, "CreateImageSource failed"); - MEDIA_INFO_LOG("CreateImageSource errorCode: %{public}d", static_cast(errorCode)); - OHOS::Media::DecodeOptions decodeOpts; - decodeOpts.desiredSize = {ICON_WIDTH, ICON_HEIGHT}; - decodeOpts.desiredPixelFormat = OHOS::Media::PixelFormat::BGRA_8888; - std::unique_ptr pixelMap = imageSourceProxy->CreatePixelMap(decodeOpts, errorCode); - MEDIA_INFO_LOG("CreateImageSource errorCode: %{public}d", static_cast(errorCode)); - CHECK_RETURN_ELOG(pixelMap == nullptr, "Create icon pixel map failed,pixelMap is nullptr"); - iconPixelMap_ = std::move(pixelMap); -} - -Global::Resource::RState CameraBeautyNotification::GetMediaDataByName(std::string name, size_t& len, - std::unique_ptr &outValue, uint32_t density) -{ - InitResourceManager(); - std::string identity = IPCSkeleton::ResetCallingIdentity(); - Global::Resource::RState rstate = resourceManager_->GetMediaDataByName(name.c_str(), len, outValue); - IPCSkeleton::SetCallingIdentity(identity); - MEDIA_INFO_LOG("rstate: %{public}d", static_cast(rstate)); - return rstate; -} - -void CameraBeautyNotification::InitResourceManager() -{ - if (!resourceManager_) { - MEDIA_INFO_LOG("Init"); - resourceManager_ = Global::Resource::GetSystemResourceManagerNoSandBox(); - } - if (!resConfig_) { - resConfig_ = Global::Resource::CreateResConfig(); - } - RefreshResConfig(); -} - -void CameraBeautyNotification::RefreshResConfig() -{ - std::string language = Global::I18n::LocaleConfig::GetSystemLanguage(); - if (language.empty()) { - MEDIA_INFO_LOG("Get system language failed, skip RefreshResConfig"); - return; - } - UErrorCode status = U_ZERO_ERROR; - icu::Locale locale = icu::Locale::forLanguageTag(language, status); - if (status != U_ZERO_ERROR || locale == nullptr) { - MEDIA_INFO_LOG("forLanguageTag failed, errCode:%{public}d", status); - return; - } - if (!resConfig_) { - MEDIA_INFO_LOG("resConfig_ is nullptr"); - return; - } - std::string region = Global::I18n::LocaleConfig::GetSystemRegion(); - resConfig_->SetLocaleInfo(locale.getLanguage(), locale.getScript(), region.c_str()); - if (!resourceManager_) { - MEDIA_INFO_LOG("resourceManager_ is nullptr"); - return; - } - resourceManager_->UpdateResConfig(*resConfig_); - MEDIA_INFO_LOG("Refresh success"); -} } // namespace CameraStandard } // namespace OHOS +// LCOV_EXCL_STOP \ No newline at end of file diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index 53392af09ec7c86c5a379d23fd22104f1e4ebc99..14881a9dc7348f97501c1e5ae03d6755b305d469 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -35,6 +35,7 @@ #include "session/capture_scene_const.h" #ifdef NOTIFICATION_ENABLE #include "camera_beauty_notification.h" +#include "camera_notification_interface.h" #endif #include "camera_info_dumper.h" #include "camera_log.h" diff --git a/services/camera_service/src/hstream_repeat.cpp b/services/camera_service/src/hstream_repeat.cpp index cb58b35003bcdb40faac9d088e8998769c184e54..81a2a6725591cf3a573ad8e23ba8c4c75f63dd9f 100644 --- a/services/camera_service/src/hstream_repeat.cpp +++ b/services/camera_service/src/hstream_repeat.cpp @@ -20,6 +20,7 @@ #ifdef NOTIFICATION_ENABLE #include "camera_beauty_notification.h" +#include "camera_notification_interface.h" #endif #include "camera_device_ability_items.h" #include "camera_log.h"