From 09005455e467dabddd5ffb14999a46568a8b0635 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Sat, 22 Jan 2022 19:44:32 +0800 Subject: [PATCH 1/5] codex Signed-off-by: hanhaibin --- .../include/ability_context_impl.h | 1 - .../src/ability_context_impl.cpp | 8 - .../ability/native/src/ability_thread.cpp | 8 +- .../native/src/data_ability_helper.cpp | 13 +- .../src/js_service_extension_context.cpp | 8 +- .../ability/native/src/new_ability_impl.cpp | 2 +- .../native/ability_runtime/context/context.h | 7 - .../ability_runtime/context/context_impl.cpp | 50 +--- .../ability_runtime/context/context_impl.h | 21 +- .../context/js_context_utils.cpp | 44 ---- .../appkit/native/app/src/main_thread.cpp | 3 +- .../kits/napi/aafwk/app/context/context.js | 51 +--- .../napi_data_ability_helper.cpp | 234 ++++++++++++------ .../featureAbility/napi_data_ability_helper.h | 1 + .../napi_common/feature_ability_common.h | 11 + .../inner/napi_common/napi_common_ability.cpp | 20 +- .../inner/napi_common/napi_common_data.h | 1 + .../resource/ams_service_config.json | 1 - .../abilitymgr/src/ability_manager_proxy.cpp | 6 +- .../src/ability_manager_service.cpp | 15 +- services/abilitymgr/src/ability_record.cpp | 2 +- .../src/ability_scheduler_proxy.cpp | 14 +- .../abilitymgr/src/ability_scheduler_stub.cpp | 4 + .../abilitymgr/src/ability_stack_manager.cpp | 21 +- services/appmgr/src/ams_mgr_scheduler.cpp | 1 - services/appmgr/src/app_mgr_service.cpp | 1 - services/appmgr/src/app_mgr_service_inner.cpp | 16 +- 27 files changed, 282 insertions(+), 282 deletions(-) mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/context.h mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/context_impl.h mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp mode change 100755 => 100644 interfaces/kits/napi/aafwk/app/context/context.js diff --git a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h index cbf3e44ade4..a3676d50ffa 100644 --- a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h @@ -34,7 +34,6 @@ public: std::string GetDatabaseDir() override; std::string GetStorageDir() override; std::string GetDistributedFilesDir() override; - void SwitchArea(int mode) override; std::string GetBundleName() const override; std::shared_ptr GetApplicationInfo() const override; std::shared_ptr GetResourceManager() const override; diff --git a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp index 6e812396a4e..4c9b1ff53e0 100644 --- a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp +++ b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp @@ -59,14 +59,6 @@ std::string AbilityContextImpl::GetDistributedFilesDir() return stageContext_ ? stageContext_->GetDistributedFilesDir() : ""; } -void AbilityContextImpl::SwitchArea(int mode) -{ - HILOG_DEBUG("AbilityContextImpl::SwitchArea."); - if (stageContext_ != nullptr) { - stageContext_->SwitchArea(mode); - } -} - ErrCode AbilityContextImpl::StartAbility(const AAFwk::Want &want, int requestCode) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index b161deeeb38..48c72e64652 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -432,12 +432,14 @@ void AbilityThread::HandleAbilityTransaction(const Want &want, const LifeCycleSt return; } - APP_LOGI("AbilityThread::HandleAbilityTransaction abilityImpl_->SetCallingContext"); + APP_LOGI("AbilityThread::HandleAbilityTransaction before abilityImpl_->SetCallingContext"); abilityImpl_->SetCallingContext(lifeCycleStateInfo.caller.deviceId, lifeCycleStateInfo.caller.bundleName, lifeCycleStateInfo.caller.abilityName); - APP_LOGI("AbilityThread::HandleAbilityTransaction abilityImpl_->HandleAbilityTransaction"); + APP_LOGI("AbilityThread::HandleAbilityTransaction after abilityImpl_->SetCallingContext"); + APP_LOGI("AbilityThread::HandleAbilityTransaction before abilityImpl_->HandleAbilityTransaction"); abilityImpl_->HandleAbilityTransaction(want, lifeCycleStateInfo); + APP_LOGI("AbilityThread::HandleAbilityTransaction after abilityImpl_->HandleAbilityTransaction"); APP_LOGI("AbilityThread::HandleAbilityTransaction end"); } @@ -1497,4 +1499,4 @@ std::shared_ptr AbilityThread::BuildAbilityConte return abilityContextImpl; } } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/ability/native/src/data_ability_helper.cpp b/frameworks/kits/ability/native/src/data_ability_helper.cpp index 89ad38d58a3..4d1d99882b8 100644 --- a/frameworks/kits/ability/native/src/data_ability_helper.cpp +++ b/frameworks/kits/ability/native/src/data_ability_helper.cpp @@ -289,7 +289,7 @@ bool DataAbilityHelper::Release() APP_LOGI("DataAbilityHelper::Release before ReleaseDataAbility."); int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy_, token_); if (err != ERR_OK) { - APP_LOGE("DataAbilityHelper::GetFileTypes failed to ReleaseDataAbility err = %{public}d", err); + APP_LOGE("DataAbilityHelper::Release failed to ReleaseDataAbility err = %{public}d", err); return false; } APP_LOGI("DataAbilityHelper::Release after ReleaseDataAbility."); @@ -926,9 +926,14 @@ void DataAbilityHelper::UnregisterObserver(const Uri &uri, const sptrScheduleUnregisterObserver(uri, dataObserver); - int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy, token_); - if (err != ERR_OK) { - APP_LOGE("DataAbilityHelper::UnregisterObserver failed to ReleaseDataAbility err = %{public}d", err); + if (uri_ == nullptr) { + APP_LOGI("DataAbilityHelper::UnregisterObserver before ReleaseDataAbility."); + int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy_, token_); + APP_LOGI("DataAbilityHelper::UnregisterObserver after ReleaseDataAbility."); + if (err != ERR_OK) { + APP_LOGE("DataAbilityHelper::UnregisterObserver failed to ReleaseDataAbility err = %{public}d", err); + } + dataAbilityProxy_ = nullptr; } registerMap_.erase(dataObserver); uriMap_.erase(dataObserver); diff --git a/frameworks/kits/ability/native/src/js_service_extension_context.cpp b/frameworks/kits/ability/native/src/js_service_extension_context.cpp index 940ef133613..8786829e243 100755 --- a/frameworks/kits/ability/native/src/js_service_extension_context.cpp +++ b/frameworks/kits/ability/native/src/js_service_extension_context.cpp @@ -264,9 +264,13 @@ private: return; } HILOG_INFO("context->DisconnectAbility"); - auto errcode = context->DisconnectAbility(want, connection); - errcode == 0 ? task.Resolve(engine, engine.CreateUndefined()) : + context->DisconnectAbility(want, connection); + /* auto errcode = context->DisconnectAbility(want, connection); + if (errcode == 0) { + task.Resolve(engine, engine.CreateUndefined()); + } else { task.Reject(engine, CreateJsError(engine, errcode, "Disconnect Ability failed.")); + } */ }; NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; diff --git a/frameworks/kits/ability/native/src/new_ability_impl.cpp b/frameworks/kits/ability/native/src/new_ability_impl.cpp index 4ef0b322829..ccb869ee2c4 100644 --- a/frameworks/kits/ability/native/src/new_ability_impl.cpp +++ b/frameworks/kits/ability/native/src/new_ability_impl.cpp @@ -99,4 +99,4 @@ bool NewAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycle return ret; } } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context.h b/frameworks/kits/appkit/native/ability_runtime/context/context.h old mode 100755 new mode 100644 index c2ae9a9b18a..c7ea7287462 --- a/frameworks/kits/appkit/native/ability_runtime/context/context.h +++ b/frameworks/kits/appkit/native/ability_runtime/context/context.h @@ -137,13 +137,6 @@ public: */ virtual std::string GetDistributedFilesDir() = 0; - /** - * @brief Switch file area - * - * @param mode file area. - */ - virtual void SwitchArea(int mode) = 0; - /** * @brief Getting derived class * diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp old mode 100755 new mode 100644 index 9654f279e15..92a2057121c --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp @@ -26,23 +26,22 @@ namespace OHOS { namespace AbilityRuntime { const size_t Context::CONTEXT_TYPE_ID(std::hash {} ("Context")); const int64_t ContextImpl::CONTEXT_CREATE_BY_SYSTEM_APP(0x00000001); -const std::string ContextImpl::CONTEXT_DATA_APP("/data/app/"); +const std::string ContextImpl::CONTEXT_BUNDLECODE_BASE("/data/app/base/"); +const std::string ContextImpl::CONTEXT_BUNDLECODE("/data/storage/app/base"); const std::string ContextImpl::CONTEXT_BUNDLE("/bundle/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE("/mnt/hmdfs/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE("/device_view/local/data/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES("distributedfiles"); const std::string ContextImpl::CONTEXT_FILE_SEPARATOR("/"); const std::string ContextImpl::CONTEXT_DATA("/data/"); -const std::string ContextImpl::CONTEXT_DATA_STORAGE("/data/storage/"); -const std::string ContextImpl::CONTEXT_BASE("base"); +const std::string ContextImpl::CONTEXT_BASE("/data/storage/"); const std::string ContextImpl::CONTEXT_PRIVATE("/private/"); const std::string ContextImpl::CONTEXT_CACHES("caches"); const std::string ContextImpl::CONTEXT_STORAGE("storage"); const std::string ContextImpl::CONTEXT_DATABASE("database"); const std::string ContextImpl::CONTEXT_TEMP("/temp"); const std::string ContextImpl::CONTEXT_FILES("/files"); -const std::string ContextImpl::CONTEXT_HAPS("/haps"); -const std::string ContextImpl::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"}; +const std::string ContextImpl::CONTEXT_CE("ce"); std::string ContextImpl::GetBundleName() const { @@ -56,9 +55,9 @@ std::string ContextImpl::GetBundleCodeDir() { std::string dir; if (IsCreateBySystemApp()) { - dir = CONTEXT_DATA_APP + CONTEXT_ELS[0] + CONTEXT_BUNDLE + GetBundleName(); + dir = CONTEXT_BUNDLECODE_BASE + GetBundleName(); } else { - dir = CONTEXT_DATA_STORAGE + CONTEXT_ELS[0] + CONTEXT_BUNDLE; + dir = CONTEXT_BUNDLECODE; } HILOG_DEBUG("ContextImpl::GetBundleCodeDir:%{public}s", dir.c_str()); return dir; @@ -73,14 +72,7 @@ std::string ContextImpl::GetCacheDir() std::string ContextImpl::GetDatabaseDir() { - std::string dir; - if (IsCreateBySystemApp()) { - dir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + CONTEXT_FILE_SEPARATOR + - CONTEXT_DATABASE + GetBundleName(); - } else { - dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DATABASE; - } - dir = dir + CONTEXT_FILE_SEPARATOR + ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); + std::string dir = GetBaseDir() + CONTEXT_PRIVATE + CONTEXT_DATABASE; HILOG_DEBUG("ContextImpl::GetDatabaseDir:%{public}s", dir.c_str()); return dir; } @@ -114,36 +106,23 @@ std::string ContextImpl::GetDistributedFilesDir() dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + GetCurrentAccountId() + CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE + GetBundleName(); } else { - dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTEDFILES + - CONTEXT_FILE_SEPARATOR + ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); + dir = CONTEXT_BASE + CONTEXT_DISTRIBUTEDFILES; } HILOG_DEBUG("ContextImpl::GetDistributedFilesDir:%{public}s", dir.c_str()); return dir; } -void ContextImpl::SwitchArea(int mode) -{ - HILOG_DEBUG("ContextImpl::SwitchArea, mode:%{public}d.", mode); - if (mode < 0 || mode >= (sizeof(CONTEXT_ELS) / sizeof(CONTEXT_ELS[0]))) { - HILOG_ERROR("ContextImpl::SwitchArea, mode is invalid."); - return; - } - currArea_ = CONTEXT_ELS[mode]; - HILOG_DEBUG("ContextImpl::SwitchArea end, currArea:%{public}s.", currArea_.c_str()); -} - std::string ContextImpl::GetBaseDir() const { std::string baseDir; if (IsCreateBySystemApp()) { - baseDir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + - CONTEXT_FILE_SEPARATOR + CONTEXT_BASE + CONTEXT_FILE_SEPARATOR + GetBundleName(); + baseDir = CONTEXT_DATA + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + + CONTEXT_BUNDLE + GetBundleName(); } else { - baseDir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE; + baseDir = CONTEXT_BASE + currArea_; } if (parentContext_ != nullptr) { - baseDir = baseDir + CONTEXT_HAPS + CONTEXT_FILE_SEPARATOR + - ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); + baseDir = baseDir + CONTEXT_FILE_SEPARATOR + GetHapModuleInfo()->moduleName; } HILOG_DEBUG("ContextImpl::GetBaseDir:%{public}s", baseDir.c_str()); @@ -321,9 +300,6 @@ void ContextImpl::InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleIn std::shared_ptr ContextImpl::GetHapModuleInfo() const { - if (hapModuleInfo_ == nullptr) { - HILOG_ERROR("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty"); - } return hapModuleInfo_; } @@ -352,4 +328,4 @@ void ContextImpl::InitAppContext() Context::appContext_ = shared_from_this(); } } // namespace AbilityRuntime -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h old mode 100755 new mode 100644 index 4658e7fb5a2..db19e2c8348 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h @@ -87,13 +87,6 @@ public: */ std::string GetDistributedFilesDir() override; - /** - * @brief Switch file area - * - * @param mode file area. - */ - void SwitchArea(int mode) override; - /** * @brief set the ResourceManager. * @@ -182,15 +175,14 @@ public: */ void InitAppContext(); private: - static const int64_t CONTEXT_CREATE_BY_SYSTEM_APP; - static const std::string CONTEXT_DATA_APP; + static const std::string CONTEXT_BUNDLECODE_BASE; + static const std::string CONTEXT_BUNDLECODE; static const std::string CONTEXT_BUNDLE; static const std::string CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE; static const std::string CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE; static const std::string CONTEXT_DISTRIBUTEDFILES; static const std::string CONTEXT_FILE_SEPARATOR; static const std::string CONTEXT_DATA; - static const std::string CONTEXT_DATA_STORAGE; static const std::string CONTEXT_BASE; static const std::string CONTEXT_PRIVATE; static const std::string CONTEXT_CACHES; @@ -198,9 +190,8 @@ private: static const std::string CONTEXT_DATABASE; static const std::string CONTEXT_TEMP; static const std::string CONTEXT_FILES; - static const std::string CONTEXT_HAPS; - static const std::string CONTEXT_ELS[]; - static const int EL_DEFAULT = 1; + static const std::string CONTEXT_CE; + static const int64_t CONTEXT_CREATE_BY_SYSTEM_APP; int flags_ = 0x00000000; void InitResourceManager( @@ -214,8 +205,8 @@ private: std::shared_ptr parentContext_ = nullptr; std::shared_ptr resourceManager_ = nullptr; std::shared_ptr hapModuleInfo_ = nullptr; - std::string currArea_ = CONTEXT_ELS[EL_DEFAULT]; + std::string currArea_ = CONTEXT_CE; }; } // namespace AbilityRuntime } // namespace OHOS -#endif // ABILITY_RUNTIME_CONTEXT_IMPL_H \ No newline at end of file +#endif // ABILITY_RUNTIME_CONTEXT_IMPL_H diff --git a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp old mode 100755 new mode 100644 index 08c265d7c6f..6ee66fa1059 --- a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp @@ -34,7 +34,6 @@ public: static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* CreateBundleContext(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetApplicationContext(NativeEngine* engine, NativeCallbackInfo* info); - static NativeValue* SwitchArea(NativeEngine* engine, NativeCallbackInfo* info); void KeepContext(std::shared_ptr context) { @@ -44,7 +43,6 @@ public: private: NativeValue* OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); - NativeValue* OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info); std::shared_ptr keepContext_; @@ -70,47 +68,6 @@ NativeValue* JsBaseContext::GetApplicationContext(NativeEngine* engine, NativeCa return me != nullptr ? me->OnGetApplicationContext(*engine, *info) : nullptr; } -NativeValue* JsBaseContext::SwitchArea(NativeEngine* engine, NativeCallbackInfo* info) -{ - HILOG_INFO("JsBaseContext::SwitchArea is called"); - JsBaseContext* me = CheckParamsAndGetThis(engine, info, BASE_CONTEXT_NAME); - return me != nullptr ? me->OnSwitchArea(*engine, *info) : nullptr; -} - -NativeValue* JsBaseContext::OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info) -{ - if (info.argc == 0) { - HILOG_ERROR("Not enough params"); - return engine.CreateUndefined(); - } - - auto context = context_.lock(); - if (!context) { - HILOG_WARN("context is already released"); - return engine.CreateUndefined(); - } - - int mode; - if (!ConvertFromJsValue(engine, info.argv[0], mode)) { - HILOG_ERROR("Parse mode failed"); - return engine.CreateUndefined(); - } - - context->SwitchArea(mode); - - NativeValue* thisVar = info.thisVar; - NativeObject* object = ConvertNativeValueTo(thisVar); - object->SetProperty("cacheDir", CreateJsValue(engine, context->GetCacheDir())); - object->SetProperty("tempDir", CreateJsValue(engine, context->GetTempDir())); - object->SetProperty("filesDir", CreateJsValue(engine, context->GetFilesDir())); - object->SetProperty("distributedFilesDir", CreateJsValue(engine, context->GetDistributedFilesDir())); - object->SetProperty("databaseDir", CreateJsValue(engine, context->GetDatabaseDir())); - object->SetProperty("storageDir", CreateJsValue(engine, context->GetStorageDir())); - object->SetProperty("bundleCodeDir", CreateJsValue(engine, context->GetBundleCodeDir())); - - return engine.CreateUndefined(); -} - NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info) { if (info.argc == 0) { @@ -194,7 +151,6 @@ NativeValue* CreateJsBaseContext(NativeEngine& engine, std::shared_ptr BindNativeFunction(engine, *object, "createBundleContext", JsBaseContext::CreateBundleContext); BindNativeFunction(engine, *object, "getApplicationContext", JsBaseContext::GetApplicationContext); - BindNativeFunction(engine, *object, "switchArea", JsBaseContext::SwitchArea); return objValue; } diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 23ad30a9702..7fb1e561bee 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -193,6 +193,7 @@ bool MainThread::ConnectToAppMgr() APP_LOGI("MainThread::connectToAppMgr before AttachApplication"); appMgr_->AttachApplication(this); APP_LOGI("MainThread::connectToAppMgr after AttachApplication"); + APP_LOGI("MainThread::connectToAppMgr end"); return true; } @@ -1184,7 +1185,7 @@ void MainThread::Start() APP_LOGI("MainThread::main called start"); std::shared_ptr runner = EventRunner::GetMainEventRunner(); if (runner == nullptr) { - APP_LOGE("MainThread::main failed, runner is nullptr"); + APP_LOGE("MainThread::main called start"); return; } std::shared_ptr runnerWatchDog = EventRunner::Create("WatchDogRunner"); diff --git a/interfaces/kits/napi/aafwk/app/context/context.js b/interfaces/kits/napi/aafwk/app/context/context.js old mode 100755 new mode 100644 index 88f512579d9..d28e3283fd0 --- a/interfaces/kits/napi/aafwk/app/context/context.js +++ b/interfaces/kits/napi/aafwk/app/context/context.js @@ -16,55 +16,24 @@ class Context { constructor(obj) { this.__context_impl__ = obj + + this.resourceManager = obj.resourceManager + this.applicationInfo = obj.applicationInfo + this.cacheDir = obj.cacheDir + this.tempDir = obj.tempDir + this.filesDir = obj.filesDir + this.distributedFilesDir = obj.distributedFilesDir + this.databaseDir = obj.databaseDir + this.storageDir = obj.storageDir + this.bundleCodeDir = obj.bundleCodeDir } createBundleContext(bundleName) { return this.__context_impl__.createBundleContext(bundleName) } - getApplicationContext() { return this.__context_impl__.getApplicationContext() } - - switchArea(mode) { - return this.__context_impl__.switchArea(mode) - } - - get resourceManager() { - return this.__context_impl__.resourceManager - } - - get applicationInfo() { - return this.__context_impl__.applicationInfo - } - - get cacheDir() { - return this.__context_impl__.cacheDir - } - - get tempDir() { - return this.__context_impl__.tempDir - } - - get filesDir() { - return this.__context_impl__.filesDir - } - - get distributedFilesDir() { - return this.__context_impl__.distributedFilesDir - } - - get databaseDir() { - return this.__context_impl__.databaseDir - } - - get storageDir() { - return this.__context_impl__.storageDir - } - - get bundleCodeDir() { - return this.__context_impl__.bundleCodeDir - } } export default Context diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index 686d0b826ba..8e57a49036a 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -208,7 +208,6 @@ napi_value InsertWrap(napi_env env, napi_callback_info info, DAHelperInsertCB *i HILOG_INFO("%{public}s,uri=%{public}s", __func__, insertCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; } insertCB->valueBucket.Clear(); @@ -347,8 +346,12 @@ void InsertExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Insert, worker pool thread execute."); DAHelperInsertCB *insertCB = static_cast(data); if (insertCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(insertCB->uri); - insertCB->result = insertCB->dataAbilityHelper->Insert(uri, insertCB->valueBucket); + insertCB->execResult = INVALID_PARAMETER; + if (!insertCB->uri.empty()) { + OHOS::Uri uri(insertCB->uri); + insertCB->result = insertCB->dataAbilityHelper->Insert(uri, insertCB->valueBucket); + insertCB->execResult = NO_ERROR; + } } else { HILOG_ERROR("NAPI_Insert, dataAbilityHelper == nullptr."); } @@ -366,7 +369,7 @@ void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, insertCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, insertCB->execResult); napi_create_int32(env, insertCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -470,7 +473,6 @@ napi_value NAPI_NotifyChange(napi_env env, napi_callback_info info) */ napi_value NotifyChangeWrap(napi_env env, napi_callback_info info, DAHelperNotifyChangeCB *notifyChangeCB) { - HILOG_INFO("%{public}s,called", __func__); size_t argcAsync = ARGS_TWO; const size_t argcPromise = ARGS_ONE; @@ -492,7 +494,6 @@ napi_value NotifyChangeWrap(napi_env env, napi_callback_info info, DAHelperNotif HILOG_INFO("%{public}s,uri=%{public}s", __func__, notifyChangeCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; } DataAbilityHelper *objectInfo = nullptr; @@ -570,8 +571,14 @@ void NotifyChangeExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_NotifyChange, worker pool thread execute."); DAHelperNotifyChangeCB *notifyChangeCB = static_cast(data); if (notifyChangeCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(notifyChangeCB->uri); - notifyChangeCB->dataAbilityHelper->NotifyChange(uri); + notifyChangeCB->execResult = INVALID_PARAMETER; + if (!notifyChangeCB->uri.empty()) { + OHOS::Uri uri(notifyChangeCB->uri); + notifyChangeCB->dataAbilityHelper->NotifyChange(uri); + notifyChangeCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("%{public}s, notifyChangeCB uri is empty.", __func__); + } } } @@ -593,7 +600,7 @@ void NotifyChangeAsyncCompleteCB(napi_env env, napi_status status, void *data) return; } - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, notifyChangeCB->execResult); result[PARAM1] = WrapVoidToJS(env); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -675,17 +682,20 @@ napi_value RegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB * return nullptr; } + onCB->result = NO_ERROR; napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { std::string type = NapiValueToStringUtf8(env, args[PARAM0]); - if (type != "dataChange") { - HILOG_ERROR("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); - return nullptr; + if (type == "dataChange") { + HILOG_INFO("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); + } else { + HILOG_ERROR("%{public}s, Wrong argument type is %{public}s.", __func__, type.c_str()); + onCB->result = INVALID_PARAMETER; } } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; + onCB->result = INVALID_PARAMETER; } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); @@ -694,7 +704,7 @@ napi_value RegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB * HILOG_INFO("%{public}s,uri=%{public}s", __func__, onCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; + onCB->result = INVALID_PARAMETER; } DataAbilityHelper *objectInfo = nullptr; @@ -724,6 +734,7 @@ napi_value RegisterAsync( NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &onCB->cbBase.cbInfo.callback)); } else { HILOG_INFO("not valuetype isn't napi_function"); + onCB->result = INVALID_PARAMETER; } sptr observer(new (std::nothrow) NAPIDataAbilityObserver()); @@ -731,7 +742,9 @@ napi_value RegisterAsync( observer->SetCallbackRef(onCB->cbBase.cbInfo.callback); onCB->observer = observer; - registerInstances_.emplace_back(onCB); + if (onCB->result == NO_ERROR) { + registerInstances_.emplace_back(onCB); + } NAPI_CALL(env, napi_create_async_work( @@ -739,9 +752,7 @@ napi_value RegisterAsync( nullptr, resourceName, RegisterExecuteCB, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_Register, main event thread complete."); - }, + RegisterCompleteCB, (void *)onCB, &onCB->cbBase.asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, onCB->cbBase.asyncWork)); @@ -755,9 +766,31 @@ void RegisterExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Register, worker pool thread execute."); DAHelperOnOffCB *onCB = static_cast(data); if (onCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(onCB->uri); - onCB->dataAbilityHelper->RegisterObserver(uri, onCB->observer); + if (onCB->result != INVALID_PARAMETER && !onCB->uri.empty() && onCB->cbBase.cbInfo.callback != nullptr) { + OHOS::Uri uri(onCB->uri); + onCB->dataAbilityHelper->RegisterObserver(uri, onCB->observer); + } else { + HILOG_ERROR("%{public}s, dataAbilityHelper uri is empty or callback is nullptr.", __func__); + } + } +} + +void RegisterCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_Register, main event thread complete."); + DAHelperOnOffCB *onCB = static_cast(data); + if (onCB == nullptr) { + HILOG_ERROR("%{public}s, input params onCB is nullptr.", __func__); + return; } + if (onCB->result == NO_ERROR) { + return; + } + HILOG_INFO("NAPI_Register, input params onCB is invalid params, will be release"); + onCB->observer->ReleaseJSCallback(); + delete onCB; + onCB = nullptr; + HILOG_INFO("NAPI_Register, main event thread complete over an release invalid onCB."); } /** @@ -818,17 +851,20 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB return nullptr; } + offCB->result = NO_ERROR; napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { std::string type = NapiValueToStringUtf8(env, args[PARAM0]); - if (type != "dataChange") { - HILOG_ERROR("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); - return nullptr; + if (type == "dataChange") { + HILOG_INFO("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); + } else { + HILOG_ERROR("%{public}s, Wrong argument type %{public}s.", __func__, type.c_str()); + offCB->result = INVALID_PARAMETER; } } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; + offCB->result = INVALID_PARAMETER; } offCB->uri = ""; @@ -840,11 +876,14 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB HILOG_INFO("%{public}s,uri=%{public}s", __func__, offCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; + offCB->result = INVALID_PARAMETER; } NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); if (valuetype == napi_function) { NAPI_CALL(env, napi_create_reference(env, args[PARAM2], 1, &offCB->cbBase.cbInfo.callback)); + } else { + HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + offCB->result = INVALID_PARAMETER; } } else { // parse uri or callback @@ -856,7 +895,7 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &offCB->cbBase.cbInfo.callback)); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; + offCB->result = INVALID_PARAMETER; } } @@ -880,7 +919,9 @@ napi_value UnRegisterAsync( napi_value resourceName = 0; NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - FindRegisterObs(env, offCB); + if (offCB->result == NO_ERROR) { + FindRegisterObs(env, offCB); + } NAPI_CALL(env, napi_create_async_work( @@ -1178,9 +1219,11 @@ static void OnChangeJSThreadWorker(uv_work_t *work, int status) void NAPIDataAbilityObserver::OnChange() { - HILOG_INFO("%{public}s, called.", __func__); + if (ref_ == nullptr) { + HILOG_ERROR("%{public}s, OnChange ref is nullptr.", __func__); + return; + } ChangeWorkPre(); - uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { @@ -1188,14 +1231,12 @@ void NAPIDataAbilityObserver::OnChange() ChangeWorkPreDone(); return; } - uv_work_t *work = new uv_work_t; if (work == nullptr) { HILOG_ERROR("%{public}s, work==nullptr.", __func__); ChangeWorkPreDone(); return; } - DAHelperOnOffCB *onCB = new (std::nothrow) DAHelperOnOffCB; if (onCB == nullptr) { HILOG_ERROR("%{public}s, onCB == nullptr.", __func__); @@ -1210,7 +1251,6 @@ void NAPIDataAbilityObserver::OnChange() onCB->cbBase.cbInfo.callback = ref_; onCB->observer = this; work->data = (void *)onCB; - int rev = uv_queue_work( loop, work, @@ -1278,7 +1318,6 @@ napi_value GetTypeWrap(napi_env env, napi_callback_info info, DAHelperGetTypeCB HILOG_INFO("%{public}s,uri=%{public}s", __func__, gettypeCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; } DataAbilityHelper *objectInfo = nullptr; @@ -1358,8 +1397,14 @@ void GetTypeExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_GetType, worker pool thread execute."); DAHelperGetTypeCB *gettypeCB = static_cast(data); if (gettypeCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(gettypeCB->uri); - gettypeCB->result = gettypeCB->dataAbilityHelper->GetType(uri); + gettypeCB->execResult = INVALID_PARAMETER; + if (!gettypeCB->uri.empty()) { + OHOS::Uri uri(gettypeCB->uri); + gettypeCB->result = gettypeCB->dataAbilityHelper->GetType(uri); + gettypeCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_GetType, dataAbilityHelper uri is empty."); + } } else { HILOG_ERROR("NAPI_GetType, dataAbilityHelper == nullptr."); } @@ -1377,7 +1422,7 @@ void GetTypeAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, gettypeCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, gettypeCB->execResult); napi_create_string_utf8(env, gettypeCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -1536,10 +1581,18 @@ void GetFileTypesExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_GetFileTypes, worker pool thread execute."); DAHelperGetFileTypesCB *getfiletypesCB = static_cast(data); if (getfiletypesCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(getfiletypesCB->uri); - HILOG_INFO("NAPI_GetFileTypes, uri:%{public}s", uri.ToString().c_str()); - HILOG_INFO("NAPI_GetFileTypes, mimeTypeFilter:%{public}s", getfiletypesCB->mimeTypeFilter.c_str()); - getfiletypesCB->result = getfiletypesCB->dataAbilityHelper->GetFileTypes(uri, getfiletypesCB->mimeTypeFilter); + getfiletypesCB->execResult = INVALID_PARAMETER; + if (!getfiletypesCB->uri.empty()) { + OHOS::Uri uri(getfiletypesCB->uri); + HILOG_INFO("NAPI_GetFileTypes, uri:%{public}s", uri.ToString().c_str()); + HILOG_INFO("NAPI_GetFileTypes, mimeTypeFilter:%{public}s", getfiletypesCB->mimeTypeFilter.c_str()); + getfiletypesCB->result = getfiletypesCB->dataAbilityHelper->GetFileTypes( + uri, + getfiletypesCB->mimeTypeFilter); + getfiletypesCB->execResult = NO_ERROR; + } else { + HILOG_INFO("NAPI_GetFileTypes, dataAbilityHelper uri is empty."); + } } else { HILOG_INFO("NAPI_GetFileTypes, dataAbilityHelper == nullptr."); } @@ -1558,7 +1611,7 @@ void GetFileTypesAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, getfiletypesCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, getfiletypesCB->execResult); result[PARAM1] = WrapGetFileTypesCB(env, *getfiletypesCB); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -1733,9 +1786,13 @@ void NormalizeUriExecuteCB(napi_env env, void *data) DAHelperNormalizeUriCB *normalizeuriCB = static_cast(data); Uri uriValue(normalizeuriCB->uri); if (normalizeuriCB->dataAbilityHelper != nullptr) { + normalizeuriCB->execResult = INVALID_PARAMETER; + if (!normalizeuriCB->uri.empty()) { OHOS::Uri uri(normalizeuriCB->uri); - uriValue = normalizeuriCB->dataAbilityHelper->NormalizeUri(uri); - normalizeuriCB->result = uriValue.ToString(); + uriValue = normalizeuriCB->dataAbilityHelper->NormalizeUri(uri); + normalizeuriCB->result = uriValue.ToString(); + normalizeuriCB->execResult = NO_ERROR; + } } else { HILOG_INFO("NAPI_NormalizeUri, dataAbilityHelper == nullptr"); } @@ -1753,7 +1810,7 @@ void NormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, normalizeuriCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, normalizeuriCB->execResult); NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, normalizeuriCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); @@ -1908,9 +1965,15 @@ void DenormalizeUriExecuteCB(napi_env env, void *data) DAHelperDenormalizeUriCB *denormalizeuriCB = static_cast(data); Uri uriValue(denormalizeuriCB->uri); if (denormalizeuriCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(denormalizeuriCB->uri); - uriValue = denormalizeuriCB->dataAbilityHelper->DenormalizeUri(uri); - denormalizeuriCB->result = uriValue.ToString(); + denormalizeuriCB->execResult = INVALID_PARAMETER; + if (!denormalizeuriCB->uri.empty()) { + OHOS::Uri uri(denormalizeuriCB->uri); + uriValue = denormalizeuriCB->dataAbilityHelper->DenormalizeUri(uri); + denormalizeuriCB->result = uriValue.ToString(); + denormalizeuriCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_DenormalizeUri, dataAbilityHelper uri is empty"); + } } else { HILOG_ERROR("NAPI_DenormalizeUri, dataAbilityHelper == nullptr"); } @@ -1928,7 +1991,7 @@ void DenormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, denormalizeuriCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, denormalizeuriCB->execResult); NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, denormalizeuriCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); @@ -2110,8 +2173,14 @@ void DeleteExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Delete, worker pool thread execute."); DAHelperDeleteCB *deleteCB = static_cast(data); if (deleteCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(deleteCB->uri); - deleteCB->result = deleteCB->dataAbilityHelper->Delete(uri, deleteCB->predicates); + deleteCB->execResult = INVALID_PARAMETER; + if (!deleteCB->uri.empty()) { + OHOS::Uri uri(deleteCB->uri); + deleteCB->result = deleteCB->dataAbilityHelper->Delete(uri, deleteCB->predicates); + deleteCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_Delete, dataAbilityHelper uri is empty"); + } } else { HILOG_ERROR("NAPI_Delete, dataAbilityHelper == nullptr"); } @@ -2129,7 +2198,7 @@ void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, DeleteCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, DeleteCB->execResult); napi_create_int32(env, DeleteCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2300,8 +2369,14 @@ void UpdateExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Update, worker pool thread execute."); DAHelperUpdateCB *updateCB = static_cast(data); if (updateCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(updateCB->uri); - updateCB->result = updateCB->dataAbilityHelper->Update(uri, updateCB->valueBucket, updateCB->predicates); + updateCB->execResult = INVALID_PARAMETER; + if (!updateCB->uri.empty()) { + OHOS::Uri uri(updateCB->uri); + updateCB->result = updateCB->dataAbilityHelper->Update(uri, updateCB->valueBucket, updateCB->predicates); + updateCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_Update, dataAbilityHelper uri is empty"); + } } else { HILOG_ERROR("NAPI_Update, dataAbilityHelper == nullptr"); } @@ -2319,7 +2394,7 @@ void UpdateAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, updateCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, updateCB->execResult); napi_create_int32(env, updateCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2493,8 +2568,14 @@ void OpenFileExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_OpenFile, worker pool thread execute."); DAHelperOpenFileCB *OpenFileCB = static_cast(data); if (OpenFileCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(OpenFileCB->uri); - OpenFileCB->result = OpenFileCB->dataAbilityHelper->OpenFile(uri, OpenFileCB->mode); + OpenFileCB->execResult = INVALID_PARAMETER; + if (!OpenFileCB->uri.empty()) { + OHOS::Uri uri(OpenFileCB->uri); + OpenFileCB->result = OpenFileCB->dataAbilityHelper->OpenFile(uri, OpenFileCB->mode); + OpenFileCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_OpenFile, dataAbilityHelper uri is empty"); + } } else { HILOG_ERROR("NAPI_OpenFile, dataAbilityHelper == nullptr"); } @@ -2512,7 +2593,7 @@ void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, OpenFileCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, OpenFileCB->execResult); napi_create_int32(env, OpenFileCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2721,8 +2802,14 @@ void BatchInsertExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_BatchInsert, worker pool thread execute."); DAHelperBatchInsertCB *batchInsertCB = static_cast(data); if (batchInsertCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(batchInsertCB->uri); - batchInsertCB->result = batchInsertCB->dataAbilityHelper->BatchInsert(uri, batchInsertCB->values); + batchInsertCB->execResult = INVALID_PARAMETER; + if (!batchInsertCB->uri.empty()) { + OHOS::Uri uri(batchInsertCB->uri); + batchInsertCB->result = batchInsertCB->dataAbilityHelper->BatchInsert(uri, batchInsertCB->values); + batchInsertCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("NAPI_BatchInsert, dataAbilityHelper uri is empyt"); + } } else { HILOG_ERROR("NAPI_BatchInsert, dataAbilityHelper == nullptr"); } @@ -2740,7 +2827,7 @@ void BatchInsertAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, BatchInsertCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, BatchInsertCB->execResult); napi_create_int32(env, BatchInsertCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2836,7 +2923,6 @@ napi_value QueryWrap(napi_env env, napi_callback_info info, DAHelperQueryCB *que arrayStringbool = NapiValueToArrayStringUtf8(env, args[PARAM1], result); if (arrayStringbool == false) { HILOG_ERROR("%{public}s, The return value of arraystringbool is false", __func__); - return nullptr; } queryCB->columns = result; for (size_t i = 0; i < queryCB->columns.size(); i++) { @@ -2934,12 +3020,18 @@ void QueryExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Query, worker pool thread execute."); DAHelperQueryCB *queryCB = static_cast(data); if (queryCB->dataAbilityHelper != nullptr) { - OHOS::Uri uri(queryCB->uri); - auto resultset = queryCB->dataAbilityHelper->Query(uri, queryCB->columns, queryCB->predicates); - if (resultset != nullptr) { - queryCB->result = resultset; + queryCB->execResult = INVALID_PARAMETER; + if (!queryCB->uri.empty()) { + OHOS::Uri uri(queryCB->uri); + auto resultset = queryCB->dataAbilityHelper->Query(uri, queryCB->columns, queryCB->predicates); + if (resultset != nullptr) { + queryCB->result = resultset; + queryCB->execResult = NO_ERROR; + } else { + HILOG_INFO("NAPI_Query, resultset == nullptr."); + } } else { - HILOG_INFO("NAPI_Query, resultset == nullptr."); + HILOG_ERROR("NAPI_Query, dataAbilityHelper uri is empty"); } } else { HILOG_ERROR("NAPI_Query, dataAbilityHelper == nullptr"); @@ -2958,7 +3050,7 @@ void QueryAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, queryCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(env, queryCB->execResult); result[PARAM1] = WrapResultSet(env, queryCB->result); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -3011,8 +3103,8 @@ napi_value NAPI_Release(napi_env env, napi_callback_info info) napi_value ReleaseWrap(napi_env env, napi_callback_info info, DAHelperReleaseCB *releaseCB) { HILOG_INFO("%{public}s,called", __func__); - size_t argcAsync = ARGS_TWO; - const size_t argcPromise = ARGS_ONE; + size_t argcAsync = ARGS_ONE; + const size_t argcPromise = ARGS_ZERO; const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; napi_value args[ARGS_MAX_COUNT] = {nullptr}; napi_value ret = nullptr; @@ -3030,7 +3122,7 @@ napi_value ReleaseWrap(napi_env env, napi_callback_info info, DAHelperReleaseCB releaseCB->dataAbilityHelper = objectInfo; if (argcAsync > argcPromise) { - ret = ReleaseAsync(env, args, ARGS_ONE, releaseCB); + ret = ReleaseAsync(env, args, PARAM0, releaseCB); } else { ret = ReleasePromise(env, releaseCB); } @@ -3222,7 +3314,6 @@ napi_value ExecuteBatchWrap(napi_env env, napi_callback_info info, DAHelperExecu HILOG_INFO("%{public}s,uri=%{public}s", __func__, executeBatchCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; } std::vector> operations; @@ -3382,6 +3473,5 @@ void GetDataAbilityResultForResult( } HILOG_INFO("%{public}s, NAPI_ExecuteBatch, getDataAbilityResultForResult end.", __func__); } - } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h index b6d469cae42..f759e1126c3 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h @@ -233,6 +233,7 @@ napi_value RegisterAsync( * @param data Point to asynchronous processing of data. */ void RegisterExecuteCB(napi_env env, void *data); +void RegisterCompleteCB(napi_env env, napi_status status, void *data); /** * @brief DataAbilityHelper NAPI method : off. diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h index 490ed709a47..004dfa0e9a7 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h @@ -219,6 +219,7 @@ struct DAHelperInsertCB { std::string uri; NativeRdb::ValuesBucket valueBucket; int result = 0; + int execResult; }; class NAPIAbilityConnection; @@ -243,6 +244,7 @@ struct DAHelperNotifyChangeCB { CBBase cbBase; DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; + int execResult; }; class NAPIDataAbilityObserver; @@ -277,6 +279,7 @@ struct DAHelperGetTypeCB { DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; + int execResult; }; struct DAHelperGetFileTypesCB { @@ -285,6 +288,7 @@ struct DAHelperGetFileTypesCB { std::string uri; std::string mimeTypeFilter; std::vector result; + int execResult; }; struct DAHelperNormalizeUriCB { @@ -292,12 +296,14 @@ struct DAHelperNormalizeUriCB { DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; + int execResult; }; struct DAHelperDenormalizeUriCB { CBBase cbBase; DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; + int execResult; }; struct DAHelperDeleteCB { @@ -306,6 +312,7 @@ struct DAHelperDeleteCB { std::string uri; NativeRdb::DataAbilityPredicates predicates; int result = 0; + int execResult; }; struct DAHelperQueryCB { @@ -315,6 +322,7 @@ struct DAHelperQueryCB { std::vector columns; NativeRdb::DataAbilityPredicates predicates; std::shared_ptr result; + int execResult; }; struct DAHelperUpdateCB { @@ -324,6 +332,7 @@ struct DAHelperUpdateCB { NativeRdb::ValuesBucket valueBucket; NativeRdb::DataAbilityPredicates predicates; int result = 0; + int execResult; }; struct DAHelperBatchInsertCB { CBBase cbBase; @@ -331,6 +340,7 @@ struct DAHelperBatchInsertCB { std::string uri; std::vector values; int result = 0; + int execResult; }; struct DAHelperOpenFileCB { CBBase cbBase; @@ -338,6 +348,7 @@ struct DAHelperOpenFileCB { std::string uri; std::string mode; int result = 0; + int execResult; }; struct DAHelperReleaseCB { diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp index a3da91d6624..5523120a439 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -2386,7 +2386,7 @@ void StartAbilityPromiseCompletedCB(napi_env env, napi_status status, void *data napi_value StartAbilityAsync( napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo) { - HILOG_INFO("%{public}s async call.", __func__); + HILOG_INFO("%{public}s asyncCallback.", __func__); if (args == nullptr || asyncCallbackInfo == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; @@ -2410,13 +2410,13 @@ napi_value StartAbilityAsync( &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - HILOG_INFO("%{public}s async end.", __func__); + HILOG_INFO("%{public}s asyncCallback end.", __func__); return WrapVoidToJS(env); } napi_value StartAbilityPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) { - HILOG_INFO("%{public}s promise call.", __func__); + HILOG_INFO("%{public}s, promise.", __func__); if (asyncCallbackInfo == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; @@ -2437,7 +2437,7 @@ napi_value StartAbilityPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInf (void *)asyncCallbackInfo, &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - HILOG_INFO("%{public}s promise end.", __func__); + HILOG_INFO("%{public}s, end.", __func__); return promise; } @@ -3449,7 +3449,17 @@ napi_value AcquireDataAbilityHelperWrap(napi_env env, napi_callback_info info, D NAPI_CALL(env, napi_new_instance(env, *(GetGlobalDataAbilityHelper()), 1, &args[PARAM0], &result)); if (!IsTypeForNapiValue(env, result, napi_object)) { - HILOG_ERROR("%{public}s, IsTypeForNapiValue retval is false", __func__); + HILOG_ERROR("%{public}s, IsTypeForNapiValue isn`t object", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_null)) { + HILOG_ERROR("%{public}s, IsTypeForNapiValue is null", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_undefined)) { + HILOG_ERROR("%{public}s, IsTypeForNapiValue is undefined", __func__); return nullptr; } diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h index 8ef50d7d2c8..ec8e4fa50b8 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h @@ -33,6 +33,7 @@ namespace AppExecFwk { #define ARGS_MAX_COUNT 10 #define ARGS_ASYNC_COUNT 1 +#define ARGS_ZERO 0 #define ARGS_ONE 1 #define ARGS_TWO 2 #define ARGS_THREE 3 diff --git a/services/abilitymgr/resource/ams_service_config.json b/services/abilitymgr/resource/ams_service_config.json index 23a25860d96..3eb6c45e883 100644 --- a/services/abilitymgr/resource/ams_service_config.json +++ b/services/abilitymgr/resource/ams_service_config.json @@ -7,7 +7,6 @@ "startup_phone_service" : true, "startup_contacts":true, "startup_mms":true, - "use_new_mission" : true, "mission_save_time" : 43200000, "root_launcher_restart_max":15 }, diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index fa18e945abc..a93b50e557b 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -360,11 +360,11 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, return INNER_ERR; } if (!data.WriteParcelable(token) || !data.WriteInt32(state)) { - HILOG_ERROR("token or state write failed."); + HILOG_ERROR("data write failed."); return INNER_ERR; } if (!data.WriteParcelable(&saveData)) { - HILOG_ERROR("saveData write failed."); + HILOG_ERROR("data write failed."); return INNER_ERR; } error = Remote()->SendRequest(IAbilityManager::ABILITY_TRANSITION_DONE, data, reply, option); @@ -2229,4 +2229,4 @@ bool AbilityManagerProxy::IsRunningInStabilityTest() return reply.ReadBool(); } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 1c3a4e3511b..1e2ecf9de5d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -231,9 +231,8 @@ int AbilityManagerService::StartAbility( const Want &want, const sptr &callerToken, int requestCode, int callerUid) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("%{public}s begin.", __func__); + HILOG_INFO("%{public}s", __func__); if (callerToken != nullptr && !VerificationToken(callerToken)) { - HILOG_ERROR("%{public}s VerificationToken failed.", __func__); return ERR_INVALID_VALUE; } AbilityRequest abilityRequest; @@ -249,44 +248,38 @@ int AbilityManagerService::StartAbility( return result; } auto type = abilityInfo.type; - HILOG_INFO("%{public}s Current ability type:%{public}d", __func__, type); if (type == AppExecFwk::AbilityType::DATA) { HILOG_ERROR("Cannot start data ability, use 'AcquireDataAbility()' instead."); return ERR_INVALID_VALUE; } if (!AbilityUtil::IsSystemDialogAbility(abilityInfo.bundleName, abilityInfo.name)) { - HILOG_INFO("%{public}s PreLoadAppDataAbilities:%{public}s", __func__, abilityInfo.bundleName.c_str()); result = PreLoadAppDataAbilities(abilityInfo.bundleName); if (result != ERR_OK) { HILOG_ERROR("StartAbility: App data ability preloading failed, '%{public}s', %{public}d", - abilityInfo.bundleName.c_str(), result); + abilityInfo.bundleName.c_str(), + result); return result; } } if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) { - HILOG_INFO("%{public}s Start SERVICE or EXTENSION", __func__); return connectManager_->StartAbility(abilityRequest); } if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { - HILOG_ERROR("IsAbilityControllerStart failed: %{public}s", abilityInfo.bundleName.c_str()); return ERR_WOULD_BLOCK; } if (useNewMission_) { if (IsSystemUiApp(abilityRequest.abilityInfo)) { - HILOG_INFO("%{public}s NewMission Start SystemUiApp", __func__); return kernalAbilityManager_->StartAbility(abilityRequest); } - HILOG_INFO("%{public}s StartAbility by MissionList", __func__); return currentMissionListManager_->StartAbility(abilityRequest); } else { if (IsSystemUiApp(abilityRequest.abilityInfo)) { - HILOG_INFO("%{public}s OldMission Start SystemUiApp", __func__); return systemAppManager_->StartAbility(abilityRequest); } - HILOG_INFO("%{public}s StartAbility by StackManager", __func__); + return currentStackManager_->StartAbility(abilityRequest); } } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 4a46419c76d..f8d4d9f72e9 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -155,7 +155,7 @@ int32_t AbilityRecord::GetUid() int AbilityRecord::LoadAbility() { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("%{public}s", __func__); + HILOG_INFO("%s", __func__); startTime_ = AbilityUtil::SystemTimeMillis(); CHECK_POINTER_AND_RETURN(token_, ERR_INVALID_VALUE); std::string appName = applicationInfo_.name; diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index b091bb8ae6a..2af8ceb8462 100755 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -266,7 +266,7 @@ int AbilitySchedulerProxy::OpenFile(const Uri &uri, const std::string &mode) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_OPENFILE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("OpenFile fail to SendRequest. err: %d", err); - return err; + return fd; } fd = reply.ReadFileDescriptor(); @@ -315,6 +315,7 @@ int AbilitySchedulerProxy::OpenRawFile(const Uri &uri, const std::string &mode) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_OPENRAWFILE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("OpenFile fail to SendRequest. err: %d", err); + return fd; } if (!reply.ReadInt32(fd)) { @@ -358,7 +359,7 @@ int AbilitySchedulerProxy::Insert(const Uri &uri, const NativeRdb::ValuesBucket int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_INSERT, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Insert fail to SendRequest. err: %d", err); - return err; + return index; } if (!reply.ReadInt32(index)) { @@ -408,7 +409,7 @@ int AbilitySchedulerProxy::Update(const Uri &uri, const NativeRdb::ValuesBucket int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_UPDATE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Update fail to SendRequest. err: %d", err); - return err; + return index; } if (!reply.ReadInt32(index)) { @@ -452,6 +453,7 @@ int AbilitySchedulerProxy::Delete(const Uri &uri, const NativeRdb::DataAbilityPr int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_DELETE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Delete fail to SendRequest. err: %d", err); + return index; } if (!reply.ReadInt32(index)) { @@ -533,6 +535,7 @@ std::string AbilitySchedulerProxy::GetType(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_GETTYPE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); + return type; } type = reply.ReadString(); @@ -579,6 +582,7 @@ bool AbilitySchedulerProxy::Reload(const Uri &uri, const PacMap &extras) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_RELOAD, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); + return ret; } ret = reply.ReadBool(); @@ -631,6 +635,7 @@ int AbilitySchedulerProxy::BatchInsert(const Uri &uri, const std::vectorSendRequest(IAbilityScheduler::SCHEDULE_BATCHINSERT, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); + return ret; } if (!reply.ReadInt32(ret)) { @@ -830,6 +835,7 @@ Uri AbilitySchedulerProxy::NormalizeUri(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_NORMALIZEURI, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("NormalizeUri fail to SendRequest. err: %d", err); + return Uri(""); } std::unique_ptr info(reply.ReadParcelable()); @@ -870,6 +876,7 @@ Uri AbilitySchedulerProxy::DenormalizeUri(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_DENORMALIZEURI, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("DenormalizeUri fail to SendRequest. err: %d", err); + return Uri(""); } std::unique_ptr info(reply.ReadParcelable()); @@ -912,6 +919,7 @@ std::vector> AbilitySchedulerProx int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_EXECUTEBATCH, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("AbilitySchedulerProxy::ExecuteBatch fail to SendRequest. err: %{public}d", err); + return results; } int total = 0; diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index aa0e7774230..522c221d1d5 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -203,6 +203,10 @@ int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &repl return ERR_INVALID_VALUE; } int fd = OpenFile(*uri, mode); + if(fd < 0){ + HILOG_ERROR("OpenFile fail, fd is %{pubilc}d", fd); + return ERR_INVALID_VALUE; + } if (!reply.WriteFileDescriptor(fd)) { HILOG_ERROR("fail to WriteFileDescriptor fd"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/ability_stack_manager.cpp b/services/abilitymgr/src/ability_stack_manager.cpp index 4ae2b321f4f..bce2de61c80 100644 --- a/services/abilitymgr/src/ability_stack_manager.cpp +++ b/services/abilitymgr/src/ability_stack_manager.cpp @@ -82,7 +82,7 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) bool result = whiteList->FindBundleNameOnWhiteList(abilityRequest.abilityInfo.bundleName, isAwakenScreen); whiteList.reset(); if (!result) { - HILOG_ERROR("the ability is not on the white list..."); + HILOG_DEBUG("the ability is not on the white list..."); return START_ABILITY_NOT_ONTHE_WHITELIST; } } @@ -90,7 +90,6 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) auto currentTopAbilityRecord = GetCurrentTopAbility(); if (!CanStartInLockMissionState(abilityRequest, currentTopAbilityRecord)) { SendUnlockMissionMessage(); - HILOG_ERROR("the ability can not start InLockMissionState"); return LOCK_MISSION_STATE_DENY_REQUEST; } @@ -104,9 +103,7 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) } if (!waittingAbilityQueue_.empty()) { - auto top = waittingAbilityQueue_.front().abilityInfo.name; - HILOG_INFO("Waiting queue not empty(%{public}s), enqueue(%{public}s) for waiting.", - top.c_str(), abilityRequest.abilityInfo.name.c_str()); + HILOG_INFO("Waiting queue is not empty, so enqueue ability for waiting."); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -116,8 +113,7 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) HILOG_DEBUG("current top: %{public}s", element.c_str()); auto targetState = currentTopAbilityRecord->IsNewVersion() ? FOREGROUND_NEW : ACTIVE; if (currentTopAbilityRecord->GetAbilityState() != targetState) { - HILOG_INFO("Top ability is not active(%{public}s), enqueue(%{public}s) for waiting.", - currentTopAbilityRecord->GetAbilityInfo().name.c_str(), abilityRequest.abilityInfo.name.c_str()); + HILOG_INFO("Top ability is not active, so enqueue ability for waiting."); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -138,8 +134,7 @@ int AbilityStackManager::StartAbilityLocked( } else { auto lockTopAbilityRecord = lockScreenMissionStack_->GetTopAbilityRecord(); if (lockTopAbilityRecord && lockTopAbilityRecord->GetAbilityState() != ACTIVE) { - HILOG_INFO("lock screen stack top ability not active(%{public}s), enqueue(%{public}s) for waiting.", - lockTopAbilityRecord->GetAbilityInfo().name.c_str(), abilityRequest.abilityInfo.name.c_str()); + HILOG_INFO("lock screen stack top ability is not active, so enqueue ability for waiting."); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -150,14 +145,14 @@ int AbilityStackManager::StartAbilityLocked( if (abilityRequest.startSetting && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp) { auto windowkey = static_cast( std::atoi(abilityRequest.startSetting->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY).c_str())); + HILOG_DEBUG("Start ability with settings ..."); if (windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING || windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) { - HILOG_INFO("Start ability AsMultiWindow: %{public}d", windowkey); return StartAbilityAsMultiWindowLocked(currentTopAbility, abilityRequest); } } - HILOG_INFO("Start ability AsDefault."); + return StartAbilityAsDefaultLocked(currentTopAbility, abilityRequest); } @@ -193,11 +188,11 @@ int AbilityStackManager::StartAbilityAsDefaultLocked( // 4. start processing ability lifecycle if (currentTopAbility == nullptr) { - HILOG_INFO("top ability is null, then launch the first Ability."); + // top ability is null, then launch the first Ability. targetAbilityRecord->SetLauncherRoot(); return targetAbilityRecord->LoadAbility(); } else { - HILOG_INFO("top ability not null, complete ability background if needed."); + // complete ability background if needed. return StartAbilityLifeCycle(lastTopAbility, currentTopAbility, targetAbilityRecord); } } diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 5757bd929cd..cad08adfb86 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -59,7 +59,6 @@ void AmsMgrScheduler::LoadAbility(const sptr &token, const sptr &app) { if (!IsReady()) { - APP_LOGE("AttachApplication failed, not ready."); return; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 7fd28d854e2..1323c9035a9 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -78,7 +78,6 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); if (!CheckLoadabilityConditions(token, abilityInfo, appInfo)) { - APP_LOGE("CheckLoadabilityConditions failed"); return; } @@ -90,7 +89,6 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; if (!GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)) { - APP_LOGE("GetBundleAndHapInfo failed"); return; } @@ -104,11 +102,14 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt appRecord = CreateAppRunningRecord(token, preToken, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo); if (!appRecord) { - APP_LOGI("CreateAppRunningRecord failed, appRecord is nullptr"); + APP_LOGI("appRecord is nullptr"); return; } - StartProcess(abilityInfo->applicationName, processName, appRecord, - abilityInfo->applicationInfo.uid, abilityInfo->applicationInfo.bundleName); + StartProcess(abilityInfo->applicationName, + processName, + appRecord, + abilityInfo->applicationInfo.uid, + abilityInfo->applicationInfo.bundleName); } else { StartAbility(token, preToken, abilityInfo, appRecord, hapModuleInfo); } @@ -209,7 +210,7 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptrGetState() != ApplicationState::APP_STATE_CREATE) { - APP_LOGE("wrong app state:%{public}d", appRecord->GetState()); + APP_LOGE("wrong app state"); return; } appRecord->LaunchApplication(); @@ -1202,8 +1203,9 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); return; } - APP_LOGI("newPid:%{public}d uid:%{public}d", pid, startMsg.uid); + APP_LOGI("newPid %{public}d", pid); appRecord->GetPriorityObject()->SetPid(pid); + APP_LOGI("app uid %{public}d", startMsg.uid); appRecord->SetUid(startMsg.uid); OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); appRecord->SetAppMgrServiceInner(weak_from_this()); -- Gitee From ef19632c7a280f361eac52bbdeda2636da3d8725 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Sat, 22 Jan 2022 20:13:45 +0800 Subject: [PATCH 2/5] codex Signed-off-by: hanhaibin --- .../inner/napi_common/napi_common_data.h | 22 +++++++++---------- .../resource/ams_service_config.json | 1 + .../abilitymgr/src/ability_scheduler_stub.cpp | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h index ec8e4fa50b8..30e3d69e068 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h @@ -33,17 +33,17 @@ namespace AppExecFwk { #define ARGS_MAX_COUNT 10 #define ARGS_ASYNC_COUNT 1 -#define ARGS_ZERO 0 -#define ARGS_ONE 1 -#define ARGS_TWO 2 -#define ARGS_THREE 3 -#define ARGS_FOUR 4 -#define ARGS_FIVE 5 -#define ARGS_SIX 6 -#define ARGS_SEVEN 7 -#define ARGS_EIGHT 8 -#define ARGS_NINE 9 -#define ARGS_TEN 10 +constexpr unsigned int ARGS_ZERO = 0; +constexpr unsigned int ARGS_ONE = 1; +constexpr unsigned int ARGS_TWO = 2; +constexpr unsigned int ARGS_THREE = 3; +constexpr unsigned int ARGS_FOUR = 4; +constexpr unsigned int ARGS_FIVE = 5; +constexpr unsigned int ARGS_SIX = 6; +constexpr unsigned int ARGS_SEVEN = 7; +constexpr unsigned int ARGS_EIGHT = 8; +constexpr unsigned int ARGS_NINE = 9; +constexpr unsigned int ARGS_TEN = 10; #define PARAM0 0 #define PARAM1 1 diff --git a/services/abilitymgr/resource/ams_service_config.json b/services/abilitymgr/resource/ams_service_config.json index 3eb6c45e883..23a25860d96 100644 --- a/services/abilitymgr/resource/ams_service_config.json +++ b/services/abilitymgr/resource/ams_service_config.json @@ -7,6 +7,7 @@ "startup_phone_service" : true, "startup_contacts":true, "startup_mms":true, + "use_new_mission" : true, "mission_save_time" : 43200000, "root_launcher_restart_max":15 }, diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index 522c221d1d5..aa18c27c53d 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -203,7 +203,7 @@ int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &repl return ERR_INVALID_VALUE; } int fd = OpenFile(*uri, mode); - if(fd < 0){ + if (fd < 0) { HILOG_ERROR("OpenFile fail, fd is %{pubilc}d", fd); return ERR_INVALID_VALUE; } -- Gitee From af1139b4d9ab629a7150fec3d8266c519c475ba7 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Sat, 22 Jan 2022 22:30:04 +0800 Subject: [PATCH 3/5] codex Signed-off-by: hanhaibin --- .../include/ability_context_impl.h | 1 + .../src/ability_context_impl.cpp | 8 + .../ability/native/src/ability_thread.cpp | 8 +- .../native/src/data_ability_helper.cpp | 13 +- .../src/js_service_extension_context.cpp | 8 +- .../ability/native/src/new_ability_impl.cpp | 2 +- frameworks/kits/appkit/BUILD.gn | 8 + .../include/ability_delegator.h | 126 +++++ .../include/ability_delegator_args.h | 47 ++ .../include/ability_delegator_registry.h | 40 ++ .../include/delegator_thread.h | 47 ++ .../include/iability_monitor.h | 64 +++ .../include/shell_cmd_result.h | 45 ++ .../ability_delegator/include/test_runner.h | 41 ++ .../src/ability_delegator.cpp | 489 ++++++++++++++++++ .../src/ability_delegator_args.cpp | 63 +++ .../src/ability_delegator_registry.cpp | 40 ++ .../src/delegator_thread.cpp | 52 ++ .../src/iability_monitor.cpp | 96 ++++ .../src/shell_cmd_result.cpp | 49 ++ .../ability_delegator/src/test_runner.cpp | 41 ++ .../native/ability_runtime/context/context.h | 7 + .../ability_runtime/context/context_impl.cpp | 50 +- .../ability_runtime/context/context_impl.h | 21 +- .../context/js_context_utils.cpp | 44 ++ .../appkit/native/app/src/main_thread.cpp | 3 +- .../kits/napi/aafwk/app/context/context.js | 51 +- .../napi_data_ability_helper.cpp | 234 +++------ .../featureAbility/napi_data_ability_helper.h | 1 - .../napi_common/feature_ability_common.h | 11 - .../inner/napi_common/napi_common_ability.cpp | 20 +- .../inner/napi_common/napi_common_data.h | 21 +- .../abilitymgr/src/ability_manager_proxy.cpp | 6 +- .../src/ability_manager_service.cpp | 15 +- services/abilitymgr/src/ability_record.cpp | 2 +- .../src/ability_scheduler_proxy.cpp | 14 +- .../abilitymgr/src/ability_scheduler_stub.cpp | 4 - .../abilitymgr/src/ability_stack_manager.cpp | 21 +- services/appmgr/src/ams_mgr_scheduler.cpp | 1 + services/appmgr/src/app_mgr_service.cpp | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 16 +- 41 files changed, 1539 insertions(+), 292 deletions(-) create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/test_runner.h create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp create mode 100644 frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp mode change 100644 => 100755 frameworks/kits/appkit/native/ability_runtime/context/context.h mode change 100644 => 100755 frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp mode change 100644 => 100755 frameworks/kits/appkit/native/ability_runtime/context/context_impl.h mode change 100644 => 100755 frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp mode change 100644 => 100755 interfaces/kits/napi/aafwk/app/context/context.js diff --git a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h index a3676d50ffa..cbf3e44ade4 100644 --- a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h @@ -34,6 +34,7 @@ public: std::string GetDatabaseDir() override; std::string GetStorageDir() override; std::string GetDistributedFilesDir() override; + void SwitchArea(int mode) override; std::string GetBundleName() const override; std::shared_ptr GetApplicationInfo() const override; std::shared_ptr GetResourceManager() const override; diff --git a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp index 4c9b1ff53e0..6e812396a4e 100644 --- a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp +++ b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp @@ -59,6 +59,14 @@ std::string AbilityContextImpl::GetDistributedFilesDir() return stageContext_ ? stageContext_->GetDistributedFilesDir() : ""; } +void AbilityContextImpl::SwitchArea(int mode) +{ + HILOG_DEBUG("AbilityContextImpl::SwitchArea."); + if (stageContext_ != nullptr) { + stageContext_->SwitchArea(mode); + } +} + ErrCode AbilityContextImpl::StartAbility(const AAFwk::Want &want, int requestCode) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 48c72e64652..b161deeeb38 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -432,14 +432,12 @@ void AbilityThread::HandleAbilityTransaction(const Want &want, const LifeCycleSt return; } - APP_LOGI("AbilityThread::HandleAbilityTransaction before abilityImpl_->SetCallingContext"); + APP_LOGI("AbilityThread::HandleAbilityTransaction abilityImpl_->SetCallingContext"); abilityImpl_->SetCallingContext(lifeCycleStateInfo.caller.deviceId, lifeCycleStateInfo.caller.bundleName, lifeCycleStateInfo.caller.abilityName); - APP_LOGI("AbilityThread::HandleAbilityTransaction after abilityImpl_->SetCallingContext"); - APP_LOGI("AbilityThread::HandleAbilityTransaction before abilityImpl_->HandleAbilityTransaction"); + APP_LOGI("AbilityThread::HandleAbilityTransaction abilityImpl_->HandleAbilityTransaction"); abilityImpl_->HandleAbilityTransaction(want, lifeCycleStateInfo); - APP_LOGI("AbilityThread::HandleAbilityTransaction after abilityImpl_->HandleAbilityTransaction"); APP_LOGI("AbilityThread::HandleAbilityTransaction end"); } @@ -1499,4 +1497,4 @@ std::shared_ptr AbilityThread::BuildAbilityConte return abilityContextImpl; } } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/kits/ability/native/src/data_ability_helper.cpp b/frameworks/kits/ability/native/src/data_ability_helper.cpp index 4d1d99882b8..89ad38d58a3 100644 --- a/frameworks/kits/ability/native/src/data_ability_helper.cpp +++ b/frameworks/kits/ability/native/src/data_ability_helper.cpp @@ -289,7 +289,7 @@ bool DataAbilityHelper::Release() APP_LOGI("DataAbilityHelper::Release before ReleaseDataAbility."); int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy_, token_); if (err != ERR_OK) { - APP_LOGE("DataAbilityHelper::Release failed to ReleaseDataAbility err = %{public}d", err); + APP_LOGE("DataAbilityHelper::GetFileTypes failed to ReleaseDataAbility err = %{public}d", err); return false; } APP_LOGI("DataAbilityHelper::Release after ReleaseDataAbility."); @@ -926,14 +926,9 @@ void DataAbilityHelper::UnregisterObserver(const Uri &uri, const sptrScheduleUnregisterObserver(uri, dataObserver); - if (uri_ == nullptr) { - APP_LOGI("DataAbilityHelper::UnregisterObserver before ReleaseDataAbility."); - int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy_, token_); - APP_LOGI("DataAbilityHelper::UnregisterObserver after ReleaseDataAbility."); - if (err != ERR_OK) { - APP_LOGE("DataAbilityHelper::UnregisterObserver failed to ReleaseDataAbility err = %{public}d", err); - } - dataAbilityProxy_ = nullptr; + int err = AbilityManagerClient::GetInstance()->ReleaseDataAbility(dataAbilityProxy, token_); + if (err != ERR_OK) { + APP_LOGE("DataAbilityHelper::UnregisterObserver failed to ReleaseDataAbility err = %{public}d", err); } registerMap_.erase(dataObserver); uriMap_.erase(dataObserver); diff --git a/frameworks/kits/ability/native/src/js_service_extension_context.cpp b/frameworks/kits/ability/native/src/js_service_extension_context.cpp index 8786829e243..940ef133613 100755 --- a/frameworks/kits/ability/native/src/js_service_extension_context.cpp +++ b/frameworks/kits/ability/native/src/js_service_extension_context.cpp @@ -264,13 +264,9 @@ private: return; } HILOG_INFO("context->DisconnectAbility"); - context->DisconnectAbility(want, connection); - /* auto errcode = context->DisconnectAbility(want, connection); - if (errcode == 0) { - task.Resolve(engine, engine.CreateUndefined()); - } else { + auto errcode = context->DisconnectAbility(want, connection); + errcode == 0 ? task.Resolve(engine, engine.CreateUndefined()) : task.Reject(engine, CreateJsError(engine, errcode, "Disconnect Ability failed.")); - } */ }; NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; diff --git a/frameworks/kits/ability/native/src/new_ability_impl.cpp b/frameworks/kits/ability/native/src/new_ability_impl.cpp index ccb869ee2c4..4ef0b322829 100644 --- a/frameworks/kits/ability/native/src/new_ability_impl.cpp +++ b/frameworks/kits/ability/native/src/new_ability_impl.cpp @@ -99,4 +99,4 @@ bool NewAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycle return ret; } } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/kits/appkit/BUILD.gn b/frameworks/kits/appkit/BUILD.gn index e6e66815782..7545a3abbaf 100644 --- a/frameworks/kits/appkit/BUILD.gn +++ b/frameworks/kits/appkit/BUILD.gn @@ -89,6 +89,7 @@ ohos_shared_library("appkit_native") { "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr", "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", "${aafwk_path}/frameworks/kits/appkit/native/app/include", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/include", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context", "${aafwk_path}/frameworks/kits/appkit/native", @@ -121,6 +122,13 @@ ohos_shared_library("appkit_native") { "${aafwk_path}/frameworks/kits/appkit/native/app/src/context_container.cpp", #"${aafwk_path}/frameworks/kits/appkit/native/app/main.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app/ability_stage.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app/js_ability_stage.cpp", "${aafwk_path}/frameworks/kits/appkit/native/app/src/context_deal.cpp", diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h new file mode 100644 index 00000000000..e085018dc45 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H +#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H + +#include +#include +#include +#include +#include +#include +#include + +#include "iability_monitor.h" +#include "delegator_thread.h" +#include "shell_cmd_result.h" +#include "test_runner.h" + +#include "ability_lifecycle_callbacks.h" +#include "ability_lifecycle_executor.h" +#include "ability_runtime/context/context.h" +#include "main_thread.h" + +namespace OHOS { +namespace AppExecFwk { +class AbilityDelegator : public AbilityLifecycleCallbacks, public std::enable_shared_from_this +{ +public: + enum class AbilityState : uint8_t + { + UNINITIALIZED = 0, + STARTED, + FOREGROUND, + BACKGROUND, + STOPED + }; + + using ability_property = std::tuple, std::shared_ptr, AbilityDelegator::AbilityState>; + using list_ability_property = std::list; + +public: + AbilityDelegator(MainThread *mainThread, std::unique_ptr &&runner, + const sptr &observer); + ~AbilityDelegator(); + + void OnAbilityStart(const std::shared_ptr &ability) override; + void OnAbilityInactive(const std::shared_ptr &ability) override; + void OnAbilityBackground(const std::shared_ptr &ability) override; + void OnAbilityForeground(const std::shared_ptr &ability) override; + void OnAbilityActive(const std::shared_ptr &ability) override; + void OnAbilityStop(const std::shared_ptr &ability) override; + void OnAbilitySaveState(const PacMap &outState) override; + + void AddAbilityMonitor(const std::shared_ptr &monitor); + void RemoveAbilityMonitor(const std::shared_ptr &monitor); + void ClearAllMonitors(); + size_t GetMonitorsNum(); + + sptr WaitAbilityMonitor(const std::shared_ptr &monitor); + sptr WaitAbilityMonitor( + const std::shared_ptr &monitor, const int64_t timeoutMs); + + std::shared_ptr GetAppContext() const; + AbilityDelegator::AbilityState GetAbilityState(const sptr &token); + sptr GetCurrentTopAbility(); + std::string GetThreadName() const; + + void Prepare(); + void OnRun(); + + bool DoAbilityForeground(const sptr &token); + bool DoAbilityBackground(const sptr &token); + + std::unique_ptr ExecuteShellCommand(const std::string &cmd, const int64_t timeoutMs); + + void Print(const std::string &msg); + + void PrePerformStart(const std::shared_ptr &ability); + void PostPerformStart(const std::shared_ptr &ability); + void PrePerformScenceCreated(const std::shared_ptr &ability); + void PrePerformScenceRestored(const std::shared_ptr &ability); + void PrePerformScenceDestroyed(const std::shared_ptr &ability); + void PrePerformForeground(const std::shared_ptr &ability); + void PrePerformBackground(const std::shared_ptr &ability); + void PrePerformStop(const std::shared_ptr &ability); + +private: + AbilityDelegator::AbilityState ConvertAbilityState(const AbilityLifecycleExecutor::LifecycleState lifecycleState); + void ProcessAbilityProperties(const std::shared_ptr &ability); + sptr GetAbilityToken(const std::shared_ptr &ability); + std::optional DoesPropertyExist(const sptr &token); + void MatchMonitor(const std::shared_ptr &ability); + +private: + static constexpr size_t FIRST_PROPERTY {0}; + static constexpr size_t SECOND_PROPERTY {1}; + static constexpr size_t THIRD_PROPERTY {2}; + +private: + MainThread *mainThread_ {nullptr}; + std::unique_ptr testRunner_; + std::unique_ptr delegatorThread_; + list_ability_property abilityProperties_; + std::vector> abilityMonitors_; + std::shared_ptr appContext_; + + std::mutex mutexMonitor_; + std::mutex mutexAbilityProperties_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h new file mode 100644 index 00000000000..b2051b25cc3 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_ARGS_H +#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_ARGS_H + +#include +#include + +namespace OHOS { +namespace AppExecFwk { +class AbilityDelegatorArgs +{ +public: + static const std::string KEY_TEST_RUNNER_CLASS; + static const std::string KEY_TEST_CASE; + +public: + void SetTestBundleName(const std::string &bundleName); + std::string GetTestBundleName() const; + + std::string GetTestRunnerClassName() const; + std::string GetTestCaseName() const; + + void SetTestParam(const std::map ¶ms); + std::map GetTestParam() const; + +private: + std::string bundleName_; + std::map params_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_ARGS_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h new file mode 100644 index 00000000000..6005d869ecc --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_REGISTRY_H +#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_REGISTRY_H + +#include +#include "ability_delegator.h" +#include "ability_delegator_args.h" + +namespace OHOS { +namespace AppExecFwk { +class AbilityDelegatorRegistry +{ +public: + static std::shared_ptr GetAbilityDelegator(); + static std::shared_ptr GetArguments(); + static void RegisterInstance( + const std::shared_ptr &delegator, const std::shared_ptr &args); + +private: + static std::shared_ptr abilityDelegator_; + static std::shared_ptr abilityDelegatorArgs_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_REGISTRY_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h new file mode 100644 index 00000000000..57333c0a57c --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_DELEGATOR_THREAD_H +#define FOUNDATION_APPEXECFWK_OHOS_DELEGATOR_THREAD_H + +#include +#include +#include +#include "event_handler.h" +#include "event_runner.h" + +namespace OHOS { +namespace AppExecFwk { +class DelegatorThread +{ +public: + using DTask = std::function; + +public: + explicit DelegatorThread(bool isMain = false); + ~DelegatorThread() = default; + + bool Run(const DTask &task); + std::string GetThreadName() const; + +private: + std::string threadName_; + std::shared_ptr runner_; + std::shared_ptr handler_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_DELEGATOR_THREAD_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h new file mode 100644 index 00000000000..b4ec25ebc68 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_IABILITY_MONITORE_H +#define FOUNDATION_APPEXECFWK_OHOS_IABILITY_MONITORE_H + +#include +#include +#include +#include +#include +#include + +#include "ability.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +class IAbilityMonitor +{ +public: + static constexpr int64_t MAX_TIME_OUT {5000}; + +public: + explicit IAbilityMonitor(const std::string &abilityName); + virtual ~IAbilityMonitor() = default; + + virtual bool Match(const std::shared_ptr &ability, const Want &want); + + virtual std::shared_ptr waitForAbility(); + virtual std::shared_ptr waitForAbility(const int64_t timeoutMs); + + virtual void OnAbilityStart(); + virtual void OnAbilityForeground(); + virtual void OnAbilityBackground(); + virtual void OnAbilityStop(); + + virtual void OnWindowStageCreate(); + virtual void OnWindowStageRestore(); + virtual void OnWindowStageDestroy(); + +private: + std::string abilityName_; + std::shared_ptr matchedAbility_; + + std::condition_variable cvMatch_; + std::mutex mMatch_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_IABILITY_MONITORE_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h new file mode 100644 index 00000000000..4bcb01bb0e2 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_SHELL_CMD_RESULT_H +#define FOUNDATION_APPEXECFWK_OHOS_SHELL_CMD_RESULT_H + +#include + +namespace OHOS { +namespace AppExecFwk { +class ShellCmdResult +{ +public: + ShellCmdResult() = default; + ShellCmdResult(const int32_t exitCode, const std::string &stdResult); + ~ShellCmdResult() = default; + + void SetExitCode(const int32_t exitCode); + int32_t GetExitCode() const; + + void SetStdResult(const std::string &stdResult); + std::string GetStdResult() const; + + std::string Dump(); + +private: + int32_t exitCode_ {-1}; + std::string stdResult_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_SHELL_CMD_RESULT_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h new file mode 100644 index 00000000000..2bdbb4b0795 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_TEST_RUNNER_H +#define FOUNDATION_APPEXECFWK_OHOS_TEST_RUNNER_H + +#include + +namespace OHOS { +namespace AbilityRuntime { +class Runtime; +} + +namespace AppExecFwk { +class TestRunner +{ +public: + static std::unique_ptr Create(const std::unique_ptr& runtime); + + TestRunner() = default; + virtual ~TestRunner() = default; + + virtual void Prepare(); + virtual void Run(); +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_TEST_RUNNER_H diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp new file mode 100644 index 00000000000..df0c8b61bfc --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -0,0 +1,489 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "ability_delegator.h" +#include "app_log_wrapper.h" +#include "ohos_application.h" +#include "ability_manager_client.h" + +#define RETURN_IF_NULL_POINTER(pointer) \ + if (!(pointer)) { \ + APP_LOGW("Invalid input parameter"); \ + return; \ + } + +#define RETURN_IF_EMPTY_MONITORS() \ + if (abilityMonitors_.empty()) { \ + APP_LOGW("Empty abilityMonitors"); \ + return; \ + } + +namespace OHOS { +namespace AppExecFwk { +AbilityDelegator::AbilityDelegator(MainThread *mainThread, std::unique_ptr &&runner, + const sptr &observer) + : mainThread_(mainThread), testRunner_(std::move(runner)) +{ + if (mainThread_ != nullptr) { + auto app = mainThread_->GetApplication(); + if (app) { + appContext_ = app->GetAppContext(); + app->RegisterAbilityLifecycleCallbacks(shared_from_this()); + } + } +} + +AbilityDelegator::~AbilityDelegator() +{ + if (mainThread_ != nullptr) { + auto app = mainThread_->GetApplication(); + if (app) { + app->UnregisterAbilityLifecycleCallbacks(shared_from_this()); + } + } +} + +void AbilityDelegator::OnAbilityStart(const std::shared_ptr &ability) +{ + ProcessAbilityProperties(ability); +} + +void AbilityDelegator::OnAbilityInactive(const std::shared_ptr &ability) +{} + +void AbilityDelegator::OnAbilityBackground(const std::shared_ptr &ability) +{ + ProcessAbilityProperties(ability); +} + +void AbilityDelegator::OnAbilityForeground(const std::shared_ptr &ability) +{ + ProcessAbilityProperties(ability); +} + +void AbilityDelegator::OnAbilityActive(const std::shared_ptr &ability) +{} + +void AbilityDelegator::OnAbilityStop(const std::shared_ptr &ability) +{ + ProcessAbilityProperties(ability); +} + +void AbilityDelegator::OnAbilitySaveState(const PacMap &outState) +{} + +void AbilityDelegator::AddAbilityMonitor(const std::shared_ptr &monitor) +{ + if (!monitor) { + APP_LOGW("Invalid input parameter"); + return; + } + + std::unique_lock lck(mutexMonitor_); + abilityMonitors_.emplace_back(monitor); +} + +void AbilityDelegator::RemoveAbilityMonitor(const std::shared_ptr &monitor) +{ + if (!monitor) { + APP_LOGW("Invalid input parameter"); + return; + } + + std::unique_lock lck(mutexMonitor_); + auto pos = std::find(abilityMonitors_.begin(), abilityMonitors_.end(), monitor); + if (pos != abilityMonitors_.end()) { + abilityMonitors_.erase(pos); + } +} + +void AbilityDelegator::ClearAllMonitors() +{ + std::unique_lock lck(mutexMonitor_); + abilityMonitors_.clear(); +} + +size_t AbilityDelegator::GetMonitorsNum() +{ + std::unique_lock lck(mutexMonitor_); + return abilityMonitors_.size(); +} + +sptr AbilityDelegator::WaitAbilityMonitor(const std::shared_ptr &monitor) +{ + if (!monitor) { + APP_LOGW("Invalid input parameter"); + return {}; + } + + auto obtainedAbility = monitor->waitForAbility(); + if (!obtainedAbility) { + APP_LOGW("Invalid obtained ability"); + return {}; + } + + return GetAbilityToken(obtainedAbility); +} + +sptr AbilityDelegator::WaitAbilityMonitor( + const std::shared_ptr &monitor, const int64_t timeoutMs) +{ + if (!monitor) { + APP_LOGW("Invalid input parameter"); + return {}; + } + + auto obtainedAbility = monitor->waitForAbility(timeoutMs); + if (!obtainedAbility) { + APP_LOGW("Invalid obtained ability"); + return {}; + } + + return GetAbilityToken(obtainedAbility); +} + +std::shared_ptr AbilityDelegator::GetAppContext() const +{ + return appContext_; +} + +AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr &token) +{ + if (!token) { + APP_LOGW("Invalid input parameter"); + return AbilityDelegator::AbilityState::UNINITIALIZED; + } + + std::unique_lock lck(mutexAbilityProperties_); + auto existedProperty = DoesPropertyExist(token); + if (!existedProperty) { + APP_LOGW("Unknown ability token"); + return AbilityDelegator::AbilityState::UNINITIALIZED; + } + + return std::get(existedProperty.value()); +} + +sptr AbilityDelegator::GetCurrentTopAbility() +{ + return {}; +} + +std::string AbilityDelegator::GetThreadName() const +{ + return {}; +} + +void AbilityDelegator::Prepare() +{ + if (!testRunner_) { + APP_LOGW("Invalid TestRunner"); + return; + } + + testRunner_->Prepare(); + + if (!delegatorThread_) { + delegatorThread_ = std::make_unique(true); + if (!delegatorThread_) { + APP_LOGE("Create delegatorThread failed"); + return; + } + } + + auto runTask = [this]() { this->OnRun(); }; + if (!delegatorThread_->Run(runTask)) { + APP_LOGE("Run task on delegatorThread failed"); + } +} + +void AbilityDelegator::OnRun() +{ + if (!testRunner_) { + APP_LOGW("Invalid TestRunner"); + return; + } + + testRunner_->Run(); +} + +bool AbilityDelegator::DoAbilityForeground(const sptr &token) +{ + if (!token) { + APP_LOGW("Invalid input parameter"); + return false; + } + + return true; +} + +bool AbilityDelegator::DoAbilityBackground(const sptr &token) +{ + if (!token) { + APP_LOGW("Invalid input parameter"); + return false; + } + + return true; +} + +std::unique_ptr AbilityDelegator::ExecuteShellCommand(const std::string &cmd, const int64_t timeoutMs) +{ + APP_LOGI("command : %{public}s", cmd.data()); + return {}; +} + +void AbilityDelegator::Print(const std::string &msg) +{} + +void AbilityDelegator::PrePerformStart(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnAbilityStart(); + } +} + +void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + } +} + +void AbilityDelegator::PrePerformScenceCreated(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnWindowStageCreate(); + } +} + +void AbilityDelegator::PrePerformScenceRestored(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnWindowStageRestore(); + } +} + +void AbilityDelegator::PrePerformScenceDestroyed(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnWindowStageDestroy(); + } +} + +void AbilityDelegator::PrePerformForeground(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnAbilityForeground(); + } +} + +void AbilityDelegator::PrePerformBackground(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnAbilityBackground(); + } +} + +void AbilityDelegator::PrePerformStop(const std::shared_ptr &ability) +{ + RETURN_IF_NULL_POINTER(ability) + + std::unique_lock lck(mutexMonitor_); + RETURN_IF_EMPTY_MONITORS() + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + monitor->OnAbilityStop(); + } +} + +AbilityDelegator::AbilityState AbilityDelegator::ConvertAbilityState( + const AbilityLifecycleExecutor::LifecycleState lifecycleState) +{ + AbilityDelegator::AbilityState abilityState {AbilityDelegator::AbilityState::UNINITIALIZED}; + switch (lifecycleState) { + case AbilityLifecycleExecutor::LifecycleState::STARTED_NEW: + abilityState = AbilityDelegator::AbilityState::STARTED; + break; + case AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW: + abilityState = AbilityDelegator::AbilityState::FOREGROUND; + break; + case AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW: + abilityState = AbilityDelegator::AbilityState::BACKGROUND; + break; + case AbilityLifecycleExecutor::LifecycleState::STOPED_NEW: + abilityState = AbilityDelegator::AbilityState::STOPED; + break; + default: + APP_LOGE("Unknown lifecycleState"); + break; + } + + return abilityState; +} + +void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr &ability) +{ + if (!ability) { + APP_LOGW("Invalid ability"); + return; + } + + auto abilityToken = GetAbilityToken(ability); + if (!abilityToken) { + APP_LOGE("Invalid ability token"); + return; + } + + std::unique_lock lck(mutexAbilityProperties_); + auto existedProperty = DoesPropertyExist(abilityToken); + if (existedProperty) { + abilityProperties_.remove(existedProperty.value()); + } + + auto abilityState = ConvertAbilityState(ability->GetState()); + if (abilityState == AbilityDelegator::AbilityState::FOREGROUND) { + abilityProperties_.emplace_front(abilityToken, ability, abilityState); + } else { + abilityProperties_.emplace_back(abilityToken, ability, abilityState); + } +} + +sptr AbilityDelegator::GetAbilityToken(const std::shared_ptr &ability) +{ + if (!ability) { + APP_LOGW("Invalid ability"); + return {}; + } + + auto abilityContext = ability->GetAbilityContext(); + if (!abilityContext) { + APP_LOGE("Invalid ability context"); + return {}; + } + + return abilityContext->GetAbilityToken(); +} + +std::optional AbilityDelegator::DoesPropertyExist(const sptr &token) +{ + if (!token) { + APP_LOGW("Invalid input parameter"); + return std::nullopt; + } + + for (auto &it : abilityProperties_) { + auto tmpToken = std::get(it); + if (token == tmpToken) { + return it; + } + } + + return std::nullopt; +} + +void AbilityDelegator::MatchMonitor(const std::shared_ptr &ability) +{ + // std::unique_lock lck(mutexMonitor_); + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } + + for (auto &monitor : abilityMonitors_) { + if (!monitor) { + continue; + } + + monitor->Match(ability, {}); + } +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp new file mode 100644 index 00000000000..ee72c311f5f --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 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 "ability_delegator_args.h" + +namespace OHOS { +namespace AppExecFwk { +const std::string AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS {"KeyTestRunnerClass"}; +const std::string AbilityDelegatorArgs::KEY_TEST_CASE {"KeyTestCase"}; + +void AbilityDelegatorArgs::SetTestBundleName(const std::string &bundleName) +{ + bundleName_ = bundleName; +} + +std::string AbilityDelegatorArgs::GetTestBundleName() const +{ + return bundleName_; +} + +std::string AbilityDelegatorArgs::GetTestRunnerClassName() const +{ + auto target = params_.find(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS); + if (target != params_.end()) { + return target->second; + } + + return {}; +} + +std::string AbilityDelegatorArgs::GetTestCaseName() const +{ + auto target = params_.find(AbilityDelegatorArgs::KEY_TEST_CASE); + if (target != params_.end()) { + return target->second; + } + + return {}; +} + +void AbilityDelegatorArgs::SetTestParam(const std::map ¶ms) +{ + params_ = params; +} + +std::map AbilityDelegatorArgs::GetTestParam() const +{ + return params_; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp new file mode 100644 index 00000000000..c4ff7b2ba17 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 "ability_delegator_registry.h" + +namespace OHOS { +namespace AppExecFwk { +std::shared_ptr AbilityDelegatorRegistry::abilityDelegator_ {}; +std::shared_ptr AbilityDelegatorRegistry::abilityDelegatorArgs_ {}; + +std::shared_ptr AbilityDelegatorRegistry::GetAbilityDelegator() +{ + return abilityDelegator_; +} + +std::shared_ptr AbilityDelegatorRegistry::GetArguments() +{ + return abilityDelegatorArgs_; +} + +void AbilityDelegatorRegistry::RegisterInstance( + const std::shared_ptr &delegator, const std::shared_ptr &args) +{ + abilityDelegator_ = delegator; + abilityDelegatorArgs_ = args; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp b/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp new file mode 100644 index 00000000000..6685dafe885 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 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 "delegator_thread.h" +#include "app_log_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +DelegatorThread::DelegatorThread(bool isMain) +{ + if (isMain) { + runner_ = EventRunner::GetMainEventRunner(); + } else { + runner_ = EventRunner::Create(); + } + + handler_ = std::make_shared(runner_); +} + +bool DelegatorThread::Run(const DTask &task) +{ + if (!task) { + APP_LOGW("Invalid input parameter"); + return false; + } + + if (!handler_) { + APP_LOGW("Invalid EventHandler"); + return false; + } + + return handler_->PostTask(task); +} + +std::string DelegatorThread::GetThreadName() const +{ + return threadName_; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp new file mode 100644 index 00000000000..7f435417307 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021 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 "iability_monitor.h" +#include "app_log_wrapper.h" + +using namespace std::chrono_literals; + +namespace OHOS { +namespace AppExecFwk { +IAbilityMonitor::IAbilityMonitor(const std::string &abilityName) : abilityName_(abilityName) +{} + +bool IAbilityMonitor::Match(const std::shared_ptr &ability, const Want &want) +{ + std::string aName; + if (ability) { + aName = ability->GetAbilityName(); + } else { + aName = want.GetElement().GetAbilityName(); + } + + if (abilityName_.empty() || aName.empty()) { + APP_LOGW("Invalid name"); + return false; + } + + if (abilityName_.compare(aName)) { + APP_LOGW("Different name"); + return false; + } + + if (ability) { + { + std::lock_guard matchLock(mMatch_); + matchedAbility_ = ability; + } + cvMatch_.notify_one(); + + return true; + } + + return false; +} + +std::shared_ptr IAbilityMonitor::waitForAbility() +{ + return waitForAbility(MAX_TIME_OUT); +} + +std::shared_ptr IAbilityMonitor::waitForAbility(const int64_t timeoutMs) +{ + std::unique_lock matchLock(mMatch_); + + auto condition = [this] { return this->matchedAbility_ != nullptr; }; + if (!cvMatch_.wait_for(matchLock, timeoutMs * 1ms, condition)) { + APP_LOGW("Wait ability timeout"); + } + + return matchedAbility_; +} + +void IAbilityMonitor::OnAbilityStart() +{} + +void IAbilityMonitor::OnAbilityForeground() +{} + +void IAbilityMonitor::OnAbilityBackground() +{} + +void IAbilityMonitor::OnAbilityStop() +{} + +void IAbilityMonitor::OnWindowStageCreate() +{} + +void IAbilityMonitor::OnWindowStageRestore() +{} + +void IAbilityMonitor::OnWindowStageDestroy() +{} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp b/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp new file mode 100644 index 00000000000..fa9d179dbeb --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 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 "shell_cmd_result.h" + +namespace OHOS { +namespace AppExecFwk { +ShellCmdResult::ShellCmdResult(const int32_t exitCode, const std::string &stdResult) + : exitCode_(exitCode), stdResult_(stdResult) +{} + +void ShellCmdResult::SetExitCode(const int32_t exitCode) +{ + exitCode_ = exitCode; +} + +int32_t ShellCmdResult::GetExitCode() const +{ + return exitCode_; +} + +void ShellCmdResult::SetStdResult(const std::string &stdResult) +{ + stdResult_ = stdResult; +} + +std::string ShellCmdResult::GetStdResult() const +{ + return stdResult_; +} + +std::string ShellCmdResult::Dump() +{ + return "ShellCmdResult { exitCode = " + std::to_string(exitCode_) + ", stdResult = " + stdResult_ + "}"; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp b/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp new file mode 100644 index 00000000000..25945bdffa9 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 "test_runner.h" +#include "runtime.h" + +namespace OHOS { +namespace AppExecFwk { +std::unique_ptr TestRunner::Create(const std::unique_ptr& runtime) +{ + if (!runtime) { + return std::make_unique(); + } + + switch (runtime->GetLanguage()) { + case AbilityRuntime::Runtime::Language::JS: + return {}; + default: + return std::make_unique(); + } +} + +void TestRunner::Prepare() +{} + +void TestRunner::Run() +{} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context.h b/frameworks/kits/appkit/native/ability_runtime/context/context.h old mode 100644 new mode 100755 index c7ea7287462..c2ae9a9b18a --- a/frameworks/kits/appkit/native/ability_runtime/context/context.h +++ b/frameworks/kits/appkit/native/ability_runtime/context/context.h @@ -137,6 +137,13 @@ public: */ virtual std::string GetDistributedFilesDir() = 0; + /** + * @brief Switch file area + * + * @param mode file area. + */ + virtual void SwitchArea(int mode) = 0; + /** * @brief Getting derived class * diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp old mode 100644 new mode 100755 index 92a2057121c..9654f279e15 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp @@ -26,22 +26,23 @@ namespace OHOS { namespace AbilityRuntime { const size_t Context::CONTEXT_TYPE_ID(std::hash {} ("Context")); const int64_t ContextImpl::CONTEXT_CREATE_BY_SYSTEM_APP(0x00000001); -const std::string ContextImpl::CONTEXT_BUNDLECODE_BASE("/data/app/base/"); -const std::string ContextImpl::CONTEXT_BUNDLECODE("/data/storage/app/base"); +const std::string ContextImpl::CONTEXT_DATA_APP("/data/app/"); const std::string ContextImpl::CONTEXT_BUNDLE("/bundle/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE("/mnt/hmdfs/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE("/device_view/local/data/"); const std::string ContextImpl::CONTEXT_DISTRIBUTEDFILES("distributedfiles"); const std::string ContextImpl::CONTEXT_FILE_SEPARATOR("/"); const std::string ContextImpl::CONTEXT_DATA("/data/"); -const std::string ContextImpl::CONTEXT_BASE("/data/storage/"); +const std::string ContextImpl::CONTEXT_DATA_STORAGE("/data/storage/"); +const std::string ContextImpl::CONTEXT_BASE("base"); const std::string ContextImpl::CONTEXT_PRIVATE("/private/"); const std::string ContextImpl::CONTEXT_CACHES("caches"); const std::string ContextImpl::CONTEXT_STORAGE("storage"); const std::string ContextImpl::CONTEXT_DATABASE("database"); const std::string ContextImpl::CONTEXT_TEMP("/temp"); const std::string ContextImpl::CONTEXT_FILES("/files"); -const std::string ContextImpl::CONTEXT_CE("ce"); +const std::string ContextImpl::CONTEXT_HAPS("/haps"); +const std::string ContextImpl::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"}; std::string ContextImpl::GetBundleName() const { @@ -55,9 +56,9 @@ std::string ContextImpl::GetBundleCodeDir() { std::string dir; if (IsCreateBySystemApp()) { - dir = CONTEXT_BUNDLECODE_BASE + GetBundleName(); + dir = CONTEXT_DATA_APP + CONTEXT_ELS[0] + CONTEXT_BUNDLE + GetBundleName(); } else { - dir = CONTEXT_BUNDLECODE; + dir = CONTEXT_DATA_STORAGE + CONTEXT_ELS[0] + CONTEXT_BUNDLE; } HILOG_DEBUG("ContextImpl::GetBundleCodeDir:%{public}s", dir.c_str()); return dir; @@ -72,7 +73,14 @@ std::string ContextImpl::GetCacheDir() std::string ContextImpl::GetDatabaseDir() { - std::string dir = GetBaseDir() + CONTEXT_PRIVATE + CONTEXT_DATABASE; + std::string dir; + if (IsCreateBySystemApp()) { + dir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + CONTEXT_FILE_SEPARATOR + + CONTEXT_DATABASE + GetBundleName(); + } else { + dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DATABASE; + } + dir = dir + CONTEXT_FILE_SEPARATOR + ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); HILOG_DEBUG("ContextImpl::GetDatabaseDir:%{public}s", dir.c_str()); return dir; } @@ -106,23 +114,36 @@ std::string ContextImpl::GetDistributedFilesDir() dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + GetCurrentAccountId() + CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE + GetBundleName(); } else { - dir = CONTEXT_BASE + CONTEXT_DISTRIBUTEDFILES; + dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTEDFILES + + CONTEXT_FILE_SEPARATOR + ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); } HILOG_DEBUG("ContextImpl::GetDistributedFilesDir:%{public}s", dir.c_str()); return dir; } +void ContextImpl::SwitchArea(int mode) +{ + HILOG_DEBUG("ContextImpl::SwitchArea, mode:%{public}d.", mode); + if (mode < 0 || mode >= (sizeof(CONTEXT_ELS) / sizeof(CONTEXT_ELS[0]))) { + HILOG_ERROR("ContextImpl::SwitchArea, mode is invalid."); + return; + } + currArea_ = CONTEXT_ELS[mode]; + HILOG_DEBUG("ContextImpl::SwitchArea end, currArea:%{public}s.", currArea_.c_str()); +} + std::string ContextImpl::GetBaseDir() const { std::string baseDir; if (IsCreateBySystemApp()) { - baseDir = CONTEXT_DATA + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + - CONTEXT_BUNDLE + GetBundleName(); + baseDir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE + CONTEXT_FILE_SEPARATOR + GetBundleName(); } else { - baseDir = CONTEXT_BASE + currArea_; + baseDir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE; } if (parentContext_ != nullptr) { - baseDir = baseDir + CONTEXT_FILE_SEPARATOR + GetHapModuleInfo()->moduleName; + baseDir = baseDir + CONTEXT_HAPS + CONTEXT_FILE_SEPARATOR + + ((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName); } HILOG_DEBUG("ContextImpl::GetBaseDir:%{public}s", baseDir.c_str()); @@ -300,6 +321,9 @@ void ContextImpl::InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleIn std::shared_ptr ContextImpl::GetHapModuleInfo() const { + if (hapModuleInfo_ == nullptr) { + HILOG_ERROR("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty"); + } return hapModuleInfo_; } @@ -328,4 +352,4 @@ void ContextImpl::InitAppContext() Context::appContext_ = shared_from_this(); } } // namespace AbilityRuntime -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h old mode 100644 new mode 100755 index db19e2c8348..4658e7fb5a2 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h @@ -87,6 +87,13 @@ public: */ std::string GetDistributedFilesDir() override; + /** + * @brief Switch file area + * + * @param mode file area. + */ + void SwitchArea(int mode) override; + /** * @brief set the ResourceManager. * @@ -175,14 +182,15 @@ public: */ void InitAppContext(); private: - static const std::string CONTEXT_BUNDLECODE_BASE; - static const std::string CONTEXT_BUNDLECODE; + static const int64_t CONTEXT_CREATE_BY_SYSTEM_APP; + static const std::string CONTEXT_DATA_APP; static const std::string CONTEXT_BUNDLE; static const std::string CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE; static const std::string CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE; static const std::string CONTEXT_DISTRIBUTEDFILES; static const std::string CONTEXT_FILE_SEPARATOR; static const std::string CONTEXT_DATA; + static const std::string CONTEXT_DATA_STORAGE; static const std::string CONTEXT_BASE; static const std::string CONTEXT_PRIVATE; static const std::string CONTEXT_CACHES; @@ -190,8 +198,9 @@ private: static const std::string CONTEXT_DATABASE; static const std::string CONTEXT_TEMP; static const std::string CONTEXT_FILES; - static const std::string CONTEXT_CE; - static const int64_t CONTEXT_CREATE_BY_SYSTEM_APP; + static const std::string CONTEXT_HAPS; + static const std::string CONTEXT_ELS[]; + static const int EL_DEFAULT = 1; int flags_ = 0x00000000; void InitResourceManager( @@ -205,8 +214,8 @@ private: std::shared_ptr parentContext_ = nullptr; std::shared_ptr resourceManager_ = nullptr; std::shared_ptr hapModuleInfo_ = nullptr; - std::string currArea_ = CONTEXT_CE; + std::string currArea_ = CONTEXT_ELS[EL_DEFAULT]; }; } // namespace AbilityRuntime } // namespace OHOS -#endif // ABILITY_RUNTIME_CONTEXT_IMPL_H +#endif // ABILITY_RUNTIME_CONTEXT_IMPL_H \ No newline at end of file diff --git a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp old mode 100644 new mode 100755 index 6ee66fa1059..08c265d7c6f --- a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp @@ -34,6 +34,7 @@ public: static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* CreateBundleContext(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetApplicationContext(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SwitchArea(NativeEngine* engine, NativeCallbackInfo* info); void KeepContext(std::shared_ptr context) { @@ -43,6 +44,7 @@ public: private: NativeValue* OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info); std::shared_ptr keepContext_; @@ -68,6 +70,47 @@ NativeValue* JsBaseContext::GetApplicationContext(NativeEngine* engine, NativeCa return me != nullptr ? me->OnGetApplicationContext(*engine, *info) : nullptr; } +NativeValue* JsBaseContext::SwitchArea(NativeEngine* engine, NativeCallbackInfo* info) +{ + HILOG_INFO("JsBaseContext::SwitchArea is called"); + JsBaseContext* me = CheckParamsAndGetThis(engine, info, BASE_CONTEXT_NAME); + return me != nullptr ? me->OnSwitchArea(*engine, *info) : nullptr; +} + +NativeValue* JsBaseContext::OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (info.argc == 0) { + HILOG_ERROR("Not enough params"); + return engine.CreateUndefined(); + } + + auto context = context_.lock(); + if (!context) { + HILOG_WARN("context is already released"); + return engine.CreateUndefined(); + } + + int mode; + if (!ConvertFromJsValue(engine, info.argv[0], mode)) { + HILOG_ERROR("Parse mode failed"); + return engine.CreateUndefined(); + } + + context->SwitchArea(mode); + + NativeValue* thisVar = info.thisVar; + NativeObject* object = ConvertNativeValueTo(thisVar); + object->SetProperty("cacheDir", CreateJsValue(engine, context->GetCacheDir())); + object->SetProperty("tempDir", CreateJsValue(engine, context->GetTempDir())); + object->SetProperty("filesDir", CreateJsValue(engine, context->GetFilesDir())); + object->SetProperty("distributedFilesDir", CreateJsValue(engine, context->GetDistributedFilesDir())); + object->SetProperty("databaseDir", CreateJsValue(engine, context->GetDatabaseDir())); + object->SetProperty("storageDir", CreateJsValue(engine, context->GetStorageDir())); + object->SetProperty("bundleCodeDir", CreateJsValue(engine, context->GetBundleCodeDir())); + + return engine.CreateUndefined(); +} + NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info) { if (info.argc == 0) { @@ -151,6 +194,7 @@ NativeValue* CreateJsBaseContext(NativeEngine& engine, std::shared_ptr BindNativeFunction(engine, *object, "createBundleContext", JsBaseContext::CreateBundleContext); BindNativeFunction(engine, *object, "getApplicationContext", JsBaseContext::GetApplicationContext); + BindNativeFunction(engine, *object, "switchArea", JsBaseContext::SwitchArea); return objValue; } diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 7fb1e561bee..23ad30a9702 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -193,7 +193,6 @@ bool MainThread::ConnectToAppMgr() APP_LOGI("MainThread::connectToAppMgr before AttachApplication"); appMgr_->AttachApplication(this); APP_LOGI("MainThread::connectToAppMgr after AttachApplication"); - APP_LOGI("MainThread::connectToAppMgr end"); return true; } @@ -1185,7 +1184,7 @@ void MainThread::Start() APP_LOGI("MainThread::main called start"); std::shared_ptr runner = EventRunner::GetMainEventRunner(); if (runner == nullptr) { - APP_LOGE("MainThread::main called start"); + APP_LOGE("MainThread::main failed, runner is nullptr"); return; } std::shared_ptr runnerWatchDog = EventRunner::Create("WatchDogRunner"); diff --git a/interfaces/kits/napi/aafwk/app/context/context.js b/interfaces/kits/napi/aafwk/app/context/context.js old mode 100644 new mode 100755 index d28e3283fd0..88f512579d9 --- a/interfaces/kits/napi/aafwk/app/context/context.js +++ b/interfaces/kits/napi/aafwk/app/context/context.js @@ -16,24 +16,55 @@ class Context { constructor(obj) { this.__context_impl__ = obj - - this.resourceManager = obj.resourceManager - this.applicationInfo = obj.applicationInfo - this.cacheDir = obj.cacheDir - this.tempDir = obj.tempDir - this.filesDir = obj.filesDir - this.distributedFilesDir = obj.distributedFilesDir - this.databaseDir = obj.databaseDir - this.storageDir = obj.storageDir - this.bundleCodeDir = obj.bundleCodeDir } createBundleContext(bundleName) { return this.__context_impl__.createBundleContext(bundleName) } + getApplicationContext() { return this.__context_impl__.getApplicationContext() } + + switchArea(mode) { + return this.__context_impl__.switchArea(mode) + } + + get resourceManager() { + return this.__context_impl__.resourceManager + } + + get applicationInfo() { + return this.__context_impl__.applicationInfo + } + + get cacheDir() { + return this.__context_impl__.cacheDir + } + + get tempDir() { + return this.__context_impl__.tempDir + } + + get filesDir() { + return this.__context_impl__.filesDir + } + + get distributedFilesDir() { + return this.__context_impl__.distributedFilesDir + } + + get databaseDir() { + return this.__context_impl__.databaseDir + } + + get storageDir() { + return this.__context_impl__.storageDir + } + + get bundleCodeDir() { + return this.__context_impl__.bundleCodeDir + } } export default Context diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index 8e57a49036a..686d0b826ba 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -208,6 +208,7 @@ napi_value InsertWrap(napi_env env, napi_callback_info info, DAHelperInsertCB *i HILOG_INFO("%{public}s,uri=%{public}s", __func__, insertCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + return nullptr; } insertCB->valueBucket.Clear(); @@ -346,12 +347,8 @@ void InsertExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Insert, worker pool thread execute."); DAHelperInsertCB *insertCB = static_cast(data); if (insertCB->dataAbilityHelper != nullptr) { - insertCB->execResult = INVALID_PARAMETER; - if (!insertCB->uri.empty()) { - OHOS::Uri uri(insertCB->uri); - insertCB->result = insertCB->dataAbilityHelper->Insert(uri, insertCB->valueBucket); - insertCB->execResult = NO_ERROR; - } + OHOS::Uri uri(insertCB->uri); + insertCB->result = insertCB->dataAbilityHelper->Insert(uri, insertCB->valueBucket); } else { HILOG_ERROR("NAPI_Insert, dataAbilityHelper == nullptr."); } @@ -369,7 +366,7 @@ void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, insertCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, insertCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_int32(env, insertCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -473,6 +470,7 @@ napi_value NAPI_NotifyChange(napi_env env, napi_callback_info info) */ napi_value NotifyChangeWrap(napi_env env, napi_callback_info info, DAHelperNotifyChangeCB *notifyChangeCB) { + HILOG_INFO("%{public}s,called", __func__); size_t argcAsync = ARGS_TWO; const size_t argcPromise = ARGS_ONE; @@ -494,6 +492,7 @@ napi_value NotifyChangeWrap(napi_env env, napi_callback_info info, DAHelperNotif HILOG_INFO("%{public}s,uri=%{public}s", __func__, notifyChangeCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + return nullptr; } DataAbilityHelper *objectInfo = nullptr; @@ -571,14 +570,8 @@ void NotifyChangeExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_NotifyChange, worker pool thread execute."); DAHelperNotifyChangeCB *notifyChangeCB = static_cast(data); if (notifyChangeCB->dataAbilityHelper != nullptr) { - notifyChangeCB->execResult = INVALID_PARAMETER; - if (!notifyChangeCB->uri.empty()) { - OHOS::Uri uri(notifyChangeCB->uri); - notifyChangeCB->dataAbilityHelper->NotifyChange(uri); - notifyChangeCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("%{public}s, notifyChangeCB uri is empty.", __func__); - } + OHOS::Uri uri(notifyChangeCB->uri); + notifyChangeCB->dataAbilityHelper->NotifyChange(uri); } } @@ -600,7 +593,7 @@ void NotifyChangeAsyncCompleteCB(napi_env env, napi_status status, void *data) return; } - result[PARAM0] = GetCallbackErrorValue(env, notifyChangeCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); result[PARAM1] = WrapVoidToJS(env); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -682,20 +675,17 @@ napi_value RegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB * return nullptr; } - onCB->result = NO_ERROR; napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { std::string type = NapiValueToStringUtf8(env, args[PARAM0]); - if (type == "dataChange") { - HILOG_INFO("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); - } else { - HILOG_ERROR("%{public}s, Wrong argument type is %{public}s.", __func__, type.c_str()); - onCB->result = INVALID_PARAMETER; + if (type != "dataChange") { + HILOG_ERROR("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); + return nullptr; } } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - onCB->result = INVALID_PARAMETER; + return nullptr; } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); @@ -704,7 +694,7 @@ napi_value RegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB * HILOG_INFO("%{public}s,uri=%{public}s", __func__, onCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - onCB->result = INVALID_PARAMETER; + return nullptr; } DataAbilityHelper *objectInfo = nullptr; @@ -734,7 +724,6 @@ napi_value RegisterAsync( NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &onCB->cbBase.cbInfo.callback)); } else { HILOG_INFO("not valuetype isn't napi_function"); - onCB->result = INVALID_PARAMETER; } sptr observer(new (std::nothrow) NAPIDataAbilityObserver()); @@ -742,9 +731,7 @@ napi_value RegisterAsync( observer->SetCallbackRef(onCB->cbBase.cbInfo.callback); onCB->observer = observer; - if (onCB->result == NO_ERROR) { - registerInstances_.emplace_back(onCB); - } + registerInstances_.emplace_back(onCB); NAPI_CALL(env, napi_create_async_work( @@ -752,7 +739,9 @@ napi_value RegisterAsync( nullptr, resourceName, RegisterExecuteCB, - RegisterCompleteCB, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("NAPI_Register, main event thread complete."); + }, (void *)onCB, &onCB->cbBase.asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, onCB->cbBase.asyncWork)); @@ -766,31 +755,9 @@ void RegisterExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Register, worker pool thread execute."); DAHelperOnOffCB *onCB = static_cast(data); if (onCB->dataAbilityHelper != nullptr) { - if (onCB->result != INVALID_PARAMETER && !onCB->uri.empty() && onCB->cbBase.cbInfo.callback != nullptr) { - OHOS::Uri uri(onCB->uri); - onCB->dataAbilityHelper->RegisterObserver(uri, onCB->observer); - } else { - HILOG_ERROR("%{public}s, dataAbilityHelper uri is empty or callback is nullptr.", __func__); - } - } -} - -void RegisterCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_Register, main event thread complete."); - DAHelperOnOffCB *onCB = static_cast(data); - if (onCB == nullptr) { - HILOG_ERROR("%{public}s, input params onCB is nullptr.", __func__); - return; + OHOS::Uri uri(onCB->uri); + onCB->dataAbilityHelper->RegisterObserver(uri, onCB->observer); } - if (onCB->result == NO_ERROR) { - return; - } - HILOG_INFO("NAPI_Register, input params onCB is invalid params, will be release"); - onCB->observer->ReleaseJSCallback(); - delete onCB; - onCB = nullptr; - HILOG_INFO("NAPI_Register, main event thread complete over an release invalid onCB."); } /** @@ -851,20 +818,17 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB return nullptr; } - offCB->result = NO_ERROR; napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { std::string type = NapiValueToStringUtf8(env, args[PARAM0]); - if (type == "dataChange") { - HILOG_INFO("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); - } else { - HILOG_ERROR("%{public}s, Wrong argument type %{public}s.", __func__, type.c_str()); - offCB->result = INVALID_PARAMETER; + if (type != "dataChange") { + HILOG_ERROR("%{public}s, Wrong type=%{public}s", __func__, type.c_str()); + return nullptr; } } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - offCB->result = INVALID_PARAMETER; + return nullptr; } offCB->uri = ""; @@ -876,14 +840,11 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB HILOG_INFO("%{public}s,uri=%{public}s", __func__, offCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - offCB->result = INVALID_PARAMETER; + return nullptr; } NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); if (valuetype == napi_function) { NAPI_CALL(env, napi_create_reference(env, args[PARAM2], 1, &offCB->cbBase.cbInfo.callback)); - } else { - HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - offCB->result = INVALID_PARAMETER; } } else { // parse uri or callback @@ -895,7 +856,7 @@ napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &offCB->cbBase.cbInfo.callback)); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - offCB->result = INVALID_PARAMETER; + return nullptr; } } @@ -919,9 +880,7 @@ napi_value UnRegisterAsync( napi_value resourceName = 0; NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - if (offCB->result == NO_ERROR) { - FindRegisterObs(env, offCB); - } + FindRegisterObs(env, offCB); NAPI_CALL(env, napi_create_async_work( @@ -1219,11 +1178,9 @@ static void OnChangeJSThreadWorker(uv_work_t *work, int status) void NAPIDataAbilityObserver::OnChange() { - if (ref_ == nullptr) { - HILOG_ERROR("%{public}s, OnChange ref is nullptr.", __func__); - return; - } + HILOG_INFO("%{public}s, called.", __func__); ChangeWorkPre(); + uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { @@ -1231,12 +1188,14 @@ void NAPIDataAbilityObserver::OnChange() ChangeWorkPreDone(); return; } + uv_work_t *work = new uv_work_t; if (work == nullptr) { HILOG_ERROR("%{public}s, work==nullptr.", __func__); ChangeWorkPreDone(); return; } + DAHelperOnOffCB *onCB = new (std::nothrow) DAHelperOnOffCB; if (onCB == nullptr) { HILOG_ERROR("%{public}s, onCB == nullptr.", __func__); @@ -1251,6 +1210,7 @@ void NAPIDataAbilityObserver::OnChange() onCB->cbBase.cbInfo.callback = ref_; onCB->observer = this; work->data = (void *)onCB; + int rev = uv_queue_work( loop, work, @@ -1318,6 +1278,7 @@ napi_value GetTypeWrap(napi_env env, napi_callback_info info, DAHelperGetTypeCB HILOG_INFO("%{public}s,uri=%{public}s", __func__, gettypeCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + return nullptr; } DataAbilityHelper *objectInfo = nullptr; @@ -1397,14 +1358,8 @@ void GetTypeExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_GetType, worker pool thread execute."); DAHelperGetTypeCB *gettypeCB = static_cast(data); if (gettypeCB->dataAbilityHelper != nullptr) { - gettypeCB->execResult = INVALID_PARAMETER; - if (!gettypeCB->uri.empty()) { - OHOS::Uri uri(gettypeCB->uri); - gettypeCB->result = gettypeCB->dataAbilityHelper->GetType(uri); - gettypeCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_GetType, dataAbilityHelper uri is empty."); - } + OHOS::Uri uri(gettypeCB->uri); + gettypeCB->result = gettypeCB->dataAbilityHelper->GetType(uri); } else { HILOG_ERROR("NAPI_GetType, dataAbilityHelper == nullptr."); } @@ -1422,7 +1377,7 @@ void GetTypeAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, gettypeCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, gettypeCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_string_utf8(env, gettypeCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -1581,18 +1536,10 @@ void GetFileTypesExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_GetFileTypes, worker pool thread execute."); DAHelperGetFileTypesCB *getfiletypesCB = static_cast(data); if (getfiletypesCB->dataAbilityHelper != nullptr) { - getfiletypesCB->execResult = INVALID_PARAMETER; - if (!getfiletypesCB->uri.empty()) { - OHOS::Uri uri(getfiletypesCB->uri); - HILOG_INFO("NAPI_GetFileTypes, uri:%{public}s", uri.ToString().c_str()); - HILOG_INFO("NAPI_GetFileTypes, mimeTypeFilter:%{public}s", getfiletypesCB->mimeTypeFilter.c_str()); - getfiletypesCB->result = getfiletypesCB->dataAbilityHelper->GetFileTypes( - uri, - getfiletypesCB->mimeTypeFilter); - getfiletypesCB->execResult = NO_ERROR; - } else { - HILOG_INFO("NAPI_GetFileTypes, dataAbilityHelper uri is empty."); - } + OHOS::Uri uri(getfiletypesCB->uri); + HILOG_INFO("NAPI_GetFileTypes, uri:%{public}s", uri.ToString().c_str()); + HILOG_INFO("NAPI_GetFileTypes, mimeTypeFilter:%{public}s", getfiletypesCB->mimeTypeFilter.c_str()); + getfiletypesCB->result = getfiletypesCB->dataAbilityHelper->GetFileTypes(uri, getfiletypesCB->mimeTypeFilter); } else { HILOG_INFO("NAPI_GetFileTypes, dataAbilityHelper == nullptr."); } @@ -1611,7 +1558,7 @@ void GetFileTypesAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, getfiletypesCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, getfiletypesCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); result[PARAM1] = WrapGetFileTypesCB(env, *getfiletypesCB); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -1786,13 +1733,9 @@ void NormalizeUriExecuteCB(napi_env env, void *data) DAHelperNormalizeUriCB *normalizeuriCB = static_cast(data); Uri uriValue(normalizeuriCB->uri); if (normalizeuriCB->dataAbilityHelper != nullptr) { - normalizeuriCB->execResult = INVALID_PARAMETER; - if (!normalizeuriCB->uri.empty()) { OHOS::Uri uri(normalizeuriCB->uri); - uriValue = normalizeuriCB->dataAbilityHelper->NormalizeUri(uri); - normalizeuriCB->result = uriValue.ToString(); - normalizeuriCB->execResult = NO_ERROR; - } + uriValue = normalizeuriCB->dataAbilityHelper->NormalizeUri(uri); + normalizeuriCB->result = uriValue.ToString(); } else { HILOG_INFO("NAPI_NormalizeUri, dataAbilityHelper == nullptr"); } @@ -1810,7 +1753,7 @@ void NormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, normalizeuriCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, normalizeuriCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, normalizeuriCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); @@ -1965,15 +1908,9 @@ void DenormalizeUriExecuteCB(napi_env env, void *data) DAHelperDenormalizeUriCB *denormalizeuriCB = static_cast(data); Uri uriValue(denormalizeuriCB->uri); if (denormalizeuriCB->dataAbilityHelper != nullptr) { - denormalizeuriCB->execResult = INVALID_PARAMETER; - if (!denormalizeuriCB->uri.empty()) { - OHOS::Uri uri(denormalizeuriCB->uri); - uriValue = denormalizeuriCB->dataAbilityHelper->DenormalizeUri(uri); - denormalizeuriCB->result = uriValue.ToString(); - denormalizeuriCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_DenormalizeUri, dataAbilityHelper uri is empty"); - } + OHOS::Uri uri(denormalizeuriCB->uri); + uriValue = denormalizeuriCB->dataAbilityHelper->DenormalizeUri(uri); + denormalizeuriCB->result = uriValue.ToString(); } else { HILOG_ERROR("NAPI_DenormalizeUri, dataAbilityHelper == nullptr"); } @@ -1991,7 +1928,7 @@ void DenormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, denormalizeuriCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, denormalizeuriCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, denormalizeuriCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); @@ -2173,14 +2110,8 @@ void DeleteExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Delete, worker pool thread execute."); DAHelperDeleteCB *deleteCB = static_cast(data); if (deleteCB->dataAbilityHelper != nullptr) { - deleteCB->execResult = INVALID_PARAMETER; - if (!deleteCB->uri.empty()) { - OHOS::Uri uri(deleteCB->uri); - deleteCB->result = deleteCB->dataAbilityHelper->Delete(uri, deleteCB->predicates); - deleteCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_Delete, dataAbilityHelper uri is empty"); - } + OHOS::Uri uri(deleteCB->uri); + deleteCB->result = deleteCB->dataAbilityHelper->Delete(uri, deleteCB->predicates); } else { HILOG_ERROR("NAPI_Delete, dataAbilityHelper == nullptr"); } @@ -2198,7 +2129,7 @@ void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, DeleteCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, DeleteCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_int32(env, DeleteCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2369,14 +2300,8 @@ void UpdateExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Update, worker pool thread execute."); DAHelperUpdateCB *updateCB = static_cast(data); if (updateCB->dataAbilityHelper != nullptr) { - updateCB->execResult = INVALID_PARAMETER; - if (!updateCB->uri.empty()) { - OHOS::Uri uri(updateCB->uri); - updateCB->result = updateCB->dataAbilityHelper->Update(uri, updateCB->valueBucket, updateCB->predicates); - updateCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_Update, dataAbilityHelper uri is empty"); - } + OHOS::Uri uri(updateCB->uri); + updateCB->result = updateCB->dataAbilityHelper->Update(uri, updateCB->valueBucket, updateCB->predicates); } else { HILOG_ERROR("NAPI_Update, dataAbilityHelper == nullptr"); } @@ -2394,7 +2319,7 @@ void UpdateAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, updateCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, updateCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_int32(env, updateCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2568,14 +2493,8 @@ void OpenFileExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_OpenFile, worker pool thread execute."); DAHelperOpenFileCB *OpenFileCB = static_cast(data); if (OpenFileCB->dataAbilityHelper != nullptr) { - OpenFileCB->execResult = INVALID_PARAMETER; - if (!OpenFileCB->uri.empty()) { - OHOS::Uri uri(OpenFileCB->uri); - OpenFileCB->result = OpenFileCB->dataAbilityHelper->OpenFile(uri, OpenFileCB->mode); - OpenFileCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_OpenFile, dataAbilityHelper uri is empty"); - } + OHOS::Uri uri(OpenFileCB->uri); + OpenFileCB->result = OpenFileCB->dataAbilityHelper->OpenFile(uri, OpenFileCB->mode); } else { HILOG_ERROR("NAPI_OpenFile, dataAbilityHelper == nullptr"); } @@ -2593,7 +2512,7 @@ void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, OpenFileCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, OpenFileCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_int32(env, OpenFileCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2802,14 +2721,8 @@ void BatchInsertExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_BatchInsert, worker pool thread execute."); DAHelperBatchInsertCB *batchInsertCB = static_cast(data); if (batchInsertCB->dataAbilityHelper != nullptr) { - batchInsertCB->execResult = INVALID_PARAMETER; - if (!batchInsertCB->uri.empty()) { - OHOS::Uri uri(batchInsertCB->uri); - batchInsertCB->result = batchInsertCB->dataAbilityHelper->BatchInsert(uri, batchInsertCB->values); - batchInsertCB->execResult = NO_ERROR; - } else { - HILOG_ERROR("NAPI_BatchInsert, dataAbilityHelper uri is empyt"); - } + OHOS::Uri uri(batchInsertCB->uri); + batchInsertCB->result = batchInsertCB->dataAbilityHelper->BatchInsert(uri, batchInsertCB->values); } else { HILOG_ERROR("NAPI_BatchInsert, dataAbilityHelper == nullptr"); } @@ -2827,7 +2740,7 @@ void BatchInsertAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, BatchInsertCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, BatchInsertCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); napi_create_int32(env, BatchInsertCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -2923,6 +2836,7 @@ napi_value QueryWrap(napi_env env, napi_callback_info info, DAHelperQueryCB *que arrayStringbool = NapiValueToArrayStringUtf8(env, args[PARAM1], result); if (arrayStringbool == false) { HILOG_ERROR("%{public}s, The return value of arraystringbool is false", __func__); + return nullptr; } queryCB->columns = result; for (size_t i = 0; i < queryCB->columns.size(); i++) { @@ -3020,18 +2934,12 @@ void QueryExecuteCB(napi_env env, void *data) HILOG_INFO("NAPI_Query, worker pool thread execute."); DAHelperQueryCB *queryCB = static_cast(data); if (queryCB->dataAbilityHelper != nullptr) { - queryCB->execResult = INVALID_PARAMETER; - if (!queryCB->uri.empty()) { - OHOS::Uri uri(queryCB->uri); - auto resultset = queryCB->dataAbilityHelper->Query(uri, queryCB->columns, queryCB->predicates); - if (resultset != nullptr) { - queryCB->result = resultset; - queryCB->execResult = NO_ERROR; - } else { - HILOG_INFO("NAPI_Query, resultset == nullptr."); - } + OHOS::Uri uri(queryCB->uri); + auto resultset = queryCB->dataAbilityHelper->Query(uri, queryCB->columns, queryCB->predicates); + if (resultset != nullptr) { + queryCB->result = resultset; } else { - HILOG_ERROR("NAPI_Query, dataAbilityHelper uri is empty"); + HILOG_INFO("NAPI_Query, resultset == nullptr."); } } else { HILOG_ERROR("NAPI_Query, dataAbilityHelper == nullptr"); @@ -3050,7 +2958,7 @@ void QueryAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, queryCB->cbBase.cbInfo.callback, &callback)); - result[PARAM0] = GetCallbackErrorValue(env, queryCB->execResult); + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); result[PARAM1] = WrapResultSet(env, queryCB->result); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -3103,8 +3011,8 @@ napi_value NAPI_Release(napi_env env, napi_callback_info info) napi_value ReleaseWrap(napi_env env, napi_callback_info info, DAHelperReleaseCB *releaseCB) { HILOG_INFO("%{public}s,called", __func__); - size_t argcAsync = ARGS_ONE; - const size_t argcPromise = ARGS_ZERO; + size_t argcAsync = ARGS_TWO; + const size_t argcPromise = ARGS_ONE; const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; napi_value args[ARGS_MAX_COUNT] = {nullptr}; napi_value ret = nullptr; @@ -3122,7 +3030,7 @@ napi_value ReleaseWrap(napi_env env, napi_callback_info info, DAHelperReleaseCB releaseCB->dataAbilityHelper = objectInfo; if (argcAsync > argcPromise) { - ret = ReleaseAsync(env, args, PARAM0, releaseCB); + ret = ReleaseAsync(env, args, ARGS_ONE, releaseCB); } else { ret = ReleasePromise(env, releaseCB); } @@ -3314,6 +3222,7 @@ napi_value ExecuteBatchWrap(napi_env env, napi_callback_info info, DAHelperExecu HILOG_INFO("%{public}s,uri=%{public}s", __func__, executeBatchCB->uri.c_str()); } else { HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + return nullptr; } std::vector> operations; @@ -3473,5 +3382,6 @@ void GetDataAbilityResultForResult( } HILOG_INFO("%{public}s, NAPI_ExecuteBatch, getDataAbilityResultForResult end.", __func__); } + } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h index f759e1126c3..b6d469cae42 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.h @@ -233,7 +233,6 @@ napi_value RegisterAsync( * @param data Point to asynchronous processing of data. */ void RegisterExecuteCB(napi_env env, void *data); -void RegisterCompleteCB(napi_env env, napi_status status, void *data); /** * @brief DataAbilityHelper NAPI method : off. diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h index 004dfa0e9a7..490ed709a47 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h @@ -219,7 +219,6 @@ struct DAHelperInsertCB { std::string uri; NativeRdb::ValuesBucket valueBucket; int result = 0; - int execResult; }; class NAPIAbilityConnection; @@ -244,7 +243,6 @@ struct DAHelperNotifyChangeCB { CBBase cbBase; DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; - int execResult; }; class NAPIDataAbilityObserver; @@ -279,7 +277,6 @@ struct DAHelperGetTypeCB { DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; - int execResult; }; struct DAHelperGetFileTypesCB { @@ -288,7 +285,6 @@ struct DAHelperGetFileTypesCB { std::string uri; std::string mimeTypeFilter; std::vector result; - int execResult; }; struct DAHelperNormalizeUriCB { @@ -296,14 +292,12 @@ struct DAHelperNormalizeUriCB { DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; - int execResult; }; struct DAHelperDenormalizeUriCB { CBBase cbBase; DataAbilityHelper *dataAbilityHelper = nullptr; std::string uri; std::string result = ""; - int execResult; }; struct DAHelperDeleteCB { @@ -312,7 +306,6 @@ struct DAHelperDeleteCB { std::string uri; NativeRdb::DataAbilityPredicates predicates; int result = 0; - int execResult; }; struct DAHelperQueryCB { @@ -322,7 +315,6 @@ struct DAHelperQueryCB { std::vector columns; NativeRdb::DataAbilityPredicates predicates; std::shared_ptr result; - int execResult; }; struct DAHelperUpdateCB { @@ -332,7 +324,6 @@ struct DAHelperUpdateCB { NativeRdb::ValuesBucket valueBucket; NativeRdb::DataAbilityPredicates predicates; int result = 0; - int execResult; }; struct DAHelperBatchInsertCB { CBBase cbBase; @@ -340,7 +331,6 @@ struct DAHelperBatchInsertCB { std::string uri; std::vector values; int result = 0; - int execResult; }; struct DAHelperOpenFileCB { CBBase cbBase; @@ -348,7 +338,6 @@ struct DAHelperOpenFileCB { std::string uri; std::string mode; int result = 0; - int execResult; }; struct DAHelperReleaseCB { diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp index 5523120a439..a3da91d6624 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -2386,7 +2386,7 @@ void StartAbilityPromiseCompletedCB(napi_env env, napi_status status, void *data napi_value StartAbilityAsync( napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo) { - HILOG_INFO("%{public}s asyncCallback.", __func__); + HILOG_INFO("%{public}s async call.", __func__); if (args == nullptr || asyncCallbackInfo == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; @@ -2410,13 +2410,13 @@ napi_value StartAbilityAsync( &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - HILOG_INFO("%{public}s asyncCallback end.", __func__); + HILOG_INFO("%{public}s async end.", __func__); return WrapVoidToJS(env); } napi_value StartAbilityPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) { - HILOG_INFO("%{public}s, promise.", __func__); + HILOG_INFO("%{public}s promise call.", __func__); if (asyncCallbackInfo == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; @@ -2437,7 +2437,7 @@ napi_value StartAbilityPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInf (void *)asyncCallbackInfo, &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - HILOG_INFO("%{public}s, end.", __func__); + HILOG_INFO("%{public}s promise end.", __func__); return promise; } @@ -3449,17 +3449,7 @@ napi_value AcquireDataAbilityHelperWrap(napi_env env, napi_callback_info info, D NAPI_CALL(env, napi_new_instance(env, *(GetGlobalDataAbilityHelper()), 1, &args[PARAM0], &result)); if (!IsTypeForNapiValue(env, result, napi_object)) { - HILOG_ERROR("%{public}s, IsTypeForNapiValue isn`t object", __func__); - return nullptr; - } - - if (IsTypeForNapiValue(env, result, napi_null)) { - HILOG_ERROR("%{public}s, IsTypeForNapiValue is null", __func__); - return nullptr; - } - - if (IsTypeForNapiValue(env, result, napi_undefined)) { - HILOG_ERROR("%{public}s, IsTypeForNapiValue is undefined", __func__); + HILOG_ERROR("%{public}s, IsTypeForNapiValue retval is false", __func__); return nullptr; } diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h index 30e3d69e068..8ef50d7d2c8 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_data.h @@ -33,17 +33,16 @@ namespace AppExecFwk { #define ARGS_MAX_COUNT 10 #define ARGS_ASYNC_COUNT 1 -constexpr unsigned int ARGS_ZERO = 0; -constexpr unsigned int ARGS_ONE = 1; -constexpr unsigned int ARGS_TWO = 2; -constexpr unsigned int ARGS_THREE = 3; -constexpr unsigned int ARGS_FOUR = 4; -constexpr unsigned int ARGS_FIVE = 5; -constexpr unsigned int ARGS_SIX = 6; -constexpr unsigned int ARGS_SEVEN = 7; -constexpr unsigned int ARGS_EIGHT = 8; -constexpr unsigned int ARGS_NINE = 9; -constexpr unsigned int ARGS_TEN = 10; +#define ARGS_ONE 1 +#define ARGS_TWO 2 +#define ARGS_THREE 3 +#define ARGS_FOUR 4 +#define ARGS_FIVE 5 +#define ARGS_SIX 6 +#define ARGS_SEVEN 7 +#define ARGS_EIGHT 8 +#define ARGS_NINE 9 +#define ARGS_TEN 10 #define PARAM0 0 #define PARAM1 1 diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index a93b50e557b..fa18e945abc 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -360,11 +360,11 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, return INNER_ERR; } if (!data.WriteParcelable(token) || !data.WriteInt32(state)) { - HILOG_ERROR("data write failed."); + HILOG_ERROR("token or state write failed."); return INNER_ERR; } if (!data.WriteParcelable(&saveData)) { - HILOG_ERROR("data write failed."); + HILOG_ERROR("saveData write failed."); return INNER_ERR; } error = Remote()->SendRequest(IAbilityManager::ABILITY_TRANSITION_DONE, data, reply, option); @@ -2229,4 +2229,4 @@ bool AbilityManagerProxy::IsRunningInStabilityTest() return reply.ReadBool(); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 1e2ecf9de5d..1c3a4e3511b 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -231,8 +231,9 @@ int AbilityManagerService::StartAbility( const Want &want, const sptr &callerToken, int requestCode, int callerUid) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("%{public}s", __func__); + HILOG_INFO("%{public}s begin.", __func__); if (callerToken != nullptr && !VerificationToken(callerToken)) { + HILOG_ERROR("%{public}s VerificationToken failed.", __func__); return ERR_INVALID_VALUE; } AbilityRequest abilityRequest; @@ -248,38 +249,44 @@ int AbilityManagerService::StartAbility( return result; } auto type = abilityInfo.type; + HILOG_INFO("%{public}s Current ability type:%{public}d", __func__, type); if (type == AppExecFwk::AbilityType::DATA) { HILOG_ERROR("Cannot start data ability, use 'AcquireDataAbility()' instead."); return ERR_INVALID_VALUE; } if (!AbilityUtil::IsSystemDialogAbility(abilityInfo.bundleName, abilityInfo.name)) { + HILOG_INFO("%{public}s PreLoadAppDataAbilities:%{public}s", __func__, abilityInfo.bundleName.c_str()); result = PreLoadAppDataAbilities(abilityInfo.bundleName); if (result != ERR_OK) { HILOG_ERROR("StartAbility: App data ability preloading failed, '%{public}s', %{public}d", - abilityInfo.bundleName.c_str(), - result); + abilityInfo.bundleName.c_str(), result); return result; } } if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) { + HILOG_INFO("%{public}s Start SERVICE or EXTENSION", __func__); return connectManager_->StartAbility(abilityRequest); } if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { + HILOG_ERROR("IsAbilityControllerStart failed: %{public}s", abilityInfo.bundleName.c_str()); return ERR_WOULD_BLOCK; } if (useNewMission_) { if (IsSystemUiApp(abilityRequest.abilityInfo)) { + HILOG_INFO("%{public}s NewMission Start SystemUiApp", __func__); return kernalAbilityManager_->StartAbility(abilityRequest); } + HILOG_INFO("%{public}s StartAbility by MissionList", __func__); return currentMissionListManager_->StartAbility(abilityRequest); } else { if (IsSystemUiApp(abilityRequest.abilityInfo)) { + HILOG_INFO("%{public}s OldMission Start SystemUiApp", __func__); return systemAppManager_->StartAbility(abilityRequest); } - + HILOG_INFO("%{public}s StartAbility by StackManager", __func__); return currentStackManager_->StartAbility(abilityRequest); } } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index f8d4d9f72e9..4a46419c76d 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -155,7 +155,7 @@ int32_t AbilityRecord::GetUid() int AbilityRecord::LoadAbility() { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("%s", __func__); + HILOG_INFO("%{public}s", __func__); startTime_ = AbilityUtil::SystemTimeMillis(); CHECK_POINTER_AND_RETURN(token_, ERR_INVALID_VALUE); std::string appName = applicationInfo_.name; diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 2af8ceb8462..b091bb8ae6a 100755 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -266,7 +266,7 @@ int AbilitySchedulerProxy::OpenFile(const Uri &uri, const std::string &mode) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_OPENFILE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("OpenFile fail to SendRequest. err: %d", err); - return fd; + return err; } fd = reply.ReadFileDescriptor(); @@ -315,7 +315,6 @@ int AbilitySchedulerProxy::OpenRawFile(const Uri &uri, const std::string &mode) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_OPENRAWFILE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("OpenFile fail to SendRequest. err: %d", err); - return fd; } if (!reply.ReadInt32(fd)) { @@ -359,7 +358,7 @@ int AbilitySchedulerProxy::Insert(const Uri &uri, const NativeRdb::ValuesBucket int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_INSERT, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Insert fail to SendRequest. err: %d", err); - return index; + return err; } if (!reply.ReadInt32(index)) { @@ -409,7 +408,7 @@ int AbilitySchedulerProxy::Update(const Uri &uri, const NativeRdb::ValuesBucket int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_UPDATE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Update fail to SendRequest. err: %d", err); - return index; + return err; } if (!reply.ReadInt32(index)) { @@ -453,7 +452,6 @@ int AbilitySchedulerProxy::Delete(const Uri &uri, const NativeRdb::DataAbilityPr int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_DELETE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("Delete fail to SendRequest. err: %d", err); - return index; } if (!reply.ReadInt32(index)) { @@ -535,7 +533,6 @@ std::string AbilitySchedulerProxy::GetType(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_GETTYPE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); - return type; } type = reply.ReadString(); @@ -582,7 +579,6 @@ bool AbilitySchedulerProxy::Reload(const Uri &uri, const PacMap &extras) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_RELOAD, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); - return ret; } ret = reply.ReadBool(); @@ -635,7 +631,6 @@ int AbilitySchedulerProxy::BatchInsert(const Uri &uri, const std::vectorSendRequest(IAbilityScheduler::SCHEDULE_BATCHINSERT, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("GetFileTypes fail to SendRequest. err: %d", err); - return ret; } if (!reply.ReadInt32(ret)) { @@ -835,7 +830,6 @@ Uri AbilitySchedulerProxy::NormalizeUri(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_NORMALIZEURI, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("NormalizeUri fail to SendRequest. err: %d", err); - return Uri(""); } std::unique_ptr info(reply.ReadParcelable()); @@ -876,7 +870,6 @@ Uri AbilitySchedulerProxy::DenormalizeUri(const Uri &uri) int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_DENORMALIZEURI, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("DenormalizeUri fail to SendRequest. err: %d", err); - return Uri(""); } std::unique_ptr info(reply.ReadParcelable()); @@ -919,7 +912,6 @@ std::vector> AbilitySchedulerProx int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_EXECUTEBATCH, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("AbilitySchedulerProxy::ExecuteBatch fail to SendRequest. err: %{public}d", err); - return results; } int total = 0; diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index aa18c27c53d..aa0e7774230 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -203,10 +203,6 @@ int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &repl return ERR_INVALID_VALUE; } int fd = OpenFile(*uri, mode); - if (fd < 0) { - HILOG_ERROR("OpenFile fail, fd is %{pubilc}d", fd); - return ERR_INVALID_VALUE; - } if (!reply.WriteFileDescriptor(fd)) { HILOG_ERROR("fail to WriteFileDescriptor fd"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/ability_stack_manager.cpp b/services/abilitymgr/src/ability_stack_manager.cpp index bce2de61c80..4ae2b321f4f 100644 --- a/services/abilitymgr/src/ability_stack_manager.cpp +++ b/services/abilitymgr/src/ability_stack_manager.cpp @@ -82,7 +82,7 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) bool result = whiteList->FindBundleNameOnWhiteList(abilityRequest.abilityInfo.bundleName, isAwakenScreen); whiteList.reset(); if (!result) { - HILOG_DEBUG("the ability is not on the white list..."); + HILOG_ERROR("the ability is not on the white list..."); return START_ABILITY_NOT_ONTHE_WHITELIST; } } @@ -90,6 +90,7 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) auto currentTopAbilityRecord = GetCurrentTopAbility(); if (!CanStartInLockMissionState(abilityRequest, currentTopAbilityRecord)) { SendUnlockMissionMessage(); + HILOG_ERROR("the ability can not start InLockMissionState"); return LOCK_MISSION_STATE_DENY_REQUEST; } @@ -103,7 +104,9 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) } if (!waittingAbilityQueue_.empty()) { - HILOG_INFO("Waiting queue is not empty, so enqueue ability for waiting."); + auto top = waittingAbilityQueue_.front().abilityInfo.name; + HILOG_INFO("Waiting queue not empty(%{public}s), enqueue(%{public}s) for waiting.", + top.c_str(), abilityRequest.abilityInfo.name.c_str()); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -113,7 +116,8 @@ int AbilityStackManager::StartAbility(const AbilityRequest &abilityRequest) HILOG_DEBUG("current top: %{public}s", element.c_str()); auto targetState = currentTopAbilityRecord->IsNewVersion() ? FOREGROUND_NEW : ACTIVE; if (currentTopAbilityRecord->GetAbilityState() != targetState) { - HILOG_INFO("Top ability is not active, so enqueue ability for waiting."); + HILOG_INFO("Top ability is not active(%{public}s), enqueue(%{public}s) for waiting.", + currentTopAbilityRecord->GetAbilityInfo().name.c_str(), abilityRequest.abilityInfo.name.c_str()); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -134,7 +138,8 @@ int AbilityStackManager::StartAbilityLocked( } else { auto lockTopAbilityRecord = lockScreenMissionStack_->GetTopAbilityRecord(); if (lockTopAbilityRecord && lockTopAbilityRecord->GetAbilityState() != ACTIVE) { - HILOG_INFO("lock screen stack top ability is not active, so enqueue ability for waiting."); + HILOG_INFO("lock screen stack top ability not active(%{public}s), enqueue(%{public}s) for waiting.", + lockTopAbilityRecord->GetAbilityInfo().name.c_str(), abilityRequest.abilityInfo.name.c_str()); EnqueueWaittingAbility(abilityRequest); return START_ABILITY_WAITING; } @@ -145,14 +150,14 @@ int AbilityStackManager::StartAbilityLocked( if (abilityRequest.startSetting && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp) { auto windowkey = static_cast( std::atoi(abilityRequest.startSetting->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY).c_str())); - HILOG_DEBUG("Start ability with settings ..."); if (windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING || windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || windowkey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) { + HILOG_INFO("Start ability AsMultiWindow: %{public}d", windowkey); return StartAbilityAsMultiWindowLocked(currentTopAbility, abilityRequest); } } - + HILOG_INFO("Start ability AsDefault."); return StartAbilityAsDefaultLocked(currentTopAbility, abilityRequest); } @@ -188,11 +193,11 @@ int AbilityStackManager::StartAbilityAsDefaultLocked( // 4. start processing ability lifecycle if (currentTopAbility == nullptr) { - // top ability is null, then launch the first Ability. + HILOG_INFO("top ability is null, then launch the first Ability."); targetAbilityRecord->SetLauncherRoot(); return targetAbilityRecord->LoadAbility(); } else { - // complete ability background if needed. + HILOG_INFO("top ability not null, complete ability background if needed."); return StartAbilityLifeCycle(lastTopAbility, currentTopAbility, targetAbilityRecord); } } diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index cad08adfb86..5757bd929cd 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -59,6 +59,7 @@ void AmsMgrScheduler::LoadAbility(const sptr &token, const sptr &app) { if (!IsReady()) { + APP_LOGE("AttachApplication failed, not ready."); return; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 1323c9035a9..7fd28d854e2 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -78,6 +78,7 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); if (!CheckLoadabilityConditions(token, abilityInfo, appInfo)) { + APP_LOGE("CheckLoadabilityConditions failed"); return; } @@ -89,6 +90,7 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; if (!GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)) { + APP_LOGE("GetBundleAndHapInfo failed"); return; } @@ -102,14 +104,11 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt appRecord = CreateAppRunningRecord(token, preToken, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo); if (!appRecord) { - APP_LOGI("appRecord is nullptr"); + APP_LOGI("CreateAppRunningRecord failed, appRecord is nullptr"); return; } - StartProcess(abilityInfo->applicationName, - processName, - appRecord, - abilityInfo->applicationInfo.uid, - abilityInfo->applicationInfo.bundleName); + StartProcess(abilityInfo->applicationName, processName, appRecord, + abilityInfo->applicationInfo.uid, abilityInfo->applicationInfo.bundleName); } else { StartAbility(token, preToken, abilityInfo, appRecord, hapModuleInfo); } @@ -210,7 +209,7 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptrGetState() != ApplicationState::APP_STATE_CREATE) { - APP_LOGE("wrong app state"); + APP_LOGE("wrong app state:%{public}d", appRecord->GetState()); return; } appRecord->LaunchApplication(); @@ -1203,9 +1202,8 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); return; } - APP_LOGI("newPid %{public}d", pid); + APP_LOGI("newPid:%{public}d uid:%{public}d", pid, startMsg.uid); appRecord->GetPriorityObject()->SetPid(pid); - APP_LOGI("app uid %{public}d", startMsg.uid); appRecord->SetUid(startMsg.uid); OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); appRecord->SetAppMgrServiceInner(weak_from_this()); -- Gitee From 389c7cfd57736f7484a47db3114d93d4b5e06478 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Sat, 22 Jan 2022 23:01:38 +0800 Subject: [PATCH 4/5] codex Signed-off-by: hanhaibin --- frameworks/kits/appkit/BUILD.gn | 4 +- .../include/ability_delegator.h | 6 +- .../include/ability_delegator_args.h | 3 +- .../include/ability_delegator_registry.h | 3 +- .../include/delegator_thread.h | 3 +- .../include/iability_monitor.h | 3 +- .../include/shell_cmd_result.h | 3 +- .../ability_delegator/include/test_runner.h | 3 +- .../src/ability_delegator.cpp | 94 +++++++++++++------ 9 files changed, 75 insertions(+), 47 deletions(-) diff --git a/frameworks/kits/appkit/BUILD.gn b/frameworks/kits/appkit/BUILD.gn index 7545a3abbaf..ad929a68f6b 100644 --- a/frameworks/kits/appkit/BUILD.gn +++ b/frameworks/kits/appkit/BUILD.gn @@ -122,11 +122,11 @@ ohos_shared_library("appkit_native") { "${aafwk_path}/frameworks/kits/appkit/native/app/src/context_container.cpp", #"${aafwk_path}/frameworks/kits/appkit/native/app/main.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app/ability_stage.cpp", diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h index e085018dc45..01d737fb28d 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h @@ -36,11 +36,9 @@ namespace OHOS { namespace AppExecFwk { -class AbilityDelegator : public AbilityLifecycleCallbacks, public std::enable_shared_from_this -{ +class AbilityDelegator : public AbilityLifecycleCallbacks, public std::enable_shared_from_this { public: - enum class AbilityState : uint8_t - { + enum class AbilityState : uint8_t { UNINITIALIZED = 0, STARTED, FOREGROUND, diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h index b2051b25cc3..50196abd059 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h @@ -21,8 +21,7 @@ namespace OHOS { namespace AppExecFwk { -class AbilityDelegatorArgs -{ +class AbilityDelegatorArgs { public: static const std::string KEY_TEST_RUNNER_CLASS; static const std::string KEY_TEST_CASE; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h index 6005d869ecc..6b40a7d135b 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h @@ -22,8 +22,7 @@ namespace OHOS { namespace AppExecFwk { -class AbilityDelegatorRegistry -{ +class AbilityDelegatorRegistry { public: static std::shared_ptr GetAbilityDelegator(); static std::shared_ptr GetArguments(); diff --git a/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h index 57333c0a57c..136c60dd2db 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h @@ -24,8 +24,7 @@ namespace OHOS { namespace AppExecFwk { -class DelegatorThread -{ +class DelegatorThread { public: using DTask = std::function; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h index b4ec25ebc68..00a01e0dea9 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h @@ -28,8 +28,7 @@ namespace OHOS { namespace AppExecFwk { -class IAbilityMonitor -{ +class IAbilityMonitor { public: static constexpr int64_t MAX_TIME_OUT {5000}; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h index 4bcb01bb0e2..cd51088c132 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h @@ -20,8 +20,7 @@ namespace OHOS { namespace AppExecFwk { -class ShellCmdResult -{ +class ShellCmdResult { public: ShellCmdResult() = default; ShellCmdResult(const int32_t exitCode, const std::string &stdResult); diff --git a/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h index 2bdbb4b0795..88151dc5bbf 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h @@ -24,8 +24,7 @@ class Runtime; } namespace AppExecFwk { -class TestRunner -{ +class TestRunner { public: static std::unique_ptr Create(const std::unique_ptr& runtime); diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp index df0c8b61bfc..17651531975 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -14,22 +14,10 @@ */ #include -#include "ability_delegator.h" #include "app_log_wrapper.h" #include "ohos_application.h" #include "ability_manager_client.h" - -#define RETURN_IF_NULL_POINTER(pointer) \ - if (!(pointer)) { \ - APP_LOGW("Invalid input parameter"); \ - return; \ - } - -#define RETURN_IF_EMPTY_MONITORS() \ - if (abilityMonitors_.empty()) { \ - APP_LOGW("Empty abilityMonitors"); \ - return; \ - } +#include "ability_delegator.h" namespace OHOS { namespace AppExecFwk { @@ -251,10 +239,16 @@ void AbilityDelegator::Print(const std::string &msg) void AbilityDelegator::PrePerformStart(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -268,10 +262,16 @@ void AbilityDelegator::PrePerformStart(const std::shared_ptr &ability) void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -284,10 +284,16 @@ void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) void AbilityDelegator::PrePerformScenceCreated(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -301,10 +307,16 @@ void AbilityDelegator::PrePerformScenceCreated(const std::shared_ptr &a void AbilityDelegator::PrePerformScenceRestored(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -318,10 +330,16 @@ void AbilityDelegator::PrePerformScenceRestored(const std::shared_ptr & void AbilityDelegator::PrePerformScenceDestroyed(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -335,10 +353,16 @@ void AbilityDelegator::PrePerformScenceDestroyed(const std::shared_ptr void AbilityDelegator::PrePerformForeground(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -352,10 +376,16 @@ void AbilityDelegator::PrePerformForeground(const std::shared_ptr &abil void AbilityDelegator::PrePerformBackground(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { @@ -369,10 +399,16 @@ void AbilityDelegator::PrePerformBackground(const std::shared_ptr &abil void AbilityDelegator::PrePerformStop(const std::shared_ptr &ability) { - RETURN_IF_NULL_POINTER(ability) + if (!ability) { + APP_LOGW("Invalid input parameter"); + return; + } std::unique_lock lck(mutexMonitor_); - RETURN_IF_EMPTY_MONITORS() + if (abilityMonitors_.empty()) { + APP_LOGW("Empty abilityMonitors"); + return; + } for (auto &monitor : abilityMonitors_) { if (!monitor) { -- Gitee From 4e5cdad15ac74c077e7bf64f5e56e947fa6b2897 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Sat, 22 Jan 2022 23:16:47 +0800 Subject: [PATCH 5/5] codex Signed-off-by: hanhaibin --- .../appkit/native/ability_delegator/src/ability_delegator.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp index 17651531975..0d909a88d73 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include #include "app_log_wrapper.h" #include "ohos_application.h" #include "ability_manager_client.h" -- Gitee