/* * 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 "../include/notificationgetparam.h" #include #include #include #include #include #include "abs_shared_result_set.h" #include "data_ability_predicates.h" #include "values_bucket.h" using namespace std; using namespace OHOS::AppExecFwk; using namespace OHOS::EventFwk; using Uri = OHOS::Uri; namespace { static const int INDEX_ZERO = 0; static const int INDEX_ONE = 1; static const int INDEX_TWO = 2; static const int INDEX_THREE = 3; static const int INDEX_FOUR = 4; static const int INDEX_FIVE = 5; static const int INDEX_SIX = 6; static const int INDEX_SEVEN = 7; static const int INDEX_EIGHT = 8; static const int INDEX_NINE = 9; static const int INDEX_TEN = 10; static const int CHAR_MINCOUNT = -128; static const int CHAR_MAXCOUNT = 127; static const int MAX_LENGTH = 255; } // namespace namespace OHOS { namespace Notification { std::mutex TestAnsSubscriber::mutex = std::mutex(); bool GetBoolParam() { bool param; if (GetIntParam() % INDEX_TWO == 0) { param = true; } else { param = false; } return param; } size_t GenRandom(size_t min, size_t max) { std::random_device rd; static uniform_int_distribution u(min, max); static default_random_engine e(rd()); size_t param = u(e); return param; } int8_t GetS8Param() { std::random_device rd; static uniform_int_distribution u(INT8_MIN, INT8_MAX); static default_random_engine e(rd()); int8_t param = u(e); return param; } int16_t GetS16Param() { std::random_device rd; static uniform_int_distribution u(INT16_MIN, INT16_MAX); static default_random_engine e(rd()); int16_t param = u(e); return param; } int32_t GetS32Param() { std::random_device rd; static uniform_int_distribution u(INT32_MIN, INT32_MAX); static default_random_engine e(rd()); int32_t param = u(e); return param; } int64_t GetS64Param() { std::random_device rd; static uniform_int_distribution u(INT64_MIN, INT64_MAX); static default_random_engine e(rd()); int64_t param = u(e); return param; } template T GetUnsignParam() { std::random_device rd; static uniform_int_distribution u; static default_random_engine e(rd()); T param = u(e); return param; } size_t GetSizeTParam() { size_t param = GetUnsignParam(); return param; } uint8_t GetU8Param() { uint8_t param = GetUnsignParam(); return param; } unsigned int GetUIntParam() { unsigned int param = GetUnsignParam(); return param; } uint16_t GetU16Param() { uint16_t param = GetUnsignParam(); return param; } uint32_t GetU32Param() { uint32_t param = GetUnsignParam(); return param; } uint64_t GetU64Param() { uint64_t param = GetUnsignParam(); return param; } short GetShortParam() { std::random_device rd; static uniform_int_distribution u(SHRT_MIN, SHRT_MAX); static default_random_engine e(rd()); short param = u(e); return param; } long GetLongParam() { std::random_device rd; static uniform_int_distribution u(LONG_MIN, LONG_MAX); static default_random_engine e(rd()); long param = u(e); return param; } int GetIntParam() { std::random_device rd; static uniform_int_distribution<> u(INT_MIN, INT_MAX); static default_random_engine e(rd()); int param = u(e); return param; } double GetDoubleParam() { double param = 0; std::random_device rd; static uniform_real_distribution u(DBL_MIN, DBL_MAX); static default_random_engine e(rd()); param = u(e); return param; } float GetFloatParam() { float param = 0; std::random_device rd; static uniform_real_distribution u(FLT_MIN, FLT_MAX); static default_random_engine e(rd()); param = u(e); return param; } char GetCharParam() { std::random_device rd; static uniform_int_distribution<> u(CHAR_MINCOUNT, CHAR_MAXCOUNT); static default_random_engine e(rd()); char param = u(e); return param; } char32_t GetChar32Param() { char32_t param = ' '; std::random_device rd; static uniform_int_distribution u; static default_random_engine e(rd()); param = u(e); return param; } char *GetCharArryParam() { static char param[256]; size_t len = 0; string strparam = GetStringParam(); if (!strparam.empty()) { len = strparam.size() + 1; if (len > sizeof(param)) { len = sizeof(param) - 1; } int ret = strcpy_s(param, len, strparam.c_str()); if (ret == 0) { return param; } else { return nullptr; } } else { return nullptr; } } string GetStringParam() { string param = ""; char ch = GetCharParam(); size_t len = GenRandom(0, MAX_LENGTH); while (len--) { ch = GetCharParam(); param += ch; } return param; } template vector GetUnsignVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { T t = GetUnsignParam(); param.push_back(t); } return param; } template T GetClassParam() { T param; return param; } std::vector GetBoolVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int t = GetBoolParam(); param.push_back(t); } return param; } std::vector GetShortVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { short t = GetShortParam(); param.push_back(t); } return param; } std::vector GetLongVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { long t = GetLongParam(); param.push_back(t); } return param; } vector GetIntVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int t = GetIntParam(); param.push_back(t); } return param; } std::vector GetFloatVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { float t = GetIntParam(); param.push_back(t); } return param; } std::vector GetDoubleVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { double t = GetIntParam(); param.push_back(t); } return param; } vector GetCharVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { char t = GetCharParam(); param.push_back(t); } return param; } vector GetChar32VectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { char32_t t = GetChar32Param(); param.push_back(t); } return param; } vector GetStringVectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { string t = GetStringParam(); param.push_back(t); } return param; } vector GetS8VectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int8_t temp = GetS8Param(); param.push_back(temp); } return param; } vector GetS16VectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int16_t temp = GetS16Param(); param.push_back(temp); } return param; } vector GetS32VectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int32_t temp = GetS32Param(); param.push_back(temp); } return param; } vector GetS64VectorParam() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int64_t temp = GetS64Param(); param.push_back(temp); } return param; } std::shared_ptr GetParamParcel() { return make_shared(); } std::shared_ptr GetParamWant() { return make_shared(); } std::vector> GetParamWantVector() { vector> param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { std::shared_ptr t = GetParamWant(); param.push_back(t); } return param; } OHOS::AAFwk::Operation GetParamOperation() { return OHOS::AAFwk::Operation(); } sptr GetParamSptrRemote() { return sptr(); } std::shared_ptr GetParamEventRunner() { return EventRunner::Create(GetCharArryParam()); } std::shared_ptr GetParamAbility() { return make_shared(); } std::shared_ptr GetParamWantParams() { return make_shared(); } OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag() { if (GetBoolParam()) { return OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO; } else { return OHOS::AppExecFwk::ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMS; } } OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo() { return OHOS::AppExecFwk::ApplicationInfo(); } OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo() { return OHOS::AppExecFwk::AbilityInfo(); } sptr GetParamIBundleStatusCallback() { return sptr(); } std::shared_ptr GetParamNotificationSorting() { return std::make_shared(); } std::vector GetParamNotificationSortingVector() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { NotificationSorting t; param.push_back(t); } return param; } std::shared_ptr GetParamNotificationSortingMap() { if (GetBoolParam()) { return std::make_shared(); } else { std::vector sortingList = GetParamNotificationSortingVector(); return std::make_shared(sortingList); } } std::shared_ptr GetParamNotificationSlot() { return std::make_shared(GetParamSlotType()); } sptr GetParamNotificationSlotSptr() { sptr param = new OHOS::Notification::NotificationSlot(GetParamSlotType()); return param; } OHOS::Notification::NotificationConstant::SlotType GetParamSlotType() { switch (GetIntParam() % INDEX_FIVE) { case INDEX_ZERO: return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION; break; case INDEX_ONE: return OHOS::Notification::NotificationConstant::SlotType::SERVICE_REMINDER; break; case INDEX_TWO: return OHOS::Notification::NotificationConstant::SlotType::CONTENT_INFORMATION; break; case INDEX_THREE: return OHOS::Notification::NotificationConstant::SlotType::CUSTOM; break; case INDEX_FOUR: return OHOS::Notification::NotificationConstant::SlotType::OTHER; break; default: return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION; break; } } std::vector> GetParamNotificationSlotSptrVector() { vector> param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationSlotSptr(); param.push_back(t); } return param; } std::vector GetParamNotificationSlotVector() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { NotificationSlot t = *GetParamNotificationSlot(); param.push_back(t); } return param; } std::shared_ptr GetParamNotificationBundleOption() { if (GetBoolParam()) { return std::make_shared(); } else { return std::make_shared(GetStringParam(), GetS32Param()); } } std::shared_ptr GetParamNotificationRequest() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: return std::make_shared(); break; case INDEX_ONE: return std::make_shared(GetS32Param()); break; case INDEX_TWO: return std::make_shared(GetParamContext(), GetS32Param()); break; default: return std::make_shared(); break; } } sptr GetParamNotificationRequestSptr() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: { sptr param = new OHOS::Notification::NotificationRequest(); return param; } break; case INDEX_ONE: { sptr param = new OHOS::Notification::NotificationRequest(GetS32Param()); return param; } break; case INDEX_TWO: { sptr param = new OHOS::Notification::NotificationRequest(GetParamContext(), GetS32Param()); return param; } break; default: { sptr param = new OHOS::Notification::NotificationRequest(); return param; } break; } } std::vector> GetParamNotificationRequestVector() { vector> param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationRequestSptr(); param.push_back(t); } return param; } sptr GetParamNotificationSortingMapSptr() { sptr param; if (GetBoolParam()) { param = new OHOS::Notification::NotificationSortingMap(); } else { std::vector sortingList = GetParamNotificationSortingVector(); param = new OHOS::Notification::NotificationSortingMap(sortingList); } return param; } OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel() { switch (GetIntParam() % INDEX_SIX) { case INDEX_ZERO: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE; break; case INDEX_ONE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_MIN; break; case INDEX_TWO: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_LOW; break; case INDEX_THREE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_DEFAULT; break; case INDEX_FOUR: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_HIGH; break; case INDEX_FIVE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_UNDEFINED; break; default: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE; break; } } std::shared_ptr GetParamNotificationSubscriber() { return std::make_shared(); } std::shared_ptr GetParamNotificationSubscribeInfo() { return std::make_shared(); } std::shared_ptr GetParamWantAgentInfo() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: return std::make_shared(); break; case INDEX_ONE: { std::vector> param = GetParamWantVector(); return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlags(), param, GetParamWantParams()); } break; case INDEX_TWO: { std::vector> param = GetParamWantVector(); return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlagsVector(), param, GetParamWantParams()); } break; default: return std::make_shared(); break; } } OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType GetParamOperationType() { switch (GetIntParam() % INDEX_SIX) { case INDEX_ZERO: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; break; case INDEX_ONE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY; break; case INDEX_TWO: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITIES; break; case INDEX_THREE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_SERVICE; break; case INDEX_FOUR: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT; break; case INDEX_FIVE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; break; default: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; break; } } OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags GetParamFlags() { switch (GetIntParam() % INDEX_TEN) { case INDEX_ZERO: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; break; case INDEX_ONE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG; break; case INDEX_TWO: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG; break; case INDEX_THREE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG; break; case INDEX_FOUR: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG; break; case INDEX_FIVE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT; break; case INDEX_SIX: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION; break; case INDEX_SEVEN: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_URI; break; case INDEX_EIGHT: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES; break; case INDEX_NINE: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE; break; default: return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; break; } } std::vector GetParamFlagsVector() { vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags t = GetParamFlags(); param.push_back(t); } return param; } std::shared_ptr GetParamNotification() { sptr param = GetParamNotificationRequestSptr(); return std::make_shared(param); } sptr GetParamNotificationSptr() { sptr t = GetParamNotificationRequestSptr(); sptr param = new OHOS::Notification::Notification(t); return param; } std::vector> GetParamNotificationSptrVector() { std::vector> param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationSptr(); param.push_back(t); } return param; } std::shared_ptr GetParamPendingWant() { sptr target = new WantSender(); sptr allowlistToken = GetParamSptrRemote(); if (GetBoolParam()) { return std::make_shared(target); } else { return std::make_shared(target, allowlistToken); } } std::shared_ptr GetParamWantAgent() { if (GetBoolParam()) { return std::make_shared(); } else { return std::make_shared(GetParamPendingWant()); } } std::shared_ptr GetParamCompletedCallback() { return std::make_shared(); } std::shared_ptr GetParamTriggerInfo() { if (GetBoolParam()) { return std::make_shared(); } else { return std::make_shared( GetStringParam(), GetParamWantParams(), GetParamWant(), GetIntParam()); } } std::shared_ptr GetParamCancelListener() { return std::make_shared(); } std::shared_ptr GetParamLauncherService() { return make_shared(); } std::vector GetParamLauncherAbilityInfoVector() { std::vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::LauncherAbilityInfo t; param.push_back(t); } return param; } std::shared_ptr GetParamLauncherAbilityInfo() { return make_shared(); } std::vector GetParamLauncherShortcutInfoVector() { std::vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::LauncherShortcutInfo t; param.push_back(t); } return param; } std::vector GetParamFormInfoVector() { std::vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::FormInfo t; param.push_back(t); } return param; } std::vector GetParamShortcutInfoVector() { std::vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::ShortcutInfo t; param.push_back(t); } return param; } std::vector GetParamModuleUsageRecordVector() { std::vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::ModuleUsageRecord t; param.push_back(t); } return param; } sptr GetParamOnPermissionChangedCallback() { return sptr(); } std::shared_ptr GetParamTaskDispatcher() { switch (GetIntParam() % INDEX_FOUR) { case INDEX_ZERO: return GetParamContext()->GetMainTaskDispatcher(); break; case INDEX_ONE: return GetParamContext()->CreateParallelTaskDispatcher(GetStringParam(), GetParamTaskPriority()); break; case INDEX_TWO: return GetParamContext()->CreateSerialTaskDispatcher(GetStringParam(), GetParamTaskPriority()); break; case INDEX_THREE: return GetParamContext()->GetGlobalTaskDispatcher(GetParamTaskPriority()); break; default: return GetParamContext()->GetMainTaskDispatcher(); break; } } OHOS::AppExecFwk::TaskPriority GetParamTaskPriority() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: return OHOS::AppExecFwk::TaskPriority::HIGH; break; case INDEX_ONE: return OHOS::AppExecFwk::TaskPriority::DEFAULT; break; case INDEX_TWO: return OHOS::AppExecFwk::TaskPriority::LOW; break; default: return OHOS::AppExecFwk::TaskPriority::HIGH; break; } } std::shared_ptr GetParamRunnable() { return std::make_shared([]() { std::cout << "Start task runnable."; }); } std::shared_ptr GetParamGroup() { return std::make_shared(); } std::shared_ptr> GetParamIteratableTask() { return std::make_shared>([](long data) { std::cout << "Start IteratableTask."; }); } OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS; case INDEX_ONE: return OHOS::Notification::NotificationConstant::SubscribeResult::PREMISSION_FAIL; case INDEX_TWO: return OHOS::Notification::NotificationConstant::SubscribeResult::RESOURCES_FAIL; default: return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS; } } OHOS::AppExecFwk::MissionInformation GetParamMissionInformation() { return OHOS::AppExecFwk::MissionInformation(); } std::shared_ptr GetParamAbilityLifecycleCallbacks() { return std::make_shared(); } std::shared_ptr GetParamBaseTaskDispatcher() { std::shared_ptr context = std::make_shared(); std::shared_ptr config = std::make_shared(GetStringParam(), GetParamTaskPriority()); std::shared_ptr specTaskDispatcher = std::make_shared(config, GetParamEventRunner()); switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority()); case INDEX_ONE: return context->CreateParallelDispatcher(GetStringParam(), GetParamTaskPriority()); case INDEX_TWO: return specTaskDispatcher; default: return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority()); } } std::shared_ptr GetParamIAbilityManager() { std::shared_ptr param = DelayedSingleton::GetInstance(); return param; } std::shared_ptr GetParamNotificationDoNotDisturbDate() { if (GetBoolParam()) { return std::make_shared(); } else { return std::make_shared( GetParamDoNotDisturbType(), GetS64Param(), GetS64Param()); } } OHOS::Notification::NotificationConstant::DoNotDisturbType GetParamDoNotDisturbType() { switch (GetIntParam() % INDEX_FOUR) { case INDEX_ZERO: return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE; break; case INDEX_ONE: return OHOS::Notification::NotificationConstant::DoNotDisturbType::ONCE; break; case INDEX_TWO: return OHOS::Notification::NotificationConstant::DoNotDisturbType::DAILY; break; case INDEX_THREE: return OHOS::Notification::NotificationConstant::DoNotDisturbType::CLEARLY; break; default: return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE; break; } } } // namespace Notification } // namespace OHOS