From 2bdde61924332ce85bc42934c0ba4ca073261f4a Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 6 Jan 2023 08:17:54 +0000 Subject: [PATCH 01/31] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 0bb6d6f4af..9feec9e6ce 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -544,6 +544,10 @@ int32_t AppMgrServiceInner::KillApplicationSelf() auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); + if (!appRecord) { + HILOG_ERROR("appRecord is nullptr"); + return ERR_NO_INIT; + } auto bundleName = appRecord->GetBundleName(); return KillApplicationByBundleName(bundleName); } From 5f2a54064ab090e234c027664332fe6f118c0af3 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 9 Jan 2023 07:38:33 +0000 Subject: [PATCH 02/31] Description:add terminate application Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/include/app_mgr_service_inner.h | 2 ++ services/appmgr/src/app_mgr_service_inner.cpp | 5 +++++ services/appmgr/src/module_running_record.cpp | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 1f1f4f38c7..5bf932e25f 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -721,6 +721,8 @@ private: void HandleTerminateApplicationTimeOut(const int64_t eventId); + void TerminateApplication(const std::shared_ptr &appRecord); + void HandleAddAbilityStageTimeOut(const int64_t eventId); void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index fdb3b100b1..266562abad 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1683,6 +1683,11 @@ void AppMgrServiceInner::HandleTerminateApplicationTimeOut(const int64_t eventId return; } auto appRecord = appRunningManager_->GetAppRunningRecord(eventId); + TerminateApplication(appRecord); +} + +void AppMgrServiceInner::TerminateApplication(const std::shared_ptr &appRecord) +{ if (!appRecord) { HILOG_ERROR("appRecord is nullptr"); return; diff --git a/services/appmgr/src/module_running_record.cpp b/services/appmgr/src/module_running_record.cpp index 90b4c1ff01..6c5622af93 100644 --- a/services/appmgr/src/module_running_record.cpp +++ b/services/appmgr/src/module_running_record.cpp @@ -267,7 +267,7 @@ void ModuleRunningRecord::TerminateAbility(const sptr &token, con auto serviceInner = appMgrServiceInner_.lock(); auto appRunningRecord = appRunningRecord_.lock(); if (serviceInner) { - serviceInner->ClearAppRunningData(appRunningRecord, true); + serviceInner->TerminateApplication(appRunningRecord); } } From 283eee2f2538dff792ce9936601d271fdf150278 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 9 Jan 2023 08:16:33 +0000 Subject: [PATCH 03/31] Description:add terminate application Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/include/app_mgr_service_inner.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 5bf932e25f..75866311cc 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -540,6 +540,8 @@ public: void ClearAppRunningData(const std::shared_ptr &appRecord, bool containsApp); + void TerminateApplication(const std::shared_ptr &appRecord); + int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); /** * Notify application status. @@ -721,8 +723,6 @@ private: void HandleTerminateApplicationTimeOut(const int64_t eventId); - void TerminateApplication(const std::shared_ptr &appRecord); - void HandleAddAbilityStageTimeOut(const int64_t eventId); void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr); From 5db1c7eecce0096dd17d79497e59b6c196d2c070 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Mon, 9 Jan 2023 17:17:17 +0800 Subject: [PATCH 04/31] =?UTF-8?q?applicationContext=E7=9A=84on=E3=80=81off?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=8D=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: Iee1708e28ba8daf2544f99f1b13fd8d990786435 --- .../napi/app/application_context/application_context.js | 8 ++++++++ .../context/js_application_context_utils.cpp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index 844540b2bb..ad56f6eef7 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -95,6 +95,14 @@ class ApplicationContext { return this.__context_impl__.unregisterEnvironmentCallback(callbackId, envcallback) } + on(type, callback) { + return this.__context_impl__.on(type, callback); + } + + off(type, callbackId, callback) { + return this.__context_impl__.off(type, callbackId, callback); + } + createBundleContext(bundleName) { return this.__context_impl__.createBundleContext(bundleName) } diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 3c82a6ec9b..71f8131ca8 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -767,7 +767,7 @@ NativeValue *JsApplicationContextUtils::OnOn(NativeEngine &engine, NativeCallbac return engine.CreateUndefined(); } - if (type == "abilityLifeCycle") { + if (type == "abilityLifecycle") { return OnOnAbilityLifecycle(engine, info); } if (type == "environment") { @@ -811,7 +811,7 @@ NativeValue *JsApplicationContextUtils::OnOff(NativeEngine &engine, const Native return engine.CreateUndefined(); } - if (type == "abilityLifeCycle") { + if (type == "abilityLifecycle") { return OnOffAbilityLifecycle(engine, info, callbackId); } if (type == "environment") { From e09329eb097e206ee21cc1747353b815284f9076 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 9 Jan 2023 09:37:19 +0000 Subject: [PATCH 05/31] Description:add terminate application Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/include/module_running_record.h | 5 ++--- services/appmgr/src/app_running_record.cpp | 2 +- services/appmgr/src/module_running_record.cpp | 11 +++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/services/appmgr/include/module_running_record.h b/services/appmgr/include/module_running_record.h index 8f41a57a0e..eacc3aa107 100644 --- a/services/appmgr/include/module_running_record.h +++ b/services/appmgr/include/module_running_record.h @@ -136,7 +136,8 @@ public: * * @return */ - void TerminateAbility(const sptr &token, const bool isForce); + void TerminateAbility(const std::shared_ptr &appRecord, + const sptr &token, const bool isForce); /** * AbilityTerminated, terminate the ability. @@ -173,8 +174,6 @@ public: void SetApplicationClient(std::shared_ptr &appLifeCycleDeal); - void SetAppRunningRecord(const std::shared_ptr &appRunningRecord); - const std::shared_ptr GetAppInfo(); bool RemoveTerminateAbilityTimeoutTask(const sptr& token) const; diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 3d1cc03f65..f00a2fda7e 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -903,7 +903,7 @@ void AppRunningRecord::TerminateAbility(const sptr &token, const auto abilityRecord = GetAbilityRunningRecordByToken(token); StateChangedNotifyObserver(abilityRecord, static_cast(AbilityState::ABILITY_STATE_TERMINATED), true); - moduleRecord->TerminateAbility(token, isForce); + moduleRecord->TerminateAbility(shared_from_this(), token, isForce); } void AppRunningRecord::AbilityTerminated(const sptr &token) diff --git a/services/appmgr/src/module_running_record.cpp b/services/appmgr/src/module_running_record.cpp index 6c5622af93..49d191f6ec 100644 --- a/services/appmgr/src/module_running_record.cpp +++ b/services/appmgr/src/module_running_record.cpp @@ -236,7 +236,8 @@ void ModuleRunningRecord::LaunchPendingAbilities() } } -void ModuleRunningRecord::TerminateAbility(const sptr &token, const bool isForce) +void ModuleRunningRecord::TerminateAbility(const std::shared_ptr &appRecord, + const sptr &token, const bool isForce) { HILOG_INFO("Terminate ability."); auto abilityRecord = GetAbilityRunningRecordByToken(token); @@ -265,9 +266,8 @@ void ModuleRunningRecord::TerminateAbility(const sptr &token, con } else { HILOG_WARN("appLifeCycleDeal_ is null"); auto serviceInner = appMgrServiceInner_.lock(); - auto appRunningRecord = appRunningRecord_.lock(); if (serviceInner) { - serviceInner->TerminateApplication(appRunningRecord); + serviceInner->TerminateApplication(appRecord); } } @@ -345,10 +345,5 @@ ModuleRecordState ModuleRunningRecord::GetState() const { return owenState_; } - -void ModuleRunningRecord::SetAppRunningRecord(const std::shared_ptr &appRunningRecord) -{ - appRunningRecord_ = appRunningRecord; -} } // namespace AppExecFwk } // namespace OHOS From 2d1201b1f51015225e764bf4b828d2f7696666eb Mon Sep 17 00:00:00 2001 From: liweifeng Date: Mon, 9 Jan 2023 18:41:55 +0800 Subject: [PATCH 06/31] =?UTF-8?q?this=20=E6=8C=87=E9=92=88=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20share=5Fptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: Ic92a508639e649d98fedeffbd155481962095678 --- frameworks/native/appkit/app/idle_time.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frameworks/native/appkit/app/idle_time.cpp b/frameworks/native/appkit/app/idle_time.cpp index eec33e9a2a..28aa60c3b2 100644 --- a/frameworks/native/appkit/app/idle_time.cpp +++ b/frameworks/native/appkit/app/idle_time.cpp @@ -97,9 +97,18 @@ void IdleTime::RequestVSync() } receiver_->Init(); } + std::weak_ptr weak(shared_from_this()); + auto task = [weak](int64_t timestamp, void* data) { + auto idleTime = weak.lock(); + if (idleTime == nullptr) { + HILOG_ERROR("idleTime is nullptr."); + return; + } + idleTime->OnVSync(timestamp, data); + }; Rosen::VSyncReceiver::FrameCallback frameCallback = { .userData_ = this, - .callback_ = [this](int64_t timestamp, void* data) { OnVSync(timestamp, data); }, + .callback_ = task, }; receiver_->RequestNextVSync(frameCallback); } From 85af367a5239635f1d2ca7f5944199f0324a5b25 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 10 Jan 2023 01:35:16 +0000 Subject: [PATCH 07/31] Description:remove unnecessary fuzzer test Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp b/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp index d9ec55a596..a5b8658720 100644 --- a/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp +++ b/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp @@ -70,8 +70,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) moduleRecord.SetModuleRecordState(moduleState); std::shared_ptr appLifeCycleDeal; moduleRecord.SetApplicationClient(appLifeCycleDeal); - std::shared_ptr appRunningRecord; - moduleRecord.SetAppRunningRecord(appRunningRecord); sptr token = GetFuzzAbilityToken(); moduleRecord.GetAbilityRunningRecordByToken(token); std::shared_ptr abilityInfo; @@ -89,7 +87,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; moduleRecord.OnAbilityStateChanged(record, state); bool isForce = *data % ENABLE; - moduleRecord.TerminateAbility(token, isForce); moduleRecord.AbilityTerminated(token); moduleRecord.GetAbilityByTerminateLists(token); uint32_t msg = GetU32Data(data); From e6be026e96ba5581f40269b26fdab4f488003a87 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 10 Jan 2023 01:49:25 +0000 Subject: [PATCH 08/31] Description:remove unnecessary fuzzer test Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp b/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp index a5b8658720..70f8ab17e9 100644 --- a/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp +++ b/test/fuzztest/modulerunningrecord_fuzzer/modulerunningrecord_fuzzer.cpp @@ -87,6 +87,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; moduleRecord.OnAbilityStateChanged(record, state); bool isForce = *data % ENABLE; + std::shared_ptr appRunningRecord; + moduleRecord.TerminateAbility(appRunningRecord, token, isForce); moduleRecord.AbilityTerminated(token); moduleRecord.GetAbilityByTerminateLists(token); uint32_t msg = GetU32Data(data); From 52ec41e080b6793df8be0ed47a5857f87565c12f Mon Sep 17 00:00:00 2001 From: Rtangyu Date: Mon, 9 Jan 2023 20:01:23 +0800 Subject: [PATCH 09/31] Uncaught exception adaptation does not decompress HAP to read the sourcemap file issues:https://gitee.com/openharmony/ability_ability_runtime/issues/I69N4H Signed-off-by: Rtangyu --- frameworks/native/appkit/app/main_thread.cpp | 8 +- frameworks/native/runtime/source_map.cpp | 82 ++++++------------- .../inner_api/runtime/include/source_map.h | 5 +- 3 files changed, 32 insertions(+), 63 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 84a87c8f82..2fe66e6a2e 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1000,13 +1000,13 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con applicationContext->AttachContextImpl(contextImpl); applicationContext->InitApplicationContext(); application_->SetApplicationContext(applicationContext); - std::string BundleCodeDir = applicationContext->GetBundleCodeDir(); if (isStageBased) { // Create runtime + auto hapPath = entryHapModuleInfo.hapPath; AbilityRuntime::Runtime::Options options; options.bundleName = appInfo.bundleName; options.codePath = LOCAL_CODE_PATH; - options.hapPath = entryHapModuleInfo.hapPath; + options.hapPath = hapPath; options.eventRunner = mainHandler_->GetEventRunner(); options.loadAce = true; options.isBundle = (entryHapModuleInfo.compileMode != AppExecFwk::CompileMode::ES_MODULE); @@ -1022,7 +1022,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con auto bundleName = appInfo.bundleName; auto versionCode = appInfo.versionCode; wptr weak = this; - auto uncaughtTask = [weak, bundleName, versionCode, BundleCodeDir](NativeValue* v) { + auto uncaughtTask = [weak, bundleName, versionCode, hapPath](NativeValue* v) { HILOG_INFO("Js uncaught exception callback come."); auto appThread = weak.promote(); if (appThread == nullptr) { @@ -1054,7 +1054,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con error = fuc->GetSourceCodeInfo(errorPos); } summary += error + "Stacktrace:\n" + OHOS::AbilityRuntime::ModSourceMap::TranslateBySourceMap(errorStack, - bindSourceMaps, BundleCodeDir); + bindSourceMaps, hapPath); time_t timet; time(&timet); HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR", diff --git a/frameworks/native/runtime/source_map.cpp b/frameworks/native/runtime/source_map.cpp index 82029938bc..1676cfa4ce 100644 --- a/frameworks/native/runtime/source_map.cpp +++ b/frameworks/native/runtime/source_map.cpp @@ -22,7 +22,12 @@ #include #include +#include "extractor.h" #include "hilog_wrapper.h" + +using namespace OHOS::AbilityBase; +using Extractor = OHOS::AbilityBase::Extractor; + namespace OHOS { namespace AbilityRuntime { @@ -37,9 +42,8 @@ constexpr char DELIMITER_SEMICOLON = ';'; constexpr char DOUBLE_SLASH = '\\'; constexpr char WEBPACK[] = "webpack:///"; const std::string REALPATH_FLAG = "/temprary/"; -const std::string ABILITYPATH_FLAG = "/entry/ets/"; +const std::string MEGER_SOURCE_MAP_PATH = "ets/sourceMaps.map"; const std::string NOT_FOUNDMAP = "Cannot get SourceMap info, dump raw stack:\n"; -constexpr int64_t ASSET_FILE_MAX_SIZE = 20 * (1 << 20); constexpr int32_t INDEX_TWO = 2; constexpr int32_t INDEX_THREE = 3; constexpr int32_t INDEX_FOUR = 4; @@ -48,32 +52,26 @@ constexpr int32_t NUM_TWENTY = 20; constexpr int32_t NUM_TWENTYSIX = 26; constexpr int32_t DIGIT_NUM = 64; -bool ModSourceMap::ReadSourceMapData(const std::string& filePath, std::string& content) +bool ModSourceMap::ReadSourceMapData(const std::string& hapPath, std::string& content) { - char path[PATH_MAX] ; - if (realpath(filePath.c_str(), path) == nullptr) { - HILOG_ERROR("ModSourceMap::ReadSourceMapData realpath(%{public}s) failed, errno = %{public}d", - filePath.c_str(), errno); + if (hapPath.empty()) { + HILOG_ERROR("hapPath is empty"); return false; } - - std::ifstream stream(path, std::ios::binary | std::ios::ate); - if (!stream.is_open()) { - HILOG_ERROR("ModSourceMap::ReadSourceMapData failed to open file %{public}s", path); + bool newCreate = false; + std::shared_ptr extractor = ExtractorUtil::GetExtractor( + ExtractorUtil::GetLoadFilePath(hapPath), newCreate); + if (extractor == nullptr) { + HILOG_ERROR("hapPath %{public}s GetExtractor failed", hapPath.c_str()); return false; } - - int64_t fileLen = stream.tellg(); - if (fileLen > ASSET_FILE_MAX_SIZE) { + std::unique_ptr dataPtr = nullptr; + size_t len = 0; + if (!extractor->ExtractToBufByName(MEGER_SOURCE_MAP_PATH, dataPtr, len)) { + HILOG_ERROR("get mergeSourceMapData fileBuffer failed"); return false; } - - char buffer[fileLen]; - buffer[fileLen - 1] = '\0'; - stream.seekg(0); - stream.read(buffer, fileLen); - content = buffer; - + content = reinterpret_cast(dataPtr.get()); return true; } @@ -355,36 +353,8 @@ bool ModSourceMap::VlqRevCode(const std::string& vStr, std::vector& ans return true; }; -bool ModSourceMap::GetSourceMapData(ModSourceMap& bindSourceMaps, const std::string& temp, SourceMapData& curMapData) -{ - // get the file path of the .map file - int32_t startPos = static_cast(temp.find(REALPATH_FLAG)); - if (startPos == -1) { - HILOG_ERROR("ModSourceMap::TranslateBySourceMap Get /temprary/ pos error."); - return false; - } - int32_t endPos = static_cast(temp.size() - 1); - std::string mapFilePath = bindSourceMaps.bundleCodeDir_ + ABILITYPATH_FLAG + - temp.substr(startPos + REALPATH_FLAG.size(), endPos - startPos) + ".map"; - - // parse file and cache - auto iter = bindSourceMaps.sourceMaps_.find(mapFilePath); - if (iter == bindSourceMaps.sourceMaps_.end()) { - std::string curSourceMap; - if (!ReadSourceMapData(mapFilePath, curSourceMap)) { - return false; - } - - Init(curSourceMap, curMapData); - bindSourceMaps.sourceMaps_.insert(std::pair(mapFilePath, curMapData)); - } else { - curMapData = iter->second; - } - return true; -} - std::string ModSourceMap::TranslateBySourceMap(const std::string& stackStr, ModSourceMap& bindSourceMaps, - const std::string& BundleCodeDir) + const std::string& hapPath) { const std::string closeBrace = ")"; const std::string openBrace = "("; @@ -418,11 +388,10 @@ std::string ModSourceMap::TranslateBySourceMap(const std::string& stackStr, ModS sourceCode = fristLine.substr(codeStartLen, fristLine.length() - codeStartLen - 1); i = 1; // 1 means Convert from the second line needGetErrorPos = true; - } + } } std::string curSourceMap; - std::string filePath = BundleCodeDir + ABILITYPATH_FLAG + "sourceMaps.map"; - if (!ReadSourceMapData(filePath, curSourceMap)) { + if (!ReadSourceMapData(hapPath, curSourceMap)) { HILOG_ERROR("ReadSourceMapData fail"); return stackStr; } @@ -570,11 +539,12 @@ std::string ModSourceMap::GetOriginalNames(std::shared_ptr target ErrorPos ModSourceMap::GetErrorPos(const std::string& rawStack) { - uint32_t lineEnd = rawStack.find("\n") - 1; - if (lineEnd < 1) { + size_t findLineEnd = rawStack.find("\n"); + if (findLineEnd == std::string::npos) { return std::make_pair(0, 0); } - if (rawStack[lineEnd - 1] == '?') { + uint32_t lineEnd = findLineEnd - 1; + if (lineEnd < 1 || rawStack[lineEnd - 1] == '?') { return std::make_pair(0, 0); } diff --git a/interfaces/inner_api/runtime/include/source_map.h b/interfaces/inner_api/runtime/include/source_map.h index d68eab063c..310b7966dc 100644 --- a/interfaces/inner_api/runtime/include/source_map.h +++ b/interfaces/inner_api/runtime/include/source_map.h @@ -72,7 +72,7 @@ public: ~ModSourceMap() = default; static std::string TranslateBySourceMap(const std::string& stackStr, ModSourceMap& targetMaps, - const std::string& BundleCodeDir); + const std::string& hapPath); static std::string GetOriginalNames(std::shared_ptr targetMapData, const std::string& sourceCode, uint32_t& errorPos); static ErrorPos GetErrorPos(const std::string& rawStack); @@ -82,7 +82,6 @@ public: private: static void Init(const std::string& sourceMap, SourceMapData& curMap); - static bool GetSourceMapData(ModSourceMap& bindSourceMaps, const std::string& temp, SourceMapData& curMapData); static MappingInfo Find(int32_t row, int32_t col, const SourceMapData& targetMap, const std::string& key); static void ExtractKeyInfo(const std::string& sourceMap, std::vector& sourceKeyInfo); static void GetPosInfo(const std::string& temp, int32_t start, std::string& line, std::string& column); @@ -90,7 +89,7 @@ private: static std::string GetRelativePath(const std::string& sources); static std::string GetSourceInfo(const std::string& line, const std::string& column, const SourceMapData& targetMap, const std::string& key); - static bool ReadSourceMapData(const std::string& filePath, std::string& content); + static bool ReadSourceMapData(const std::string& hapPath, std::string& content); static std::vector HandleMappings(const std::string& mapping); static uint32_t Base64CharToInt(char charCode); static bool VlqRevCode(const std::string& vStr, std::vector& ans); From 1e765b14008a58b096bc48646953a8a5aa844dd8 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 10 Jan 2023 11:21:00 +0800 Subject: [PATCH 10/31] add tdd Signed-off-by: xinking129 --- .../test/unittest/ability_delegator/BUILD.gn | 35 + .../accessibility_ability_command_test.cpp | 1614 +++++++++++++++++ 2 files changed, 1649 insertions(+) create mode 100644 tools/test/unittest/ability_delegator/accessibility_ability_command_test.cpp diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index 119316924b..97d548b3f8 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -129,11 +129,46 @@ ohos_unittest("shell_command_result_test") { ] } +ohos_unittest("accessibility_ability_command_test") { + module_out_path = module_output_path + + symlink_target_name = [ "ability_tool" ] + + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/token_setproc/include/", + ] + + configs = [ ":tools_ability_delegator_config" ] + + sources = [ + "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_command.cpp", + "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_utils.cpp", + "accessibility_ability_command_test.cpp", + ] + + deps = [ + "${ability_runtime_path}/tools/aa:tools_aa_source_set", + "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "access_token:libaccesstoken_sdk", + "accessibility:accessibilityclient", + "accessibility:accessibilityconfig", + "bundle_framework:appexecfwk_base", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + group("unittest") { testonly = true deps = [ ":ability_command_test", + ":accessibility_ability_command_test", ":shell_command_result_test", ":test_observer_proxy_test", ":test_observer_stub_test", diff --git a/tools/test/unittest/ability_delegator/accessibility_ability_command_test.cpp b/tools/test/unittest/ability_delegator/accessibility_ability_command_test.cpp new file mode 100644 index 0000000000..fb07c073f3 --- /dev/null +++ b/tools/test/unittest/ability_delegator/accessibility_ability_command_test.cpp @@ -0,0 +1,1614 @@ +/* + * 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. + */ + +#include + +#define private public +#define protected public +#include "accessibility_ability_command.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AAFwk; + +namespace { +const std::string ACCESSIBILITY_TOOL_NAME = "accessibility"; +const std::string ACCESSIBILITY_HELP_MSG = + "usage: accessibility \n" + "these are common accessibility commands list:\n" + " help list available commands\n" + " enable enable ability with options\n" + " disable disable ability with options\n" + " list list the installed abilities info\n" + " setShortKeyState set the state of the short key configuration item\n" + " setMouseKeyState set the state of the mouse key configuration item\n" + " setCaptionState set the state of the caption configuration item\n" + " setMouseAutoClick set the time of the mouse auto click configuration item\n" + " setShortKeyTarget set the name of the short key target configuration item\n" + " setHighContrastTextState set the state of the high contrast text configuration item\n" + " setInvertColorState set the state of the invert color configuration item\n" + " setDaltonizationColorFilter set the type of the daltonization color filter configuration item\n" + " setContentTimeout set the time of the toast content duration configuration item\n" + " setAnimationOffState set the state of the animation off configuration item\n" + " setBrightnessDiscount set the discount of the screen brightness configuration item\n" + " setAudioMonoState set the state of the audio mono configuration item\n" + " setAudioBalance set the value of the audio balance configuration item\n"; + +const std::string ACCESSIBILITY_SET_SCREEN_MAGNIFICATION_STATE_OK = "set screen magnification state successfully."; +const std::string ACCESSIBILITY_SET_SHORT_KEY_STATE_OK = "set short key state successfully."; +const std::string ACCESSIBILITY_SET_MOUSE_KEY_STATE_OK = "set mouse key state successfully."; +const std::string ACCESSIBILITY_SET_CAPTION_STATE_OK = "set caption state successfully."; +const std::string ACCESSIBILITY_SET_AUTO_CLICK_TIME_OK = "set mouse auto click time successfully."; +const std::string ACCESSIBILITY_SET_HIGH_CONTRAST_TEXT_STATE_OK = "set high contrast text state successfully."; +const std::string ACCESSIBILITY_SET_INVERT_COLOR_STATE_OK = "set invert color state successfully."; +const std::string ACCESSIBILITY_SET_DALTONIZATIONZATION_COLOR_FILTER_OK = + "set daltonization color filter successfully."; +const std::string ACCESSIBILITY_SET_CONTENT_TIME_OK = "set content timeout successfully."; +const std::string ACCESSIBILITY_SET_ANIMATION_OFF_STATE_OK = "set animation off state successfully."; +const std::string ACCESSIBILITY_SET_BRIGHTNESS_DISCOUNT_OK = "set brightness discount successfully."; +const std::string ACCESSIBILITY_SET_BRIGHTNESS_DISCOUNT_NG = "error: failed to set brightness discount.\n"; +const std::string ACCESSIBILITY_SET_AUDIO_MONO_STATE_OK = "set audio mono state successfully."; +const std::string ACCESSIBILITY_SET_AUDIO_BALANCE_OK = "set audio balance successfully."; + +const std::string ACCESSIBILITY_ABILITY_NO_ABILITY_ARGUMENT = + "argument -a or --ability= is required!"; +const std::string ACCESSIBILITY_ABILITY_DUPLICATE_ARGUMENT = "there are duplicate arguments."; +const std::string ACCESSIBILITY_ABILITY_NO_ABILITY_ARGUMENT_VALUE = "option -a requires a value."; +const std::string ACCESSIBILITY_ABILITY_NO_BUNDLE_ARGUMENT = + "argument -b or --bundle= is required!"; +const std::string ACCESSIBILITY_ABILITY_NO_BUNDLE_ARGUMENT_VALUE = "option -b requires a value."; +const std::string ACCESSIBILITY_ABILITY_NO_CAPABILITIES_ARGUMENT = + "argument -c " + " or --capabilities= is required!"; +const std::string ACCESSIBILITY_ABILITY_NO_CAPABILITIES_ARGUMENT_VALUE = "option -c requires a value."; +const std::string ACCESSIBILITY_ABILITY_NO_SET_ARGUMENT_VALUE = "option -v requires a value."; +const std::string ACCESSIBILITY_ABILITY_SET_VALUE_INVALID = "value is invalid."; +const std::string ACCESSIBILITY_HELP_MSG_NO_OPTION = "missing options."; +const std::string ACCESSIBILITY_ABILITY_NOT_FOUND = " was not found!"; +const std::string ACCESSIBILITY_ABILITY_TOO_MANY_ARGUMENT = "there are too many arguments "; + +const std::string ACCESSIBILITY_HELP_MSG_SET_SCREEN_MAGNIFICATION_STATE = + "usage: accessibility setScreenMagnificationState [-v <0 | 1> ]\n" + "set the state of the screen magnification configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_SHORT_KEY_STATE = + "usage: accessibility setShortKeyState [-v <0 | 1> ]\n" + "set the state of the short key configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_MOUSE_KEY_STATE = + "usage: accessibility setMouseKeyState [-v <0 | 1> ]\n" + "set the state of the mouse key configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_CAPTION_STATE = + "usage: accessibility setCaptionState [-v <0 | 1> ]\n" + "set the state of the caption configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_AUTO_CLICK_TIME = + "usage: accessibility setMouseAutoClick [-v ]\n" + "the range of time-value is 1000 to 5000 and the default unit is ms\n" + "set the time of the mouse auto click configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_SHORT_KEY_TARGET = + "usage: accessibility setShortKeyTarget -a -b \n" + "set the name of the short key target configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_HIGH_CONTRAST_TEXT_STATE = + "usage: accessibility setHighContrastTextState [-v <0 | 1> ]\n" + "set the state of the high contrast text configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_INVERT_COLOR_STATE = + "usage: accessibility setInvertColorState [-v <0 | 1>]\n" + "set the state of the invert color configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_DALTONIZATION_COLOR_FILTER = + "usage: accessibility setDaltonizationColorFilter [-v <0 | 1 | 2 | 3>]\n" + "normal = 0, protanomaly = 1, deuteranomaly = 2, tritanomaly = 3\n" + "set the type of the daltonization color filter configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_CONTENT_TIME_OUT = + "usage: accessibility setContentTimeout [-v ]\n" + "the range of time-value is 0 to 5000 and the default unit is ms\n" + "set the time of the toast content duration configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_ANIMATION_OFF_STATE = + "usage: accessibility setAnimationOffState [-v <0 | 1>]\n" + "set the state of the animation off configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_BRIGHTNESS_DISCOUNT = + "usage: accessibility setBrightnessDiscount [-v ]\n" + "the percentage of discount-value is 0 to 100\n" + "set the discount of the screen brightness configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_AUDIO_MONO_STATE = + "usage: accessibility setAudioMonoState [-v <0 | 1>]\n" + "set the state of the audio mono configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_SET_AUDIO_BALANCE = + "usage: accessibility setAudioBalance [-v ]\n" + "the percentage of balance-value is -100 to 100\n" + "the negative values represent the left channel and positive values represent the right channel\n" + "set the value of the audio balance configuration item\n"; + +const std::string ACCESSIBILITY_HELP_MSG_ENABLE_ABILITY = + "usage: accessibility enable [-a ] [-b ] [-c ]\n" + "enable the auxiliary application with bundle-name and ability-name and capabilities-abbr\n"; + +const std::string ACCESSIBILITY_HELP_MSG_DISABLE_ABILITY = + "usage: accessibility disable [-a ] [-b ]\n" + "disable the auxiliary application with bundle-name and ability-name\n"; +} // namespace + +namespace OHOS { +namespace AAFwk { +class AccessibilityAbilityShellCommandTest : public ::testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::string cmdhelp_ = "help"; + std::string cmdenable_ = "enable"; + std::string cmddisable_ = "disable"; + std::string cmdsetShortKeyState_ = "setShortKeyState"; + std::string cmdsetMouseKeyState_ = "setMouseKeyState"; + std::string cmdsetCaptionState_ = "setCaptionState"; + std::string cmdssetMouseAutoClick_ = "setMouseAutoClick"; + std::string cmdsetShortKeyTarget_ = "setShortKeyTarget"; + std::string cmdsetHighContrastTextState_ = "setHighContrastTextState"; + std::string cmdsetInvertColorState_ = "setInvertColorState"; + std::string cmdsetDaltonizationColorFilter_ = "setDaltonizationColorFilter"; + std::string cmdsetContentTimeout_ = "setContentTimeout"; + std::string cmdsetAnimationOffState_ = "setAnimationOffState"; + std::string cmdsetBrightnessDiscount_ = "setBrightnessDiscount"; + std::string cmdsetAudioMonoState_ = "setAudioMonoState"; + std::string cmdsetAudioBalance_ = "setAudioBalance"; + std::string cmdSetScreenMagnificationState_ = "setScreenMagnificationState"; +}; + +void AccessibilityAbilityShellCommandTest::SetUpTestCase() +{} + +void AccessibilityAbilityShellCommandTest::TearDownTestCase() +{} + +void AccessibilityAbilityShellCommandTest::SetUp() +{ + // reset optind to 0 + optind = 0; +} + +void AccessibilityAbilityShellCommandTest::TearDown() +{} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0100 + * @tc.name: RunAsSetMouseAutoClick + * @tc.desc: Test whether RunAsSetMouseAutoClick is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdssetMouseAutoClick_.c_str(), + (char*)"-v", + (char*)"1000", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetMouseAutoClick(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUTO_CLICK_TIME_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0200 + * @tc.name: RunAsSetMouseAutoClick + * @tc.desc: Test whether RunAsSetMouseAutoClick is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdssetMouseAutoClick_.c_str(), + (char*)"-v", + (char*)"5000", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetMouseAutoClick(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUTO_CLICK_TIME_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0300 + * @tc.name: RunAsSetMouseAutoClick + * @tc.desc: Test whether RunAsSetMouseAutoClick is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdssetMouseAutoClick_.c_str(), + (char*)"-v", + (char*)"5001", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetMouseAutoClick(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setMouseAutoClick: " + ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_AUTO_CLICK_TIME); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0400 + * @tc.name: RunAsSetMouseAutoClick + * @tc.desc: Test whether RunAsSetMouseAutoClick is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetMouseAutoClick(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n"+ACCESSIBILITY_HELP_MSG_SET_AUTO_CLICK_TIME); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetMouseAutoClick_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetShortKeyTarget_0100 + * @tc.name: RunAsSetShortKeyTarget + * @tc.desc: Test whether RunAsSetShortKeyTarget is called normally. + * (MakeSetShortKeyTargetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetShortKeyTarget_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetShortKeyTarget_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetShortKeyTarget(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n"+ACCESSIBILITY_HELP_MSG_SET_SHORT_KEY_TARGET); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetShortKeyTarget_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0100 + * @tc.name: RunAsSetHighContrastTextState + * @tc.desc: Test whether RunAsSetHighContrastTextState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetHighContrastTextState_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetHighContrastTextState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_HIGH_CONTRAST_TEXT_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0200 + * @tc.name: RunAsSetHighContrastTextState + * @tc.desc: Test whether RunAsSetHighContrastTextState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetHighContrastTextState_.c_str(), + (char*)"-v", + (char*)"1", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetHighContrastTextState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_HIGH_CONTRAST_TEXT_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0300 + * @tc.name: RunAsSetHighContrastTextState + * @tc.desc: Test whether RunAsSetHighContrastTextState is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetHighContrastTextState_.c_str(), + (char*)"-v", + (char*)"2", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetHighContrastTextState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setHighContrastTextState: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_HIGH_CONTRAST_TEXT_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0400 + * @tc.name: RunAsSetHighContrastTextState + * @tc.desc: Test whether RunAsSetHighContrastTextState is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetHighContrastTextState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_HIGH_CONTRAST_TEXT_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetHighContrastTextState_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0100 + * @tc.name: RunAsSetInvertColorState + * @tc.desc: Test whether RunAsSetInvertColorState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetInvertColorState_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetInvertColorState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_INVERT_COLOR_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0200 + * @tc.name: RunAsSetInvertColorState + * @tc.desc: Test whether RunAsSetInvertColorState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetInvertColorState_.c_str(), + (char*)"-v", + (char*)"1", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetInvertColorState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_INVERT_COLOR_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0300 + * @tc.name: RunAsSetInvertColorState + * @tc.desc: Test whether RunAsSetInvertColorState is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetInvertColorState_.c_str(), + (char*)"-v", + (char*)"2", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetInvertColorState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setInvertColorState: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_INVERT_COLOR_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0400 + * @tc.name: RunAsSetInvertColorState + * @tc.desc: Test whether RunAsSetInvertColorState is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetInvertColorState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n"+ACCESSIBILITY_HELP_MSG_SET_INVERT_COLOR_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetInvertColorState_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0100 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetDaltonizationColorFilter_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_DALTONIZATIONZATION_COLOR_FILTER_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0200 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetDaltonizationColorFilter_.c_str(), + (char*)"-v", + (char*)"1", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_DALTONIZATIONZATION_COLOR_FILTER_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0300 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetDaltonizationColorFilter_.c_str(), + (char*)"-v", + (char*)"2", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_DALTONIZATIONZATION_COLOR_FILTER_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0400 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetDaltonizationColorFilter_.c_str(), + (char*)"-v", + (char*)"3", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_DALTONIZATIONZATION_COLOR_FILTER_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0500 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0500 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetDaltonizationColorFilter_.c_str(), + (char*)"-v", + (char*)"4", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setDaltonizationColorFilter: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0500 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0600 + * @tc.name: RunAsSetDaltonizationColorFilter + * @tc.desc: Test whether RunAsSetDaltonizationColorFilter is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0600 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetDaltonizationColorFilter(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n"+ACCESSIBILITY_HELP_MSG_SET_DALTONIZATION_COLOR_FILTER); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetDaltonizationColorFilter_0600 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0100 + * @tc.name: RunAsSetContentTimeout + * @tc.desc: Test whether RunAsSetContentTimeout is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetContentTimeout_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetContentTimeout(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_CONTENT_TIME_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0200 + * @tc.name: RunAsSetContentTimeout + * @tc.desc: Test whether RunAsSetContentTimeout is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetContentTimeout_.c_str(), + (char*)"-v", + (char*)"5000", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetContentTimeout(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_CONTENT_TIME_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0300 + * @tc.name: RunAsSetContentTimeout + * @tc.desc: Test whether RunAsSetContentTimeout is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetContentTimeout_.c_str(), + (char*)"-v", + (char*)"5001", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetContentTimeout(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setContentTimeout: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_CONTENT_TIME_OUT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0400 + * @tc.name: RunAsSetContentTimeout + * @tc.desc: Test whether RunAsSetContentTimeout is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetContentTimeout(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_SET_CONTENT_TIME_OUT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetContentTimeout_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0100 + * @tc.name: RunAsSetAnimationOffState + * @tc.desc: Test whether RunAsSetAnimationOffState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAnimationOffState_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAnimationOffState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_ANIMATION_OFF_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0200 + * @tc.name: RunAsSetAnimationOffState + * @tc.desc: Test whether RunAsSetAnimationOffState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAnimationOffState_.c_str(), + (char*)"-v", + (char*)"1", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAnimationOffState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_ANIMATION_OFF_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0300 + * @tc.name: RunAsSetAnimationOffState + * @tc.desc: Test whether RunAsSetAnimationOffState is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAnimationOffState_.c_str(), + (char*)"-v", + (char*)"2", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAnimationOffState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setAnimationOffState: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_ANIMATION_OFF_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0400 + * @tc.name: RunAsSetAnimationOffState + * @tc.desc: Test whether RunAsSetAnimationOffState is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAnimationOffState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_ANIMATION_OFF_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAnimationOffState_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0100 + * @tc.name: RunAsSetBrightnessDiscount + * @tc.desc: Test whether RunAsSetBrightnessDiscount is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetBrightnessDiscount_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetBrightnessDiscount(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_BRIGHTNESS_DISCOUNT_NG); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0200 + * @tc.name: RunAsSetBrightnessDiscount + * @tc.desc: Test whether RunAsSetBrightnessDiscount is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetBrightnessDiscount_.c_str(), + (char*)"-v", + (char*)"100", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetBrightnessDiscount(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_BRIGHTNESS_DISCOUNT_NG); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0300 + * @tc.name: RunAsSetBrightnessDiscount + * @tc.desc: Test whether RunAsSetBrightnessDiscount is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetBrightnessDiscount_.c_str(), + (char*)"-v", + (char*)"101", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetBrightnessDiscount(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setSetBrightnessDiscount: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_BRIGHTNESS_DISCOUNT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0400 + * @tc.name: RunAsSetBrightnessDiscount + * @tc.desc: Test whether RunAsSetBrightnessDiscount is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetBrightnessDiscount(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_SET_BRIGHTNESS_DISCOUNT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetBrightnessDiscount_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0100 + * @tc.name: RunAsSetAudioMonoState + * @tc.desc: Test whether RunAsSetAudioMonoState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioMonoState_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioMonoState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUDIO_MONO_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0200 + * @tc.name: RunAsSetAudioMonoState + * @tc.desc: Test whether RunAsSetAudioMonoState is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioMonoState_.c_str(), + (char*)"-v", + (char*)"1", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioMonoState(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUDIO_MONO_STATE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0300 + * @tc.name: RunAsSetAudioMonoState + * @tc.desc: Test whether RunAsSetAudioMonoState is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioMonoState_.c_str(), + (char*)"-v", + (char*)"2", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioMonoState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setAudioMonoState: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_AUDIO_MONO_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0400 + * @tc.name: RunAsSetAudioMonoState + * @tc.desc: Test whether RunAsSetAudioMonoState is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioMonoState(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_SET_AUDIO_MONO_STATE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioMonoState_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0100 + * @tc.name: RunAsSetAudioBalance + * @tc.desc: Test whether RunAsSetAudioBalance is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0100 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioBalance_.c_str(), + (char*)"-v", + (char*)"-100", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioBalance(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUDIO_BALANCE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0200 + * @tc.name: RunAsSetAudioBalance + * @tc.desc: Test whether RunAsSetAudioBalance is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0200 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioBalance_.c_str(), + (char*)"-v", + (char*)"100", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioBalance(); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_SET_AUDIO_BALANCE_OK + "\n"); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0300 + * @tc.name: RunAsSetAudioBalance + * @tc.desc: Test whether RunAsSetAudioBalance is called normally.(value is invalid) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0300 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetAudioBalance_.c_str(), + (char*)"-v", + (char*)"101", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioBalance(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setAudioBalance: "+ ACCESSIBILITY_ABILITY_SET_VALUE_INVALID + + "\n" + ACCESSIBILITY_HELP_MSG_SET_AUDIO_BALANCE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0400 + * @tc.name: RunAsSetAudioBalance + * @tc.desc: Test whether RunAsSetAudioBalance is called normally. + * (MakeSetCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0400 start"; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.RunAsSetAudioBalance(); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "\n" + ACCESSIBILITY_HELP_MSG_SET_AUDIO_BALANCE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_RunAsSetAudioBalance_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetShortKeyTargetCommandArgumentFromCmd_0100 + * @tc.name: MakeSetShortKeyTargetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetShortKeyTargetCommandArgumentFromCmd is called normally. + * (MakeCommandArgumentFromCmd = OHOS::ERR_OK,MakeCommandArgumentFromCmd = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetShortKeyTargetCommandArgumentFromCmd_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetShortKeyTargetCommandArgumentFromCmd_0100 start"; + AccessibilityCommandArgument argument; + optind = 5; + std::string resultMessage; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)"-a", + (char*)"ability", + (char*)"-b", + (char*)"bundle", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetShortKeyTargetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, "setShortkeyTarget: " + ACCESSIBILITY_ABILITY_NO_ABILITY_ARGUMENT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetShortKeyTargetCommandArgumentFromCmd_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0100 + * @tc.name: MakeSetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetCommandArgumentFromCmd is called normally.(OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0100 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyState_.c_str(), + (char*)"-v", + (char*)"0", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_OK); + EXPECT_EQ(cmd.resultReceiver_, ": "); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0200 + * @tc.name: MakeSetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetCommandArgumentFromCmd is called normally.(optind < 0) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0200 start"; + AccessibilityCommandArgument argument; + optind = -1; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0300 + * @tc.name: MakeSetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetCommandArgumentFromCmd is called normally.(option = -1) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0300 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyState_.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": " + ACCESSIBILITY_HELP_MSG_NO_OPTION); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0400 + * @tc.name: MakeSetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetCommandArgumentFromCmd is called normally.(option = ?) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0400 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyState_.c_str(), + (char*)"-v", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": " + ACCESSIBILITY_ABILITY_NO_SET_ARGUMENT_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0500 + * @tc.name: MakeSetCommandArgumentFromCmd + * @tc.desc: Test whether MakeSetCommandArgumentFromCmd is called normally.(option = default) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0500 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyState_.c_str(), + (char*)"-a", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeSetCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": unknown arguments -a "); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeSetCommandArgumentFromCmd_0500 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0100 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(return OHOS::ERR_OK) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0100 start"; + AccessibilityCommandArgument argument; + optind = 5; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)"-a", + (char*)"ability", + (char*)"-b", + (char*)"bundle", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_OK); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0200 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(return OHOS::ERR_OK,option a b) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0200 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)"-a", + (char*)"ability", + (char*)"-b", + (char*)"bundle", + (char*)"-v", + (char*)"value", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_OK); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0300 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(missing options) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0300 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": " + ACCESSIBILITY_HELP_MSG_NO_OPTION); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0400 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(NO_ABILITY) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0400 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)"-a", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": " + ACCESSIBILITY_ABILITY_NO_ABILITY_ARGUMENT_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0500 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(NO_BUNDLE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0500 start"; + AccessibilityCommandArgument argument; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmdsetShortKeyTarget_.c_str(), + (char*)"-a", + (char*)"ability", + (char*)"-b", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(cmd.resultReceiver_, ": " + ACCESSIBILITY_ABILITY_NO_BUNDLE_ARGUMENT_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0500 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0600 + * @tc.name: MakeCommandArgumentFromCmd + * @tc.desc: Test whether MakeCommandArgumentFromCmd is called normally.(optind = -1) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0600 start"; + AccessibilityCommandArgument argument; + optind = -1; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeCommandArgumentFromCmd_0600 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_MakeDisableCommandArgumentFromCmd_0100 + * @tc.name: MakeDisableCommandArgumentFromCmd + * @tc.desc: Test whether MakeDisableCommandArgumentFromCmd is called normally. + * (MakeCommandArgumentFromCmd = OHOS::ERR_OK,CheckDisableCommandArgument = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_MakeDisableCommandArgumentFromCmd_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeDisableCommandArgumentFromCmd_0100 start"; + AccessibilityCommandArgument argument; + argument.abilityArgumentNum = 1; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 1; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 0; + argument.unknownArgumentNum = 0; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + (char*)cmddisable_.c_str(), + (char*)"-a", + (char*)"ability", + (char*)"-b", + (char*)"bundle", + (char*)" ", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.MakeDisableCommandArgumentFromCmd(argument); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_MakeDisableCommandArgumentFromCmd_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckDisableCommandArgument_0100 + * @tc.name: CheckDisableCommandArgument + * @tc.desc: Test whether CheckDisableCommandArgument is called normally. + * (CheckCommandArgument = OHOS::ERR_INVALID_VALUE) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckDisableCommandArgument_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckDisableCommandArgument_0100 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 1; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 1; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 0; + argument.unknownArgumentNum = 0; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckDisableCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": the auxiliary application bundle/ability" + ACCESSIBILITY_ABILITY_NOT_FOUND); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckDisableCommandArgument_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckCommandArgument_0100 + * @tc.name: CheckCommandArgument + * @tc.desc: Test whether CheckCommandArgument is called normally.(totalArgumentNum > 2) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckCommandArgument_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0100 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 2; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 1; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 0; + argument.unknownArgumentNum = 1; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": and exist duplicated arguments.and exist unknown arguments "); + EXPECT_EQ(cmd.resultReceiver_, ACCESSIBILITY_ABILITY_TOO_MANY_ARGUMENT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0100 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckCommandArgument_0200 + * @tc.name: CheckCommandArgument + * @tc.desc: Test whether CheckCommandArgument is called normally.(unknownArgumentNum > 0) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckCommandArgument_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0200 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 0; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 0; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 0; + argument.unknownArgumentNum = 1; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": unknown arguments "); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0200 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckCommandArgument_0300 + * @tc.name: CheckCommandArgument + * @tc.desc: Test whether CheckCommandArgument is called normally.(CheckAbilityArgument = false) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckCommandArgument_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0300 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 0; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 1; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 1; + argument.unknownArgumentNum = 0; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": " + ACCESSIBILITY_ABILITY_NO_ABILITY_ARGUMENT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0300 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckCommandArgument_0400 + * @tc.name: CheckCommandArgument + * @tc.desc: Test whether CheckCommandArgument is called normally.(CheckBundleArgument = false) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckCommandArgument_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0400 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 1; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 0; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 1; + argument.unknownArgumentNum = 0; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": " + ACCESSIBILITY_ABILITY_NO_BUNDLE_ARGUMENT); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0400 end"; +} + +/** + * @tc.number: AccessibilityAbilityShellCommand_CheckCommandArgument_0500 + * @tc.name: CheckCommandArgument + * @tc.desc: Test whether CheckCommandArgument is called normally.(CheckParamValidity = false) + */ +HWTEST_F(AccessibilityAbilityShellCommandTest, +AccessibilityAbilityShellCommand_CheckCommandArgument_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0500 start"; + AccessibilityCommandArgument argument; + std::string resultMessage; + argument.abilityArgumentNum = 1; + argument.abilityName = "ability"; + argument.bundleArgumentNum = 1; + argument.bundleName = "bundle"; + argument.capabilityNamesArgumentNum = 0; + argument.unknownArgumentNum = 0; + char* argv[] = { + (char*)ACCESSIBILITY_TOOL_NAME.c_str(), + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + AccessibilityAbilityShellCommand cmd(argc, argv); + ErrCode result = cmd.CheckCommandArgument(argument,resultMessage); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); + EXPECT_EQ(resultMessage, ": the auxiliary application " + + argument.bundleName + "/" + argument.abilityName + ACCESSIBILITY_ABILITY_NOT_FOUND); + GTEST_LOG_(INFO) << "AccessibilityAbilityShellCommand_CheckCommandArgument_0500 end"; +} +} // namespace AAFwk +} // namespace OHOS From 63756783fe16c5a40c0aaa6b2399fe03a927f61e Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 10 Jan 2023 13:45:20 +0800 Subject: [PATCH 11/31] fix build Signed-off-by: xinking129 --- .../test/unittest/ability_delegator/BUILD.gn | 84 ++++++++++++------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index 97d548b3f8..2e3bd2344e 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -129,49 +129,77 @@ ohos_unittest("shell_command_result_test") { ] } -ohos_unittest("accessibility_ability_command_test") { - module_out_path = module_output_path +print("accessibility_enable = ", accessibility_enable) +if (accessibility_enable) { + ohos_unittest("shell_command_executor_test") { + module_out_path = module_output_path - symlink_target_name = [ "ability_tool" ] + sources = [ "shell_command_executor_test.cpp" ] - include_dirs = [ - "//base/security/access_token/interfaces/innerkits/token_setproc/include/", - ] + configs = [ ":tools_ability_delegator_config" ] - configs = [ ":tools_ability_delegator_config" ] + deps = [ + "${ability_runtime_path}/tools/aa:tools_aa_source_set", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] - sources = [ - "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_command.cpp", - "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_utils.cpp", - "accessibility_ability_command_test.cpp", - ] + external_deps = [ + "ability_base:configuration", + "accessibility:accessibility_common", + "accessibility:accessibilityclient", + "accessibility:accessibilityconfig", + "bundle_framework:appexecfwk_base", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + } + ohos_unittest("accessibility_ability_command_test") { + module_out_path = module_output_path - deps = [ - "${ability_runtime_path}/tools/aa:tools_aa_source_set", - "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", - "//third_party/googletest:gtest_main", - ] + symlink_target_name = [ "ability_tool" ] - external_deps = [ - "ability_base:configuration", - "access_token:libaccesstoken_sdk", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - "bundle_framework:appexecfwk_base", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] + include_dirs = [ "//base/security/access_token/interfaces/innerkits/token_setproc/include/" ] + + configs = [ ":tools_ability_delegator_config" ] + + sources = [ + "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_command.cpp", + "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_utils.cpp", + "accessibility_ability_command_test.cpp", + ] + + deps = [ + "${ability_runtime_path}/tools/aa:tools_aa_source_set", + "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "access_token:libaccesstoken_sdk", + "accessibility:accessibilityclient", + "accessibility:accessibilityconfig", + "bundle_framework:appexecfwk_base", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + } } - group("unittest") { testonly = true deps = [ ":ability_command_test", - ":accessibility_ability_command_test", ":shell_command_result_test", ":test_observer_proxy_test", ":test_observer_stub_test", ":test_observer_test", ] + if (accessibility_enable) { + deps += [ + ":accessibility_ability_command_test", + ":shell_command_executor_test", + ] + } } From cc00f574972361778049b56667b0b77f3d1dbe1f Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 10 Jan 2023 14:01:43 +0800 Subject: [PATCH 12/31] fix tdd build Signed-off-by: xinking129 --- .../test/unittest/ability_delegator/BUILD.gn | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index 2e3bd2344e..1723d028af 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -131,29 +131,6 @@ ohos_unittest("shell_command_result_test") { print("accessibility_enable = ", accessibility_enable) if (accessibility_enable) { - ohos_unittest("shell_command_executor_test") { - module_out_path = module_output_path - - sources = [ "shell_command_executor_test.cpp" ] - - configs = [ ":tools_ability_delegator_config" ] - - deps = [ - "${ability_runtime_path}/tools/aa:tools_aa_source_set", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "ability_base:configuration", - "accessibility:accessibility_common", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - "bundle_framework:appexecfwk_base", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] - } ohos_unittest("accessibility_ability_command_test") { module_out_path = module_output_path @@ -199,7 +176,6 @@ group("unittest") { if (accessibility_enable) { deps += [ ":accessibility_ability_command_test", - ":shell_command_executor_test", ] } } From 667caecccc0b7bc6118fc96341ab7bb2e42897b6 Mon Sep 17 00:00:00 2001 From: zhoujun62 Date: Tue, 10 Jan 2023 15:09:31 +0800 Subject: [PATCH 13/31] modify function name Signed-off-by: zhoujun62 --- frameworks/native/appkit/app/main_thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 2fe66e6a2e..ca16204fc5 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1145,7 +1145,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con } HILOG_DEBUG("MainThread handle launch application, InitResourceManager End."); contextImpl->SetResourceManager(resourceManager); - AbilityBase::ExtractResourceManager::GetExtractResourceManager().AddGlobalObject(resourceManager); + AbilityBase::ExtractResourceManager::GetExtractResourceManager().SetGlobalObject(resourceManager); contextDeal->initResourceManager(resourceManager); contextDeal->SetApplicationContext(application_); From 14b95ff517e660f323800a696faf0473fda1f280 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 10 Jan 2023 16:03:57 +0800 Subject: [PATCH 14/31] format Signed-off-by: xinking129 --- tools/test/unittest/ability_delegator/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index 1723d028af..f1e2abe47d 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -141,20 +141,20 @@ if (accessibility_enable) { configs = [ ":tools_ability_delegator_config" ] sources = [ - "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_command.cpp", - "//foundation/ability/ability_runtime/tools/aa/src/accessibility_ability_utils.cpp", + "${ability_runtime_path}/tools/aa/src/accessibility_ability_command.cpp", + "${ability_runtime_path}/tools/aa/src/accessibility_ability_utils.cpp", "accessibility_ability_command_test.cpp", ] deps = [ "${ability_runtime_path}/tools/aa:tools_aa_source_set", - "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", "//third_party/googletest:gtest_main", ] external_deps = [ "ability_base:configuration", "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", "accessibility:accessibilityclient", "accessibility:accessibilityconfig", "bundle_framework:appexecfwk_base", From 9e40ac5e3faeaf20e52a829f5ddd31bf41eb23b3 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 10 Jan 2023 16:15:21 +0800 Subject: [PATCH 15/31] format Signed-off-by: xinking129 --- tools/test/unittest/ability_delegator/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index f1e2abe47d..e559caeafe 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -174,8 +174,6 @@ group("unittest") { ":test_observer_test", ] if (accessibility_enable) { - deps += [ - ":accessibility_ability_command_test", - ] + deps += [ ":accessibility_ability_command_test" ] } } From 6bffb6924bb2dfb912b42f572794b99dacc713ea Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Mon, 9 Jan 2023 17:11:25 +0800 Subject: [PATCH 16/31] adapter publish interface Signed-off-by: fangJinliang1 Change-Id: Ic87ce28d30c3b6fc324dfc7148f44f4bbf485b1d Signed-off-by: fangJinliang1 --- .../abilitymgr/include/pending_want_manager.h | 3 +- .../abilitymgr/include/pending_want_record.h | 3 +- .../abilitymgr/src/pending_want_manager.cpp | 9 ++-- .../abilitymgr/src/pending_want_record.cpp | 7 ++-- .../pendingwantmanager_fuzzer.cpp | 2 +- .../pending_want_manager_dump_test.cpp | 2 +- .../pending_want_manager_test.cpp | 2 +- .../pending_want_record_test.cpp | 42 +++++++++---------- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/services/abilitymgr/include/pending_want_manager.h b/services/abilitymgr/include/pending_want_manager.h index 3b71be5e3f..1aa6d02a7b 100644 --- a/services/abilitymgr/include/pending_want_manager.h +++ b/services/abilitymgr/include/pending_want_manager.h @@ -152,7 +152,8 @@ public: int32_t requestCode, const int32_t callerUid); int32_t DeviceIdDetermine( const Want &want, const sptr &callerToken, int32_t requestCode, const int32_t callerUid); - int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid); + int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid, + int32_t callerTokenId); void ClearPendingWantRecord(const std::string &bundleName, int32_t uid); void Dump(std::vector &info); diff --git a/services/abilitymgr/include/pending_want_record.h b/services/abilitymgr/include/pending_want_record.h index 40fc1f2a02..5d23bb4d3c 100644 --- a/services/abilitymgr/include/pending_want_record.h +++ b/services/abilitymgr/include/pending_want_record.h @@ -34,7 +34,7 @@ public: PendingWantRecord(); PendingWantRecord(const std::shared_ptr &pendingWantManager, int32_t uid, - const sptr &callerToken, std::shared_ptr key); + int32_t callerTokenId, const sptr &callerToken, std::shared_ptr key); virtual ~PendingWantRecord(); virtual void Send(SenderInfo &senderInfo); @@ -55,6 +55,7 @@ private: std::weak_ptr pendingWantManager_ = {}; int32_t uid_ = 0; int32_t callerUid_ = 0; + int32_t callerTokenId_ = 0; sptr callerToken_ = {}; bool canceled_ = false; std::shared_ptr key_ = {}; diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index ed64f0135a..9e5931fefc 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -109,7 +109,8 @@ sptr PendingWantManager::GetWantSenderLocked(const int32_t callingU } sptr rec = - new (std::nothrow) PendingWantRecord(shared_from_this(), uid, callerToken, pendingKey); + new (std::nothrow) PendingWantRecord(shared_from_this(), uid, IPCSkeleton::GetCallingTokenID(), + callerToken, pendingKey); if (rec != nullptr) { rec->SetCallerUid(callingUid); pendingKey->SetCode(PendingRecordIdCreate()); @@ -274,7 +275,7 @@ int32_t PendingWantManager::PendingWantStartAbilitys(const std::vectorSetWantParams(wantParams); } - bool result = DelayedSingleton::GetInstance()->PublishCommonEvent( - eventData, eventPublishData, pendingWantCommonEvent, callerUid); + bool result = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->PublishCommonEvent( + eventData, eventPublishData, pendingWantCommonEvent, callerUid, callerTokenId)); return ((result == true) ? ERR_OK : (-1)); } diff --git a/services/abilitymgr/src/pending_want_record.cpp b/services/abilitymgr/src/pending_want_record.cpp index e880178332..81d4681522 100644 --- a/services/abilitymgr/src/pending_want_record.cpp +++ b/services/abilitymgr/src/pending_want_record.cpp @@ -25,8 +25,9 @@ PendingWantRecord::PendingWantRecord() {} PendingWantRecord::PendingWantRecord(const std::shared_ptr &pendingWantManager, int32_t uid, - const sptr &callerToken, std::shared_ptr key) - : pendingWantManager_(pendingWantManager), uid_(uid), callerToken_(callerToken), key_(key) + int32_t callerTokenId, const sptr &callerToken, std::shared_ptr key) + : pendingWantManager_(pendingWantManager), uid_(uid), callerTokenId_(callerTokenId), + callerToken_(callerToken), key_(key) {} PendingWantRecord::~PendingWantRecord() @@ -103,7 +104,7 @@ int32_t PendingWantRecord::SenderInner(SenderInfo &senderInfo) res = pendingWantManager->PendingWantStartAbility(want, callerToken_, -1, callerUid_); break; case static_cast(OperationType::SEND_COMMON_EVENT): - res = pendingWantManager->PendingWantPublishCommonEvent(want, senderInfo, callerUid_); + res = pendingWantManager->PendingWantPublishCommonEvent(want, senderInfo, callerUid_, callerTokenId_); (res == ERR_OK) ? (sendFinish = false) : (sendFinish = (senderInfo.finishedReceiver != nullptr)); break; default: diff --git a/test/fuzztest/pendingwantmanager_fuzzer/pendingwantmanager_fuzzer.cpp b/test/fuzztest/pendingwantmanager_fuzzer/pendingwantmanager_fuzzer.cpp index c301181957..6c7d860156 100755 --- a/test/fuzztest/pendingwantmanager_fuzzer/pendingwantmanager_fuzzer.cpp +++ b/test/fuzztest/pendingwantmanager_fuzzer/pendingwantmanager_fuzzer.cpp @@ -129,7 +129,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) pendingWantManager->DeviceIdDetermine(*want, token, int32Param, int32Param); pendingWantManager->PendingWantStartAbility(*want, token, int32Param, int32Param); pendingWantManager->PendingWantStartAbilitys(allWantsInfos, token, int32Param, int32Param); - pendingWantManager->PendingWantPublishCommonEvent(*want, senderInfo, int32Param); + pendingWantManager->PendingWantPublishCommonEvent(*want, senderInfo, int32Param, int32Param); pendingWantManager->PendingRecordIdCreate(); pendingWantManager->GetPendingWantRecordByCode(int32Param); pendingWantManager->GetPendingWantUid(wantSenderPtr); diff --git a/test/unittest/pending_want_manager_dump_test/pending_want_manager_dump_test.cpp b/test/unittest/pending_want_manager_dump_test/pending_want_manager_dump_test.cpp index ef1b865411..cf39389e99 100644 --- a/test/unittest/pending_want_manager_dump_test/pending_want_manager_dump_test.cpp +++ b/test/unittest/pending_want_manager_dump_test/pending_want_manager_dump_test.cpp @@ -68,7 +68,7 @@ HWTEST_F(PendingWantManagerDumpTest, PendingWantManagerDump_DumpByRecordId_0100, EXPECT_NE(pendingKey, nullptr); pendingKey->SetCode(CODE); - auto pendingWantRecord = std::make_shared(pendingManager, UID, nullptr, pendingKey); + auto pendingWantRecord = std::make_shared(pendingManager, UID, 0, nullptr, pendingKey); EXPECT_NE(pendingWantRecord, nullptr); pendingManager->wantRecords_ = { {pendingKey, pendingWantRecord.get()} }; diff --git a/test/unittest/pending_want_manager_test/pending_want_manager_test.cpp b/test/unittest/pending_want_manager_test/pending_want_manager_test.cpp index e5885f13e8..a537639178 100644 --- a/test/unittest/pending_want_manager_test/pending_want_manager_test.cpp +++ b/test/unittest/pending_want_manager_test/pending_want_manager_test.cpp @@ -510,7 +510,7 @@ HWTEST_F(PendingWantManagerTest, PendingWantManagerTest_1400, TestSize.Level1) pendingManager_ = std::make_shared(); EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); - sptr pendingWantRecord = new PendingWantRecord(pendingManager_, 1, nullptr, key); + sptr pendingWantRecord = new PendingWantRecord(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; info.finishedReceiver = new CancelReceiver(); diff --git a/test/unittest/pending_want_record_test/pending_want_record_test.cpp b/test/unittest/pending_want_record_test/pending_want_record_test.cpp index fbfb4609b5..dd6371f8c9 100644 --- a/test/unittest/pending_want_record_test/pending_want_record_test.cpp +++ b/test/unittest/pending_want_record_test/pending_want_record_test.cpp @@ -164,7 +164,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0100, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); EXPECT_EQ(pendingWantRecord->uid_, 1); EXPECT_EQ(pendingWantRecord->callerToken_, nullptr); @@ -186,7 +186,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0200, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(cance); EXPECT_EQ(static_cast(pendingWantRecord->mCancelCallbacks_.size()), 1); @@ -208,7 +208,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0300, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(nullptr); EXPECT_EQ(static_cast(pendingWantRecord->mCancelCallbacks_.size()), 0); @@ -231,7 +231,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0400, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(cance); pendingWantRecord->RegisterCancelListener(cance1); @@ -255,7 +255,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0500, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(cance); pendingWantRecord->RegisterCancelListener(cance1); @@ -280,7 +280,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0600, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(cance); pendingWantRecord->RegisterCancelListener(cance1); @@ -303,7 +303,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0700, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; pendingWantRecord->canceled_ = true; @@ -326,7 +326,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0800, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; EXPECT_NE(pendingWantRecord->SenderInner(info), 0); // Assert SenderInner failed. @@ -346,7 +346,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0900, TestSize.Level1) WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::CONSTANT_FLAG, 0); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(nullptr, 1, nullptr, key); + std::make_shared(nullptr, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; EXPECT_EQ(pendingWantRecord->SenderInner(info), ERR_INVALID_VALUE); @@ -366,7 +366,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1000, TestSize.Level1) WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::ONE_TIME_FLAG, 0); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(nullptr, 1, nullptr, key); + std::make_shared(nullptr, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; info.finishedReceiver = new CancelReceiver(); @@ -390,7 +390,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1100, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR); @@ -413,7 +413,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1200, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR); @@ -437,7 +437,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1300, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR); @@ -461,7 +461,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1400, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; pendingWantRecord->SenderInner(info); @@ -485,7 +485,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1500, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; info.finishedReceiver = new CancelReceiver(); @@ -511,7 +511,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1600, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); EXPECT_EQ(pendingWantRecord->GetKey(), key); } @@ -532,7 +532,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1700, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); EXPECT_EQ(pendingWantRecord->GetUid(), 1); } @@ -553,7 +553,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1800, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); EXPECT_EQ(pendingWantRecord->GetCanceled(), false); pendingWantRecord->SetCanceled(); @@ -577,7 +577,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1900, TestSize.Level1) EXPECT_NE(pendingManager_, nullptr); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); pendingWantRecord->RegisterCancelListener(cance); pendingWantRecord->RegisterCancelListener(cance1); @@ -599,7 +599,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_2000, TestSize.Level1) WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::CONSTANT_FLAG, 0); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; pendingWantRecord->SenderInner(info); @@ -621,7 +621,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_2100, TestSize.Level1) WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::ONE_TIME_FLAG, 0); std::shared_ptr key = MakeWantKey(wantSenderInfo); std::shared_ptr pendingWantRecord = - std::make_shared(pendingManager_, 1, nullptr, key); + std::make_shared(pendingManager_, 1, 0, nullptr, key); EXPECT_NE(pendingWantRecord, nullptr); SenderInfo info; info.finishedReceiver = new CancelReceiver(); From a3df3fecbb7775387e4186af05a4f988bfd21a85 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2023 20:07:50 +0800 Subject: [PATCH 17/31] add user Signed-off-by: unknown --- bundle.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index bdf5411e0f..7ef3cb30bf 100644 --- a/bundle.json +++ b/bundle.json @@ -258,8 +258,16 @@ "header_files": [ "quick_fix_manager_client.h" ] + }, + "name": "//foundation/ability/ability_runtime/interfaces/inner_api/quick_fix:quickfix_manager" }, - "name": "//foundation/ability/ability_runtime/interfaces/inner_api/quick_fix:quickfix_manager" + { + "header": { + "header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/dataobs_manager/", + "header_files": [ + ] + }, + "name": "//foundation/ability/ability_runtime/interfaces/inner_api/dataobs_manager:dataobs_manager" } ], "test": [ From 48ccb61e9bc361285a3616a62d820545772d9d00 Mon Sep 17 00:00:00 2001 From: caochunlei Date: Tue, 10 Jan 2023 21:28:58 +0800 Subject: [PATCH 18/31] caochunlei1@huawei.com Signed-off-by: caochunlei --- frameworks/js/napi/ability_context/ability_context.js | 4 ++++ .../service_extension_context/service_extension_context.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/frameworks/js/napi/ability_context/ability_context.js b/frameworks/js/napi/ability_context/ability_context.js index ac2593d6aa..4f6e49e6a5 100644 --- a/frameworks/js/napi/ability_context/ability_context.js +++ b/frameworks/js/napi/ability_context/ability_context.js @@ -41,6 +41,10 @@ class AbilityContext extends Context { return this.__context_impl__.startAbility(want, options, callback) } + startRecentAbility(want, options, callback) { + return this.__context_impl__.startRecentAbility(want, options, callback) + } + startAbilityWithAccount(want, accountId, options, callback) { return this.__context_impl__.startAbilityWithAccount(want, accountId, options, callback) } diff --git a/frameworks/js/napi/service_extension_context/service_extension_context.js b/frameworks/js/napi/service_extension_context/service_extension_context.js index 810040e881..49a0e89d0a 100644 --- a/frameworks/js/napi/service_extension_context/service_extension_context.js +++ b/frameworks/js/napi/service_extension_context/service_extension_context.js @@ -35,6 +35,11 @@ class ServiceExtensionContext extends ExtensionContext { return this.__context_impl__.startAbility(want, options, callback); } + startRecentAbility(want, options, callback) { + console.log("startRecentAbility"); + return this.__context_impl__.startRecentAbility(want, options, callback); + } + connectAbility(want, options) { console.log("connectAbility"); return this.__context_impl__.connectAbility(want, options); From 770a3f413a9b0b6966569727e9ca195fa50aae5d Mon Sep 17 00:00:00 2001 From: yanmengzhao1 Date: Wed, 11 Jan 2023 18:02:56 +0800 Subject: [PATCH 19/31] print space between thread stacktrace Signed-off-by: yanmengzhao1 --- frameworks/native/appkit/app/mix_stack_dumper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/native/appkit/app/mix_stack_dumper.cpp b/frameworks/native/appkit/app/mix_stack_dumper.cpp index 105aa4648a..676e87a715 100644 --- a/frameworks/native/appkit/app/mix_stack_dumper.cpp +++ b/frameworks/native/appkit/app/mix_stack_dumper.cpp @@ -299,6 +299,7 @@ void MixStackDumper::BuildJsNativeMixStack(int fd, std::vector& jsFram nativeIdx++; } write(fd, mixStackStr.c_str(), mixStackStr.size()); + write(fd, "\n", 1); } std::string MixStackDumper::GetThreadStackTraceLabel(pid_t tid) @@ -321,6 +322,7 @@ void MixStackDumper::PrintNativeFrames(int fd, std::vector& nativeF std::string nativeFrameStr = PrintNativeFrame(frame); write(fd, nativeFrameStr.c_str(), nativeFrameStr.size()); } + write(fd, "\n", 1); } void MixStackDumper::PrintProcessHeader(int fd, pid_t pid, uid_t uid) From bd80cb97644a91805dd7c6e3df631038be5e56e8 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Wed, 11 Jan 2023 10:12:21 +0800 Subject: [PATCH 20/31] intercept Signed-off-by: zhaoyuan --- services/abilitymgr/src/ability_manager_service.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 5b4ef2c78a..9f1e7ab96a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1721,6 +1721,13 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u AbilityRequest abilityRequest; ErrCode result = GenerateAbilityRequest(want, DEFAULT_INVAL_VALUE, abilityRequest, callerToken, userId); + + Want requestWant = want; + requestWant.SetParam("abilityConnectionObj", connect->AsObject()); + if (!IsComponentInterceptionStart(requestWant, callerToken, 0, result, abilityRequest)) { + return ERR_OK; + } + if (result != ERR_OK) { HILOG_ERROR("Generate ability request error."); return result; From 8c8db073c107f04c87b7d4b81c606e75709682c4 Mon Sep 17 00:00:00 2001 From: wangzhaoyong Date: Wed, 11 Jan 2023 19:27:36 +0800 Subject: [PATCH 21/31] =?UTF-8?q?=E9=80=82=E9=85=8Dhap=E4=B8=8D=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=20issue:=20https://gitee.com/openharmony/ability=5Fab?= =?UTF-8?q?ility=5Fruntime/issues/I6A307?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaoyong Change-Id: I57cdbfd2e0245d55b5cc882dadec498d12f0515d --- frameworks/native/runtime/js_worker.cpp | 41 ++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index 89d33a10ae..481f0dc055 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -129,9 +129,13 @@ struct AssetHelper final { std::string filePath = uri.substr(0, index) + ".abc"; ami = codePath_ + filePath; HILOG_INFO("Get asset, ami: %{private}s", ami.c_str()); - if (!ReadAssetData(filePath, content)) { - HILOG_ERROR("Get asset content failed."); - return; + std::string flag = "el2"; + if (ami.find(flag) != std::string::npos) { + if (!ReadAmiData(ami, content)) { + HILOG_ERROR("Get asset content by ami failed."); + } + } else if (!ReadFilePathData(filePath, content)) { + HILOG_ERROR("Get asset content by filepath failed."); } } @@ -154,7 +158,34 @@ struct AssetHelper final { return iface_cast(remoteObject); } - bool ReadAssetData(const std::string& filePath, std::vector& content) const + bool ReadAmiData(const std::string& ami, std::vector& content) const + { + char path[PATH_MAX]; + if (realpath(ami.c_str(), path) == nullptr) { + HILOG_ERROR("ReadAmiData realpath(%{private}s) failed, errno = %{public}d", ami.c_str(), errno); + return false; + } + + std::ifstream stream(path, std::ios::binary | std::ios::ate); + if (!stream.is_open()) { + HILOG_ERROR("ReadAmiData failed to open file %{private}s", ami.c_str()); + return false; + } + + auto fileLen = stream.tellg(); + if (!isDebugVersion_ && fileLen > ASSET_FILE_MAX_SIZE) { + HILOG_ERROR("ReadAmiData failed, file is too large"); + return false; + } + + content.resize(fileLen); + + stream.seekg(0); + stream.read(reinterpret_cast(content.data()), content.size()); + return true; + } + + bool ReadFilePathData(const std::string& filePath, std::vector& content) const { bool newCreate = false; size_t fileLen = 0; @@ -203,7 +234,7 @@ struct AssetHelper final { return false; } if (!isDebugVersion_ && fileLen > ASSET_FILE_MAX_SIZE) { - HILOG_ERROR("ReadAssetData failed, file is too large"); + HILOG_ERROR("ReadFilePathData failed, file is too large"); return false; } content.assign(dataPtr.get(), dataPtr.get() + fileLen); From e3f66d54ffa04fa1b8b378376135caae438c0fed Mon Sep 17 00:00:00 2001 From: HuangXW Date: Wed, 11 Jan 2023 01:05:01 +0000 Subject: [PATCH 22/31] fix abilityConnectionMap duplicate keys Change-Id: Ia40b7655d6340eda57dc22851b00e3114d53bf88 Signed-off-by: HuangXW --- .../ability/ability_runtime/connection_manager.cpp | 9 ++++----- .../native/ability_runtime/js_ability_context.cpp | 9 +++------ .../ability/native/js_service_extension_context.cpp | 7 ++----- .../native/ability/ability_runtime/connection_manager.h | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/frameworks/native/ability/ability_runtime/connection_manager.cpp b/frameworks/native/ability/ability_runtime/connection_manager.cpp index 75823c931a..00a872d3ca 100644 --- a/frameworks/native/ability/ability_runtime/connection_manager.cpp +++ b/frameworks/native/ability/ability_runtime/connection_manager.cpp @@ -62,10 +62,10 @@ ErrCode ConnectionManager::ConnectAbilityInner(const sptr& connec connectReceiver.GetBundleName() == obj.first.connectReceiver.GetBundleName() && connectReceiver.GetAbilityName() == obj.first.connectReceiver.GetAbilityName(); }); + HILOG_DEBUG("abilityConnectionsSize: %{public}zu.", abilityConnections_.size()); if (item != abilityConnections_.end()) { - std::vector> callbacks = item->second; + std::vector>& callbacks = item->second; callbacks.push_back(connectCallback); - abilityConnections_[item->first] = callbacks; abilityConnection = item->first.abilityConnection; abilityConnection->AddConnectCallback(connectCallback); HILOG_INFO("find abilityConnection exist, callbackSize:%{public}zu.", callbacks.size()); @@ -76,9 +76,8 @@ ErrCode ConnectionManager::ConnectAbilityInner(const sptr& connec } else if (abilityConnection->GetConnectionState() == CONNECTION_STATE_CONNECTING) { return ERR_OK; } else { - HILOG_ERROR("AbilityConnection has disconnected"); + HILOG_ERROR("AbilityConnection has disconnected, erase it."); abilityConnections_.erase(item); - HILOG_DEBUG("not find connection, abilityConnectionsSize:%{public}zu.", abilityConnections_.size()); return ERR_INVALID_VALUE; } } else { @@ -90,6 +89,7 @@ ErrCode ConnectionManager::CreateConnection(const sptr& connectCa const AAFwk::Want& want, int accountId, const sptr& connectCallback, const AppExecFwk::ElementName& connectReceiver) { + HILOG_INFO("Can not find connection, CreateConnection"); sptr abilityConnection = new AbilityConnection(); if (abilityConnection == nullptr) { HILOG_ERROR("create connedction failed."); @@ -107,7 +107,6 @@ ErrCode ConnectionManager::CreateConnection(const sptr& connectCa } else { HILOG_ERROR("Call AbilityManagerService's ConnectAbility error:%{public}d", ret); } - HILOG_DEBUG("not find connection, abilityConnectionsSize:%{public}zu.", abilityConnections_.size()); return ret; } diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index faa21b26c6..a72797b916 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -757,13 +757,12 @@ NativeValue* JsAbilityContext::OnConnectAbility(NativeEngine& engine, NativeCall } else { g_serialNumber = 0; } - HILOG_INFO("%{public}s not find connection, make new one", __func__); + AsyncTask::CompleteCallback complete = [weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) { - HILOG_INFO("OnConnectAbility begin"); auto context = weak.lock(); if (!context) { - HILOG_WARN("Connect ability failed, context is released."); + HILOG_ERROR("Connect ability failed, context is released."); task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); return; } @@ -822,14 +821,12 @@ NativeValue* JsAbilityContext::OnConnectAbilityWithAccount(NativeEngine& engine, } else { g_serialNumber = 0; } - HILOG_INFO("%{public}s not find connection, make new one", __func__); AsyncTask::CompleteCallback complete = [weak = context_, want, accountId, connection, connectId]( NativeEngine& engine, AsyncTask& task, int32_t status) { - HILOG_INFO("OnConnectAbilityWithAccount begin"); auto context = weak.lock(); if (!context) { - HILOG_WARN("context is released"); + HILOG_ERROR("context is released"); task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); return; } diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 8e376d4126..16880040d0 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -461,7 +461,6 @@ private: NativeValue* OnConnectAbility(NativeEngine& engine, NativeCallbackInfo& info) { - HILOG_INFO("OnConnectAbility is called"); HILOG_INFO("Connect ability called."); // Check params count if (info.argc < ARGC_TWO) { @@ -480,10 +479,9 @@ private: int64_t connectId = connection->GetConnectionId(); AsyncTask::CompleteCallback complete = [weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) { - HILOG_INFO("OnConnectAbility begin"); auto context = weak.lock(); if (!context) { - HILOG_WARN("context is released"); + HILOG_ERROR("context is released"); task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released")); return; } @@ -524,10 +522,9 @@ private: AsyncTask::CompleteCallback complete = [weak = context_, want, accountId, connection, connectId]( NativeEngine& engine, AsyncTask& task, int32_t status) { - HILOG_INFO("OnConnectAbilityWithAccount begin"); auto context = weak.lock(); if (!context) { - HILOG_WARN("context is released"); + HILOG_ERROR("context is released"); task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released")); return; } diff --git a/interfaces/kits/native/ability/ability_runtime/connection_manager.h b/interfaces/kits/native/ability/ability_runtime/connection_manager.h index 25a60a4b2f..69c9511e89 100644 --- a/interfaces/kits/native/ability/ability_runtime/connection_manager.h +++ b/interfaces/kits/native/ability/ability_runtime/connection_manager.h @@ -57,7 +57,7 @@ struct ConnectionInfo { if (connectCaller == that.connectCaller && connectReceiver.GetBundleName() == that.connectReceiver.GetBundleName() && connectReceiver.GetModuleName() == that.connectReceiver.GetModuleName() && - connectReceiver.GetAbilityName() == that.connectReceiver.GetAbilityName()) { + connectReceiver.GetAbilityName() < that.connectReceiver.GetAbilityName()) { return true; } return false; From e732a33cfc2557dde7f54ae6e20f445dfc59a681 Mon Sep 17 00:00:00 2001 From: liule Date: Wed, 11 Jan 2023 23:45:41 +0800 Subject: [PATCH 23/31] process reused Signed-off-by: liule --- .../appmgr/application_state_observer_proxy.h | 2 + .../appmgr/application_state_observer_stub.h | 4 ++ .../appmgr/iapplication_state_observer.h | 3 ++ .../application_state_observer_proxy.cpp | 21 ++++++++++ .../application_state_observer_stub.cpp | 19 +++++++++ .../include/app_state_observer_manager.h | 2 + services/appmgr/src/app_mgr_service_inner.cpp | 6 ++- .../appmgr/src/app_state_observer_manager.cpp | 39 +++++++++++++++++++ 8 files changed, 95 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h index 51c47b8cff..2fa71b0fdb 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h @@ -79,6 +79,8 @@ public: virtual void OnAppStateChanged(const AppStateData &appStateData) override; + virtual void OnProcessReused(const ProcessData &processData) override; + private: bool WriteInterfaceToken(MessageParcel &data); static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_stub.h b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_stub.h index 710900562c..e086d978d8 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_stub.h @@ -86,6 +86,8 @@ public: virtual void OnAppStateChanged(const AppStateData &appStateData) override; + virtual void OnProcessReused(const ProcessData &processData) override; + private: int32_t HandleOnForegroundApplicationChanged(MessageParcel &data, MessageParcel &reply); @@ -103,6 +105,8 @@ private: int32_t HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnProcessReused(MessageParcel &data, MessageParcel &reply); + using ApplicationStateObserverFunc = int32_t (ApplicationStateObserverStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h b/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h index 5678ff9fdd..88bc185bac 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h +++ b/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h @@ -79,6 +79,8 @@ public: virtual void OnAppStateChanged(const AppStateData &appStateData) {} + virtual void OnProcessReused(const ProcessData &processData) {} + enum class Message { TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED = 0, TRANSACT_ON_ABILITY_STATE_CHANGED, @@ -88,6 +90,7 @@ public: TRANSACT_ON_PROCESS_DIED, TRANSACT_ON_APPLICATION_STATE_CHANGED, TRANSACT_ON_APP_STATE_CHANGED, + TRANSACT_ON_PROCESS_REUSED, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_proxy.cpp index b1059f44ca..32dea1cda8 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_proxy.cpp @@ -122,6 +122,27 @@ void ApplicationStateObserverProxy::OnProcessCreated(const ProcessData &processD } } +void ApplicationStateObserverProxy::OnProcessReused(const ProcessData &processData) { + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + data.WriteParcelable(&processData); + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return; + } + int32_t ret = remote->SendRequest( + static_cast(IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_REUSED), + data, reply, option); + if (ret != NO_ERROR) { + HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); + } +} + void ApplicationStateObserverProxy::OnProcessStateChanged(const ProcessData &processData) { MessageParcel data; diff --git a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp index 2009558506..2ee35f8a26 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp @@ -49,6 +49,10 @@ ApplicationStateObserverStub::ApplicationStateObserverStub() memberFuncMap_[static_cast( IApplicationStateObserver::Message::TRANSACT_ON_APP_STATE_CHANGED)] = &ApplicationStateObserverStub::HandleOnAppStateChanged; + memberFuncMap_[static_cast( + IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_REUSED)] = + &ApplicationStateObserverStub::HandleOnProcessReused; + } ApplicationStateObserverStub::~ApplicationStateObserverStub() @@ -102,6 +106,9 @@ void ApplicationStateObserverStub::OnApplicationStateChanged(const AppStateData void ApplicationStateObserverStub::OnAppStateChanged(const AppStateData &appStateData) {} +void ApplicationStateObserverStub::OnProcessReused(const ProcessData &processData) +{} + int32_t ApplicationStateObserverStub::HandleOnForegroundApplicationChanged(MessageParcel &data, MessageParcel &reply) { std::unique_ptr processData(data.ReadParcelable()); @@ -222,6 +229,18 @@ void ApplicationStateObserverRecipient::OnRemoteDied(const wptr & } } +int32_t ApplicationStateObserverStub::HandleOnProcessReused(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr processData(data.ReadParcelable()); + if (!processData) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + OnProcessReused(*processData); + return NO_ERROR; +} + ApplicationStateObserverRecipient::ApplicationStateObserverRecipient(RemoteDiedHandler handler) : handler_(handler) {} diff --git a/services/appmgr/include/app_state_observer_manager.h b/services/appmgr/include/app_state_observer_manager.h index 79cee9dde6..69d935d835 100644 --- a/services/appmgr/include/app_state_observer_manager.h +++ b/services/appmgr/include/app_state_observer_manager.h @@ -47,6 +47,7 @@ public: void OnRenderProcessCreated(const std::shared_ptr &RenderRecord); void OnProcessDied(const std::shared_ptr &appRecord); void OnRenderProcessDied(const std::shared_ptr &renderRecord); + void OnProcessReused(const std::shared_ptr &appRecord); private: void HandleAppStateChanged(const std::shared_ptr &appRecord, const ApplicationState state, bool needNotifyApp); @@ -66,6 +67,7 @@ private: void HandleOnProcessCreated(const ProcessData &data); void HandleOnProcessStateChanged(const std::shared_ptr &appRecord); void HandleOnProcessDied(const ProcessData &data); + void HandleOnProcessResued(const std::shared_ptr &appRecord); private: std::shared_ptr handler_; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 7ee8e748f3..a3bf330650 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -181,7 +181,11 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord, appInfo->uid, appInfo->bundleName, bundleIndex); } else { - appRecord->SetRequestProcCode((want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); + int32_t requestProcCode = (want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0); + if (requestProcCode != 0 && appRecord->GetRequestProcCode() == 0) { + appRecord->SetRequestProcCode(requestProcCode); + DelayedSingleton::GetInstance()->OnProcessReused(appRecord); + } StartAbility(token, preToken, abilityInfo, appRecord, hapModuleInfo, want); } PerfProfile::GetInstance().SetAbilityLoadEndTime(GetTickCount()); diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index 9e775e8a1c..315d4ac09b 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -188,6 +188,25 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptrPostTask(task); } +void AppStateObserverManager::OnProcessReused(const std::shared_ptr &appRecord) +{ + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnProcessReused failed."); + return; + } + + auto task = [weak = weak_from_this(), appRecord]() { + auto self = weak.lock(); + if (self == nullptr) { + HILOG_ERROR("self is nullptr, OnProcessReused failed."); + return; + } + HILOG_INFO("OnProcessReused come."); + self->HandleOnProcessResued(appRecord); + }; + handler_->PostTask(task); +} + void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr &renderRecord) { if (handler_ == nullptr) { @@ -299,6 +318,26 @@ void AppStateObserverManager::HandleOnAppProcessCreated(const std::shared_ptr &appRecord) +{ + if (!appRecord) { + HILOG_ERROR("app record is null"); + return; + } + ProcessData data = WrapProcessData(appRecord); + HILOG_DEBUG("Process Resued, bundle:%{public}s, pid:%{public}d, uid:%{public}d", + data.bundleName.c_str(), data.pid, data.uid); + + std::lock_guard lockNotify(observerLock_); + for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { + std::vector::iterator iter = std::find(it->second.begin(), + it->second.end(), data.bundleName); + if ((it->second.empty() || iter != it->second.end()) && it->first != nullptr) { + it->first->OnProcessReused(data); + } + } +} + void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr &renderRecord) { if (!renderRecord) { From 9b8fbe6236e85039c2f6a81bfb2832ca166091b3 Mon Sep 17 00:00:00 2001 From: xuzheheng Date: Thu, 12 Jan 2023 02:15:18 +0000 Subject: [PATCH 24/31] xuzheheng1@huawei.com Signed-off-by: xuzheheng Change-Id: I43d0223944fb8344b921bc1589fbae1dc0940395 --- test/unittest/app_mgr_client_test/app_mgr_client_test.cpp | 5 +++-- .../ability_process_test.cpp | 1 + .../frameworks_kits_runtime_native_test/source_map_test.cpp | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index a631d2fb9a..596935d750 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -315,10 +315,11 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_KillApplicationSelf_001, TestSize.Level0 */ HWTEST_F(AppMgrClientTest, AppMgrClient_AbilityAttachTimeOut_001, TestSize.Level0) { - sptr token = nullptr; auto appMgrClient = std::make_unique(); auto result = appMgrClient->ConnectAppMgrService(); - EXPECT_EQ(result, AppMgrResultCode::ERROR_SERVICE_NOT_READY); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + + sptr token = nullptr; appMgrClient->AbilityAttachTimeOut(token); } diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_process_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_process_test.cpp index 701e128f9f..c3d9125f09 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_process_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_process_test.cpp @@ -208,6 +208,7 @@ HWTEST_F(AbilityProcessTest, AaFwk_AbilityProcess_0800, Function | MediumTest | HWTEST_F(AbilityProcessTest, AaFwk_AbilityProcess_0900, Function | MediumTest | Level1) { GTEST_LOG_(INFO) << "AaFwk_AbilityProcess_0900 start"; + process_->abilityResultMap_.clear(); Ability *ability = new (std::nothrow) MockNewAbility(); CallAbilityParam param; param.forResultOption = true; diff --git a/test/unittest/frameworks_kits_runtime_native_test/source_map_test.cpp b/test/unittest/frameworks_kits_runtime_native_test/source_map_test.cpp index 2f0a2e8d10..15db847ab0 100644 --- a/test/unittest/frameworks_kits_runtime_native_test/source_map_test.cpp +++ b/test/unittest/frameworks_kits_runtime_native_test/source_map_test.cpp @@ -199,7 +199,7 @@ HWTEST_F(SourceMapTest, AaFwk_SourceMap_0700, Function | MediumTest | Level1) /** * @tc.number: AaFwk_SourceMap_0800 * @tc.name: ReadSourceMapData - * @tc.desc: Verifying ReadSourceMapData succeeded. + * @tc.desc: Verifying ReadSourceMapData Failed. */ HWTEST_F(SourceMapTest, AaFwk_SourceMap_0800, Function | MediumTest | Level1) { @@ -207,8 +207,7 @@ HWTEST_F(SourceMapTest, AaFwk_SourceMap_0800, Function | MediumTest | Level1) auto modSourceMap = std::make_shared(); std::string filePath = "./source_map_test"; std::string context; - modSourceMap->ReadSourceMapData(filePath, context); - EXPECT_TRUE(!context.empty()); + EXPECT_FALSE(modSourceMap->ReadSourceMapData(filePath, context)); GTEST_LOG_(INFO) << "AaFwk_SourceMap_0800 end"; } From cecce5e121300d0709b5aee0c89083ed5c250d33 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Thu, 12 Jan 2023 19:08:25 +0800 Subject: [PATCH 25/31] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- frameworks/js/napi/inner/napi_common/napi_common_want.cpp | 1 - .../native/appkit/ability_delegator/ability_delegator.cpp | 2 +- frameworks/native/runtime/js_runtime.cpp | 2 +- .../kits/native/ability/native/extension_config_mgr.h | 8 ++++---- services/abilitymgr/src/mission_info_mgr.cpp | 2 -- services/appmgr/include/app_running_record.h | 2 +- services/appmgr/include/quick_fix_callback_with_record.h | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/frameworks/js/napi/inner/napi_common/napi_common_want.cpp b/frameworks/js/napi/inner/napi_common/napi_common_want.cpp index 8a61186a71..1db0d2ff11 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_want.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_want.cpp @@ -911,7 +911,6 @@ void HandleNapiObject(napi_env env, napi_value param, napi_value jsProValue, std HandleFdObject(env, param, strProName, wantParams); } else if (IsSpecialObject(env, param, strProName, REMOTE_OBJECT, napi_object)) { HILOG_WARN("REMOTE_OBJECT is FORIBBED IN WANT."); - // HandleRemoteObject(env, param, strProName, wantParams); } else { bool isArray = false; if (napi_is_array(env, jsProValue, &isArray) == napi_ok) { diff --git a/frameworks/native/appkit/ability_delegator/ability_delegator.cpp b/frameworks/native/appkit/ability_delegator/ability_delegator.cpp index 1e7f887e34..c66b3aab3b 100644 --- a/frameworks/native/appkit/ability_delegator/ability_delegator.cpp +++ b/frameworks/native/appkit/ability_delegator/ability_delegator.cpp @@ -644,7 +644,7 @@ void AbilityDelegator::RemoveAbilityProperty(const std::shared_ptrname_.data(), ability->lifecycleState_); std::unique_lock lck(mutexAbilityProperties_); - abilityProperties_.remove_if([ability](auto &properties) { + abilityProperties_.remove_if([ability](const auto &properties) { return ability->fullName_ == properties->fullName_; }); } diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index c0c13e2ae7..2e9c2ee22b 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -167,7 +167,7 @@ public: } } - auto func = [&](std::string modulePath, std::string abcPath) { + auto func = [&](std::string modulePath, const std::string abcPath) { std::ostringstream outStream; if (!extractor->GetFileBuffer(modulePath, outStream)) { HILOG_ERROR("Get abc file failed"); diff --git a/interfaces/kits/native/ability/native/extension_config_mgr.h b/interfaces/kits/native/ability/native/extension_config_mgr.h index 7a13a28ab5..484cb2bf09 100644 --- a/interfaces/kits/native/ability/native/extension_config_mgr.h +++ b/interfaces/kits/native/ability/native/extension_config_mgr.h @@ -40,20 +40,20 @@ public: /** * @brief ExtensionConfigMgr initialization - * + * */ void Init(); /** * @brief Update bundle extension information - * + * * @param engine JS NativeEngine */ void UpdateBundleExtensionInfo(NativeEngine &engine, AppExecFwk::BundleInfo &bundleInfo); /** * @brief Add extension blacklist item - * + * * @param name Extension name * @param type Extension type */ @@ -61,7 +61,7 @@ public: /** * @brief Update extension blacklist to native engine - * + * * @param engine JS NativeEngine */ void UpdateBlackListToEngine(NativeEngine &engine); diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission_info_mgr.cpp index 16762bfc59..36b3584e5b 100644 --- a/services/abilitymgr/src/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission_info_mgr.cpp @@ -295,8 +295,6 @@ bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName, return false; } - - std::lock_guard lock(mutex_); auto it = std::find_if(missionInfoList_.begin(), missionInfoList_.end(), [&missionName, &flag, &isFindRecentStandard](const InnerMissionInfo item) { diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index cf24274c99..12e4b42a1b 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -545,7 +545,7 @@ public: int64_t GetAppStartTime() const; - void SetRestartTimeMillis(const int64_t restartTimeMills); + void SetRestartTimeMillis(const int64_t restartTimeMillis); void SetRequestProcCode(int32_t requestProcCode); int32_t GetRequestProcCode() const; diff --git a/services/appmgr/include/quick_fix_callback_with_record.h b/services/appmgr/include/quick_fix_callback_with_record.h index cfc5120379..a5491c82e8 100644 --- a/services/appmgr/include/quick_fix_callback_with_record.h +++ b/services/appmgr/include/quick_fix_callback_with_record.h @@ -30,7 +30,7 @@ public: : callback_(callback) {} - virtual ~QuickFixCallbackWithRecord(); + ~QuickFixCallbackWithRecord() override; void OnLoadPatchDone(int32_t resultCode, int32_t recordId) override; void OnUnloadPatchDone(int32_t resultCode, int32_t recordId) override; From cae3c96c7798f45b86b63913107b39c4f757184c Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Wed, 11 Jan 2023 08:50:12 +0000 Subject: [PATCH 26/31] Issue:#I6A12D Signed-off-by: zhoushicheng Change-Id: I65301933da89d529dee6e524e339f1c31952ae89 --- frameworks/native/ability/native/ability.cpp | 1 + hisysevent.yaml | 5 +++-- services/common/include/event_report.h | 1 + services/common/src/event_report.cpp | 12 +++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index fddbe96ce4..cc8cf3c493 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -334,6 +334,7 @@ void Ability::OnActive() eventInfo.bundleName = abilityInfo_->bundleName; eventInfo.moduleName = abilityInfo_->moduleName; eventInfo.abilityName = abilityInfo_->name; + eventInfo.abilityType = static_cast(abilityInfo_->type); AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONACTIVE, HiSysEventType::BEHAVIOR, eventInfo); HILOG_DEBUG("%{public}s end.", __func__); diff --git a/hisysevent.yaml b/hisysevent.yaml index 4d5c70185a..890540c6ff 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -139,6 +139,7 @@ ABILITY_ONACTIVE: BUNDLE_NAME: {type: STRING, desc: bundle name} MODULE_NAME: {type: STRING, desc: module name} ABILITY_NAME: {type: STRING, desc: ability name} + ABILITY_TYPE: {type: INT32, desc: ability type} ABILITY_ONINACTIVE: __BASE: {type: BEHAVIOR, level: MINOR, desc: ability onInactive} @@ -154,7 +155,7 @@ START_SERVICE: BUNDLE_NAME: {type: STRING, desc: bundle name} MODULE_NAME: {type: STRING, desc: module name} ABILITY_NAME: {type: STRING, desc: ability name} - EXTENSION_TYPE: {type: STRING, desc: extension type} + EXTENSION_TYPE: {type: INT32, desc: extension type} STOP_SERVICE: __BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: stop serviceExtensionAbility} @@ -162,7 +163,7 @@ STOP_SERVICE: BUNDLE_NAME: {type: STRING, desc: bundle name} MODULE_NAME: {type: STRING, desc: module name} ABILITY_NAME: {type: STRING, desc: ability name} - EXTENSION_TYPE: {type: STRING, desc: extension type} + EXTENSION_TYPE: {type: INT32, desc: extension type} CONNECT_SERVICE: __BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: connect serviceAbility} diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index 54d473412b..403b4491ed 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -38,6 +38,7 @@ struct EventInfo { std::string moduleName; std::string abilityName; std::string processName; + int32_t abilityType = -1; }; enum class EventName { diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 3357a3d800..ed717952d4 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -30,6 +30,7 @@ const std::string EVENT_KEY_ERROR_CODE = "ERROR_CODE"; const std::string EVENT_KEY_BUNDLE_NAME = "BUNDLE_NAME"; const std::string EVENT_KEY_MODULE_NAME = "MODULE_NAME"; const std::string EVENT_KEY_ABILITY_NAME = "ABILITY_NAME"; +const std::string EVENT_KEY_ABILITY_TYPE = "ABILITY_TYPE"; const std::string EVENT_KEY_VERSION_NAME = "VERSION_NAME"; const std::string EVENT_KEY_VERSION_CODE = "VERSION_CODE"; const std::string EVENT_KEY_PROCESS_NAME = "PROCESS_NAME"; @@ -132,7 +133,6 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty break; case EventName::ABILITY_ONFOREGROUND: case EventName::ABILITY_ONBACKGROUND: - case EventName::ABILITY_ONACTIVE: case EventName::ABILITY_ONINACTIVE: HiSysEventWrite( HiSysEvent::Domain::AAFWK, @@ -142,6 +142,16 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty EVENT_KEY_MODULE_NAME, eventInfo.moduleName, EVENT_KEY_ABILITY_NAME, eventInfo.abilityName); break; + case EventName::ABILITY_ONACTIVE: + HiSysEventWrite( + HiSysEvent::Domain::AAFWK, + name, + type, + EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName, + EVENT_KEY_MODULE_NAME, eventInfo.moduleName, + EVENT_KEY_ABILITY_NAME, eventInfo.abilityName, + EVENT_KEY_ABILITY_TYPE, eventInfo.abilityType); + break; default: break; } From a3d3dcc14d940c70aada832180f97eb75014b0c9 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 13 Jan 2023 09:29:34 +0000 Subject: [PATCH 27/31] Description:add if appRecord is null Sig:SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9feec9e6ce..4564880254 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -743,6 +743,9 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf } auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); + if(!appRecord) { + HiLOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid); + } GetRunningProcess(appRecord, info); return ERR_OK; } From bcddbd7ccda88956f08a1c13081466e3a0e0a838 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 13 Jan 2023 09:53:23 +0000 Subject: [PATCH 28/31] update services/appmgr/src/app_mgr_service_inner.cpp. Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index aadf255759..1747c4f4c7 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -743,7 +743,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if(!appRecord) { - HiLOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid); + HILOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid); } GetRunningProcess(appRecord, info); return ERR_OK; From 2db44757c00466444a58e2032e91e27b39c90808 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 16 Jan 2023 00:49:11 +0000 Subject: [PATCH 29/31] update services/appmgr/src/app_mgr_service_inner.cpp. Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 1747c4f4c7..3e1fbfacab 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -744,6 +744,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf auto appRecord = GetAppRunningRecordByPid(callerPid); if(!appRecord) { HILOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid); + return ERR_INVALID_VALUE; } GetRunningProcess(appRecord, info); return ERR_OK; From 25a1f5e1f491cd35e8a630bb3d3938cbbc98deda Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 16 Jan 2023 01:00:38 +0000 Subject: [PATCH 30/31] update services/appmgr/src/app_mgr_service_inner.cpp. Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 3e1fbfacab..4e5202c433 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -742,7 +742,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf } auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); - if(!appRecord) { + if (!appRecord) { HILOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid); return ERR_INVALID_VALUE; } From 2e26a1b2bd08f20fd147cfad320c4b95e0f5f1da Mon Sep 17 00:00:00 2001 From: caochunlei Date: Sat, 14 Jan 2023 22:35:13 +0800 Subject: [PATCH 31/31] caochunlei1@huawei.com Signed-off-by: caochunlei --- bundle.json | 9 + frameworks/js/napi/BUILD.gn | 1 + .../napi/ability_context/ability_context.js | 4 + .../js/napi/dialog_request_info/BUILD.gn | 43 +++++ .../include/request_info.h | 38 ++++ .../napi/dialog_request_info/request_info.cpp | 99 ++++++++++ frameworks/js/napi/inner/napi_common/BUILD.gn | 1 + .../inner/napi_common/napi_common_want.cpp | 9 +- frameworks/js/napi/js_dialog_request/BUILD.gn | 54 ++++++ .../include/js_dialog_request.h | 26 +++ .../include/js_dialog_request_callback.h | 26 +++ .../js_dialog_request/js_dialog_request.cpp | 173 ++++++++++++++++++ .../js_dialog_request_callback.cpp | 119 ++++++++++++ .../napi/js_dialog_request/native_module.cpp | 30 +++ frameworks/native/ability/BUILD.gn | 2 + .../ability_runtime/ability_context_impl.cpp | 76 ++++++++ .../dialog_request_callback_impl.cpp | 31 ++++ frameworks/native/ability/native/BUILD.gn | 33 ++++ .../ability_runtime/js_ability_context.cpp | 66 +++++++ .../dialog_request_callback_proxy.cpp | 48 +++++ .../dialog_request_callback_stub.cpp | 55 ++++++ .../ability/ability_runtime/ability_context.h | 13 ++ .../ability_runtime/ability_context_impl.h | 3 + .../dialog_request_callback_impl.h | 36 ++++ .../ability_runtime/request_constants.h | 27 +++ .../ability_runtime/js_ability_context.h | 3 + .../dialog_request_callback_proxy.h | 46 +++++ .../dialog_request_callback_stub.h | 50 +++++ .../idialog_request_callback.h | 48 +++++ 29 files changed, 1168 insertions(+), 1 deletion(-) create mode 100755 frameworks/js/napi/dialog_request_info/BUILD.gn create mode 100755 frameworks/js/napi/dialog_request_info/include/request_info.h create mode 100755 frameworks/js/napi/dialog_request_info/request_info.cpp create mode 100755 frameworks/js/napi/js_dialog_request/BUILD.gn create mode 100755 frameworks/js/napi/js_dialog_request/include/js_dialog_request.h create mode 100755 frameworks/js/napi/js_dialog_request/include/js_dialog_request_callback.h create mode 100755 frameworks/js/napi/js_dialog_request/js_dialog_request.cpp create mode 100755 frameworks/js/napi/js_dialog_request/js_dialog_request_callback.cpp create mode 100755 frameworks/js/napi/js_dialog_request/native_module.cpp create mode 100755 frameworks/native/ability/ability_runtime/dialog_request_callback_impl.cpp create mode 100755 frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_proxy.cpp create mode 100755 frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp create mode 100755 interfaces/kits/native/ability/ability_runtime/dialog_request_callback_impl.h create mode 100755 interfaces/kits/native/ability/ability_runtime/request_constants.h create mode 100755 interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_proxy.h create mode 100755 interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h create mode 100755 interfaces/kits/native/ability/native/dialog_request_callback/idialog_request_callback.h diff --git a/bundle.json b/bundle.json index 7ef3cb30bf..f3357aecca 100644 --- a/bundle.json +++ b/bundle.json @@ -243,6 +243,15 @@ }, "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:data_ability_helper" }, + { + "header": { + "header_base": "//foundation/ability/ability_runtime/frameworks/js/napi/dialog_request_info/include", + "header_files": [ + "request_info.h" + ] + }, + "name": "//foundation/ability/ability_runtime/frameworks/js/napi/dialog_request_info:dialog_request_info" + }, { "header": { "header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/", diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 208670cb37..2ea0157654 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -49,6 +49,7 @@ group("napi_packages") { "${ability_runtime_napi_path}/featureAbility:featureability", "${ability_runtime_napi_path}/feature_ability:featureability_napi", "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_napi_path}/js_dialog_request:dialogrequest_napi", "${ability_runtime_napi_path}/js_mission_manager:missionmanager", "${ability_runtime_napi_path}/mission_manager:distributedmissionmanager", "${ability_runtime_napi_path}/mission_manager:missionmanager_napi", diff --git a/frameworks/js/napi/ability_context/ability_context.js b/frameworks/js/napi/ability_context/ability_context.js index 4f6e49e6a5..24ef687523 100644 --- a/frameworks/js/napi/ability_context/ability_context.js +++ b/frameworks/js/napi/ability_context/ability_context.js @@ -146,6 +146,10 @@ class AbilityContext extends Context { setMissionIcon(icon, callback) { return this.__context_impl__.setMissionIcon(icon, callback) } + + requestDialogService(want, resultCallback) { + return this.__context_impl__.requestDialogService(want, resultCallback) + } } export default AbilityContext diff --git a/frameworks/js/napi/dialog_request_info/BUILD.gn b/frameworks/js/napi/dialog_request_info/BUILD.gn new file mode 100755 index 0000000000..9f9567428e --- /dev/null +++ b/frameworks/js/napi/dialog_request_info/BUILD.gn @@ -0,0 +1,43 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +config("dialog_request_info_external_config") { + include_dirs = [ "include" ] +} + +ohos_shared_library("dialog_request_info") { + sources = [ "request_info.cpp" ] + + public_configs = [ ":dialog_request_info_external_config" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_runtime:abilitykit_native", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/dialog_request_info/include/request_info.h b/frameworks/js/napi/dialog_request_info/include/request_info.h new file mode 100755 index 0000000000..ac31897a7f --- /dev/null +++ b/frameworks/js/napi/dialog_request_info/include/request_info.h @@ -0,0 +1,38 @@ +/* + * 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_ABILITY_RUNTIME_REQUEST_INFO_H +#define OHOS_ABILITY_RUNTIME_REQUEST_INFO_H + +#include "iremote_object.h" +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +class RequestInfo { +public: + explicit RequestInfo(const sptr &token); + ~RequestInfo(); + + static NativeValue* WrapRequestInfo(NativeEngine &engine, RequestInfo *request); + static std::shared_ptr UnwrapRequestInfo(NativeEngine &engine, NativeValue *jsParam); + + sptr GetToken(); +private: + sptr callerToken_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REQUEST_INFO_H diff --git a/frameworks/js/napi/dialog_request_info/request_info.cpp b/frameworks/js/napi/dialog_request_info/request_info.cpp new file mode 100755 index 0000000000..5406dc18d1 --- /dev/null +++ b/frameworks/js/napi/dialog_request_info/request_info.cpp @@ -0,0 +1,99 @@ +/* + * 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. + */ + +#include "request_info.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { + +RequestInfo::RequestInfo(const sptr &token) +{ + callerToken_ = token; +} + +RequestInfo::~RequestInfo() +{ +} + +sptr RequestInfo::GetToken() +{ + return callerToken_; +} + +NativeValue* RequestInfo::WrapRequestInfo(NativeEngine &engine, RequestInfo *request) +{ + HILOG_DEBUG("WrapRequestInfo called."); + if (request == nullptr) { + HILOG_ERROR("request is nullptr."); + return nullptr; + } + + NativeCallback callback = [](NativeEngine* engine, NativeCallbackInfo* info) -> NativeValue* { + return info->thisVar; + }; + + NativeValue* requestInfoClass = engine.DefineClass("RequestInfoClass", callback, nullptr, nullptr, 0); + NativeValue* result = engine.CreateInstance(requestInfoClass, nullptr, 0); + if (result == nullptr) { + HILOG_ERROR("create instance failed."); + return nullptr; + } + + NativeObject* nativeObject = reinterpret_cast(result->GetInterface(NativeObject::INTERFACE_ID)); + if (nativeObject == nullptr) { + HILOG_ERROR("get nativeObject failed."); + return nullptr; + } + + NativeFinalize nativeFinalize = [](NativeEngine* engine, void* data, void* hint) { + HILOG_INFO("Js RequestInfo finalizer is called"); + auto requestInfo = static_cast(data); + if (requestInfo) { + delete requestInfo; + requestInfo = nullptr; + } + }; + + nativeObject->SetNativePointer(reinterpret_cast(request), nativeFinalize, nullptr); + return result; +} + +std::shared_ptr RequestInfo::UnwrapRequestInfo(NativeEngine &engine, NativeValue *jsParam) +{ + HILOG_INFO("UnwrapRequestInfo called."); + if (jsParam == nullptr) { + HILOG_ERROR("jsParam is nullptr"); + return nullptr; + } + + if (jsParam->TypeOf() != NATIVE_OBJECT) { + HILOG_ERROR("UnwrapRequestInfo jsParam type error!"); + return nullptr; + } + + NativeObject *nativeObject = reinterpret_cast(jsParam->GetInterface(NativeObject::INTERFACE_ID)); + if (nativeObject == nullptr) { + HILOG_ERROR("UnwrapRequestInfo reinterpret_cast failed!"); + return nullptr; + } + HILOG_INFO("UnwrapRequestInfo success."); + + RequestInfo *info = static_cast(nativeObject->GetNativePointer()); + return std::make_shared(*info); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index 32e1618c17..6fbf903a55 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -45,6 +45,7 @@ ohos_shared_library("napi_common") { "ability_runtime:napi_base_context", "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/js/napi/inner/napi_common/napi_common_want.cpp b/frameworks/js/napi/inner/napi_common/napi_common_want.cpp index 1db0d2ff11..097ae119f7 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_want.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_want.cpp @@ -16,6 +16,7 @@ #include "napi_common_want.h" #include "hilog_wrapper.h" +#include "ipc_skeleton.h" #include "napi_common_util.h" #include "array_wrapper.h" #include "bool_wrapper.h" @@ -27,6 +28,7 @@ #include "long_wrapper.h" #include "short_wrapper.h" #include "string_wrapper.h" +#include "tokenid_kit.h" #include "zchar_wrapper.h" #include "remote_object_wrapper.h" #include "want_params_wrapper.h" @@ -910,7 +912,12 @@ void HandleNapiObject(napi_env env, napi_value param, napi_value jsProValue, std if (IsSpecialObject(env, param, strProName, FD, napi_number)) { HandleFdObject(env, param, strProName, wantParams); } else if (IsSpecialObject(env, param, strProName, REMOTE_OBJECT, napi_object)) { - HILOG_WARN("REMOTE_OBJECT is FORIBBED IN WANT."); + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + HandleRemoteObject(env, param, strProName, wantParams); + } else { + HILOG_WARN("not system app, REMOTE_OBJECT is FORIBBED IN WANT."); + } } else { bool isArray = false; if (napi_is_array(env, jsProValue, &isArray) == napi_ok) { diff --git a/frameworks/js/napi/js_dialog_request/BUILD.gn b/frameworks/js/napi/js_dialog_request/BUILD.gn new file mode 100755 index 0000000000..bb707d2348 --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +config("dialog_request_external_config") { + include_dirs = [ "include" ] +} + +ohos_shared_library("dialogrequest_napi") { + sources = [ + "js_dialog_request.cpp", + "js_dialog_request_callback.cpp", + "native_module.cpp", + ] + + public_configs = [ ":dialog_request_external_config" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:dialog_request_callback", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_runtime:abilitykit_native", + "ability_runtime:dialog_request_info", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/js_dialog_request/include/js_dialog_request.h b/frameworks/js/napi/js_dialog_request/include/js_dialog_request.h new file mode 100755 index 0000000000..2c927ce1dc --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/include/js_dialog_request.h @@ -0,0 +1,26 @@ +/* + * 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_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H +#define OHOS_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +NativeValue* JsDialogRequestInit(NativeEngine* engine, NativeValue* exportObj); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H diff --git a/frameworks/js/napi/js_dialog_request/include/js_dialog_request_callback.h b/frameworks/js/napi/js_dialog_request/include/js_dialog_request_callback.h new file mode 100755 index 0000000000..97d8366844 --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/include/js_dialog_request_callback.h @@ -0,0 +1,26 @@ +/* + * 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_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H + +#include "idialog_request_callback.h" +#include "native_engine/native_value.h" + +namespace OHOS { +namespace AbilityRuntime { +NativeValue* CreateJsDialogRequestCallback(NativeEngine &engine, const sptr &remoteObj); +} // AbilityRuntime +} // OHOS +#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H diff --git a/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp new file mode 100755 index 0000000000..7cb7973952 --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp @@ -0,0 +1,173 @@ +/* + * 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. + */ + +#include "js_dialog_request.h" + +#include "hilog_wrapper.h" +#include "js_error_utils.h" +#include "js_dialog_request_callback.h" +#include "js_runtime_utils.h" +#include "napi_common_want.h" +#include "request_constants.h" +#include "request_info.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr size_t ARGC_ONE = 1; +constexpr int32_t RESULT_OK = 0; +constexpr int32_t RESULT_CANCEL = 1; +} + +NativeValue* ResultCodeInit(NativeEngine* engine) +{ + HILOG_INFO("%{public}s is called", __FUNCTION__); + if (engine == nullptr) { + HILOG_ERROR("Invalid input parameters"); + return nullptr; + } + + NativeValue* objValue = engine->CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + HILOG_ERROR("Failed to get object"); + return nullptr; + } + + object->SetProperty("RESULT_OK", CreateJsValue(*engine, RESULT_OK)); + object->SetProperty("RESULT_CANCEL", CreateJsValue(*engine, RESULT_CANCEL)); + + return objValue; +} + +class JsDialogRequest { +public: + JsDialogRequest() = default; + ~JsDialogRequest() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + HILOG_INFO("JsDialogRequest::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* GetRequestInfo(NativeEngine* engine, NativeCallbackInfo* info) + { + JsDialogRequest* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetRequestInfo(*engine, *info) : nullptr; + } + + static NativeValue* GetRequestCallback(NativeEngine* engine, NativeCallbackInfo* info) + { + JsDialogRequest* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetRequestCallback(*engine, *info) : nullptr; + } + +private: + NativeValue* OnGetRequestInfo(NativeEngine &engine, NativeCallbackInfo &info) + { + HILOG_INFO("%{public}s is called", __FUNCTION__); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Params not match"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + OHOS::AAFwk::Want want; + if (!OHOS::AppExecFwk::UnwrapWant(reinterpret_cast(&engine), + reinterpret_cast(info.argv[0]), want)) { + HILOG_ERROR("The input want is invalid."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + sptr callerToken = want.GetRemoteObject(RequestConstants::REQUEST_TOKEN_KEY); + if (!callerToken) { + HILOG_ERROR("Can not get token from target want."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + auto requestInfo = new RequestInfo(callerToken); + auto jsRequestInfo = RequestInfo::WrapRequestInfo(engine, requestInfo); + if (jsRequestInfo == nullptr) { + HILOG_ERROR("Can not wrap requestinfo from target request."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + return jsRequestInfo; + } + + NativeValue* OnGetRequestCallback(NativeEngine &engine, NativeCallbackInfo &info) + { + HILOG_INFO("%{public}s is called", __FUNCTION__); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Params is not match"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + OHOS::AAFwk::Want want; + if (!OHOS::AppExecFwk::UnwrapWant(reinterpret_cast(&engine), + reinterpret_cast(info.argv[0]), want)) { + HILOG_ERROR("The input want is invalid."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + sptr remoteObj = want.GetRemoteObject(RequestConstants::REQUEST_CALLBACK_KEY); + if (!remoteObj) { + HILOG_ERROR("Can not get callback from target want."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + sptr callback = iface_cast(remoteObj); + if (!callback) { + HILOG_ERROR("Cast to IDialogRequestCallback failed."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER); + return engine.CreateUndefined(); + } + + return CreateJsDialogRequestCallback(engine, callback); + } +}; + +NativeValue* JsDialogRequestInit(NativeEngine* engine, NativeValue* exportObj) +{ + HILOG_INFO("JsDialogRequestInit is called"); + if (engine == nullptr || exportObj == nullptr) { + HILOG_INFO("Invalid input parameters"); + return nullptr; + } + + NativeObject* object = ConvertNativeValueTo(exportObj); + if (object == nullptr) { + HILOG_INFO("object is nullptr"); + return nullptr; + } + + std::unique_ptr jsDialogRequest = std::make_unique(); + object->SetNativePointer(jsDialogRequest.release(), JsDialogRequest::Finalizer, nullptr); + object->SetProperty("ResultCode", ResultCodeInit(engine)); + + const char *moduleName = "JsDialogRequest"; + BindNativeFunction(*engine, *object, "getRequestInfo", moduleName, JsDialogRequest::GetRequestInfo); + BindNativeFunction(*engine, *object, "getRequestCallback", moduleName, JsDialogRequest::GetRequestCallback); + return engine->CreateUndefined(); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/js_dialog_request/js_dialog_request_callback.cpp b/frameworks/js/napi/js_dialog_request/js_dialog_request_callback.cpp new file mode 100755 index 0000000000..ad58076d35 --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/js_dialog_request_callback.cpp @@ -0,0 +1,119 @@ +/* + * 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. + */ + +#include "js_dialog_request_callback.h" + +#include "hilog_wrapper.h" +#include "js_context_utils.h" +#include "js_error_utils.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { // nameless +class JsDialogRequestCallback { +public: + explicit JsDialogRequestCallback(const sptr remoteObj) :callback_(remoteObj) {} + + virtual ~JsDialogRequestCallback() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + HILOG_DEBUG("JsDialogRequestCallback::Finalizer is called."); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* SetRequestResult(NativeEngine* engine, NativeCallbackInfo* info) + { + if (engine == nullptr || info == nullptr) { + HILOG_ERROR("input parameters %{public}s is nullptr", ((engine == nullptr) ? "engine" : "info")); + return nullptr; + } + + auto object = CheckParamsAndGetThis(engine, info); + if (object == nullptr) { + HILOG_ERROR("CheckParamsAndGetThis return nullptr"); + return nullptr; + } + + return object->OnSetRequestResult(*engine, *info); + } + +private: + NativeValue* OnSetRequestResult(NativeEngine& engine, NativeCallbackInfo& info) + { + HILOG_INFO("function called"); + if (info.argc < 1) { + HILOG_ERROR("Params not match"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + if (info.argv[0]->TypeOf() != NativeValueType::NATIVE_OBJECT) { + HILOG_ERROR("param type mismatch!"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + NativeObject* paramObject = ConvertNativeValueTo(info.argv[0]); + NativeValue* resultCode = paramObject->GetProperty("result"); + int32_t resultCodeValue = 0; + if (!ConvertFromJsValue(engine, resultCode, resultCodeValue)) { + HILOG_ERROR("Convert result failed!"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + if (callback_ == nullptr) { + HILOG_ERROR("JsDialogRequestCallback::%{public}s, callback_ is nullptr", __func__); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER); + return engine.CreateUndefined(); + } + callback_->SendResult(resultCodeValue); + HILOG_INFO("function called end."); + return engine.CreateUndefined(); + } + +private: + sptr callback_; +}; +} // nameless + +NativeValue* CreateJsDialogRequestCallback(NativeEngine &engine, const sptr &remoteObj) +{ + HILOG_INFO("CreateJsDialogRequestCallback"); + if (!remoteObj) { + HILOG_ERROR("remoteObj is invalid."); + return engine.CreateUndefined(); + } + + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + HILOG_ERROR("object is invalid."); + return engine.CreateUndefined(); + } + + auto jsDialogRequestCallback = std::make_unique(remoteObj); + object->SetNativePointer(jsDialogRequestCallback.release(), JsDialogRequestCallback::Finalizer, nullptr); + const char *moduleName = "JsDialogRequestCallback"; + BindNativeFunction(engine, *object, "setRequestResult", moduleName, JsDialogRequestCallback::SetRequestResult); + + HILOG_INFO("CreateJsDialogRequestCallback end"); + return objValue; +} +} // AbilityRuntime +} // OHOS diff --git a/frameworks/js/napi/js_dialog_request/native_module.cpp b/frameworks/js/napi/js_dialog_request/native_module.cpp new file mode 100755 index 0000000000..faeaf69b9f --- /dev/null +++ b/frameworks/js/napi/js_dialog_request/native_module.cpp @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#include "js_dialog_request.h" +#include "native_engine/native_engine.h" + +extern "C" __attribute__((constructor)) +void NAPI_app_ability_dialogrequest_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "app.ability.dialogRequest", + .fileName = "app/ability/libdialogrequest.so/dialogrequest.js", + .registerCallback = OHOS::AbilityRuntime::JsDialogRequestInit, + }; + + moduleManager->Register(&newModuleInfo); +} diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index 8a885581f1..c541e133d6 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -41,12 +41,14 @@ ohos_shared_library("ability_context_native") { "ability_runtime/ability_context_impl.cpp", "ability_runtime/authorization_result.cpp", "ability_runtime/connection_manager.cpp", + "ability_runtime/dialog_request_callback_impl.cpp", "ability_runtime/js_extension_context.cpp", "ability_runtime/local_call_container.cpp", "ability_runtime/local_call_record.cpp", ] deps = [ + "${ability_runtime_native_path}/ability/native:dialog_request_callback", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", ] diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index 6a7c8e2661..0925a0b4dd 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -22,9 +22,11 @@ #include "authorization_result.h" #include "hitrace_meter.h" #include "connection_manager.h" +#include "dialog_request_callback_impl.h" #include "hilog_wrapper.h" #include "permission_list_state.h" #include "remote_object_wrapper.h" +#include "request_constants.h" #include "string_wrapper.h" #include "want_params_wrapper.h" @@ -45,6 +47,11 @@ const std::string CALLBACK_KEY = "ohos.ability.params.callback"; std::mutex AbilityContextImpl::mutex_; std::map AbilityContextImpl::permissionRequestCallbacks; +struct RequestResult { + int32_t resultCode {0}; + RequestDialogResultTask task; +}; + Global::Resource::DeviceType AbilityContextImpl::GetDeviceType() const { return (stageContext_ != nullptr) ? stageContext_->GetDeviceType() : Global::Resource::DeviceType::DEVICE_PHONE; @@ -546,6 +553,75 @@ void AbilityContextImpl::RegisterAbilityCallback(std::weak_ptrresultCode = resultCode; + retData->task = std::move(outTask); + + auto loop = engine.GetUVLoop(); + if (loop == nullptr) { + HILOG_ERROR("RequestDialogService, fail to get uv loop."); + return; + } + auto work = new uv_work_t; + work->data = static_cast(retData); + int rev = uv_queue_work( + loop, + work, + [](uv_work_t* work) {}, + RequestDialogResultJSThreadWorker); + if (rev != 0) { + if (retData != nullptr) { + delete retData; + retData = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } + } + }; + + sptr remoteObject = new DialogRequestCallbackImpl(std::move(resultTask)); + want.SetParam(RequestConstants::REQUEST_CALLBACK_KEY, remoteObject); + + auto err = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility( + want, token_, -1, AppExecFwk::ExtensionAbilityType::SERVICE); + HILOG_DEBUG("RequestDialogService ret=%{public}d", static_cast(err)); + return err; +} + +void AbilityContextImpl::RequestDialogResultJSThreadWorker(uv_work_t* work, int status) +{ + HILOG_DEBUG("RequestDialogResultJSThreadWorker is called."); + if (work == nullptr) { + HILOG_ERROR("RequestDialogResultJSThreadWorker, uv_queue_work input work is nullptr"); + return; + } + RequestResult* retCB = static_cast(work->data); + if (retCB == nullptr) { + HILOG_ERROR("RequestDialogResultJSThreadWorker, retCB is nullptr"); + delete work; + work = nullptr; + return; + } + + if (retCB->task) { + retCB->task(retCB->resultCode); + } + + delete retCB; + retCB = nullptr; + delete work; + work = nullptr; +} + #ifdef SUPPORT_GRAPHICS ErrCode AbilityContextImpl::SetMissionLabel(const std::string& label) { diff --git a/frameworks/native/ability/ability_runtime/dialog_request_callback_impl.cpp b/frameworks/native/ability/ability_runtime/dialog_request_callback_impl.cpp new file mode 100755 index 0000000000..e49dc0324b --- /dev/null +++ b/frameworks/native/ability/ability_runtime/dialog_request_callback_impl.cpp @@ -0,0 +1,31 @@ +/* + * 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. + */ + +#include "dialog_request_callback_impl.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +void DialogRequestCallbackImpl::SendResult(int32_t resultCode) +{ + HILOG_INFO("%{public}s called.", __func__); + if (task_) { + HILOG_DEBUG("result code:%{public}d.", resultCode); + task_(resultCode); + } +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 4d77bf6f28..a87aed39c5 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -522,6 +522,39 @@ ohos_shared_library("ability_business_error") { part_name = "ability_runtime" } +config("dialog_request_callback_config") { + visibility = [ ":*" ] + include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/dialog_request_callback" ] +} + +config("dialog_request_callback_public_config") { + visibility = [ ":*" ] + include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/dialog_request_callback" ] +} + +ohos_shared_library("dialog_request_callback") { + sources = [ + "${ability_runtime_native_path}/ability/native/dialog_request_callback/dialog_request_callback_proxy.cpp", + "${ability_runtime_native_path}/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp", + ] + + configs = [ + ":dialog_request_callback_config", + "${ability_runtime_services_path}/common:common_config", + ] + + public_configs = [ ":dialog_request_callback_public_config" ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_prebuilt_etc("extension_blacklist_config.json") { source = "etc/extension_blacklist_config.json" subsystem_name = "ability" diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index a72797b916..dc8ad82a0e 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -168,6 +168,12 @@ NativeValue* JsAbilityContext::RestoreWindowStage(NativeEngine* engine, NativeCa return (me != nullptr) ? me->OnRestoreWindowStage(*engine, *info) : nullptr; } +NativeValue* JsAbilityContext::RequestDialogService(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsAbilityContext* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnRequestDialogService(*engine, *info) : nullptr; +} + NativeValue* JsAbilityContext::IsTerminating(NativeEngine* engine, NativeCallbackInfo* info) { JsAbilityContext* me = CheckParamsAndGetThis(engine, info); @@ -1007,6 +1013,51 @@ NativeValue* JsAbilityContext::OnRestoreWindowStage(NativeEngine& engine, Native return engine.CreateUndefined(); } +NativeValue* JsAbilityContext::OnRequestDialogService(NativeEngine& engine, NativeCallbackInfo& info) +{ + HILOG_INFO("OnRequestDialogService is called"); + + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Not enough params"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + AAFwk::Want want; + OHOS::AppExecFwk::UnwrapWant(reinterpret_cast(&engine), reinterpret_cast(info.argv[0]), want); + HILOG_INFO("requestdialogservice, target:%{public}s.%{public}s.", want.GetBundle().c_str(), + want.GetElement().GetAbilityName().c_str()); + + NativeValue* lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + NativeValue* result = nullptr; + auto uasyncTask = CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result); + std::shared_ptr asyncTask = std::move(uasyncTask); + RequestDialogResultTask task = + [&engine, asyncTask](int32_t resultCode) { + HILOG_INFO("OnRequestDialogService async callback is called"); + NativeValue* requestResult = JsAbilityContext::WrapRequestDialogResult(engine, resultCode); + if (requestResult == nullptr) { + HILOG_WARN("wrap requestResult failed"); + asyncTask->Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); + } else { + asyncTask->Resolve(engine, requestResult); + } + HILOG_INFO("OnRequestDialogService async callback is called end"); + }; + auto context = context_.lock(); + if (context == nullptr) { + HILOG_WARN("context is released, can not requestDialogService"); + asyncTask->Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); + } else { + auto errCode = context->RequestDialogService(engine, want, std::move(task)); + if (errCode != ERR_OK) { + asyncTask->Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(errCode))); + } + } + HILOG_INFO("OnRequestDialogService is called end"); + return result; +} + NativeValue* JsAbilityContext::OnIsTerminating(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_INFO("OnIsTerminating is called"); @@ -1066,6 +1117,19 @@ bool JsAbilityContext::UnWrapAbilityResult(NativeEngine& engine, NativeValue* ar return JsAbilityContext::UnWrapWant(engine, jWant, want); } +NativeValue* JsAbilityContext::WrapRequestDialogResult(NativeEngine& engine, int32_t resultCode) +{ + NativeValue *objValue = engine.CreateObject(); + NativeObject *object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + HILOG_ERROR("Native object is nullptr."); + return objValue; + } + + object->SetProperty("result", CreateJsValue(engine, resultCode)); + return objValue; +} + NativeValue* JsAbilityContext::WrapAbilityResult(NativeEngine& engine, const int& resultCode, const AAFwk::Want& want) { NativeValue* jAbilityResult = engine.CreateObject(); @@ -1186,6 +1250,8 @@ NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptrSendRequest(IDialogRequestCallback::CODE_SEND_RESULT, data, reply, option); + HILOG_INFO("SendRequest result, error code: %{public}d", errCode); + } +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp b/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp new file mode 100755 index 0000000000..a37fc2a8d2 --- /dev/null +++ b/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include "dialog_request_callback_stub.h" + +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "message_parcel.h" + +namespace OHOS { +namespace AbilityRuntime { +DialogRequestCallbackStub::DialogRequestCallbackStub() +{ + vecMemberFunc_.resize(IDialogRequestCallback::CODE_MAX); + vecMemberFunc_[CODE_SEND_RESULT] = &DialogRequestCallbackStub::SendResultInner; +} + +int DialogRequestCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string descriptor = DialogRequestCallbackStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("Local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + if (code < IDialogRequestCallback::CODE_MAX) { + auto memberFunc = vecMemberFunc_[code]; + return (this->*memberFunc)(data, reply); + } + + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int DialogRequestCallbackStub::SendResultInner(MessageParcel &data, MessageParcel &reply) +{ + auto resultCode = data.ReadInt32(); + SendResult(resultCode); + return NO_ERROR; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context.h b/interfaces/kits/native/ability/ability_runtime/ability_context.h index 78dd4099e5..048bcec1e4 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context.h @@ -36,6 +36,7 @@ namespace OHOS { namespace AbilityRuntime { using RuntimeTask = std::function; using PermissionRequestTask = std::function&, const std::vector&)>; +using RequestDialogResultTask = std::function; class LocalCallContainer; class AbilityContext : public Context { public: @@ -221,6 +222,18 @@ public: virtual void RegisterAbilityCallback(std::weak_ptr abilityCallback) = 0; + /** + * @brief Requests dialogService from the system. + * This method is called for dialog request. This is an asynchronous method. When it is executed, + * the task will be called back. + * + * @param engine js native engine. + * @param want Indicates the dialog service to be requested. + * @param task The callback or promise fo js interface. + * @return Returns ERR_OK if success. + */ + virtual ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) = 0; + #ifdef SUPPORT_GRAPHICS /** * @brief Set mission label of this ability. diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h index 4b8467ebe6..a076ae8e4f 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h @@ -168,6 +168,8 @@ public: isTerminating_ = state; } + ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) override; + #ifdef SUPPORT_GRAPHICS /** * @brief Set mission label of this ability. @@ -207,6 +209,7 @@ private: bool isTerminating_ = false; static void ResultCallbackJSThreadWorker(uv_work_t* work, int status); + static void RequestDialogResultJSThreadWorker(uv_work_t* work, int status); void StartGrantExtension(NativeEngine& engine, const std::vector& permissions, const std::vector& permissionsState, int requestCode, PermissionRequestTask &&task); diff --git a/interfaces/kits/native/ability/ability_runtime/dialog_request_callback_impl.h b/interfaces/kits/native/ability/ability_runtime/dialog_request_callback_impl.h new file mode 100755 index 0000000000..28e493de48 --- /dev/null +++ b/interfaces/kits/native/ability/ability_runtime/dialog_request_callback_impl.h @@ -0,0 +1,36 @@ +/* + * 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_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_IMPL_H +#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_IMPL_H + +#include "ability_context.h" +#include "dialog_request_callback_stub.h" + +namespace OHOS { +namespace AbilityRuntime { +class DialogRequestCallbackImpl : public DialogRequestCallbackStub { +public: + explicit DialogRequestCallbackImpl(RequestDialogResultTask &&task) : task_(task) {} + virtual ~DialogRequestCallbackImpl() = default; + + void SendResult(int32_t resultCode) override; + +private: + RequestDialogResultTask task_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_AUTHORIZATION_RESULT_H diff --git a/interfaces/kits/native/ability/ability_runtime/request_constants.h b/interfaces/kits/native/ability/ability_runtime/request_constants.h new file mode 100755 index 0000000000..ee4f4b60e3 --- /dev/null +++ b/interfaces/kits/native/ability/ability_runtime/request_constants.h @@ -0,0 +1,27 @@ +/* + * 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_ABILITY_RUNTIME_REQUEST_CONSTANTS_H +#define OHOS_ABILITY_RUNTIME_REQUEST_CONSTANTS_H + +namespace OHOS { +namespace AbilityRuntime { +namespace RequestConstants { +constexpr const char* REQUEST_TOKEN_KEY = "ohos.ability.params.request.token"; +constexpr const char* REQUEST_CALLBACK_KEY = "ohos.ability.params.request.callback"; +} // namespace RequestConstants +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REQUEST_CONSTANTS_H diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h index a54e935f64..7040adac23 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h @@ -55,6 +55,7 @@ public: static NativeValue* TerminateSelfWithResult(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* RequestPermissionsFromUser(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* RestoreWindowStage(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* RequestDialogService(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* IsTerminating(NativeEngine* engine, NativeCallbackInfo* info); static void ConfigurationUpdated(NativeEngine* engine, std::shared_ptr &jsContext, @@ -92,6 +93,7 @@ private: NativeValue* OnTerminateSelf(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnRequestPermissionsFromUser(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnRestoreWindowStage(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnRequestDialogService(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnIsTerminating(NativeEngine& engine, NativeCallbackInfo& info); static bool UnWrapWant(NativeEngine& engine, NativeValue* argv, AAFwk::Want& want); @@ -101,6 +103,7 @@ private: static NativeValue* WrapPermissionRequestResult(NativeEngine& engine, const std::vector &permissions, const std::vector &grantResults); void InheritWindowMode(AAFwk::Want &want); + static NativeValue* WrapRequestDialogResult(NativeEngine& engine, int32_t resultCode); std::weak_ptr context_; int curRequestCode_ = 0; diff --git a/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_proxy.h b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_proxy.h new file mode 100755 index 0000000000..e8ad32906c --- /dev/null +++ b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_proxy.h @@ -0,0 +1,46 @@ +/* + * 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_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H +#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H + +#include + +#include "idialog_request_callback.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * proxy of dialog request callback. + */ +class DialogRequestCallbackProxy : public IRemoteProxy { +public: + explicit DialogRequestCallbackProxy(const sptr &impl) : IRemoteProxy(impl) + {} + + /** + * @brief Send dialogRequest result. + * + * @param resultCode result code. + */ + virtual void SendResult(int32_t resultCode) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H diff --git a/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h new file mode 100755 index 0000000000..68bec89043 --- /dev/null +++ b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h @@ -0,0 +1,50 @@ +/* + * 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_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H +#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H + +#include + +#include "idialog_request_callback.h" +#include "iremote_object.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @class DialogRequestCallbackStub + * DialogRequestCallback Stub. + */ +class DialogRequestCallbackStub : public IRemoteStub { +public: + DialogRequestCallbackStub(); + virtual ~DialogRequestCallbackStub() = default; + + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(DialogRequestCallbackStub); + + int SendResultInner(MessageParcel &data, MessageParcel &reply); + + using StubFunc = int (DialogRequestCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::vector vecMemberFunc_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H diff --git a/interfaces/kits/native/ability/native/dialog_request_callback/idialog_request_callback.h b/interfaces/kits/native/ability/native/dialog_request_callback/idialog_request_callback.h new file mode 100755 index 0000000000..48ea6f7942 --- /dev/null +++ b/interfaces/kits/native/ability/native/dialog_request_callback/idialog_request_callback.h @@ -0,0 +1,48 @@ +/* + * 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_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H + +#include "iremote_broker.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @class IMissionListener + * IMissionListener is used to notify caller ability that connect or disconnect is complete. + */ +class IDialogRequestCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ability.dialogrequestcallback"); + + /** + * @brief Send dialogRequest result. + * + * @param resultCode result code. + */ + virtual void SendResult(int32_t resultCode) = 0; + + enum DialogRequestCallbackCmd { + // ipc id for SendResult + CODE_SEND_RESULT = 1, + + // maximum of enum + CODE_MAX + }; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H