From 026f30f9982e96b7af51f40a56719fd066d49eb4 Mon Sep 17 00:00:00 2001 From: chensi10 Date: Tue, 14 Sep 2021 22:22:11 +0800 Subject: [PATCH] test Signed-off-by: chensi10 --- .../kits/ability/native/include/ability.h | 11 +- .../kits/ability/native/src/ability.cpp | 213 +- .../ability/native/src/ability_context.cpp | 9 + .../ability/native/src/ability_process.cpp | 8 +- .../ability/native/src/ability_thread.cpp | 30 + .../native/src/form_provider_client.cpp | 11 +- .../ability/native/src/page_ability_impl.cpp | 1 + .../cpp/src/ohos/aafwk/content/pac_map.cpp | 110 +- .../src/ohos/aafwk/content/want_params.cpp | 15 - .../kits/js/@ohos.ability.featureAbility.d.ts | 108 +- .../js/@ohos.ability.particleAbility.d.ts | 43 +- .../kits/js/@ohos.ability.wantConstant.d.ts | 2 +- .../kits/js/@ohos.app.abilityManager.d.ts | 10 +- interfaces/kits/js/@ohos.bundle.d.ts | 582 ++-- .../kits/js/ability/dataAbilityHelper.d.ts | 2 +- .../js/ability/startAbilityParameter.d.ts | 6 +- interfaces/kits/js/ability/want.d.ts | 2 +- .../kits/js/app/abilityMissionInfo.d.ts | 54 +- interfaces/kits/js/app/activeProcessInfo.d.ts | 3 +- .../kits/js/app/activeServiceAbilityInfo.d.ts | 55 + interfaces/kits/js/app/context.d.ts | 97 +- interfaces/kits/js/app/memoryMapInfo.d.ts | 63 + .../app/missionSnapshot.d.ts} | 24 +- interfaces/kits/js/app/processErrorInfo.d.ts | 56 + interfaces/kits/js/app/processInfo.d.ts | 44 - interfaces/kits/js/app/splitMissionInfo.d.ts | 47 + .../systemMemoryAttr.d.ts} | 76 +- interfaces/kits/js/bundle/abilityInfo.d.ts | 303 +- .../kits/js/bundle/applicationInfo.d.ts | 179 +- interfaces/kits/js/bundle/bundleInfo.d.ts | 311 +- .../kits/js/bundle/bundleInstaller.d.ts | 191 +- interfaces/kits/js/bundle/customizeData.d.ts | 18 + interfaces/kits/js/bundle/elementName.d.ts | 44 +- interfaces/kits/js/bundle/hapModuleInfo.d.ts | 116 + interfaces/kits/js/bundle/moduleInfo.d.ts | 25 +- .../kits/js/bundle/moduleUsageRecord.d.ts | 73 + interfaces/kits/js/bundle/shortcutInfo.d.ts | 80 +- interfaces/kits/napi/aafwk/context/BUILD.gn | 51 - .../kits/napi/aafwk/context/napi_context.cpp | 876 ----- .../kits/napi/aafwk/context/napi_context.h | 205 -- .../kits/napi/aafwk/featureAbility/BUILD.gn | 1 + .../aafwk/featureAbility/feature_ability.cpp | 149 +- .../aafwk/featureAbility/feature_ability.h | 64 +- .../feature_ability_constant.cpp | 73 + .../feature_ability_constant.h} | 48 +- .../aafwk/featureAbility/napi_context.cpp | 1807 +++++++++- .../napi/aafwk/featureAbility/napi_context.h | 51 +- .../napi_data_ability_helper.cpp | 159 +- .../aafwk/featureAbility/native_module.cpp | 2 + .../aafwk/formAbility/napi_form_ability.cpp | 41 +- .../napi/aafwk/inner/napi_common/BUILD.gn | 2 + .../napi_common/feature_ability_common.h | 5 + .../inner/napi_common/napi_common_ability.cpp | 2915 +++++------------ .../inner/napi_common/napi_common_ability.h | 85 +- .../particleAbility/particle_ability.cpp | 81 +- ohos.build | 3 +- services/abilitymgr/BUILD.gn | 21 +- services/abilitymgr/abilitymgr.gni | 1 + .../include/ability_manager_service.h | 24 +- .../include/ams_configuration_parameter.h | 85 + .../resource/ams_service_config.json | 8 + .../src/ability_manager_service.cpp | 151 +- .../abilitymgr/src/ability_stack_manager.cpp | 6 +- .../src/ams_configuration_parameter.cpp | 97 + .../ability_manager_service_test.cpp | 46 + .../ability_mgr_module_test.cpp | 47 + tools/zip/src/file_path.cpp | 24 +- tools/zip/src/zip.cpp | 4 + 68 files changed, 5360 insertions(+), 4794 deletions(-) mode change 100755 => 100644 interfaces/kits/js/@ohos.ability.featureAbility.d.ts mode change 100644 => 100755 interfaces/kits/js/app/abilityMissionInfo.d.ts mode change 100644 => 100755 interfaces/kits/js/app/activeProcessInfo.d.ts create mode 100755 interfaces/kits/js/app/activeServiceAbilityInfo.d.ts create mode 100755 interfaces/kits/js/app/memoryMapInfo.d.ts rename interfaces/kits/{napi/aafwk/context/napi_error.h => js/app/missionSnapshot.d.ts} (52%) mode change 100644 => 100755 create mode 100755 interfaces/kits/js/app/processErrorInfo.d.ts delete mode 100644 interfaces/kits/js/app/processInfo.d.ts create mode 100755 interfaces/kits/js/app/splitMissionInfo.d.ts rename interfaces/kits/js/{ability/connectOptions.d.ts => app/systemMemoryAttr.d.ts} (46%) mode change 100644 => 100755 create mode 100644 interfaces/kits/js/bundle/hapModuleInfo.d.ts delete mode 100644 interfaces/kits/napi/aafwk/context/BUILD.gn delete mode 100644 interfaces/kits/napi/aafwk/context/napi_context.cpp delete mode 100644 interfaces/kits/napi/aafwk/context/napi_context.h create mode 100644 interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.cpp rename interfaces/kits/napi/aafwk/{context/native_module.cpp => featureAbility/feature_ability_constant.h} (49%) mode change 100644 => 100755 ohos.build create mode 100644 services/abilitymgr/include/ams_configuration_parameter.h create mode 100644 services/abilitymgr/resource/ams_service_config.json create mode 100644 services/abilitymgr/src/ams_configuration_parameter.cpp diff --git a/frameworks/kits/ability/native/include/ability.h b/frameworks/kits/ability/native/include/ability.h index 42140a34c30..a02f029c2d5 100755 --- a/frameworks/kits/ability/native/include/ability.h +++ b/frameworks/kits/ability/native/include/ability.h @@ -74,6 +74,8 @@ class Ability : public IAbilityEvent, public IAbilityContinuation, public std::enable_shared_from_this { public: + friend class PageAbilityImpl; + Ability() = default; virtual ~Ability() = default; @@ -724,7 +726,6 @@ public: */ virtual ContinuationState GetContinuationState() final; - /** * @brief Obtains the singleton AbilityPackage object to which this ability belongs. * @@ -1280,6 +1281,13 @@ private: bool VerifySupportForContinuation(); void HandleCreateAsContinuation(const Want &want); bool IsFlagExists(int flag, int flagSet); + /** + * @brief Set the start ability setting. + * @param setting the start ability setting. + */ + void SetStartAbilitySetting(std::shared_ptr setting); + +private: std::shared_ptr continuationHandler_ = nullptr; std::shared_ptr continuationManager_ = nullptr; std::shared_ptr continuationRegisterManager_ = nullptr; @@ -1293,6 +1301,7 @@ private: std::shared_ptr abilityWindow_ = nullptr; std::shared_ptr setWant_ = nullptr; sptr reverseContinuationSchedulerReplica_ = nullptr; + std::shared_ptr setting_ = nullptr; bool bWindowFocus_ = false; static const std::string SYSTEM_UI; diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index d2ae59a1d5f..a09913e2391 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include "ability.h" @@ -150,8 +151,7 @@ void Ability::OnStart(const Want &want) winType = OHOS::WindowType::WINDOW_TYPE_ALARM_SCREEN; } - if (abilityInfo_->bundleName == DEVICE_MANAGER_BUNDLE_NAME && - abilityInfo_->name == DEVICE_MANAGER_NAME) { + if (abilityInfo_->bundleName == DEVICE_MANAGER_BUNDLE_NAME && abilityInfo_->name == DEVICE_MANAGER_NAME) { winType = OHOS::WindowType::WINDOW_TYPE_ALARM_SCREEN; } @@ -161,6 +161,18 @@ void Ability::OnStart(const Want &want) abilityInfo_->name.c_str(), winType); + if (setting_ != nullptr) { + auto windowMode = static_cast( + std::atoi(setting_->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY).c_str())); + APP_LOGI("%{public}s windowMode : %{public}d", __func__, windowMode); + if (windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) { + APP_LOGI("%{public}s begin SetWindowMode : WINDOW_MODE_FREE.", __func__); + config->SetWindowType(WINDOW_TYPE_FLOAT); + APP_LOGI("%{public}s end SetWindowMode : WINDOW_MODE_FREE.", __func__); + } + } else { + APP_LOGI("Ability::OnStart setting_ == nullptr."); + } SetUIContent(config); if (abilityWindow_ != nullptr) { @@ -169,7 +181,6 @@ void Ability::OnStart(const Want &want) APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityStart.", __func__); } } - // should called in ace ability onStart methord. SetWant(want); if (abilityLifecycleExecutor_ == nullptr) { @@ -1454,7 +1465,7 @@ bool Ability::OnSaveData(WantParams &saveData) } /** - * @brief After creating the Ability on the remote device, + * @brief After creating the Ability on the remote device, * immediately restore the user data saved during the migration of the Ability on the remote device. * @param restoreData Indicates the user data to be restored. * @return If the data is restored successfully, it returns true; otherwise, it returns false . @@ -1637,7 +1648,7 @@ bool Ability::ReleaseForm(const int64_t formId, const bool isReleaseCache) APP_LOGI("%{public}s called.", __func__); // release form with formId and specifies whether to release the cache - return DeleteForm(formId, isReleaseCache ? RELEASE_CACHED_FORM : RELEASE_FORM); + return DeleteForm(formId, isReleaseCache ? RELEASE_CACHED_FORM : RELEASE_FORM); } /** @@ -1671,18 +1682,18 @@ bool Ability::DeleteForm(const int64_t formId) * @brief Cast temp form with formId. * * @param formId Indicates the form's ID. - * + * * @return Returns {@code true} if the form is successfully casted; returns {@code false} otherwise. */ bool Ability::CastTempForm(const int64_t formId) { - APP_LOGI("%{public}s start",__func__); + APP_LOGI("%{public}s start", __func__); if (formId <= 0) { APP_LOGE("%{public}s error, passing in form id can't be negative.", __func__); return false; } - //APP_LOGI("%{public}s, castTempForm begin of temp form %{public}lld", __func__, formId); + APP_LOGI("%{public}s, castTempForm begin of temp form %{public}" PRId64 "", __func__, formId); bool result = FormMgr::GetInstance().CastTempForm(formId, FormHostClient::GetInstance()); @@ -1693,7 +1704,7 @@ bool Ability::CastTempForm(const int64_t formId) userReqParams_[formId].SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, false); - APP_LOGI("%{public}s end",__func__); + APP_LOGI("%{public}s end", __func__); return true; } @@ -1725,7 +1736,7 @@ bool Ability::AcquireForm(const int64_t formId, const Want &want, const std::sha } // check form id - //APP_LOGD("%{public}s, param of formId %{public}lld.", __func__, formId); + APP_LOGD("%{public}s, param of formId %{public}" PRId64 ".", __func__, formId); if (formId < 0) { APP_LOGE("%{public}s error, form id should not be negative.", __func__); return false; @@ -1740,7 +1751,12 @@ bool Ability::AcquireForm(const int64_t formId, const Want &want, const std::sha ElementName elementName = want.GetElement(); std::string bundleName = elementName.GetBundleName(); std::string abilityName = elementName.GetAbilityName(); - //APP_LOGI("%{public}s, begin to acquire form, bundleName is %{public}s, abilityName is %{public}s, formId is %{public}lld.",__func__, bundleName.c_str(), abilityName.c_str(), formId); + APP_LOGI("%{public}s, begin to acquire form, bundleName is %{public}s, abilityName is %{public}s, formId is " + "%{public}lld.", + __func__, + bundleName.c_str(), + abilityName.c_str(), + formId); // hostClient init sptr formHostClient = FormHostClient::GetInstance(); @@ -1755,8 +1771,9 @@ bool Ability::AcquireForm(const int64_t formId, const Want &want, const std::sha APP_LOGE("%{public}s error, acquire form for fms failed.", __func__); return false; } - // APP_LOGI("%{public}s, end to acquire form, the formId returned from the fms is %{public}lld.", - // __func__, formJsInfo.formId); + APP_LOGI("%{public}s, end to acquire form, the formId returned from the fms is %{public}lld.", + __func__, + formJsInfo.formId); // check for form presence in hostForms if (formHostClient->ContainsForm(formJsInfo.formId)) { @@ -1769,7 +1786,7 @@ bool Ability::AcquireForm(const int64_t formId, const Want &want, const std::sha formHostClient->AddForm(thisAbility, formJsInfo.formId); // post the async task of handleAcquireResult - PostTask([this, want, formJsInfo, callback]() {HandleAcquireResult(want, formJsInfo, callback);}, 0L); + PostTask([this, want, formJsInfo, callback]() { HandleAcquireResult(want, formJsInfo, callback); }, 0L); // the acquire form is successfully return true; @@ -1849,14 +1866,14 @@ bool Ability::NotifyInvisibleForms(const std::vector &formIds) } /** -* @brief Set form next refresh time. -* -*

This method is called by a form provider to set refresh time. -* -* @param formId Indicates the ID of the form to set refresh time. -* @param nextTime Indicates the next time gap now in seconds, can not be litter than 300 seconds. -* @return Returns {@code true} if seting succeed; returns {@code false} otherwise. -*/ + * @brief Set form next refresh time. + * + *

This method is called by a form provider to set refresh time. + * + * @param formId Indicates the ID of the form to set refresh time. + * @param nextTime Indicates the next time gap now in seconds, can not be litter than 300 seconds. + * @return Returns {@code true} if seting succeed; returns {@code false} otherwise. + */ bool Ability::SetFormNextRefreshTime(const int64_t formId, const int64_t nextTime) { APP_LOGI("%{public}s called.", __func__); @@ -1908,32 +1925,31 @@ void Ability::ProcessFormUpdate(const FormJsInfo &formJsInfo) // post the async task of handleFormMessage int32_t msgCode = OHOS_FORM_UPDATE_FORM; - PostTask([this, msgCode, formJsInfo]() {HandleFormMessage(msgCode, formJsInfo);}, 0L); + PostTask([this, msgCode, formJsInfo]() { HandleFormMessage(msgCode, formJsInfo); }, 0L); } /** * @brief Uninstall form. * * @param formId Indicates the ID of the form to uninstall. */ -void Ability::ProcessFormUninstall(const int64_t formId) { +void Ability::ProcessFormUninstall(const int64_t formId) +{ APP_LOGI("%{public}s start.", __func__); std::shared_ptr formCallback = nullptr; { std::lock_guard lock(formLock); // get callback iterator by formId - std::map>::iterator appCallbackIterator = - appCallbacks_.find(formId); - + std::map>::iterator appCallbackIterator = appCallbacks_.find(formId); // call the callback function when you need to be notified if (appCallbackIterator == appCallbacks_.end()) { - //APP_LOGE("%{public}s failed, callback not find, formId: %{public}lld.", __func__, formId); + APP_LOGE("%{public}s failed, callback not find, formId: %{public}" PRId64 ".", __func__, formId); return; } formCallback = appCallbackIterator->second; CleanFormResource(formId); } - if ( formCallback == nullptr) { + if (formCallback == nullptr) { APP_LOGE("%{public}s failed, callback is nullptr.", __func__); return; } @@ -1955,7 +1971,7 @@ void Ability::ProcessFormUninstall(const int64_t formId) { * Ability#PARAM_FORM_NAME_KEY, and Ability#PARAM_FORM_DIMENSION_KEY, * respectively. Such form information must be managed as persistent data for further form * acquisition, update, and deletion. - * + * * @return Returns the created FormProviderInfo object. */ FormProviderInfo Ability::OnCreate(const Want &want) @@ -1982,8 +1998,7 @@ void Ability::OnDelete(const int64_t formId) * @return none. */ void Ability::OnUpdate(const int64_t formId) -{ -} +{} /** * @brief Called when the form provider is notified that a temporary form is successfully converted to a normal form. @@ -2004,8 +2019,7 @@ void Ability::OnCastTemptoNormal(const int64_t formId) * @return none. */ void Ability::OnVisibilityChanged(const std::map &formEventsMap) -{ -} +{} /** * @brief Called to notify the form provider to update a specified form. * @@ -2013,8 +2027,7 @@ void Ability::OnVisibilityChanged(const std::map &formEventsMa * @param message Form event message. */ void Ability::OnTriggerEvent(const int64_t formId, const std::string &message) -{ -} +{} /** * @brief Delete or release form with formId. * @@ -2030,22 +2043,22 @@ bool Ability::DeleteForm(const int64_t formId, const int32_t deleteType) APP_LOGE("%{public}s error, form is in recover status, can't do action on form.", __func__); return false; } - // check formId + // check formId if (formId <= 0) { APP_LOGE("%{public}s error, the passed in formId can't be negative or zero.", __func__); return false; } - // APP_LOGI("%{public}s, delete form begin, formId is %{public}lld and deleteType is %{public}d.", - // __func__, formId, deleteType); + APP_LOGI("%{public}s, delete form begin, formId is %{public}lld and deleteType is %{public}d.", + __func__, + formId, + deleteType); { // form lock std::lock_guard lock(formLock); // clean form resource when form is temp form - if (std::find( - lostedByReconnectTempForms_.begin(), - lostedByReconnectTempForms_.end(), - formId) != lostedByReconnectTempForms_.end()) { + if (std::find(lostedByReconnectTempForms_.begin(), lostedByReconnectTempForms_.end(), formId) != + lostedByReconnectTempForms_.end()) { CleanFormResource(formId); // the delete temp form is successfully return true; @@ -2060,9 +2073,7 @@ bool Ability::DeleteForm(const int64_t formId, const int32_t deleteType) result = FormMgr::GetInstance().DeleteForm(formId, formHostClient); } else { result = FormMgr::GetInstance().ReleaseForm( - formId, - formHostClient, - (deleteType == RELEASE_CACHED_FORM) ? true : false); + formId, formHostClient, (deleteType == RELEASE_CACHED_FORM) ? true : false); } if (result != ERR_OK) { APP_LOGE("%{public}s error, some internal server occurs, error code is %{public}d.", __func__, result); @@ -2083,11 +2094,11 @@ bool Ability::DeleteForm(const int64_t formId, const int32_t deleteType) * * @param formId Indicates the form's ID. */ -void Ability::CleanFormResource(const int64_t formId) +void Ability::CleanFormResource(const int64_t formId) { APP_LOGI("%{public}s called.", __func__); // compatible with int form id - int64_t cleanId {-1L}; + int64_t cleanId{-1L}; for (auto param : userReqParams_) { if ((param.first & 0x00000000ffffffffL) == (formId & 0x00000000ffffffffL)) { cleanId = param.first; @@ -2098,7 +2109,7 @@ void Ability::CleanFormResource(const int64_t formId) return; } - //APP_LOGD("%{public}s. clean id is %{public}lld.", __func__, cleanId); + APP_LOGD("%{public}s. clean id is %{public}" PRId64 ".", __func__, cleanId); // remove wantParam, callback and lostedByReconnectTempForms appCallbacks_.erase(cleanId); userReqParams_.erase(cleanId); @@ -2111,7 +2122,6 @@ void Ability::CleanFormResource(const int64_t formId) std::shared_ptr thisAbility = this->shared_from_this(); FormHostClient::GetInstance()->RemoveForm(thisAbility, cleanId); - // unregister death callback when appCallbacks is empty if (appCallbacks_.empty()) { std::shared_ptr thisAbility = this->shared_from_this(); @@ -2129,9 +2139,7 @@ void Ability::CleanFormResource(const int64_t formId) * @param callback Indicates the callback to be invoked whenever the {@link FormJsInfo} instance is obtained. */ void Ability::HandleAcquireResult( - const Want &want, - const FormJsInfo &formJsInfo, - const std::shared_ptr callback) + const Want &want, const FormJsInfo &formJsInfo, const std::shared_ptr callback) { APP_LOGI("%{public}s called.", __func__); { @@ -2171,23 +2179,22 @@ void Ability::HandleFormMessage(const int32_t msgCode, const FormJsInfo &formJsI { std::lock_guard lock(formLock); // get callback iterator by formId - std::map>::iterator appCallbackIterator = + std::map>::iterator appCallbackIterator = appCallbacks_.find(formJsInfo.formId); - // call the callback function when you need to be notified if (appCallbackIterator == appCallbacks_.end()) { - // APP_LOGE("%{public}s failed, callback not find, formId: %{public}lld.", __func__, formJsInfo.formId); + APP_LOGE("%{public}s failed, callback not find, formId: %{public}" PRId64 ".", __func__, formJsInfo.formId); return; } formCallback = appCallbackIterator->second; } - if ( formCallback == nullptr) { + if (formCallback == nullptr) { APP_LOGE("%{public}s failed, callback is nullptr.", __func__); return; } - //APP_LOGI("%{public}s, call user implement of form %{public}lld.", __func__, formJsInfo.formId); + APP_LOGI("%{public}s, call user implement of form %{public}" PRId64 ".", __func__, formJsInfo.formId); if (msgCode == OHOS_FORM_ACQUIRE_FORM) { formCallback->OnAcquired(FormCallback::OHOS_FORM_ACQUIRE_SUCCESS, formJsInfo); @@ -2198,7 +2205,7 @@ void Ability::HandleFormMessage(const int32_t msgCode, const FormJsInfo &formJsI /** * @brief Notify the forms visibility change event. - * + * * @param formIds Indicates the IDs of the forms to be made visible or invisible. * @param eventType Indicates the form events occurred. FORM_VISIBLE means that the form becomes visible, * and FORM_INVISIBLE means that the form becomes invisible. @@ -2218,9 +2225,10 @@ bool Ability::NotifyWhetherVisibleForms(const std::vector &formIds, int return false; } - int resultCode = FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, FormHostClient::GetInstance(), eventType); + int resultCode = + FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, FormHostClient::GetInstance(), eventType); if (resultCode != ERR_OK) { - APP_LOGE("%{public}s error, internal error occurs, error code:%{public}d.", __func__, resultCode); + APP_LOGE("%{public}s error, internal error occurs, error code:%{public}d.", __func__, resultCode); return false; } return true; @@ -2228,7 +2236,7 @@ bool Ability::NotifyWhetherVisibleForms(const std::vector &formIds, int /** * @brief Check the param of want. - * + * * @param formId Indicates the form's ID. * @param want Indicates the detailed information about the form to be obtained, including the bundle name, * module name, ability name, form name, form id, tempForm flag, form dimension, and form customize data. @@ -2298,7 +2306,7 @@ bool Ability::DisableUpdateForm(const std::vector &formIds) return LifecycleUpdate(formIds, DISABLE_FORM_UPDATE); } -bool Ability::LifecycleUpdate(std::vector formIds, int32_t updateType) +bool Ability::LifecycleUpdate(std::vector formIds, int32_t updateType) { if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) { APP_LOGE("%{public}s error, form is in recover status, can't do action on form.", __func__); @@ -2350,7 +2358,10 @@ bool Ability::RequestForm(const int64_t formId, const Want &want) // requestForm request to fms int resultCode = FormMgr::GetInstance().RequestForm(formId, FormHostClient::GetInstance(), want); if (resultCode != ERR_OK) { - APP_LOGE("%{public}s error, failed to notify the form service that the form user's lifecycle is updated, error code is %{public}d.", __func__, resultCode); + APP_LOGE("%{public}s error, failed to notify the form service that the form user's lifecycle is updated, error " + "code is %{public}d.", + __func__, + resultCode); return false; } @@ -2374,9 +2385,8 @@ void Ability::OnDeathReceived() { std::lock_guard lock(formLock); want = userReqRaram.second; - if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false) - && std::find(lostedTempForms.begin(), lostedTempForms.end(), - formId) == lostedTempForms.end()) { + if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false) && + std::find(lostedTempForms.begin(), lostedTempForms.end(), formId) == lostedTempForms.end()) { lostedTempForms.emplace_back(formId); continue; } @@ -2384,23 +2394,25 @@ void Ability::OnDeathReceived() bool result = ReAcquireForm(formId, want); if (!result) { - // APP_LOGI("%{public}s error, reacquire form failed, formId:%{public}lld.", __func__, formId); + APP_LOGI("%{public}s error, reacquire form failed, formId:%{public}" PRId64 ".", __func__, formId); std::shared_ptr formCallback = nullptr; { std::lock_guard lock(formLock); // get callback iterator by formId - std::map>::iterator appCallbackIterator = appCallbacks_.find(formId); - + std::map>::iterator appCallbackIterator = + appCallbacks_.find(formId); + if (appCallbackIterator == appCallbacks_.end()) { - //APP_LOGW("%{public}s error, lack of form callback for form, formId:%{public}lld.", __func__, formId); + APP_LOGW( + "%{public}s error, lack of form callback for form, formId:%{public}lld.", __func__, formId); continue; } formCallback = appCallbackIterator->second; } - if(formCallback == nullptr) { + if (formCallback == nullptr) { APP_LOGW("%{public}s failed, callback is nullptr.", __func__); continue; - } + } FormJsInfo formJsInfo; formJsInfo.formId = formId; @@ -2411,7 +2423,7 @@ void Ability::OnDeathReceived() /** * @brief Reacquire a specified form when the death callback is received. - * + * * @param formId Indicates the form ID. * @param want Indicates the detailed information about the form to be obtained. * @return Returns true if the request is successfully initiated; returns false otherwise. @@ -2423,15 +2435,15 @@ bool Ability::ReAcquireForm(const int64_t formId, const Want &want) // get the form host client sptr formHostClient = FormHostClient::GetInstance(); if (formHostClient == nullptr) { - //APP_LOGE("%{public}s error, formHostClient is nullptr, formId:%{public}lld.", __func__, formId); + APP_LOGE("%{public}s error, formHostClient is nullptr, formId:%{public}" PRId64 ".", __func__, formId); return false; } // reacquire form FormJsInfo formJsInfo; - if (FormMgr::GetInstance().AddForm(formId, want, formHostClient, formJsInfo) != ERR_OK - || formJsInfo.formId <= 0 || formJsInfo.formId != formId) { - //APP_LOGE("%{public}s error, fms reacquire form failed, formId:%{public}lld.", __func__, formId); + if (FormMgr::GetInstance().AddForm(formId, want, formHostClient, formJsInfo) != ERR_OK || formJsInfo.formId <= 0 || + formJsInfo.formId != formId) { + APP_LOGE("%{public}s error, fms reacquire form failed, formId:%{public}lld.", __func__, formId); return false; } @@ -2451,13 +2463,13 @@ bool Ability::CheckFMSReady() APP_LOGI("%{public}s called.", __func__); sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); auto remoteObject = systemAbilityManager->GetSystemAbility(FORM_MGR_SERVICE_ID); if (remoteObject == nullptr) { APP_LOGI("%{public}s, form manager service is not ready.", __func__); return false; } - + return true; } @@ -2476,7 +2488,7 @@ bool Ability::GetAllFormsInfo(std::vector &formInfos) APP_LOGE("%{public}s error, failed to get IBundleMgr.", __func__); return false; } - + if (!CheckPermission()) { return false; } @@ -2505,21 +2517,20 @@ bool Ability::GetFormsInfoByApp(std::string &bundleName, std::vector & APP_LOGE("%{public}s error, failed to get IBundleMgr.", __func__); return IsGetFormsInfoByApp; } - + if (!CheckPermission()) { return IsGetFormsInfoByApp; } - + IsGetFormsInfoByApp = iBundleMgr->GetFormsInfoByApp(bundleName, formInfos); - if (formInfos.size() == 0){ + if (formInfos.size() == 0) { return IsGetFormsInfoByApp; } - + return IsGetFormsInfoByApp; } - - /** +/** * @brief Get forms info by application name and module name. * * @param bundleName Application name. @@ -2546,9 +2557,9 @@ bool Ability::GetFormsInfoByModule(std::string &bundleName, std::string &moduleN if (!CheckPermission()) { return IsGetFormsInfoByModule; } - + IsGetFormsInfoByModule = iBundleMgr->GetFormsInfoByModule(bundleName, moduleName, formInfos); - + return IsGetFormsInfoByModule; } @@ -2562,7 +2573,7 @@ sptr Ability::GetBundleMgr() if (iBundleMgr_ == nullptr) { sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); auto remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (remoteObject == nullptr) { APP_LOGE("%{public}s error, failed to get bundle manager service.", __func__); @@ -2570,12 +2581,12 @@ sptr Ability::GetBundleMgr() } iBundleMgr_ = iface_cast(remoteObject); - if (iBundleMgr_ == nullptr) { + if (iBundleMgr_ == nullptr) { APP_LOGE("%{public}s error, failed to get bundle manager service", __func__); - return nullptr; + return nullptr; } } - + return iBundleMgr_; } @@ -2583,7 +2594,8 @@ sptr Ability::GetBundleMgr() * @brief check permission of bundle, if it not existed. * @return returns the permission is vaild, or false for failed. */ -bool Ability::CheckPermission() { +bool Ability::CheckPermission() +{ APP_LOGI("%{public}s called.", __func__); int32_t uid = IPCSkeleton::GetCallingUid(); @@ -2620,10 +2632,10 @@ void Ability::SetBundleManager(const sptr &bundleManager) sptr Ability::GetFormRemoteObject() { APP_LOGI("%{public}s start", __func__); - if(providerRemoteObject_ == nullptr) { + if (providerRemoteObject_ == nullptr) { sptr providerClient = new (std::nothrow) FormProviderClient(); std::shared_ptr thisAbility = this->shared_from_this(); - if(thisAbility == nullptr) { + if (thisAbility == nullptr) { APP_LOGE("%{public}s failed, thisAbility is nullptr", __func__); } providerClient->SetOwner(thisAbility); @@ -2633,5 +2645,14 @@ sptr Ability::GetFormRemoteObject() return providerRemoteObject_; } +/** + * @brief Set the start ability setting. + * @param setting the start ability setting. + */ +void Ability::SetStartAbilitySetting(std::shared_ptr setting) +{ + APP_LOGI("%{public}s called.", __func__); + setting_ = setting; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/ability/native/src/ability_context.cpp b/frameworks/kits/ability/native/src/ability_context.cpp index f2d7584623e..5379b60a1e8 100755 --- a/frameworks/kits/ability/native/src/ability_context.cpp +++ b/frameworks/kits/ability/native/src/ability_context.cpp @@ -96,6 +96,15 @@ void AbilityContext::StartAbility(const Want &want, int requestCode, const Abili APP_LOGE("AbilityContext::StartAbility AbilityType = %{public}d", type); return; } + + APP_LOGI("%{public}s. Start calling ams->StartAbility.", __func__); + ErrCode err = + AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, abilityStartSetting, token_, requestCode); + APP_LOGI("%{public}s. End calling ams->StartAbility. ret=%{public}d", __func__, err); + if (err != ERR_OK) { + APP_LOGE("AbilityContext::StartAbility is failed %{public}d", err); + } + APP_LOGI("%{public}s end.", __func__); } diff --git a/frameworks/kits/ability/native/src/ability_process.cpp b/frameworks/kits/ability/native/src/ability_process.cpp index 507f1a7eb20..88a68530f2a 100755 --- a/frameworks/kits/ability/native/src/ability_process.cpp +++ b/frameworks/kits/ability/native/src/ability_process.cpp @@ -57,9 +57,11 @@ void AbilityProcess::StartAbility(Ability *ability, CallAbilityParam param, Call if (param.forResultOption == true) { if (param.setting == nullptr) { + APP_LOGI("%{public}s param.setting == nullptr call StartAbilityForResult.", __func__); ability->StartAbilityForResult(param.want, param.requestCode); } else { - ability->StartAbilityForResult(param.want, param.requestCode, *(param.setting.get())); + APP_LOGI("%{public}s param.setting != nullptr call StartAbilityForResult.", __func__); + ability->StartAbilityForResult(param.want, param.requestCode, *(param.setting)); } std::lock_guard lock_l(mutex_); @@ -77,9 +79,11 @@ void AbilityProcess::StartAbility(Ability *ability, CallAbilityParam param, Call abilityResultMap_[ability] = map; } else { if (param.setting == nullptr) { + APP_LOGI("%{public}s param.setting == nullptr call StartAbility.", __func__); ability->StartAbility(param.want); } else { - ability->StartAbility(param.want, *(param.setting.get())); + APP_LOGI("%{public}s param.setting != nullptr call StartAbility.", __func__); + ability->StartAbility(param.want, *(param.setting)); } } APP_LOGI("AbilityProcess::StartAbility end"); diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index db87af94789..2a1e7d3d5f3 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -852,12 +852,42 @@ int AbilityThread::BatchInsert(const Uri &uri, const std::vector & void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag) { APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d,flag:%{public}d", winModeKey, flag); + sptr window = currentAbility_->GetWindow(); + if (window == nullptr) { + APP_LOGE("NotifyMultiWinModeChanged window == nullptr"); + return; + } + + if (flag) { + // true: normal windowMode -> free windowMode + if (winModeKey == MULTI_WINDOW_DISPLAY_FLOATING) { + APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE begin."); + window->SetWindowType(WINDOW_TYPE_FLOAT); + APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE end."); + } else { + APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d", winModeKey); + } + } else { + // false: free windowMode -> normal windowMode + APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP begin."); + window->SetWindowType(WINDOW_TYPE_NORMAL); + APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP end."); + } + return; } void AbilityThread::NotifyTopActiveAbilityChanged(bool flag) { APP_LOGI("NotifyTopActiveAbilityChanged,flag:%{public}d", flag); + sptr window = currentAbility_->GetWindow(); + if (window == nullptr) { + APP_LOGE("NotifyMultiWinModeChanged window == nullptr"); + return; + } + if (flag) { + window->SwitchTop(); + } return; } diff --git a/frameworks/kits/ability/native/src/form_provider_client.cpp b/frameworks/kits/ability/native/src/form_provider_client.cpp index 03805526ccb..a94857d5bcf 100755 --- a/frameworks/kits/ability/native/src/form_provider_client.cpp +++ b/frameworks/kits/ability/native/src/form_provider_client.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include + #include "form_provider_client.h" #include "appexecfwk_errors.h" #include "app_log_wrapper.h" @@ -67,8 +70,8 @@ int FormProviderClient::AcquireProviderFormInfo( FormProviderInfo formProviderInfo = ownerAbility->OnCreate(cloneWant); formProviderInfo.SetFormId(formId); newWant.SetParam(Constants::PROVIDER_FLAG, ERR_OK); - // APP_LOGD("%{public}s, formId: %{public}lld, data: %{public}s", - // __func__, formProviderInfo.GetFormId(), formProviderInfo.GetFormDataString().c_str()); + APP_LOGD("%{public}s, formId: %{public}" PRId64 ", data: %{public}s", + __func__, formProviderInfo.GetFormId(), formProviderInfo.GetFormDataString().c_str()); return HandleAcquire(formProviderInfo, newWant, callerToken); } @@ -145,8 +148,8 @@ int FormProviderClient::NotifyFormsDelete( break; } - // APP_LOGI("%{public}s come,formIds size=%{public}d, abilityName:%{public}s", - // __func__, formIds.size(), ownerAbility->GetAbilityName().c_str()); + APP_LOGI("%{public}s come,formIds size=%{public}zu, abilityName:%{public}s", + __func__, formIds.size(), ownerAbility->GetAbilityName().c_str()); for (int64_t formId : formIds) { ownerAbility->OnDelete(formId); } diff --git a/frameworks/kits/ability/native/src/page_ability_impl.cpp b/frameworks/kits/ability/native/src/page_ability_impl.cpp index f46dbcb5908..84244afd5a1 100755 --- a/frameworks/kits/ability/native/src/page_ability_impl.cpp +++ b/frameworks/kits/ability/native/src/page_ability_impl.cpp @@ -41,6 +41,7 @@ void PageAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Li SetLifeCycleStateInfo(targetState); if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) { + ability_->SetStartAbilitySetting(targetState.setting); Start(want); CheckAndRestore(); } diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp index f55ad05f863..0d8467f30e7 100755 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp @@ -99,7 +99,7 @@ const std::regex NUMBER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); std::size_t size = value.size(); \ sptr ao = new Array(size, g_IID_##I##id); \ for (std::size_t i = 0; i < size; i++) { \ - ao->Set(i, id::Box(value[i])); \ + ao->Set(i, id::Box((value)[i])); \ } \ (mapList).emplace(key, sptr(static_cast(ao.GetRefPtr()))); \ } while (0); @@ -112,7 +112,7 @@ const std::regex NUMBER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); if (Array::Is##id##Array(IArray::Query(it->second.GetRefPtr()))) { \ auto func = [&](IInterface *object) { \ if (I##id::Query(object) != nullptr) { \ - value.push_back(id::Unbox(I##id::Query(object))); \ + (value).push_back(id::Unbox(I##id::Query(object))); \ } \ }; \ Array::ForEach(IArray::Query(it->second.GetRefPtr()), func); \ @@ -121,6 +121,15 @@ const std::regex NUMBER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); } \ } while (0); +template +static void GetBaseDataValue(OHOS::AAFwk::IInterface *baseObj, Json::Value &json, int type) +{ + IClassName *data = IClassName::Query(baseObj); + baseValue val = 0; + data->GetValue(val); + json["data"] = val; + json["type"] = type; +} #define GET_BASE_DATA_VALUE(id, it, value, json, type) \ do { \ I##id *data = I##id::Query((it)->second.GetRefPtr()); \ @@ -130,6 +139,19 @@ const std::regex NUMBER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); (json)["type"] = type; \ } while (0); +template +static std::string RawTypeToString(const RawType value, unsigned int precisionAfterPoint); + +template +static void GetBaseFloatDoubleDataValue(OHOS::AAFwk::IInterface *baseObj, Json::Value &json, int type, int precision) +{ + IClassName *data = IClassName::Query(baseObj); + if (data != nullptr) { + baseValue val = ClassName::Unbox(data); + json["data"] = RawTypeToString(val, precision); + json["type"] = type; + } +} #define GET_BASE_FLOAT_DOUBLE_DATA_VALUE(iid, id, it, value, precision, json, type) \ do { \ iid *data = iid::Query((it)->second); \ @@ -158,6 +180,24 @@ const std::regex NUMBER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); (json)["type"] = type; \ } while (0); +template +static void PacmapGetArrayVal(OHOS::AAFwk::IInterface *ao, std::vector &array) +{ + if (ao == nullptr) { + return; + } + if (IArray::Query(ao) != nullptr) { + auto func = [&](AAFwk::IInterface *object) { + if (object != nullptr) { + IClassName *value = IClassName::Query(object); + if (value != nullptr) { + array.emplace_back(ClassName::Unbox(value)); + } + } + }; + Array::ForEach(IArray::Query(ao), func); + } +} #define PAC_MAP_GET_ARRAY_VAL(idInterface, id, ao, array) \ do { \ if ((ao) == nullptr) { \ @@ -1204,26 +1244,28 @@ static std::string RawTypeToString(const RawType value, unsigned int precisionAf bool PacMap::GetBaseJsonValue(PacMapList::const_iterator &it, Json::Value &json) const { - // base data : long =>string + // base data : short if (IShort::Query(it->second.GetRefPtr()) != nullptr) { - GET_BASE_DATA_VALUE(Short, it, short, json, PACMAP_DATA_SHORT) + GetBaseDataValue(it->second.GetRefPtr(), json, PACMAP_DATA_SHORT); } else if (IInteger::Query(it->second.GetRefPtr()) != nullptr) { - GET_BASE_DATA_VALUE(Integer, it, int, json, PACMAP_DATA_INTEGER) + GetBaseDataValue(it->second.GetRefPtr(), json, PACMAP_DATA_INTEGER); } else if (ILong::Query(it->second.GetRefPtr()) != nullptr) { // long:string GET_BASE_LONG_DATA_VALUE(Long, it, long, json, PACMAP_DATA_LONG) } else if (IChar::Query(it->second.GetRefPtr()) != nullptr) { - GET_BASE_DATA_VALUE(Char, it, zchar, json, PACMAP_DATA_CHAR) + GetBaseDataValue(it->second.GetRefPtr(), json, PACMAP_DATA_CHAR); } else if (IByte::Query(it->second.GetRefPtr()) != nullptr) { - GET_BASE_DATA_VALUE(Byte, it, byte, json, PACMAP_DATA_BYTE) + GetBaseDataValue(it->second.GetRefPtr(), json, PACMAP_DATA_BYTE); } else if (IBoolean::Query(it->second.GetRefPtr()) != nullptr) { - GET_BASE_DATA_VALUE(Boolean, it, bool, json, PACMAP_DATA_BOOLEAN) + GetBaseDataValue(it->second.GetRefPtr(), json, PACMAP_DATA_BOOLEAN); } else if (IFloat::Query(it->second.GetRefPtr()) != nullptr) { // base long:string - GET_BASE_FLOAT_DOUBLE_DATA_VALUE(IFloat, Float, it, float, FLOAT_PRECISION, json, PACMAP_DATA_FLOAT) + GetBaseFloatDoubleDataValue( + it->second.GetRefPtr(), json, PACMAP_DATA_FLOAT, FLOAT_PRECISION); } else if (IDouble::Query(it->second.GetRefPtr()) != nullptr) { // base :double to string - GET_BASE_FLOAT_DOUBLE_DATA_VALUE(IDouble, Double, it, double, DOUBLE_PRECISION, json, PACMAP_DATA_DOUBLE) + GetBaseFloatDoubleDataValue( + it->second.GetRefPtr(), json, PACMAP_DATA_DOUBLE, DOUBLE_PRECISION); } else if (IString::Query(it->second.GetRefPtr()) != nullptr) { GET_BASE_STRING_DATA_VALUE(String, it, std::string, json, PACMAP_DATA_STRING) } else if (IArray::Query(it->second.GetRefPtr()) != nullptr) { @@ -1347,39 +1389,39 @@ bool PacMap::GetArrayJsonValue(PacMapList::const_iterator &it, Json::Value &json return false; } if (Array::IsShortArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IShort, AAFwk::Short, it->second.GetRefPtr(), array) - return ToJsonArrayShort(array, json, PACMAP_DATA_ARRAY_SHORT); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayShort(arrayData, json, PACMAP_DATA_ARRAY_SHORT); } else if (Array::IsIntegerArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IInteger, AAFwk::Integer, it->second.GetRefPtr(), array) - return ToJsonArrayInt(array, json, PACMAP_DATA_ARRAY_INTEGER); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayInt(arrayData, json, PACMAP_DATA_ARRAY_INTEGER); } else if (Array::IsLongArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::ILong, AAFwk::Long, it->second.GetRefPtr(), array); - return ToJsonArrayLong(array, json, PACMAP_DATA_ARRAY_LONG); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayLong(arrayData, json, PACMAP_DATA_ARRAY_LONG); } else if (Array::IsCharArray(array)) { return false; } else if (Array::IsByteArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IByte, AAFwk::Byte, it->second.GetRefPtr(), array); - return ToJsonArrayByte(array, json, PACMAP_DATA_ARRAY_BYTE); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayByte(arrayData, json, PACMAP_DATA_ARRAY_BYTE); } else if (Array::IsBooleanArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IBoolean, AAFwk::Boolean, it->second.GetRefPtr(), array); - return ToJsonArrayBoolean(array, json, PACMAP_DATA_ARRAY_BOOLEAN); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayBoolean(arrayData, json, PACMAP_DATA_ARRAY_BOOLEAN); } else if (Array::IsFloatArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IFloat, AAFwk::Float, it->second.GetRefPtr(), array); - return ToJsonArrayFloat(array, json, PACMAP_DATA_ARRAY_FLOAT); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayFloat(arrayData, json, PACMAP_DATA_ARRAY_FLOAT); } else if (Array::IsDoubleArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IDouble, AAFwk::Double, it->second.GetRefPtr(), array); - return ToJsonArrayDouble(array, json, PACMAP_DATA_ARRAY_DOUBLE); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayDouble(arrayData, json, PACMAP_DATA_ARRAY_DOUBLE); } else if (Array::IsStringArray(array)) { - std::vector array; - PAC_MAP_GET_ARRAY_VAL(AAFwk::IString, AAFwk::String, it->second.GetRefPtr(), array); - return ToJsonArrayString(array, json, PACMAP_DATA_ARRAY_STRING); + std::vector arrayData; + PacmapGetArrayVal(it->second.GetRefPtr(), arrayData); + return ToJsonArrayString(arrayData, json, PACMAP_DATA_ARRAY_STRING); } else { return false; } diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp index a222e151145..cf50fa11dbe 100755 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp @@ -244,21 +244,6 @@ bool WantParams::operator==(const WantParams &other) return true; } -// #define GETWRAPDATATYPE(id, value, ret) \ -// do { \ -// if (value != nullptr && id::Query(value) != nullptr) { \ -// return ret; \ -// } else { \ -// break; \ -// } \ -// } while (0) -// #define GETSPTRBYTYPE(type, typeid, typeClass, str) \ -// do { \ -// if (type == typeid) { \ -// return typeClass::Parse(str); \ -// } \ -// } while (0) - int WantParams::GetDataType(const sptr iIt) { if (iIt != nullptr && IBoolean::Query(iIt) != nullptr) { diff --git a/interfaces/kits/js/@ohos.ability.featureAbility.d.ts b/interfaces/kits/js/@ohos.ability.featureAbility.d.ts old mode 100755 new mode 100644 index de9a10b563e..043a7951ec2 --- a/interfaces/kits/js/@ohos.ability.featureAbility.d.ts +++ b/interfaces/kits/js/@ohos.ability.featureAbility.d.ts @@ -17,10 +17,7 @@ import { Want } from './ability/want'; import { StartAbilityParameter } from './ability/startAbilityParameter'; import { AbilityResult } from './ability/abilityResult'; import { Context } from './app/context'; -import { ConnectOptions } from './ability/connectOptions'; import { DataAbilityHelper } from './ability/dataAbilityHelper'; -import { ProcessInfo } from './app/processInfo'; -import { ElementName } from './bundle/elementName'; /** * A Feature Ability represents an ability with a UI and is designed to interact with users. @@ -36,6 +33,7 @@ declare namespace featureAbility { * @devices phone, tablet * @since 6 * @sysCap AAFwk + * @param parameter Indicates the ability to start. * @return - */ function getWant(callback: AsyncCallback): void; @@ -92,99 +90,37 @@ declare namespace featureAbility { */ function terminateSelf(callback: AsyncCallback): void; - /** - * Checks whether the main window of this ability has window focus. - * @devices phone, tablet - * @since 7 - * @sysCap AAFwk - */ - function hasWindowFocus(callback: AsyncCallback): void; - function hasWindowFocus(): Promise; - - /** - * Connects an ability to a Service ability. - * @devices phone, tablet - * @since 7 - * @sysCap AAFwk - * @param request Indicates the Service ability to connect. - * @param options Indicates the callback object when the Service ability is connected. - * @return Returns true if the connection is successful; returns false otherwise. - */ - function connectAbility(request: Want, options:ConnectOptions): number; - /** - * Disconnects an ability from a Service ability. + * Obtains the dataAbilityHelper. * @devices phone, tablet * @since 7 * @sysCap AAFwk - * @param connection Indicates the Service ability to disconnect. - */ - function disconnectAbility(connection: number, callback:AsyncCallback): void; - function disconnectAbility(connection: number): Promise; - - /** - * Obtains the type of this application. - * @devices phone, tablet - * @since 7 - * @sysCap appexecfwk - * @return Returns {@code system} if this application is a system application; - * returns {@code normal} if it is released in Ohos AppGallery; - * returns {@code other} if it is released by a third-party vendor; - * returns an empty string if the query fails. - */ - function getAppType(callback: AsyncCallback): void; - function getAppType(): Promise; - - /** - * Obtains the bundle name of the current ability. - * @devices phone, tablet - * @since 7 - * @sysCap appexecfwk - * @return Returns the bundle name of the current ability. - */ - function getBundleName(callback: AsyncCallback): void; - function getBundleName(): Promise; - - /** - * Obtains the bundle name of the calling ability. - * @devices phone, tablet - * @since 7 - * @sysCap appexecfwk - * @return Returns the bundle name of the current ability. + * @param uri Indicates the path of the file to open. + * @return Returns the dataAbilityHelper. */ - function getCallingBundle(callback: AsyncCallback): void; - function getCallingBundle(): Promise; + function acquireDataAbilityHelper(uri: string): DataAbilityHelper; - /** - * Connects an ability to a Service ability. + /** + * Checks whether the main window of this ability has window focus. * @devices phone, tablet * @since 7 * @sysCap AAFwk - * @param want Indicates the Service ability to connect. - * @param connectionCallback Indicates the callback object when the Service ability is connected. - * @return Returns true if the connection is successful; returns false otherwise. */ - function getDataAbilityHelper(URI: string, callback:AsyncCallback): void; - function getDataAbilityHelper(URI: string): Promise; + function hasWindowFocus(callback: AsyncCallback): void; + function hasWindowFocus(): Promise; - /** - * Obtains the element name of the current ability. - * @devices phone, tablet - * @since 7 - * @sysCap appexecfwk - * @return Returns the element name of the current ability. - */ - function getElementName(callback: AsyncCallback): void; - function getElementName(): Promise; + export enum AbilityWindowConfiguration { + WINDOW_MODE_UNDEFINED = 0, + WINDOW_MODE_FULLSCREEN = 1, + WINDOW_MODE_SPLIT_PRIMARY = 100, + WINDOW_MODE_SPLIT_SECONDARY = 101, + WINDOW_MODE_FLOATING = 102 + } - /** - * Obtains information about the current process, including the process ID and name. - * @devices phone, tablet - * @since 7 - * @sysCap appxecfwk - * @return Returns the process info of the current process. - */ - function getProcessInfo(callback: AsyncCallback): void; - function getProcessInfo(): Promise; + export enum AbilityStartSetting { + BOUNDS_KEY = "abilityBounds", + WINDOW_MODE_KEY = "windowMode", + DISPLAY_ID_KEY = "displayId" + } } -export default featureAbility; \ No newline at end of file +export default featureAbility; diff --git a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts index f276af1c0c9..e6388be0229 100644 --- a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts +++ b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts @@ -14,13 +14,11 @@ */ import { AsyncCallback } from './basic'; import { StartAbilityParameter } from './ability/startAbilityParameter'; -import { Want } from './ability/want'; -import { ConnectOptions } from './ability/connectOptions'; /** * A Particle Ability represents an ability with service. * @name particleAbility - * @since 6 + * @since 7 * @sysCap AAFwk * @devices phone, tablet * @permission N/A @@ -30,43 +28,12 @@ declare namespace particleAbility { /** * Service ability uses this method to start a specific ability. * @devices phone, tablet - * @since 6 + * @since 7 * @sysCap AAFwk * @param parameter Indicates the ability to start. * @return - */ - function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback): void; - function startAbility(parameter: StartAbilityParameter): Promise; - - /** - * Destroys another Service ability. - * - * @param want Indicates information about the Service ability. - * @return Returns true if the Service ability is destroyed; returns false otherwise. - * @since 6 - */ - function stopAbility(request: Want, callback:AsyncCallback): void; - function stopAbility(request: Want): Promise; - - /** - * Connects an ability to a Service ability. - * @devices phone, tablet - * @since 7 - * @sysCap AAFwk - * @param request Indicates the Service ability to connect. - * @param options Indicates the callback object when the Service ability is connected. - * @return Returns true if the connection is successful; returns false otherwise. - */ - function connectAbility(request: Want, options:ConnectOptions): number; - - /** - * Disconnects an ability from a Service ability. - * @devices phone, tablet - * @since 7 - * @sysCap AAFwk - * @param connection Indicates the Service ability to disconnect. - */ - function disconnectAbility(connection: number, callback:AsyncCallback): void; - function disconnectAbility(connection: number): Promise; + function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback): void; + function startAbility(parameter: StartAbilityParameter): Promise; } -export default particleAbility; +export default particleAbility; \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.ability.wantConstant.d.ts b/interfaces/kits/js/@ohos.ability.wantConstant.d.ts index e05916b8cff..edae0e993c1 100644 --- a/interfaces/kits/js/@ohos.ability.wantConstant.d.ts +++ b/interfaces/kits/js/@ohos.ability.wantConstant.d.ts @@ -21,7 +21,7 @@ * @devices phone, tablet * @permission N/A */ - declare namespace wantConstant { +declare namespace wantConstant { /** * the constant for action of the want * @name Action diff --git a/interfaces/kits/js/@ohos.app.abilityManager.d.ts b/interfaces/kits/js/@ohos.app.abilityManager.d.ts index f9393afbaf2..f5b7ce142bb 100644 --- a/interfaces/kits/js/@ohos.app.abilityManager.d.ts +++ b/interfaces/kits/js/@ohos.app.abilityManager.d.ts @@ -22,7 +22,7 @@ import { ActiveProcessInfo } from './app/activeProcessInfo'; * * @since 7 * @SysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car * @import import abilityManager from '@ohos.app.abilityManager' * @permission N/A */ @@ -39,7 +39,7 @@ declare namespace abilityManager { * Get information about running processes * @since 7 * @SysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car * @return a list of ActiveProcessInfo records describing each process. * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION * @systemapi hide this for inner system use @@ -51,7 +51,7 @@ declare namespace abilityManager { * Get information about the running ability missions * @since 7 * @SysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car * @param upperLimit The maximum number of mission infos to return in the array. * @return an array of AbilityMissionInfo records describing each active mission. * @permission ohos.permission.ACCESS_MISSIONS @@ -64,7 +64,7 @@ declare namespace abilityManager { * Get information about recently run missions * @since 7 * @SysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car * @param upperLimit The maximum number of previous mission infos to return in the array. * @return an array of AbilityMissionInfo records describing each of the previous mission. * @permission ohos.permission.ACCESS_MISSIONS_EXTRA @@ -77,7 +77,7 @@ declare namespace abilityManager { * Delete the specified missions * @since 7 * @SysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car * @param missionIds An array of missions, representing the missions that need to be deleted. * @permission ohos.permission.DELETE_MISSIONS * @systemapi hide this for inner system use diff --git a/interfaces/kits/js/@ohos.bundle.d.ts b/interfaces/kits/js/@ohos.bundle.d.ts index 08c015fea98..6e9ff46b8dd 100644 --- a/interfaces/kits/js/@ohos.bundle.d.ts +++ b/interfaces/kits/js/@ohos.bundle.d.ts @@ -1,235 +1,347 @@ -/* - * 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. - */ -import { AsyncCallback } from './basic'; -import { ApplicationInfo } from './bundle/applicationInfo'; -import { BundleInfo } from './bundle/bundleInfo'; -import { AbilityInfo } from './bundle/abilityInfo'; -import { Want } from './ability/want'; -import { BundleInstaller } from './bundle/bundleInstaller'; -import { ElementName } from './bundle/elementName'; -import { ShortcutInfo } from './bundle/shortcutInfo'; -import { ModuleUsageRecord } from './bundle/moduleUsageRecord'; -import permission from './@ohos.security.permission'; - -/** - * @name BundleFlag - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -type PermissionEvent = 'permissionChange' | 'anyPermissionChange'; - -/** - * bundle. - * @name bundle - * @since 3 - * @sysCap appexecfwk - * @devices phone, tablet - * @permission N/A - */ -declare namespace bundle { - - enum BundleFlag { - GET_BUNDLE_DEFAULT = 0x00000000, - GET_BUNDLE_WITH_ABILITIES = 0x00000001, - GET_APPLICATION_INFO_WITH_PERMISSION = 0x00000008, - } - - export enum GrantStatus { - PERMISSION_DENIED = -1, - PERMISSION_GRANTED = 0, - } - - /** - * @name AbilityType - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ - export enum AbilityType { - UNKNOWN, - PAGE, - SERVICE, - DATA, - } - - /** - * @name AbilitySubType - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ - export enum AbilitySubType { - UNSPECIFIED = 0, - CA = 1, - } - - /** - * @name DisplayOrientation - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ - export enum DisplayOrientation { - UNSPECIFIED, - LANDSCAPE, - PORTRAIT, - FOLLOWRECENT, - } - - /** - * @name LaunchMode - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ - export enum LaunchMode { - SINGLETON = 0, - STANDARD = 1, - } - - export enum InstallErrorCode{ - SUCCESS = 0, - STATUS_INSTALL_FAILURE = 1, - STATUS_INSTALL_FAILURE_ABORTED = 2, - STATUS_INSTALL_FAILURE_INVALID = 3, - STATUS_INSTALL_FAILURE_CONFLICT = 4, - STATUS_INSTALL_FAILURE_STORAGE = 5, - STATUS_INSTALL_FAILURE_INCOMPATIBLE = 6, - STATUS_UNINSTALL_FAILURE = 7, - STATUS_UNINSTALL_FAILURE_BLOCKED = 8, - STATUS_UNINSTALL_FAILURE_ABORTED = 9, - STATUS_UNINSTALL_FAILURE_CONFLICT = 10, - STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT = 0x0B, - STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED = 0x0C, - STATUS_ABILITY_NOT_FOUND = 0x40, - STATUS_BMS_SERVICE_ERROR = 0x41 - } - - /** - * Obtains BundleInfo based on a given bundle name. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param bundleName Indicates the bundle name. - * @param callback Specified callback method. - */ - function getBundleInfo(bundleName: string, bundelFlags: number, callback: AsyncCallback): void; - - /** - * Obtains Bundle installer to install or uninstall hap. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @return BundleInstaller. - */ - function getBundleInstaller(callback: AsyncCallback): void; - function getBundleInstaller(): Promise; - - /** - * Obtains the ApplicationInfo based on a given application name. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param bundleName Indicates the application name. - * @param callback Specified callback method. - */ - function getApplicationInfo(bundleName: string, bundelFlags: number, userId: number, callback: AsyncCallback) : void; - function getApplicationInfo(bundleName: string, bundelFlags: number, userId?: number) : Promise; - - function checkPermission(bundleName: string, permission: string, callback: AsyncCallback): void; - function checkPermission(bundleName: string, permission: string): Promise; - - /** - * Obtains BundleInfo of all bundles available in the system. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param callback Specified callback method. - */ - function getBundleInfos(bundelFlag: BundleFlag, callback: AsyncCallback>) : void; - function getBundleInfos(bundelFlag: BundleFlag) : Promise>; - - // void registerAllPermissionsChanged(IRemoteObject callback) throws RemoteException; - function on(type: PermissionEvent, callback: AsyncCallback): void; - function on(type: PermissionEvent, uids: Array, callback: AsyncCallback): void; - - // void unregisterPermissionsChanged(IRemoteObject callback) throws RemoteException; - function off(type: PermissionEvent, callback: AsyncCallback):void; - function off(type: PermissionEvent, uids: Array, callback: AsyncCallback): void; - - /** - * Obtains information about all installed applications. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param callback Specified callback method. - */ - function getApplicationInfos(bundelFlags: number, userId: number, callback: AsyncCallback>) : void; - function getApplicationInfos(bundelFlags: number, callback: AsyncCallback>) : void; - function getApplicationInfos(bundelFlags: number, userId?: number) : Promise>; - - /** - * Obtains information about a bundle contained in a HAP. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param hapFilePath Indicates the path of the HAP. - * @param callback Specified callback method. - */ - function getBundleArchiveInfo(hapFilePath: string, bundelFlags: number, callback: AsyncCallback) : void - function getBundleArchiveInfo(hapFilePath: string, bundelFlags: number) : Promise; - - // List getShortcutInfos(String bundleName) throws RemoteException; - function getShortcutInfos(bundleName: string, callback: AsyncCallback>): void; - function getShortcutInfos(bundleName: string): Promise>; - - /** - * Obtains detailed information about a specified permission. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param permissionName Indicates the name of the permission. - * @param callback Specified callback method. - */ - function getPermissionDef(permissionName: string, callback: AsyncCallback) : void; - function getPermissionDef(permissionName: string) : Promise; - - function getHomeShortcutInfos(callback: AsyncCallback>): void; - function getHomeShortcutInfos(): Promise; - - // List getModuleUsageRecords(int maxNum) throws RemoteException, IllegalArgumentException; - function getModuleUsageRecords(maxNum: number, callback: AsyncCallback>): void; - function getModuleUsageRecords(maxNum: number): Promise>; -} - -export default bundle; +/* + * 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. + */ + +import { AsyncCallback, Callback } from './basic'; +import { ApplicationInfo } from './bundle/applicationInfo'; +import { BundleInfo } from './bundle/bundleInfo'; +import { AbilityInfo } from './bundle/abilityInfo'; +import { Want } from './ability/want'; +import { BundleInstaller } from './bundle/bundleInstaller'; +import { ElementName } from './bundle/elementName'; +import { ShortcutInfo } from './bundle/shortcutInfo'; +import { ModuleUsageRecord } from './bundle/moduleUsageRecord'; + +/** + * bundle. + * @name bundle + * @since 7 + * @sysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable + * @permission NA + */ +declare namespace bundle { + +/** + * @name BundleFlag + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + enum BundleFlag { + GET_BUNDLE_DEFAULT = 0x00000000, + GET_BUNDLE_WITH_ABILITIES = 0x00000001, + GET_APPLICATION_INFO_WITH_PERMISSION = 0x00000008, + } + +/** + * @name GrantStatus + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum GrantStatus { + PERMISSION_DENIED = -1, + PERMISSION_GRANTED = 0, + } + + /** + * @name AbilityType + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum AbilityType { + /** + * @default Indicates an unknown ability type + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + UNKNOWN, + + /** + * @default Indicates that the ability has a UI + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + PAGE, + + /** + * @default Indicates that the ability does not have a UI + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + SERVICE, + + /** + * @default Indicates that the ability is used to provide data access services + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + DATA, + } + + /** + * @name AbilitySubType + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum AbilitySubType { + UNSPECIFIED = 0, + CA = 1, + } + + /** + * @name DisplayOrientation + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum DisplayOrientation { + /** + * @default Indicates that the system automatically determines the display orientation + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + UNSPECIFIED, + + /** + * @default Indicates the landscape orientation + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + LANDSCAPE, + + /** + * @default Indicates the portrait orientation + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + PORTRAIT, + + /** + * @default Indicates the page ability orientation is the same as that of the nearest ability in the stack + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + FOLLOW_RECENT, + } + + /** + * @name LaunchMode + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum LaunchMode { + /** + * @default Indicates that the ability has only one instance + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + SINGLETON = 0, + + /** + * @default Indicates that the ability can have multiple instances + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + STANDARD = 1, + } + + /** + * @name InstallErrorCode + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import NA + * @permission NA + * @devices phone, tablet, tv, wearable + */ + export enum InstallErrorCode{ + SUCCESS = 0, + STATUS_INSTALL_FAILURE = 1, + STATUS_INSTALL_FAILURE_ABORTED = 2, + STATUS_INSTALL_FAILURE_INVALID = 3, + STATUS_INSTALL_FAILURE_CONFLICT = 4, + STATUS_INSTALL_FAILURE_STORAGE = 5, + STATUS_INSTALL_FAILURE_INCOMPATIBLE = 6, + STATUS_UNINSTALL_FAILURE = 7, + STATUS_UNINSTALL_FAILURE_BLOCKED = 8, + STATUS_UNINSTALL_FAILURE_ABORTED = 9, + STATUS_UNINSTALL_FAILURE_CONFLICT = 10, + STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT = 0x0B, + STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED = 0x0C, + STATUS_ABILITY_NOT_FOUND = 0x40, + STATUS_BMS_SERVICE_ERROR = 0x41 + } + + /** + * Obtains based on a given networkId and bundle name. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param networkId Indicates the device networkId in area network. + * @param bundleName Indicates the application bundle name to be queried. + * @param flags Indicates the flag used to specify information contained in that will be + * returned. + * @return Returns the BundleInfo object. + * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO + */ + function getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback): void; + function getBundleInfo(bundleName: string, bundleFlags: number): Promise; + + /** + * Obtains the interface used to install bundles. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @return Returns the IBundleInstaller interface. + * @permission ohos.permission.INSTALL_BUNDLE + */ + function getBundleInstaller(callback: AsyncCallback): void; + function getBundleInstaller(): Promise; + + /** + * Obtains based on a given bundle name. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param bundleName Indicates the application bundle name to be queried. + * @param flags Indicates the flag used to specify information contained in the ApplicationInfo object + * that will be returned. + * @param userId Indicates the user ID. + * @return Returns the ApplicationInfo object. + * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO + */ + function getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback) : void; + function getApplicationInfo(bundleName: string, bundleFlags: number, userId: number) : Promise; + + /** + * Checks whether a specified bundle has been granted a specific permission. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param bundleName Indicates the name of the bundle to check. + * @param permission Indicates the permission to check. + * @return Returns 0 if the bundle has the permission; returns -1 otherwise. + */ + function checkPermission(bundleName: string, permission: string, callback: AsyncCallback): void; + function checkPermission(bundleName: string, permission: string): Promise; + + /** + * Query the AbilityInfo by the given Want. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param intent Indicates the Intent containing the application bundle name to + * be queried. + * @param flags Indicates the flag used to specify information contained in the AbilityInfo objects that + * will be returned. + * @param userId Indicates the user ID. + * @return Returns a list of AbilityInfo objects. + * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO + */ + function queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback>): void; + function queryAbilityByWant(want: Want, bundleFlags: number, userId:number): Promise>; + + /** + * Obtains BundleInfo of all bundles available in the system. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param flags Indicates the flag used to specify information contained in the BundleInfo that will be + * returned. + * @return Returns a list of BundleInfo objects. + * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + */ + function getAllBundleInfo(bundlelFlag: BundleFlag, callback: AsyncCallback>) : void; + function getAllBundleInfo(bundlelFlag: BundleFlag) : Promise>; + + /** + * Obtains information about all installed applications of a specified user. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param flags Indicates the flag used to specify information contained in the ApplicationInfo objects + * that will be returned. + * @param userId Indicates the user ID. + * @return Returns a list of ApplicationInfo objects. + * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + */ + function getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback>) : void; + function getAllApplicationInfo(bundleFlags: number, userId: number) : Promise>; + + /** + * Obtains information about an application bundle contained in an ohos Ability Package (HAP). + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param hapFilePath Indicates the path storing the HAP. The path should be the relative path to the data + * directory of the current application. + * @param flags Indicates the flag used to specify information contained in the BundleInfo object to be + * returned. + * @return Returns the BundleInfo object. + */ + function getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback) : void + function getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) : Promise; + + /** + * Obtains information about the shortcuts of the application. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param bundleName Indicates the bundle name of the application. + * @return Returns a list of ShortcutInfo objects containing shortcut information about the application. + * @permission ohos.permission.MANAGE_SHORTCUTS + */ + function getAllShortcutInfo(bundleName: string, callback: AsyncCallback>): void; + function getAllShortcutInfo(bundleName: string): Promise>; + + /** + * get module usage record list in descending order of lastLaunchTime. + * + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @param maxNum the return size of the records, must be in range of 1 to 1000. + * @return Returns ability usage record list. + * @systemapi hide this for inner system use + */ + function getModuleUsageRecords(maxNum: number, callback: AsyncCallback>): void; + function getModuleUsageRecords(maxNum: number): Promise>; +} + +export default bundle; diff --git a/interfaces/kits/js/ability/dataAbilityHelper.d.ts b/interfaces/kits/js/ability/dataAbilityHelper.d.ts index 9ac55382f67..b37781aec0f 100644 --- a/interfaces/kits/js/ability/dataAbilityHelper.d.ts +++ b/interfaces/kits/js/ability/dataAbilityHelper.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AsyncCallback } from './../.basic'; +import { AsyncCallback } from './../basic'; import { DataAbilityOperation } from './dataAbilityOperation'; import { ValuesBucket, ResultSet, DataAbilityPredicates } from './../@ohos.data.rdb'; diff --git a/interfaces/kits/js/ability/startAbilityParameter.d.ts b/interfaces/kits/js/ability/startAbilityParameter.d.ts index 3e449112768..a628cffd1d3 100644 --- a/interfaces/kits/js/ability/startAbilityParameter.d.ts +++ b/interfaces/kits/js/ability/startAbilityParameter.d.ts @@ -38,11 +38,13 @@ export interface StartAbilityParameter { /** * Indicates the special start setting used in starting ability with TaskSyncAnimation. + *

Requires Permission: {@code ohos.permission.CONTROL_TASK_SYNC_ANIMATOR} * * @default - * @devices phone, tablet - * @since 8 + * @permission ohos.permission.CONTROL_TASK_SYNC_ANIMATOR + * @since 7 * @SysCap aafwk */ taskSyncAnimationOptions?: TaskSyncAnimationOptions; -} \ No newline at end of file +} diff --git a/interfaces/kits/js/ability/want.d.ts b/interfaces/kits/js/ability/want.d.ts index 90a6b23ddd5..af2183ded2e 100644 --- a/interfaces/kits/js/ability/want.d.ts +++ b/interfaces/kits/js/ability/want.d.ts @@ -21,7 +21,7 @@ * @devices phone, tablet * @permission N/A */ - export declare interface Want { +export declare interface Want { /** * device id * @default - diff --git a/interfaces/kits/js/app/abilityMissionInfo.d.ts b/interfaces/kits/js/app/abilityMissionInfo.d.ts old mode 100644 new mode 100755 index eb7d23cb39e..bd219349286 --- a/interfaces/kits/js/app/abilityMissionInfo.d.ts +++ b/interfaces/kits/js/app/abilityMissionInfo.d.ts @@ -21,37 +21,37 @@ import { ElementName } from '../bundle/elementName'; * @SysCap SystemCapability.Appexecfwk * @import import AbilityMissionInfo from 'app/abilityMissionInfo' * @permission N/A - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car */ export interface AbilityMissionInfo { - /** - * @default Unique identification of task stack information corresponding to ability - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ - missionId: number; + /** + * @default Unique identification of task stack information corresponding to ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + missionId: number; - /** - * @default The component launched as the first ability in the task stack - * This can be considered the "application" of this task stack - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ - bottomAbility: ElementName; + /** + * @default The component launched as the first ability in the task stack + * This can be considered the "application" of this task stack + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + bottomAbility: ElementName; - /** - * @default The ability component at the top of the history stack of the task - * This is what the user is currently doing - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ - topAbility: ElementName; + /** + * @default The ability component at the top of the history stack of the task + * This is what the user is currently doing + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + topAbility: ElementName; - /** - * @default The corresponding ability description information in the task stack - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ - windowMode: number; + /** + * @default The corresponding ability description information in the task stack + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + windowMode: number; } diff --git a/interfaces/kits/js/app/activeProcessInfo.d.ts b/interfaces/kits/js/app/activeProcessInfo.d.ts old mode 100644 new mode 100755 index 865f77595c8..4ab5a6aa3d1 --- a/interfaces/kits/js/app/activeProcessInfo.d.ts +++ b/interfaces/kits/js/app/activeProcessInfo.d.ts @@ -13,14 +13,13 @@ * limitations under the License. */ - /** * @name This class saves process information about an application * @since 7 * @SysCap SystemCapability.Appexecfwk * @import import app from 'app/activeProcessInfo' * @permission N/A - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car */ export interface ActiveProcessInfo { /** diff --git a/interfaces/kits/js/app/activeServiceAbilityInfo.d.ts b/interfaces/kits/js/app/activeServiceAbilityInfo.d.ts new file mode 100755 index 00000000000..8e9c14e1142 --- /dev/null +++ b/interfaces/kits/js/app/activeServiceAbilityInfo.d.ts @@ -0,0 +1,55 @@ +/* + * 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. + */ + +import { ElementName } from '../bundle/elementName'; + +/** + * @name information corresponding to active service ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import import AbilityMissionInfo from 'app/activeServiceAbilityInfo' + * @permission N/A + * @devices phone, tablet, tv, wearable, car + */ +export interface ActiveServiceAbilityInfo { + /** + * @default process id + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + pid: number; + + /** + * @default user id + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + uid: number; + + /** + * @default the name of the process + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + processName: string; + + /** + * @default The element name of the service ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + serviceAbility: ElementName; +} + diff --git a/interfaces/kits/js/app/context.d.ts b/interfaces/kits/js/app/context.d.ts index 2dc41d7f460..4ccb5f05a9e 100755 --- a/interfaces/kits/js/app/context.d.ts +++ b/interfaces/kits/js/app/context.d.ts @@ -15,12 +15,55 @@ import { AsyncCallback } from '../basic'; +/** + * The context of an ability or an application. It allows access to + * application-specific resources, request and verification permissions. + * Can only be obtained through the ability. + * + * @since 6 + * @SysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car + * @import import abilityManager from 'app/context' + * @permission N/A + */ +export interface Context { + + /** + * Verify whether the specified permission is allowed for a particular + * pid and uid running in the system. + * @param permission The name of the specified permission + * @param pid process id + * @param uid user id + * @note Pid and uid are optional. If you do not pass in pid and uid, + * it will check your own permission. + * @since 7 + * @sysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car + * @return asynchronous callback with {@code 0} if the PID + * and UID have the permission; callback with {@code -1} otherwise. + */ + verifyPermission(permission: string, options?: PermissionOptions): Promise; + verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback): void; + verifyPermission(permission: string, callback: AsyncCallback): void; + + /** + * Requests certain permissions from the system. + * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. + * @param requestCode Indicates the request code to be passed to the PermissionRequestResult + * @since 7 + * @sysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car + */ + requestPermissionsFromUser(permissions: Array, requestCode: number, resultCallback: AsyncCallback): void; + +} + /** * @name the result of requestPermissionsFromUser with asynchronous callback * @since 7 * @SysCap SystemCapability.Appexecfwk * @permission N/A - * @devices phone, tablet, tv, wearable + * @devices phone, tablet, tv, wearable, car */ interface PermissionRequestResult { /** @@ -47,52 +90,16 @@ interface PermissionRequestResult { interface PermissionOptions { /** - * @default The process id - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ + * @default The process id + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ pid?: number; /** - * @default The user id - * @since 7 - * @SysCap SystemCapability.Appexecfwk - */ - uid?: number; -} - -/** -* Requests certain permissions from the system. -* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. -* @param requestCode Indicates the request code to be passed to the PermissionRequestResult -* @since 7 -* @sysCap SystemCapability.Appexecfwk -* @devices phone, tablet, tv, wearable -*/ -export interface Context { - /** - * Verify whether the specified permission is allowed for a particular - * pid and uid running in the system. - * @param permission The name of the specified permission - * @param options process id and user id - * @since 7 - * @sysCap SystemCapability.Appexecfwk - * @devices phone, tablet, tv, wearable - * @return asynchronous callback with {@code 0} if the PID - * and UID have the permission; callback with {@code -1} otherwise. - */ - verifyPermission(permission: string, callback: AsyncCallback): void; - verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback): void; - verifyPermission(permission: string, options?: PermissionOptions): Promise; - - /** - * Requests certain permissions from the system. - * required for granting a certain permission. - * @devices phone + * @default The user id * @since 7 - * @sysCap AAFwk - * @param - - * @return Return grant result + * @SysCap SystemCapability.Appexecfwk */ - requestPermissionsFromUser(permissions: Array, requestCode: number, resultCallback: AsyncCallback): void; -} \ No newline at end of file + uid?: number; +} diff --git a/interfaces/kits/js/app/memoryMapInfo.d.ts b/interfaces/kits/js/app/memoryMapInfo.d.ts new file mode 100755 index 00000000000..4c8ab45c3b1 --- /dev/null +++ b/interfaces/kits/js/app/memoryMapInfo.d.ts @@ -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. + */ + +/** + * @name This class saves memory map information about an application. + * All results are in kB. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import import MemoryMapInfo from 'app/memoryMapInfo' + * @permission N/A + * @devices phone, tablet, tv, wearable, car + * @systemapi hide this for inner system use + */ +export interface MemoryMapInfo { + /** + * @default The pss page size for virtual machine heap + */ + vmPss: number; + /** + * @default The private dirty page size for virtual machine heap + */ + vmPrivateDirty: number; + /** + * @default The shared dirty page size for virtual machine heap + */ + vmSharedDirty: number; + /** + * @default The pss page size for native heap + */ + nativePss: number; + /** + * @default The private dirty page size for native heap + */ + nativePrivateDirty: number; + /** + * @default The shared dirty page size for native heap + */ + nativeSharedDirty: number; + /** + * @default The pss page size for others + */ + otherPss: number; + /** + * @default The private dirty page size for others + */ + otherPrivateDirty: number; + /** + * @default The shared dirty page size for others + */ + otherSharedDirty: number; +} diff --git a/interfaces/kits/napi/aafwk/context/napi_error.h b/interfaces/kits/js/app/missionSnapshot.d.ts old mode 100644 new mode 100755 similarity index 52% rename from interfaces/kits/napi/aafwk/context/napi_error.h rename to interfaces/kits/js/app/missionSnapshot.d.ts index f2199a40c7d..01ae787ee8c --- a/interfaces/kits/napi/aafwk/context/napi_error.h +++ b/interfaces/kits/js/app/missionSnapshot.d.ts @@ -13,9 +13,25 @@ * limitations under the License. */ -#ifndef NAPI_CONTEXT_ERROR_H -#define NAPI_CONTEXT_ERROR_H +import { ElementName } from '../bundle/elementName'; +import { image } from '../@ohos.multimedia.image'; -#define NAPI_ERR_NO_PERMISSION -100 +/** + * @name This class represents a mission snapshot. + * @since 7 + * @SysCap appexecfwk + * @import import MissionSnapshot from 'app/missionSnapshot' + * @devices phone, tablet + * @systemapi hide this for inner system use + */ +export interface MissionSnapshot { + /** + * @default The top ability in this mission snapshot + */ + topAbility: ElementName; -#endif + /** + * @default The entity of snapshot + */ + snapshot: image.PixelMap; +} diff --git a/interfaces/kits/js/app/processErrorInfo.d.ts b/interfaces/kits/js/app/processErrorInfo.d.ts new file mode 100755 index 00000000000..f08a28f7059 --- /dev/null +++ b/interfaces/kits/js/app/processErrorInfo.d.ts @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import { ProcessErrCode } from '../@ohos.app.abilityManager.d.ts'; + +/** + * @name This class saves process error information + * @since 7 + * @SysCap appexecfwk + * @import import app from 'app/processErrorInfo' + * @devices phone, tablet + * @systemapi hide this for inner system use + */ +export interface ProcessErrorInfo { + /** + * @default Error reason, see { ProcessErrCode } in abilityManager + */ + errStatus: ProcessErrCode; + /** + * @default the name of the error process + */ + processName: string; + /** + * @default the process ID + */ + pid: number; + /** + * @default the user ID + */ + uid: number; + /** + * @default the name of the ability corresponding with the error + */ + abilityName: string; + /** + * @default the error message + */ + errMsg: string; + /** + * @default the error trace, for you to find the original error + */ + backTrace: string; +} + diff --git a/interfaces/kits/js/app/processInfo.d.ts b/interfaces/kits/js/app/processInfo.d.ts deleted file mode 100644 index 8af0490e0c4..00000000000 --- a/interfaces/kits/js/app/processInfo.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* -* 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. -*/ - -/** - * @name This class saves process information about an application - * @since 6 - * @SysCap appexecfwk - * @import import app from '@system.app' - * @permission N/A - * @devices phone - */ - export interface ProcessInfo { - /** - * The id of the current process - * - * @default - - * @devices phone - * @since 6 - * @SysCap appexecfwk - */ - pid: number; - - /** - * The name of the current process - * - * @default - - * @devices phone - * @since 6 - * @SysCap appexecfwk - */ - processName: string; -} diff --git a/interfaces/kits/js/app/splitMissionInfo.d.ts b/interfaces/kits/js/app/splitMissionInfo.d.ts new file mode 100755 index 00000000000..6f911d73360 --- /dev/null +++ b/interfaces/kits/js/app/splitMissionInfo.d.ts @@ -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. + */ + +import { RectBounds } from '../wallpaper'; + +/** + * @name This class is the input param for { moveMissionToFirstSplitScreen }. + * @since 7 + * @SysCap appexecfwk + * @import import app from 'app/splitMissionInfo' + * @devices phone, tablet + * @systemapi hide this for inner system use + */ +export interface SplitMissionInfo { + /** + * @default the mission id that you want to move + */ + missionId: number; + /** + * @default whether the target window is the first one + */ + isFirstWindow: boolean; + /** + * @default whether to move the mission to top + */ + isToTop: boolean; + /** + * @default Whether you want an animation when moving the task + */ + isAnimating: boolean; + /** + * @default The bounds of the split window + */ + initialBounds: RectBounds; +} diff --git a/interfaces/kits/js/ability/connectOptions.d.ts b/interfaces/kits/js/app/systemMemoryAttr.d.ts old mode 100644 new mode 100755 similarity index 46% rename from interfaces/kits/js/ability/connectOptions.d.ts rename to interfaces/kits/js/app/systemMemoryAttr.d.ts index 9247001a4d2..eee6e70681a --- a/interfaces/kits/js/ability/connectOptions.d.ts +++ b/interfaces/kits/js/app/systemMemoryAttr.d.ts @@ -1,32 +1,44 @@ -/* - * 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. - */ -import rpc from './../@ohos.rpc'; -import { ElementName } from '../bundle/elementName'; - -/** - * Provides callback methods that are called when a remote ability using the Service template is connected or - * disconnected. - * - *

You must override the methods of this interface to implement your processing logic for the connection and - * disconnection of an ability using the Service template (Service ability for short).

- * - * @Syscap {@link SystemCapability.Aafwk#ABILITY} - * @since 1 - */ -declare interface ConnectOptions { - onConnect: (elementName: ElementName, iRemoteObject: IRemoteObject) => void; - onDisconnect: (elementName: ElementName) => void; - onFailed: (code: number) => void; -} \ No newline at end of file +/* + * 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. + */ + +/** + * @name This class saves system memory attributes + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @import import MemoryMapInfo from 'app/systemMemoryAttr' + * @devices phone, tablet, tv, wearable, car + * @systemapi hide this for inner system use + */ + export interface SystemMemoryAttr { + /** + * @default The available memory on the system + */ + availSysMem: number; + /** + * @default The total memory on the system + */ + totalSysMem: number; + /** + * @default The low memory threshold under which the system + * will kill background processes + */ + threshold: number; + /** + * @default Whether the system is in low memory status + */ + isSysInlowMem: boolean; +} + + diff --git a/interfaces/kits/js/bundle/abilityInfo.d.ts b/interfaces/kits/js/bundle/abilityInfo.d.ts index 08ccc709df0..7e6904ab2e9 100644 --- a/interfaces/kits/js/bundle/abilityInfo.d.ts +++ b/interfaces/kits/js/bundle/abilityInfo.d.ts @@ -1,59 +1,244 @@ -/* - * 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. - */ -import { ApplicationInfo } from './applicationInfo'; -import { CustomizeData } from './customizeData' -import bundle from './../@ohos.bundle'; - -/** - * @name AbilityInfo - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface AbilityInfo { - readonly bundleName: string; - readonly name: string; - readonly label: string; - readonly description: string; - readonly icon: string; - readonly labelId: number; - readonly descriptionId: number; - readonly iconId: number; - readonly moduleName: string; - readonly process: string; - readonly targetAbility: string; - readonly backgroundModes: number; - readonly isVisible: boolean; - readonly formEnabled: boolean; - readonly type: bundle.AbilityType; - readonly subType: bundle.AbilitySubType; - readonly orientation: bundle.DisplayOrientation; - readonly launchMode: bundle.LaunchMode; - readonly permissions: Array; - readonly deviceTypes: Array; - readonly deviceCapabilities: Array; - readonly readPermission: string; - readonly writePermission: string; - readonly applicationInfo: ApplicationInfo; - readonly formEntity: number; - readonly minFormHeight: number; - readonly defaultFormHeight: number; - readonly minFormWidth: number; - readonly defaultFormWidth: number; - readonly uri: string; - customizeData: Map>; -} +/* + * 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. + */ + +import { ApplicationInfo } from './applicationInfo'; +import { CustomizeData } from './customizeData' +import bundle from './../@ohos.bundle'; + +/** + * @name Obtains configuration information about an ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface AbilityInfo { + /** + * @default Indicates the name of the bundle containing the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly bundleName: string; + + /** + * @default Ability simplified class name + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly name: string; + + /** + * @default Indicates the label of the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly label: string; + + /** + * @default Describes the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly description: string; + + /** + * @default Indicates the icon of the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly icon: string; + + /** + * @default Indicates the label id of the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly labelId: number; + + /** + * @default Indicates the description id of the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly descriptionId: number; + + /** + * @default Indicates the icon id of the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly iconId: number; + + /** + * @default Indicates the name of the .hap package to which the capability belongs + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly moduleName: string; + + /** + * @default Process of ability, if user do not set it ,the value equal application process + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly process: string; + + /** + * @default Info about which ability is this nick point to + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly targetAbility: string; + + /** + * @default Indicates the background service addressing a specific usage scenario + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly backgroundModes: number; + + /** + * @default Indicates whether an ability can be called by other abilities + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly isVisible: boolean; + + /** + * @default Indicates whether the ability provides the embedded card capability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly formEnabled: boolean; + + /** + * @default Enumerates types of templates that can be used by an ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly type: bundle.AbilityType; + + /** + * @default Enumerates the subType of templates used by an ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly subType: bundle.AbilitySubType; + + /** + * @default Enumerates ability display orientations + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly orientation: bundle.DisplayOrientation; + + /** + * @default Enumerates ability launch modes + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly launchMode: bundle.LaunchMode; + + /** + * @default The permissions that others need to launch this ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly permissions: Array; + + /** + * @default The device types that this ability can run on + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly deviceTypes: Array; + + /** + * @default The device capability that this ability needs + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly deviceCapabilities: Array; + + /** + * @default Indicates the permission required for reading ability data + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly readPermission: string; + + /** + * @default Indicates the permission required for writing data to the ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly writePermission: string; + + /** + * @default Obtains configuration information about an application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly applicationInfo: ApplicationInfo; + + /** + * @default Where form can be displayed + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly formEntity: number; + + /** + * @default Minimum height of ability. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly minFormHeight: number; + + /** + * @default Default height of ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly defaultFormHeight: number; + + /** + * @default Minimum width of ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly minFormWidth: number; + + /** + * @default Default width of ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly defaultFormWidth: number; + + /** + * @default Uri of ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly uri: string; + + /** + * @default Indicates the custom metadata of ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + customizeData: Map>; +} diff --git a/interfaces/kits/js/bundle/applicationInfo.d.ts b/interfaces/kits/js/bundle/applicationInfo.d.ts index 86f76f69cbf..4820474ef88 100644 --- a/interfaces/kits/js/bundle/applicationInfo.d.ts +++ b/interfaces/kits/js/bundle/applicationInfo.d.ts @@ -1,43 +1,138 @@ -/* - * 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. - */ -import { ModuleInfo } from './moduleInfo'; -import { CustomizeData } from './customizeData' - -/** - * @name ApplicationInfo - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface ApplicationInfo { - readonly name: string; - readonly description: string; - readonly descriptionId: number; - readonly systemApp: boolean; - readonly enabled: boolean; - readonly label: string; - readonly labelId: string; - readonly icon: string; - readonly iconId: string; - readonly process: string; - readonly supportedModes: number; - readonly moduleSourceDirs: Array; - readonly permissions: Array; - readonly moduleInfos: Array; - readonly entryDir: string; - customizeData: Map; +/* + * 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. + */ + +import { ModuleInfo } from './moduleInfo'; +import { CustomizeData } from './customizeData' + +/** + * @name Obtains configuration information about an application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface ApplicationInfo { + /** + * @default Indicates the application name, which is the same as {@code bundleName} + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly name: string; + + /** + * @default Description of application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly description: string; + + /** + * @default Indicates the description id of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly descriptionId: number; + + /** + * @default Indicates whether the application is a system application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly systemApp: boolean; + + /** + * @default Indicates whether or not this application may be instantiated + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly enabled: boolean; + + /** + * @default Indicates the label of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly label: string; + + /** + * @default Indicates the label id of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly labelId: string; + + /** + * @default Indicates the icon of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly icon: string; + + /** + * @default Indicates the icon id of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly iconId: string; + + /** + * @default Process of application, if user do not set it ,the value equal bundleName + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly process: string; + + /** + * @default Indicates the running mode supported by the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly supportedModes: number; + + /** + * @default Indicates the path storing the module resources of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly moduleSourceDirs: Array; + + /** + * @default Indicates the permissions required for accessing the application. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly permissions: Array; + + /** + * @default Indicates module information about an application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly moduleInfo: Array; + + /** + * @default Indicates the path where the {@code Entry.hap} file of the application is saved + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly entryDir: string; + + /** + * @default Indicates the custom metadata of the application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + customizeData: Map; } \ No newline at end of file diff --git a/interfaces/kits/js/bundle/bundleInfo.d.ts b/interfaces/kits/js/bundle/bundleInfo.d.ts index 58c69d4616c..6353eaef993 100644 --- a/interfaces/kits/js/bundle/bundleInfo.d.ts +++ b/interfaces/kits/js/bundle/bundleInfo.d.ts @@ -1,74 +1,237 @@ -/* - * 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. - */ -import { AbilityInfo } from './abilityInfo'; -import { ApplicationInfo } from './applicationInfo'; - -/** - * @name UsedScene - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface UsedScene { - abilities: Array; - when: string; -} - -/** - * @name ReqPermissionDetail - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface ReqPermissionDetail { - name: string; - reason: string; - usedScene: UsedScene; -} - -/** - * @name BundleInfo - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface BundleInfo { - readonly name: string; - readonly type: string; - readonly appId: string; - readonly uid: number; - readonly installTime: number; - readonly updateTime: number; - readonly appInfo: ApplicationInfo; - readonly abilityInfos: Array; - readonly reqPermissions: Array; - readonly vendor: string; - readonly versionCode: number; - readonly versionName: string; - readonly compatibleVersion: number; - readonly targetVersion: number; - readonly isCompressNativeLibs: boolean; - readonly entryModuleName: string; - readonly cpuAbi: string; - readonly isSilentInstallation: string; - readonly minCompatibleVersionCode: number; - readonly entryInstallationFree: boolean; -} +/* + * 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. + */ + +import { AbilityInfo } from './abilityInfo'; +import { ApplicationInfo } from './applicationInfo'; +import { HapModuleInfo } from './hapModuleInfo'; + +/** + * @name The scene which is used + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface UsedScene { + /** + * @default Indicates the abilities that need the permission + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + abilities: Array; + + /** + * @default Indicates the time when the permission is used + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + when: string; +} + +/** + * @name Indicates the required permissions details defined in file config.json + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface ReqPermissionDetail { + /** + * @default Indicates the name of this required permissions + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + name: string; + + /** + * @default Indicates the reason of this required permissions + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + reason: string; + + /** + * @default Indicates the used scene of this required permissions + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + usedScene: UsedScene; +} + +/** + * @name Obtains configuration information about a bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface BundleInfo { + /** + * @default Indicates the name of this bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly name: string; + + /** + * @default Indicates the name of this original bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly type: string; + + /** + * @default Indicates the ID of the application to which this bundle belongs + * The application ID uniquely identifies an application. It is determined by the bundle name and signature + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly appId: string; + + /** + * @default Indicates the UID of the application to which this bundle belongs + * The UID uniquely identifies an application. It is determined by the process and user IDs of the application + * After an application is installed, its UID remains unchanged unless it is uninstalled and then reinstalled + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly uid: number; + + /** + * @default Indicates the hap install time + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly installTime: number; + + /** + * @default Indicates the hap update time + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly updateTime: number; + + /** + * @default Obtains configuration information about an application + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly appInfo: ApplicationInfo; + + /** + * @default Obtains configuration information about an ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly abilityInfo: Array; + + /** + * @default Indicates the required permissions name defined in file config.json + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly reqPermissions: Array; + + /** + * @default Indicates the required permissions details defined in file config.json + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly reqPermissionDetails: Array; + + /** + * @default Describes the bundle vendor + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly vendor: string; + + /** + * @default Indicates the version number of the bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly versionCode: number; + + /** + * @default Indicates the text description of the bundle version + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly versionName: string; + + /** + * @default Indicates the compatible version number of the bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly compatibleVersion: number; + + /** + * @default Indicates the target version number of the bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly targetVersion: number; + + /** + * @default Indicates is compress native libs + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly isCompressNativeLibs: boolean; + + /** + * @default Obtains configuration information about an module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly hapModuleInfo: Array; + + /** + * @default Indicates entry module name + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly entryModuleName: string; + + /** + * @default Indicates the cpuAbi information of this bundle. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly cpuAbi: string; + + /** + * @default Indicates is silent installation + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly isSilentInstallation: string; + + /** + * @default Indicates the earliest historical version compatible with the bundle + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly minCompatibleVersionCode: number; + + /** + * @default Indicates whether free installation of the entry is supported + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly entryInstallationFree: boolean; +} diff --git a/interfaces/kits/js/bundle/bundleInstaller.d.ts b/interfaces/kits/js/bundle/bundleInstaller.d.ts index 8e4a49e0768..5cdfc48f780 100644 --- a/interfaces/kits/js/bundle/bundleInstaller.d.ts +++ b/interfaces/kits/js/bundle/bundleInstaller.d.ts @@ -1,86 +1,107 @@ -/* - * 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. - */ - -import { AsyncCallback } from './../basic'; -import bundle from './../@ohos.bundle'; - -/** - * @name InstallParam - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface InstallParam { - userId: number; - installFlag: number; - isKeepData: boolean; -} - -/** - * @name InstallStatus - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface InstallStatus { - status: bundle.InstallErrorCode; - /** - * The install result string message. - * - * @default - - * @devices phone, tablet - * @since 3 - * @SysCap BMS - */ - statusMessage: string; -} - -/** - * @name BundleInstaller - * @since 3 - * @SysCap BMS - * @import NA - * @permission NA - * @devices phone, tablet - */ -export interface BundleInstaller { - /** - * Install an application in a HAP. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param bundleFilePaths Indicates the paths of the HAP. - * @param InstallParam Indicates the userId and whether keep data. - * @return InstallStatus - */ - install(bundleFilePaths: Array, param: InstallParam, callback: AsyncCallback): void; - - /** - * Uninstall an application. - * - * @devices phone, tablet - * @since 3 - * @SysCap BMS - * @param bundleName Indicates the bundle name. - * @param InstallParam Indicates the userId and whether keep data. - * @return InstallStatus - */ - uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback): void; +/* + * 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. + */ + +import { AsyncCallback } from './../basic'; +import bundle from './../@ohos.bundle'; + +/** + * @name Provides parameters required for installing or uninstalling an application. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface InstallParam { + /** + * @default Indicates the user id + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + userId: number; + + /** + * @default Indicates the install flag + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + installFlag: number; + + /** + * @default Indicates whether the param has data + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + isKeepData: boolean; +} + +/** + * @name Indicates the install or uninstall status + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface InstallStatus { + + /** + * @default Indicates the install or uninstall error code + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + status: bundle.InstallErrorCode; + + /** + * @default Indicates the install or uninstall result string message + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + statusMessage: string; +} + +/** + * @name Offers install, upgrade, and remove bundles on the devices. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface BundleInstaller { + /** + * Install an application in a HAP. + * + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car + * @param bundleFilePaths Indicates the path where the bundle of the application is stored. The path should be the + * relative path to the data directory of the current application. + * @param installParam Indicates other parameters required for the installation. + * @return InstallStatus + * @permission ohos.permission.INSTALL_BUNDLE + */ + install(bundleFilePaths: Array, param: InstallParam, callback: AsyncCallback): void; + + /** + * Uninstall an application. + * + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car + * @param bundleName Indicates the bundle name of the application to be uninstalled. + * @param installParam Indicates other parameters required for the uninstallation. + * @return InstallStatus + * @permission ohos.permission.INSTALL_BUNDLE + */ + uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback): void; } \ No newline at end of file diff --git a/interfaces/kits/js/bundle/customizeData.d.ts b/interfaces/kits/js/bundle/customizeData.d.ts index 68258099d6e..17393229f1f 100644 --- a/interfaces/kits/js/bundle/customizeData.d.ts +++ b/interfaces/kits/js/bundle/customizeData.d.ts @@ -13,7 +13,25 @@ * limitations under the License. */ + /** + * @name Indicates the custom metadata + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ export interface CustomizeData { + /** + * @default Indicates the custom metadata name + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ name: string; + + /** + * @default Indicates the custom metadata value + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ value: string; } \ No newline at end of file diff --git a/interfaces/kits/js/bundle/elementName.d.ts b/interfaces/kits/js/bundle/elementName.d.ts index fa0552f7049..68fe8ddda30 100644 --- a/interfaces/kits/js/bundle/elementName.d.ts +++ b/interfaces/kits/js/bundle/elementName.d.ts @@ -17,55 +17,55 @@ * Contains basic Ability information, which uniquely identifies an ability. * You can use this class to obtain values of the fields set in an element, * such as the device ID, bundle name, and ability name. - * @name ElementName - * @since 3 - * @sysCap AAFwk - * @devices phone, tablet + * @name Contains basic Ability information, which uniquely identifies an ability + * @since 7 + * @sysCap SystemCapability.Appexecfwk + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface ElementName { /** * device id * @default - - * @devices phone, tablet - * @since 3 - * @sysCap AAFwk + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @sysCap SystemCapability.Appexecfwk */ deviceId?: string; /** * bundle name * @default - - * @devices phone, tablet - * @since 3 - * @sysCap AAFwk + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @sysCap SystemCapability.Appexecfwk */ bundleName: string; /** * ability name - * @default - - * @devices phone, tablet - * @since 3 - * @sysCap AAFwk + * @default ability class name. + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @sysCap SystemCapability.Appexecfwk */ abilityName: string; /** - * shortName name + * uri * @default - - * @devices phone, tablet - * @since 3 - * @sysCap AAFwk + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @sysCap SystemCapability.Appexecfwk */ uri?: string; /** - * shortName name + * shortName * @default - - * @devices phone, tablet - * @since 3 - * @sysCap AAFwk + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @sysCap SystemCapability.Appexecfwk */ shortName?: string; } diff --git a/interfaces/kits/js/bundle/hapModuleInfo.d.ts b/interfaces/kits/js/bundle/hapModuleInfo.d.ts new file mode 100644 index 00000000000..a62a66955d3 --- /dev/null +++ b/interfaces/kits/js/bundle/hapModuleInfo.d.ts @@ -0,0 +1,116 @@ +/* + * 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. + */ + +import { AbilityInfo } from "./abilityInfo"; + +/** + * @name Obtains configuration information about an module. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface HapModuleInfo { + /** + * @default Indicates the name of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly name: string; + /** + * @default Describes the hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly description: string; + /** + * @default Indicates the description of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly descriptionId: number; + /** + * @default Indicates the icon of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly icon: string; + /** + * @default Indicates the label of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly label: string; + /** + * @default Indicates the label id of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly labelId: number; + /** + * @default Indicates the icon id of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly iconId: number; + /** + * @default Indicates the background img of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly backgroundImg: string; + /** + * @default Indicates the supported modes of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly supportedModes: number; + /** + * @default Indicates the req capabilities of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly reqCapabilities: Array; + /** + * @default The device types that this hapmodule can run on + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly deviceTypes: Array; + /** + * @default Obtains configuration information about ability + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly abilityInfo: Array; + /** + * @default Indicates the name of the .hap package to which the capability belongs + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly moduleName: string; + /** + * @default Indicates the main ability name of this hapmodule + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly mainAbilityName: string; + /** + * @default Indicates whether free installation of the hapmodule is supported + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly installationFree: boolean; +} \ No newline at end of file diff --git a/interfaces/kits/js/bundle/moduleInfo.d.ts b/interfaces/kits/js/bundle/moduleInfo.d.ts index b856a0042b9..437ca90fa90 100644 --- a/interfaces/kits/js/bundle/moduleInfo.d.ts +++ b/interfaces/kits/js/bundle/moduleInfo.d.ts @@ -14,31 +14,30 @@ */ /** - * @name ModuleInfo - * @since 3 - * @SysCap BMS - * @import NA + * @name Stores module information about an application. + * @since 7 + * @SysCap SystemCapability.Appexecfwk * @permission NA - * @devices phone, tablet + * @devices phone, tablet, tv, wearable, car */ export interface ModuleInfo { /** * The module name. * - * @default - - * @devices phone, tablet - * @since 3 - * @SysCap BMS + * @default Indicates the name of the .hap package to which the capability belongs + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @SysCap SystemCapability.Appexecfwk */ readonly moduleName: string; /** * The module source path. * - * @default - - * @devices phone, tablet - * @since 3 - * @SysCap BMS + * @default Indicates the module source dir of this module + * @devices phone, tablet, tv, wearable, car + * @since 7 + * @SysCap SystemCapability.Appexecfwk */ readonly moduleSourceDir: string; } \ No newline at end of file diff --git a/interfaces/kits/js/bundle/moduleUsageRecord.d.ts b/interfaces/kits/js/bundle/moduleUsageRecord.d.ts index 8cc84046b05..0bc3620102c 100644 --- a/interfaces/kits/js/bundle/moduleUsageRecord.d.ts +++ b/interfaces/kits/js/bundle/moduleUsageRecord.d.ts @@ -13,18 +13,91 @@ * limitations under the License. */ +/** + * @name Stores FA usage information. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + * @systemapi hide this for inner system use + */ export interface ModuleUsageRecord { + /** + * @default Indicates the name of the bundle containing the module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly bundleName: string; + /** + * @default Indicates the app label id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly appLabelId: number; + /** + * @default Indicates the name of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly name: string; + /** + * @default Indicates the label id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly labelId: number; + /** + * @default Indicates the description id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly descriptionId: number; + /** + * @default Indicates the ability name of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly abilityName: string; + /** + * @default Indicates the ability label id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly abilityLabelId: number; + /** + * @default Indicates the ability description id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly abilityDescriptionId: number; + /** + * @default Indicates the ability icon id of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly abilityIconId: number; + /** + * @default Indicates the launched count of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly launchedCount: number; + /** + * @default Indicates the last launch time of this module + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly lastLaunchTime: number; + /** + * @default Indicates whether the module is removed + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly isRemoved: boolean; + /** + * @default Indicates whether free installation of the module is supported + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly installationFreeSupported: boolean; } \ No newline at end of file diff --git a/interfaces/kits/js/bundle/shortcutInfo.d.ts b/interfaces/kits/js/bundle/shortcutInfo.d.ts index 1e6ce78bf9d..0caaa904588 100644 --- a/interfaces/kits/js/bundle/shortcutInfo.d.ts +++ b/interfaces/kits/js/bundle/shortcutInfo.d.ts @@ -12,20 +12,96 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export interface ShortcutIntent{ + + /** + * @name Provides methods for obtaining information about the ability that a shortcut will start, including the target + * bundle name and ability class name. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ +export interface ShortcutWant{ + /** + * @default Indicates the target bundle of the shortcut want + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly targetBundle: string; + /** + * @default Indicates the target class of the shortcut want + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly targetClass: string; } + /** + * @name Provides information about a shortcut, including the shortcut ID and label. + * @since 7 + * @SysCap SystemCapability.Appexecfwk + * @permission NA + * @devices phone, tablet, tv, wearable, car + */ export interface ShortcutInfo { + /** + * @default Indicates the ID of the application to which this shortcut belongs + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly id: string; + /** + * @default Indicates the name of the bundle containing the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly bundleName: string; + /** + * @default Indicates the host ability of the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly hostAbility: string; + /** + * @default Indicates the icon of the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly icon: string; + /** + * @default Indicates the label of the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly label: string; + /** + * @default Indicates the disableMessage of the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly disableMessage: string; - readonly intents: Array; + /** + * @default Indicates the wants of the shortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ + readonly wants: Array; + /** + * @default Indicates whether the shortcut is static + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly isStatic?: boolean + /** + * @default Indicates whether the shortcut is homeshortcut + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly isHomeShortcut?: boolean; + /** + * @default Indicates whether the shortcut is enabled + * @since 7 + * @SysCap SystemCapability.Appexecfwk + */ readonly isEnabled?: boolean; } \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/context/BUILD.gn b/interfaces/kits/napi/aafwk/context/BUILD.gn deleted file mode 100644 index 373c8d581bc..00000000000 --- a/interfaces/kits/napi/aafwk/context/BUILD.gn +++ /dev/null @@ -1,51 +0,0 @@ -# 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. - -# import("//build/config/ohos/rules.gni") -import("//build/ohos.gni") -ohos_shared_library("context") { - include_dirs = [ - "//foundation/ace/napi/interfaces/kits", - "//third_party/node/src", - "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility", - "//foundation/aafwk/standard/frameworks/kits/ability/native/include", - "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/context", - ] - - sources = [ - "napi_context.cpp", - "native_module.cpp", - ] - - deps = [ - "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/ace/napi:ace_napi", - "//foundation/appexecfwk/standard/kits:appkit_native", - "//utils/native/base:utils", - ] - - external_deps = [ - "aafwk_standard:ability_manager", - "aafwk_standard:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", - "communication_L2:ipc_core", - "hiviewdfx_hilog_native:libhilog", - ] - - relative_install_dir = "module" - - subsystem_name = "aafwk" - part_name = "aafwk_standard" -} diff --git a/interfaces/kits/napi/aafwk/context/napi_context.cpp b/interfaces/kits/napi/aafwk/context/napi_context.cpp deleted file mode 100644 index 770eb523111..00000000000 --- a/interfaces/kits/napi/aafwk/context/napi_context.cpp +++ /dev/null @@ -1,876 +0,0 @@ -/* - * 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 "securec.h" -#include "napi_context.h" -#include "hilog_wrapper.h" -#include "ability_process.h" -#include "napi_error.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -#define PERMISSOIN_EVENT_VERIFYSELFPERMISSION 1 -#define PERMISSION_EVENT_REQUEST_PERMISSION 2 - -namespace OHOS { -namespace AppExecFwk { -CallbackInfo aceCallbackInfoPermission; - -static void VerifySelfPermissionExecuteCallback(napi_env env, void *data); -static void RequestPermissionsFromUserExecuteCallback(napi_env env, void *data); -static void RequestPermissionsFromUserExecutePromise(napi_env env, void *data); -static napi_value NAPI_RequestPermissionsFromUserWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo); -static napi_value NAPI_VerifySelfPermissionWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo); -static napi_value NAPI_VerifySelfPermission(napi_env env, napi_callback_info info); -static napi_value NAPI_RequestPermissionsFromUser(napi_env env, napi_callback_info info); -static napi_value NAPI_OnRequestPermissionsFromUserResultWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo); -static napi_value NAPI_OnRequestPermissionsFromUserResult(napi_env env, napi_callback_info info); -static void GetBundleNameExecuteCallback(napi_env env, void *data); -static napi_value NAPI_GetBundleNameWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo); -static napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info); - -/** - * @brief Context NAPI module registration. - * - * @param env The environment that the Node-API call is invoked under. - * @param exports An empty object via the exports parameter as a convenience. - * - * @return The return value from Init is treated as the exports object for the module. - */ -napi_value ContextPermissionInit(napi_env env, napi_value exports) -{ - HILOG_INFO("Context::ContextPermissionInit called."); - - napi_property_descriptor properties[] = { - DECLARE_NAPI_FUNCTION("verifySelfPermission", NAPI_VerifySelfPermission), - DECLARE_NAPI_FUNCTION("requestPermissionsFromUser", NAPI_RequestPermissionsFromUser), - DECLARE_NAPI_FUNCTION("onRequestPermissionsFromUserResult", NAPI_OnRequestPermissionsFromUserResult), - DECLARE_NAPI_FUNCTION("getBundleName", NAPI_GetBundleName), - }; - - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); - return exports; -} - -void ClearNativeData(ThreadReturnData *data) -{ - if (data != nullptr) { - data->data_type = NVT_NONE; - data->int32_value = 0; - data->bool_value = false; - data->str_value = ""; - } -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to AsyncPermissionCallbackInfo on success, nullptr on failure - */ -AsyncPermissionCallbackInfo *CreateAsyncPermissionCallbackInfo(napi_env env) -{ - napi_value global = 0; - NAPI_CALL(env, napi_get_global(env, &global)); - - napi_value abilityObj = 0; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); - - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncPermissionCallbackInfo{ - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .ability = ability, - .aceCallback = nullptr, - }; - if (asyncCallbackInfo != nullptr) { - ClearNativeData(&asyncCallbackInfo->native_data); - } - return asyncCallbackInfo; -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * @param argc Number of parameters. - * @param startIndex The position of the first event parameter. - * @param args Parameter list. - * @param callback Point to asynchronous processing of data. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value CreateAsyncCallback( - napi_env env, size_t argc, size_t startIndex, napi_value *args, AsyncPermissionCallbackInfo *callback) -{ - if (args == nullptr) { - return nullptr; - } - - size_t argCount = (argc - startIndex > PERMISSION_EVENT_SIZE) ? (startIndex + PERMISSION_EVENT_SIZE) : argc; - - for (size_t i = startIndex; i < argCount; i++) { - napi_valuetype valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[i], &valueType)); - if (valueType != napi_function) { - return nullptr; - } - NAPI_CALL(env, napi_create_reference(env, args[i], 1, &callback->callback[i - startIndex])); - } - - napi_value result = 0; - NAPI_CALL(env, napi_create_int32(env, 1, &result)); - return result; -} - -/** - * @brief Parse JS string parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return stirng value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamString(std::vector &value, napi_env env, napi_value args) -{ - HILOG_INFO("Context::UnwrapParamString in."); - char buf[PERMISSION_C_BUFFER_SIZE] = {0}; - size_t len = 0; - - // unwrap the param : permission - memset_s(buf, sizeof(buf), 0x0, sizeof(buf)); - NAPI_CALL(env, napi_get_value_string_utf8(env, args, buf, PERMISSION_C_BUFFER_SIZE, &len)); - value.push_back(std::string(buf)); - HILOG_INFO("Context::UnwrapParamString permission=%{public}s.", buf); - - // create result code - napi_value result = 0; - NAPI_CALL(env, napi_create_int32(env, 1, &result)); - return result; -} - -/** - * @brief Parse JS numeric parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return integer value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamInt(int *value, napi_env env, napi_value args) -{ - if (value == nullptr) { - HILOG_INFO("Invalid param(value = nullptr)"); - return nullptr; - } - - napi_valuetype valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args, &valueType)); - if (valueType != napi_number) { - return nullptr; - } - - int32_t value32 = 0; - NAPI_CALL(env, napi_get_value_int32(env, args, &value32)); - HILOG_INFO("UnwrapParamInt value=%{public}d", value32); - *value = value32; - napi_value result = 0; - NAPI_CALL(env, napi_create_int32(env, 1, &result)); - return result; -} - -/** - * @brief Parse JS array of string parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return array of stirng value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamArrayString(std::vector &value, napi_env env, napi_value args) -{ - value.clear(); - char buf[PERMISSION_C_BUFFER_SIZE] = {0}; - size_t len = 0; - napi_valuetype valueType = napi_undefined; - - bool isArray = false; - uint32_t arrayLength = 0; - napi_value valueArray = 0; - - NAPI_CALL(env, napi_is_array(env, args, &isArray)); - if (!isArray) { - HILOG_INFO("property type mismatch"); - return nullptr; - } - - NAPI_CALL(env, napi_get_array_length(env, args, &arrayLength)); - HILOG_INFO("property is array, length=%{public}d", arrayLength); - - for (uint32_t i = 0; i < arrayLength; i++) { - memset_s(buf, sizeof(buf), 0x0, sizeof(buf)); - - NAPI_CALL(env, napi_get_element(env, args, i, &valueArray)); - NAPI_CALL(env, napi_typeof(env, valueArray, &valueType)); - if (valueType != napi_string) { - return nullptr; - } - - NAPI_CALL(env, napi_get_value_string_utf8(env, valueArray, buf, PERMISSION_C_BUFFER_SIZE, &len)); - HILOG_INFO("UnwrapParamInt array string value=%{public}s", buf); - - value.emplace_back(std::string(buf)); - } - - napi_value result = 0; - NAPI_CALL(env, napi_create_int32(env, 1, &result)); - return result; -} - -/** - * @brief Convert local data to JS data. - * - * @param env The environment that the Node-API call is invoked under. - * @param data The local data. - * @param value the JS data. - * - * @return The return value from NAPI C++ to JS for the module. - */ -void NAPI_GetNapiValue(napi_env env, const ThreadReturnData *data, napi_value *value) -{ - if (data == nullptr || value == nullptr) { - return; - } - switch (data->data_type) { - case NVT_INT32: - napi_create_int32(env, data->int32_value, value); - break; - case NVT_BOOL: - napi_create_int32(env, data->bool_value ? 1 : 0, value); - break; - case NVT_STRING: - napi_create_string_utf8(env, data->str_value.c_str(), NAPI_AUTO_LENGTH, value); - break; - default: - napi_get_null(env, value); - break; - } -} - -/** - * @brief VerifySelfPermission asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void VerifySelfPermissionExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("Context::NAPI_VerifySelfPermission worker pool thread execute."); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo != nullptr) { - int rev = -1; - if (asyncCallbackInfo->ability != nullptr && asyncCallbackInfo->param.permission_list.size() > 0) { - rev = asyncCallbackInfo->ability->VerifySelfPermission(asyncCallbackInfo->param.permission_list[0]); - } - - asyncCallbackInfo->native_data.data_type = NVT_INT32; - asyncCallbackInfo->native_data.int32_value = rev; - - asyncCallbackInfo->run_status = (rev == 0) ? true : false; - if (asyncCallbackInfo->run_status == false) { - asyncCallbackInfo->error_code = NAPI_ERR_NO_PERMISSION; - } - } -} - -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void AsyncCompleteCallback(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("main event thread complete."); - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo == nullptr) { - return; - } - - const size_t cbCount = 2; - napi_value callback = 0; - napi_value undefined = 0; - napi_get_undefined(env, &undefined); - napi_value result = 0; - napi_value callResult = 0; - NAPI_GetNapiValue(env, &asyncCallbackInfo->native_data, &result); - if (asyncCallbackInfo->run_status) { - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, 1, &result, &callResult); - - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - } else { - if (asyncCallbackInfo->callback[1] != nullptr) { - napi_value rev[2] = {nullptr}; - napi_create_int32(env, asyncCallbackInfo->error_code, &rev[0]); - napi_create_int32(env, asyncCallbackInfo->run_status ? 0 : -1, &rev[1]); - napi_get_reference_value(env, asyncCallbackInfo->callback[1], &callback); - napi_call_function(env, undefined, callback, cbCount, rev, &callResult); - napi_delete_reference(env, asyncCallbackInfo->callback[1]); - } - } - - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; -} - -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void PromiseCompleteCallback(napi_env env, napi_status status, void *data) -{ - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo != nullptr) { - napi_value result = 0; - NAPI_GetNapiValue(env, &asyncCallbackInfo->native_data, &result); - napi_resolve_deferred(env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - } -} - -/** - * @brief Asynchronous callback processing. - * - * @param env The environment that the Node-API call is invoked under. - * @param args list of JS of param. - * @param asyncCallbackInfo Process data asynchronously. - * @param param other param. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value ExecuteAsyncCallback( - napi_env env, napi_value *args, AsyncPermissionCallbackInfo *asyncCallbackInfo, const AsyncParamEx *param) -{ - if (param == nullptr) { - return nullptr; - } - - napi_value resourceName = 0; - NAPI_CALL(env, napi_create_string_latin1(env, param->resource.c_str(), NAPI_AUTO_LENGTH, &resourceName)); - if (CreateAsyncCallback(env, param->argc, param->startIndex, args, asyncCallbackInfo) == nullptr) { - return nullptr; - } - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - param->execute, - param->complete, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - - // create result code - napi_value result = 0; - NAPI_CALL(env, napi_get_null(env, &result)); - - return result; -} - -/** - * @brief Asynchronous promise processing. - * - * @param env The environment that the Node-API call is invoked under. - * @param args list of JS of param. - * @param asyncCallbackInfo Process data asynchronously. - * @param param other param. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value ExecutePromiseCallback( - napi_env env, napi_value *args, AsyncPermissionCallbackInfo *asyncCallbackInfo, const AsyncParamEx *param) -{ - if (args == nullptr) { - return nullptr; - } - - napi_value resourceName = 0; - NAPI_CALL(env, napi_create_string_latin1(env, param->resource.c_str(), NAPI_AUTO_LENGTH, &resourceName)); - - napi_deferred deferred = 0; - napi_value promise = 0; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - - asyncCallbackInfo->deferred = deferred; - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - param->execute, - param->complete, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - return promise; -} - -/** - * @brief VerifySelfPermission processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param asyncCallbackInfo Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value NAPI_VerifySelfPermissionWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo) -{ - size_t argc = 3; - const size_t argCount = 1; - napi_value args[PERMISSION_ARGS_SIZE] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - CallAbilityPermissionParam param; - if (UnwrapParamString(param.permission_list, env, args[0]) == nullptr) { - return nullptr; - } - asyncCallbackInfo->param = param; - - AsyncParamEx asyncParamEx; - asyncParamEx.argc = argc; - - if (argc > argCount) { - HILOG_INFO("Context::NAPI_VerifySelfPermission asyncCallback."); - asyncParamEx.resource = "NAPI_VerifySelfPermission1"; - asyncParamEx.startIndex = PERMISSOIN_EVENT_VERIFYSELFPERMISSION; - asyncParamEx.execute = VerifySelfPermissionExecuteCallback; - asyncParamEx.complete = AsyncCompleteCallback; - return ExecuteAsyncCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("Context::NAPI_VerifySelfPermission promise."); - asyncParamEx.resource = "NAPI_VerifySelfPermission2"; - asyncParamEx.startIndex = 0; - asyncParamEx.execute = VerifySelfPermissionExecuteCallback; - asyncParamEx.complete = PromiseCompleteCallback; - - return ExecutePromiseCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } -} - -/** - * @brief Checks whether the current process has the given permission. - * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only - * if the current process does not have the specific permission. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ -napi_value NAPI_VerifySelfPermission(napi_env env, napi_callback_info info) -{ - HILOG_INFO("Context::NAPI_VerifySelfPermission. called."); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = CreateAsyncPermissionCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - return nullptr; - } - - napi_value rev = NAPI_VerifySelfPermissionWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - napi_value result = 0; - napi_get_null(env, &result); - return result; - } - return rev; -} - -/** - * @brief RequestPermissionsFromUser asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void RequestPermissionsFromUserExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("Context::NAPI_VerifySelfPermission worker pool thread execute."); - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo != nullptr) { - AbilityProcess::GetInstance()->RequestPermissionsFromUser( - asyncCallbackInfo->ability, asyncCallbackInfo->param, *asyncCallbackInfo->aceCallback); - asyncCallbackInfo->run_status = true; - asyncCallbackInfo->native_data.data_type = NVT_INT32; - asyncCallbackInfo->native_data.int32_value = 1; - } -} - -void RequestPermissionsFromUserExecutePromise(napi_env env, void *data) -{ - HILOG_INFO("Context::NAPI_VerifySelfPermission worker pool thread execute."); - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo != nullptr) { - AbilityProcess::GetInstance()->RequestPermissionsFromUser( - asyncCallbackInfo->ability, asyncCallbackInfo->param, *asyncCallbackInfo->aceCallback); - asyncCallbackInfo->run_status = true; - asyncCallbackInfo->native_data.data_type = NVT_NONE; - } -} - -/** - * @brief RequestPermissionsFromUser processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param asyncCallbackInfo Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value NAPI_RequestPermissionsFromUserWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo) -{ - size_t argc = 4; - const size_t argCount = 2; - napi_value args[PERMISSION_ARGS_SIZE] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - CallAbilityPermissionParam param; - if (UnwrapParamArrayString(param.permission_list, env, args[0]) == nullptr) { - return nullptr; - } - - if (UnwrapParamInt(¶m.requestCode, env, args[1]) == nullptr) { - return nullptr; - } - - asyncCallbackInfo->param = param; - asyncCallbackInfo->aceCallback = &aceCallbackInfoPermission; - AsyncParamEx asyncParamEx; - asyncParamEx.argc = argc; - if (argc > argCount) { - HILOG_INFO("Context::NAPI_RequestPermissionsFromUser asyncCallback."); - asyncParamEx.resource = "NAPI_RequestPermissionsFromUser_Callback"; - asyncParamEx.startIndex = PERMISSION_EVENT_REQUEST_PERMISSION; - asyncParamEx.execute = RequestPermissionsFromUserExecuteCallback; - asyncParamEx.complete = AsyncCompleteCallback; - return ExecuteAsyncCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("Context::NAPI_RequestPermissionsFromUser promise."); - asyncParamEx.resource = "NAPI_RequestPermissionsFromUser_Promise"; - asyncParamEx.startIndex = 0; - asyncParamEx.execute = RequestPermissionsFromUserExecutePromise; - asyncParamEx.complete = PromiseCompleteCallback; - return ExecutePromiseCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } -} - -/** - * @brief Requests certain permissions from the system. - * This method is called for permission request. This is an asynchronous method. When it is executed, - * the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - */ -napi_value NAPI_RequestPermissionsFromUser(napi_env env, napi_callback_info info) -{ - HILOG_INFO("Context::NAPI_RequestPermissionsFromUser. called."); - AsyncPermissionCallbackInfo *asyncCallbackInfo = CreateAsyncPermissionCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - return nullptr; - } - - napi_value rev = NAPI_RequestPermissionsFromUserWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - napi_value result = 0; - napi_get_null(env, &result); - return result; - } - return rev; -} - -/** - * @brief OnRequestPermissionsFromUserResult processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param asyncCallbackInfo Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value NAPI_OnRequestPermissionsFromUserResultWrap( - napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo) -{ - size_t argc = 2; - napi_value args[PERMISSION_ARGS_SIZE] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - if (argc > 0) { - HILOG_INFO("Context::NAPI_OnRequestPermissionsFromUserResult"); - - napi_value resourceName = 0; - NAPI_CALL(env, - napi_create_string_latin1(env, "NAPI_OnRequestPermissionsFromUserResult", NAPI_AUTO_LENGTH, &resourceName)); - - aceCallbackInfoPermission.env = env; - size_t argcCount = (argc > PERMISSION_EVENT_SIZE) ? PERMISSION_EVENT_SIZE : argc; - for (size_t i = 0; i < argcCount; i++) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[i], &valuetype)); - if (valuetype != napi_function) { - return nullptr; - } - napi_create_reference(env, args[i], 1, &aceCallbackInfoPermission.callback[i]); - } - - NAPI_CALL(env, - napi_create_async_work( - env, - nullptr, - resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Context::NAPI_OnRequestPermissionsFromUserResult worker pool thread execute."); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Conext::NAPI_OnRequestPermissionsFromUserResult main event thread complete."); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - if (asyncCallbackInfo != nullptr) { - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - } - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - } - - // create result code - napi_value result = 0; - NAPI_CALL(env, napi_create_int32(env, 1, &result)); - return result; -} - -/** - * @brief Called back after permissions are requested by using - * AbilityContext.requestPermissionsFromUser(java.lang.String[],int). - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - */ -napi_value NAPI_OnRequestPermissionsFromUserResult(napi_env env, napi_callback_info info) -{ - HILOG_INFO("Context::NAPI_OnRequestPermissionsFromUserResult. called."); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = CreateAsyncPermissionCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - return nullptr; - } - - napi_value rev = NAPI_OnRequestPermissionsFromUserResultWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return rev; -} - -/** - * @brief The interface of onRequestPermissionsFromUserResult provided for ACE to call back to JS. - * - * @param requestCode Indicates the request code returned after the ability is started. - * @param permissions Indicates list of permission. - * @param grantResults Indicates List of authorization results. - * @param callbackInfo The environment and call back info that the Node-API call is invoked under. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector &permissions, - const std::vector &grantResults, CallbackInfo callbackInfo) -{ - HILOG_INFO("Context::CallOnRequestPermissionsFromUserResult called"); - napi_value result = 0; - NAPI_CALL(callbackInfo.env, napi_create_object(callbackInfo.env, &result)); - - // create requestCode - napi_value jsValue = 0; - NAPI_CALL(callbackInfo.env, napi_create_int32(callbackInfo.env, requestCode, &jsValue)); - NAPI_CALL(callbackInfo.env, napi_set_named_property(callbackInfo.env, result, "requestCode", jsValue)); - - // create permissions - napi_value perValue = 0; - napi_value perArray = 0; - NAPI_CALL(callbackInfo.env, napi_create_array(callbackInfo.env, &perArray)); - - for (size_t i = 0; i < permissions.size(); i++) { - NAPI_CALL(callbackInfo.env, - napi_create_string_utf8(callbackInfo.env, permissions[i].c_str(), NAPI_AUTO_LENGTH, &perValue)); - NAPI_CALL(callbackInfo.env, napi_set_element(callbackInfo.env, perArray, i, perValue)); - } - NAPI_CALL(callbackInfo.env, napi_set_named_property(callbackInfo.env, result, "permissions", perArray)); - - // create grantResults - napi_value grantArray; - NAPI_CALL(callbackInfo.env, napi_create_array(callbackInfo.env, &grantArray)); - - for (size_t i = 0; i < grantResults.size(); i++) { - NAPI_CALL(callbackInfo.env, napi_create_int32(callbackInfo.env, grantResults[i], &perValue)); - NAPI_CALL(callbackInfo.env, napi_set_element(callbackInfo.env, grantArray, i, perValue)); - } - NAPI_CALL(callbackInfo.env, napi_set_named_property(callbackInfo.env, result, "grantResults", grantArray)); - - // call CB function - napi_value callback = 0; - napi_value undefined = 0; - NAPI_CALL(callbackInfo.env, napi_get_undefined(callbackInfo.env, &undefined)); - - napi_value callResult = 0; - NAPI_CALL(callbackInfo.env, napi_get_reference_value(callbackInfo.env, callbackInfo.callback[0], &callback)); - NAPI_CALL(callbackInfo.env, napi_call_function(callbackInfo.env, undefined, callback, 1, &result, &callResult)); - - if (callbackInfo.callback[0] != nullptr) { - NAPI_CALL(callbackInfo.env, napi_delete_reference(callbackInfo.env, callbackInfo.callback[0])); - } - if (callbackInfo.callback[1] != nullptr) { - NAPI_CALL(callbackInfo.env, napi_delete_reference(callbackInfo.env, callbackInfo.callback[1])); - } - - // create reutrn - napi_value ret = 0; - NAPI_CALL(callbackInfo.env, napi_create_int32(callbackInfo.env, 1, &ret)); - return ret; -} - -/** - * @brief GetBundleName asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetBundleNameExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("FeatureAbility::NAPI_GetBundleName worker pool thread execute."); - AsyncPermissionCallbackInfo *asyncCallbackInfo = (AsyncPermissionCallbackInfo *)data; - - if (asyncCallbackInfo->ability != nullptr) { - asyncCallbackInfo->native_data.data_type = NVT_STRING; - asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetBundleName(); - HILOG_INFO("FeatureAbility::NAPI_GetBundleName bundleName = %{public}s.", - asyncCallbackInfo->native_data.str_value.c_str()); - asyncCallbackInfo->run_status = true; - } -} - -/** - * @brief GetBundleName processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param asyncCallbackInfo Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value NAPI_GetBundleNameWrap(napi_env env, napi_callback_info info, AsyncPermissionCallbackInfo *asyncCallbackInfo) -{ - size_t argc = 2; - const size_t argCount = 0; - napi_value args[PERMISSION_ARGS_SIZE] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - AsyncParamEx asyncParamEx; - asyncParamEx.argc = argc; - if (argc > argCount) { - HILOG_INFO("Context::NAPI_GetBundleName asyncCallback."); - asyncParamEx.resource = "NAPI_GetBundleName_Callback"; - asyncParamEx.startIndex = 0; - asyncParamEx.execute = GetBundleNameExecuteCallback; - asyncParamEx.complete = AsyncCompleteCallback; - return ExecuteAsyncCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("Context::NAPI_GetBundleName promise."); - asyncParamEx.resource = "NAPI_GetBundleName_Promise"; - asyncParamEx.startIndex = 0; - asyncParamEx.execute = GetBundleNameExecuteCallback; - asyncParamEx.complete = PromiseCompleteCallback; - return ExecutePromiseCallback(env, args, asyncCallbackInfo, &asyncParamEx); - } -} - -/** - * @brief Get bundle name. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("FeatureAbility::NAPI_GetBundleName. called."); - - AsyncPermissionCallbackInfo *asyncCallbackInfo = CreateAsyncPermissionCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - return nullptr; - } - - napi_value rev = NAPI_GetBundleNameWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - napi_value result = 0; - napi_get_null(env, &result); - return result; - } - - return rev; -} -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/context/napi_context.h b/interfaces/kits/napi/aafwk/context/napi_context.h deleted file mode 100644 index d1d58d568e8..00000000000 --- a/interfaces/kits/napi/aafwk/context/napi_context.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - * 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 NAPI_CONTEXT_PERMISSION_H_ -#define NAPI_CONTEXT_PERMISSION_H_ -#include "napi/native_common.h" -#include "napi/native_node_api.h" -#include "ability.h" -#include "feature_ability_common.h" - -#define PERMISSION_C_BUFFER_SIZE 1024 /* Converted to C-style string buffer size */ -#define PERMISSION_ARGS_SIZE 10 -#define PERMISSION_EVENT_SIZE 2 -using Ability = OHOS::AppExecFwk::Ability; - -namespace OHOS { -namespace AppExecFwk { -struct CallAbilityPermissionParam { - std::vector permission_list; - int requestCode = 0; - int syncOption = false; -}; - -typedef enum { - NVT_NONE = 0, - NVT_INT32, - NVT_BOOL, - NVT_STRING, -} TNativeValueType; - -typedef struct __ThreadReturnData { - TNativeValueType data_type; - int32_t int32_value; - bool bool_value; - std::string str_value; -} ThreadReturnData; - -struct AsyncPermissionCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - Ability *ability; - CallAbilityPermissionParam param; - napi_ref callback[2] = {0}; - ThreadReturnData native_data; - napi_value result; - bool run_status; - int error_code; - OHOS::AppExecFwk::CallbackInfo *aceCallback; -}; - -struct AsyncParamEx { - std::string resource; - size_t argc; - size_t startIndex; - napi_async_execute_callback execute; - napi_async_complete_callback complete; -}; - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to AsyncPermissionCallbackInfo on success, nullptr on failure - */ -AsyncPermissionCallbackInfo *CreateAsyncPermissionCallbackInfo(napi_env env); - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * @param argc Number of parameters. - * @param startIndex The position of the first event parameter. - * @param args Parameter list. - * @param callback Point to asynchronous processing of data. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value CreateAsyncCallback( - napi_env env, size_t argc, size_t startIndex, napi_value *args, AsyncPermissionCallbackInfo *callback); - -/** - * @brief Parse JS numeric parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return integer value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamInt(int *value, napi_env env, napi_value args); - -/** - * @brief Parse JS string parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return stirng value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamString(std::vector &value, napi_env env, napi_value args); - -/** - * @brief Parse JS array of string parameters. - * - * @param env The environment that the Node-API call is invoked under. - * @param value Return array of stirng value. - * @param args Parameter list. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value UnwrapParamArrayString(std::vector &value, napi_env env, napi_value args); - -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void AsyncCompleteCallback(napi_env env, napi_status status, void *data); - -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void PromiseCompleteCallback(napi_env env, napi_status status, void *data); - -/** - * @brief Asynchronous callback processing. - * - * @param env The environment that the Node-API call is invoked under. - * @param args list of JS of param. - * @param asyncCallbackInfo Process data asynchronously. - * @param param other param. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value ExecuteAsyncCallback( - napi_env env, napi_value *args, AsyncPermissionCallbackInfo *asyncCallbackInfo, const AsyncParamEx *param); - -/** - * @brief Asynchronous promise processing. - * - * @param env The environment that the Node-API call is invoked under. - * @param args list of JS of param. - * @param asyncCallbackInfo Process data asynchronously. - * @param param other param. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value ExecutePromiseCallback( - napi_env env, napi_value *args, AsyncPermissionCallbackInfo *asyncCallbackInfo, const AsyncParamEx *param); - -/** - * @brief Convert local data to JS data. - * - * @param env The environment that the Node-API call is invoked under. - * @param data The local data. - * @param value the JS data. - * - * @return The return value from NAPI C++ to JS for the module. - */ -void NAPI_GetNapiValue(napi_env env, const ThreadReturnData *data, napi_value *value); - -/** - * @brief Context NAPI module registration. - * - * @param env The environment that the Node-API call is invoked under. - * @param exports An empty object via the exports parameter as a convenience. - * - * @return The return value from Init is treated as the exports object for the module. - */ -napi_value ContextPermissionInit(napi_env env, napi_value exports); - -/** - * @brief The interface of onRequestPermissionsFromUserResult provided for ACE to call back to JS. - * - * @param requestCode Indicates the request code returned after the ability is started. - * @param permissions Indicates list of permission. - * @param grantResults Indicates List of authorization results. - * @param callbackInfo The environment and call back info that the Node-API call is invoked under. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector &permissions, - const std::vector &grantResults, OHOS::AppExecFwk::CallbackInfo callbackInfo); -} // namespace AppExecFwk -} // namespace OHOS -#endif /* ABILITY_PERMISSION_H_ */ diff --git a/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn b/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn index 89e899452f7..e87b658e33b 100755 --- a/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn +++ b/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("featureability") { sources = [ "feature_ability.cpp", + "feature_ability_constant.cpp", "napi_context.cpp", "napi_data_ability_helper.cpp", "native_module.cpp", diff --git a/interfaces/kits/napi/aafwk/featureAbility/feature_ability.cpp b/interfaces/kits/napi/aafwk/featureAbility/feature_ability.cpp index 6ea5d5ba39b..b7cfa8fc0b0 100755 --- a/interfaces/kits/napi/aafwk/featureAbility/feature_ability.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/feature_ability.cpp @@ -58,13 +58,8 @@ napi_value FeatureAbilityInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("hasWindowFocus", NAPI_HasWindowFocus), DECLARE_NAPI_FUNCTION("getContext", NAPI_GetContext), DECLARE_NAPI_FUNCTION("getWant", NAPI_GetWant), - DECLARE_NAPI_FUNCTION("getApplicationInfo", NAPI_GetApplicationInfo), DECLARE_NAPI_FUNCTION("getAppType", NAPI_GetAppType), - DECLARE_NAPI_FUNCTION("getElementName", NAPI_GetElementName), DECLARE_NAPI_FUNCTION("getAbilityName", NAPI_GetAbilityName), - DECLARE_NAPI_FUNCTION("getProcessInfo", NAPI_GetProcessInfo), - DECLARE_NAPI_FUNCTION("getProcessName", NAPI_GetProcessName), - DECLARE_NAPI_FUNCTION("getCallingBundle", NAPI_GetCallingBundle), DECLARE_NAPI_FUNCTION("getAbilityInfo", NAPI_GetAbilityInfo), DECLARE_NAPI_FUNCTION("getHapModuleInfo", NAPI_GetHapModuleInfo), DECLARE_NAPI_FUNCTION("getDataAbilityHelper", NAPI_GetDataAbilityHelper), @@ -355,6 +350,7 @@ napi_value SetResultAsync( if (asyncCallbackInfo->ability != nullptr) { asyncCallbackInfo->ability->SetResult( asyncCallbackInfo->param.requestCode, asyncCallbackInfo->param.want); + asyncCallbackInfo->ability->TerminateAbility(); } else { HILOG_ERROR("NAPI_SetResult, ability == nullptr"); } @@ -413,6 +409,7 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) if (asyncCallbackInfo->ability != nullptr) { asyncCallbackInfo->ability->SetResult( asyncCallbackInfo->param.requestCode, asyncCallbackInfo->param.want); + asyncCallbackInfo->ability->TerminateAbility(); } else { HILOG_ERROR("NAPI_SetResult, ability == nullptr"); } @@ -926,9 +923,6 @@ bool InnerUnwrapWant(napi_env env, napi_value args, Want &want) napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_value args) { HILOG_INFO("%{public}s,called", __func__); - // unwrap the param - napi_valuetype valueType = napi_undefined; - // unwrap the param : want object InnerUnwrapWant(env, args, param.want); @@ -942,12 +936,13 @@ napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_valu param.forResultOption); // unwrap the param : abilityStartSetting (optional) - napi_value abilityStartSettingProp = nullptr; - NAPI_CALL(env, napi_get_named_property(env, args, "abilityStartSetting", &abilityStartSettingProp)); - NAPI_CALL(env, napi_typeof(env, abilityStartSettingProp, &valueType)); - if (valueType == napi_object) { + napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object); + if (jsSettingObj != nullptr) { param.setting = AbilityStartSetting::GetEmptySetting(); - HILOG_INFO("%{public}s, abilityStartSetting=%{public}p.", __func__, param.setting.get()); + if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) { + HILOG_ERROR("%{public}s, unwrap abilityStartSetting falied.", __func__); + } + HILOG_INFO("%{public}s abilityStartSetting = %{public}p.", __func__, param.setting.get()); } napi_value result; @@ -1003,20 +998,6 @@ napi_value NAPI_GetWant(napi_env env, napi_callback_info info) return NAPI_GetWantCommon(env, info, AbilityType::PAGE); } -/** - * @brief Obtains information about the current application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s,called", __func__); - return NAPI_GetApplicationInfoCommon(env, info, AbilityType::PAGE); -} - /** * @brief Obtains the type of this application. * @@ -1031,20 +1012,6 @@ napi_value NAPI_GetAppType(napi_env env, napi_callback_info info) return NAPI_GetAppTypeCommon(env, info, AbilityType::PAGE); } -/** - * @brief Obtains the elementName object of the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetElementName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetElementNameCommon(env, info, AbilityType::PAGE); -} - /** * @brief Obtains the class name in this ability name, without the prefixed bundle name. * @@ -1059,48 +1026,6 @@ napi_value NAPI_GetAbilityName(napi_env env, napi_callback_info info) return NAPI_GetAbilityNameCommon(env, info, AbilityType::PAGE); } -/** - * @brief Obtains the process Info this application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessInfo(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetProcessInfoCommon(env, info, AbilityType::PAGE); -} - -/** - * @brief Obtains the name of the current process. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetProcessNameCommon(env, info, AbilityType::PAGE); -} - -/** - * @brief Obtains the bundle name of the ability that called the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetCallingBundleCommon(env, info, AbilityType::PAGE); -} - /** * @brief Obtains information about the current ability. * @@ -1318,63 +1243,7 @@ void GetDataAbilityHelperPromiseCompleteCB(napi_env env, napi_status status, voi napi_value NAPI_AcquireDataAbilityHelper(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DataAbilityHelperCB *dataAbilityHelperCB = new (std::nothrow) DataAbilityHelperCB; - dataAbilityHelperCB->cbBase.cbInfo.env = env; - if (dataAbilityHelperCB == nullptr) { - HILOG_ERROR("%{public}s, dataAbilityHelperCB == nullptr", __func__); - return WrapVoidToJS(env); - } - napi_value ret = AcquireDataAbilityHelperWrap(env, info, dataAbilityHelperCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s, ret == nullptr", __func__); - if (dataAbilityHelperCB != nullptr) { - delete dataAbilityHelperCB; - dataAbilityHelperCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s,end", __func__); - return ret; -} - -/** - * @brief acquireDataAbilityHelper processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param dataAbilityHelperCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value AcquireDataAbilityHelperWrap(napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB) -{ - HILOG_INFO("%{public}s,called", __func__); - if (dataAbilityHelperCB == nullptr) { - HILOG_ERROR("%{public}s,dataAbilityHelperCB == nullptr", __func__); - return nullptr; - } - - size_t requireArgc = ARGS_ONE; - size_t argc = ARGS_ONE; - napi_value args[ARGS_ONE] = {nullptr}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); - if (argc > requireArgc) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); - if (valuetype != napi_string) { - HILOG_ERROR("%{public}s, Wrong argument type.", __func__); - return nullptr; - } - - napi_value result = nullptr; - NAPI_CALL(env, napi_new_instance(env, g_dataAbilityHelper, 1, &args[PARAM0], &result)); - delete dataAbilityHelperCB; - dataAbilityHelperCB = nullptr; - HILOG_INFO("%{public}s,end", __func__); - return result; + return NAPI_AcquireDataAbilityHelperCommon(env, info, AbilityType::PAGE); } /** diff --git a/interfaces/kits/napi/aafwk/featureAbility/feature_ability.h b/interfaces/kits/napi/aafwk/featureAbility/feature_ability.h index 64839aca40f..c9a99616c48 100755 --- a/interfaces/kits/napi/aafwk/featureAbility/feature_ability.h +++ b/interfaces/kits/napi/aafwk/featureAbility/feature_ability.h @@ -114,16 +114,6 @@ napi_value NAPI_GetContext(napi_env env, napi_callback_info info); */ napi_value NAPI_GetWant(napi_env env, napi_callback_info info); -/** - * @brief Obtains information about the current application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info); - /** * @brief Obtains the type of this application. * @@ -134,16 +124,6 @@ napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info); */ napi_value NAPI_GetAppType(napi_env env, napi_callback_info info); -/** - * @brief Obtains the elementName object of the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetElementName(napi_env env, napi_callback_info info); - /** * @brief Obtains the class name in this ability name, without the prefixed bundle name. * @@ -154,36 +134,6 @@ napi_value NAPI_GetElementName(napi_env env, napi_callback_info info); */ napi_value NAPI_GetAbilityName(napi_env env, napi_callback_info info); -/** - * @brief Obtains the process Info this application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessInfo(napi_env env, napi_callback_info info); - -/** - * @brief Obtains the name of the current process. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info); - -/** - * @brief Obtains the bundle name of the ability that called the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info); - /** * @brief Obtains information about the current ability. * @@ -306,8 +256,7 @@ napi_value StartAbilityForResultPromise(napi_env env, AsyncCallbackInfo *asyncCa * @return Return JS data successfully, otherwise return nullptr. */ napi_value ContinueAbilityWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); -napi_value ContinueAbilityAsync( - napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); +napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); /** @@ -369,17 +318,6 @@ void GetDataAbilityHelperAsyncCompleteCB(napi_env env, napi_status status, void */ void GetDataAbilityHelperPromiseCompleteCB(napi_env env, napi_status status, void *data); -/** - * @brief acquireDataAbilityHelper processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param dataAbilityHelperCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value AcquireDataAbilityHelperWrap( - napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB); - /** * @brief FeatureAbility NAPI method : connectAbility. * diff --git a/interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.cpp b/interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.cpp new file mode 100644 index 00000000000..3da89cf09b7 --- /dev/null +++ b/interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.cpp @@ -0,0 +1,73 @@ +/* + * 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 "feature_ability_constant.h" +#include +#include +#include "securec.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @brief FeatureAbilityConstantInit NAPI module registration. + * + * @param env The environment that the Node-API call is invoked under. + * @param exports An empty object via the exports parameter as a convenience. + * + * @return The return value from Init is treated as the exports object for the module. + */ +napi_value FAConstantInit(napi_env env, napi_value exports) +{ + HILOG_INFO("%{public}s,called", __func__); + napi_value abilityStartSetting = nullptr; + napi_value abilityWindowConfiguration = nullptr; + napi_create_object(env, &abilityStartSetting); + napi_create_object(env, &abilityWindowConfiguration); + + SetNamedProperty(env, abilityStartSetting, "abilityBounds", "BOUNDS_KEY"); + SetNamedProperty(env, abilityStartSetting, "windowMode", "WINDOW_MODE_KEY"); + SetNamedProperty(env, abilityStartSetting, "displayId", "DISPLAY_ID_KEY"); + + SetNamedProperty(env, abilityWindowConfiguration, 0, "WINDOW_MODE_UNDEFINED"); + SetNamedProperty(env, abilityWindowConfiguration, 1, "WINDOW_MODE_FULLSCREEN"); + SetNamedProperty(env, abilityWindowConfiguration, 100, "WINDOW_MODE_SPLIT_PRIMARY"); + SetNamedProperty(env, abilityWindowConfiguration, 101, "WINDOW_MODE_SPLIT_SECONDARY"); + SetNamedProperty(env, abilityWindowConfiguration, 102, "WINDOW_MODE_FLOATING"); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_PROPERTY("AbilityStartSetting", abilityStartSetting), + DECLARE_NAPI_PROPERTY("AbilityWindowConfiguration", abilityWindowConfiguration), + }; + napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); + + return exports; +} + +void SetNamedProperty(napi_env env, napi_value dstObj, const char *objName, const char *propName) +{ + napi_value prop = nullptr; + napi_create_string_utf8(env, objName, NAPI_AUTO_LENGTH, &prop); + napi_set_named_property(env, dstObj, propName, prop); +} + +void SetNamedProperty(napi_env env, napi_value dstObj, const int32_t objValue, const char *propName) +{ + napi_value prop = nullptr; + napi_create_int32(env, objValue, &prop); + napi_set_named_property(env, dstObj, propName, prop); +} + +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/context/native_module.cpp b/interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.h similarity index 49% rename from interfaces/kits/napi/aafwk/context/native_module.cpp rename to interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.h index a1a5191a093..a2eb59c82b3 100644 --- a/interfaces/kits/napi/aafwk/context/native_module.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/feature_ability_constant.h @@ -13,44 +13,24 @@ * limitations under the License. */ -#include -#include -#include -#include - -#include "napi_context.h" -#include "napi/native_api.h" +#ifndef OHOS_APPEXECFWK_FEATURE_ABILITY_CONSTANT_H +#define OHOS_APPEXECFWK_FEATURE_ABILITY_CONSTANT_H +#include "napi/native_common.h" #include "napi/native_node_api.h" namespace OHOS { namespace AppExecFwk { -EXTERN_C_START -/* - * Module initialization - */ -static napi_value Init(napi_env env, napi_value exports) -{ - ContextPermissionInit(env, exports); - return exports; -} -EXTERN_C_END - -/* - * Module definition - */ -static napi_module _module = {.nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "context", - .nm_priv = ((void *)0), - .reserved = {0}}; -/* - * Module registration function +/** + * @brief FeatureAbilityConstantInit NAPI module registration. + * + * @param env The environment that the Node-API call is invoked under. + * @param exports An empty object via the exports parameter as a convenience. + * + * @return The return value from Init is treated as the exports object for the module. */ -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - napi_module_register(&_module); -} +napi_value FAConstantInit(napi_env env, napi_value exports); +void SetNamedProperty(napi_env env, napi_value dstObj, const char *objName, const char *propName); +void SetNamedProperty(napi_env env, napi_value dstObj, const int32_t objValue, const char *propName); } // namespace AppExecFwk } // namespace OHOS +#endif /* OHOS_APPEXECFWK_FEATURE_ABILITY_CONSTANT_H */ diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp index 6fc1906790e..abca947bb66 100755 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp @@ -20,6 +20,8 @@ #include "ability_process.h" #include "feature_ability_common.h" #include "../inner/napi_common/napi_common_ability.h" +#include "file_ex.h" +#include "directory_ex.h" using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; @@ -445,20 +447,6 @@ void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vectorcbBase.errCode = NAPI_ERR_NO_ERROR; + + if (appInfoCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo, ability == nullptr"); + appInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + std::shared_ptr appInfoPtr = appInfoCB->cbBase.ability->GetApplicationInfo(); + if (appInfoPtr != nullptr) { + SaveAppInfo(appInfoCB->appInfo, *appInfoPtr); + } else { + HILOG_ERROR("NAPI_GetApplicationInfo, appInfoPtr == nullptr"); + appInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; + } + HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetAppInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); + AppInfoCB *appInfoCB = (AppInfoCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, appInfoCB->cbBase.errCode); + if (appInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapAppInfo(env, appInfoCB->appInfo); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, appInfoCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (appInfoCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, appInfoCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, appInfoCB->cbBase.asyncWork)); + delete appInfoCB; + appInfoCB = nullptr; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); +} + +/** + * @brief GetApplicationInfo Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param appInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetApplicationInfoAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AppInfoCB *appInfoCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || appInfoCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &appInfoCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetAppInfoExecuteCB, + GetAppInfoAsyncCompleteCB, + (void *)appInfoCB, + &appInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, appInfoCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return result; +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetAppInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); + AppInfoCB *appInfoCB = (AppInfoCB *)data; + if (appInfoCB == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo, appInfoCB == nullptr"); + return; + } + + napi_value result = nullptr; + if (appInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapAppInfo(env, appInfoCB->appInfo); + napi_resolve_deferred(env, appInfoCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, appInfoCB->cbBase.errCode); + napi_reject_deferred(env, appInfoCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, appInfoCB->cbBase.asyncWork); + delete appInfoCB; + appInfoCB = nullptr; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); +} + +/** + * @brief GetApplicationInfo Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param appInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetApplicationInfoPromise(napi_env env, AppInfoCB *appInfoCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (appInfoCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + appInfoCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetAppInfoExecuteCB, + GetAppInfoPromiseCompleteCB, + (void *)appInfoCB, + &appInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, appInfoCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetApplicationInfo processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param appInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetApplicationInfoWrap(napi_env env, napi_callback_info info, AppInfoCB *appInfoCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (appInfoCB == nullptr) { + HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetApplicationInfoAsync(env, args, argcAsync, argcPromise, appInfoCB); + } else { + ret = GetApplicationInfoPromise(env, appInfoCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to AppInfoCB on success, nullptr on failure. + */ +AppInfoCB *CreateAppInfoCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s, called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + AppInfoCB *appInfoCB = new (std::nothrow) AppInfoCB; + if (appInfoCB == nullptr) { + HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); + return nullptr; + } + appInfoCB->cbBase.cbInfo.env = env; + appInfoCB->cbBase.asyncWork = nullptr; + appInfoCB->cbBase.deferred = nullptr; + appInfoCB->cbBase.ability = ability; + appInfoCB->cbBase.abilityType = AbilityType::UNKNOWN; + appInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + + HILOG_INFO("%{public}s, end.", __func__); + return appInfoCB; +} + +/** + * @brief GetBundleName asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetBundleNameExecuteCallback(napi_env env, void *data) +{ + HILOG_INFO("%{public}s called", __func__); + AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data; + if (asyncCallbackInfo == nullptr) { + HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__); + return; + } + + asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR; + asyncCallbackInfo->native_data.data_type = NVT_NONE; + if (asyncCallbackInfo->ability == nullptr) { + HILOG_ERROR("%{public}s ability == nullptr", __func__); + asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY; + return; + } + + asyncCallbackInfo->native_data.data_type = NVT_STRING; + asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetBundleName(); + HILOG_INFO("%{public}s end. bundleName=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str()); +} + +/** + * @brief GetBundleName processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param asyncCallbackInfo Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value NAPI_GetBundleNameWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo) +{ + HILOG_INFO("%{public}s called", __func__); + size_t argc = ARGS_MAX_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value jsthis = 0; + void *data = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); + + if (argc > ARGS_ONE) { + HILOG_INFO("%{public}s called, parameters is invalid.", __func__); + return nullptr; + } + + if (argc == ARGS_ONE) { + if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) { + HILOG_INFO("%{public}s called, the first parameter is invalid.", __func__); + return nullptr; + } + } + + AsyncParamEx asyncParamEx; + if (asyncCallbackInfo->cbInfo.callback != nullptr) { + HILOG_INFO("%{public}s called. asyncCallback.", __func__); + asyncParamEx.resource = "NAPI_GetBundleNameCallback"; + asyncParamEx.execute = GetBundleNameExecuteCallback; + asyncParamEx.complete = CompleteAsyncCallbackWork; + + return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); + } else { + HILOG_INFO("%{public}s called. promise.", __func__); + asyncParamEx.resource = "NAPI_GetBundleNamePromise"; + asyncParamEx.execute = GetBundleNameExecuteCallback; + asyncParamEx.complete = CompletePromiseCallbackWork; + + return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); + } +} + +napi_value WrapProcessInfo(napi_env env, ProcessInfoCB *processInfoCB) +{ + HILOG_INFO("%{public}s called", __func__); + if (processInfoCB == nullptr) { + HILOG_ERROR("%{public}s Invalid param(processInfoCB == nullptr)", __func__); + return nullptr; + } + napi_value result = nullptr; + napi_value proValue = nullptr; + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, napi_create_int32(env, processInfoCB->pid, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "pid", proValue)); + + NAPI_CALL(env, napi_create_string_utf8(env, processInfoCB->processName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "processName", proValue)); + HILOG_INFO("%{public}s end", __func__); + return result; +} + +/** + * @brief GetProcessInfo asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessInfoExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetProcessInfo, worker pool thread execute."); + ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; + if (processInfoCB == nullptr) { + return; + } + + processInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (processInfoCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetProcessInfo, ability == nullptr"); + processInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + std::shared_ptr processInfoPtr = processInfoCB->cbBase.ability->GetProcessInfo(); + if (processInfoPtr != nullptr) { + processInfoCB->processName = processInfoPtr->GetProcessName(); + processInfoCB->pid = processInfoPtr->GetPid(); + } else { + HILOG_ERROR("NAPI_GetProcessInfo, processInfoPtr == nullptr"); + processInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; + } + HILOG_INFO("NAPI_GetProcessInfo, worker pool thread execute end."); +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetProcessInfo, main event thread complete."); + ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, processInfoCB->cbBase.errCode); + if (processInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapProcessInfo(env, processInfoCB); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, processInfoCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (processInfoCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, processInfoCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, processInfoCB->cbBase.asyncWork)); + delete processInfoCB; + processInfoCB = nullptr; + HILOG_INFO("NAPI_GetProcessInfo, main event thread complete end."); +} + +/** + * @brief GetProcessInfo Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param ProcessInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessInfoAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ProcessInfoCB *processInfoCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || processInfoCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &processInfoCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetProcessInfoExecuteCB, + GetProcessInfoAsyncCompleteCB, + (void *)processInfoCB, + &processInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, processInfoCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return result; +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetProcessInfo, main event thread complete."); + ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; + napi_value result = nullptr; + if (processInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapProcessInfo(env, processInfoCB); + napi_resolve_deferred(env, processInfoCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, processInfoCB->cbBase.errCode); + napi_reject_deferred(env, processInfoCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, processInfoCB->cbBase.asyncWork); + delete processInfoCB; + processInfoCB = nullptr; + HILOG_INFO("NAPI_GetProcessInfo, main event thread complete end."); +} + +/** + * @brief GetProcessInfo Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param ProcessInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessInfoPromise(napi_env env, ProcessInfoCB *processInfoCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (processInfoCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + processInfoCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetProcessInfoExecuteCB, + GetProcessInfoPromiseCompleteCB, + (void *)processInfoCB, + &processInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, processInfoCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetProcessInfo processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param ProcessInfoCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessInfoWrap(napi_env env, napi_callback_info info, ProcessInfoCB *processInfoCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (processInfoCB == nullptr) { + HILOG_ERROR("%{public}s, processInfoCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetProcessInfoAsync(env, args, argcAsync, argcPromise, processInfoCB); + } else { + ret = GetProcessInfoPromise(env, processInfoCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to ProcessInfoCB on success, nullptr on failure. + */ +ProcessInfoCB *CreateProcessInfoCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s, called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + ProcessInfoCB *processInfoCB = new (std::nothrow) ProcessInfoCB; + if (processInfoCB == nullptr) { + HILOG_ERROR("%{public}s, processInfoCB == nullptr.", __func__); + return nullptr; + } + processInfoCB->cbBase.cbInfo.env = env; + processInfoCB->cbBase.asyncWork = nullptr; + processInfoCB->cbBase.deferred = nullptr; + processInfoCB->cbBase.ability = ability; + + HILOG_INFO("%{public}s, end.", __func__); + return processInfoCB; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to ElementNameCB on success, nullptr on failure. + */ +ElementNameCB *CreateElementNameCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s, called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + ElementNameCB *elementNameCB = new (std::nothrow) ElementNameCB; + if (elementNameCB == nullptr) { + HILOG_ERROR("%{public}s, elementNameCB == nullptr.", __func__); + return nullptr; + } + elementNameCB->cbBase.cbInfo.env = env; + elementNameCB->cbBase.asyncWork = nullptr; + elementNameCB->cbBase.deferred = nullptr; + elementNameCB->cbBase.ability = ability; + + HILOG_INFO("%{public}s, end.", __func__); + return elementNameCB; +} + +napi_value WrapElementName(napi_env env, ElementNameCB *elementNameCB) +{ + HILOG_INFO("%{public}s, called.", __func__); + if (elementNameCB == nullptr) { + HILOG_ERROR("%{public}s,Invalid param(appInfoCB = nullptr)", __func__); + return nullptr; + } + napi_value result = nullptr; + napi_value proValue = nullptr; + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->abilityName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "abilityName", proValue)); + + NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->bundleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "bundleName", proValue)); + + NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->deviceId.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "deviceId", proValue)); + + NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->shortName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "shortName", proValue)); + + NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->uri.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "uri", proValue)); + HILOG_INFO("%{public}s, end.", __func__); + return result; +} + +/** + * @brief GetElementName asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetElementNameExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetElementName, worker pool thread execute."); + if (data == nullptr) { + HILOG_ERROR("%{public}s, data == nullptr.", __func__); + return; + } + ElementNameCB *elementNameCB = (ElementNameCB *)data; + if (elementNameCB == nullptr) { + HILOG_ERROR("NAPI_GetElementName, elementNameCB == nullptr"); + return; + } + + elementNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (elementNameCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetElementName, ability == nullptr"); + elementNameCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + std::shared_ptr elementName = elementNameCB->cbBase.ability->GetElementName(); + if (elementNameCB != nullptr) { + elementNameCB->deviceId = elementName->GetDeviceID(); + elementNameCB->bundleName = elementName->GetBundleName(); + elementNameCB->abilityName = elementName->GetAbilityName(); + elementNameCB->uri = elementNameCB->cbBase.ability->GetWant()->GetUriString(); + elementNameCB->shortName = ""; + } else { + elementNameCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; + } + HILOG_INFO("NAPI_GetElementName, worker pool thread execute end."); +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetElementNameAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetElementName, main event thread complete."); + ElementNameCB *elementNameCB = (ElementNameCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, elementNameCB->cbBase.errCode); + if (elementNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapElementName(env, elementNameCB); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, elementNameCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (elementNameCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, elementNameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, elementNameCB->cbBase.asyncWork)); + delete elementNameCB; + elementNameCB = nullptr; + HILOG_INFO("NAPI_GetElementName, main event thread complete end."); +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetElementNamePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetElementName, main event thread complete."); + ElementNameCB *elementNameCB = (ElementNameCB *)data; + napi_value result = nullptr; + if (elementNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapElementName(env, elementNameCB); + napi_resolve_deferred(env, elementNameCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, elementNameCB->cbBase.errCode); + napi_reject_deferred(env, elementNameCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, elementNameCB->cbBase.asyncWork); + delete elementNameCB; + elementNameCB = nullptr; + HILOG_INFO("NAPI_GetElementName, main event thread complete end."); +} + +/** + * @brief GetElementName Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param elementNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetElementNamePromise(napi_env env, ElementNameCB *elementNameCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (elementNameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + elementNameCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetElementNameExecuteCB, + GetElementNamePromiseCompleteCB, + (void *)elementNameCB, + &elementNameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, elementNameCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetElementName Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param elementNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetElementNameAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ElementNameCB *elementNameCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || elementNameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &elementNameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetElementNameExecuteCB, + GetElementNameAsyncCompleteCB, + (void *)elementNameCB, + &elementNameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, elementNameCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + return result; + HILOG_INFO("%{public}s, asyncCallback end.", __func__); +} + +/** + * @brief GetElementName processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param elementNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetElementNameWrap(napi_env env, napi_callback_info info, ElementNameCB *elementNameCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (elementNameCB == nullptr) { + HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetElementNameAsync(env, args, argcAsync, argcPromise, elementNameCB); + } else { + ret = GetElementNamePromise(env, elementNameCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to ProcessNameCB on success, nullptr on failure. + */ +ProcessNameCB *CreateProcessNameCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + ProcessNameCB *processNameCB = new (std::nothrow) ProcessNameCB; + if (processNameCB == nullptr) { + HILOG_ERROR("%{public}s, processNameCB == nullptr.", __func__); + return nullptr; + } + processNameCB->cbBase.cbInfo.env = env; + processNameCB->cbBase.asyncWork = nullptr; + processNameCB->cbBase.deferred = nullptr; + processNameCB->cbBase.ability = ability; + + HILOG_INFO("%{public}s end.", __func__); + return processNameCB; +} + +/** + * @brief GetProcessName asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessNameExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetProcessName, worker pool thread execute."); + ProcessNameCB *processNameCB = (ProcessNameCB *)data; + if (processNameCB == nullptr) { + HILOG_ERROR("NAPI_GetProcessName, processNameCB == nullptr"); + return; + } + + processNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (processNameCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetProcessName, ability == nullptr"); + processNameCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + processNameCB->processName = processNameCB->cbBase.ability->GetProcessName(); + HILOG_INFO("NAPI_GetProcessName, worker pool thread execute end."); +} + +napi_value WrapProcessName(napi_env env, ProcessNameCB *processNameCB) +{ + HILOG_INFO("%{public}s, called.", __func__); + if (processNameCB == nullptr) { + HILOG_ERROR("%{public}s, Invalid param(processNameCB == nullptr)", __func__); + return nullptr; + } + napi_value result = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, processNameCB->processName.c_str(), NAPI_AUTO_LENGTH, &result)); + HILOG_INFO("%{public}s, end.", __func__); + return result; +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessNameAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetProcessName, main event thread complete."); + ProcessNameCB *processNameCB = (ProcessNameCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, processNameCB->cbBase.errCode); + if (processNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapProcessName(env, processNameCB); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, processNameCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (processNameCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, processNameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, processNameCB->cbBase.asyncWork)); + delete processNameCB; + processNameCB = nullptr; + HILOG_INFO("NAPI_GetProcessName, main event thread complete end."); +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetProcessNamePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetProcessName, main event thread complete."); + ProcessNameCB *processNameCB = (ProcessNameCB *)data; + napi_value result = nullptr; + if (processNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapProcessName(env, processNameCB); + napi_resolve_deferred(env, processNameCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, processNameCB->cbBase.errCode); + napi_reject_deferred(env, processNameCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, processNameCB->cbBase.asyncWork); + delete processNameCB; + processNameCB = nullptr; + HILOG_INFO("NAPI_GetProcessName, main event thread complete end."); +} + +/** + * @brief GetProcessName Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param ProcessNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessNameAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ProcessNameCB *processNameCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || processNameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &processNameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetProcessNameExecuteCB, + GetProcessNameAsyncCompleteCB, + (void *)processNameCB, + &processNameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, processNameCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return result; +} + +/** + * @brief GetProcessName Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param ProcessNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessNamePromise(napi_env env, ProcessNameCB *processNameCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (processNameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + processNameCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetProcessNameExecuteCB, + GetProcessNamePromiseCompleteCB, + (void *)processNameCB, + &processNameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, processNameCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetProcessName processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param ProcessNameCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetProcessNameWrap(napi_env env, napi_callback_info info, ProcessNameCB *processNameCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (processNameCB == nullptr) { + HILOG_ERROR("%{public}s, processNameCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetProcessNameAsync(env, args, argcAsync, argcPromise, processNameCB); + } else { + ret = GetProcessNamePromise(env, processNameCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to CallingBundleCB on success, nullptr on failure. + */ +CallingBundleCB *CreateCallingBundleCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + CallingBundleCB *callingBundleCB = new (std::nothrow) CallingBundleCB; + if (callingBundleCB == nullptr) { + HILOG_ERROR("%{public}s, callingBundleCB == nullptr.", __func__); + return nullptr; + } + callingBundleCB->cbBase.cbInfo.env = env; + callingBundleCB->cbBase.asyncWork = nullptr; + callingBundleCB->cbBase.deferred = nullptr; + callingBundleCB->cbBase.ability = ability; + + HILOG_INFO("%{public}s end.", __func__); + return callingBundleCB; +} + +/** + * @brief GetCallingBundle asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetCallingBundleExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetCallingBundle, worker pool thread execute."); + CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; + if (callingBundleCB == nullptr) { + HILOG_ERROR("NAPI_GetCallingBundle, callingBundleCB == nullptr"); + return; + } + + callingBundleCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (callingBundleCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetCallingBundle, ability == nullptr"); + callingBundleCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + callingBundleCB->callingBundleName = callingBundleCB->cbBase.ability->GetCallingBundle(); + HILOG_INFO("NAPI_GetCallingBundle, worker pool thread execute end."); +} + +napi_value WrapCallingBundle(napi_env env, CallingBundleCB *callingBundleCB) +{ + HILOG_INFO("%{public}s, called.", __func__); + if (callingBundleCB == nullptr) { + HILOG_ERROR("%{public}s,Invalid param(callingBundleCB == nullptr)", __func__); + return nullptr; + } + napi_value result = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, callingBundleCB->callingBundleName.c_str(), NAPI_AUTO_LENGTH, &result)); + HILOG_INFO("%{public}s, end.", __func__); + return result; +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetCallingBundleAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetCallingBundle, main event thread complete."); + CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, callingBundleCB->cbBase.errCode); + if (callingBundleCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapCallingBundle(env, callingBundleCB); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, callingBundleCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (callingBundleCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, callingBundleCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, callingBundleCB->cbBase.asyncWork)); + delete callingBundleCB; + callingBundleCB = nullptr; + HILOG_INFO("NAPI_GetCallingBundle, main event thread complete end."); +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetCallingBundlePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetCallingBundle, main event thread complete."); + CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; + napi_value result = nullptr; + if (callingBundleCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapCallingBundle(env, callingBundleCB); + napi_resolve_deferred(env, callingBundleCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, callingBundleCB->cbBase.errCode); + napi_reject_deferred(env, callingBundleCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, callingBundleCB->cbBase.asyncWork); + delete callingBundleCB; + callingBundleCB = nullptr; + HILOG_INFO("NAPI_GetCallingBundle, main event thread complete end."); +} + +/** + * @brief GetCallingBundle Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetCallingBundleAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, CallingBundleCB *callingBundleCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || callingBundleCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &callingBundleCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetCallingBundleExecuteCB, + GetCallingBundleAsyncCompleteCB, + (void *)callingBundleCB, + &callingBundleCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, callingBundleCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return result; +} + +/** + * @brief GetCallingBundle Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetCallingBundlePromise(napi_env env, CallingBundleCB *callingBundleCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (callingBundleCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + callingBundleCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetCallingBundleExecuteCB, + GetCallingBundlePromiseCompleteCB, + (void *)callingBundleCB, + &callingBundleCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, callingBundleCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetCallingBundle processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetCallingBundleWrap(napi_env env, napi_callback_info info, CallingBundleCB *callingBundleCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (callingBundleCB == nullptr) { + HILOG_ERROR("%{public}s, callingBundleCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetCallingBundleAsync(env, args, argcAsync, argcPromise, callingBundleCB); + } else { + ret = GetCallingBundlePromise(env, callingBundleCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to CallingBundleCB on success, nullptr on failure. + */ +GetOrCreateLocalDirCB *CreateGetOrCreateLocalDirCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + GetOrCreateLocalDirCB *getOrCreateLocalDirCB = new (std::nothrow) GetOrCreateLocalDirCB; + if (getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("%{public}s, getOrCreateLocalDirCB == nullptr.", __func__); + return nullptr; + } + getOrCreateLocalDirCB->cbBase.cbInfo.env = env; + getOrCreateLocalDirCB->cbBase.asyncWork = nullptr; + getOrCreateLocalDirCB->cbBase.deferred = nullptr; + getOrCreateLocalDirCB->cbBase.ability = ability; + + HILOG_INFO("%{public}s end.", __func__); + return getOrCreateLocalDirCB; +} + +/** + * @brief GetOrCreateLocalDir asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetOrCreateLocalDirExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetOrCreateLocalDir, worker pool thread execute."); + GetOrCreateLocalDirCB *getOrCreateLocalDirCB = (GetOrCreateLocalDirCB *)data; + if (getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("NAPI_GetOrCreateLocalDir, callingBundleCB == nullptr"); + return; + } + + getOrCreateLocalDirCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (getOrCreateLocalDirCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetOrCreateLocalDir, ability == nullptr"); + getOrCreateLocalDirCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + string abilityName = getOrCreateLocalDirCB->cbBase.ability->GetAbilityInfo()->name; + HILOG_INFO("NAPI_GetOrCreateLocalDir, abilityName:%{public}s.", abilityName.c_str()); + // getOrCreateLocalDirCB->rootDir = // TODO + CONTEXT_DEAL_FILE_SEPARATOR + abilityName; + HILOG_INFO("NAPI_GetOrCreateLocalDir, GetDir rootDir:%{public}s.", getOrCreateLocalDirCB->rootDir.c_str()); + if (!OHOS::FileExists(getOrCreateLocalDirCB->rootDir)) { + HILOG_INFO("NAPI_GetOrCreateLocalDir dir is not exits, create dir."); + OHOS::ForceCreateDirectory(getOrCreateLocalDirCB->rootDir); + OHOS::ChangeModeDirectory(getOrCreateLocalDirCB->rootDir, MODE); + } + HILOG_INFO("NAPI_GetOrCreateLocalDir, worker pool thread execute end."); +} + +napi_value WrapGetOrCreateLocalDir(napi_env env, GetOrCreateLocalDirCB *getOrCreateLocalDirCB) +{ + HILOG_INFO("%{public}s, called.", __func__); + if (getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("%{public}s,Invalid param(getOrCreateLocalDirCB == nullptr)", __func__); + return nullptr; + } + napi_value result = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, getOrCreateLocalDirCB->rootDir.c_str(), NAPI_AUTO_LENGTH, &result)); + HILOG_INFO("%{public}s, end.", __func__); + return result; +} + +/** + * @brief The callback at the end of the asynchronous callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetOrCreateLocalDirAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetOrCreateLocalDir, main event thread complete."); + GetOrCreateLocalDirCB *getOrCreateLocalDirCB = (GetOrCreateLocalDirCB *)data; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + result[PARAM0] = GetCallbackErrorValue(env, getOrCreateLocalDirCB->cbBase.errCode); + if (getOrCreateLocalDirCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapGetOrCreateLocalDir(env, getOrCreateLocalDirCB); + } else { + result[PARAM1] = WrapUndefinedToJS(env); + } + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, getOrCreateLocalDirCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (getOrCreateLocalDirCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, getOrCreateLocalDirCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, getOrCreateLocalDirCB->cbBase.asyncWork)); + delete getOrCreateLocalDirCB; + getOrCreateLocalDirCB = nullptr; + HILOG_INFO("NAPI_GetOrCreateLocalDir, main event thread complete end."); +} + +/** + * @brief The callback at the end of the Promise callback. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetOrCreateLocalDirPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("NAPI_GetOrCreateLocalDir, main event thread complete."); + GetOrCreateLocalDirCB *getOrCreateLocalDirCB = (GetOrCreateLocalDirCB *)data; + napi_value result = nullptr; + if (getOrCreateLocalDirCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapGetOrCreateLocalDir(env, getOrCreateLocalDirCB); + napi_resolve_deferred(env, getOrCreateLocalDirCB->cbBase.deferred, result); + } else { + result = GetCallbackErrorValue(env, getOrCreateLocalDirCB->cbBase.errCode); + napi_reject_deferred(env, getOrCreateLocalDirCB->cbBase.deferred, result); + } + + napi_delete_async_work(env, getOrCreateLocalDirCB->cbBase.asyncWork); + delete getOrCreateLocalDirCB; + getOrCreateLocalDirCB = nullptr; + HILOG_INFO("NAPI_GetOrCreateLocalDir, main event thread complete end."); +} + +/** + * @brief GetOrCreateLocalDir Async. + * + * @param env The environment that the Node-API call is invoked under. + * @param args Indicates the arguments passed into the callback. + * @param argcPromise Asynchronous data processing. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetOrCreateLocalDirAsync(napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, + GetOrCreateLocalDirCB *getOrCreateLocalDirCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (args == nullptr || getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL( + env, napi_create_reference(env, args[argcPromise], 1, &getOrCreateLocalDirCB->cbBase.cbInfo.callback)); + } + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetOrCreateLocalDirExecuteCB, + GetOrCreateLocalDirAsyncCompleteCB, + (void *)getOrCreateLocalDirCB, + &getOrCreateLocalDirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, getOrCreateLocalDirCB->cbBase.asyncWork)); + napi_value result = nullptr; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return result; +} + +/** + * @brief GetOrCreateLocalDir Promise. + * + * @param env The environment that the Node-API call is invoked under. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetOrCreateLocalDirPromise(napi_env env, GetOrCreateLocalDirCB *getOrCreateLocalDirCB) +{ + HILOG_INFO("%{public}s, promise.", __func__); + if (getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = nullptr; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = nullptr; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + getOrCreateLocalDirCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetOrCreateLocalDirExecuteCB, + GetOrCreateLocalDirPromiseCompleteCB, + (void *)getOrCreateLocalDirCB, + &getOrCreateLocalDirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, getOrCreateLocalDirCB->cbBase.asyncWork)); + HILOG_INFO("%{public}s, promise end.", __func__); + return promise; +} + +/** + * @brief GetOrCreateLocalDir processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param CallingBundleCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value GetOrCreateLocalDirWrap(napi_env env, napi_callback_info info, GetOrCreateLocalDirCB *getOrCreateLocalDirCB) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + if (getOrCreateLocalDirCB == nullptr) { + HILOG_ERROR("%{public}s, getOrCreateLocalDirCB == nullptr.", __func__); + return nullptr; + } + + size_t argcAsync = 1; + const size_t argcPromise = 0; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + if (argcAsync > argcPromise) { + ret = GetOrCreateLocalDirAsync(env, args, argcAsync, argcPromise, getOrCreateLocalDirCB); + } else { + ret = GetOrCreateLocalDirPromise(env, getOrCreateLocalDirCB); + } + HILOG_INFO("%{public}s, asyncCallback end.", __func__); + return ret; +} + +/** + * @brief Get bundle name. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called", __func__); + AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env); + if (asyncCallbackInfo == nullptr) { + HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__); + return WrapVoidToJS(env); + } + + napi_value ret = NAPI_GetBundleNameWrap(env, info, asyncCallbackInfo); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr", __func__); + FreeAsyncJSCallbackInfo(&asyncCallbackInfo); + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end", __func__); + return ret; +} + +/** + * @brief Obtains information about the current application. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s,called", __func__); + AppInfoCB *appInfoCB = CreateAppInfoCBInfo(env); + if (appInfoCB == nullptr) { + return WrapVoidToJS(env); + } + + napi_value ret = GetApplicationInfoWrap(env, info, appInfoCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s,ret == nullptr", __func__); + if (appInfoCB != nullptr) { + delete appInfoCB; + appInfoCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s,end", __func__); + return ret; +} + +/** + * @brief Obtains the process Info this application. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetProcessInfo(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + ProcessInfoCB *processInfoCB = CreateProcessInfoCBInfo(env); + if (processInfoCB == nullptr) { + return WrapVoidToJS(env); + } + + processInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + napi_value ret = GetProcessInfoWrap(env, info, processInfoCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s, ret == nullptr.", __func__); + if (processInfoCB != nullptr) { + delete processInfoCB; + processInfoCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s, end.", __func__); + return ret; +} + +/** + * @brief Obtains the elementName object of the current ability. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetElementName(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + ElementNameCB *elementNameCB = CreateElementNameCBInfo(env); + if (elementNameCB == nullptr) { + return WrapVoidToJS(env); + } + + elementNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + napi_value ret = GetElementNameWrap(env, info, elementNameCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr.", __func__); + if (elementNameCB != nullptr) { + delete elementNameCB; + elementNameCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end.", __func__); + return ret; +} + +/** + * @brief Obtains the name of the current process. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + ProcessNameCB *processNameCB = CreateProcessNameCBInfo(env); + if (processNameCB == nullptr) { + return WrapVoidToJS(env); + } + + processNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + napi_value ret = GetProcessNameWrap(env, info, processNameCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr.", __func__); + if (processNameCB != nullptr) { + delete processNameCB; + processNameCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end.", __func__); + return ret; +} + +/** + * @brief Obtains the bundle name of the ability that called the current ability. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + CallingBundleCB *callingBundleCB = CreateCallingBundleCBInfo(env); + if (callingBundleCB == nullptr) { + return WrapVoidToJS(env); + } + + callingBundleCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + napi_value ret = GetCallingBundleWrap(env, info, callingBundleCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr", __func__); + if (callingBundleCB != nullptr) { + delete callingBundleCB; + callingBundleCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end.", __func__); + return ret; +} + +/** + * @brief Get the local root dir of an app. If it is the first call, the dir will be created. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetOrCreateLocalDir(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + GetOrCreateLocalDirCB *getOrCreateLocalDirCB = CreateGetOrCreateLocalDirCBInfo(env); + if (getOrCreateLocalDirCB == nullptr) { + return WrapVoidToJS(env); + } + + getOrCreateLocalDirCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + napi_value ret = GetOrCreateLocalDirWrap(env, info, getOrCreateLocalDirCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr", __func__); + if (getOrCreateLocalDirCB != nullptr) { + delete getOrCreateLocalDirCB; + getOrCreateLocalDirCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end.", __func__); + return ret; +} /** * @brief Context NAPI module registration. * @@ -853,6 +2626,12 @@ napi_value ContextPermissionInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("verifyPermission", NAPI_VerifyPermission), DECLARE_NAPI_FUNCTION("verifyCallingPermission", NAPI_VerifyCallingPermission), DECLARE_NAPI_FUNCTION("verifyCallingOrSelfPermission", NAPI_VerifyCallingOrSelfPermission), + DECLARE_NAPI_FUNCTION("getApplicationInfo", NAPI_GetApplicationInfo), + DECLARE_NAPI_FUNCTION("getProcessInfo", NAPI_GetProcessInfo), + DECLARE_NAPI_FUNCTION("getElementName", NAPI_GetElementName), + DECLARE_NAPI_FUNCTION("getProcessName", NAPI_GetProcessName), + DECLARE_NAPI_FUNCTION("getCallingBundle", NAPI_GetCallingBundle), + DECLARE_NAPI_FUNCTION("getOrCreateLocalDir", NAPI_GetOrCreateLocalDir), }; NAPI_CALL(env, diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_context.h b/interfaces/kits/napi/aafwk/featureAbility/napi_context.h index f6a1eb27373..aa26368a7c1 100755 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_context.h +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_context.h @@ -21,7 +21,7 @@ #include "../inner/napi_common/napi_common.h" using Ability = OHOS::AppExecFwk::Ability; - +#define MODE 0771 namespace OHOS { namespace AppExecFwk { @@ -62,6 +62,55 @@ void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vectorcbBase.cbInfo.env = env; + insertCB->cbBase.asyncWork = nullptr; + insertCB->cbBase.deferred = nullptr; + insertCB->cbBase.ability = nullptr; napi_value ret = InsertWrap(env, info, insertCB); if (ret == nullptr) { @@ -366,12 +365,15 @@ napi_value UnwrapValuesBucket(std::string &value, napi_env env, napi_value args) napi_value NAPI_GetType(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperGetTypeCB *gettypeCB = new (std::nothrow) DAHelperGetTypeCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperGetTypeCB *gettypeCB = new (std::nothrow) DAHelperGetTypeCB; + if (gettypeCB == nullptr) { + HILOG_ERROR("%{public}s, gettypeCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + gettypeCB->cbBase.cbInfo.env = env; + gettypeCB->cbBase.asyncWork = nullptr; + gettypeCB->cbBase.deferred = nullptr; + gettypeCB->cbBase.ability = nullptr; napi_value ret = GetTypeWrap(env, info, gettypeCB); if (ret == nullptr) { @@ -539,12 +541,15 @@ void GetTypePromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_GetFileTypes(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperGetFileTypesCB *getfiletypesCB = new (std::nothrow) DAHelperGetFileTypesCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperGetFileTypesCB *getfiletypesCB = new (std::nothrow) DAHelperGetFileTypesCB; + if (getfiletypesCB == nullptr) { + HILOG_ERROR("%{public}s, getfiletypesCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + getfiletypesCB->cbBase.cbInfo.env = env; + getfiletypesCB->cbBase.asyncWork = nullptr; + getfiletypesCB->cbBase.deferred = nullptr; + getfiletypesCB->cbBase.ability = nullptr; napi_value ret = GetFileTypesWrap(env, info, getfiletypesCB); if (ret == nullptr) { @@ -738,12 +743,15 @@ void GetFileTypesPromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_NormalizeUri(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperNormalizeUriCB *normalizeuriCB = new (std::nothrow) DAHelperNormalizeUriCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperNormalizeUriCB *normalizeuriCB = new (std::nothrow) DAHelperNormalizeUriCB; + if (normalizeuriCB == nullptr) { + HILOG_ERROR("%{public}s, normalizeuriCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + normalizeuriCB->cbBase.cbInfo.env = env; + normalizeuriCB->cbBase.asyncWork = nullptr; + normalizeuriCB->cbBase.deferred = nullptr; + normalizeuriCB->cbBase.ability = nullptr; napi_value ret = NormalizeUriWrap(env, info, normalizeuriCB); if (ret == nullptr) { @@ -910,12 +918,15 @@ void NormalizeUriPromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_DenormalizeUri(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperDenormalizeUriCB *denormalizeuriCB = new (std::nothrow) DAHelperDenormalizeUriCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperDenormalizeUriCB *denormalizeuriCB = new (std::nothrow) DAHelperDenormalizeUriCB; + if (denormalizeuriCB == nullptr) { + HILOG_ERROR("%{public}s, denormalizeuriCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + denormalizeuriCB->cbBase.cbInfo.env = env; + denormalizeuriCB->cbBase.asyncWork = nullptr; + denormalizeuriCB->cbBase.deferred = nullptr; + denormalizeuriCB->cbBase.ability = nullptr; napi_value ret = DenormalizeUriWrap(env, info, denormalizeuriCB); if (ret == nullptr) { @@ -1116,12 +1127,15 @@ napi_value UnwrapDataAbilityPredicates(std::string &value, napi_env env, napi_va napi_value NAPI_Delete(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperDeleteCB *deleteCB = new (std::nothrow) DAHelperDeleteCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperDeleteCB *deleteCB = new (std::nothrow) DAHelperDeleteCB; + if (deleteCB == nullptr) { + HILOG_ERROR("%{public}s, deleteCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + deleteCB->cbBase.cbInfo.env = env; + deleteCB->cbBase.asyncWork = nullptr; + deleteCB->cbBase.deferred = nullptr; + deleteCB->cbBase.ability = nullptr; napi_value ret = DeleteWrap(env, info, deleteCB); if (ret == nullptr) { @@ -1307,12 +1321,15 @@ void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_Update(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperUpdateCB *updateCB = new (std::nothrow) DAHelperUpdateCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperUpdateCB *updateCB = new (std::nothrow) DAHelperUpdateCB; + if (updateCB == nullptr) { + HILOG_ERROR("%{public}s, updateCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + updateCB->cbBase.cbInfo.env = env; + updateCB->cbBase.asyncWork = nullptr; + updateCB->cbBase.deferred = nullptr; + updateCB->cbBase.ability = nullptr; napi_value ret = UpdateWrap(env, info, updateCB); if (ret == nullptr) { @@ -1504,12 +1521,15 @@ void UpdatePromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperOpenFileCB *openFileCB = new (std::nothrow) DAHelperOpenFileCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperOpenFileCB *openFileCB = new (std::nothrow) DAHelperOpenFileCB; + if (openFileCB == nullptr) { + HILOG_ERROR("%{public}s, openFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + openFileCB->cbBase.cbInfo.env = env; + openFileCB->cbBase.asyncWork = nullptr; + openFileCB->cbBase.deferred = nullptr; + openFileCB->cbBase.ability = nullptr; napi_value ret = OpenFileWrap(env, info, openFileCB); if (ret == nullptr) { @@ -1695,12 +1715,15 @@ void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_BatchInsert(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperBatchInsertCB *BatchInsertCB = new (std::nothrow) DAHelperBatchInsertCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperBatchInsertCB *BatchInsertCB = new (std::nothrow) DAHelperBatchInsertCB; + if (BatchInsertCB == nullptr) { + HILOG_ERROR("%{public}s, BatchInsertCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + BatchInsertCB->cbBase.cbInfo.env = env; + BatchInsertCB->cbBase.asyncWork = nullptr; + BatchInsertCB->cbBase.deferred = nullptr; + BatchInsertCB->cbBase.ability = nullptr; napi_value ret = BatchInsertWrap(env, info, BatchInsertCB); if (ret == nullptr) { @@ -1920,12 +1943,15 @@ void BatchInsertPromiseCompleteCB(napi_env env, napi_status status, void *data) napi_value NAPI_Query(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperQueryCB *QueryCB = new (std::nothrow) DAHelperQueryCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = nullptr, - }; + DAHelperQueryCB *QueryCB = new (std::nothrow) DAHelperQueryCB; + if (QueryCB == nullptr) { + HILOG_ERROR("%{public}s, QueryCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + QueryCB->cbBase.cbInfo.env = env; + QueryCB->cbBase.asyncWork = nullptr; + QueryCB->cbBase.deferred = nullptr; + QueryCB->cbBase.ability = nullptr; napi_value ret = QueryWrap(env, info, QueryCB); if (ret == nullptr) { @@ -2134,11 +2160,14 @@ napi_value WrapResultSet(napi_env env, const ResultSet &resultSet) napi_value NAPI_Release(napi_env env, napi_callback_info info) { HILOG_INFO("%{public}s,called", __func__); - DAHelperReleaseCB *releaseCB = new (std::nothrow) DAHelperReleaseCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - }; + DAHelperReleaseCB *releaseCB = new (std::nothrow) DAHelperReleaseCB; + if (releaseCB == nullptr) { + HILOG_ERROR("%{public}s, releaseCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + releaseCB->cbBase.cbInfo.env = env; + releaseCB->cbBase.asyncWork = nullptr; + releaseCB->cbBase.deferred = nullptr; napi_value ret = ReleaseWrap(env, info, releaseCB); if (ret == nullptr) { diff --git a/interfaces/kits/napi/aafwk/featureAbility/native_module.cpp b/interfaces/kits/napi/aafwk/featureAbility/native_module.cpp index c01d8940d99..fae1617e5b1 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/native_module.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/native_module.cpp @@ -19,6 +19,7 @@ #include #include "feature_ability.h" +#include "feature_ability_constant.h" #include "napi_context.h" #include "napi_data_ability_helper.h" #include "napi/native_api.h" @@ -34,6 +35,7 @@ static napi_value Init(napi_env env, napi_value exports) FeatureAbilityInit(env, exports); ContextPermissionInit(env, exports); DataAbilityHelperInit(env, exports); + FAConstantInit(env, exports); return exports; } EXTERN_C_END diff --git a/interfaces/kits/napi/aafwk/formAbility/napi_form_ability.cpp b/interfaces/kits/napi/aafwk/formAbility/napi_form_ability.cpp index 59126008c20..cddee9b697d 100644 --- a/interfaces/kits/napi/aafwk/formAbility/napi_form_ability.cpp +++ b/interfaces/kits/napi/aafwk/formAbility/napi_form_ability.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include + #include "napi_form_ability.h" #include "napi/native_api.h" #include "napi/native_node_api.h" @@ -168,7 +171,7 @@ static napi_value ParseNapiIntoFormInfo(napi_env env, } else { formReqInfo.formId = 0; } - //HILOG_DEBUG("%{public}s, acquireForm formId=%{public}lld.", __func__, formReqInfo.formId); + HILOG_DEBUG("%{public}s, acquireForm formId=%{public}" PRId64 ".", __func__, formReqInfo.formId); // formReqInfo:formName property prop = nullptr; @@ -320,7 +323,7 @@ static void ParseFormJsInfoIntoNapi(napi_env env, const FormJsInfo &formInfo, na napi_value formId; std::string strFormId = std::to_string(formInfo.formId); napi_create_string_utf8(env, strFormId.c_str(), NAPI_AUTO_LENGTH, &formId); - //HILOG_DEBUG("%{public}s, formId=%{public}lld.", __func__, formInfo.formId); + HILOG_DEBUG("%{public}s, formId=%{public}" PRId64 ".", __func__, formInfo.formId); napi_set_named_property(env, result, "formId", formId); // formName @@ -487,7 +490,7 @@ static void ParseFormInfoIntoNapi(napi_env env, const FormInfo &formInfo, napi_v napi_set_element(env, supportDimensions, iDimensionsCount, dimensionInfo); ++iDimensionsCount; } - //HILOG_DEBUG("%{public}s, supportDimensions size=%{public}d.", __func__, formInfo.supportDimensions.size()); + HILOG_DEBUG("%{public}s, supportDimensions size=%{public}zu.", __func__, formInfo.supportDimensions.size()); napi_set_named_property(env, result, "supportDimensions", supportDimensions); // customizeDatas @@ -514,7 +517,7 @@ static void ParseFormInfoIntoNapi(napi_env env, const FormInfo &formInfo, napi_v napi_set_element(env, customizeDatas, iCustomizeDatasCount, customizeDataInfo); ++iDimensionsCount; } - //HILOG_DEBUG("%{public}s, customizeDatas size=%{public}d.", __func__, formInfo.customizeDatas.size()); + HILOG_DEBUG("%{public}s, customizeDatas size=%{public}zu.", __func__, formInfo.customizeDatas.size()); napi_set_named_property(env, result, "supportDimensions", customizeDatas); // relatedBundleName @@ -746,7 +749,7 @@ napi_value NAPI_AcquireForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, Wrong argument count.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Parse form info from JavaScript value FormReqInfo formReqInfo; @@ -926,7 +929,7 @@ napi_value NAPI_DeleteForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // get global value napi_value global = nullptr; @@ -1085,7 +1088,7 @@ napi_value NAPI_ReleaseForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -1252,7 +1255,7 @@ napi_value NAPI_RequestForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -1410,7 +1413,7 @@ napi_value NAPI_SetFormNextRefreshTime(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -1585,7 +1588,7 @@ napi_value NAPI_UpdateForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -1751,7 +1754,7 @@ napi_value NAPI_CastTempForm(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -1904,7 +1907,7 @@ napi_value NAPI_NotifyVisibleForms(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); uint32_t arrayLength = 0; NAPI_CALL(env, napi_get_array_length(env, argv[0], &arrayLength)); @@ -2082,7 +2085,7 @@ napi_value NAPI_NotifyInvisibleForms(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); uint32_t arrayLength = 0; NAPI_CALL(env, napi_get_array_length(env, argv[0], &arrayLength)); @@ -2265,7 +2268,7 @@ napi_value NAPI_EnableFormsUpdate(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); uint32_t arrayLength = 0; NAPI_CALL(env, napi_get_array_length(env, argv[0], &arrayLength)); @@ -2447,7 +2450,7 @@ napi_value NAPI_DisableFormsUpdate(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); uint32_t arrayLength = 0; NAPI_CALL(env, napi_get_array_length(env, argv[0], &arrayLength)); @@ -2625,7 +2628,7 @@ napi_value NAPI_CheckFMSReady(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - // HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // get global value napi_value global = nullptr; @@ -2780,7 +2783,7 @@ napi_value NAPI_GetAllFormsInfo(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - // HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); std::vector formInfos; formInfos.clear(); @@ -2965,7 +2968,7 @@ napi_value NAPI_GetFormsInfoByApp(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; @@ -3164,7 +3167,7 @@ napi_value NAPI_GetFormsInfoByModule(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); return nullptr; } - //HILOG_INFO("%{public}s, argc = [%{public}d]", __func__, argc); + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); // Check the value type of the arguments napi_valuetype valueType; diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn index 92a62226381..3787bd6e384 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn +++ b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn @@ -43,6 +43,8 @@ ohos_shared_library("napi_common") { "appexecfwk_standard:appexecfwk_core", "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "ipc_js:rpc", "samgr_L2:samgr_proxy", ] 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 15d08b5e766..edbed418f0b 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 @@ -159,6 +159,11 @@ struct CallingBundleCB { std::string callingBundleName; }; +struct GetOrCreateLocalDirCB { + CBBase cbBase; + std::string rootDir; +}; + struct ElementNameCB { CBBase cbBase; std::string deviceId; 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 8015bffda73..77228fb0b07 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -19,16 +19,13 @@ #include "napi_common_util.h" #include "securec.h" #include "hilog_wrapper.h" - +#include "napi_remote_object.h" namespace OHOS { namespace AppExecFwk { napi_value g_classContext; -static void *g_handle = nullptr; -constexpr char SHARED_LIBRARY_RPC[] = "/system/lib/module/librpc.z.so"; -constexpr char FUNC_RPC_CREATE_JS_REMOTE_OBJECT[] = "NAPI_ohos_rpc_CreateJsRemoteObject"; - +napi_value g_dataAbilityHelper; using NAPICreateJsRemoteObject = napi_value (*)(napi_env env, const sptr target); napi_value *GetGlobalClassContext(void) @@ -138,40 +135,6 @@ void SaveAppInfo(AppInfo_ &appInfo, const ApplicationInfo &appInfoOrg) HILOG_INFO("%{public}s end.", __func__); } -/** - * @brief GetApplicationInfo asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAppInfoExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); - AppInfoCB *appInfoCB = (AppInfoCB *)data; - appInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - - if (appInfoCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, ability == nullptr"); - appInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - if (!CheckAbilityType(&appInfoCB->cbBase)) { - HILOG_ERROR("NAPI_GetApplicationInfo, wrong ability type"); - appInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } - - std::shared_ptr appInfoPtr = appInfoCB->cbBase.ability->GetApplicationInfo(); - if (appInfoPtr != nullptr) { - SaveAppInfo(appInfoCB->appInfo, *appInfoPtr); - } else { - HILOG_ERROR("NAPI_GetApplicationInfo, appInfoPtr == nullptr"); - appInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; - } - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); -} - napi_value GetContinueAbilityOptionsInfoCommon( const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info) { @@ -307,36 +270,103 @@ napi_value WrapAppInfo(napi_env env, const AppInfo_ &appInfo) return result; } +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to AppTypeCB on success, nullptr on failure. + */ +AppTypeCB *CreateAppTypeCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s, called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + AppTypeCB *appTypeCB = new (std::nothrow) AppTypeCB{ + .cbBase.cbInfo.env = env, + .cbBase.asyncWork = nullptr, + .cbBase.deferred = nullptr, + .cbBase.ability = ability, + }; + if (appTypeCB == nullptr) { + HILOG_ERROR("%{public}s, appTypeCB == nullptr.", __func__); + } + HILOG_INFO("%{public}s, end.", __func__); + return appTypeCB; +} + +/** + * @brief GetAppType asynchronous processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param data Point to asynchronous processing of data. + */ +void GetAppTypeExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); + AppTypeCB *appTypeCB = (AppTypeCB *)data; + if (appTypeCB == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo,appTypeCB == nullptr"); + return; + } + + appTypeCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (appTypeCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo,ability == nullptr"); + appTypeCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + return; + } + + if (!CheckAbilityType(&appTypeCB->cbBase)) { + HILOG_ERROR("NAPI_GetApplicationInfo,wrong ability type"); + appTypeCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; + return; + } + + appTypeCB->name = appTypeCB->cbBase.ability->GetAppType(); + HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); +} + /** * @brief The callback at the end of the asynchronous callback. * * @param env The environment that the Node-API call is invoked under. * @param data Point to asynchronous processing of data. */ -void GetAppInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) +void GetAppTypeAsyncCompleteCB(napi_env env, napi_status status, void *data) { HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - AppInfoCB *appInfoCB = (AppInfoCB *)data; + AppTypeCB *appTypeCB = (AppTypeCB *)data; napi_value callback = nullptr; napi_value undefined = nullptr; napi_value result[ARGS_TWO] = {nullptr}; napi_value callResult = nullptr; NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, appInfoCB->cbBase.errCode); - if (appInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapAppInfo(env, appInfoCB->appInfo); + + result[PARAM0] = GetCallbackErrorValue(env, appTypeCB->cbBase.errCode); + if (appTypeCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8( + env, appTypeCB->cbBase.ability->GetAppType().c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); } else { result[PARAM1] = WrapUndefinedToJS(env); } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, appInfoCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, appTypeCB->cbBase.cbInfo.callback, &callback)); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - if (appInfoCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, appInfoCB->cbBase.cbInfo.callback)); + if (appTypeCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, appTypeCB->cbBase.cbInfo.callback)); } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, appInfoCB->cbBase.asyncWork)); - delete appInfoCB; - appInfoCB = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, appTypeCB->cbBase.asyncWork)); + delete appTypeCB; + appTypeCB = nullptr; HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); } @@ -346,45 +376,40 @@ void GetAppInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) * @param env The environment that the Node-API call is invoked under. * @param data Point to asynchronous processing of data. */ -void GetAppInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) +void GetAppTypePromiseCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - AppInfoCB *appInfoCB = (AppInfoCB *)data; - if (appInfoCB == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, appInfoCB == nullptr"); - return; - } - + HILOG_INFO("GetAppTypePromiseCompleteCB, main event thread complete."); + AppTypeCB *appTypeCB = (AppTypeCB *)data; napi_value result = nullptr; - if (appInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapAppInfo(env, appInfoCB->appInfo); - napi_resolve_deferred(env, appInfoCB->cbBase.deferred, result); + if (appTypeCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + napi_create_string_utf8(env, appTypeCB->cbBase.ability->GetAppType().c_str(), NAPI_AUTO_LENGTH, &result); + napi_resolve_deferred(env, appTypeCB->cbBase.deferred, result); } else { - result = GetCallbackErrorValue(env, appInfoCB->cbBase.errCode); - napi_reject_deferred(env, appInfoCB->cbBase.deferred, result); + result = GetCallbackErrorValue(env, appTypeCB->cbBase.errCode); + napi_reject_deferred(env, appTypeCB->cbBase.deferred, result); } - napi_delete_async_work(env, appInfoCB->cbBase.asyncWork); - delete appInfoCB; - appInfoCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); + napi_delete_async_work(env, appTypeCB->cbBase.asyncWork); + delete appTypeCB; + appTypeCB = nullptr; + HILOG_INFO("GetAppTypePromiseCompleteCB, main event thread complete end."); } /** - * @brief GetApplicationInfo Async. + * @brief GetAppType Async. * * @param env The environment that the Node-API call is invoked under. * @param args Indicates the arguments passed into the callback. * @param argcPromise Asynchronous data processing. - * @param appInfoCB Process data asynchronously. + * @param appTypeCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetApplicationInfoAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AppInfoCB *appInfoCB) +napi_value GetAppTypeAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AppTypeCB *appTypeCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || appInfoCB == nullptr) { + if (args == nullptr || appTypeCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -394,17 +419,17 @@ napi_value GetApplicationInfoAsync( napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &appInfoCB->cbBase.cbInfo.callback)); + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &appTypeCB->cbBase.cbInfo.callback)); } NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetAppInfoExecuteCB, - GetAppInfoAsyncCompleteCB, - (void *)appInfoCB, - &appInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, appInfoCB->cbBase.asyncWork)); + GetAppTypeExecuteCB, + GetAppTypeAsyncCompleteCB, + (void *)appTypeCB, + &appTypeCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, appTypeCB->cbBase.asyncWork)); napi_value result = nullptr; NAPI_CALL(env, napi_get_null(env, &result)); HILOG_INFO("%{public}s, asyncCallback end.", __func__); @@ -412,17 +437,17 @@ napi_value GetApplicationInfoAsync( } /** - * @brief GetApplicationInfo Promise. + * @brief GetAppType Promise. * * @param env The environment that the Node-API call is invoked under. - * @param appInfoCB Process data asynchronously. + * @param appTypeCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetApplicationInfoPromise(napi_env env, AppInfoCB *appInfoCB) +napi_value GetAppTypePromise(napi_env env, AppTypeCB *appTypeCB) { HILOG_INFO("%{public}s, promise.", __func__); - if (appInfoCB == nullptr) { + if (appTypeCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -431,34 +456,34 @@ napi_value GetApplicationInfoPromise(napi_env env, AppInfoCB *appInfoCB) napi_deferred deferred; napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - appInfoCB->cbBase.deferred = deferred; + appTypeCB->cbBase.deferred = deferred; NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetAppInfoExecuteCB, - GetAppInfoPromiseCompleteCB, - (void *)appInfoCB, - &appInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, appInfoCB->cbBase.asyncWork)); + GetAppTypeExecuteCB, + GetAppTypePromiseCompleteCB, + (void *)appTypeCB, + &appTypeCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, appTypeCB->cbBase.asyncWork)); HILOG_INFO("%{public}s, promise end.", __func__); return promise; } /** - * @brief GetApplicationInfo processing function. + * @brief GetAppType processing function. * * @param env The environment that the Node-API call is invoked under. - * @param appInfoCB Process data asynchronously. + * @param appTypeCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetApplicationInfoWrap(napi_env env, napi_callback_info info, AppInfoCB *appInfoCB) +napi_value GetAppTypeWrap(napi_env env, napi_callback_info info, AppTypeCB *appTypeCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (appInfoCB == nullptr) { - HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); + if (appTypeCB == nullptr) { + HILOG_ERROR("%{public}s, appTypeCB == nullptr.", __func__); return nullptr; } @@ -475,24 +500,55 @@ napi_value GetApplicationInfoWrap(napi_env env, napi_callback_info info, AppInfo } if (argcAsync > argcPromise) { - ret = GetApplicationInfoAsync(env, args, argcAsync, argcPromise, appInfoCB); + ret = GetAppTypeAsync(env, args, argcAsync, argcPromise, appTypeCB); } else { - ret = GetApplicationInfoPromise(env, appInfoCB); + ret = GetAppTypePromise(env, appTypeCB); } HILOG_INFO("%{public}s, asyncCallback end.", __func__); return ret; } +/** + * @brief Obtains the type of this application. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_GetAppTypeCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +{ + HILOG_INFO("%{public}s called.", __func__); + AppTypeCB *appTypeCB = CreateAppTypeCBInfo(env); + if (appTypeCB == nullptr) { + return WrapVoidToJS(env); + } + + appTypeCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + appTypeCB->cbBase.abilityType = abilityType; + napi_value ret = GetAppTypeWrap(env, info, appTypeCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s, ret == nullptr.", __func__); + if (appTypeCB != nullptr) { + delete appTypeCB; + appTypeCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s, end.", __func__); + return ret; +} + /** * @brief Create asynchronous data. * * @param env The environment that the Node-API call is invoked under. * - * @return Return a pointer to AppInfoCB on success, nullptr on failure. + * @return Return a pointer to AbilityInfoCB on success, nullptr on failure. */ -AppInfoCB *CreateAppInfoCBInfo(napi_env env) +AbilityInfoCB *CreateAbilityInfoCBInfo(napi_env env) { - HILOG_INFO("%{public}s, called.", __func__); + HILOG_INFO("%{public}s called.", __func__); napi_value global = nullptr; NAPI_CALL(env, napi_get_global(env, &global)); @@ -502,1905 +558,222 @@ AppInfoCB *CreateAppInfoCBInfo(napi_env env) Ability *ability = nullptr; NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - AppInfoCB *appInfoCB = new (std::nothrow) AppInfoCB{ + AbilityInfoCB *abilityInfoCB = new (std::nothrow) AbilityInfoCB{ .cbBase.cbInfo.env = env, .cbBase.asyncWork = nullptr, .cbBase.deferred = nullptr, .cbBase.ability = ability, - .cbBase.abilityType = AbilityType::UNKNOWN, - .cbBase.errCode = NAPI_ERR_NO_ERROR, }; - if (appInfoCB == nullptr) { - HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); + if (abilityInfoCB == nullptr) { + HILOG_ERROR("%{public}s, abilityInfoCB == nullptr.", __func__); } - HILOG_INFO("%{public}s, end.", __func__); - return appInfoCB; + HILOG_INFO("%{public}s end.", __func__); + return abilityInfoCB; } -/** - * @brief Obtains information about the current application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetApplicationInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +void SaveAbilityInfo(AbilityInfo_ &abilityInfo, const AbilityInfo &abilityInfoOrg) { - HILOG_INFO("%{public}s,called", __func__); - AppInfoCB *appInfoCB = CreateAppInfoCBInfo(env); - if (appInfoCB == nullptr) { - return WrapVoidToJS(env); - } + HILOG_INFO("%{public}s called.", __func__); + abilityInfo.bundleName = abilityInfoOrg.bundleName; + abilityInfo.name = abilityInfoOrg.name; + abilityInfo.label = abilityInfoOrg.label; + abilityInfo.description = abilityInfoOrg.description; + abilityInfo.icon = abilityInfoOrg.iconPath; + abilityInfo.labelId = abilityInfoOrg.applicationInfo.labelId; + abilityInfo.descriptionId = abilityInfoOrg.applicationInfo.descriptionId; + abilityInfo.iconId = abilityInfoOrg.applicationInfo.iconId; + abilityInfo.moduleName = abilityInfoOrg.moduleName; + abilityInfo.process = abilityInfoOrg.process; + abilityInfo.isVisible = abilityInfoOrg.visible; - appInfoCB->cbBase.abilityType = abilityType; - napi_value ret = GetApplicationInfoWrap(env, info, appInfoCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s,ret == nullptr", __func__); - if (appInfoCB != nullptr) { - delete appInfoCB; - appInfoCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s,end", __func__); - return ret; -} + abilityInfo.type = static_cast(abilityInfoOrg.type); + abilityInfo.orientation = static_cast(abilityInfoOrg.orientation); + abilityInfo.launchMode = static_cast(abilityInfoOrg.launchMode); -/** - * @brief GetBundleName asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetBundleNameExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("%{public}s called", __func__); - AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data; - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__); - return; - } + abilityInfo.uri = abilityInfoOrg.uri; + abilityInfo.targetAbility = abilityInfoOrg.targetAbility; - asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR; - asyncCallbackInfo->native_data.data_type = NVT_NONE; - if (asyncCallbackInfo->ability == nullptr) { - HILOG_ERROR("%{public}s ability == nullptr", __func__); - asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY; - return; + for (size_t i = 0; i < abilityInfoOrg.permissions.size(); i++) { + abilityInfo.permissions.emplace_back(abilityInfoOrg.permissions.at(i)); } - - if (!CheckAbilityType(asyncCallbackInfo)) { - HILOG_ERROR("%{public}s wrong ability type", __func__); - asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID; - asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED; - return; + for (size_t i = 0; i < abilityInfoOrg.deviceTypes.size(); i++) { + abilityInfo.deviceTypes.emplace_back(abilityInfoOrg.deviceTypes.at(i)); + } + for (size_t i = 0; i < abilityInfoOrg.deviceCapabilities.size(); i++) { + abilityInfo.deviceCapabilities.emplace_back(abilityInfoOrg.deviceCapabilities.at(i)); } - asyncCallbackInfo->native_data.data_type = NVT_STRING; - asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetBundleName(); - HILOG_INFO("%{public}s end. bundleName=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str()); -} + SaveAppInfo(abilityInfo.appInfo, abilityInfoOrg.applicationInfo); -/** - * @brief GetBundleName processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param asyncCallbackInfo Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value NAPI_GetBundleNameWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called", __func__); - size_t argc = ARGS_MAX_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - if (argc > ARGS_ONE) { - HILOG_INFO("%{public}s called, parameters is invalid.", __func__); - return nullptr; - } - - if (argc == ARGS_ONE) { - if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) { - HILOG_INFO("%{public}s called, the first parameter is invalid.", __func__); - return nullptr; - } - } - - AsyncParamEx asyncParamEx; - if (asyncCallbackInfo->cbInfo.callback != nullptr) { - HILOG_INFO("%{public}s called. asyncCallback.", __func__); - asyncParamEx.resource = "NAPI_GetBundleNameCallback"; - asyncParamEx.execute = GetBundleNameExecuteCallback; - asyncParamEx.complete = CompleteAsyncCallbackWork; - - return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("%{public}s called. promise.", __func__); - asyncParamEx.resource = "NAPI_GetBundleNamePromise"; - asyncParamEx.execute = GetBundleNameExecuteCallback; - asyncParamEx.complete = CompletePromiseCallbackWork; - - return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } -} - -/** - * @brief Get bundle name. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetBundleNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called", __func__); - AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__); - return WrapVoidToJS(env); - } - - asyncCallbackInfo->abilityType = abilityType; - napi_value ret = NAPI_GetBundleNameWrap(env, info, asyncCallbackInfo); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullptr", __func__); - FreeAsyncJSCallbackInfo(&asyncCallbackInfo); - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end", __func__); - return ret; + abilityInfo.readPermission = abilityInfoOrg.readPermission; + abilityInfo.writePermission = abilityInfoOrg.writePermission; + abilityInfo.formEntity = 0; // no data + abilityInfo.minFormHeight = 0; // no data + abilityInfo.defaultFormHeight = 0; // no data + abilityInfo.minFormWidth = 0; // no data + abilityInfo.defaultFormWidth = 0; // no data + abilityInfo.backgroundModes = 0; // no data + abilityInfo.subType = 0; // no data + abilityInfo.formEnabled = false; // no data + HILOG_INFO("%{public}s end.", __func__); } -napi_value WrapProcessInfo(napi_env env, ProcessInfoCB *processInfoCB) +napi_value WrapAbilityInfo(napi_env env, const AbilityInfo_ &abilityInfo) { - HILOG_INFO("%{public}s called", __func__); - if (processInfoCB == nullptr) { - HILOG_ERROR("%{public}s Invalid param(processInfoCB == nullptr)", __func__); - return nullptr; - } + HILOG_INFO("%{public}s called.", __func__); napi_value result = nullptr; napi_value proValue = nullptr; NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_create_int32(env, processInfoCB->pid, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "pid", proValue)); + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.bundleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "bundleName", proValue)); - NAPI_CALL(env, napi_create_string_utf8(env, processInfoCB->processName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "processName", proValue)); - HILOG_INFO("%{public}s end", __func__); - return result; -} + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.name.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "name", proValue)); -/** - * @brief GetProcessInfo asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetProcessInfoExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetProcessInfo, worker pool thread execute."); - ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; - if (processInfoCB == nullptr) { - return; - } + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.label.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "label", proValue)); - processInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (processInfoCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetProcessInfo, ability == nullptr"); - processInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.description.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "description", proValue)); - if (!CheckAbilityType(&processInfoCB->cbBase)) { - HILOG_ERROR("NAPI_GetProcessInfo, wrong ability type"); - processInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.icon.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "icon", proValue)); - std::shared_ptr processInfoPtr = processInfoCB->cbBase.ability->GetProcessInfo(); - if (processInfoPtr != nullptr) { - processInfoCB->processName = processInfoPtr->GetProcessName(); - processInfoCB->pid = processInfoPtr->GetPid(); - } else { - HILOG_ERROR("NAPI_GetProcessInfo, processInfoPtr == nullptr"); - processInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; - } - HILOG_INFO("NAPI_GetProcessInfo, worker pool thread execute end."); -} + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.moduleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "moduleName", proValue)); -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetProcessInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetProcessInfo, main event thread complete."); - ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value result[ARGS_TWO] = {nullptr}; - napi_value callResult = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, processInfoCB->cbBase.errCode); - if (processInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapProcessInfo(env, processInfoCB); - } else { - result[PARAM1] = WrapUndefinedToJS(env); - } + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.process.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "process", proValue)); - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, processInfoCB->cbBase.cbInfo.callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.type), &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "type", proValue)); - if (processInfoCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, processInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, processInfoCB->cbBase.asyncWork)); - delete processInfoCB; - processInfoCB = nullptr; - HILOG_INFO("NAPI_GetProcessInfo, main event thread complete end."); -} + NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.orientation), &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "orientation", proValue)); -/** - * @brief GetProcessInfo Async. - * - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * @param argcPromise Asynchronous data processing. - * @param ProcessInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetProcessInfoAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ProcessInfoCB *processInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || processInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.launchMode), &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "launchMode", proValue)); - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &processInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetProcessInfoExecuteCB, - GetProcessInfoAsyncCompleteCB, - (void *)processInfoCB, - &processInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, processInfoCB->cbBase.asyncWork)); - napi_value result = nullptr; - NAPI_CALL(env, napi_get_null(env, &result)); - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return result; -} + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.uri.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "uri", proValue)); -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetProcessInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetProcessInfo, main event thread complete."); - ProcessInfoCB *processInfoCB = (ProcessInfoCB *)data; - napi_value result = nullptr; - if (processInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapProcessInfo(env, processInfoCB); - napi_resolve_deferred(env, processInfoCB->cbBase.deferred, result); - } else { - result = GetCallbackErrorValue(env, processInfoCB->cbBase.errCode); - napi_reject_deferred(env, processInfoCB->cbBase.deferred, result); - } + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.readPermission.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "readPermission", proValue)); - napi_delete_async_work(env, processInfoCB->cbBase.asyncWork); - delete processInfoCB; - processInfoCB = nullptr; - HILOG_INFO("NAPI_GetProcessInfo, main event thread complete end."); -} + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.writePermission.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "writePermission", proValue)); -/** - * @brief GetProcessInfo Promise. - * - * @param env The environment that the Node-API call is invoked under. - * @param ProcessInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetProcessInfoPromise(napi_env env, ProcessInfoCB *processInfoCB) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (processInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - processInfoCB->cbBase.deferred = deferred; + NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.targetAbility.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "targetAbility", proValue)); - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetProcessInfoExecuteCB, - GetProcessInfoPromiseCompleteCB, - (void *)processInfoCB, - &processInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, processInfoCB->cbBase.asyncWork)); - HILOG_INFO("%{public}s, promise end.", __func__); - return promise; -} + NAPI_CALL(env, napi_create_int32(env, abilityInfo.labelId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "labelId", proValue)); -/** - * @brief GetProcessInfo processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param ProcessInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetProcessInfoWrap(napi_env env, napi_callback_info info, ProcessInfoCB *processInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (processInfoCB == nullptr) { - HILOG_ERROR("%{public}s, processInfoCB == nullptr.", __func__); - return nullptr; - } + NAPI_CALL(env, napi_create_int32(env, abilityInfo.descriptionId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "descriptionId", proValue)); - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = nullptr; + NAPI_CALL(env, napi_create_int32(env, abilityInfo.iconId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "iconId", proValue)); - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } + NAPI_CALL(env, napi_create_int32(env, abilityInfo.formEntity, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "formEntity", proValue)); - if (argcAsync > argcPromise) { - ret = GetProcessInfoAsync(env, args, argcAsync, argcPromise, processInfoCB); - } else { - ret = GetProcessInfoPromise(env, processInfoCB); - } - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return ret; -} + NAPI_CALL(env, napi_create_int32(env, abilityInfo.minFormHeight, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "minFormHeight", proValue)); -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to ProcessInfoCB on success, nullptr on failure. - */ -ProcessInfoCB *CreateProcessInfoCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s, called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); + NAPI_CALL(env, napi_create_int32(env, abilityInfo.defaultFormHeight, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "defaultFormHeight", proValue)); - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + NAPI_CALL(env, napi_create_int32(env, abilityInfo.minFormWidth, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "minFormWidth", proValue)); - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + NAPI_CALL(env, napi_create_int32(env, abilityInfo.defaultFormWidth, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "defaultFormWidth", proValue)); - ProcessInfoCB *processInfoCB = new (std::nothrow) ProcessInfoCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (processInfoCB == nullptr) { - HILOG_ERROR("%{public}s, processInfoCB == nullptr.", __func__); - } - HILOG_INFO("%{public}s, end.", __func__); - return processInfoCB; -} - -/** - * @brief Obtains the process Info this application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called.", __func__); - ProcessInfoCB *processInfoCB = CreateProcessInfoCBInfo(env); - if (processInfoCB == nullptr) { - return WrapVoidToJS(env); - } - - processInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - processInfoCB->cbBase.abilityType = abilityType; - napi_value ret = GetProcessInfoWrap(env, info, processInfoCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s, ret == nullptr.", __func__); - if (processInfoCB != nullptr) { - delete processInfoCB; - processInfoCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s, end.", __func__); - return ret; -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to AppTypeCB on success, nullptr on failure. - */ -AppTypeCB *CreateAppTypeCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s, called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); - - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); - - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - - AppTypeCB *appTypeCB = new (std::nothrow) AppTypeCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (appTypeCB == nullptr) { - HILOG_ERROR("%{public}s, appTypeCB == nullptr.", __func__); - } - HILOG_INFO("%{public}s, end.", __func__); - return appTypeCB; -} - -/** - * @brief GetAppType asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAppTypeExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); - AppTypeCB *appTypeCB = (AppTypeCB *)data; - if (appTypeCB == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo,appTypeCB == nullptr"); - return; - } - - appTypeCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (appTypeCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo,ability == nullptr"); - appTypeCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - if (!CheckAbilityType(&appTypeCB->cbBase)) { - HILOG_ERROR("NAPI_GetApplicationInfo,wrong ability type"); - appTypeCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } - - appTypeCB->name = appTypeCB->cbBase.ability->GetAppType(); - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); -} - -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAppTypeAsyncCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - AppTypeCB *appTypeCB = (AppTypeCB *)data; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value result[ARGS_TWO] = {nullptr}; - napi_value callResult = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - - result[PARAM0] = GetCallbackErrorValue(env, appTypeCB->cbBase.errCode); - if (appTypeCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - NAPI_CALL_RETURN_VOID(env, - napi_create_string_utf8( - env, appTypeCB->cbBase.ability->GetAppType().c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); - } else { - result[PARAM1] = WrapUndefinedToJS(env); - } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, appTypeCB->cbBase.cbInfo.callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - - if (appTypeCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, appTypeCB->cbBase.cbInfo.callback)); - } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, appTypeCB->cbBase.asyncWork)); - delete appTypeCB; - appTypeCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); -} - -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAppTypePromiseCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("GetAppTypePromiseCompleteCB, main event thread complete."); - AppTypeCB *appTypeCB = (AppTypeCB *)data; - napi_value result = nullptr; - if (appTypeCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - napi_create_string_utf8(env, appTypeCB->cbBase.ability->GetAppType().c_str(), NAPI_AUTO_LENGTH, &result); - napi_resolve_deferred(env, appTypeCB->cbBase.deferred, result); - } else { - result = GetCallbackErrorValue(env, appTypeCB->cbBase.errCode); - napi_reject_deferred(env, appTypeCB->cbBase.deferred, result); - } - - napi_delete_async_work(env, appTypeCB->cbBase.asyncWork); - delete appTypeCB; - appTypeCB = nullptr; - HILOG_INFO("GetAppTypePromiseCompleteCB, main event thread complete end."); -} - -/** - * @brief GetAppType Async. - * - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * @param argcPromise Asynchronous data processing. - * @param appTypeCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAppTypeAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AppTypeCB *appTypeCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || appTypeCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &appTypeCB->cbBase.cbInfo.callback)); - } - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetAppTypeExecuteCB, - GetAppTypeAsyncCompleteCB, - (void *)appTypeCB, - &appTypeCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, appTypeCB->cbBase.asyncWork)); - napi_value result = nullptr; - NAPI_CALL(env, napi_get_null(env, &result)); - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return result; -} - -/** - * @brief GetAppType Promise. - * - * @param env The environment that the Node-API call is invoked under. - * @param appTypeCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAppTypePromise(napi_env env, AppTypeCB *appTypeCB) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (appTypeCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - appTypeCB->cbBase.deferred = deferred; - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetAppTypeExecuteCB, - GetAppTypePromiseCompleteCB, - (void *)appTypeCB, - &appTypeCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, appTypeCB->cbBase.asyncWork)); - HILOG_INFO("%{public}s, promise end.", __func__); - return promise; -} - -/** - * @brief GetAppType processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param appTypeCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAppTypeWrap(napi_env env, napi_callback_info info, AppTypeCB *appTypeCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (appTypeCB == nullptr) { - HILOG_ERROR("%{public}s, appTypeCB == nullptr.", __func__); - return nullptr; - } - - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (argcAsync > argcPromise) { - ret = GetAppTypeAsync(env, args, argcAsync, argcPromise, appTypeCB); - } else { - ret = GetAppTypePromise(env, appTypeCB); - } - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return ret; -} - -/** - * @brief Obtains the type of this application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetAppTypeCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called.", __func__); - AppTypeCB *appTypeCB = CreateAppTypeCBInfo(env); - if (appTypeCB == nullptr) { - return WrapVoidToJS(env); - } - - appTypeCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - appTypeCB->cbBase.abilityType = abilityType; - napi_value ret = GetAppTypeWrap(env, info, appTypeCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s, ret == nullptr.", __func__); - if (appTypeCB != nullptr) { - delete appTypeCB; - appTypeCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s, end.", __func__); - return ret; -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to ElementNameCB on success, nullptr on failure. - */ -ElementNameCB *CreateElementNameCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s, called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); - - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); - - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - - ElementNameCB *elementNameCB = new (std::nothrow) ElementNameCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (elementNameCB == nullptr) { - HILOG_ERROR("%{public}s, elementNameCB == nullptr.", __func__); - } - HILOG_INFO("%{public}s, end.", __func__); - return elementNameCB; -} - -napi_value WrapElementName(napi_env env, ElementNameCB *elementNameCB) -{ - HILOG_INFO("%{public}s, called.", __func__); - if (elementNameCB == nullptr) { - HILOG_ERROR("%{public}s,Invalid param(appInfoCB = nullptr)", __func__); - return nullptr; - } - napi_value result = nullptr; - napi_value proValue = nullptr; - NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->abilityName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "abilityName", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->bundleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "bundleName", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->deviceId.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "deviceId", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->shortName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "shortName", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, elementNameCB->uri.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "uri", proValue)); - HILOG_INFO("%{public}s, end.", __func__); - return result; -} - -/** - * @brief GetElementName asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetElementNameExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); - if (data == nullptr) { - HILOG_ERROR("%{public}s, data == nullptr.", __func__); - return; - } - ElementNameCB *elementNameCB = (ElementNameCB *)data; - if (elementNameCB == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, elementNameCB == nullptr"); - return; - } - - elementNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (elementNameCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, ability == nullptr"); - elementNameCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - if (!CheckAbilityType(&elementNameCB->cbBase)) { - HILOG_ERROR("NAPI_GetApplicationInfo,wrong ability type"); - elementNameCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } - - std::shared_ptr elementName = elementNameCB->cbBase.ability->GetElementName(); - if (elementNameCB != nullptr) { - elementNameCB->deviceId = elementName->GetDeviceID(); - elementNameCB->bundleName = elementName->GetBundleName(); - elementNameCB->abilityName = elementName->GetAbilityName(); - elementNameCB->uri = elementNameCB->cbBase.ability->GetWant()->GetUriString(); - elementNameCB->shortName = ""; - } else { - elementNameCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; - } - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); -} - -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetElementNameAsyncCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - ElementNameCB *elementNameCB = (ElementNameCB *)data; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value result[ARGS_TWO] = {nullptr}; - napi_value callResult = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, elementNameCB->cbBase.errCode); - if (elementNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapElementName(env, elementNameCB); - } else { - result[PARAM1] = WrapUndefinedToJS(env); - } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, elementNameCB->cbBase.cbInfo.callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - - if (elementNameCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, elementNameCB->cbBase.cbInfo.callback)); - } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, elementNameCB->cbBase.asyncWork)); - delete elementNameCB; - elementNameCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); -} - -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetElementNamePromiseCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - ElementNameCB *elementNameCB = (ElementNameCB *)data; - napi_value result = nullptr; - if (elementNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapElementName(env, elementNameCB); - napi_resolve_deferred(env, elementNameCB->cbBase.deferred, result); - } else { - result = GetCallbackErrorValue(env, elementNameCB->cbBase.errCode); - napi_reject_deferred(env, elementNameCB->cbBase.deferred, result); - } - - napi_delete_async_work(env, elementNameCB->cbBase.asyncWork); - delete elementNameCB; - elementNameCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); -} - -/** - * @brief GetElementName Promise. - * - * @param env The environment that the Node-API call is invoked under. - * @param elementNameCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetElementNamePromise(napi_env env, ElementNameCB *elementNameCB) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (elementNameCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - elementNameCB->cbBase.deferred = deferred; - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetElementNameExecuteCB, - GetElementNamePromiseCompleteCB, - (void *)elementNameCB, - &elementNameCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, elementNameCB->cbBase.asyncWork)); - HILOG_INFO("%{public}s, promise end.", __func__); - return promise; -} - -/** - * @brief GetElementName Async. - * - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * @param argcPromise Asynchronous data processing. - * @param elementNameCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetElementNameAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ElementNameCB *elementNameCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || elementNameCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &elementNameCB->cbBase.cbInfo.callback)); - } - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetElementNameExecuteCB, - GetElementNameAsyncCompleteCB, - (void *)elementNameCB, - &elementNameCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, elementNameCB->cbBase.asyncWork)); - napi_value result = nullptr; - NAPI_CALL(env, napi_get_null(env, &result)); - return result; - HILOG_INFO("%{public}s, asyncCallback end.", __func__); -} - -/** - * @brief GetElementName processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param elementNameCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetElementNameWrap(napi_env env, napi_callback_info info, ElementNameCB *elementNameCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (elementNameCB == nullptr) { - HILOG_ERROR("%{public}s, appInfoCB == nullptr.", __func__); - return nullptr; - } - - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (argcAsync > argcPromise) { - ret = GetElementNameAsync(env, args, argcAsync, argcPromise, elementNameCB); - } else { - ret = GetElementNamePromise(env, elementNameCB); - } - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return ret; -} - -/** - * @brief Obtains the elementName object of the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetElementNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called.", __func__); - ElementNameCB *elementNameCB = CreateElementNameCBInfo(env); - if (elementNameCB == nullptr) { - return WrapVoidToJS(env); - } - - elementNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - elementNameCB->cbBase.abilityType = abilityType; - napi_value ret = GetElementNameWrap(env, info, elementNameCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullptr.", __func__); - if (elementNameCB != nullptr) { - delete elementNameCB; - elementNameCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to AbilityInfoCB on success, nullptr on failure. - */ -AbilityInfoCB *CreateAbilityInfoCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); - - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); - - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - - AbilityInfoCB *abilityInfoCB = new (std::nothrow) AbilityInfoCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (abilityInfoCB == nullptr) { - HILOG_ERROR("%{public}s, abilityInfoCB == nullptr.", __func__); - } - HILOG_INFO("%{public}s end.", __func__); - return abilityInfoCB; -} - -void SaveAbilityInfo(AbilityInfo_ &abilityInfo, const AbilityInfo &abilityInfoOrg) -{ - HILOG_INFO("%{public}s called.", __func__); - abilityInfo.bundleName = abilityInfoOrg.bundleName; - abilityInfo.name = abilityInfoOrg.name; - abilityInfo.label = abilityInfoOrg.label; - abilityInfo.description = abilityInfoOrg.description; - abilityInfo.icon = abilityInfoOrg.iconPath; - abilityInfo.labelId = abilityInfoOrg.applicationInfo.labelId; - abilityInfo.descriptionId = abilityInfoOrg.applicationInfo.descriptionId; - abilityInfo.iconId = abilityInfoOrg.applicationInfo.iconId; - abilityInfo.moduleName = abilityInfoOrg.moduleName; - abilityInfo.process = abilityInfoOrg.process; - abilityInfo.isVisible = abilityInfoOrg.visible; - - abilityInfo.type = static_cast(abilityInfoOrg.type); - abilityInfo.orientation = static_cast(abilityInfoOrg.orientation); - abilityInfo.launchMode = static_cast(abilityInfoOrg.launchMode); - - abilityInfo.uri = abilityInfoOrg.uri; - abilityInfo.targetAbility = abilityInfoOrg.targetAbility; - - for (size_t i = 0; i < abilityInfoOrg.permissions.size(); i++) { - abilityInfo.permissions.emplace_back(abilityInfoOrg.permissions.at(i)); - } - for (size_t i = 0; i < abilityInfoOrg.deviceTypes.size(); i++) { - abilityInfo.deviceTypes.emplace_back(abilityInfoOrg.deviceTypes.at(i)); - } - for (size_t i = 0; i < abilityInfoOrg.deviceCapabilities.size(); i++) { - abilityInfo.deviceCapabilities.emplace_back(abilityInfoOrg.deviceCapabilities.at(i)); - } - - SaveAppInfo(abilityInfo.appInfo, abilityInfoOrg.applicationInfo); - - abilityInfo.readPermission = abilityInfoOrg.readPermission; - abilityInfo.writePermission = abilityInfoOrg.writePermission; - abilityInfo.formEntity = 0; // no data - abilityInfo.minFormHeight = 0; // no data - abilityInfo.defaultFormHeight = 0; // no data - abilityInfo.minFormWidth = 0; // no data - abilityInfo.defaultFormWidth = 0; // no data - abilityInfo.backgroundModes = 0; // no data - abilityInfo.subType = 0; // no data - abilityInfo.formEnabled = false; // no data - HILOG_INFO("%{public}s end.", __func__); -} - -napi_value WrapAbilityInfo(napi_env env, const AbilityInfo_ &abilityInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value result = nullptr; - napi_value proValue = nullptr; - NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.bundleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "bundleName", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.name.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "name", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.label.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "label", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.description.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "description", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.icon.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "icon", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.moduleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "moduleName", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.process.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "process", proValue)); - - NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.type), &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "type", proValue)); - - NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.orientation), &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "orientation", proValue)); - - NAPI_CALL(env, napi_create_int32(env, static_cast(abilityInfo.launchMode), &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "launchMode", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.uri.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "uri", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.readPermission.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "readPermission", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.writePermission.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "writePermission", proValue)); - - NAPI_CALL(env, napi_create_string_utf8(env, abilityInfo.targetAbility.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "targetAbility", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.labelId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "labelId", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.descriptionId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "descriptionId", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.iconId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "iconId", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.formEntity, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "formEntity", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.minFormHeight, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "minFormHeight", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.defaultFormHeight, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "defaultFormHeight", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.minFormWidth, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "minFormWidth", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.defaultFormWidth, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "defaultFormWidth", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.backgroundModes, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "backgroundModes", proValue)); - - NAPI_CALL(env, napi_create_int32(env, abilityInfo.subType, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "subType", proValue)); - - NAPI_CALL(env, napi_get_boolean(env, abilityInfo.isVisible, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "isVisible", proValue)); - - NAPI_CALL(env, napi_get_boolean(env, abilityInfo.formEnabled, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "formEnabled", proValue)); - - napi_value jsArrayPermissions = nullptr; - NAPI_CALL(env, napi_create_array(env, &jsArrayPermissions)); - for (size_t i = 0; i < abilityInfo.permissions.size(); i++) { - proValue = nullptr; - NAPI_CALL( - env, napi_create_string_utf8(env, abilityInfo.permissions.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_element(env, jsArrayPermissions, i, proValue)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "permissions", jsArrayPermissions)); - - napi_value jsArrayDeviceCapabilities = nullptr; - NAPI_CALL(env, napi_create_array(env, &jsArrayDeviceCapabilities)); - for (size_t i = 0; i < abilityInfo.deviceCapabilities.size(); i++) { - proValue = nullptr; - NAPI_CALL(env, - napi_create_string_utf8(env, abilityInfo.deviceCapabilities.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_element(env, jsArrayDeviceCapabilities, i, proValue)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "deviceCapabilities", jsArrayDeviceCapabilities)); - - napi_value jsArrayDeviceTypes = nullptr; - NAPI_CALL(env, napi_create_array(env, &jsArrayDeviceTypes)); - for (size_t i = 0; i < abilityInfo.deviceTypes.size(); i++) { - proValue = nullptr; - NAPI_CALL( - env, napi_create_string_utf8(env, abilityInfo.deviceTypes.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_element(env, jsArrayDeviceTypes, i, proValue)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "deviceTypes", jsArrayDeviceTypes)); - - napi_value appInfo = nullptr; - appInfo = WrapAppInfo(env, abilityInfo.appInfo); - NAPI_CALL(env, napi_set_named_property(env, result, "applicationInfo", appInfo)); - HILOG_INFO("%{public}s end.", __func__); - return result; -} - -/** - * @brief GetAbilityInfo asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAbilityInfoExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); - AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; - if (abilityInfoCB == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, abilityInfoCB == nullptr"); - return; - } - - abilityInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (abilityInfoCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetApplicationInfo, ability == nullptr"); - abilityInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - if (!CheckAbilityType(&abilityInfoCB->cbBase)) { - HILOG_ERROR("NAPI_GetApplicationInfo,wrong ability type"); - abilityInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } - - std::shared_ptr abilityInfoPtr = abilityInfoCB->cbBase.ability->GetAbilityInfo(); - if (abilityInfoPtr != nullptr) { - SaveAbilityInfo(abilityInfoCB->abilityInfo, *abilityInfoPtr); - } else { - abilityInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; - } - HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); -} - -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAbilityInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value result[ARGS_TWO] = {nullptr}; - napi_value callResult = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, abilityInfoCB->cbBase.errCode); - if (abilityInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapAbilityInfo(env, abilityInfoCB->abilityInfo); - } else { - result[PARAM1] = WrapUndefinedToJS(env); - } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, abilityInfoCB->cbBase.cbInfo.callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - - if (abilityInfoCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, abilityInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, abilityInfoCB->cbBase.asyncWork)); - delete abilityInfoCB; - abilityInfoCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); -} - -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetAbilityInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); - AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; - napi_value result = nullptr; - if (abilityInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapAbilityInfo(env, abilityInfoCB->abilityInfo); - napi_resolve_deferred(env, abilityInfoCB->cbBase.deferred, result); - } else { - result = GetCallbackErrorValue(env, abilityInfoCB->cbBase.errCode); - napi_reject_deferred(env, abilityInfoCB->cbBase.deferred, result); - } - - napi_delete_async_work(env, abilityInfoCB->cbBase.asyncWork); - delete abilityInfoCB; - abilityInfoCB = nullptr; - HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); -} - -/** - * @brief GetAbilityInfo Async. - * - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * @param argcPromise Asynchronous data processing. - * @param abilityInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAbilityInfoAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AbilityInfoCB *abilityInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || abilityInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &abilityInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetAbilityInfoExecuteCB, - GetAbilityInfoAsyncCompleteCB, - (void *)abilityInfoCB, - &abilityInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, abilityInfoCB->cbBase.asyncWork)); - napi_value result = nullptr; - NAPI_CALL(env, napi_get_null(env, &result)); - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return result; -} - -/** - * @brief GetAbilityInfo Promise. - * - * @param env The environment that the Node-API call is invoked under. - * @param abilityInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAbilityInfoPromise(napi_env env, AbilityInfoCB *abilityInfoCB) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (abilityInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - abilityInfoCB->cbBase.deferred = deferred; - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetAbilityInfoExecuteCB, - GetAbilityInfoPromiseCompleteCB, - (void *)abilityInfoCB, - &abilityInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, abilityInfoCB->cbBase.asyncWork)); - HILOG_INFO("%{public}s, promise end.", __func__); - return promise; -} - -/** - * @brief GetAbilityInfo processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param abilityInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetAbilityInfoWrap(napi_env env, napi_callback_info info, AbilityInfoCB *abilityInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (abilityInfoCB == nullptr) { - HILOG_ERROR("%{public}s, abilityInfoCB == nullptr.", __func__); - return nullptr; - } - - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (argcAsync > argcPromise) { - ret = GetAbilityInfoAsync(env, args, argcAsync, argcPromise, abilityInfoCB); - } else { - ret = GetAbilityInfoPromise(env, abilityInfoCB); - } - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return ret; -} - -/** - * @brief Obtains information about the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetAbilityInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called.", __func__); - AbilityInfoCB *abilityInfoCB = CreateAbilityInfoCBInfo(env); - if (abilityInfoCB == nullptr) { - return WrapVoidToJS(env); - } - - abilityInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - abilityInfoCB->cbBase.abilityType = abilityType; - napi_value ret = GetAbilityInfoWrap(env, info, abilityInfoCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullptr", __func__); - if (abilityInfoCB != nullptr) { - delete abilityInfoCB; - abilityInfoCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to HapModuleInfoCB on success, nullptr on failure. - */ -HapModuleInfoCB *CreateHapModuleInfoCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); - - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); - - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - - HapModuleInfoCB *hapModuleInfoCB = new (std::nothrow) HapModuleInfoCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (hapModuleInfoCB == nullptr) { - HILOG_ERROR("%{public}s, hapModuleInfoCB == nullptr.", __func__); - } - HILOG_INFO("%{public}s end.", __func__); - return hapModuleInfoCB; -} - -void SaveHapModuleInfo(HapModuleInfo_ &hapModuleInfo, const HapModuleInfo &hapModuleInfoOrg) -{ - HILOG_INFO("%{public}s called.", __func__); - hapModuleInfo.name = hapModuleInfoOrg.name; - hapModuleInfo.description = hapModuleInfoOrg.description; - hapModuleInfo.icon = hapModuleInfoOrg.iconPath; - hapModuleInfo.label = hapModuleInfoOrg.label; - hapModuleInfo.backgroundImg = hapModuleInfoOrg.backgroundImg; - hapModuleInfo.moduleName = hapModuleInfoOrg.moduleName; - hapModuleInfo.supportedModes = hapModuleInfoOrg.supportedModes; - hapModuleInfo.descriptionId = 0; // no data - hapModuleInfo.labelId = 0; // no data - hapModuleInfo.iconId = 0; // no data - hapModuleInfo.mainAbilityName = ""; // no data - hapModuleInfo.installationFree = false; // no data - - for (size_t i = 0; i < hapModuleInfoOrg.reqCapabilities.size(); i++) { - hapModuleInfo.reqCapabilities.emplace_back(hapModuleInfoOrg.reqCapabilities.at(i)); - } - - for (size_t i = 0; i < hapModuleInfoOrg.deviceTypes.size(); i++) { - hapModuleInfo.deviceTypes.emplace_back(hapModuleInfoOrg.deviceTypes.at(i)); - } - - for (size_t i = 0; i < hapModuleInfoOrg.abilityInfos.size(); i++) { - AbilityInfo_ abilityInfo; - SaveAbilityInfo(abilityInfo, hapModuleInfoOrg.abilityInfos.at(i)); - hapModuleInfo.abilityInfos.emplace_back(abilityInfo); - } - HILOG_INFO("%{public}s end.", __func__); -} - -napi_value WrapHapModuleInfo(napi_env env, const HapModuleInfoCB &hapModuleInfoCB) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value result = nullptr; - napi_value proValue = nullptr; - NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL( - env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.name.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "name", proValue)); - - NAPI_CALL(env, - napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.description.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "description", proValue)); - - NAPI_CALL( - env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.icon.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "icon", proValue)); - - NAPI_CALL( - env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.label.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "label", proValue)); - - NAPI_CALL(env, - napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.backgroundImg.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "backgroundImg", proValue)); - - NAPI_CALL(env, - napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.moduleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "moduleName", proValue)); - - NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.supportedModes, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "supportedModes", proValue)); - - NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.descriptionId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "descriptionId", proValue)); - - NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.labelId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "labelId", proValue)); - - NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.iconId, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "iconId", proValue)); - - NAPI_CALL(env, - napi_create_string_utf8( - env, hapModuleInfoCB.hapModuleInfo.mainAbilityName.c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "mainAbilityName", proValue)); - - NAPI_CALL(env, napi_get_boolean(env, hapModuleInfoCB.hapModuleInfo.installationFree, &proValue)); - NAPI_CALL(env, napi_set_named_property(env, result, "installationFree", proValue)); - - napi_value jsArrayreqCapabilities = nullptr; - NAPI_CALL(env, napi_create_array(env, &jsArrayreqCapabilities)); - for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.reqCapabilities.size(); i++) { - proValue = nullptr; - NAPI_CALL(env, - napi_create_string_utf8( - env, hapModuleInfoCB.hapModuleInfo.reqCapabilities.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_element(env, jsArrayreqCapabilities, i, proValue)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "reqCapabilities", jsArrayreqCapabilities)); - - napi_value jsArraydeviceTypes = nullptr; - NAPI_CALL(env, napi_create_array(env, &jsArraydeviceTypes)); - for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.deviceTypes.size(); i++) { - proValue = nullptr; - NAPI_CALL(env, - napi_create_string_utf8( - env, hapModuleInfoCB.hapModuleInfo.deviceTypes.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); - NAPI_CALL(env, napi_set_element(env, jsArraydeviceTypes, i, proValue)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "deviceTypes", jsArraydeviceTypes)); - - napi_value abilityInfos = nullptr; - NAPI_CALL(env, napi_create_array(env, &abilityInfos)); - for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.abilityInfos.size(); i++) { - napi_value abilityInfo = nullptr; - abilityInfo = WrapAbilityInfo(env, hapModuleInfoCB.hapModuleInfo.abilityInfos.at(i)); - NAPI_CALL(env, napi_set_element(env, abilityInfos, i, abilityInfo)); - } - NAPI_CALL(env, napi_set_named_property(env, result, "abilityInfos", abilityInfos)); - HILOG_INFO("%{public}s end.", __func__); - return result; -} - -void GetHapModuleInfoExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_GetHapModuleInfo, worker pool thread execute."); - HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; - if (hapModuleInfoCB == nullptr) { - HILOG_ERROR("NAPI_GetHapModuleInfo, hapModuleInfoCB == nullptr"); - return; - } - - hapModuleInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (hapModuleInfoCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetHapModuleInfo, ability == nullptr"); - hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - if (!CheckAbilityType(&hapModuleInfoCB->cbBase)) { - HILOG_ERROR("NAPI_GetHapModuleInfo,wrong ability type"); - hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; - return; - } - - std::shared_ptr hapModuleInfoPtr = hapModuleInfoCB->cbBase.ability->GetHapModuleInfo(); - if (hapModuleInfoPtr != nullptr) { - SaveHapModuleInfo(hapModuleInfoCB->hapModuleInfo, *hapModuleInfoPtr); - } else { - hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; - } - HILOG_INFO("NAPI_GetHapModuleInfo, worker pool thread execute end."); -} - -void GetHapModuleInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete."); - HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value result[ARGS_TWO] = {nullptr}; - napi_value callResult = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, hapModuleInfoCB->cbBase.errCode); - if (hapModuleInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapHapModuleInfo(env, *hapModuleInfoCB); - } else { - result[PARAM1] = WrapUndefinedToJS(env); - } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, hapModuleInfoCB->cbBase.cbInfo.callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - - if (hapModuleInfoCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, hapModuleInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); - delete hapModuleInfoCB; - hapModuleInfoCB = nullptr; - HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete end."); -} - -void GetHapModuleInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete."); - HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; - napi_value result = nullptr; - if (hapModuleInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapHapModuleInfo(env, *hapModuleInfoCB); - napi_resolve_deferred(env, hapModuleInfoCB->cbBase.deferred, result); - } else { - result = GetCallbackErrorValue(env, hapModuleInfoCB->cbBase.errCode); - napi_reject_deferred(env, hapModuleInfoCB->cbBase.deferred, result); - } - - napi_delete_async_work(env, hapModuleInfoCB->cbBase.asyncWork); - delete hapModuleInfoCB; - hapModuleInfoCB = nullptr; - HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete end."); -} - -/** - * @brief GetHapModuleInfo Async. - * - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * @param argcPromise Asynchronous data processing. - * @param hapModuleInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetHapModuleInfoAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, HapModuleInfoCB *hapModuleInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || hapModuleInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &hapModuleInfoCB->cbBase.cbInfo.callback)); - } - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetHapModuleInfoExecuteCB, - GetHapModuleInfoAsyncCompleteCB, - (void *)hapModuleInfoCB, - &hapModuleInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); - napi_value result = nullptr; - NAPI_CALL(env, napi_get_null(env, &result)); - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return result; -} - -/** - * @brief GetHapModuleInfo Promise. - * - * @param env The environment that the Node-API call is invoked under. - * @param hapModuleInfoCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetHapModuleInfoPromise(napi_env env, HapModuleInfoCB *hapModuleInfoCB) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (hapModuleInfoCB == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - hapModuleInfoCB->cbBase.deferred = deferred; - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - GetHapModuleInfoExecuteCB, - GetHapModuleInfoPromiseCompleteCB, - (void *)hapModuleInfoCB, - &hapModuleInfoCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); - HILOG_INFO("%{public}s, promise end.", __func__); - return promise; -} - -napi_value GetHapModuleInfoWrap(napi_env env, napi_callback_info info, HapModuleInfoCB *hapModuleInfoCB) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (hapModuleInfoCB == nullptr) { - HILOG_ERROR("%{public}s, hapModuleInfoCB == nullptr.", __func__); - return nullptr; - } - - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (argcAsync > argcPromise) { - ret = GetHapModuleInfoAsync(env, args, argcAsync, argcPromise, hapModuleInfoCB); - } else { - ret = GetHapModuleInfoPromise(env, hapModuleInfoCB); - } - HILOG_INFO("%{public}s, asyncCallback end.", __func__); - return ret; -} + NAPI_CALL(env, napi_create_int32(env, abilityInfo.backgroundModes, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "backgroundModes", proValue)); -/** - * @brief Obtains the HapModuleInfo object of the application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) -{ - HILOG_INFO("%{public}s called.", __func__); - HapModuleInfoCB *hapModuleInfoCB = CreateHapModuleInfoCBInfo(env); - if (hapModuleInfoCB == nullptr) { - return WrapVoidToJS(env); - } + NAPI_CALL(env, napi_create_int32(env, abilityInfo.subType, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "subType", proValue)); - hapModuleInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - hapModuleInfoCB->cbBase.abilityType = abilityType; - napi_value ret = GetHapModuleInfoWrap(env, info, hapModuleInfoCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullptr", __func__); - if (hapModuleInfoCB != nullptr) { - delete hapModuleInfoCB; - hapModuleInfoCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} + NAPI_CALL(env, napi_get_boolean(env, abilityInfo.isVisible, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "isVisible", proValue)); -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to ProcessNameCB on success, nullptr on failure. - */ -ProcessNameCB *CreateProcessNameCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); + NAPI_CALL(env, napi_get_boolean(env, abilityInfo.formEnabled, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "formEnabled", proValue)); - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + napi_value jsArrayPermissions = nullptr; + NAPI_CALL(env, napi_create_array(env, &jsArrayPermissions)); + for (size_t i = 0; i < abilityInfo.permissions.size(); i++) { + proValue = nullptr; + NAPI_CALL( + env, napi_create_string_utf8(env, abilityInfo.permissions.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_element(env, jsArrayPermissions, i, proValue)); + } + NAPI_CALL(env, napi_set_named_property(env, result, "permissions", jsArrayPermissions)); - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + napi_value jsArrayDeviceCapabilities = nullptr; + NAPI_CALL(env, napi_create_array(env, &jsArrayDeviceCapabilities)); + for (size_t i = 0; i < abilityInfo.deviceCapabilities.size(); i++) { + proValue = nullptr; + NAPI_CALL(env, + napi_create_string_utf8(env, abilityInfo.deviceCapabilities.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_element(env, jsArrayDeviceCapabilities, i, proValue)); + } + NAPI_CALL(env, napi_set_named_property(env, result, "deviceCapabilities", jsArrayDeviceCapabilities)); - ProcessNameCB *processNameCB = new (std::nothrow) ProcessNameCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (processNameCB == nullptr) { - HILOG_ERROR("%{public}s, processNameCB == nullptr.", __func__); + napi_value jsArrayDeviceTypes = nullptr; + NAPI_CALL(env, napi_create_array(env, &jsArrayDeviceTypes)); + for (size_t i = 0; i < abilityInfo.deviceTypes.size(); i++) { + proValue = nullptr; + NAPI_CALL( + env, napi_create_string_utf8(env, abilityInfo.deviceTypes.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_element(env, jsArrayDeviceTypes, i, proValue)); } + NAPI_CALL(env, napi_set_named_property(env, result, "deviceTypes", jsArrayDeviceTypes)); + + napi_value appInfo = nullptr; + appInfo = WrapAppInfo(env, abilityInfo.appInfo); + NAPI_CALL(env, napi_set_named_property(env, result, "applicationInfo", appInfo)); HILOG_INFO("%{public}s end.", __func__); - return processNameCB; + return result; } /** - * @brief GetProcessName asynchronous processing function. + * @brief GetAbilityInfo asynchronous processing function. * * @param env The environment that the Node-API call is invoked under. * @param data Point to asynchronous processing of data. */ -void GetProcessNameExecuteCB(napi_env env, void *data) +void GetAbilityInfoExecuteCB(napi_env env, void *data) { - HILOG_INFO("NAPI_GetProcessName, worker pool thread execute."); - ProcessNameCB *processNameCB = (ProcessNameCB *)data; - if (processNameCB == nullptr) { - HILOG_ERROR("NAPI_GetProcessName, processNameCB == nullptr"); + HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute."); + AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; + if (abilityInfoCB == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo, abilityInfoCB == nullptr"); return; } - processNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (processNameCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetProcessName, ability == nullptr"); - processNameCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + abilityInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (abilityInfoCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetApplicationInfo, ability == nullptr"); + abilityInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; return; } - if (!CheckAbilityType(&processNameCB->cbBase)) { - HILOG_ERROR("NAPI_GetProcessName,wrong ability type"); - processNameCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; + if (!CheckAbilityType(&abilityInfoCB->cbBase)) { + HILOG_ERROR("NAPI_GetApplicationInfo,wrong ability type"); + abilityInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; return; } - processNameCB->processName = processNameCB->cbBase.ability->GetProcessName(); - HILOG_INFO("NAPI_GetProcessName, worker pool thread execute end."); -} - -napi_value WrapProcessName(napi_env env, ProcessNameCB *processNameCB) -{ - HILOG_INFO("%{public}s, called.", __func__); - if (processNameCB == nullptr) { - HILOG_ERROR("%{public}s, Invalid param(processNameCB == nullptr)", __func__); - return nullptr; + std::shared_ptr abilityInfoPtr = abilityInfoCB->cbBase.ability->GetAbilityInfo(); + if (abilityInfoPtr != nullptr) { + SaveAbilityInfo(abilityInfoCB->abilityInfo, *abilityInfoPtr); + } else { + abilityInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; } - napi_value result = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, processNameCB->processName.c_str(), NAPI_AUTO_LENGTH, &result)); - HILOG_INFO("%{public}s, end.", __func__); - return result; + HILOG_INFO("NAPI_GetApplicationInfo, worker pool thread execute end."); } /** @@ -2409,31 +782,31 @@ napi_value WrapProcessName(napi_env env, ProcessNameCB *processNameCB) * @param env The environment that the Node-API call is invoked under. * @param data Point to asynchronous processing of data. */ -void GetProcessNameAsyncCompleteCB(napi_env env, napi_status status, void *data) +void GetAbilityInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_GetProcessName, main event thread complete."); - ProcessNameCB *processNameCB = (ProcessNameCB *)data; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); + AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; napi_value callback = nullptr; napi_value undefined = nullptr; napi_value result[ARGS_TWO] = {nullptr}; napi_value callResult = nullptr; NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, processNameCB->cbBase.errCode); - if (processNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapProcessName(env, processNameCB); + result[PARAM0] = GetCallbackErrorValue(env, abilityInfoCB->cbBase.errCode); + if (abilityInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapAbilityInfo(env, abilityInfoCB->abilityInfo); } else { result[PARAM1] = WrapUndefinedToJS(env); } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, processNameCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, abilityInfoCB->cbBase.cbInfo.callback, &callback)); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - if (processNameCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, processNameCB->cbBase.cbInfo.callback)); + if (abilityInfoCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, abilityInfoCB->cbBase.cbInfo.callback)); } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, processNameCB->cbBase.asyncWork)); - delete processNameCB; - processNameCB = nullptr; - HILOG_INFO("NAPI_GetProcessName, main event thread complete end."); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, abilityInfoCB->cbBase.asyncWork)); + delete abilityInfoCB; + abilityInfoCB = nullptr; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); } /** @@ -2442,40 +815,40 @@ void GetProcessNameAsyncCompleteCB(napi_env env, napi_status status, void *data) * @param env The environment that the Node-API call is invoked under. * @param data Point to asynchronous processing of data. */ -void GetProcessNamePromiseCompleteCB(napi_env env, napi_status status, void *data) +void GetAbilityInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_GetProcessName, main event thread complete."); - ProcessNameCB *processNameCB = (ProcessNameCB *)data; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete."); + AbilityInfoCB *abilityInfoCB = (AbilityInfoCB *)data; napi_value result = nullptr; - if (processNameCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapProcessName(env, processNameCB); - napi_resolve_deferred(env, processNameCB->cbBase.deferred, result); + if (abilityInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapAbilityInfo(env, abilityInfoCB->abilityInfo); + napi_resolve_deferred(env, abilityInfoCB->cbBase.deferred, result); } else { - result = GetCallbackErrorValue(env, processNameCB->cbBase.errCode); - napi_reject_deferred(env, processNameCB->cbBase.deferred, result); + result = GetCallbackErrorValue(env, abilityInfoCB->cbBase.errCode); + napi_reject_deferred(env, abilityInfoCB->cbBase.deferred, result); } - napi_delete_async_work(env, processNameCB->cbBase.asyncWork); - delete processNameCB; - processNameCB = nullptr; - HILOG_INFO("NAPI_GetProcessName, main event thread complete end."); + napi_delete_async_work(env, abilityInfoCB->cbBase.asyncWork); + delete abilityInfoCB; + abilityInfoCB = nullptr; + HILOG_INFO("NAPI_GetApplicationInfo, main event thread complete end."); } /** - * @brief GetProcessName Async. + * @brief GetAbilityInfo Async. * * @param env The environment that the Node-API call is invoked under. * @param args Indicates the arguments passed into the callback. * @param argcPromise Asynchronous data processing. - * @param ProcessNameCB Process data asynchronously. + * @param abilityInfoCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetProcessNameAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, ProcessNameCB *processNameCB) +napi_value GetAbilityInfoAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, AbilityInfoCB *abilityInfoCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || processNameCB == nullptr) { + if (args == nullptr || abilityInfoCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -2485,17 +858,17 @@ napi_value GetProcessNameAsync( napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &processNameCB->cbBase.cbInfo.callback)); + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &abilityInfoCB->cbBase.cbInfo.callback)); } NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetProcessNameExecuteCB, - GetProcessNameAsyncCompleteCB, - (void *)processNameCB, - &processNameCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, processNameCB->cbBase.asyncWork)); + GetAbilityInfoExecuteCB, + GetAbilityInfoAsyncCompleteCB, + (void *)abilityInfoCB, + &abilityInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, abilityInfoCB->cbBase.asyncWork)); napi_value result = nullptr; NAPI_CALL(env, napi_get_null(env, &result)); HILOG_INFO("%{public}s, asyncCallback end.", __func__); @@ -2503,17 +876,17 @@ napi_value GetProcessNameAsync( } /** - * @brief GetProcessName Promise. + * @brief GetAbilityInfo Promise. * * @param env The environment that the Node-API call is invoked under. - * @param ProcessNameCB Process data asynchronously. + * @param abilityInfoCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetProcessNamePromise(napi_env env, ProcessNameCB *processNameCB) +napi_value GetAbilityInfoPromise(napi_env env, AbilityInfoCB *abilityInfoCB) { HILOG_INFO("%{public}s, promise.", __func__); - if (processNameCB == nullptr) { + if (abilityInfoCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -2522,34 +895,34 @@ napi_value GetProcessNamePromise(napi_env env, ProcessNameCB *processNameCB) napi_deferred deferred; napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - processNameCB->cbBase.deferred = deferred; + abilityInfoCB->cbBase.deferred = deferred; NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetProcessNameExecuteCB, - GetProcessNamePromiseCompleteCB, - (void *)processNameCB, - &processNameCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, processNameCB->cbBase.asyncWork)); + GetAbilityInfoExecuteCB, + GetAbilityInfoPromiseCompleteCB, + (void *)abilityInfoCB, + &abilityInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, abilityInfoCB->cbBase.asyncWork)); HILOG_INFO("%{public}s, promise end.", __func__); return promise; } /** - * @brief GetProcessName processing function. + * @brief GetAbilityInfo processing function. * * @param env The environment that the Node-API call is invoked under. - * @param ProcessNameCB Process data asynchronously. + * @param abilityInfoCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetProcessNameWrap(napi_env env, napi_callback_info info, ProcessNameCB *processNameCB) +napi_value GetAbilityInfoWrap(napi_env env, napi_callback_info info, AbilityInfoCB *abilityInfoCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (processNameCB == nullptr) { - HILOG_ERROR("%{public}s, processNameCB == nullptr.", __func__); + if (abilityInfoCB == nullptr) { + HILOG_ERROR("%{public}s, abilityInfoCB == nullptr.", __func__); return nullptr; } @@ -2566,194 +939,285 @@ napi_value GetProcessNameWrap(napi_env env, napi_callback_info info, ProcessName } if (argcAsync > argcPromise) { - ret = GetProcessNameAsync(env, args, argcAsync, argcPromise, processNameCB); + ret = GetAbilityInfoAsync(env, args, argcAsync, argcPromise, abilityInfoCB); } else { - ret = GetProcessNamePromise(env, processNameCB); + ret = GetAbilityInfoPromise(env, abilityInfoCB); } HILOG_INFO("%{public}s, asyncCallback end.", __func__); return ret; } /** - * @brief Obtains the name of the current process. + * @brief Obtains information about the current ability. * * @param env The environment that the Node-API call is invoked under. * @param info The callback info passed into the callback function. * * @return The return value from NAPI C++ to JS for the module. */ -napi_value NAPI_GetProcessNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +napi_value NAPI_GetAbilityInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) { HILOG_INFO("%{public}s called.", __func__); - ProcessNameCB *processNameCB = CreateProcessNameCBInfo(env); - if (processNameCB == nullptr) { + AbilityInfoCB *abilityInfoCB = CreateAbilityInfoCBInfo(env); + if (abilityInfoCB == nullptr) { return WrapVoidToJS(env); } - processNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - processNameCB->cbBase.abilityType = abilityType; - napi_value ret = GetProcessNameWrap(env, info, processNameCB); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullptr.", __func__); - if (processNameCB != nullptr) { - delete processNameCB; - processNameCB = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} + abilityInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + abilityInfoCB->cbBase.abilityType = abilityType; + napi_value ret = GetAbilityInfoWrap(env, info, abilityInfoCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s ret == nullptr", __func__); + if (abilityInfoCB != nullptr) { + delete abilityInfoCB; + abilityInfoCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s end.", __func__); + return ret; +} + +/** + * @brief Create asynchronous data. + * + * @param env The environment that the Node-API call is invoked under. + * + * @return Return a pointer to HapModuleInfoCB on success, nullptr on failure. + */ +HapModuleInfoCB *CreateHapModuleInfoCBInfo(napi_env env) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value global = nullptr; + NAPI_CALL(env, napi_get_global(env, &global)); + + napi_value abilityObj = nullptr; + NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + + Ability *ability = nullptr; + NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + + HapModuleInfoCB *hapModuleInfoCB = new (std::nothrow) HapModuleInfoCB{ + .cbBase.cbInfo.env = env, + .cbBase.asyncWork = nullptr, + .cbBase.deferred = nullptr, + .cbBase.ability = ability, + }; + if (hapModuleInfoCB == nullptr) { + HILOG_ERROR("%{public}s, hapModuleInfoCB == nullptr.", __func__); + } + HILOG_INFO("%{public}s end.", __func__); + return hapModuleInfoCB; +} + +void SaveHapModuleInfo(HapModuleInfo_ &hapModuleInfo, const HapModuleInfo &hapModuleInfoOrg) +{ + HILOG_INFO("%{public}s called.", __func__); + hapModuleInfo.name = hapModuleInfoOrg.name; + hapModuleInfo.description = hapModuleInfoOrg.description; + hapModuleInfo.icon = hapModuleInfoOrg.iconPath; + hapModuleInfo.label = hapModuleInfoOrg.label; + hapModuleInfo.backgroundImg = hapModuleInfoOrg.backgroundImg; + hapModuleInfo.moduleName = hapModuleInfoOrg.moduleName; + hapModuleInfo.supportedModes = hapModuleInfoOrg.supportedModes; + hapModuleInfo.descriptionId = 0; // no data + hapModuleInfo.labelId = 0; // no data + hapModuleInfo.iconId = 0; // no data + hapModuleInfo.mainAbilityName = ""; // no data + hapModuleInfo.installationFree = false; // no data + + for (size_t i = 0; i < hapModuleInfoOrg.reqCapabilities.size(); i++) { + hapModuleInfo.reqCapabilities.emplace_back(hapModuleInfoOrg.reqCapabilities.at(i)); + } + + for (size_t i = 0; i < hapModuleInfoOrg.deviceTypes.size(); i++) { + hapModuleInfo.deviceTypes.emplace_back(hapModuleInfoOrg.deviceTypes.at(i)); + } + + for (size_t i = 0; i < hapModuleInfoOrg.abilityInfos.size(); i++) { + AbilityInfo_ abilityInfo; + SaveAbilityInfo(abilityInfo, hapModuleInfoOrg.abilityInfos.at(i)); + hapModuleInfo.abilityInfos.emplace_back(abilityInfo); + } + HILOG_INFO("%{public}s end.", __func__); +} + +napi_value WrapHapModuleInfo(napi_env env, const HapModuleInfoCB &hapModuleInfoCB) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value result = nullptr; + napi_value proValue = nullptr; + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL( + env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.name.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "name", proValue)); + + NAPI_CALL(env, + napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.description.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "description", proValue)); + + NAPI_CALL( + env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.icon.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "icon", proValue)); + + NAPI_CALL( + env, napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.label.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "label", proValue)); + + NAPI_CALL(env, + napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.backgroundImg.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "backgroundImg", proValue)); + + NAPI_CALL(env, + napi_create_string_utf8(env, hapModuleInfoCB.hapModuleInfo.moduleName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "moduleName", proValue)); + + NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.supportedModes, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "supportedModes", proValue)); + + NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.descriptionId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "descriptionId", proValue)); + + NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.labelId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "labelId", proValue)); + + NAPI_CALL(env, napi_create_int32(env, hapModuleInfoCB.hapModuleInfo.iconId, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "iconId", proValue)); -/** - * @brief Create asynchronous data. - * - * @param env The environment that the Node-API call is invoked under. - * - * @return Return a pointer to CallingBundleCB on success, nullptr on failure. - */ -CallingBundleCB *CreateCallingBundleCBInfo(napi_env env) -{ - HILOG_INFO("%{public}s called.", __func__); - napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); + NAPI_CALL(env, + napi_create_string_utf8( + env, hapModuleInfoCB.hapModuleInfo.mainAbilityName.c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "mainAbilityName", proValue)); - napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + NAPI_CALL(env, napi_get_boolean(env, hapModuleInfoCB.hapModuleInfo.installationFree, &proValue)); + NAPI_CALL(env, napi_set_named_property(env, result, "installationFree", proValue)); - Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + napi_value jsArrayreqCapabilities = nullptr; + NAPI_CALL(env, napi_create_array(env, &jsArrayreqCapabilities)); + for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.reqCapabilities.size(); i++) { + proValue = nullptr; + NAPI_CALL(env, + napi_create_string_utf8( + env, hapModuleInfoCB.hapModuleInfo.reqCapabilities.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_element(env, jsArrayreqCapabilities, i, proValue)); + } + NAPI_CALL(env, napi_set_named_property(env, result, "reqCapabilities", jsArrayreqCapabilities)); - CallingBundleCB *callingBundleCB = new (std::nothrow) CallingBundleCB{ - .cbBase.cbInfo.env = env, - .cbBase.asyncWork = nullptr, - .cbBase.deferred = nullptr, - .cbBase.ability = ability, - }; - if (callingBundleCB == nullptr) { - HILOG_ERROR("%{public}s, callingBundleCB == nullptr.", __func__); + napi_value jsArraydeviceTypes = nullptr; + NAPI_CALL(env, napi_create_array(env, &jsArraydeviceTypes)); + for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.deviceTypes.size(); i++) { + proValue = nullptr; + NAPI_CALL(env, + napi_create_string_utf8( + env, hapModuleInfoCB.hapModuleInfo.deviceTypes.at(i).c_str(), NAPI_AUTO_LENGTH, &proValue)); + NAPI_CALL(env, napi_set_element(env, jsArraydeviceTypes, i, proValue)); + } + NAPI_CALL(env, napi_set_named_property(env, result, "deviceTypes", jsArraydeviceTypes)); + + napi_value abilityInfos = nullptr; + NAPI_CALL(env, napi_create_array(env, &abilityInfos)); + for (size_t i = 0; i < hapModuleInfoCB.hapModuleInfo.abilityInfos.size(); i++) { + napi_value abilityInfo = nullptr; + abilityInfo = WrapAbilityInfo(env, hapModuleInfoCB.hapModuleInfo.abilityInfos.at(i)); + NAPI_CALL(env, napi_set_element(env, abilityInfos, i, abilityInfo)); } + NAPI_CALL(env, napi_set_named_property(env, result, "abilityInfos", abilityInfos)); HILOG_INFO("%{public}s end.", __func__); - return callingBundleCB; + return result; } -/** - * @brief GetCallingBundle asynchronous processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetCallingBundleExecuteCB(napi_env env, void *data) +void GetHapModuleInfoExecuteCB(napi_env env, void *data) { - HILOG_INFO("NAPI_GetCallingBundle, worker pool thread execute."); - CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; - if (callingBundleCB == nullptr) { - HILOG_ERROR("NAPI_GetCallingBundle, callingBundleCB == nullptr"); + HILOG_INFO("NAPI_GetHapModuleInfo, worker pool thread execute."); + HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; + if (hapModuleInfoCB == nullptr) { + HILOG_ERROR("NAPI_GetHapModuleInfo, hapModuleInfoCB == nullptr"); return; } - callingBundleCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - if (callingBundleCB->cbBase.ability == nullptr) { - HILOG_ERROR("NAPI_GetCallingBundle, ability == nullptr"); - callingBundleCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; + hapModuleInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + if (hapModuleInfoCB->cbBase.ability == nullptr) { + HILOG_ERROR("NAPI_GetHapModuleInfo, ability == nullptr"); + hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY; return; } - if (!CheckAbilityType(&callingBundleCB->cbBase)) { - HILOG_ERROR("NAPI_GetCallingBundle,wrong ability type"); - callingBundleCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; + if (!CheckAbilityType(&hapModuleInfoCB->cbBase)) { + HILOG_ERROR("NAPI_GetHapModuleInfo,wrong ability type"); + hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; return; } - callingBundleCB->callingBundleName = callingBundleCB->cbBase.ability->GetCallingBundle(); - HILOG_INFO("NAPI_GetCallingBundle, worker pool thread execute end."); -} -napi_value WrapCallingBundle(napi_env env, CallingBundleCB *callingBundleCB) -{ - HILOG_INFO("%{public}s, called.", __func__); - if (callingBundleCB == nullptr) { - HILOG_ERROR("%{public}s,Invalid param(callingBundleCB == nullptr)", __func__); - return nullptr; + std::shared_ptr hapModuleInfoPtr = hapModuleInfoCB->cbBase.ability->GetHapModuleInfo(); + if (hapModuleInfoPtr != nullptr) { + SaveHapModuleInfo(hapModuleInfoCB->hapModuleInfo, *hapModuleInfoPtr); + } else { + hapModuleInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID; } - napi_value result = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, callingBundleCB->callingBundleName.c_str(), NAPI_AUTO_LENGTH, &result)); - HILOG_INFO("%{public}s, end.", __func__); - return result; + HILOG_INFO("NAPI_GetHapModuleInfo, worker pool thread execute end."); } -/** - * @brief The callback at the end of the asynchronous callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetCallingBundleAsyncCompleteCB(napi_env env, napi_status status, void *data) +void GetHapModuleInfoAsyncCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_GetCallingBundle, main event thread complete."); - CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; + HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete."); + HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; napi_value callback = nullptr; napi_value undefined = nullptr; napi_value result[ARGS_TWO] = {nullptr}; napi_value callResult = nullptr; NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - result[PARAM0] = GetCallbackErrorValue(env, callingBundleCB->cbBase.errCode); - if (callingBundleCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result[PARAM1] = WrapCallingBundle(env, callingBundleCB); + result[PARAM0] = GetCallbackErrorValue(env, hapModuleInfoCB->cbBase.errCode); + if (hapModuleInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result[PARAM1] = WrapHapModuleInfo(env, *hapModuleInfoCB); } else { result[PARAM1] = WrapUndefinedToJS(env); } - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, callingBundleCB->cbBase.cbInfo.callback, &callback)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, hapModuleInfoCB->cbBase.cbInfo.callback, &callback)); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); - if (callingBundleCB->cbBase.cbInfo.callback != nullptr) { - NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, callingBundleCB->cbBase.cbInfo.callback)); + if (hapModuleInfoCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, hapModuleInfoCB->cbBase.cbInfo.callback)); } - NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, callingBundleCB->cbBase.asyncWork)); - delete callingBundleCB; - callingBundleCB = nullptr; - HILOG_INFO("NAPI_GetCallingBundle, main event thread complete end."); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); + delete hapModuleInfoCB; + hapModuleInfoCB = nullptr; + HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete end."); } -/** - * @brief The callback at the end of the Promise callback. - * - * @param env The environment that the Node-API call is invoked under. - * @param data Point to asynchronous processing of data. - */ -void GetCallingBundlePromiseCompleteCB(napi_env env, napi_status status, void *data) +void GetHapModuleInfoPromiseCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("NAPI_GetCallingBundle, main event thread complete."); - CallingBundleCB *callingBundleCB = (CallingBundleCB *)data; + HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete."); + HapModuleInfoCB *hapModuleInfoCB = (HapModuleInfoCB *)data; napi_value result = nullptr; - if (callingBundleCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { - result = WrapCallingBundle(env, callingBundleCB); - napi_resolve_deferred(env, callingBundleCB->cbBase.deferred, result); + if (hapModuleInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) { + result = WrapHapModuleInfo(env, *hapModuleInfoCB); + napi_resolve_deferred(env, hapModuleInfoCB->cbBase.deferred, result); } else { - result = GetCallbackErrorValue(env, callingBundleCB->cbBase.errCode); - napi_reject_deferred(env, callingBundleCB->cbBase.deferred, result); + result = GetCallbackErrorValue(env, hapModuleInfoCB->cbBase.errCode); + napi_reject_deferred(env, hapModuleInfoCB->cbBase.deferred, result); } - napi_delete_async_work(env, callingBundleCB->cbBase.asyncWork); - delete callingBundleCB; - callingBundleCB = nullptr; - HILOG_INFO("NAPI_GetCallingBundle, main event thread complete end."); + napi_delete_async_work(env, hapModuleInfoCB->cbBase.asyncWork); + delete hapModuleInfoCB; + hapModuleInfoCB = nullptr; + HILOG_INFO("NAPI_GetHapModuleInfo, main event thread complete end."); } /** - * @brief GetCallingBundle Async. + * @brief GetHapModuleInfo Async. * * @param env The environment that the Node-API call is invoked under. * @param args Indicates the arguments passed into the callback. * @param argcPromise Asynchronous data processing. - * @param CallingBundleCB Process data asynchronously. + * @param hapModuleInfoCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetCallingBundleAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, CallingBundleCB *callingBundleCB) +napi_value GetHapModuleInfoAsync( + napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, HapModuleInfoCB *hapModuleInfoCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || callingBundleCB == nullptr) { + if (args == nullptr || hapModuleInfoCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -2763,17 +1227,17 @@ napi_value GetCallingBundleAsync( napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &callingBundleCB->cbBase.cbInfo.callback)); + NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &hapModuleInfoCB->cbBase.cbInfo.callback)); } NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetCallingBundleExecuteCB, - GetCallingBundleAsyncCompleteCB, - (void *)callingBundleCB, - &callingBundleCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, callingBundleCB->cbBase.asyncWork)); + GetHapModuleInfoExecuteCB, + GetHapModuleInfoAsyncCompleteCB, + (void *)hapModuleInfoCB, + &hapModuleInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); napi_value result = nullptr; NAPI_CALL(env, napi_get_null(env, &result)); HILOG_INFO("%{public}s, asyncCallback end.", __func__); @@ -2781,17 +1245,17 @@ napi_value GetCallingBundleAsync( } /** - * @brief GetCallingBundle Promise. + * @brief GetHapModuleInfo Promise. * * @param env The environment that the Node-API call is invoked under. - * @param CallingBundleCB Process data asynchronously. + * @param hapModuleInfoCB Process data asynchronously. * * @return Return JS data successfully, otherwise return nullptr. */ -napi_value GetCallingBundlePromise(napi_env env, CallingBundleCB *callingBundleCB) +napi_value GetHapModuleInfoPromise(napi_env env, HapModuleInfoCB *hapModuleInfoCB) { HILOG_INFO("%{public}s, promise.", __func__); - if (callingBundleCB == nullptr) { + if (hapModuleInfoCB == nullptr) { HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } @@ -2800,34 +1264,26 @@ napi_value GetCallingBundlePromise(napi_env env, CallingBundleCB *callingBundleC napi_deferred deferred; napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - callingBundleCB->cbBase.deferred = deferred; + hapModuleInfoCB->cbBase.deferred = deferred; NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, - GetCallingBundleExecuteCB, - GetCallingBundlePromiseCompleteCB, - (void *)callingBundleCB, - &callingBundleCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, callingBundleCB->cbBase.asyncWork)); + GetHapModuleInfoExecuteCB, + GetHapModuleInfoPromiseCompleteCB, + (void *)hapModuleInfoCB, + &hapModuleInfoCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, hapModuleInfoCB->cbBase.asyncWork)); HILOG_INFO("%{public}s, promise end.", __func__); return promise; } -/** - * @brief GetCallingBundle processing function. - * - * @param env The environment that the Node-API call is invoked under. - * @param CallingBundleCB Process data asynchronously. - * - * @return Return JS data successfully, otherwise return nullptr. - */ -napi_value GetCallingBundleWrap(napi_env env, napi_callback_info info, CallingBundleCB *callingBundleCB) +napi_value GetHapModuleInfoWrap(napi_env env, napi_callback_info info, HapModuleInfoCB *hapModuleInfoCB) { HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (callingBundleCB == nullptr) { - HILOG_ERROR("%{public}s, callingBundleCB == nullptr.", __func__); + if (hapModuleInfoCB == nullptr) { + HILOG_ERROR("%{public}s, hapModuleInfoCB == nullptr.", __func__); return nullptr; } @@ -2844,38 +1300,38 @@ napi_value GetCallingBundleWrap(napi_env env, napi_callback_info info, CallingBu } if (argcAsync > argcPromise) { - ret = GetCallingBundleAsync(env, args, argcAsync, argcPromise, callingBundleCB); + ret = GetHapModuleInfoAsync(env, args, argcAsync, argcPromise, hapModuleInfoCB); } else { - ret = GetCallingBundlePromise(env, callingBundleCB); + ret = GetHapModuleInfoPromise(env, hapModuleInfoCB); } HILOG_INFO("%{public}s, asyncCallback end.", __func__); return ret; } /** - * @brief Obtains the bundle name of the ability that called the current ability. + * @brief Obtains the HapModuleInfo object of the application. * * @param env The environment that the Node-API call is invoked under. * @param info The callback info passed into the callback function. * * @return The return value from NAPI C++ to JS for the module. */ -napi_value NAPI_GetCallingBundleCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType) { HILOG_INFO("%{public}s called.", __func__); - CallingBundleCB *calloingBundleCB = CreateCallingBundleCBInfo(env); - if (calloingBundleCB == nullptr) { + HapModuleInfoCB *hapModuleInfoCB = CreateHapModuleInfoCBInfo(env); + if (hapModuleInfoCB == nullptr) { return WrapVoidToJS(env); } - calloingBundleCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - calloingBundleCB->cbBase.abilityType = abilityType; - napi_value ret = GetCallingBundleWrap(env, info, calloingBundleCB); + hapModuleInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + hapModuleInfoCB->cbBase.abilityType = abilityType; + napi_value ret = GetHapModuleInfoWrap(env, info, hapModuleInfoCB); if (ret == nullptr) { HILOG_ERROR("%{public}s ret == nullptr", __func__); - if (calloingBundleCB != nullptr) { - delete calloingBundleCB; - calloingBundleCB = nullptr; + if (hapModuleInfoCB != nullptr) { + delete hapModuleInfoCB; + hapModuleInfoCB = nullptr; } ret = WrapVoidToJS(env); } @@ -3591,6 +2047,82 @@ napi_value NAPI_GetAbilityNameCommon(napi_env env, napi_callback_info info, Abil return ret; } +bool UnwrapAbilityStartSetting(napi_env env, napi_value param, AAFwk::AbilityStartSetting &setting) +{ + HILOG_INFO("%{public}s called.", __func__); + + if (!IsTypeForNapiValue(env, param, napi_object)) { + return false; + } + + napi_valuetype jsValueType = napi_undefined; + napi_value jsProNameList = nullptr; + uint32_t jsProCount = 0; + + NAPI_CALL_BASE(env, napi_get_property_names(env, param, &jsProNameList), false); + NAPI_CALL_BASE(env, napi_get_array_length(env, jsProNameList, &jsProCount), false); + HILOG_INFO("%{public}s called. Property size=%{public}d.", __func__, jsProCount); + + napi_value jsProName = nullptr; + napi_value jsProValue = nullptr; + for (uint32_t index = 0; index < jsProCount; index++) { + NAPI_CALL_BASE(env, napi_get_element(env, jsProNameList, index, &jsProName), false); + + std::string strProName = UnwrapStringFromJS(env, jsProName); + HILOG_INFO("%{public}s called. Property name=%{public}s.", __func__, strProName.c_str()); + NAPI_CALL_BASE(env, napi_get_named_property(env, param, strProName.c_str(), &jsProValue), false); + NAPI_CALL_BASE(env, napi_typeof(env, jsProValue, &jsValueType), false); + + switch (jsValueType) { + case napi_string: { + std::string natValue = UnwrapStringFromJS(env, jsProValue); + HILOG_INFO("%{public}s called. Property value=%{public}s.", __func__, natValue.c_str()); + setting.AddProperty(strProName, natValue); + break; + } + case napi_boolean: { + bool natValue = false; + NAPI_CALL_BASE(env, napi_get_value_bool(env, jsProValue, &natValue), false); + HILOG_INFO("%{public}s called. Property value=%{public}s.", __func__, natValue ? "true" : "false"); + setting.AddProperty(strProName, std::to_string(natValue)); + break; + } + case napi_number: { + int32_t natValue32 = 0; + double natValueDouble = 0.0; + bool isReadValue32 = false; + bool isReadDouble = false; + if (napi_get_value_int32(env, jsProValue, &natValue32) == napi_ok) { + HILOG_INFO("%{public}s called. Property value=%{public}d.", __func__, natValue32); + isReadValue32 = true; + } + + if (napi_get_value_double(env, jsProValue, &natValueDouble) == napi_ok) { + HILOG_INFO("%{public}s called. Property value=%{public}lf.", __func__, natValueDouble); + isReadDouble = true; + } + + if (isReadValue32 && isReadDouble) { + if (abs(natValueDouble - natValue32 * 1.0) > 0.0) { + setting.AddProperty(strProName, std::to_string(natValueDouble)); + } else { + setting.AddProperty(strProName, std::to_string(natValue32)); + } + } else if (isReadValue32) { + setting.AddProperty(strProName, std::to_string(natValue32)); + } else if (isReadDouble) { + setting.AddProperty(strProName, std::to_string(natValueDouble)); + } + break; + } + default: + break; + } + } + + return true; +} + /** * @brief Parse the parameters. * @@ -3623,6 +2155,9 @@ bool UnwrapParamForWant(napi_env env, napi_value args, AbilityType abilityType, napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object); if (jsSettingObj != nullptr) { param.setting = AbilityStartSetting::GetEmptySetting(); + if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) { + HILOG_ERROR("%{public}s, unwrap abilityStartSetting falied.", __func__); + } HILOG_INFO("%{public}s abilityStartSetting = %{public}p.", __func__, param.setting.get()); } @@ -3652,10 +2187,11 @@ void StartAbilityExecuteCB(napi_env env, void *data) } if (asyncCallbackInfo->param.setting == nullptr) { + HILOG_INFO("%{public}s param.setting == nullptr call StartAbility.", __func__); asyncCallbackInfo->ability->StartAbility(asyncCallbackInfo->param.want); } else { - asyncCallbackInfo->ability->StartAbility( - asyncCallbackInfo->param.want, *(asyncCallbackInfo->param.setting.get())); + HILOG_INFO("%{public}s param.setting != nullptr call StartAbility.", __func__); + asyncCallbackInfo->ability->StartAbility(asyncCallbackInfo->param.want, *(asyncCallbackInfo->param.setting)); } HILOG_INFO("%{public}s end.", __func__); } @@ -4503,31 +3039,8 @@ void NAPIAbilityConnection::OnAbilityConnectDone( ConnectAbilityCB *event = (ConnectAbilityCB *)work->data; napi_value result[ARGS_TWO] = {0}; result[PARAM0] = WrapElementName(event->cbBase.cbInfo.env, event->abilityConnectionCB.elementName); - // start open rpc lib - if (g_handle == nullptr) { - g_handle = dlopen(SHARED_LIBRARY_RPC, RTLD_LAZY); - if (g_handle == nullptr) { - HILOG_ERROR( - "%{public}s, dlopen failed %{public}s. %{public}s", __func__, SHARED_LIBRARY_RPC, dlerror()); - return; - } - } - - // get function - auto func = reinterpret_cast(dlsym(g_handle, FUNC_RPC_CREATE_JS_REMOTE_OBJECT)); - if (func == nullptr) { - HILOG_ERROR("%{public}s, dlsym failed %{public}s. %{public}s", - __func__, - FUNC_RPC_CREATE_JS_REMOTE_OBJECT, - dlerror()); - dlclose(g_handle); - g_handle = nullptr; - return; - } - - // transform native remoteObject to js remoteObject - napi_value jsRemoteObject = func(event->cbBase.cbInfo.env, event->abilityConnectionCB.connection); - + napi_value jsRemoteObject = + NAPI_ohos_rpc_CreateJsRemoteObject(event->cbBase.cbInfo.env, event->abilityConnectionCB.connection); result[PARAM1] = jsRemoteObject; napi_value callback = 0; @@ -4613,5 +3126,83 @@ void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementNam HILOG_INFO("%{public}s, end.", __func__); } +/** + * @brief AcquireDataAbilityHelper. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +{ + HILOG_INFO("%{public}s,called", __func__); + DataAbilityHelperCB *dataAbilityHelperCB = new (std::nothrow) DataAbilityHelperCB; + dataAbilityHelperCB->cbBase.cbInfo.env = env; + if (dataAbilityHelperCB == nullptr) { + HILOG_ERROR("%{public}s, dataAbilityHelperCB == nullptr", __func__); + return WrapVoidToJS(env); + } + + dataAbilityHelperCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + dataAbilityHelperCB->cbBase.abilityType = abilityType; + napi_value ret = AcquireDataAbilityHelperWrap(env, info, dataAbilityHelperCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s, ret == nullptr", __func__); + if (dataAbilityHelperCB != nullptr) { + delete dataAbilityHelperCB; + dataAbilityHelperCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("%{public}s,end", __func__); + return ret; +} + +/** + * @brief acquireDataAbilityHelper processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param dataAbilityHelperCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value AcquireDataAbilityHelperWrap(napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB) +{ + HILOG_INFO("%{public}s,called", __func__); + if (dataAbilityHelperCB == nullptr) { + HILOG_ERROR("%{public}s,dataAbilityHelperCB == nullptr", __func__); + return nullptr; + } + + size_t requireArgc = ARGS_ONE; + size_t argc = ARGS_ONE; + napi_value args[ARGS_ONE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + if (argc > requireArgc) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype != napi_string) { + HILOG_ERROR("%{public}s, Wrong argument type.", __func__); + return nullptr; + } + + if (!CheckAbilityType(&dataAbilityHelperCB->cbBase)) { + dataAbilityHelperCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID; + HILOG_ERROR("%{public}s ability type invalid.", __func__); + return nullptr; + } + + napi_value result = nullptr; + NAPI_CALL(env, napi_new_instance(env, g_dataAbilityHelper, 1, &args[PARAM0], &result)); + delete dataAbilityHelperCB; + dataAbilityHelperCB = nullptr; + HILOG_INFO("%{public}s,end", __func__); + return result; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h index fc37a2f470a..04ba9a6e399 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h @@ -27,35 +27,6 @@ const std::int32_t STR_MAX_SIZE = 128; napi_value *GetGlobalClassContext(void); void SaveAppInfo(AppInfo_ &appInfo, const ApplicationInfo &appInfoOrg); napi_value WrapAppInfo(napi_env env, const AppInfo_ &appInfo); -/** - * @brief Obtains information about the current application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetApplicationInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType); - -/** - * @brief Get bundle name. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetBundleNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType); - -/** - * @brief Obtains the process Info this application. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType); /** * @brief Obtains the type of this application. @@ -67,16 +38,6 @@ napi_value NAPI_GetProcessInfoCommon(napi_env env, napi_callback_info info, Abil */ napi_value NAPI_GetAppTypeCommon(napi_env env, napi_callback_info info, AbilityType abilityType); -/** - * @brief Obtains the elementName object of the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetElementNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType); - /** * @brief Obtains information about the current ability. * @@ -97,26 +58,6 @@ napi_value NAPI_GetAbilityInfoCommon(napi_env env, napi_callback_info info, Abil */ napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType); -/** - * @brief Obtains the name of the current process. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetProcessNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType); - -/** - * @brief Obtains the bundle name of the ability that called the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_GetCallingBundleCommon(napi_env env, napi_callback_info info, AbilityType abilityType); - /** * @brief Create asynchronous data. * @@ -184,7 +125,8 @@ napi_value NAPI_StopAbilityCommon(napi_env env, napi_callback_info info, Ability * * @return The return value from NAPI C++ to JS for the module. */ -napi_value GetContinueAbilityOptionsInfoCommon(const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info); +napi_value GetContinueAbilityOptionsInfoCommon( + const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info); /** * @brief Obtains the continue ability can reversible or not @@ -210,6 +152,8 @@ napi_value GetContinueAbilityOptionsReversible( napi_value GetContinueAbilityOptionsDeviceID( const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info); +bool UnwrapAbilityStartSetting(napi_env env, napi_value param, AAFwk::AbilityStartSetting &setting); + class NAPIAbilityConnection : public AAFwk::AbilityConnectionStub { public: void OnAbilityConnectDone( @@ -245,6 +189,27 @@ napi_value NAPI_ConnectAbilityCommon(napi_env env, napi_callback_info info, Abil */ napi_value NAPI_DisConnectAbilityCommon(napi_env env, napi_callback_info info, AbilityType abilityType); +/** + * @brief acquireDataAbilityHelper processing function. + * + * @param env The environment that the Node-API call is invoked under. + * @param dataAbilityHelperCB Process data asynchronously. + * + * @return Return JS data successfully, otherwise return nullptr. + */ +napi_value AcquireDataAbilityHelperWrap( + napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB); + +/** + * @brief AcquireDataAbilityHelper. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType); + struct ConnecttionKey { Want want; int64_t id; diff --git a/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp b/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp index 0150609d7e2..2de3dd1ea82 100755 --- a/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp +++ b/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp @@ -26,24 +26,6 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace AppExecFwk { -napi_value NAPI_PAGetApplicationInfo(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetApplicationInfoCommon(env, info, AbilityType::UNKNOWN); -} - -napi_value NAPI_PAGetBundleName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetBundleNameCommon(env, info, AbilityType::UNKNOWN); -} - -napi_value NAPI_PAGetProcessInfo(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetProcessInfoCommon(env, info, AbilityType::UNKNOWN); -} - /** * @brief Obtains the type of this application. * @@ -58,20 +40,6 @@ napi_value NAPI_PAGetAppType(napi_env env, napi_callback_info info) return NAPI_GetAppTypeCommon(env, info, AbilityType::UNKNOWN); } -/** - * @brief Obtains the elementName object of the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_PAGetElementName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetElementNameCommon(env, info, AbilityType::UNKNOWN); -} - /** * @brief Obtains information about the current ability. * @@ -100,34 +68,6 @@ napi_value NAPI_PAGetHapModuleInfo(napi_env env, napi_callback_info info) return NAPI_GetHapModuleInfoCommon(env, info, AbilityType::UNKNOWN); } -/** - * @brief Obtains the name of the current process. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_PAProcessName(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetProcessNameCommon(env, info, AbilityType::UNKNOWN); -} - -/** - * @brief Obtains the bundle name of the ability that called the current ability. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_PAGetCallingBundle(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - return NAPI_GetCallingBundleCommon(env, info, AbilityType::UNKNOWN); -} - /** * @brief Get context. * @@ -226,6 +166,20 @@ napi_value NAPI_PADisConnectAbility(napi_env env, napi_callback_info info) return NAPI_DisConnectAbilityCommon(env, info, AbilityType::UNKNOWN); } +/** + * @brief FeatureAbility NAPI method : acquireDataAbilityHelper. + * + * @param env The environment that the Node-API call is invoked under. + * @param info The callback info passed into the callback function. + * + * @return The return value from NAPI C++ to JS for the module. + */ +napi_value NAPI_PAAcquireDataAbilityHelper(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s,called", __func__); + return NAPI_AcquireDataAbilityHelperCommon(env, info, AbilityType::UNKNOWN); +} + /** * @brief ParticleAbility NAPI module registration. * @@ -238,15 +192,9 @@ napi_value ParticleAbilityInit(napi_env env, napi_value exports) { HILOG_INFO("%{public}s called.", __func__); napi_property_descriptor properties[] = { - DECLARE_NAPI_FUNCTION("getApplicationInfo", NAPI_PAGetApplicationInfo), - DECLARE_NAPI_FUNCTION("getBundleName", NAPI_PAGetBundleName), - DECLARE_NAPI_FUNCTION("getProcessInfo", NAPI_PAGetProcessInfo), DECLARE_NAPI_FUNCTION("getAppType", NAPI_PAGetAppType), - DECLARE_NAPI_FUNCTION("getElementName", NAPI_PAGetElementName), DECLARE_NAPI_FUNCTION("getAbilityInfo", NAPI_PAGetAbilityInfo), DECLARE_NAPI_FUNCTION("getHapModuleInfo", NAPI_PAGetHapModuleInfo), - DECLARE_NAPI_FUNCTION("getProcessName", NAPI_PAProcessName), - DECLARE_NAPI_FUNCTION("getCallingBundle", NAPI_PAGetCallingBundle), DECLARE_NAPI_FUNCTION("getContext", NAPI_PAGetContext), DECLARE_NAPI_FUNCTION("getWant", NAPI_PAGetWant), DECLARE_NAPI_FUNCTION("getAbilityName", NAPI_PAGetAbilityName), @@ -254,6 +202,7 @@ napi_value ParticleAbilityInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("stopAbility", NAPI_PAStopAbility), DECLARE_NAPI_FUNCTION("connectAbility", NAPI_PAConnectAbility), DECLARE_NAPI_FUNCTION("disconnectAbility", NAPI_PADisConnectAbility), + DECLARE_NAPI_FUNCTION("acquireDataAbilityHelper", NAPI_PAAcquireDataAbilityHelper), }; napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties); diff --git a/ohos.build b/ohos.build old mode 100644 new mode 100755 index 3bb586dd004..0f802dabcd7 --- a/ohos.build +++ b/ohos.build @@ -81,7 +81,8 @@ "//foundation/aafwk/standard/services:unittest", "//foundation/aafwk/standard/tools/test:systemtest", "//foundation/aafwk/standard/tools/test:moduletest", - "//foundation/aafwk/standard/tools/test:unittest" + "//foundation/aafwk/standard/tools/test:unittest", + "//foundation/aafwk/standard/tools/zip/test:unittest" ] } }, diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 5c39f87a528..ee5f4f8def2 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -17,13 +17,18 @@ import("//foundation/aafwk/standard/services/abilitymgr/abilitymgr.gni") EVENT_DIR = "//base/notification/ces_standard/" group("abilityms_target") { - deps = [ ":abilityms" ] + deps = [ + ":abilityms", + ":ams_service_config", + ] } group("unittest") { testonly = true - deps = [ "test:unittest" ] + deps = [ + "test:unittest", + ] } config("abilityms_config") { @@ -81,3 +86,15 @@ ohos_shared_library("abilityms") { subsystem_name = "aafwk" part_name = "aafwk_standard" } + +ohos_prebuilt_etc("ams_service_config.json") { + source = "//foundation/aafwk/standard/services/abilitymgr/resource/ams_service_config.json" + subsystem_name = "aafwk" + part_name = "aafwk_standard" +} + +group("ams_service_config") { + deps = [ + ":ams_service_config.json", + ] +} diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 6d46d2ecc91..fe5beb7822a 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -63,4 +63,5 @@ abilityms_files = [ "${services_path}/abilitymgr/src/aafwk_dummy_configuration.cpp", "${services_path}/abilitymgr/src/configuration_holder.cpp", "${services_path}/abilitymgr/src/resume_mission_container.cpp", + "${services_path}/abilitymgr/src/ams_configuration_parameter.cpp", ] diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 74da3e2137a..7f28e830576 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -35,6 +35,7 @@ #include "uri.h" #include "ability_config.h" #include "pending_want_manager.h" +#include "ams_configuration_parameter.h" namespace OHOS { namespace AAFwk { @@ -569,10 +570,22 @@ private: */ bool Init(); /** - * wait for starting lanucher ability. + * starting lanucher ability. * */ - void WaitForStartingLauncherAbility(); + void StartingLauncherAbility(); + + /** + *starting system ui abilites. + * + */ + void StartingSystemUiAbility(SatrtUiMode mode); + + /** + * connet bms. + * + */ + void ConnectBmsService(); /** * get the user id. * @@ -586,6 +599,11 @@ private: */ int GenerateAbilityRequest( const Want &want, int requestCode, AbilityRequest &request, const sptr &callerToken); + /** + * Select to start the application according to the configuration file of AMS + * + */ + void StartSystemApplication(); sptr GetBundleManager(); int PreLoadAppDataAbilities(const std::string &bundleName); @@ -620,8 +638,10 @@ private: std::shared_ptr dataAbilityManager_; std::shared_ptr pendingWantManager_; std::shared_ptr systemAppManager_; + std::shared_ptr amsConfigResolver_; const static std::map dumpMap; }; + } // namespace AAFwk } // namespace OHOS #endif // OHOS_AAFWK_ABILITY_MANAGER_SERVICE_H diff --git a/services/abilitymgr/include/ams_configuration_parameter.h b/services/abilitymgr/include/ams_configuration_parameter.h new file mode 100644 index 00000000000..c803db74d36 --- /dev/null +++ b/services/abilitymgr/include/ams_configuration_parameter.h @@ -0,0 +1,85 @@ +/* + * 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 OHOS_AAFWK_AMS_CONFIGURATION_PARAMETER_H +#define OHOS_AAFWK_AMS_CONFIGURATION_PARAMETER_H + +#include +#include + +namespace OHOS { +namespace AAFwk { + +namespace AmsConfig { + +const std::string AMS_CONFIG_FILE_PATH{"/system/etc/ams_service_config.json"}; +const std::string SERVICE_ITEM_AMS{"service_startup_config"}; +const std::string STARTUP_LUNCHER{"startup_launcher"}; +const std::string STARTUP_STATUS_BAR{"startup_system_ui_status_bar"}; +const std::string STARTUP_NAVIGATION_BAR{"startup_system_ui_navigation_bar"}; + +} // namespace AmsConfig + +class AmsConfigurationParameter final{ + +private: + bool nonConfigFile{false}; + bool canStartLuncher{false}; + bool canStartUiStatusBar{false}; + bool canStartUiNavigationBar{false}; + +public: + AmsConfigurationParameter(); + ~AmsConfigurationParameter(); + /** + * return true : ams no config file + * return false : ams have config file + */ + bool NonConfigFile() const; + /** + * return true : ams can start luncher + * return false : ams do not start luncher + */ + bool GetStartLuncherState() const; + /** + * return true : ams can start system ui status bar + * return false : ams do not start system ui status bar + */ + bool GetStatusBarState() const; + /** + * return true : ams can start system ui navigation bar + * return false : ams do not start system ui navigation bar + */ + bool GetNavigationBarState() const; + /** + * Get profile information + */ + void Parse(); + + enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 }; + +private: + /** + * Read the configuration file of ams + * + */ + int LoadAmsConfiguration(const std::string &filePath); +}; + +enum SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 }; + +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_AMS_CONFIGURATION_PARAMETER_H diff --git a/services/abilitymgr/resource/ams_service_config.json b/services/abilitymgr/resource/ams_service_config.json new file mode 100644 index 00000000000..0dd3ebfb965 --- /dev/null +++ b/services/abilitymgr/resource/ams_service_config.json @@ -0,0 +1,8 @@ +{ + "service_startup_config":{ + "startup_launcher":true, + "startup_system_ui_status_bar" : true, + "startup_system_ui_navigation_bar" : true + } + +} diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index efb99dd6145..d9114d500ae 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -115,6 +115,12 @@ bool AbilityManagerService::Init() auto dataAbilityManager = std::make_shared(); CHECK_POINTER_RETURN_BOOL(dataAbilityManager); + amsConfigResolver_ = std::make_shared(); + if (amsConfigResolver_) { + amsConfigResolver_->Parse(); + HILOG_INFO("ams config parse"); + } + auto pendingWantManager = std::make_shared(); if (!pendingWantManager) { HILOG_ERROR("Failed to init pending want ability manager."); @@ -126,11 +132,7 @@ bool AbilityManagerService::Init() systemAppManager_ = std::make_shared(userId); CHECK_POINTER_RETURN_BOOL(systemAppManager_); - auto startLauncherAbilityTask = [aams = shared_from_this()]() { - aams->WaitForStartingLauncherAbility(); - aams->StartSystemUi(AbilityConfig::SYSTEM_UI_STATUS_BAR); - aams->StartSystemUi(AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); - }; + auto startLauncherAbilityTask = [aams = shared_from_this()]() { aams->StartSystemApplication(); }; handler_->PostTask(startLauncherAbilityTask, "startLauncherAbility"); dataAbilityManager_ = dataAbilityManager; pendingWantManager_ = pendingWantManager; @@ -167,7 +169,6 @@ int AbilityManagerService::StartAbility( const Want &want, const sptr &callerToken, int requestCode, int callerUid) { HILOG_INFO("%{public}s", __func__); - if (callerToken != nullptr && !VerificationToken(callerToken)) { return ERR_INVALID_VALUE; } @@ -1041,29 +1042,13 @@ int AbilityManagerService::GetUserId() return DEFAULT_USER_ID; } -void AbilityManagerService::WaitForStartingLauncherAbility() +void AbilityManagerService::StartingLauncherAbility() { - HILOG_INFO("Waiting AppMgr Service run completed."); - while (!appScheduler_->Init(shared_from_this())) { - HILOG_ERROR("Failed to init appScheduler_"); - usleep(REPOLL_TIME_MICRO_SECONDS); - } - - HILOG_INFO("Waiting BundleMgr Service run completed."); - /* wait until connected to bundle manager service */ - while (iBundleManager_ == nullptr) { - sptr bundle_obj = - OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (bundle_obj == nullptr) { - HILOG_ERROR("Failed to get bundle manager service"); - usleep(REPOLL_TIME_MICRO_SECONDS); - continue; - } - iBundleManager_ = iface_cast(bundle_obj); + HILOG_DEBUG("%{public}s", __func__); + if (!iBundleManager_) { + HILOG_INFO("bms service is null"); } - HILOG_INFO("Waiting Home Launcher Ability install completed."); - /* query if launcher ability has installed */ AppExecFwk::AbilityInfo abilityInfo; /* First stage, hardcoding for the first launcher App */ @@ -1074,22 +1059,7 @@ void AbilityManagerService::WaitForStartingLauncherAbility() usleep(REPOLL_TIME_MICRO_SECONDS); } - AppExecFwk::AbilityInfo statusBarInfo; - AppExecFwk::AbilityInfo navigationBarInfo; - Want statusBarWant; - Want navigationBarWant; - statusBarWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); - navigationBarWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); - uint32_t waitCnt = 0; - // Wait 10 minutes for the installation to complete. - while ((!(iBundleManager_->QueryAbilityInfo(statusBarWant, statusBarInfo)) || - !(iBundleManager_->QueryAbilityInfo(navigationBarWant, navigationBarInfo))) && - waitCnt < MAX_WAIT_SYSTEM_UI_NUM) { - HILOG_INFO("Waiting query system ui info completed."); - usleep(REPOLL_TIME_MICRO_SECONDS); - waitCnt++; - } - HILOG_INFO("Waiting boot animation for 5 seconds."); + HILOG_INFO("waiting boot animation for 5 seconds."); usleep(REPOLL_TIME_MICRO_SECONDS * 5); HILOG_INFO("Start Home Launcher Ability."); /* start launch ability */ @@ -1519,11 +1489,100 @@ void AbilityManagerService::NotifyBmsAbilityLifeStatus( bundleManager->NotifyActivityLifeStatus(bundleName, abilityName, launchTime); } -int AbilityManagerService::CheckPermission(const std::string &bundleName, const std::string &permission) +void AbilityManagerService::StartSystemApplication() { - auto bundleManager = GetBundleManager(); - CHECK_POINTER_AND_RETURN(bundleManager, INNER_ERR); - return bundleManager->CheckPermission(bundleName, permission); + HILOG_DEBUG("%{public}s", __func__); + + ConnectBmsService(); + + if (!amsConfigResolver_ || amsConfigResolver_->NonConfigFile()) { + HILOG_INFO("start all"); + StartingLauncherAbility(); + StartingSystemUiAbility(SatrtUiMode::STARTUIBOTH); + return; + } + + if (amsConfigResolver_->GetStartLuncherState()) { + HILOG_INFO("start luncher"); + StartingLauncherAbility(); + } + + if (amsConfigResolver_->GetStatusBarState()) { + HILOG_INFO("start status bar"); + StartingSystemUiAbility(SatrtUiMode::STATUSBAR); + } + + if (amsConfigResolver_->GetNavigationBarState()) { + HILOG_INFO("start navigation bar"); + StartingSystemUiAbility(SatrtUiMode::NAVIGATIONBAR); + } } + +void AbilityManagerService::ConnectBmsService() +{ + HILOG_DEBUG("%{public}s", __func__); + HILOG_INFO("Waiting AppMgr Service run completed."); + while (!appScheduler_->Init(shared_from_this())) { + HILOG_ERROR("failed to init appScheduler_"); + usleep(REPOLL_TIME_MICRO_SECONDS); + } + + HILOG_INFO("Waiting BundleMgr Service run completed."); + /* wait until connected to bundle manager service */ + while (iBundleManager_ == nullptr) { + sptr bundle_obj = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundle_obj == nullptr) { + HILOG_ERROR("failed to get bundle manager service"); + usleep(REPOLL_TIME_MICRO_SECONDS); + continue; + } + iBundleManager_ = iface_cast(bundle_obj); + } + + HILOG_INFO("Connect bms success!"); +} + +void AbilityManagerService::StartingSystemUiAbility(SatrtUiMode mode) +{ + HILOG_DEBUG("%{public}s", __func__); + if (!iBundleManager_) { + HILOG_INFO("bms service is null"); + } + + AppExecFwk::AbilityInfo statusBarInfo; + AppExecFwk::AbilityInfo navigationBarInfo; + Want statusBarWant; + Want navigationBarWant; + statusBarWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + navigationBarWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + uint32_t waitCnt = 0; + // Wait 10 minutes for the installation to complete. + while ((!(iBundleManager_->QueryAbilityInfo(statusBarWant, statusBarInfo)) || + !(iBundleManager_->QueryAbilityInfo(navigationBarWant, navigationBarInfo))) && + waitCnt < MAX_WAIT_SYSTEM_UI_NUM) { + HILOG_INFO("Waiting query system ui info completed."); + usleep(REPOLL_TIME_MICRO_SECONDS); + waitCnt++; + } + + HILOG_INFO("start ui mode : %{public}d", mode); + switch (mode) { + case SatrtUiMode::STATUSBAR: + StartSystemUi(AbilityConfig::SYSTEM_UI_STATUS_BAR); + break; + case SatrtUiMode::NAVIGATIONBAR: + StartSystemUi(AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + break; + case SatrtUiMode::STARTUIBOTH: + StartSystemUi(AbilityConfig::SYSTEM_UI_STATUS_BAR); + StartSystemUi(AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + break; + default: + HILOG_INFO("Input mode error ..."); + break; + } +} + } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_stack_manager.cpp b/services/abilitymgr/src/ability_stack_manager.cpp index aceaae1791c..db461cfb9a6 100644 --- a/services/abilitymgr/src/ability_stack_manager.cpp +++ b/services/abilitymgr/src/ability_stack_manager.cpp @@ -296,9 +296,6 @@ void AbilityStackManager::MoveMissionAndAbility(const std::shared_ptrSetIsLauncherCreate(); } } - - // add caller record - targetAbilityRecord->SetMissionRecord(targetMissionRecord); // check mission window mode. if (targetAbilityRecord->GetMissionRecord() == nullptr) { auto option = targetMissionRecord->GetMissionOption(); @@ -310,6 +307,9 @@ void AbilityStackManager::MoveMissionAndAbility(const std::shared_ptrSetStartSetting(setting); } } + + // add caller record + targetAbilityRecord->SetMissionRecord(targetMissionRecord); // add ability record to mission record. // if this ability record exist this mission record, do not add. targetMissionRecord->AddAbilityRecordToTop(targetAbilityRecord); diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp new file mode 100644 index 00000000000..b3180fa181f --- /dev/null +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -0,0 +1,97 @@ +/* + * 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 "ams_configuration_parameter.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +using json = nlohmann::json; + +AmsConfigurationParameter::AmsConfigurationParameter() +{} + +AmsConfigurationParameter::~AmsConfigurationParameter() +{} + +void AmsConfigurationParameter::Parse() +{ + auto ref = LoadAmsConfiguration(AmsConfig::AMS_CONFIG_FILE_PATH); + HILOG_INFO("load config ref : %{public}d", ref); +} + +bool AmsConfigurationParameter::GetStartLuncherState() const +{ + return canStartLuncher; +} + +bool AmsConfigurationParameter::GetStatusBarState() const +{ + return canStartUiStatusBar; +} + +bool AmsConfigurationParameter::GetNavigationBarState() const +{ + return canStartUiNavigationBar; +} + +bool AmsConfigurationParameter::NonConfigFile() const +{ + return nonConfigFile; +} + +int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) +{ + HILOG_DEBUG("%{public}s", __func__); + + std::ifstream inFile; + inFile.open(filePath, std::ios::in); + if (!inFile.is_open()) { + HILOG_INFO("read ams config error ..."); + nonConfigFile = true; + return READ_FAIL; + } + + json amsJson; + inFile >> amsJson; + if (amsJson.is_discarded()) { + HILOG_INFO("json discarded error ..."); + nonConfigFile = true; + inFile.close(); + return READ_JSON_FAIL; + } + + if (amsJson.contains(AmsConfig::SERVICE_ITEM_AMS)) { + canStartLuncher = amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_LUNCHER).get(); + canStartUiStatusBar = amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_STATUS_BAR).get(); + canStartUiNavigationBar = + amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_NAVIGATION_BAR).get(); + HILOG_INFO("get ams service config succes!"); + } else { + HILOG_INFO("json no have service item ..."); + nonConfigFile = true; + amsJson.clear(); + inFile.close(); + return READ_JSON_FAIL; + } + + amsJson.clear(); + inFile.close(); + HILOG_INFO("read ams config succes!"); + return READ_OK; +} + +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index 6b943551b96..bca90d0b7e2 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -2555,5 +2555,51 @@ HWTEST_F(AbilityManagerServiceTest, compelverifypermission_001, TestSize.Level1) EXPECT_EQ(resultFunction, ERR_OK); } +/* + * Feature: AbilityManagerService + * Function: AmsConfigurationParameter + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompelVerifyPermission + * EnvConditions: NA + * CaseDescription: Already configured + */ +HWTEST_F(AbilityManagerServiceTest, AmsConfigurationParameter_001, TestSize.Level1) +{ + EXPECT_TRUE(abilityMs_->amsConfigResolver_); + EXPECT_FALSE(abilityMs_->amsConfigResolver_->NonConfigFile()); +} + +/* + * Feature: AbilityManagerService + * Function: AmsConfigurationParameter + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompelVerifyPermission + * EnvConditions: NA + * CaseDescription: Already configured + */ +HWTEST_F(AbilityManagerServiceTest, AmsConfigurationParameter_002, TestSize.Level1) +{ + EXPECT_TRUE(abilityMs_->amsConfigResolver_); + // At present, all three are started and may be changed later + EXPECT_TRUE(abilityMs_->amsConfigResolver_->GetStartLuncherState()); + EXPECT_TRUE(abilityMs_->amsConfigResolver_->GetStatusBarState()); + EXPECT_TRUE(abilityMs_->amsConfigResolver_->GetNavigationBarState()); +} + +/* + * Feature: AbilityManagerService + * Function: AmsConfigurationParameter + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompelVerifyPermission + * EnvConditions: NA + * CaseDescription: Already configured + */ +HWTEST_F(AbilityManagerServiceTest, AmsConfigurationParameter_003, TestSize.Level1) +{ + EXPECT_TRUE(abilityMs_->amsConfigResolver_); + auto ref = abilityMs_->amsConfigResolver_->LoadAmsConfiguration(" "); + EXPECT_EQ(ref, 1); +} + } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 511b49308e7..ca01102c0fc 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include @@ -1632,6 +1634,51 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_025, TestSize.Level1) auto resultFunction = abilityMgrServ_->CompelVerifyPermission(permission, pid, uid, message); EXPECT_EQ(resultFunction, 0); } +/* + * Feature: AbilityManagerService + * Function: AmsConfigurationParameter + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompelVerifyPermission + * EnvConditions: NA + * CaseDescription: Judge the acquired properties + */ +HWTEST_F(AbilityMgrModuleTest, AmsConfigurationParameter_026, TestSize.Level1) +{ + EXPECT_TRUE(abilityMgrServ_->amsConfigResolver_); + EXPECT_FALSE(abilityMgrServ_->amsConfigResolver_->NonConfigFile()); + + // Open a path that does not exist + auto ref = abilityMgrServ_->amsConfigResolver_->LoadAmsConfiguration("/system/etc/ams.txt"); + // faild return 1 + EXPECT_EQ(ref, 1); +} + +/* + * Feature: AbilityManagerService + * Function: AmsConfigurationParameter + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompelVerifyPermission + * EnvConditions: NA + * CaseDescription: Judge the acquired properties + */ +HWTEST_F(AbilityMgrModuleTest, AmsConfigurationParameter_027, TestSize.Level1) +{ + bool startLuncher = false; + bool startstatusbar = false; + bool startnavigationbar = false; + nlohmann::json info; + std::ifstream file(AmsConfig::AMS_CONFIG_FILE_PATH, std::ios::in); + if (file.is_open()) { + file >> info; + info.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_LUNCHER).get_to(startLuncher); + info.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_STATUS_BAR).get_to(startstatusbar); + info.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_NAVIGATION_BAR).get_to(startnavigationbar); + } + + EXPECT_EQ(startLuncher, abilityMgrServ_->amsConfigResolver_->GetStartLuncherState()); + EXPECT_EQ(startstatusbar, abilityMgrServ_->amsConfigResolver_->GetStatusBarState()); + EXPECT_EQ(startnavigationbar, abilityMgrServ_->amsConfigResolver_->GetNavigationBarState()); +} } // namespace AAFwk } // namespace OHOS diff --git a/tools/zip/src/file_path.cpp b/tools/zip/src/file_path.cpp index 197b1550844..555791d7582 100755 --- a/tools/zip/src/file_path.cpp +++ b/tools/zip/src/file_path.cpp @@ -324,32 +324,32 @@ bool FilePath::AppendRelativePath(const FilePath &child, FilePath *path) } std::vector parentComponentsReverse; - std::vector childComponents_reverse; + std::vector childComponentsReverse; std::vector::reverse_iterator riter; for (riter = parentComponents.rbegin(); riter != parentComponents.rend(); riter++) { parentComponentsReverse.push_back(*riter); } for (riter = childComponents.rbegin(); riter != childComponents.rend(); riter++) { - childComponents_reverse.push_back(*riter); + childComponentsReverse.push_back(*riter); } - std::vector::const_iterator parent_it = parentComponentsReverse.begin(); - std::vector::const_iterator child_it = childComponents_reverse.begin(); - while (parent_it != parentComponentsReverse.end()) { - if (*parent_it != *child_it) + std::vector::const_iterator parentIt = parentComponentsReverse.begin(); + std::vector::const_iterator childIt = childComponentsReverse.begin(); + while (parentIt != parentComponentsReverse.end()) { + if (*parentIt != *childIt) return false; - ++parent_it; - ++child_it; + ++parentIt; + ++childIt; } if (path != nullptr) { // Relative paths do not include separator - if ((child_it != childComponents_reverse.end()) && (*child_it == SEPARATOR)) { - ++child_it; + if ((childIt != childComponentsReverse.end()) && (*childIt == SEPARATOR)) { + ++childIt; } - for (; child_it != childComponents_reverse.end(); child_it++) { - *path = path->Append(*child_it); + for (; childIt != childComponentsReverse.end(); childIt++) { + *path = path->Append(*childIt); } } return true; diff --git a/tools/zip/src/zip.cpp b/tools/zip/src/zip.cpp index ae7ccf8cb81..7c3372726dd 100755 --- a/tools/zip/src/zip.cpp +++ b/tools/zip/src/zip.cpp @@ -148,12 +148,14 @@ bool Zip(const ZipParams ¶ms, const OPTIONS &options, CALLBACK callback) if (params.DestFd() != kInvalidPlatformFile) { zipWriter = ZipWriter::CreateWithFd(params.DestFd(), rootPath); if (!zipWriter) { + CALLING_CALL_BACK(callback, ERROR_CODE_STREAM_ERROR) return false; } } if (!zipWriter) { zipWriter = ZipWriter::Create(params.DestFile(), rootPath); if (!zipWriter) { + CALLING_CALL_BACK(callback, ERROR_CODE_STREAM_ERROR) return false; } } @@ -254,9 +256,11 @@ bool ZipWithFilterCallback(const FilePath &srcDir, const FilePath &destFile, con FilePath srcPath = srcDir; if (!EndsWith(srcPath.Value(), SEPARATOR)) { if (!FilePath::DirectoryExists(srcPath.DirName())) { + CALLING_CALL_BACK(callback, ERROR_CODE_DATA_ERROR) return false; } } else if (!FilePath::DirectoryExists(srcDir)) { + CALLING_CALL_BACK(callback, ERROR_CODE_DATA_ERROR) return false; } ZipParams params(srcDir, destFile); -- Gitee