diff --git a/ability_runtime.gni b/ability_runtime.gni index 729ad0ef0f..648264530e 100644 --- a/ability_runtime.gni +++ b/ability_runtime.gni @@ -126,6 +126,11 @@ declare_args() { resource_schedule_service_enable = false } + if (defined(global_parts_info) && + !defined(global_parts_info.powermgr_power_manager)) { + ability_runtime_power = false + } + if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_efficiency_manager)) { efficiency_manager = false diff --git a/bundle.json b/bundle.json index 1157cd7261..090d7539de 100644 --- a/bundle.json +++ b/bundle.json @@ -80,11 +80,13 @@ "netmanager_base", "node", "os_account", + "power_manager", "relational_store", "resource_management", "resource_schedule_service", "safwk", "samgr", + "screenlock_mgr", "storage_service", "toolchain", "webview", diff --git a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.cpp b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.cpp index 9d0f9d888b..1ac5ccf4ce 100644 --- a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.cpp +++ b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.cpp @@ -46,7 +46,7 @@ void JsAbilityAutoStartupCallBack::OnAutoStartupOff(const AutoStartupInfo &info) void JsAbilityAutoStartupCallBack::Register(napi_value value) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); for (const auto &callback : callbacks_) { if (IsJsCallbackEquals(callback, value)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The current callback already exists."); @@ -64,7 +64,7 @@ void JsAbilityAutoStartupCallBack::UnRegister(napi_value value) TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); napi_valuetype type = napi_undefined; napi_typeof(env_, value, &type); - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); if (type == napi_undefined || type == napi_null) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "jsCallback is nullptr, delete all callback."); callbacks_.clear(); @@ -105,7 +105,7 @@ void JsAbilityAutoStartupCallBack::JSCallFunction(const AutoStartupInfo &info, c void JsAbilityAutoStartupCallBack::JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName) { - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); for (auto callback : callbacks_) { if (callback == nullptr) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "callback is nullptr."); diff --git a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.h b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.h index 0e49f5620f..6017641867 100644 --- a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.h +++ b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_callback.h @@ -49,7 +49,7 @@ private: napi_env env_; std::vector> callbacks_; - std::mutex mutexlock; + std::mutex mutexlock_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_manager_utils.cpp b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_manager_utils.cpp index 2565aac763..e4d1d6fd97 100644 --- a/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_manager_utils.cpp +++ b/frameworks/js/napi/ability_auto_startup_callback/js_ability_auto_startup_manager_utils.cpp @@ -72,7 +72,7 @@ napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector jsObserver = this; @@ -51,7 +51,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); for (auto &item : jsObserverObjectSet_) { if (item == nullptr) { continue; @@ -112,7 +112,7 @@ void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsO } napi_ref ref = nullptr; napi_create_reference(env_, jsObserverObject, 1, &ref); - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); jsObserverObjectSet_.emplace(std::shared_ptr(reinterpret_cast(ref))); } @@ -124,7 +124,7 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value & } auto observer = GetObserverObject(jsObserverObject); - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); if (observer != nullptr) { jsObserverObjectSet_.erase(observer); } @@ -132,7 +132,7 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value & void JSAbilityForegroundStateObserver::RemoveAllJsObserverObject() { - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); if (!jsObserverObjectSet_.empty()) { jsObserverObjectSet_.clear(); } @@ -144,7 +144,7 @@ std::shared_ptr JSAbilityForegroundStateObserver::GetObserverOb TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null."); return nullptr; } - std::lock_guard lock(mutexlock); + std::lock_guard lock(mutexlock_); for (auto &observer : jsObserverObjectSet_) { if (observer == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid observer."); diff --git a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h index d6f1e00828..3723a0a9ff 100644 --- a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h +++ b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h @@ -47,7 +47,7 @@ public: private: napi_env env_; volatile bool valid_ = true; - std::mutex mutexlock; + std::mutex mutexlock_; std::set> jsObserverObjectSet_; }; } // namespace AbilityRuntime diff --git a/frameworks/js/napi/ability_manager/js_ability_manager_utils.cpp b/frameworks/js/napi/ability_manager/js_ability_manager_utils.cpp index f2fc9411cc..18c915a525 100644 --- a/frameworks/js/napi/ability_manager/js_ability_manager_utils.cpp +++ b/frameworks/js/napi/ability_manager/js_ability_manager_utils.cpp @@ -39,8 +39,8 @@ napi_value CreateJSToken(napi_env env, const sptr target) env, "TokenClass", NAPI_AUTO_LENGTH, constructorcb, nullptr, 0, nullptr, &tokenClass); napi_value jsToken = nullptr; napi_new_instance(env, tokenClass, 0, nullptr, &jsToken); - auto finalizecb = [](napi_env env, void *data, void *hint) {}; - napi_wrap(env, jsToken, static_cast(target.GetRefPtr()), finalizecb, nullptr, nullptr); + auto finalizercb = [](napi_env env, void *data, void *hint) {}; + napi_wrap(env, jsToken, static_cast(target.GetRefPtr()), finalizercb, nullptr, nullptr); return jsToken; } diff --git a/frameworks/js/napi/app/ability_delegator/js_ability_delegator.h b/frameworks/js/napi/app/ability_delegator/js_ability_delegator.h index b972359cfd..663d001214 100644 --- a/frameworks/js/napi/app/ability_delegator/js_ability_delegator.h +++ b/frameworks/js/napi/app/ability_delegator/js_ability_delegator.h @@ -46,7 +46,7 @@ public: ~JSAbilityDelegator() = default; /** - * Destory object. + * Destroy object. * * @param env Indicates the native engine. * @param data Indicates the object to be destroyed. diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp index cb66c9468c..de626ce7f6 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -94,7 +94,7 @@ public: static napi_value KillProcessesByBundleName(napi_env env, napi_callback_info info) { TAG_LOGD(AAFwkTag::APPMGR, "KillProcessesByBundleName start."); - GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnkillProcessByBundleName); + GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessByBundleName); } static napi_value ClearUpApplicationData(napi_env env, napi_callback_info info) @@ -130,7 +130,7 @@ private: } static int64_t serialNumber = 0; std::vector bundleNameList; - // unwarp observer + // unwrap observer if (observer_ == nullptr) { observer_ = new JSAppStateObserver(env); } @@ -310,9 +310,9 @@ private: return result; } - napi_value OnkillProcessByBundleName(napi_env env, size_t argc, napi_value* argv) + napi_value OnKillProcessByBundleName(napi_env env, size_t argc, napi_value* argv) { - TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessByBundleName called"); + TAG_LOGD(AAFwkTag::APPMGR, "called"); int32_t errCode = 0; std::string bundleName; @@ -350,7 +350,7 @@ private: napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnkillProcessByBundleName", + NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessByBundleName", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } diff --git a/frameworks/js/napi/app/app_manager/js_app_state_observer.cpp b/frameworks/js/napi/app/app_manager/js_app_state_observer.cpp index 23e2376bc8..5fe5949d42 100644 --- a/frameworks/js/napi/app/app_manager/js_app_state_observer.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_state_observer.cpp @@ -47,8 +47,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData) { - TAG_LOGI(AAFwkTag::APPMGR, - "HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.", + TAG_LOGI(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d.", appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); auto tmpMap = jsObserverObjectMap_; for (auto &item : tmpMap) { diff --git a/frameworks/js/napi/app/app_manager/js_app_state_observer.h b/frameworks/js/napi/app/app_manager/js_app_state_observer.h index 34e3adf638..0c838fc3a5 100644 --- a/frameworks/js/napi/app/app_manager/js_app_state_observer.h +++ b/frameworks/js/napi/app/app_manager/js_app_state_observer.h @@ -29,7 +29,7 @@ using OHOS::AppExecFwk::ProcessData; class JSAppStateObserver : public ApplicationStateObserverStub { public: explicit JSAppStateObserver(napi_env engine); - ~JSAppStateObserver(); + virtual ~JSAppStateObserver(); void OnForegroundApplicationChanged(const AppStateData &appStateData) override; void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override; void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override; diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index 5c12391586..609b8c7071 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -189,8 +189,8 @@ class ApplicationContext { return this.__context_impl__.setSupportedProcessCache(isSupport); } - getCurrentAppCloneIndex(){ - return this.__context_impl__.getCurrentAppCloneIndex() + getCurrentAppCloneIndex() { + return this.__context_impl__.getCurrentAppCloneIndex(); } set area(mode) { diff --git a/frameworks/js/napi/app/error_manager/js_error_manager.cpp b/frameworks/js/napi/app/error_manager/js_error_manager.cpp index c5189a6c2b..6675901b8e 100644 --- a/frameworks/js/napi/app/error_manager/js_error_manager.cpp +++ b/frameworks/js/napi/app/error_manager/js_error_manager.cpp @@ -211,7 +211,7 @@ private: if (type == ON_OFF_TYPE_SYNC_LOOP) { if (!AppExecFwk::EventRunner::IsAppMainThread()) { TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread."); - ThrowInvaildCallerError(env); + ThrowInvalidCallerError(env); return CreateJsUndefined(env); } return OnSetLoopWatch(env, argc, argv); @@ -219,7 +219,7 @@ private: if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) { if (!AppExecFwk::EventRunner::IsAppMainThread()) { TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be set from main thread."); - ThrowInvaildCallerError(env); + ThrowInvalidCallerError(env); return CreateJsUndefined(env); } if (argc != ARGC_TWO) { @@ -327,7 +327,7 @@ private: if (type == ON_OFF_TYPE_SYNC_LOOP) { if (!AppExecFwk::EventRunner::IsAppMainThread()) { TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread."); - ThrowInvaildCallerError(env); + ThrowInvalidCallerError(env); return CreateJsUndefined(env); } return OnRemoveLoopWatch(env, argc, argv); @@ -335,7 +335,7 @@ private: if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) { if (!AppExecFwk::EventRunner::IsAppMainThread()) { TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be unset from main thread."); - ThrowInvaildCallerError(env); + ThrowInvalidCallerError(env); return CreateJsUndefined(env); } if (argc != ARGC_TWO && argc != ARGC_ONE) { @@ -418,7 +418,7 @@ private: return res; } } - TAG_LOGE(AAFwkTag::JSNAPI, "Remove UnhandledRjectionObserver failed"); + TAG_LOGE(AAFwkTag::JSNAPI, "Remove UnhandledRejectionObserver failed"); ThrowError(env, AbilityErrorCode::ERROR_CODE_OBSERVER_NOT_FOUND); return res; } @@ -479,15 +479,15 @@ private: std::unique_ptr complete = std::make_unique ([number](napi_env env, NapiAsyncTask &task, int32_t status) { if (loopObserver_ == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: loopObserver_ is null."); + TAG_LOGE(AAFwkTag::JSNAPI, "loopObserver_ is null."); return; } if (loopObserver_->env == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: env is null."); + TAG_LOGE(AAFwkTag::JSNAPI, "env is null."); return; } if (loopObserver_->observerObject == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: observerObject is null."); + TAG_LOGE(AAFwkTag::JSNAPI, "observerObject is null."); return; } napi_value jsValue[] = { CreateJsValue(loopObserver_->env, number) }; diff --git a/frameworks/js/napi/app/js_app_manager/js_app_foreground_state_observer.cpp b/frameworks/js/napi/app/js_app_manager/js_app_foreground_state_observer.cpp index ae877cf792..6b33ee615a 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_foreground_state_observer.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_foreground_state_observer.cpp @@ -29,7 +29,7 @@ void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStat { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destoryed."); + TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destroyed."); return; } wptr self = this; diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 39085f6438..05813d0703 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -125,7 +125,7 @@ public: static napi_value KillProcessesByBundleName(napi_env env, napi_callback_info info) { - GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnkillProcessesByBundleName); + GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessesByBundleName); } static napi_value ClearUpApplicationData(napi_env env, napi_callback_info info) @@ -187,8 +187,8 @@ public: } napi_ref ref = nullptr; napi_create_reference(env, para, 1, &ref); - NativeReference* nativeReferece = reinterpret_cast(ref); - auto object = nativeReferece->GetNapiValue(); + NativeReference* nativeReference = reinterpret_cast(ref); + auto object = nativeReference->GetNapiValue(); napi_value method = nullptr; napi_get_named_property(env, object, methodName.c_str(), &method); if (method == nullptr) { @@ -487,7 +487,7 @@ private: int64_t observerId = -1; napi_get_value_int64(env, argv[INDEX_ONE], &observerId); if (observer_ == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "observer_ is nullptr, please register first"); + TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr, please register first"); ThrowInvalidParamError(env, "observer is nullptr, please register first"); return CreateJsUndefined(env); } @@ -762,9 +762,9 @@ private: return result; } - napi_value OnkillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv) + napi_value OnKillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv) { - TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessesByBundleName called"); + TAG_LOGD(AAFwkTag::APPMGR, "OnKillProcessesByBundleName called"); if (argc < ARGC_ONE) { TAG_LOGE(AAFwkTag::APPMGR, "Params not match"); ThrowTooFewParametersError(env); @@ -796,7 +796,7 @@ private: napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnkillProcessesByBundleName", + NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessesByBundleName", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } diff --git a/frameworks/js/napi/app/js_app_manager/js_app_state_observer.cpp b/frameworks/js/napi/app/js_app_manager/js_app_state_observer.cpp index 817a8dafbc..de7aa3cc66 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_state_observer.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_state_observer.cpp @@ -29,10 +29,10 @@ JSAppStateObserver::~JSAppStateObserver() = default; void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData) { - TAG_LOGD(AAFwkTag::APPMGR, "onForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d", + TAG_LOGD(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d", appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; @@ -53,8 +53,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData) { - TAG_LOGD(AAFwkTag::APPMGR, - "HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d", + TAG_LOGD(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d", appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); auto tmpMap = jsObserverObjectMap_; for (auto &item : tmpMap) { @@ -102,7 +101,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; @@ -170,7 +169,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData) { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; @@ -204,7 +203,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData) { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; @@ -239,7 +238,7 @@ void JSAppStateObserver::OnAppStarted(const AppStateData &appStateData) TAG_LOGD(AAFwkTag::APPMGR, "onAppStarted bundleName:%{public}s, uid:%{public}d, state:%{public}d", appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; @@ -279,7 +278,7 @@ void JSAppStateObserver::OnAppStopped(const AppStateData &appStateData) TAG_LOGD(AAFwkTag::APPMGR, "OnAppStopped bundleName:%{public}s, uid:%{public}d, state:%{public}d", appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); if (!valid_) { - TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed"); + TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed"); return; } wptr jsObserver = this; diff --git a/frameworks/js/napi/featureAbility/feature_ability.cpp b/frameworks/js/napi/featureAbility/feature_ability.cpp index 4b1f0feaea..6f7787e69f 100644 --- a/frameworks/js/napi/featureAbility/feature_ability.cpp +++ b/frameworks/js/napi/featureAbility/feature_ability.cpp @@ -48,14 +48,6 @@ CallbackInfo g_aceCallbackInfo; const int PARA_SIZE_IS_ONE = 1; const int PARA_SIZE_IS_TWO = 2; -/** - * @brief FeatureAbility 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 FeatureAbilityInit(napi_env env, napi_value exports) { TAG_LOGD(AAFwkTag::FA, "called"); @@ -441,14 +433,6 @@ napi_value JsFeatureAbility::OnGetWindow(napi_env env, napi_callback_info info) } #endif -/** - * @brief FeatureAbility NAPI method : setResult. - * - * @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_SetResult(napi_env env, napi_callback_info info) { TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__); @@ -471,14 +455,6 @@ napi_value NAPI_SetResult(napi_env env, napi_callback_info info) return ret; } -/** - * @brief SetResult 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 SetResultWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo) { TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__); @@ -633,16 +609,6 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) } EXTERN_C_START -/** - * @brief The interface of onAbilityResult provided for ACE to call back to JS. - * - * @param requestCode Indicates the request code returned after the ability is started. - * @param resultCode Indicates the result code returned after the ability is started. - * @param resultData Indicates the data returned after the ability is started. - * @param cb 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. - */ void CallOnAbilityResult(int requestCode, int resultCode, const Want &resultData, CallbackInfo callbackInfo) { TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__); @@ -758,15 +724,6 @@ bool InnerUnwrapWant(napi_env env, napi_value args, Want &want) return UnwrapWant(env, jsWant, want); } -/** - * @brief Parse the parameters. - * - * @param param Indicates the parameters saved the parse result. - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * - * @return The return value from NAPI C++ to JS for the module. - */ napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_value args) { TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__); @@ -804,15 +761,6 @@ napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_valu return result; } -/** - * @brief Parse the abilityResult parameters. - * - * @param param Indicates the want parameters saved the parse result. - * @param env The environment that the Node-API call is invoked under. - * @param args Indicates the arguments passed into the callback. - * - * @return The return value from NAPI C++ to JS for the module. - */ napi_value UnwrapAbilityResult(CallAbilityParam ¶m, napi_env env, napi_value args) { TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__); diff --git a/frameworks/js/napi/featureAbility/feature_ability_constant.cpp b/frameworks/js/napi/featureAbility/feature_ability_constant.cpp index eab8f55e56..32b59b35f2 100644 --- a/frameworks/js/napi/featureAbility/feature_ability_constant.cpp +++ b/frameworks/js/napi/featureAbility/feature_ability_constant.cpp @@ -23,14 +23,6 @@ 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) { const int Window_Configuration_Zero = 100; diff --git a/frameworks/js/napi/featureAbility/napi_data_ability_helper.cpp b/frameworks/js/napi/featureAbility/napi_data_ability_helper.cpp index 1845dce9d3..818e630bbd 100644 --- a/frameworks/js/napi/featureAbility/napi_data_ability_helper.cpp +++ b/frameworks/js/napi/featureAbility/napi_data_ability_helper.cpp @@ -263,7 +263,7 @@ void AnalysisValuesBucket(NativeRdb::ValuesBucket &valuesBucket, const napi_env uint32_t arrLen = 0; napi_status status = napi_get_array_length(env, keys, &arrLen); if (status != napi_ok) { - TAG_LOGE(AAFwkTag::FA, "ValuesBucket errr"); + TAG_LOGE(AAFwkTag::FA, "ValuesBucket error"); return; } TAG_LOGI(AAFwkTag::FA, "ValuesBucket num:%{public}d ", arrLen); @@ -419,7 +419,7 @@ void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data) void InsertPromiseCompleteCB(napi_env env, napi_status status, void *data) { - TAG_LOGI(AAFwkTag::FA, "NAPI_Insert, main event thread complete."); + TAG_LOGI(AAFwkTag::FA, "NAPI_Insert, main event thread complete."); DAHelperInsertCB *insertCB = static_cast(data); napi_value result = nullptr; napi_create_int32(env, insertCB->result, &result); diff --git a/frameworks/js/napi/featureAbility/napi_data_ability_operation.cpp b/frameworks/js/napi/featureAbility/napi_data_ability_operation.cpp index 58bb0c322e..2df1518915 100644 --- a/frameworks/js/napi/featureAbility/napi_data_ability_operation.cpp +++ b/frameworks/js/napi/featureAbility/napi_data_ability_operation.cpp @@ -103,7 +103,7 @@ napi_value BuildDataAbilityOperation( UnwrapDataAbilityPredicates(*predicates, env, jsPredicates); builder->WithPredicates(predicates); - // get expectedcount property + // get expectedCount property int expectedCount = 0; UnwrapInt32ByPropertyName(env, param, "expectedCount", expectedCount); TAG_LOGI(AAFwkTag::FA, "%{public}s, expectedCount:%{public}d", __func__, expectedCount); diff --git a/frameworks/js/napi/inner/napi_ability_common/feature_ability_common.h b/frameworks/js/napi/inner/napi_ability_common/feature_ability_common.h index bdfddf2135..bd69c41cf9 100644 --- a/frameworks/js/napi/inner/napi_ability_common/feature_ability_common.h +++ b/frameworks/js/napi/inner/napi_ability_common/feature_ability_common.h @@ -15,6 +15,7 @@ #ifndef OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H #define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H + #include "ability.h" #include "ability_info.h" #include "application_info.h" diff --git a/frameworks/js/napi/inner/napi_ability_common/js_feature_ability_common.h b/frameworks/js/napi/inner/napi_ability_common/js_feature_ability_common.h index 0e4cded4d7..f5405635fb 100644 --- a/frameworks/js/napi/inner/napi_ability_common/js_feature_ability_common.h +++ b/frameworks/js/napi/inner/napi_ability_common/js_feature_ability_common.h @@ -15,6 +15,7 @@ #ifndef OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_COMMON_H #define OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_COMMON_H + #include "ability.h" #include "ability_info.h" #include "abs_shared_result_set.h" diff --git a/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h b/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h index bcff1450ce..9d982dd686 100644 --- a/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h +++ b/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h @@ -127,7 +127,7 @@ public: napi_value CreateAbilityInfos(napi_env env, const std::vector &abilityInfos); napi_value CreateAppVersionInfo(napi_env env, const std::shared_ptr &appInfo); napi_value CreateWant(napi_env env, const std::shared_ptr &want); - bool UnwarpVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options); + bool UnwrapVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options); bool GetStringsValue(napi_env env, napi_value object, std::vector &strList); bool GetPermissionOptions(napi_env env, napi_value object, JsPermissionOptions &options); void AddFreeInstallObserver(napi_env env, const AAFwk::Want &want, napi_value callback, napi_value* result); diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp index c7f9d7c229..b8e2136764 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp @@ -2991,20 +2991,20 @@ napi_value GetAbilityNameWrap(napi_env env, napi_callback_info info, AbilityName napi_value NAPI_GetAbilityNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType) { TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); - AbilityNameCB *ablityNameCB = CreateAbilityNameCBInfo(env); - if (ablityNameCB == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ablityNameCB == nullptr", __func__); + AbilityNameCB *abilityNameCB = CreateAbilityNameCBInfo(env); + if (abilityNameCB == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s abilityNameCB == nullptr", __func__); return WrapVoidToJS(env); } - ablityNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; - ablityNameCB->cbBase.abilityType = abilityType; - napi_value ret = GetAbilityNameWrap(env, info, ablityNameCB); + abilityNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + abilityNameCB->cbBase.abilityType = abilityType; + napi_value ret = GetAbilityNameWrap(env, info, abilityNameCB); if (ret == nullptr) { TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullptr", __func__); - if (ablityNameCB != nullptr) { - delete ablityNameCB; - ablityNameCB = nullptr; + if (abilityNameCB != nullptr) { + delete abilityNameCB; + abilityNameCB = nullptr; } ret = WrapVoidToJS(env); } @@ -3131,7 +3131,7 @@ bool UnwrapParamForWant(napi_env env, napi_value args, AbilityType, CallAbilityP if (jsSettingObj != nullptr) { param.setting = AbilityStartSetting::GetEmptySetting(); if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, unwrap abilityStartSetting falied.", __func__); + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, unwrap abilityStartSetting failed.", __func__); } TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s abilityStartSetting", __func__); } @@ -3743,7 +3743,7 @@ void StartBackgroundRunningExecuteCB(napi_env env, void *data) } const std::shared_ptr info = asyncCallbackInfo->ability->GetAbilityInfo(); if (info == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "abilityinfo is null"); + TAG_LOGE(AAFwkTag::JSNAPI, "ability info is null"); asyncCallbackInfo->errCode = NAPI_ERR_ACE_ABILITY; return; } @@ -3900,7 +3900,7 @@ napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info in TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env); if (asyncCallbackInfo == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullpter", __func__); + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullptr", __func__); return WrapVoidToJS(env); } @@ -4018,14 +4018,14 @@ napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info i TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env); if (asyncCallbackInfo == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullpter", __func__); + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullptr", __func__); return WrapVoidToJS(env); } asyncCallbackInfo->errCode = NAPI_ERR_NO_ERROR; napi_value ret = CancelBackgroundRunningWrap(env, info, asyncCallbackInfo); if (ret == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullpter", __func__); + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullptr", __func__); if (asyncCallbackInfo != nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -4119,7 +4119,7 @@ napi_value JsNapiCommon::JsConnectAbility(napi_env env, napi_callback_info info, connectionCallback->Reset(); RemoveConnectionLocked(want); } - // free failedcallback here, avoid possible multi-threading problems when disconnect success + // free failed callback here, avoid possible multi-threading problems when disconnect success napi_delete_reference(env, connectionCallback->failedCallbackRef); connectionCallback->failedCallbackRef = nullptr; return CreateJsValue(env, id); @@ -4454,7 +4454,7 @@ napi_value JsNapiCommon::JsGetCacheDir(napi_env env, napi_callback_info info, co auto context = obj->ability_->GetAbilityContext(); if (context == nullptr) { *value = static_cast(NAPI_ERR_ABILITY_CALL_INVALID); - TAG_LOGE(AAFwkTag::JSNAPI, "JsGetCacheDir task execute error, the abilitycontext is nullptr"); + TAG_LOGE(AAFwkTag::JSNAPI, "JsGetCacheDir task execute error, the ability context is nullptr"); return; } dir->name = context->GetCacheDir(); @@ -4706,7 +4706,7 @@ napi_value JsNapiCommon::JsGetOrCreateDistributedDir( auto context = obj->ability_->GetAbilityContext(); if (context == nullptr) { *value = static_cast(NAPI_ERR_ACE_ABILITY); - TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the abilitycontext is nullptr"); + TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the ability context is nullptr"); return; } dir->name = context->GetDistributedFilesDir(); @@ -5041,7 +5041,7 @@ napi_value JsNapiCommon::CreateAppVersionInfo(napi_env env, const std::shared_pt return objContext; } -bool JsNapiCommon::UnwarpVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options) +bool JsNapiCommon::UnwrapVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options) { bool flagCall = true; size_t argc = ARGS_MAX_COUNT; diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_context.cpp b/frameworks/js/napi/inner/napi_ability_common/napi_context.cpp index c77b64f885..0b4ad48489 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_context.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/napi_context.cpp @@ -2887,12 +2887,12 @@ static napi_value ConstructNapiJSContext(napi_env env) TAG_LOGE(AAFwkTag::JSNAPI, "CreateObject failed"); return nullptr; } - auto jsCalss = std::make_unique(); - if (!jsCalss->DataInit(env)) { + auto jsClass = std::make_unique(); + if (!jsClass->DataInit(env)) { TAG_LOGE(AAFwkTag::JSNAPI, "NapiJsContext init failed"); return nullptr; } - napi_wrap(env, objContext, jsCalss.release(), NapiJsContext::Finalizer, nullptr, nullptr); + napi_wrap(env, objContext, jsClass.release(), NapiJsContext::Finalizer, nullptr, nullptr); napi_set_named_property(env, objContext, "stageMode", CreateJsValue(env, false)); if (!BindNapiJSContextFunction(env, objContext)) { TAG_LOGE(AAFwkTag::JSNAPI, "bind func failed"); @@ -3326,7 +3326,7 @@ napi_value NapiJsContext::OnVerifyPermission(napi_env env, napi_callback_info in return CreateJsNull(env); } JsPermissionOptions options; - bool flagCall = UnwarpVerifyPermissionParams(env, info, options); + bool flagCall = UnwrapVerifyPermissionParams(env, info, options); auto execute = [obj = this, permission, options, value = errorVal] () { if (obj->ability_ == nullptr) { *value = static_cast(NAPI_ERR_ACE_ABILITY); @@ -3607,7 +3607,7 @@ napi_value NapiJsContext::OnGetOrCreateLocalDir(napi_env env, napi_callback_info auto context = obj->ability_->GetAbilityContext(); if (context == nullptr || dir == nullptr) { *value = static_cast(NAPI_ERR_ABILITY_CALL_INVALID); - TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the abilitycontext is nullptr"); + TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the ability context is nullptr"); return; } dir->name = context->GetBaseDir(); diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp index 4fad091ba5..8f1c3c1f7a 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp @@ -36,7 +36,7 @@ bool UnwrapExecuteResult(napi_env env, napi_value param, InsightIntentExecuteRes } int32_t code = 0; if (!UnwrapInt32ByPropertyName(env, param, "code", code)) { - TAG_LOGE(AAFwkTag::JSNAPI, "Intent result must contian a code."); + TAG_LOGE(AAFwkTag::JSNAPI, "Intent result must contain a code."); return false; } executeResult.code = code; diff --git a/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp index 2dd74532f0..ff9d5239f5 100755 --- a/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp +++ b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp @@ -105,8 +105,8 @@ private: auto requestInfo = new RequestInfo(callerToken, left, top, width, height); auto jsRequestInfo = RequestInfo::WrapRequestInfo(env, requestInfo); if (jsRequestInfo == nullptr) { - TAG_LOGE(AAFwkTag::DIALOG, "Can not wrap requestinfo from target request."); - ThrowInvalidParamError(env, "Parameter error: Can not wrap requestinfo from target request."); + TAG_LOGE(AAFwkTag::DIALOG, "Can not wrap request info from target request."); + ThrowInvalidParamError(env, "Parameter error: Can not wrap request info from target request."); return CreateJsUndefined(env); } diff --git a/frameworks/js/napi/js_mission_manager/mission_manager.cpp b/frameworks/js/napi/js_mission_manager/mission_manager.cpp index 71452e7f79..aea7139e60 100755 --- a/frameworks/js/napi/js_mission_manager/mission_manager.cpp +++ b/frameworks/js/napi/js_mission_manager/mission_manager.cpp @@ -265,7 +265,7 @@ private: napi_value lastParam = (argc <= ARG_COUNT_TWO) ? nullptr : argv[INDEX_TWO]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnUnregisterMissionListener", + NapiAsyncTask::Schedule("MissionManager::OnUnregisterMissionListener", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -350,7 +350,7 @@ private: napi_value lastParam = (argc <= 2) ? nullptr : argv[2]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfos", + NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfos", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -390,7 +390,7 @@ private: napi_value lastParam = (argc <= 2) ? nullptr : argv[2]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfo", + NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfo", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -423,7 +423,7 @@ private: }; std::shared_ptr snapshotWrap = std::make_shared(); - auto excute = [deviceId, missionId, isLowResolution, snapshotWrap]() { + auto execute = [deviceId, missionId, isLowResolution, snapshotWrap]() { snapshotWrap->result = AbilityManagerClient::GetInstance()->GetMissionSnapshot( deviceId, missionId, snapshotWrap->missionSnapshot, isLowResolution); }; @@ -452,8 +452,8 @@ private: }; napi_value lastParam = (argc > ARG_COUNT_TWO) ? argv[ARG_COUNT_TWO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnGetMissionSnapShot", - env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(excute), std::move(complete), &result)); + NapiAsyncTask::Schedule("MissionManager::OnGetMissionSnapShot", + env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result)); return result; } @@ -508,7 +508,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnLockMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnLockMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -541,7 +541,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnUnlockMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnUnlockMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -574,7 +574,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnClearMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnClearMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -595,7 +595,7 @@ private: napi_value lastParam = (argc > 0) ? argv[0] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -636,7 +636,7 @@ private: napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -694,7 +694,7 @@ private: napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionsToForeground", env, + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionsToForeground", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -748,7 +748,7 @@ private: napi_value lastParam = (argc <= 1) ? nullptr : argv[1]; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionsToBackground", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionsToBackground", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } diff --git a/frameworks/js/napi/mission_manager/mission_manager.cpp b/frameworks/js/napi/mission_manager/mission_manager.cpp index b739c159d7..df2ffe01bf 100644 --- a/frameworks/js/napi/mission_manager/mission_manager.cpp +++ b/frameworks/js/napi/mission_manager/mission_manager.cpp @@ -182,7 +182,7 @@ private: napi_value lastParam = (argc <= 1) ? nullptr : argv[1]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnUnregisterMissionListener", + NapiAsyncTask::Schedule("MissionManager::OnUnregisterMissionListener", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -222,7 +222,7 @@ private: napi_value lastParam = (argc <= 2) ? nullptr : argv[2]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfos", + NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfos", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -262,7 +262,7 @@ private: napi_value lastParam = (argc <= 2) ? nullptr : argv[2]; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfo", + NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfo", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -323,7 +323,7 @@ private: }; napi_value lastParam = (argc > ARG_COUNT_TWO) ? argv[ARG_COUNT_TWO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("MissioManager::GetMissionSnapShot", + NapiAsyncTask::Schedule("MissionManager::GetMissionSnapShot", env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(excute), std::move(complete), &result)); return result; } @@ -379,7 +379,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnLockMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnLockMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -412,7 +412,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnUnlockMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnUnlockMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -445,7 +445,7 @@ private: napi_value lastParam = (argc > 1) ? argv[1] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnClearMission", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnClearMission", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -466,7 +466,7 @@ private: napi_value lastParam = (argc > 0) ? argv[0] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -507,7 +507,7 @@ private: napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront", + NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); return result; } diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index cc9163e41d..0abffa54cc 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -287,6 +287,18 @@ ohos_shared_library("abilitykit_native") { defines = [] + if (cj_frontend) { + sources += [ "${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_object.cpp" ] + include_dirs += [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/frameworks/cj/ffi", + ] + external_deps += [ + "napi:cj_bind_ffi", + "napi:cj_bind_native", + ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] @@ -545,6 +557,21 @@ ohos_shared_library("uiabilitykit_native") { "node:node_header_notice", ] + if (cj_frontend) { + sources += [ + "${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_object.cpp", + "${ability_runtime_native_path}/ability/native/ability_runtime/cj_ui_ability.cpp", + ] + + include_dirs += [ "${ability_runtime_path}/frameworks/cj/ffi" ] + + external_deps += [ + "napi:cj_bind_ffi", + "napi:cj_bind_native", + "window_manager:cj_window_ffi", + ] + } + if (ability_runtime_graphics) { external_deps += [ "ability_base:session_info", diff --git a/frameworks/native/ability/native/ability_runtime/cj_ability_object.cpp b/frameworks/native/ability/native/ability_runtime/cj_ability_object.cpp new file mode 100644 index 0000000000..c0eb908f9e --- /dev/null +++ b/frameworks/native/ability/native/ability_runtime/cj_ability_object.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ability_runtime/cj_ability_object.h" + +#include "hilog_wrapper.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +using WantHandle = void*; + +namespace { +// g_cjAbilityFuncs is used to save cj functions. +// It is assigned by the global variable REGISTER_ABILITY on the cj side which invokes RegisterCJAbilityFuncs. +// And it is never released. +CJAbilityFuncs* g_cjAbilityFuncs = nullptr; +} // namespace + +void RegisterCJAbilityFuncs(void (*registerFunc)(CJAbilityFuncs*)) +{ + HILOG_INFO("RegisterCJAbilityFuncs start."); + if (g_cjAbilityFuncs != nullptr) { + HILOG_ERROR("Repeated registration for cj functions of CJAbility."); + return; + } + + if (registerFunc == nullptr) { + HILOG_ERROR("RegisterCJAbilityFuncs failed, registerFunc is nullptr."); + return; + } + + g_cjAbilityFuncs = new CJAbilityFuncs(); + registerFunc(g_cjAbilityFuncs); + HILOG_INFO("RegisterCJAbilityFuncs end."); +} + +namespace OHOS { +namespace AbilityRuntime { +std::shared_ptr CJAbilityObject::LoadModule(const std::string& name) +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return nullptr; + } + auto id = g_cjAbilityFuncs->cjAbilityCreate(name.c_str()); + if (id == 0) { + HILOG_ERROR( + "Failed to invoke CJAbilityObject::LoadModule. Ability: %{public}s is not registered.", name.c_str()); + return nullptr; + } + return std::make_shared(id); +} + +CJAbilityObject::~CJAbilityObject() +{ + if (g_cjAbilityFuncs != nullptr) { + g_cjAbilityFuncs->cjAbilityRelease(id_); + } + id_ = 0; +} + +void CJAbilityObject::OnStart(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + WantHandle wantHandle = const_cast(&want); + CJLaunchParam param; + param.launchReason = launchParam.launchReason; + param.lastExitReason = launchParam.lastExitReason; + g_cjAbilityFuncs->cjAbilityOnStart(id_, wantHandle, param); +} + +void CJAbilityObject::OnStop() const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + g_cjAbilityFuncs->cjAbilityOnStop(id_); +} + +void CJAbilityObject::OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + WindowStagePtr windowStage = reinterpret_cast(cjWindowStage); + g_cjAbilityFuncs->cjAbilityOnSceneCreated(id_, windowStage); +} + +void CJAbilityObject::OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + WindowStagePtr windowStage = reinterpret_cast(cjWindowStage); + g_cjAbilityFuncs->cjAbilityOnSceneRestored(id_, windowStage); +} + +void CJAbilityObject::OnSceneDestroyed() const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + g_cjAbilityFuncs->cjAbilityOnSceneDestroyed(id_); +} + +void CJAbilityObject::OnForeground(const Want& want) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + WantHandle wantHandle = const_cast(&want); + g_cjAbilityFuncs->cjAbilityOnForeground(id_, wantHandle); +} + +void CJAbilityObject::OnBackground() const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + g_cjAbilityFuncs->cjAbilityOnBackground(id_); +} + +void CJAbilityObject::OnConfigurationUpdated(const std::shared_ptr& configuration) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } +} + +void CJAbilityObject::OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + WantHandle wantHandle = const_cast(&want); + CJLaunchParam param; + param.launchReason = launchParam.launchReason; + param.lastExitReason = launchParam.lastExitReason; + g_cjAbilityFuncs->cjAbilityOnNewWant(id_, wantHandle, param); +} + +void CJAbilityObject::Dump(const std::vector& params, std::vector& info) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + + VectorStringHandle paramHandle = const_cast*>(¶ms); + VectorStringHandle cjInfo = g_cjAbilityFuncs->cjAbilityDump(id_, paramHandle); + if (cjInfo == nullptr) { + HILOG_ERROR("CJ info nullptr"); + return; + } + + auto infoHandle = reinterpret_cast*>(cjInfo); + for (std::string item : *infoHandle) { + info.push_back(item); + } + // infoHandle is created in cj. + delete infoHandle; + infoHandle = nullptr; +} + +int32_t CJAbilityObject::OnContinue(AAFwk::WantParams& wantParams) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return ContinuationManager::OnContinueResult::REJECT; + } + return 0; +} + +void CJAbilityObject::Init(AbilityHandle ability) const +{ + if (g_cjAbilityFuncs == nullptr) { + HILOG_ERROR("CJ functions for CJAbility are not registered"); + return; + } + g_cjAbilityFuncs->cjAbilityInit(id_, ability); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp new file mode 100644 index 0000000000..2aa5aaa064 --- /dev/null +++ b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp @@ -0,0 +1,760 @@ +/* + * Copyright (c) 2024 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 "cj_ui_ability.h" + +#include +#include + +#include "ability_business_error.h" +#include "ability_delegator_registry.h" +#include "ability_recovery.h" +#include "ability_start_setting.h" +#include "app_recovery.h" +#include "context/application_context.h" +#include "connection_manager.h" +#include "context/context.h" +#include "hilog_wrapper.h" +#include "hitrace_meter.h" +#include "if_system_ability_manager.h" +#include "insight_intent_executor_info.h" +#include "insight_intent_executor_mgr.h" +#include "insight_intent_execute_param.h" +#include "cj_runtime.h" +#include "cj_ability_object.h" +#include "time_util.h" +#include "scene_board_judgement.h" +#include "string_wrapper.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +#ifdef SUPPORT_GRAPHICS +const std::string PAGE_STACK_PROPERTY_NAME = "pageStack"; +const std::string METHOD_NAME = "WindowScene::GoForeground"; +const std::string SUPPORT_CONTINUE_PAGE_STACK_PROPERTY_NAME = "ohos.extra.param.key.supportContinuePageStack"; +#endif +// Numerical base (radix) that determines the valid characters and their interpretation. +const int32_t BASE_DISPLAY_ID_NUM (10); +} + +UIAbility *CJUIAbility::Create(const std::unique_ptr &runtime) +{ + return new (std::nothrow) CJUIAbility(static_cast(*runtime)); +} + +CJUIAbility::CJUIAbility(CJRuntime &cjRuntime) : cjRuntime_(cjRuntime) +{ + HILOG_DEBUG("Called."); +} + +CJUIAbility::~CJUIAbility() +{ + HILOG_DEBUG("Called."); + if (abilityContext_ != nullptr) { + abilityContext_->Unbind(); + } +} + +void CJUIAbility::Init(std::shared_ptr record, + const std::shared_ptr application, std::shared_ptr &handler, + const sptr &token) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (record == nullptr) { + HILOG_ERROR("AbilityLocalRecord is nullptr."); + return; + } + auto abilityInfo = record->GetAbilityInfo(); + if (abilityInfo == nullptr) { + HILOG_ERROR("AbilityInfo is nullptr."); + return; + } + UIAbility::Init(record, application, handler, token); + +#ifdef SUPPORT_GRAPHICS + if (abilityContext_ != nullptr) { + AppExecFwk::AppRecovery::GetInstance().AddAbility( + shared_from_this(), abilityContext_->GetAbilityInfo(), abilityContext_->GetToken()); + } +#endif + SetAbilityContext(abilityInfo); +} + +void CJUIAbility::SetAbilityContext( + const std::shared_ptr &abilityInfo) +{ + if (!abilityInfo) { + HILOG_ERROR("abilityInfo is nullptr"); + return; + } + + cjAbilityObj_ = CJAbilityObject::LoadModule(abilityInfo->name); + if (!cjAbilityObj_) { + HILOG_ERROR("Failed to get CJAbility object."); + return; + } + cjAbilityObj_->Init(this); +} + +void CJUIAbility::OnStart(const Want &want, sptr sessionInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_INFO("Begin ability is %{public}s.", GetAbilityName().c_str()); + UIAbility::OnStart(want, sessionInfo); + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + std::string methodName = "OnStart"; + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + cjAbilityObj_->OnStart(want, GetLaunchParam()); + AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformStart."); + delegator->PostPerformStart(CreateADelegatorAbilityProperty()); + } + HILOG_INFO("End ability is %{public}s.", GetAbilityName().c_str()); +} + +void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const +{ + FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; + auto entry = std::to_string(TimeUtil::SystemTimeMillisecond()) + "; CJUIAbility::" + methodName + + "; the " + methodName + " begin."; + FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); +} + +void CJUIAbility::AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const +{ + FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; + auto entry = std::to_string(TimeUtil::SystemTimeMillisecond()) + "; CJUIAbility::" + methodName + + "; the " + methodName + " end."; + FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); +} + +int32_t CJUIAbility::OnShare(WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + return ERR_OK; +} + +void CJUIAbility::OnStop() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin."); + if (abilityContext_) { + HILOG_DEBUG("Set terminating true."); + abilityContext_->SetTerminating(true); + } + UIAbility::OnStop(); + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + cjAbilityObj_->OnStop(); + CJUIAbility::OnStopCallback(); + HILOG_DEBUG("End."); +} + +void CJUIAbility::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) +{ + if (callbackInfo == nullptr) { + isAsyncCallback = false; + OnStop(); + return; + } + + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin"); + if (abilityContext_) { + HILOG_DEBUG("Set terminating true."); + abilityContext_->SetTerminating(true); + } + + UIAbility::OnStop(); + cjAbilityObj_->OnStop(); + OnStopCallback(); + HILOG_DEBUG("End."); +} + +void CJUIAbility::OnStopCallback() +{ + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformStop."); + delegator->PostPerformStop(CreateADelegatorAbilityProperty()); + } + + bool ret = ConnectionManager::GetInstance().DisconnectCaller(AbilityContext::token_); + if (!ret) { + HILOG_ERROR("The service connection is disconnected."); + } + ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); + HILOG_DEBUG("The service connection is not disconnected."); +} + +#ifdef SUPPORT_GRAPHICS +void CJUIAbility::OnSceneCreated() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str()); + UIAbility::OnSceneCreated(); + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + + cjWindowStage_ = OHOS::Rosen::CJWindowStageImpl::CreateCJWindowStage(GetScene()); + if (!cjWindowStage_) { + HILOG_ERROR("Failed to create CJWindowStage object."); + return; + } + + { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "onWindowStageCreate"); + std::string methodName = "OnSceneCreated"; + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + cjAbilityObj_->OnSceneCreated(cjWindowStage_.get()); + AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + } + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformScenceCreated."); + delegator->PostPerformScenceCreated(CreateADelegatorAbilityProperty()); + } + + HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str()); +} + +void CJUIAbility::OnSceneRestored() +{ + UIAbility::OnSceneRestored(); + HILOG_DEBUG("called."); + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + + if (!cjWindowStage_) { + cjWindowStage_ = OHOS::Rosen::CJWindowStageImpl::CreateCJWindowStage(scene_); + if (!cjWindowStage_) { + HILOG_ERROR("Failed to create CJWindowStage object."); + return; + } + } + + cjAbilityObj_->OnSceneRestored(cjWindowStage_.get()); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformScenceRestored."); + delegator->PostPerformScenceRestored(CreateADelegatorAbilityProperty()); + } +} + +void CJUIAbility::OnSceneDestroyed() +{ + HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str()); + UIAbility::onSceneDestroyed(); + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + cjAbilityObj_->OnSceneDestroyed(); + + if (scene_ != nullptr) { + auto window = scene_->GetMainWindow(); + if (window != nullptr) { + HILOG_DEBUG("Call window UnregisterDisplayMoveListener."); + window->UnregisterDisplayMoveListener(abilityDisplayMoveListener_); + } + } + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call delegator PostPerformScenceDestroyed."); + delegator->PostPerformScenceDestroyed(CreateADelegatorAbilityProperty()); + } + HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str()); +} + +void CJUIAbility::OnForeground(const Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str()); + + UIAbility::OnForeground(want); + CallOnForegroundFunc(want); +} + +void CJUIAbility::CallOnForegroundFunc(const Want &want) +{ + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + std::string methodName = "OnForeground"; + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + cjAbilityObj_->OnForeground(want); + AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformForeground."); + delegator->PostPerformForeground(CreateADelegatorAbilityProperty()); + } + + HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str()); +} + +void CJUIAbility::OnBackground() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str()); + + UIAbility::OnBackground(); + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + std::string methodName = "OnBackground"; + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::BACKGROUND, methodName); + cjAbilityObj_->OnBackground(); + AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::BACKGROUND, methodName); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_DEBUG("Call PostPerformBackground."); + delegator->PostPerformBackground(CreateADelegatorAbilityProperty()); + } + + HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str()); +} + +bool CJUIAbility::OnBackPress() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str()); + UIAbility::OnBackPress(); + return true; +} + +bool CJUIAbility::OnPrepareTerminate() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str()); + UIAbility::OnPrepareTerminate(); + + return true; +} + +void CJUIAbility::GetPageStackFromWant(const Want &want, std::string &pageStack) +{ + auto stringObj = AAFwk::IString::Query(want.GetParams().GetParam(PAGE_STACK_PROPERTY_NAME)); + if (stringObj != nullptr) { + pageStack = AAFwk::String::Unbox(stringObj); + } +} + +bool CJUIAbility::IsRestorePageStack(const Want &want) +{ + return want.GetBoolParam(SUPPORT_CONTINUE_PAGE_STACK_PROPERTY_NAME, true); +} + +void CJUIAbility::RestorePageStack(const Want &want) +{ + if (IsRestorePageStack(want)) { + std::string pageStack; + GetPageStackFromWant(want, pageStack); + } +} + +void CJUIAbility::AbilityContinuationOrRecover(const Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + // multi-instance ability continuation + HILOG_DEBUG("Launch reason is %{public}d.", launchParam_.launchReason); + if (IsRestoredInContinuation()) { + RestorePageStack(want); + OnSceneRestored(); + NotifyContinuationResult(want, true); + } else if (ShouldRecoverState(want)) { + std::string pageStack = abilityRecovery_->GetSavedPageStack(AppExecFwk::StateReason::DEVELOPER_REQUEST); + OnSceneRestored(); + } else { + OnSceneCreated(); + } +} + +void CJUIAbility::DoOnForeground(const Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (scene_ == nullptr) { + if ((abilityContext_ == nullptr) || (sceneListener_ == nullptr)) { + HILOG_ERROR("AbilityContext or sceneListener_ is nullptr ."); + return; + } + scene_ = std::make_shared(); + InitSceneDoOnForeground(scene_, want); + } else { + auto window = scene_->GetMainWindow(); + if (window == nullptr) { + HILOG_ERROR("MainWindow is nullptr ."); + return; + } + if (want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) { + HILOG_ERROR("want has parameter PARAM_RESV_WINDOW_MODE."); + auto windowMode = want.GetIntParam( + Want::PARAM_RESV_WINDOW_MODE, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); + window->SetWindowMode(static_cast(windowMode)); + windowMode_ = windowMode; + HILOG_DEBUG("Set window mode is %{public}d .", windowMode); + } + } + + auto window = scene_->GetMainWindow(); + if (window == nullptr) { + HILOG_ERROR("MainWindow is nullptr ."); + return; + } + if (securityFlag_) { + window->SetSystemPrivacyMode(true); + } + + HILOG_INFO("Move scene to foreground, sceneFlag_: %{public}d .", UIAbility::sceneFlag_); + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME); + scene_->GoForeground(UIAbility::sceneFlag_); + HILOG_DEBUG("End."); +} + +void CJUIAbility::InitSceneDoOnForeground(std::shared_ptr scene, const Want &want) +{ + int32_t displayId = static_cast(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId()); + if (setting_ != nullptr) { + std::string strDisplayId = setting_->GetProperty(OHOS::AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY); + std::regex formatRegex("[0-9]{0,9}$"); + std::smatch sm; + bool flag = std::regex_match(strDisplayId, sm, formatRegex); + if (flag && !strDisplayId.empty()) { + displayId = strtol(strDisplayId.c_str(), nullptr, BASE_DISPLAY_ID_NUM); + HILOG_DEBUG("Success displayId is %{public}d .", displayId); + } else { + HILOG_ERROR("Failed to formatRegex: [%{public}s] .", strDisplayId.c_str()); + } + } + Rosen::WMError ret = Rosen::WMError::WM_OK; + auto option = GetWindowOption(want); + auto sessionToken = GetSessionToken(); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) { + abilityContext_->SetWeakSessionToken(sessionToken); + ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken); + } else { + ret = scene_->Init(displayId, abilityContext_, sceneListener_, option); + } + if (ret != Rosen::WMError::WM_OK) { + HILOG_ERROR("Failed to init window scene ."); + return; + } + + AbilityContinuationOrRecover(want); + auto window = scene_->GetMainWindow(); + if (window) { + HILOG_DEBUG("Call RegisterDisplayMoveListener, windowId: %{public}d .", window->GetWindowId()); + abilityDisplayMoveListener_ = new AbilityDisplayMoveListener(weak_from_this()); + if (abilityDisplayMoveListener_ == nullptr) { + HILOG_ERROR("abilityDisplayMoveListener_ is nullptr ."); + return; + } + window->RegisterDisplayMoveListener(abilityDisplayMoveListener_); + } +} + +void CJUIAbility::RequestFocus(const Want &want) +{ + HILOG_INFO("Lifecycle: begin ."); + if (scene_ == nullptr) { + HILOG_ERROR("scene_ is nullptr ."); + return; + } + auto window = scene_->GetMainWindow(); + if (window != nullptr && want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) { + auto windowMode = want.GetIntParam( + Want::PARAM_RESV_WINDOW_MODE, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); + window->SetWindowMode(static_cast(windowMode)); + HILOG_DEBUG("Set window mode is %{public}d .", windowMode); + } + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME); + scene_->GoForeground(UIAbility::sceneFlag_); + HILOG_INFO("Lifecycle: end ."); +} + +void CJUIAbility::ContinuationRestore(const Want &want) +{ + HILOG_DEBUG("Called ."); + if (!IsRestoredInContinuation() || scene_ == nullptr) { + HILOG_ERROR("Is not in continuation or scene_ is nullptr ."); + return; + } + RestorePageStack(want); + OnSceneRestored(); + NotifyContinuationResult(want, true); +} + +std::shared_ptr CJUIAbility::GetCJWindowStage() +{ + HILOG_DEBUG("Called."); + if (cjWindowStage_ == nullptr) { + HILOG_ERROR("CJWindowSatge is nullptr ."); + } + return cjWindowStage_; +} + +const CJRuntime &CJUIAbility::GetCJRuntime() +{ + return cjRuntime_; +} + +void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want, + const std::shared_ptr &executeParam, + std::unique_ptr callback) +{ + HILOG_DEBUG("called ."); + if (executeParam == nullptr) { + HILOG_WARN("Intention execute param invalid."); + RequestFocus(want); + InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK); + return; + } + + auto asyncCallback = [weak = weak_from_this(), want](InsightIntentExecuteResult result) { + HILOG_DEBUG("Begin request focus ."); + auto ability = weak.lock(); + if (ability == nullptr) { + HILOG_ERROR("ability is nullptr ."); + return; + } + ability->RequestFocus(want); + }; + callback->Push(asyncCallback); + + InsightIntentExecutorInfo executeInfo; + auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo); + if (!ret) { + HILOG_ERROR("Get Intention executor failed."); + InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), + static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + return; + } +} + +void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want, + const std::shared_ptr &executeParam, + std::unique_ptr callback) +{ + HILOG_DEBUG("called."); + if (executeParam == nullptr) { + HILOG_WARN("Intention execute param invalid."); + OnForeground(want); + InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK); + return; + } + + UIAbility::OnForeground(want); + + auto asyncCallback = [weak = weak_from_this(), want](InsightIntentExecuteResult result) { + HILOG_DEBUG("Begin call onForeground."); + auto ability = weak.lock(); + if (ability == nullptr) { + HILOG_ERROR("ability is nullptr."); + return; + } + ability->CallOnForegroundFunc(want); + }; + callback->Push(asyncCallback); + + InsightIntentExecutorInfo executeInfo; + auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo); + if (!ret) { + HILOG_ERROR("Get Intention executor failed."); + InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), + static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + return; + } +} + +bool CJUIAbility::GetInsightIntentExecutorInfo(const Want &want, + const std::shared_ptr &executeParam, + InsightIntentExecutorInfo& executeInfo) +{ + HILOG_DEBUG("called."); + auto context = GetAbilityContext(); + if (executeParam == nullptr || context == nullptr || abilityInfo_ == nullptr || cjWindowStage_ == nullptr) { + HILOG_ERROR("Param invalid."); + return false; + } + + const WantParams &wantParams = want.GetParams(); + executeInfo.srcEntry = wantParams.GetStringParam("ohos.insightIntent.srcEntry"); + executeInfo.hapPath = abilityInfo_->hapPath; + executeInfo.esmodule = abilityInfo_->compileMode == AppExecFwk::CompileMode::ES_MODULE; + executeInfo.windowMode = windowMode_; + executeInfo.token = context->GetToken(); + executeInfo.executeParam = executeParam; + return true; +} +#endif + +int32_t CJUIAbility::OnContinue(WantParams &wantParams) +{ + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return AppExecFwk::ContinuationManagerStage::OnContinueResult::REJECT; + } + auto res = cjAbilityObj_->OnContinue(wantParams); + HILOG_INFO("CJAbility::OnContinue end, return value is %{public}d", res); + + return res; +} + +int32_t CJUIAbility::OnSaveState(int32_t reason, WantParams &wantParams) +{ + return 0; +} + +void CJUIAbility::OnConfigurationUpdated(const Configuration &configuration) +{ + UIAbility::OnConfigurationUpdated(configuration); + HILOG_DEBUG("Called."); + auto fullConfig = GetAbilityContext()->GetConfiguration(); + if (!fullConfig) { + HILOG_ERROR("configuration is nullptr."); + return; + } + + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + + cjAbilityObj_->OnConfigurationUpdated(fullConfig); + HILOG_INFO("CJAbility::OnConfigurationUpdated end"); +} + +void CJUIAbility::OnMemoryLevel(int level) +{ + UIAbility::OnMemoryLevel(level); + HILOG_DEBUG("Called."); +} + +void CJUIAbility::UpdateContextConfiguration() +{ + HILOG_DEBUG("Called."); +} + +void CJUIAbility::OnNewWant(const Want &want) +{ + HILOG_DEBUG("Begin."); + UIAbility::OnNewWant(want); + +#ifdef SUPPORT_GRAPHICS + if (scene_) { + scene_->OnNewWant(want); + } +#endif + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + std::string methodName = "OnNewWant"; + AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + cjAbilityObj_->OnNewWant(want, GetLaunchParam()); + AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName); + + HILOG_DEBUG("End."); +} + +void CJUIAbility::OnAbilityResult(int requestCode, int resultCode, const Want &resultData) +{ + HILOG_DEBUG("Begin ."); + UIAbility::OnAbilityResult(requestCode, resultCode, resultData); + if (abilityContext_ == nullptr) { + HILOG_ERROR("abilityContext_ is nullptr ."); + return; + } + abilityContext_->OnAbilityResult(requestCode, resultCode, resultData); + HILOG_DEBUG("End ."); +} + +sptr CJUIAbility::CallRequest() +{ + return nullptr; +} + +std::shared_ptr CJUIAbility::CreateADelegatorAbilityProperty() +{ + if (abilityContext_ == nullptr) { + HILOG_ERROR("abilityContext_ is nullptr."); + return nullptr; + } + auto property = std::make_shared(); + property->token_ = abilityContext_->GetToken(); + property->name_ = GetAbilityName(); + property->moduleName_ = GetModuleName(); + if (GetApplicationInfo() == nullptr || GetApplicationInfo()->bundleName.empty()) { + property->fullName_ = GetAbilityName(); + } else { + std::string::size_type pos = GetAbilityName().find(GetApplicationInfo()->bundleName); + if (pos == std::string::npos || pos != 0) { + property->fullName_ = GetApplicationInfo()->bundleName + "." + GetAbilityName(); + } else { + property->fullName_ = GetAbilityName(); + } + } + property->lifecycleState_ = GetState(); + return property; +} + +void CJUIAbility::Dump(const std::vector ¶ms, std::vector &info) +{ + UIAbility::Dump(params, info); + HILOG_DEBUG("Called."); + if (!cjAbilityObj_) { + HILOG_ERROR("CJAbility is not loaded."); + return; + } + cjAbilityObj_->Dump(params, info); + HILOG_DEBUG("Dump info size: %{public}zu.", info.size()); +} + +std::shared_ptr CJUIAbility::GetCJAbility() +{ + HILOG_DEBUG("Called."); + if (cjAbilityObj_ == nullptr) { + HILOG_ERROR("cjAbility object is nullptr."); + } + return cjAbilityObj_; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp index d59c77b0d4..399977be42 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp @@ -27,6 +27,8 @@ constexpr const char *VIEW_DATA_BUNDLE_NAME = "bundleName"; constexpr const char *VIEW_DATA_MODULE_NAME = "moduleName"; constexpr const char *VIEW_DATA_ABILITY_NAME = "abilityName"; constexpr const char *VIEW_DATA_PAGEURL = "pageUrl"; +constexpr const char *VIEW_DATA_USER_SELECTED = "isUserSelected"; +constexpr const char *VIEW_DATA_OTHER_ACCOUNT = "isOtherAccount"; constexpr const char *VIEW_DATA_PAGE_NODE_INFOS = "pageNodeInfos"; constexpr const char *VIEW_DATA_VIEW_DATA = "viewData"; constexpr const char *VIEW_DATA_TYPE = "type"; @@ -73,6 +75,12 @@ napi_value JsAutoFillExtensionUtil::WrapViewData(const napi_env env, const Abili jsValue = WrapStringToJS(env, viewData.pageUrl); SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_PAGEURL, jsValue); + jsValue = WrapBoolToJS(env, viewData.isUserSelected); + SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_USER_SELECTED, jsValue); + + jsValue = WrapBoolToJS(env, viewData.isOtherAccount); + SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_OTHER_ACCOUNT, jsValue); + napi_value jsArray = nullptr; NAPI_CALL(env, napi_create_array(env, &jsArray)); napi_value jsSubValue = nullptr; @@ -183,6 +191,8 @@ void JsAutoFillExtensionUtil::UnwrapViewData( viewData.abilityName = UnwrapStringFromJS(env, jsValue, ""); jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_PAGEURL, napi_string); viewData.pageUrl = UnwrapStringFromJS(env, jsValue, ""); + UnwrapBooleanByPropertyName(env, jsViewData, VIEW_DATA_USER_SELECTED, viewData.isUserSelected); + UnwrapBooleanByPropertyName(env, jsViewData, VIEW_DATA_OTHER_ACCOUNT, viewData.isOtherAccount); jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_PAGE_NODE_INFOS, napi_object); if (jsValue != nullptr) { uint32_t jsProCount = 0; diff --git a/frameworks/native/ability/native/child_process_manager/native_child_ipc_process.cpp b/frameworks/native/ability/native/child_process_manager/native_child_ipc_process.cpp index 905c32a4b9..29b4bdc376 100644 --- a/frameworks/native/ability/native/child_process_manager/native_child_ipc_process.cpp +++ b/frameworks/native/ability/native/child_process_manager/native_child_ipc_process.cpp @@ -54,7 +54,7 @@ bool NativeChildIpcProcess::Init(const std::shared_ptr &i } if (!LoadNativeLib(info)) { - iNotify->OnError(static_cast(ChildProcessManagerErrorCode::ERR_NATIVE_CHILD_PROCESS_LOAD_LIB)); + iNotify->OnError(static_cast(ChildProcessManagerErrorCode::ERR_LIB_LOADING_FAILED)); return false; } @@ -73,7 +73,7 @@ void NativeChildIpcProcess::OnStart() OHIPCRemoteStub *ipcStub = funcNativeLibOnConnect_(); if (ipcStub == nullptr || ipcStub->remote == nullptr) { TAG_LOGE(AAFwkTag::PROCESSMGR, "Native lib OnConnect function return null stub"); - mainProcessCb_->OnError(static_cast(ChildProcessManagerErrorCode::ERR_NATIVE_CHILD_PROCESS_CONNECT)); + mainProcessCb_->OnError(static_cast(ChildProcessManagerErrorCode::ERR_CONNECTION_FAILED)); return; } diff --git a/frameworks/native/ability/native/ui_ability.cpp b/frameworks/native/ability/native/ui_ability.cpp index 9b81b97cf3..08d64fb6e6 100644 --- a/frameworks/native/ability/native/ui_ability.cpp +++ b/frameworks/native/ability/native/ui_ability.cpp @@ -23,6 +23,7 @@ #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "js_ui_ability.h" +#include "cj_ui_ability.h" #include "ohos_application.h" #include "reverse_continuation_scheduler_primary_stage.h" #include "runtime.h" @@ -54,6 +55,8 @@ UIAbility *UIAbility::Create(const std::unique_ptr &runtime) switch (runtime->GetLanguage()) { case Runtime::Language::JS: return JsUIAbility::Create(runtime); + case Runtime::Language::CJ: + return CJUIAbility::Create(runtime); default: return new (std::nothrow) UIAbility(); } diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp index e2c4ff5c40..14460d7aa1 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp @@ -887,7 +887,7 @@ napi_value JsUIExtensionContentSession::OnStartAbilityByType(napi_env env, NapiC } bool JsUIExtensionContentSession::CheckStartAbilityByTypeParam(napi_env env, - NapiCallbackInfo& info, std::string type, AAFwk::WantParams wantParam) + NapiCallbackInfo& info, std::string& type, AAFwk::WantParams& wantParam) { TAG_LOGI(AAFwkTag::UI_EXT, "start"); diff --git a/frameworks/native/child_process/src/native_child_process.cpp b/frameworks/native/child_process/src/native_child_process.cpp index d5036d7b8e..f87e4a8562 100644 --- a/frameworks/native/child_process/src/native_child_process.cpp +++ b/frameworks/native/child_process/src/native_child_process.cpp @@ -26,20 +26,20 @@ using namespace OHOS::AbilityRuntime; namespace { -std::mutex g_MutexCallBackObj; +std::mutex g_mutexCallBackObj; sptr g_CallbackStub; OH_Ability_OnNativeChildProcessStarted g_Callback = nullptr; const std::map CPM_ERRCODE_MAP = { - { ChildProcessManagerErrorCode::ERR_OK, NCP_NOERROR }, + { ChildProcessManagerErrorCode::ERR_OK, NCP_NO_ERROR }, { ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED, NCP_ERR_MULTI_PROCESS_DISABLED }, { ChildProcessManagerErrorCode::ERR_ALREADY_IN_CHILD_PROCESS, NCP_ERR_ALREADY_IN_CHILD }, - { ChildProcessManagerErrorCode::ERR_GET_APP_MGR_FAILED, NCP_ERR_SERVICE }, - { ChildProcessManagerErrorCode::ERR_GET_APP_MGR_START_PROCESS_FAILED, NCP_ERR_SERVICE }, + { ChildProcessManagerErrorCode::ERR_GET_APP_MGR_FAILED, NCP_ERR_SERVICE_ERROR }, + { ChildProcessManagerErrorCode::ERR_GET_APP_MGR_START_PROCESS_FAILED, NCP_ERR_SERVICE_ERROR }, { ChildProcessManagerErrorCode::ERR_UNSUPPORT_NATIVE_CHILD_PROCESS, NCP_ERR_NOT_SUPPORTED }, { ChildProcessManagerErrorCode::ERR_MAX_NATIVE_CHILD_PROCESSES, NCP_ERR_MAX_CHILD_PROCESSES_REACHED }, - { ChildProcessManagerErrorCode::ERR_NATIVE_CHILD_PROCESS_LOAD_LIB, NCP_ERR_CHILD_PROCESS_LOAD_LIB }, - { ChildProcessManagerErrorCode::ERR_NATIVE_CHILD_PROCESS_CONNECT, NCP_ERR_CHILD_PROCESS_CONNECT }, + { ChildProcessManagerErrorCode::ERR_LIB_LOADING_FAILED, NCP_ERR_LIB_LOADING_FAILED }, + { ChildProcessManagerErrorCode::ERR_CONNECTION_FAILED, NCP_ERR_CONNECTION_FAILED }, }; int CvtChildProcessManagerErrCode(ChildProcessManagerErrorCode cpmErr) @@ -54,7 +54,7 @@ int CvtChildProcessManagerErrCode(ChildProcessManagerErrorCode cpmErr) void OnNativeChildProcessStartedWapper(int errCode, OHIPCRemoteProxy *ipcProxy) { - std::unique_lock autoLock(g_MutexCallBackObj); + std::unique_lock autoLock(g_mutexCallBackObj); if (g_Callback != nullptr) { g_Callback(CvtChildProcessManagerErrCode(static_cast(errCode)), ipcProxy); g_Callback = nullptr; @@ -80,7 +80,7 @@ int OH_Ability_CreateNativeChildProcess(const char* libName, OH_Ability_OnNative return NCP_ERR_INVALID_PARAM; } - std::unique_lock autoLock(g_MutexCallBackObj); + std::unique_lock autoLock(g_mutexCallBackObj); if (g_Callback != nullptr || g_CallbackStub != nullptr) { TAG_LOGW(AAFwkTag::PROCESSMGR, "Another native process process starting, try again later"); return NCP_ERR_BUSY; @@ -100,5 +100,5 @@ int OH_Ability_CreateNativeChildProcess(const char* libName, OH_Ability_OnNative g_Callback = onProcessStarted; g_CallbackStub = callbackStub; - return NCP_NOERROR; + return NCP_NO_ERROR; } diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 588daf9a4f..a53087f916 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -95,7 +95,7 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) void* handle = nullptr; for (const auto& libPath : appLibPaths) { for (auto& itor : std::filesystem::directory_iterator(libPath)) { - // According to the convention, the names of Cangjie generated products must contain the following keywords + // According to the convention, the names of cj generated products must contain the following keywords if (itor.path().string().find("ohos_app_cangjie") == std::string::npos) { continue; } diff --git a/frameworks/native/runtime/js_error_utils.cpp b/frameworks/native/runtime/js_error_utils.cpp index 32be7a3044..b9993ef2d7 100755 --- a/frameworks/native/runtime/js_error_utils.cpp +++ b/frameworks/native/runtime/js_error_utils.cpp @@ -36,7 +36,7 @@ void ThrowError(napi_env env, const AbilityErrorCode& err) napi_throw(env, CreateJsError(env, static_cast(err), GetErrorMsg(err))); } -void ThrowInvaildCallerError(napi_env env) +void ThrowInvalidCallerError(napi_env env) { napi_throw(env, CreateJsError(env, static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CALLER), diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 71badbb21f..c512aa819c 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -514,6 +514,11 @@ enum { * Result(2097251) not support twin. */ ERR_MULTI_APP_NOT_SUPPORTED, + + /** + * Result(2097252) for unlock screen failed in developer mode. + */ + ERR_UNLOCK_SCREEN_FAILED_IN_DEVELOPER_MODE, }; enum { diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_host.h b/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_host.h index 64d8e70eae..b80157a978 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_host.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_host.h @@ -62,12 +62,19 @@ public: * @param bundleInfos resident process bundle infos. */ virtual void NotifyStartResidentProcess(std::vector &bundleInfos) override; + + /** + * @brief Notify abilityms app process OnRemoteDied + * @param abilityTokens abilities in died process. + */ + virtual void OnAppRemoteDied(const std::vector> &abilityTokens) override; private: int32_t HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply); int32_t HandleOnAbilityRequestDone(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyConfigurationChange(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyStartResidentProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnAppRemoteDied(MessageParcel &data, MessageParcel &reply); using AppStateCallbackFunc = int32_t (AppStateCallbackHost::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_proxy.h index b464a65a54..1995ea5668 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_state_callback_proxy.h @@ -57,6 +57,12 @@ public: */ virtual void NotifyStartResidentProcess(std::vector &bundleInfos) override; + /** + * @brief Notify abilityms app process OnRemoteDied + * @param abilityTokens abilities in died process. + */ + virtual void OnAppRemoteDied(const std::vector> &abilityTokens) override; + private: bool WriteInterfaceToken(MessageParcel &data); static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/iapp_state_callback.h b/interfaces/inner_api/app_manager/include/appmgr/iapp_state_callback.h index 938104b90f..767fd95b98 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/iapp_state_callback.h +++ b/interfaces/inner_api/app_manager/include/appmgr/iapp_state_callback.h @@ -63,11 +63,18 @@ public: */ virtual void NotifyStartResidentProcess(std::vector &bundleInfos) {} + /** + * @brief Notify abilityms app process OnRemoteDied + * @param abilityTokens abilities in died process. + */ + virtual void OnAppRemoteDied(const std::vector> &abilityTokens) {} + enum class Message { TRANSACT_ON_APP_STATE_CHANGED = 0, TRANSACT_ON_ABILITY_REQUEST_DONE, TRANSACT_ON_NOTIFY_CONFIG_CHANGE, - TRANSACT_ON_NOTIFY_START_RESIDENT_PROCESS + TRANSACT_ON_NOTIFY_START_RESIDENT_PROCESS, + TRANSACT_ON_APP_REMOTE_DIED }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_host.cpp index 42779c87e0..e71dbf28c5 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_host.cpp @@ -38,6 +38,8 @@ AppStateCallbackHost::AppStateCallbackHost() &AppStateCallbackHost::HandleNotifyConfigurationChange; memberFuncMap_[static_cast(IAppStateCallback::Message::TRANSACT_ON_NOTIFY_START_RESIDENT_PROCESS)] = &AppStateCallbackHost::HandleNotifyStartResidentProcess; + memberFuncMap_[static_cast(IAppStateCallback::Message::TRANSACT_ON_APP_REMOTE_DIED)] = + &AppStateCallbackHost::HandleOnAppRemoteDied; } AppStateCallbackHost::~AppStateCallbackHost() @@ -87,6 +89,11 @@ void AppStateCallbackHost::NotifyStartResidentProcess(std::vector> &abilityTokens) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); +} + int32_t AppStateCallbackHost::HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); @@ -143,5 +150,25 @@ int32_t AppStateCallbackHost::HandleNotifyStartResidentProcess(MessageParcel &da NotifyStartResidentProcess(bundleInfos); return NO_ERROR; } + +int32_t AppStateCallbackHost::HandleOnAppRemoteDied(MessageParcel &data, MessageParcel &reply) +{ + std::vector> abilityTokens; + int32_t infoSize = data.ReadInt32(); + if (infoSize > CYCLE_LIMIT) { + TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large"); + return ERR_INVALID_VALUE; + } + for (int32_t i = 0; i < infoSize; i++) { + sptr obj = data.ReadRemoteObject(); + if (!obj) { + TAG_LOGE(AAFwkTag::APPMGR, "Read token failed."); + return ERR_INVALID_VALUE; + } + abilityTokens.emplace_back(obj); + } + OnAppRemoteDied(abilityTokens); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_proxy.cpp index 25f37a9e6d..1636c1c45e 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_state_callback_proxy.cpp @@ -138,6 +138,35 @@ void AppStateCallbackProxy::NotifyStartResidentProcess(std::vector> &abilityTokens) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed"); + return; + } + + if (!data.WriteInt32(abilityTokens.size())) { + TAG_LOGE(AAFwkTag::APPMGR, "write token size failed."); + return; + } + + for (auto &token : abilityTokens) { + if (!data.WriteRemoteObject(token.GetRefPtr())) { + TAG_LOGE(AAFwkTag::APPMGR, "write token failed"); + return; + } + } + auto ret = SendTransactCmd( + static_cast(IAppStateCallback::Message::TRANSACT_ON_APP_REMOTE_DIED), + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + } +} + int32_t AppStateCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h b/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h index 18c572d1ea..93e28ccfdf 100644 --- a/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h +++ b/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h @@ -33,8 +33,8 @@ enum class ChildProcessManagerErrorCode { ERR_GET_APP_MGR_START_PROCESS_FAILED = 7, ERR_UNSUPPORT_NATIVE_CHILD_PROCESS = 8, ERR_MAX_NATIVE_CHILD_PROCESSES = 9, - ERR_NATIVE_CHILD_PROCESS_LOAD_LIB = 10, - ERR_NATIVE_CHILD_PROCESS_CONNECT = 11, + ERR_LIB_LOADING_FAILED = 10, + ERR_CONNECTION_FAILED = 11, }; const std::map INTERNAL_ERR_CODE_MAP = { diff --git a/interfaces/inner_api/runtime/include/js_error_utils.h b/interfaces/inner_api/runtime/include/js_error_utils.h index 9388851313..731f18a59b 100755 --- a/interfaces/inner_api/runtime/include/js_error_utils.h +++ b/interfaces/inner_api/runtime/include/js_error_utils.h @@ -24,7 +24,7 @@ namespace AbilityRuntime { void ThrowError(napi_env env, int32_t errCode, const std::string& errorMsg = ""); void ThrowError(napi_env env, const AbilityErrorCode& err); -void ThrowInvaildCallerError(napi_env env); +void ThrowInvalidCallerError(napi_env env); void ThrowTooFewParametersError(napi_env env); void ThrowInvalidNumParametersError(napi_env env); void ThrowNoPermissionError(napi_env env, const std::string& permission); diff --git a/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h b/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h index 85301c6a59..60ab59bc0f 100644 --- a/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h +++ b/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h @@ -13,15 +13,27 @@ * limitations under the License. */ -#ifndef OHOS_C_ABILITY_RUNTIME_NATIVE_CHILD_PROCESS_H -#define OHOS_C_ABILITY_RUNTIME_NATIVE_CHILD_PROCESS_H +#ifndef OHOS_ABILITY_RUNTIME_C_NATIVE_CHILD_PROCESS_H +#define OHOS_ABILITY_RUNTIME_C_NATIVE_CHILD_PROCESS_H #include "ipc_cparcel.h" +/** + * @addtogroup ChildProcess + * @{ + * + * @brief Provides the APIs to manage child processes. + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 12 + */ + /** * @file native_child_process.h * - * @brief Defines the functions for native child process management. + * @brief Declares the APIs used to create a native child process and establish an IPC channel between the parent and + * child processes. + * * @library libchild_process.so * @syscap SystemCapability.Ability.AbilityRuntime.Core * @since 12 @@ -32,104 +44,128 @@ extern "C" { #endif /** - * @brief native child process error code + * @brief Enumerates the error codes used by the native child process module. * @since 12 */ -enum Ability_NativeChildProcess_ErrCode { +typedef enum Ability_NativeChildProcess_ErrCode { /** - * @error The operation completed successfully + * @error Operation successful. */ - NCP_NOERROR = 0, + NCP_NO_ERROR = 0, /** - * @error Invalid param + * @error Invalid parameter. */ NCP_ERR_INVALID_PARAM = 401, /** - * @error Unsupport start native process + * @error Creating a native child process is not supported. */ NCP_ERR_NOT_SUPPORTED = 801, /** - * @error Internal error + * @error Internal error. */ NCP_ERR_INTERNAL = 16000050, /** - * @error Can not start another during child process startup, try again after current child process started + * @error A new child process cannot be created during the startup of another native child process. + * You can try again after the child process is started. */ NCP_ERR_BUSY = 16010001, /** - * @error Start native child time out + * @error Starting the native child process times out. */ NCP_ERR_TIMEOUT = 16010002, /** - * @error Service process error + * @error Server error. */ - NCP_ERR_SERVICE = 16010003, + NCP_ERR_SERVICE_ERROR = 16010003, /** - * @error Multi process disabled, can not start child process + * @error The multi-process mode is disabled. A child process cannot be started. */ NCP_ERR_MULTI_PROCESS_DISABLED = 16010004, /** - * @error Already in child process, only main process can start child + * @error A process cannot be created in a child process. */ NCP_ERR_ALREADY_IN_CHILD = 16010005, /** - * @error Max native child processes reached, can not start another + * @error The number of native child processes reaches the maximum. */ NCP_ERR_MAX_CHILD_PROCESSES_REACHED = 16010006, /** - * @error Child process load library failed + * @error The child process fails to load the dynamic library because the file does not exist + * or the corresponding method is not implemented or exported. */ - NCP_ERR_CHILD_PROCESS_LOAD_LIB = 16010007, + NCP_ERR_LIB_LOADING_FAILED = 16010007, /** - * @error Faild to invoke OnConnect method in library + * @error The child process fails to call the OnConnect method of the dynamic library. + * An invalid IPC object pointer may be returned. */ - NCP_ERR_CHILD_PROCESS_CONNECT = 16010008, -}; + NCP_ERR_CONNECTION_FAILED = 16010008, +} Ability_NativeChildProcess_ErrCode; /** - * @brief callback function for notify the child process start result, see OH_Ability_CreateNativeChildProcess + * @brief Defines a callback function for notifying the child process startup result. * - * @param errCode Zero if successful, an error otherwise, see Ability_NativeChildProcess_ErrCode for detail - * @param remoteProxy IPC object implemented in the sharded lib loaded by child process; will be nullptr when failed + * @param errCode Error code corresponding to the callback function. The following values are available: + * {@link NCP_NO_ERROR} if the child process is created successfully.\n + * {@link NCP_ERR_LIB_LOADING_FAILED} if loading the dynamic library file fails or the necessary export function + * is not implemented in the dynamic library.\n + * {@link NCP_ERR_CONNECTION_FAILED} if the OnConnect method implemented in the dynamic library does not return + * a valid IPC stub pointer.\n + * For details, see {@link Ability_NativeChildProcess_ErrCode}. + * @param remoteProxy Pointer to the IPC object of the child process. If an exception occurs, the value may be nullptr. + * The object must be released by calling {@link OH_IPCRemoteProxy_Destory} when it is no longer needed. + * @see OH_Ability_CreateNativeChildProcess + * @see OH_IPCRemoteProxy_Destory * @since 12 */ typedef void (*OH_Ability_OnNativeChildProcessStarted)(int errCode, OHIPCRemoteProxy *remoteProxy); /** - * @brief Create native child process for app and load shared library specified by param, - * process startup result is asynchronously notified via callback - * Lib file must be implemented and exported follow functions: - * 1. OHIPCRemoteStub* NativeChildProcess_OnConnect() - * 2. void NativeChildProcess_MainProc() + * @brief Creates a child process, loads the specified dynamic library file, and returns the startup result + * asynchronously through a callback parameter. + * The callback notification is an independent thread. When implementing the callback function, + * pay attention to thread synchronization and do not perform time-consuming operations to avoid long-time blocking. * - * Processing logic be like follows: - * Main Process: - * 1. Call OH_Ability_CreateNativeChildProcess(libName, onProcessStartedCallback) - * Child Process: - * 2. dlopen(libName) - * 3. dlsym("NativeChildProcess_OnConnect") & dlsym("NativeChildProcess_MainProc") - * 4. ipcRemote = NativeChildProcess_OnConnect() - * 5. NativeChildProcess_MainProc() - * Main Process: - * 6. onProcessStartedCallback(ipcRemote, errCode) - * Child Process: - * 7. Process exit after NativeChildProcess_MainProc() method returned + * The dynamic library specified must implement and export the following functions:\n + * 1. OHIPCRemoteStub* NativeChildProcess_OnConnect()\n + * 2. void NativeChildProcess_MainProc()\n * - * @param libName Name of the library file loaded by child process, can not be nullptr - * @param onProcessStarted Callback for notify the child process start result - * @return Zero if successful, an error otherwise, see Ability_NativeChildProcess_ErrCode for detail + * The processing logic sequence is shown in the following pseudocode: \n + * Main process: \n + * 1. OH_Ability_CreateNativeChildProcess(libName, onProcessStartedCallback)\n + * Child process: \n + * 2. dlopen(libName)\n + * 3. dlsym("NativeChildProcess_OnConnect")\n + * 4. dlsym("NativeChildProcess_MainProc")\n + * 5. ipcRemote = NativeChildProcess_OnConnect()\n + * 6. NativeChildProcess_MainProc()\n + * Main process: \n + * 7. onProcessStartedCallback(ipcRemote, errCode)\n + * Child process: \n + * 8. The child process exits after the NativeChildProcess_MainProc() function is returned. \n + * + * @param libName Name of the dynamic library file loaded in the child process. The value cannot be nullptr. + * @param onProcessStarted Pointer to the callback function for notifying the child process startup result. + * The value cannot be nullptr. For details, see {@link OH_Ability_OnNativeChildProcessStarted}. + * @return Returns {@link NCP_NO_ERROR} if the call is successful, but the actual startup result is notified by the + * callback function.\n + * Returns {@link NCP_ERR_INVALID_PARAM} if the dynamic library name or callback function pointer is invalid.\n + * Returns {@link NCP_ERR_NOT_SUPPORTED} if the device does not support the creation of native child processes.\n + * Returns {@link NCP_ERR_MULTI_PROCESS_DISABLED} if the multi-process mode is disabled on the device.\n + * Returns {@link NCP_ERR_ALREADY_IN_CHILD} if it is not allowed to create another child process in the child process.\n + * Returns {@link NCP_ERR_MAX_CHILD_PROCESSES_REACHED} if the maximum number of native child processes is reached.\n + * For details, see {@link Ability_NativeChildProcess_ErrCode}. * @see OH_Ability_OnNativeChildProcessStarted * @since 12 */ @@ -141,4 +177,5 @@ int OH_Ability_CreateNativeChildProcess(const char* libName, } // extern "C" #endif -#endif // OHOS_C_ABILITY_RUNTIME_NATIVE_CHILD_PROCESS_H +/** @} */ +#endif // OHOS_ABILITY_RUNTIME_C_NATIVE_CHILD_PROCESS_H diff --git a/interfaces/kits/native/ability/native/ability_runtime/cj_ability_object.h b/interfaces/kits/native/ability/native/ability_runtime/cj_ability_object.h new file mode 100644 index 0000000000..8ea7a9c24c --- /dev/null +++ b/interfaces/kits/native/ability/native/ability_runtime/cj_ability_object.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_CJ_ABILITY_OBJECT_H +#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_OBJECT_H + +#include + +#include "ability.h" +#include "cj_runtime.h" +#include "configuration.h" + +#ifdef WINDOWS_PLATFORM +#define CJ_EXPORT __declspec(dllexport) +#else +#define CJ_EXPORT __attribute__((visibility("default"))) +#endif + +using AbilityHandle = void*; +using WantHandle = void*; +using WindowStagePtr = void*; +using VectorStringHandle = void*; + +extern "C" { +struct CJConfiguration { + bool isValid; + const char* language; + int32_t colorMode; + int32_t direction; + int32_t screenDensity; + int32_t displayId; +}; +} + +extern "C" { +struct CJLaunchParam { + int32_t launchReason; + int32_t lastExitReason; +}; + +struct CJAbilityFuncs { + int64_t (*cjAbilityCreate)(const char* name); + void (*cjAbilityRelease)(int64_t id); + void (*cjAbilityOnStart)(int64_t id, WantHandle want, CJLaunchParam launchParam); + void (*cjAbilityOnStop)(int64_t id); + void (*cjAbilityOnSceneCreated)(int64_t id, WindowStagePtr cjWindowStage); + void (*cjAbilityOnSceneRestored)(int64_t id, WindowStagePtr cjWindowStage); + void (*cjAbilityOnSceneDestroyed)(int64_t id); + void (*cjAbilityOnForeground)(int64_t id, WantHandle want); + void (*cjAbilityOnBackground)(int64_t id); + void (*cjAbilityOnConfigurationUpdated)(int64_t id, CJConfiguration configuration); + void (*cjAbilityOnNewWant)(int64_t id, WantHandle want, CJLaunchParam launchParam); + VectorStringHandle (*cjAbilityDump)(int64_t id, VectorStringHandle params); + int32_t (*cjAbilityOnContinue)(int64_t id, const char* params); + void (*cjAbilityInit)(int64_t id, void* ability); +}; + +CJ_EXPORT void RegisterCJAbilityFuncs(void (*registerFunc)(CJAbilityFuncs*)); +} + +namespace OHOS { + +namespace Rosen { +class CJWindowStageImpl; +} + +namespace AbilityRuntime { +class CJAbilityObject { +public: + static std::shared_ptr LoadModule(const std::string& name); + + explicit CJAbilityObject(int64_t id) : id_(id) {} + ~CJAbilityObject(); + void OnStart(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const; + void OnStop() const; + void OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const; + void OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const; + void OnSceneDestroyed() const; + void OnForeground(const AAFwk::Want& want) const; + void OnBackground() const; + void OnConfigurationUpdated(const std::shared_ptr& configuration) const; + void OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const; + void Dump(const std::vector& params, std::vector& info) const; + int32_t OnContinue(AAFwk::WantParams &wantParams) const; + void Init(AbilityHandle ability) const; + +private: + int64_t id_ = 0; +}; +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_CJ_ABILITY_PROXY_H diff --git a/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h b/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h new file mode 100644 index 0000000000..1d6bf47186 --- /dev/null +++ b/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_CJ_UI_ABILITY_H +#define OHOS_ABILITY_RUNTIME_CJ_UI_ABILITY_H + +#include "ability_delegator_infos.h" +#include "freeze_util.h" +#include "ui_ability.h" +#ifdef SUPPORT_GRAPHICS +#include "window_stage_impl.h" +#endif + +namespace OHOS { + +namespace AbilityRuntime { +class CJRuntime; +class CJAbilityObject; +struct InsightIntentExecutorInfo; +using AbilityHandler = AppExecFwk::AbilityHandler; +using AbilityInfo = AppExecFwk::AbilityInfo; +using OHOSApplication = AppExecFwk::OHOSApplication; +using Want = AppExecFwk::Want; +using AbilityStartSetting = AppExecFwk::AbilityStartSetting; +using Configuration = AppExecFwk::Configuration; +using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult; +using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam; +using InsightIntentExecutorAsyncCallback = AppExecFwk::InsightIntentExecutorAsyncCallback; + +class CJUIAbility : public UIAbility { +public: + /** + * @brief Create a JsUIAbility instance through the singleton pattern + * @param runtime The runtime of the ability + * @return Returns the JsUIability Instance point + */ + static UIAbility *Create(const std::unique_ptr &runtime); + + explicit CJUIAbility(CJRuntime &cjRuntime); + ~CJUIAbility() override; + + /** + * @brief Init the UIability + * @param abilityInfo Indicate the Ability information + * @param ohosAppObject Indicates the main process + * @param handler the UIability EventHandler object + * @param token the remote token + */ + void Init(std::shared_ptr record, + const std::shared_ptr application, + std::shared_ptr &handler, const sptr &token) override; + + /** + * @brief OnStart,Start JsUIability + * @param want Indicates the {@link Want} structure containing startup information about the ability + * @param sessionInfo Indicates the sessionInfo + */ + void OnStart(const Want &want, sptr sessionInfo = nullptr) override; + + /** + * @brief Called when this ability enters the STATE_STOP state. + * The ability in the STATE_STOP is being destroyed. + * You can override this function to implement your own processing logic. + */ + void OnStop() override; + + /** + * @brief Called when this ability enters the STATE_STOP state. + * The ability in the STATE_STOP is being destroyed. + * You can override this function to implement your own processing logic. + * @param callbackInfo Indicates the lifecycle transaction callback information + * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback + */ + void OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) override; + + /** + * @brief The callback of OnStop. + */ + void OnStopCallback() override; + + /** + * @brief Prepare user data of local Ability. + * @param wantParams Indicates the user data to be saved. + * @return If the ability is willing to continue and data saved successfully, it returns 0; + * otherwise, it returns errcode. + */ + int32_t OnContinue(WantParams &wantParams) override; + + /** + * @brief Update configuration + * @param configuration Indicates the updated configuration information. + */ + void OnConfigurationUpdated(const Configuration &configuration) override; + + /** + * @brief Update Contextconfiguration + */ + void UpdateContextConfiguration() override; + + /** + * @brief Called when the system configuration is updated. + * @param level Indicates the memory trim level, which shows the current memory usage status. + */ + void OnMemoryLevel(int level) override; + + /** + * @brief Called when the launch mode of an ability is set to singleInstance. This happens when you re-launch an + * ability that has been at the top of the ability stack. + * @param want Indicates the new Want containing information about the ability. + */ + void OnNewWant(const Want &want) override; + + /** + * @brief Prepare user data of local Ability. + * @param reason the reason why framework invoke this function + * @param wantParams Indicates the user data to be saved. + * @return result code defined in abilityConstants + */ + int32_t OnSaveState(int32_t reason, WantParams &wantParams) override; + + /** + * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int) is called to start an ability and the + * result is returned. This method is called only on Page abilities. You can start a new ability to perform some + * calculations and use setResult (int,ohos.aafwk.content.Want) to return the calculation result. Then the system + * calls back the current method to use the returned data to execute its own logic. + * @param requestCode Indicates the request code returned after the ability is started. You can define the request + * code to identify the results returned by abilities. The value ranges from 0 to 65535. + * @param resultCode Indicates the result code returned after the ability is started. You can define the result code + * to identify an error. + * @param want Indicates the data returned after the ability is started. You can define the data returned. The + * value can be null. + */ + void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override; + + /** + * @brief request a remote object of callee from this ability. + * @return Returns the remote object of callee. + */ + sptr CallRequest() override; + + /** + * @brief dump ability info + * @param params dump params that indicate different dump targets + * @param info dump ability info + */ + void Dump(const std::vector ¶ms, std::vector &info) override; + + std::shared_ptr GetCJAbility(); + + /** + * @brief Callback when the ability is shared.You can override this function to implement your own sharing logic. + * @param wantParams Indicates the user data to be saved. + * @return the result of OnShare + */ + int32_t OnShare(WantParams &wantParams) override; + +#ifdef SUPPORT_GRAPHICS +public: + /** + * @brief Called after instantiating WindowScene. + * You can override this function to implement your own processing logic. + */ + void OnSceneCreated() override; + + /** + * @brief Called after ability stoped. + * You can override this function to implement your own processing logic. + */ + void OnSceneDestroyed() ; + + /** + * @brief Called after ability restored. + * You can override this function to implement your own processing logic. + */ + void OnSceneRestored() override; + + /** + * @brief Called when this ability enters the STATE_FOREGROUND state. + * The ability in the STATE_FOREGROUND state is visible. + * You can override this function to implement your own processing logic. + */ + void OnForeground(const Want &want) override; + + /** + * @brief Call "onForeground" js function barely. + * + * @param want Want + */ + void CallOnForegroundFunc(const Want &want) override; + + /** + * @brief Request focus for current window, can be override. + * + * @param want Want + */ + void RequestFocus(const Want &want) override; + + /** + * @brief Called when this ability enters the STATE_BACKGROUND state. + * The ability in the STATE_BACKGROUND state is invisible. + * You can override this function to implement your own processing logic. + */ + void OnBackground() override; + + /** + * Called when back press is dispatched. + * Return true if ability will be moved to background; return false if will be terminated + */ + bool OnBackPress() override; + + /** + * @brief Called when ability prepare terminate. + * @return Return true if ability need to stop terminating; return false if ability need to terminate. + */ + bool OnPrepareTerminate() override; + + /** + * @brief Get CJWindow Stage + * @return Returns the current CJWindowStage + */ + std::shared_ptr GetCJWindowStage(); + + /** + * @brief Get CJRuntime + * @return Returns the current CJRuntime + */ + const CJRuntime &GetCJRuntime(); + + /** + * @brief Execute insight intention when an ability is in foreground, schedule it to foreground repeatly. + * + * @param want Want. + * @param executeParam insight intention execute param. + * @param callback insight intention async callback. + */ + void ExecuteInsightIntentRepeateForeground(const Want &want, + const std::shared_ptr &executeParam, + std::unique_ptr callback) override; + + /** + * @brief Execute insight intention when an ability didn't started or in background, schedule it to foreground. + * + * @param want Want. + * @param executeParam insight intention execute param. + * @param callback insight intention async callback. + */ + void ExecuteInsightIntentMoveToForeground(const Want &want, + const std::shared_ptr &executeParam, + std::unique_ptr callback) override; + +protected: + void DoOnForeground(const Want &want) override; + void ContinuationRestore(const Want &want) override; + +private: + bool IsRestorePageStack(const Want &want); + void RestorePageStack(const Want &want); + void GetPageStackFromWant(const Want &want, std::string &pageStack); + void AbilityContinuationOrRecover(const Want &want); + inline bool GetInsightIntentExecutorInfo(const Want &want, + const std::shared_ptr &executeParam, + InsightIntentExecutorInfo& executeInfo); + + std::shared_ptr cjWindowStage_; + int32_t windowMode_ = 0; +#endif + +private: + std::shared_ptr CreateADelegatorAbilityProperty(); + sptr SetNewRuleFlagToCallee(napi_env env, napi_value remoteJsObj); + void SetAbilityContext(const std::shared_ptr &abilityInfo); + void InitSceneDoOnForeground(std::shared_ptr scene, const Want &want); + void AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const; + void AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const; + + CJRuntime &cjRuntime_; + std::shared_ptr cjAbilityObj_; + sptr remoteCallee_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CJ_UI_ABILITY_H diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h index aae8440a77..bf112df27d 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h @@ -119,8 +119,8 @@ protected: std::shared_ptr asyncTask, size_t& unwrapArgc, AAFwk::StartOptions startOptions); void SetCallbackForTerminateWithResult(int32_t resultCode, AAFwk::Want& want, NapiAsyncTask::CompleteCallback& complete); - bool CheckStartAbilityByTypeParam(napi_env env, NapiCallbackInfo& info, std::string type, - AAFwk::WantParams wantParam); + bool CheckStartAbilityByTypeParam(napi_env env, NapiCallbackInfo& info, std::string& type, + AAFwk::WantParams& wantParam); private: sptr sessionInfo_; diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index d2dfe0bc21..bf50c889bb 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -31,6 +31,7 @@ config("abilityms_config") { include_dirs = [ "include/", "include/rdb/", + "include/screen_lock/", "${ability_runtime_innerkits_path}/ability_manager/include", "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_innerkits_path}/app_manager/include", @@ -204,7 +205,10 @@ ohos_shared_library("abilityms") { external_deps += [ "dlp_permission_service:libdlp_permission_sdk" ] } + defines = [] + if (ability_runtime_graphics) { + defines += [ "SUPPORT_GRAPHICS" ] external_deps += [ "ability_base:session_info", "i18n:intl_util", @@ -212,6 +216,7 @@ ohos_shared_library("abilityms") { "image_framework:image_native", "input:libmmi-client", "resource_management:global_resmgr", + "screenlock_mgr:screenlock_client", "window_manager:libdm", "window_manager:libmodal_system_ui_extension_client", "window_manager:libwm", @@ -221,6 +226,11 @@ ohos_shared_library("abilityms") { ] } + if (ability_runtime_power) { + defines += [ "SUPPORT_POWER" ] + external_deps += [ "power_manager:powermgr_client" ] + } + version_script = "libabilityms.map" subsystem_name = "ability" innerapi_tags = [ "platformsdk_indirect" ] diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 15bae44f83..2b3fbe6753 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -14,7 +14,6 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") abilityms_files = [ - "src/ability_app_state_observer.cpp", "src/preload_uiext_state_observer.cpp", "src/ability_background_connection.cpp", "src/ability_connect_manager.cpp", @@ -80,6 +79,7 @@ abilityms_files = [ "src/extension_record_factory.cpp", "src/ui_extension_record.cpp", "src/ui_extension_record_factory.cpp", + "src/screen_lock/unlock_screen_manager.cpp", "src/start_options.cpp", "src/user_callback_proxy.cpp", "src/call_container.cpp", @@ -140,6 +140,7 @@ if (ability_runtime_graphics) { "src/implicit_start_processor.cpp", "src/system_dialog_scheduler.cpp", "src/ability_first_frame_state_observer_manager.cpp", + "src/screen_lock/unlock_screen_callback.cpp", ] } diff --git a/services/abilitymgr/include/ability_app_state_observer.h b/services/abilitymgr/include/ability_app_state_observer.h deleted file mode 100644 index 0b8d83e142..0000000000 --- a/services/abilitymgr/include/ability_app_state_observer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_ABILITY_APP_STATE_OBSERVER_H -#define OHOS_ABILITY_RUNTIME_ABILITY_APP_STATE_OBSERVER_H - -#include - -#include "application_state_observer_stub.h" - -namespace OHOS { -namespace AAFwk { -class AbilityRecord; -class AbilityAppStateObserver : public AppExecFwk::ApplicationStateObserverStub { -public: - AbilityAppStateObserver(std::shared_ptr abilityRecord); - virtual void OnProcessDied(const AppExecFwk::ProcessData &processData) override; - -private: - std::weak_ptr abilityRecord_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_ABILITY_APP_STATE_OBSERVER_H \ No newline at end of file diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index b187888e23..5cb99026d4 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1752,6 +1752,8 @@ protected: void NotifyStartResidentProcess(std::vector &bundleInfos) override; + void OnAppRemoteDied(const std::vector> &abilityTokens) override; + private: int TerminateAbilityWithFlag(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, const Want *resultWant = nullptr, bool flag = true); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 25019e971f..35b55bc49f 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -57,7 +57,6 @@ class ConnectionRecord; class Mission; class MissionList; class CallContainer; -class AbilityAppStateObserver; constexpr const char* ABILITY_TOKEN_NAME = "AbilityToken"; constexpr const char* LAUNCHER_BUNDLE_NAME = "com.ohos.launcher"; @@ -1001,7 +1000,6 @@ private: */ void GetAbilityTypeString(std::string &typeStr); void OnSchedulerDied(const wptr &remote); - void RemoveAppStateObserver(bool force = false); void GrantUriPermission(Want &want, std::string targetBundleName, bool isSandboxApp, uint32_t tokenId); void GrantDmsUriPermission(Want &want, std::string targetBundleName); bool IsDmsCall(Want &want); @@ -1177,7 +1175,6 @@ private: // scene session sptr sessionInfo_ = nullptr; mutable ffrt::mutex sessionLock_; - sptr abilityAppStateObserver_; std::map abilityWindowStateMap_; sptr uiExtRequestSessionInfo_ = nullptr; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 760e9c1295..db716ce3a9 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -93,6 +93,8 @@ public: virtual void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) {} virtual void NotifyStartResidentProcess(std::vector &bundleInfos) {} + + virtual void OnAppRemoteDied(const std::vector> &abilityTokens) {} }; class StartSpecifiedAbilityResponse : public AppExecFwk::StartSpecifiedAbilityResponseStub { @@ -461,6 +463,8 @@ protected: */ virtual void NotifyStartResidentProcess(std::vector &bundleInfos) override; + virtual void OnAppRemoteDied(const std::vector> &abilityTokens) override; + private: std::mutex lock_; bool isInit_ {false}; diff --git a/services/abilitymgr/include/screen_lock/unlock_screen_callback.h b/services/abilitymgr/include/screen_lock/unlock_screen_callback.h new file mode 100644 index 0000000000..6c3946a7a1 --- /dev/null +++ b/services/abilitymgr/include/screen_lock/unlock_screen_callback.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_CALLBACK_H + +#ifdef SUPPORT_GRAPHICS +#include "screenlock_manager.h" +#include "screenlock_callback_stub.h" + +namespace OHOS { +namespace AbilityRuntime { +class UnlockScreenCallback : public ScreenLock::ScreenLockCallbackStub { +public: + explicit UnlockScreenCallback(); + ~UnlockScreenCallback() override; + void OnCallBack(const int32_t screenLockResult) override; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // SUPPORT_GRAPHICS +#endif // OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_CALLBACK_H diff --git a/services/abilitymgr/include/screen_lock/unlock_screen_manager.h b/services/abilitymgr/include/screen_lock/unlock_screen_manager.h new file mode 100644 index 0000000000..b843b6133c --- /dev/null +++ b/services/abilitymgr/include/screen_lock/unlock_screen_manager.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_MANAGER_H +#define OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_MANAGER_H + +#include "nocopyable.h" + +#ifdef SUPPORT_POWER +#include "power_mgr_client.h" +#endif + +#ifdef SUPPORT_GRAPHICS +#include "unlock_screen_callback.h" +#include "screenlock_manager.h" +#include "screenlock_common.h" +#endif + +namespace OHOS { +namespace AbilityRuntime { +class UnlockScreenManager { +public: + static UnlockScreenManager &GetInstance(); + ~UnlockScreenManager(); + bool UnlockScreen(); +private: + UnlockScreenManager(); + DISALLOW_COPY_AND_MOVE(UnlockScreenManager); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UNLOCK_SCREEN_MANAGER_H \ No newline at end of file diff --git a/services/abilitymgr/src/ability_app_state_observer.cpp b/services/abilitymgr/src/ability_app_state_observer.cpp deleted file mode 100644 index 866af1664c..0000000000 --- a/services/abilitymgr/src/ability_app_state_observer.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ability_app_state_observer.h" -#include "ability_record.h" -#include "hilog_tag_wrapper.h" -#include "hilog_wrapper.h" - -namespace OHOS { -namespace AAFwk { -AbilityAppStateObserver::AbilityAppStateObserver(std::shared_ptr abilityRecord) - : abilityRecord_(abilityRecord) {} -void AbilityAppStateObserver::OnProcessDied(const AppExecFwk::ProcessData &processData) -{ - auto abilityRecord = abilityRecord_.lock(); - if (abilityRecord) { - const auto &abilityInfo = abilityRecord->GetAbilityInfo(); - if (abilityInfo.bundleName == processData.bundleName && - processData.processType == AppExecFwk::ProcessType::NORMAL && - abilityInfo.type == AppExecFwk::AbilityType::PAGE) { - abilityRecord->OnProcessDied(); - } - if (abilityRecord->IsSceneBoard() && abilityRecord->GetPid() == processData.pid) { - abilityRecord->OnProcessDied(); - } - } else { - TAG_LOGW(AAFwkTag::ABILITYMGR, "AbilityRecord null"); - } -} -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 00186183d3..d07648f24f 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -101,6 +101,7 @@ #include "system_ability_token_callback.h" #include "extension_record_manager.h" #include "ui_extension_utils.h" +#include "unlock_screen_manager.h" #include "uri_permission_manager_client.h" #include "uri_utils.h" #include "view_data.h" @@ -538,6 +539,10 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re TAG_LOGE(AAFwkTag::ABILITYMGR, "Developer Mode is false."); return ERR_NOT_DEVELOPER_MODE; } + if (!UnlockScreenManager::GetInstance().UnlockScreen()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Screen need passord to unlock"); + return ERR_UNLOCK_SCREEN_FAILED_IN_DEVELOPER_MODE; + } TAG_LOGD(AAFwkTag::ABILITYMGR, "coldStart:%{public}d", want.GetBoolParam("coldStart", false)); bool startWithAccount = want.GetBoolParam(START_ABILITY_TYPE, false); if (startWithAccount || IsCrossUserCall(userId)) { @@ -1201,6 +1206,10 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt TAG_LOGE(AAFwkTag::ABILITYMGR, "Developer Mode is false."); return ERR_NOT_DEVELOPER_MODE; } + if (!UnlockScreenManager::GetInstance().UnlockScreen()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Screen need passord to unlock"); + return ERR_UNLOCK_SCREEN_FAILED_IN_DEVELOPER_MODE; + } AbilityUtil::RemoveWantKey(const_cast(want)); StartAbilityParams startParams(const_cast(want)); startParams.callerToken = callerToken; @@ -9892,6 +9901,20 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vector> &abilityTokens) +{ + std::shared_ptr abilityRecord; + for (auto &token : abilityTokens) { + abilityRecord = Token::GetAbilityRecordByToken(token); + if (abilityRecord == nullptr) { + continue; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "App OnRemoteDied, ability is %{public}s, app is %{public}s", + abilityRecord->GetAbilityInfo().name.c_str(), abilityRecord->GetAbilityInfo().bundleName.c_str()); + abilityRecord->OnProcessDied(); + } +} + int32_t AbilityManagerService::OpenFile(const Uri& uri, uint32_t flag) { auto accessTokenId = IPCSkeleton::GetCallingTokenID(); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index e2ef37aa6e..c8a2204062 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1488,13 +1488,13 @@ int AbilityManagerStub::ContinueMissionOfBundleNameInner(MessageParcel &data, Me return ERR_NULL_OBJECT; } std::unique_ptr wantParams(data.ReadParcelable()); - continueMissionInfo.wantParams = *wantParams; - continueMissionInfo.srcBundleName = data.ReadString(); - continueMissionInfo.continueType = data.ReadString(); if (wantParams == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ContinueMissionInner wantParams readParcelable failed!"); return ERR_NULL_OBJECT; } + continueMissionInfo.wantParams = *wantParams; + continueMissionInfo.srcBundleName = data.ReadString(); + continueMissionInfo.continueType = data.ReadString(); int32_t result = ContinueMission(continueMissionInfo, callback); TAG_LOGI(AAFwkTag::ABILITYMGR, "ContinueMissionInner result = %{public}d", result); return result; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 46f2c32ff0..a482e15572 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -21,7 +21,6 @@ #include #include "constants.h" -#include "ability_app_state_observer.h" #include "ability_event_handler.h" #include "ability_manager_service.h" #include "ability_resident_process_rdb.h" @@ -248,7 +247,6 @@ AbilityRecord::~AbilityRecord() } } want_.CloseAllFd(); - RemoveAppStateObserver(true); } std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityRequest &abilityRequest) @@ -275,30 +273,9 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRecord->collaboratorType_ = abilityRequest.collaboratorType; abilityRecord->missionAffinity_ = abilityRequest.want.GetStringParam(PARAM_MISSION_AFFINITY_KEY); - // Before the ability attaches - abilityRecord->abilityAppStateObserver_ = sptr( - new AbilityAppStateObserver(abilityRecord)); - DelayedSingleton::GetInstance()->RegisterApplicationStateObserver( - abilityRecord->abilityAppStateObserver_, {abilityRequest.abilityInfo.bundleName}); return abilityRecord; } -void AbilityRecord::RemoveAppStateObserver(bool force) -{ - if (!force && IsSceneBoard()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "Special ability no need to RemoveAppStateObserver."); - return; - } - auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); - if (handler && abilityAppStateObserver_) { - handler->SubmitTask([appStateObserver = abilityAppStateObserver_]() { - DelayedSingleton::GetInstance()->UnregisterApplicationStateObserver( - appStateObserver); - }); - abilityAppStateObserver_ = nullptr; - } -} - bool AbilityRecord::Init() { lifecycleDeal_ = std::make_unique(); @@ -1432,7 +1409,6 @@ void AbilityRecord::SetScheduler(const sptr &scheduler) } }); } - RemoveAppStateObserver(); isReady_ = true; scheduler_ = scheduler; lifecycleDeal_->SetScheduler(scheduler); @@ -2408,7 +2384,10 @@ void AbilityRecord::OnSchedulerDied(const wptr &remote) void AbilityRecord::OnProcessDied() { std::lock_guard guard(lock_); - RemoveAppStateObserver(true); + if (!IsSceneBoard() && scheduler_ != nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "OnProcessDied: '%{public}s', attached.", abilityInfo_.name.c_str()); + return; + } isWindowAttached_ = false; auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index d7b3fb298a..a5de63c336 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -239,6 +239,13 @@ void AppScheduler::NotifyStartResidentProcess(std::vectorNotifyStartResidentProcess(bundleInfos); } +void AppScheduler::OnAppRemoteDied(const std::vector> &abilityTokens) +{ + auto callback = callback_.lock(); + CHECK_POINTER(callback); + callback->OnAppRemoteDied(abilityTokens); +} + int AppScheduler::KillApplication(const std::string &bundleName) { TAG_LOGI(AAFwkTag::ABILITYMGR, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); diff --git a/services/abilitymgr/src/screen_lock/unlock_screen_callback.cpp b/services/abilitymgr/src/screen_lock/unlock_screen_callback.cpp new file mode 100644 index 0000000000..03befbaca4 --- /dev/null +++ b/services/abilitymgr/src/screen_lock/unlock_screen_callback.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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. + */ +#ifdef SUPPORT_GRAPHICS +#include "unlock_screen_callback.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +UnlockScreenCallback::~UnlockScreenCallback() {} + +UnlockScreenCallback::UnlockScreenCallback() {} + +void UnlockScreenCallback::OnCallBack(const int32_t screenLockResult) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "Unlock Screen result is %{public}d", screenLockResult); +} +} // namespace AbilityRuntime +} // namespace OHOS +#endif // SUPPORT_GRAPHICS + diff --git a/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp b/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp new file mode 100644 index 0000000000..5f4de0e448 --- /dev/null +++ b/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 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 "unlock_screen_manager.h" + +#include "hilog_tag_wrapper.h" +#include "in_process_call_wrapper.h" +#include "parameters.h" +#include "permission_verification.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; +} + +UnlockScreenManager::~UnlockScreenManager() {} + +UnlockScreenManager::UnlockScreenManager() {} + +UnlockScreenManager &UnlockScreenManager::GetInstance() +{ + static UnlockScreenManager instance; + return instance; +} + +bool UnlockScreenManager::UnlockScreen() +{ + bool isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + bool isDeveloperMode = system::GetBoolParameter(DEVELOPER_MODE_STATE, false); + if (!isShellCall) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "not aa start call, just start ability"); + return true; + } + if (!isDeveloperMode) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "not devlop mode, just start ability"); + return true; + } + +#ifdef SUPPORT_GRAPHICS + bool isScreenLocked = OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked(); + bool isScreenSecured = OHOS::ScreenLock::ScreenLockManager::GetInstance()->GetSecure(); + TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenLocked: %{public}d, isScreenSecured: %{public}d", + isScreenLocked, isScreenSecured); + if (isScreenLocked && isScreenSecured) { + return false; + } + if (isScreenLocked) { + sptr listener = sptr(new (std::nothrow) UnlockScreenCallback()); + IN_PROCESS_CALL(OHOS::ScreenLock::ScreenLockManager::GetInstance()->Unlock( + OHOS::ScreenLock::Action::UNLOCKSCREEN, listener)); + } +#endif + +#ifdef SUPPORT_POWER + bool isScreenOn = PowerMgr::PowerMgrClient::GetInstance().IsScreenOn(); + TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenOn: %{public}d", isScreenOn); + if (!isScreenOn) { + PowerMgr::PowerMgrClient::GetInstance().WakeupDevice(); + } +#endif + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 3d210cb988..7061bceedd 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -542,12 +542,16 @@ public: bool IsEmptyKeepAliveApp() const; + bool IsMainProcess() const; + void SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp); void SetKeepAliveEnableState(bool isKeepAliveEnable); void SetSingleton(bool isSingleton); + void SetMainProcess(bool isMainProcess); + void SetStageModelState(bool isStageBasedModel); std::list> GetAllModuleRecord() const; @@ -849,6 +853,7 @@ private: bool isKeepAliveApp_ = false; // Only resident processes can be set to true, please choose carefully bool isEmptyKeepAliveApp_ = false; // Only empty resident processes can be set to true, please choose carefully + bool isMainProcess_ = true; // Only MainProcess can be keepalive bool isSingleton_ = false; bool isStageBasedModel_ = false; ApplicationState curState_ = ApplicationState::APP_STATE_CREATE; // current state of this process diff --git a/services/appmgr/include/app_spawn_client.h b/services/appmgr/include/app_spawn_client.h index 693dfab866..cb53111a71 100644 --- a/services/appmgr/include/app_spawn_client.h +++ b/services/appmgr/include/app_spawn_client.h @@ -104,6 +104,11 @@ public: */ explicit AppSpawnClient(bool isNWebSpawn = false); + /** + * Constructor by service name + */ + explicit AppSpawnClient(const char* serviceName); + /** * Destructor */ diff --git a/services/appmgr/include/remote_client_manager.h b/services/appmgr/include/remote_client_manager.h index 1e088e3931..175396082a 100644 --- a/services/appmgr/include/remote_client_manager.h +++ b/services/appmgr/include/remote_client_manager.h @@ -59,10 +59,13 @@ public: std::shared_ptr GetNWebSpawnClient(); + std::shared_ptr GetCJSpawnClient(); + private: std::shared_ptr appSpawnClient_; std::shared_ptr bundleManagerHelper_; std::shared_ptr nwebSpawnClient_; + std::shared_ptr cjAppSpawnClient_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 2a27ced442..0e345a6c4d 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -217,6 +217,15 @@ int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; } + +bool isCjAbility(const std::string& info) +{ + std::string cjCheckFlag = ".cj"; + if (info.length() < cjCheckFlag.length()) { + return false; + } + return info.substr(info.length() - cjCheckFlag.length()) == cjCheckFlag; +} } // namespace using OHOS::AppExecFwk::Constants::PERMISSION_GRANTED; @@ -636,6 +645,7 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptrSetEmptyKeepAliveAppState(false); + appRecord->SetMainProcess(false); TAG_LOGI(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); } // As taskHandler_ is busy now, the task should be submit to other task queue. @@ -2750,10 +2760,40 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str return; }; + bool findEntryHapModuleInfo = false; + bool isCJApp = false; + AppExecFwk::HapModuleInfo entryHapModuleInfo; + if (!bundleInfo.hapModuleInfos.empty()) { + for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { + if (hapModuleInfo.moduleType == AppExecFwk::ModuleType::ENTRY) { + findEntryHapModuleInfo = true; + entryHapModuleInfo = hapModuleInfo; + break; + } + } + if (!findEntryHapModuleInfo) { + TAG_LOGW(AAFwkTag::APPKIT, "HandleLaunchApplication find entry hap module info failed!"); + entryHapModuleInfo = bundleInfo.hapModuleInfos.back(); + } + if (!entryHapModuleInfo.abilityInfos.empty()) { + isCJApp = isCjAbility(entryHapModuleInfo.abilityInfos.front().srcEntrance); + } + } + SetProcessJITState(appRecord); PerfProfile::GetInstance().SetAppForkStartTime(GetTickCount()); pid_t pid = 0; - ErrCode errCode = remoteClientManager_->GetSpawnClient()->StartProcess(startMsg, pid); + ErrCode errCode = ERR_OK; + if (isCJApp) { + if (!remoteClientManager_->GetCJSpawnClient()) { + TAG_LOGE(AAFwkTag::APPMGR, "cj appSpawnClient is null"); + appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); + return; + } + errCode = remoteClientManager_->GetCJSpawnClient()->StartProcess(startMsg, pid); + } else { + errCode = remoteClientManager_->GetSpawnClient()->StartProcess(startMsg, pid); + } if (FAILED(errCode)) { TAG_LOGE(AAFwkTag::APPMGR, "failed to spawn new app process, errCode %{public}08x", errCode); appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); @@ -3026,6 +3066,15 @@ void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool is return; } + std::vector> abilityTokens; + for (const auto &token : appRecord->GetAbilities()) { + abilityTokens.emplace_back(token.first); + } + for (const auto &callback : appStateCallbacks_) { + if (callback != nullptr) { + callback->OnAppRemoteDied(abilityTokens); + } + } ClearData(appRecord); } @@ -3777,6 +3826,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap } if (hapModuleInfo.isStageBasedModel && !IsMainProcess(appInfo, hapModuleInfo)) { appRecord->SetEmptyKeepAliveAppState(false); + appRecord->SetMainProcess(false); TAG_LOGD(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); } auto wantPtr = std::make_shared(want); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index f67930dd18..f8e1914c1d 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1370,7 +1370,7 @@ bool AppRunningRecord::IsTerminating() bool AppRunningRecord::IsKeepAliveApp() const { - return isKeepAliveApp_ && isSingleton_; + return isKeepAliveApp_ && isSingleton_ && isMainProcess_; } void AppRunningRecord::SetKeepAliveEnableState(bool isKeepAliveEnable) @@ -1388,6 +1388,16 @@ void AppRunningRecord::SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp) isEmptyKeepAliveApp_ = isEmptyKeepAliveApp; } +bool AppRunningRecord::IsMainProcess() const +{ + return isMainProcess_; +} + +void AppRunningRecord::SetMainProcess(bool isMainProcess) +{ + isMainProcess_ = isMainProcess; +} + void AppRunningRecord::SetSingleton(bool isSingleton) { isSingleton_ = isSingleton; diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 3aaab43f99..7d4bfc4478 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -48,6 +48,23 @@ AppSpawnClient::AppSpawnClient(bool isNWebSpawn) state_ = SpawnConnectionState::STATE_NOT_CONNECT; } +AppSpawnClient::AppSpawnClient(const char* serviceName) +{ + TAG_LOGD(AAFwkTag::APPMGR, "AppspawnCreateClient"); + std::string serviceName__ = serviceName; + if (serviceName__ == APPSPAWN_SERVER_NAME) { + serviceName_ = APPSPAWN_SERVER_NAME; + } else if (serviceName__ == CJAPPSPAWN_SERVER_NAME) { + serviceName_ = CJAPPSPAWN_SERVER_NAME; + } else if (serviceName__ == NWEBSPAWN_SERVER_NAME) { + serviceName_ = NWEBSPAWN_SERVER_NAME; + } else { + TAG_LOGE(AAFwkTag::APPMGR, "unknown service name"); + serviceName_ = NWEBSPAWN_SERVER_NAME; + } + state_ = SpawnConnectionState::STATE_NOT_CONNECT; +} + AppSpawnClient::~AppSpawnClient() { CloseConnection(); diff --git a/services/appmgr/src/remote_client_manager.cpp b/services/appmgr/src/remote_client_manager.cpp index b2a1035b07..1a8f293210 100644 --- a/services/appmgr/src/remote_client_manager.cpp +++ b/services/appmgr/src/remote_client_manager.cpp @@ -24,7 +24,8 @@ namespace OHOS { namespace AppExecFwk { RemoteClientManager::RemoteClientManager() - : appSpawnClient_(std::make_shared()), nwebSpawnClient_(std::make_shared(true)) + : appSpawnClient_(std::make_shared()), nwebSpawnClient_(std::make_shared(true)), + cjAppSpawnClient_(std::make_shared("cjappspawn")) {} RemoteClientManager::~RemoteClientManager() @@ -60,5 +61,13 @@ std::shared_ptr RemoteClientManager::GetNWebSpawnClient() { return nwebSpawnClient_; } + +std::shared_ptr RemoteClientManager::GetCJSpawnClient() +{ + if (cjAppSpawnClient_) { + return cjAppSpawnClient_; + } + return nullptr; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 68d6078ecb..f60d60d8ef 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -357,6 +357,7 @@ group("unittest") { "ability_scheduler_proxy_test:unittest", "ability_scheduler_stub_test:unittest", "ability_service_extension_test:unittest", + "ability_service_log_test:unittest", "ability_service_start_test:unittest", "ability_timeout_test", "ability_token_proxy_test:unittest", diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index 3bb478cde2..0e8689ec66 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -945,6 +945,54 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartExtensionAbilityInner_0 EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: RequestModalUIExtensionInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RequestModalUIExtensionInner + * EnvConditions: NA + * CaseDescription: Verify the function RequestModalUIExtensionInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RequestModalUIExtensionInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RequestModalUIExtensionInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: PreloadUIExtensionAbilityInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService PreloadUIExtensionAbilityInner + * EnvConditions: NA + * CaseDescription: Verify the function PreloadUIExtensionAbilityInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_PreloadUIExtensionAbilityInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->PreloadUIExtensionAbilityInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: StartUIExtensionAbilityInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIExtensionAbilityInner + * EnvConditions: NA + * CaseDescription: Verify the function StartUIExtensionAbilityInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartUIExtensionAbilityInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartUIExtensionAbilityInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: StopExtensionAbilityInner @@ -1073,6 +1121,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ConnectAbilityWithTypeInner_ EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: ConnectUIExtensionAbilityInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ConnectUIExtensionAbilityInner + * EnvConditions: NA + * CaseDescription: Verify the function ConnectUIExtensionAbilityInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ConnectUIExtensionAbilityInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->ConnectUIExtensionAbilityInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /* * Feature: AbilityManagerService * Function: DisconnectAbilityInner @@ -1169,6 +1233,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartAbilityForOptionsInner_ EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: CloseUIAbilityBySCBInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService CloseUIAbilityBySCBInner + * EnvConditions: NA + * CaseDescription: Verify the function CloseUIAbilityBySCBInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_CloseUIAbilityBySCBInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->CloseUIAbilityBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: GetWantSenderInner @@ -1425,6 +1505,24 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ContinueMissionOfBundleNameI EXPECT_EQ(res, ERR_NULL_OBJECT); } +/* + * Feature: AbilityManagerService + * Function: ContinueMissionOfBundleNameInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ContinueMissionOfBundleNameInner + * EnvConditions: NA + * CaseDescription: Verify the function ContinueMissionOfBundleNameInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ContinueMissionOfBundleNameInner_002, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + Want want; + data.WriteParcelable(&want); + auto res = stub_->ContinueMissionOfBundleNameInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + /* * Feature: AbilityManagerService * Function: ContinueAbilityInner @@ -1521,6 +1619,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnlockMissionForCleanupInner EXPECT_EQ(res, NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: SetLockedStateInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService SetLockedStateInner + * EnvConditions: NA + * CaseDescription: Verify the function SetLockedStateInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_SetLockedStateInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->SetLockedStateInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: RegisterMissionListenerInner @@ -1715,6 +1829,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartAbilityByCallInner_001, EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: StartUIAbilityBySCBInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilityBySCBInner + * EnvConditions: NA + * CaseDescription: Verify the function StartUIAbilityBySCBInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartUIAbilityBySCBInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartUIAbilityBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: ReleaseCallInner @@ -2310,6 +2440,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_FreeInstallAbilityFromRemote EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: AddFreeInstallObserverInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService AddFreeInstallObserverInner + * EnvConditions: NA + * CaseDescription: Verify the function AddFreeInstallObserverInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AddFreeInstallObserverInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->AddFreeInstallObserverInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /* * Feature: AbilityManagerService * Function: DumpAbilityInfoDoneInner @@ -2326,6 +2472,54 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_DumpAbilityInfoDoneInner_001 EXPECT_EQ(res, NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: UpdateMissionSnapShotFromWMSInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService UpdateMissionSnapShotFromWMSInner + * EnvConditions: NA + * CaseDescription: Verify the function UpdateMissionSnapShotFromWMSInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UpdateMissionSnapShotFromWMSInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->UpdateMissionSnapShotFromWMSInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: EnableRecoverAbilityInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService EnableRecoverAbilityInner + * EnvConditions: NA + * CaseDescription: Verify the function EnableRecoverAbilityInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_EnableRecoverAbilityInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->EnableRecoverAbilityInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: HandleRequestDialogService + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleRequestDialogService + * EnvConditions: NA + * CaseDescription: Verify the function HandleRequestDialogService is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_HandleRequestDialogService_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->HandleRequestDialogService(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /** * @tc.number: HandleReportDrawnCompleted_001 * @tc.name: HandleReportDrawnCompleted @@ -2339,6 +2533,54 @@ HWTEST_F(AbilityManagerStubTest, HandleReportDrawnCompleted_001, TestSize.Level1 EXPECT_EQ(res, ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: AcquireShareDataInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService AcquireShareDataInner + * EnvConditions: NA + * CaseDescription: Verify the function AcquireShareDataInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AcquireShareDataInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->AcquireShareDataInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: ShareDataDoneInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ShareDataDoneInner + * EnvConditions: NA + * CaseDescription: Verify the function ShareDataDoneInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ShareDataDoneInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->ShareDataDoneInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: GetAbilityTokenByCalleeObjInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetAbilityTokenByCalleeObjInner + * EnvConditions: NA + * CaseDescription: Verify the function GetAbilityTokenByCalleeObjInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_GetAbilityTokenByCalleeObjInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->GetAbilityTokenByCalleeObjInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + #ifdef ABILITY_COMMAND_FOR_TEST /* * Feature: AbilityManagerService @@ -2423,6 +2665,22 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_GetDlpConnectionInfosInner_0 EXPECT_EQ(res, ERR_OK); } +/* + * Feature: AbilityManagerService + * Function: GetConnectionDataInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetConnectionDataInner + * EnvConditions: NA + * CaseDescription: Verify the function GetConnectionDataInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_GetConnectionDataInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->GetConnectionDataInner(data, reply); + EXPECT_EQ(res, ERR_OK); +} + /* * Feature: AbilityManagerService * Function: SetMissionContinueStateInner @@ -2503,6 +2761,86 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_CompleteFirstFrameDrawingInn EXPECT_EQ(res, ERR_NULL_OBJECT); } +/* + * Feature: AbilityManagerService + * Function: CompleteFirstFrameDrawingBySCBInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService CompleteFirstFrameDrawingBySCBInner + * EnvConditions: NA + * CaseDescription: Verify the function CompleteFirstFrameDrawingBySCBInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_CompleteFirstFrameDrawingBySCBInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->CompleteFirstFrameDrawingBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: GetDialogSessionInfoInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetDialogSessionInfoInner + * EnvConditions: NA + * CaseDescription: Verify the function GetDialogSessionInfoInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_GetDialogSessionInfoInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->GetDialogSessionInfoInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: SendDialogResultInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService SendDialogResultInner + * EnvConditions: NA + * CaseDescription: Verify the function SendDialogResultInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_SendDialogResultInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->SendDialogResultInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: RegisterAbilityFirstFrameStateObserverInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RegisterAbilityFirstFrameStateObserverInner + * EnvConditions: NA + * CaseDescription: Verify the function RegisterAbilityFirstFrameStateObserverInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterAbilityFirstFrameStateObserverInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RegisterAbilityFirstFrameStateObserverInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: UnregisterAbilityFirstFrameStateObserverInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService UnregisterAbilityFirstFrameStateObserverInner + * EnvConditions: NA + * CaseDescription: Verify the function UnregisterAbilityFirstFrameStateObserverInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterAbilityFirstFrameStateObserverInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->UnregisterAbilityFirstFrameStateObserverInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /* * Feature: AbilityManagerService * Function: CallRequestDone @@ -2562,6 +2900,134 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_IsValidMissionIdsInner_002, EXPECT_EQ(stub_->IsValidMissionIdsInner(data, reply), NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: ForceExitAppInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ForceExitAppInner + * EnvConditions: NA + * CaseDescription: Verify the function ForceExitAppInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ForceExitAppInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->ForceExitAppInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: RecordAppExitReasonInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RecordAppExitReasonInner + * EnvConditions: NA + * CaseDescription: Verify the function RecordAppExitReasonInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RecordAppExitReasonInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RecordAppExitReasonInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: RecordProcessExitReasonInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RecordProcessExitReasonInner + * EnvConditions: NA + * CaseDescription: Verify the function RecordProcessExitReasonInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RecordProcessExitReasonInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RecordProcessExitReasonInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: SetRootSceneSessionInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService SetRootSceneSessionInner + * EnvConditions: NA + * CaseDescription: Verify the function SetRootSceneSessionInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_SetRootSceneSessionInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->SetRootSceneSessionInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: CallUIAbilityBySCBInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService CallUIAbilityBySCBInner + * EnvConditions: NA + * CaseDescription: Verify the function CallUIAbilityBySCBInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_CallUIAbilityBySCBInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->CallUIAbilityBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: SetSessionManagerServiceInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService SetSessionManagerServiceInner + * EnvConditions: NA + * CaseDescription: Verify the function SetSessionManagerServiceInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_SetSessionManagerServiceInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->CallUIAbilityBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: RegisterIAbilityManagerCollaboratorInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RegisterIAbilityManagerCollaboratorInner + * EnvConditions: NA + * CaseDescription: Verify the function RegisterIAbilityManagerCollaboratorInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterIAbilityManagerCollaboratorInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RegisterIAbilityManagerCollaboratorInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: UnregisterIAbilityManagerCollaboratorInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService UnregisterIAbilityManagerCollaboratorInner + * EnvConditions: NA + * CaseDescription: Verify the function UnregisterIAbilityManagerCollaboratorInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterIAbilityManagerCollaboratorInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->UnregisterIAbilityManagerCollaboratorInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: PrepareTerminateAbilityBySCBInner @@ -2583,6 +3049,38 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_PrepareTerminateAbilityBySCB EXPECT_EQ(stub_->PrepareTerminateAbilityBySCBInner(data, reply), ERR_INVALID_VALUE); } +/* + * Feature: AbilityManagerService + * Function: RegisterStatusBarDelegateInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RegisterStatusBarDelegateInner + * EnvConditions: NA + * CaseDescription: Verify the function RegisterStatusBarDelegateInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterStatusBarDelegateInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RegisterStatusBarDelegateInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: KillProcessWithPrepareTerminateInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService KillProcessWithPrepareTerminateInner + * EnvConditions: NA + * CaseDescription: Verify the function KillProcessWithPrepareTerminateInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_KillProcessWithPrepareTerminateInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->KillProcessWithPrepareTerminateInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /* * Feature: AbilityManagerService * Function: RegisterSessionHandlerInner @@ -2649,6 +3147,230 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_IsAbilityControllerStartInne EXPECT_EQ(stub_->IsAbilityControllerStartInner(data, reply), NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: ExecuteIntentInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ExecuteIntentInner + * EnvConditions: NA + * CaseDescription: Verify the function ExecuteIntentInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ExecuteIntentInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->ExecuteIntentInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityByInsightIntentInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityByInsightIntentInner + * EnvConditions: NA + * CaseDescription: Verify the function StartAbilityByInsightIntentInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartAbilityByInsightIntentInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartAbilityByInsightIntentInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: ExecuteInsightIntentDoneInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService ExecuteInsightIntentDoneInner + * EnvConditions: NA + * CaseDescription: Verify the function ExecuteInsightIntentDoneInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ExecuteInsightIntentDoneInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->ExecuteInsightIntentDoneInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: SetApplicationAutoStartupByEDMInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService SetApplicationAutoStartupByEDMInner + * EnvConditions: NA + * CaseDescription: Verify the function SetApplicationAutoStartupByEDMInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_SetApplicationAutoStartupByEDMInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->SetApplicationAutoStartupByEDMInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: CancelApplicationAutoStartupByEDMInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService CancelApplicationAutoStartupByEDMInner + * EnvConditions: NA + * CaseDescription: Verify the function CancelApplicationAutoStartupByEDMInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_CancelApplicationAutoStartupByEDMInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->CancelApplicationAutoStartupByEDMInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: OpenFileInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService OpenFileInner + * EnvConditions: NA + * CaseDescription: Verify the function OpenFileInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_OpenFileInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->OpenFileInner(data, reply); + EXPECT_EQ(res, ERR_DEAD_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: RequestAssertFaultDialogInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService RequestAssertFaultDialogInner + * EnvConditions: NA + * CaseDescription: Verify the function RequestAssertFaultDialogInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RequestAssertFaultDialogInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->RequestAssertFaultDialogInner(data, reply); + EXPECT_EQ(res, ERR_NULL_OBJECT); +} + +/* + * Feature: AbilityManagerService + * Function: NotifyDebugAssertResultInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService NotifyDebugAssertResultInner + * EnvConditions: NA + * CaseDescription: Verify the function NotifyDebugAssertResultInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_NotifyDebugAssertResultInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->NotifyDebugAssertResultInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: UpdateSessionInfoBySCBInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService UpdateSessionInfoBySCBInner + * EnvConditions: NA + * CaseDescription: Verify the function UpdateSessionInfoBySCBInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UpdateSessionInfoBySCBInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->UpdateSessionInfoBySCBInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: OpenAtomicServiceInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService OpenAtomicServiceInner + * EnvConditions: NA + * CaseDescription: Verify the function OpenAtomicServiceInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_OpenAtomicServiceInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->OpenAtomicServiceInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: IsEmbeddedOpenAllowedInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService IsEmbeddedOpenAllowedInner + * EnvConditions: NA + * CaseDescription: Verify the function IsEmbeddedOpenAllowedInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_IsEmbeddedOpenAllowedInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->IsEmbeddedOpenAllowedInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: StartShortcutInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartShortcutInner + * EnvConditions: NA + * CaseDescription: Verify the function StartShortcutInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartShortcutInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartShortcutInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AbilityManagerService + * Function: GetAbilityStateByPersistentIdInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetAbilityStateByPersistentIdInner + * EnvConditions: NA + * CaseDescription: Verify the function GetAbilityStateByPersistentIdInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_GetAbilityStateByPersistentIdInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->GetAbilityStateByPersistentIdInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: TransferAbilityResultForExtensionInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService TransferAbilityResultForExtensionInner + * EnvConditions: NA + * CaseDescription: Verify the function TransferAbilityResultForExtensionInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_TransferAbilityResultForExtensionInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->TransferAbilityResultForExtensionInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /** * @tc.name: AbilityManagerStub_RegisterAppDebugListenerInner_001 * @tc.desc: Test the status of RegisterAppDebugListenerInner, check empty AppDebugListener. diff --git a/test/unittest/ability_service_log_test/BUILD.gn b/test/unittest/ability_service_log_test/BUILD.gn new file mode 100644 index 0000000000..7b4e840fdc --- /dev/null +++ b/test/unittest/ability_service_log_test/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("ability_service_log_test") { + module_out_path = "ability_runtime/service_log" + + include_dirs = [ "${ability_runtime_path}/services/common/include" ] + + sources = [ "ability_service_log_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + cflags = [] + + deps = [] + + external_deps = [ "hilog:libhilog" ] +} + +group("unittest") { + testonly = true + deps = [ ":ability_service_log_test" ] +} diff --git a/test/unittest/ability_service_log_test/ability_service_log_test.cpp b/test/unittest/ability_service_log_test/ability_service_log_test.cpp new file mode 100644 index 0000000000..f9eef16b2f --- /dev/null +++ b/test/unittest/ability_service_log_test/ability_service_log_test.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 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 "hilog_tag_wrapper.h" + +using namespace testing::ext; +using UTAAFwkTag = OHOS::AAFwk::AAFwkLogTag; + +namespace OHOS { +namespace AbilityRuntime { +class AbilityServiceLogTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AbilityServiceLogTest::SetUpTestCase(void) +{} + +void AbilityServiceLogTest::TearDownTestCase(void) +{} + +void AbilityServiceLogTest::SetUp() +{} + +void AbilityServiceLogTest::TearDown() +{} + +/* + * Feature: HILOG + * Function: Create + * SubFunction: NA + * FunctionPoints: Create + * EnvConditions: NA + * CaseDescription: NA + */ +HWTEST_F(AbilityServiceLogTest, Log_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityServiceLog_0100 start"; + TAG_LOGI(AAFwkTag::TEST, "AbilityServiceLog_0100 info start"); + TAG_LOGD(AAFwkTag::TEST, "AbilityServiceLog_0100 debug start"); + TAG_LOGW(AAFwkTag::TEST, "AbilityServiceLog_0100 warn start"); + TAG_LOGE(AAFwkTag::TEST, "AbilityServiceLog_0100 error start"); + TAG_LOGF(AAFwkTag::TEST, "AbilityServiceLog_0100 fatal start"); + GTEST_LOG_(INFO) << "AbilityServiceLog_0100 end"; +} + +/* + * Feature: HILOG + * Function: Create + * SubFunction: NA + * FunctionPoints: Create + * EnvConditions: NA + * CaseDescription: NA + */ +HWTEST_F(AbilityServiceLogTest, Log_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityServiceLog_0200 start"; + TAG_LOGI(AAFwkTag::END, "AbilityServiceLog_0200 info start"); + TAG_LOGD(AAFwkTag::END, "AbilityServiceLog_0200 debug start"); + TAG_LOGW(AAFwkTag::END, "AbilityServiceLog_0200 warn start"); + TAG_LOGE(AAFwkTag::END, "AbilityServiceLog_0200 error start"); + TAG_LOGF(AAFwkTag::END, "AbilityServiceLog_0200 fatal start"); + GTEST_LOG_(INFO) << "AbilityServiceLog_0200 end"; +} + +/* + * Feature: HILOG + * Function: Create + * SubFunction: NA + * FunctionPoints: Create + * EnvConditions: NA + * CaseDescription: NA + */ +HWTEST_F(AbilityServiceLogTest, Log_0300, TestSize.Level1) +{ + size_t tag = 255; + GTEST_LOG_(INFO) << "AbilityServiceLog_0300 start"; + TAG_LOGI(static_cast(tag), "AbilityServiceLog_0300 info start"); + TAG_LOGD(static_cast(tag), "AbilityServiceLog_0300 debug start"); + TAG_LOGW(static_cast(tag), "AbilityServiceLog_0300 warn start"); + TAG_LOGE(static_cast(tag), "AbilityServiceLog_0300 error start"); + TAG_LOGF(static_cast(tag), "AbilityServiceLog_0300 fatal start"); + GTEST_LOG_(INFO) << "AbilityServiceLog_0300 end"; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/distributed_client_test.cpp b/test/unittest/frameworks_kits_ability_native_test/distributed_client_test.cpp index c289262b13..de5a775741 100644 --- a/test/unittest/frameworks_kits_ability_native_test/distributed_client_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/distributed_client_test.cpp @@ -64,6 +64,21 @@ HWTEST_F(DistributedClientTest, GetDmsProxy_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest GetDmsProxy_0100 end"; } +/** + * @tc.number: GetDmsProxy_0200 + * @tc.name: GetDmsProxy + * @tc.desc: GetDmsProxy Test, return is nullptr. + */ +HWTEST_F(DistributedClientTest, GetDmsProxy_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest GetDmsProxy_0200 start"; + auto client = std::make_shared(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + auto result = client->GetDmsProxy(); + EXPECT_EQ(result, nullptr); + GTEST_LOG_(INFO) << "DistributedClientTest GetDmsProxy_0200 end"; +} + /** * @tc.number: StartRemoteAbility_0100 * @tc.name: StartRemoteAbility @@ -86,6 +101,26 @@ HWTEST_F(DistributedClientTest, StartRemoteAbility_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbility_0100 end"; } +/** + * @tc.number: StartRemoteAbility_0200 + * @tc.name: StartRemoteAbility + * @tc.desc: StartRemoteAbility Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StartRemoteAbility_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbility_0200 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + int32_t callerUid = 5; + uint32_t accessToken = 0; + int32_t requestCode = 0; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StartRemoteAbility(want, callerUid, accessToken, requestCode); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbility_0200 end"; +} + /** * @tc.number: ConnectRemoteAbility_0100 * @tc.name: ConnectRemoteAbility @@ -121,6 +156,24 @@ HWTEST_F(DistributedClientTest, ConnectRemoteAbility_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest ConnectRemoteAbility_0200 end"; } +/** + * @tc.number: ConnectRemoteAbility_0300 + * @tc.name: ConnectRemoteAbility + * @tc.desc: ConnectRemoteAbility Test, when remote is nullptr, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, ConnectRemoteAbility_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest ConnectRemoteAbility_0300 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + sptr connect = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->ConnectRemoteAbility(want, connect); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + + GTEST_LOG_(INFO) << "DistributedClientTest ConnectRemoteAbility_0300 end"; +} + /** * @tc.number: DisconnectRemoteAbility_0100 * @tc.name: DisconnectRemoteAbility @@ -163,6 +216,26 @@ HWTEST_F(DistributedClientTest, DisconnectRemoteAbility_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest DisconnectRemoteAbility_0200 end"; } +/** + * @tc.number: DisconnectRemoteAbility_0300 + * @tc.name: DisconnectRemoteAbility + * @tc.desc: DisconnectRemoteAbility Test, when remote is nullptr, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, DisconnectRemoteAbility_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest DisconnectRemoteAbility_0300 start"; + auto client = std::make_shared(); + int32_t callerUid = 0; + uint32_t accessToken = 0; + OHOS::AAFwk::Want want; + sptr connect = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + client->ConnectRemoteAbility(want, connect); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->DisconnectRemoteAbility(connect, callerUid, accessToken); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest DisconnectRemoteAbility_0300 end"; +} + /** * @tc.number: ContinueMission_0100 * @tc.name: ContinueMission @@ -204,6 +277,27 @@ HWTEST_F(DistributedClientTest, ContinueMission_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest ContinueMission_0200 end"; } +/** + * @tc.number: ContinueMission_0300 + * @tc.name: ContinueMission + * @tc.desc: ContinueMission Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, ContinueMission_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest ContinueMission_300 start"; + auto client = std::make_shared(); + std::string srcDeviceId = "deviceId"; + std::string dstDeviceId = "deviceId"; + int32_t missionId = 0 ; + OHOS::AAFwk::WantParams wantParams; + sptr callback = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->ContinueMission(srcDeviceId, dstDeviceId, missionId, callback, wantParams); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + + GTEST_LOG_(INFO) << "DistributedClientTest ContinueMission_0300 end"; +} + /** * @tc.number: ContinueMissionBundleName_0100 * @tc.name: ContinueMissionBundleName @@ -254,6 +348,31 @@ HWTEST_F(DistributedClientTest, ContinueMissionBundleName_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest ContinueMissionBundleName_0200 end"; } +/** + * @tc.number: ContinueMissionBundleName_0300 + * @tc.name: ContinueMissionBundleName + * @tc.desc: ContinueMissionBundleName Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, ContinueMissionBundleName_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest ContinueMissionBundleName_0300 start"; + auto client = std::make_shared(); + std::string srcDeviceId = ""; + std::string dstDeviceId = ""; + AAFwk::WantParams wantParams; + OHOS::AAFwk::ContinueMissionInfo continueMissionInfo; + continueMissionInfo.dstDeviceId = dstDeviceId; + continueMissionInfo.srcDeviceId = srcDeviceId; + continueMissionInfo.bundleName = "bundleName"; + continueMissionInfo.wantParams = wantParams; + sptr callback = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->ContinueMission(continueMissionInfo, callback); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + + GTEST_LOG_(INFO) << "DistributedClientTest ContinueMissionBundleName_0300 end"; +} + /** * @tc.number: NotifyCompleteContinuation_0100 * @tc.name: NotifyCompleteContinuation @@ -275,6 +394,25 @@ HWTEST_F(DistributedClientTest, NotifyCompleteContinuation_0100, TestSize.Level3 GTEST_LOG_(INFO) << "DistributedClientTest NotifyCompleteContinuation_0100 end"; } +/** + * @tc.number: NotifyCompleteContinuation_0200 + * @tc.name: NotifyCompleteContinuation + * @tc.desc: NotifyCompleteContinuation Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, NotifyCompleteContinuation_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest NotifyCompleteContinuation_0200 start"; + auto client = std::make_shared(); + std::u16string devId = to_utf16("deviceId"); + int32_t sessionId = 0; + bool isSuccess = true; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + auto result = client->NotifyCompleteContinuation(devId, sessionId, isSuccess); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + + GTEST_LOG_(INFO) << "DistributedClientTest NotifyCompleteContinuation_0200 end"; +} + /** * @tc.number: StartSyncRemoteMissions_0100 * @tc.name: StartSyncRemoteMissions @@ -296,6 +434,24 @@ HWTEST_F(DistributedClientTest, StartSyncRemoteMissions_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StartSyncRemoteMissions_0100 end"; } +/** + * @tc.number: StartSyncRemoteMissions_0200 + * @tc.name: StartSyncRemoteMissions + * @tc.desc: StartSyncRemoteMissions Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StartSyncRemoteMissions_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StartSyncRemoteMissions_0200 start"; + auto client = std::make_shared(); + std::string devId = ""; + bool fixConflict = true; + int64_t tag = 0; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StartSyncRemoteMissions(devId, fixConflict, tag); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StartSyncRemoteMissions_0200 end"; +} + /** * @tc.number: StopSyncRemoteMissions_0100 * @tc.name: StopSyncRemoteMissions @@ -315,6 +471,22 @@ HWTEST_F(DistributedClientTest, StopSyncRemoteMissions_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StopSyncRemoteMissions_0100 end"; } +/** + * @tc.number: StopSyncRemoteMissions_0200 + * @tc.name: StopSyncRemoteMissions + * @tc.desc: StopSyncRemoteMissions Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StopSyncRemoteMissions_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StopSyncRemoteMissions_0200 start"; + auto client = std::make_shared(); + std::string devId = ""; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StopSyncRemoteMissions(devId); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StopSyncRemoteMissions_0200 end"; +} + /** * @tc.number: RegisterMissionListener_0100 * @tc.name: RegisterMissionListener @@ -335,6 +507,23 @@ HWTEST_F(DistributedClientTest, RegisterMissionListener_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest RegisterMissionListener_0100 end"; } +/** + * @tc.number: RegisterMissionListener_0200 + * @tc.name: RegisterMissionListener + * @tc.desc: RegisterMissionListener Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, RegisterMissionListener_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest RegisterMissionListener_0200 start"; + auto client = std::make_shared(); + std::u16string devId = to_utf16("deviceId"); + sptr obj = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->RegisterMissionListener(devId, obj); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest RegisterMissionListener_0200 end"; +} + /** * @tc.number: RegisterOnListener_0100 * @tc.name: RegisterOnListener @@ -354,6 +543,22 @@ HWTEST_F(DistributedClientTest, RegisterOnListener_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest RegisterOnListener_0100 end"; } +/** + * @tc.number: RegisterOnListener_0100 + * @tc.name: RegisterOnListener + * @tc.desc: RegisterOnListener Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, RegisterOnListener_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest RegisterOnListener_0200 start"; + auto client = std::make_shared(); + sptr obj = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->RegisterOnListener("type", obj); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest RegisterOnListener_0200 end"; +} + /** * @tc.number: RegisterOffListener_0100 * @tc.name: RegisterOffListener @@ -374,6 +579,23 @@ HWTEST_F(DistributedClientTest, RegisterOffListener_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest RegisterOffListener_0100 end"; } +/** + * @tc.number: RegisterOffListener_0200 + * @tc.name: RegisterOffListener + * @tc.desc: RegisterOffListener Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, RegisterOffListener_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest RegisterOffListener_0200 start"; + auto client = std::make_shared(); + sptr obj = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + client->RegisterOnListener("type", obj); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->RegisterOffListener("type", obj); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest RegisterOffListener_0200 end"; +} + /** * @tc.number: UnRegisterMissionListener_0100 * @tc.name: UnRegisterMissionListener @@ -395,6 +617,24 @@ HWTEST_F(DistributedClientTest, UnRegisterMissionListener_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest UnRegisterMissionListener_0100 end"; } +/** + * @tc.number: UnRegisterMissionListener_0200 + * @tc.name: UnRegisterMissionListener + * @tc.desc: UnRegisterMissionListener Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, UnRegisterMissionListener_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest UnRegisterMissionListener_0200 start"; + auto client = std::make_shared(); + std::u16string devId = to_utf16("deviceId"); + sptr obj = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + client->RegisterMissionListener(devId, obj); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->UnRegisterMissionListener(devId, obj); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest UnRegisterMissionListener_0200 end"; +} + /** * @tc.number: GetMissionInfos_0100 * @tc.name: GetMissionInfos @@ -416,6 +656,24 @@ HWTEST_F(DistributedClientTest, GetMissionInfos_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest GetMissionInfos_0100 end"; } +/** + * @tc.number: GetMissionInfos_0200 + * @tc.name: GetMissionInfos + * @tc.desc: GetMissionInfosTest, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, GetMissionInfos_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest GetMissionInfos_0200 start"; + auto client = std::make_shared(); + std::string deviceId = ""; + int32_t numMissions = 0; + std::vector missionInfos; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->GetMissionInfos(deviceId, numMissions, missionInfos); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest GetMissionInfos_0200 end"; +} + /** * @tc.number: GetRemoteMissionSnapshotInfo_0100 * @tc.name: GetRemoteMissionSnapshotInfo @@ -454,6 +712,24 @@ HWTEST_F(DistributedClientTest, GetRemoteMissionSnapshotInfo_0200, TestSize.Leve GTEST_LOG_(INFO) << "DistributedClientTest GetRemoteMissionSnapshotInfo_0200 end"; } +/** + * @tc.number: GetRemoteMissionSnapshotInfo_0300 + * @tc.name: GetRemoteMissionSnapshotInfo + * @tc.desc: GetRemoteMissionSnapshotInfo Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, GetRemoteMissionSnapshotInfo_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest GetRemoteMissionSnapshotInfo_0300 start"; + auto client = std::make_shared(); + std::string deviceId ="deviceId"; + int32_t numMissions = 0; + std::unique_ptr missionSnapshot = std::make_unique(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->GetRemoteMissionSnapshotInfo(deviceId, numMissions, missionSnapshot); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest GetRemoteMissionSnapshotInfo_0300 end"; +} + /** * @tc.number: ReadMissionInfosFromParcel_0100 * @tc.name: ReadMissionInfosFromParcel @@ -608,6 +884,26 @@ HWTEST_F(DistributedClientTest, StartContinuation_0100, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StartContinuation_0100 end"; } +/** + * @tc.number: StartContinuation_0200 + * @tc.name: StartContinuation + * @tc.desc: StartContinuation Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StartContinuation_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StartContinuation_0200 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + int32_t missionId = 0; + int32_t callerUid = -1; + int32_t status =0; + uint32_t accessToken = 0; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StartContinuation(want, missionId, callerUid, status, accessToken); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StartContinuation_0200 end"; +} + /** * @tc.number: StartRemoteAbilityByCall_0100 * @tc.name: StartRemoteAbilityByCall @@ -643,6 +939,23 @@ HWTEST_F(DistributedClientTest, StartRemoteAbilityByCall_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbilityByCall_0200 end"; } +/** + * @tc.number: StartRemoteAbilityByCall_0300 + * @tc.name: StartRemoteAbilityByCall + * @tc.desc: StartRemoteAbilityByCall Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StartRemoteAbilityByCall_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbilityByCall_0300 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + sptr connect = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StartRemoteAbilityByCall(want, connect); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteAbilityByCall_0300 end"; +} + /** * @tc.number: ReleaseRemoteAbility_0100 * @tc.name: ReleaseRemoteAbility @@ -683,6 +996,28 @@ HWTEST_F(DistributedClientTest, ReleaseRemoteAbility_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest ReleaseRemoteAbility_0200 end"; } +/** + * @tc.number: ReleaseRemoteAbility_0300 + * @tc.name: ReleaseRemoteAbility + * @tc.desc: ReleaseRemoteAbility Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, ReleaseRemoteAbility_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest ReleaseRemoteAbility_0300 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + int32_t callerUid = 0; + uint32_t accessToken = 0; + int32_t requestCode = 0; + client->StartRemoteAbility(want, callerUid, accessToken, requestCode); + AppExecFwk::ElementName element; + sptr connect = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->ReleaseRemoteAbility(connect, element); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest ReleaseRemoteAbility_0300 end"; +} + /** * @tc.number: StartRemoteFreeInstall_0100 * @tc.name: StartRemoteFreeInstall @@ -724,6 +1059,26 @@ HWTEST_F(DistributedClientTest, StartRemoteFreeInstall_0200, TestSize.Level3) GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteFreeInstall_0200 end"; } +/** + * @tc.number: StartRemoteFreeInstall_0300 + * @tc.name: StartRemoteFreeInstall + * @tc.desc: StartRemoteFreeInstall Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StartRemoteFreeInstall_0300, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteFreeInstall_0300 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + int32_t callerUid = 0; + int32_t requestCode = 0; + uint32_t accessToken = 0; + sptr callback = new (std::nothrow) OHOS::AAFwk::AbilityConnectCallback(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->StartRemoteFreeInstall(want, callerUid, requestCode, accessToken, callback); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StartRemoteFreeInstall_0300 end"; +} + /** * @tc.number: WriteInfosToParcel_0100 * @tc.name: WriteInfosToParcel @@ -763,6 +1118,25 @@ HWTEST_F(DistributedClientTest, StopRemoteExtensionAbility_0100, TestSize.Level1 GTEST_LOG_(INFO) << "DistributedClientTest StopRemoteExtensionAbility_0100 end"; } +/** + * @tc.number: StopRemoteExtensionAbility_0200 + * @tc.name: StopRemoteExtensionAbility + * @tc.desc: StopRemoteExtensionAbility Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, StopRemoteExtensionAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DistributedClientTest StopRemoteExtensionAbility_0200 start"; + auto client = std::make_shared(); + OHOS::AAFwk::Want want; + constexpr int32_t callerUid = 0; + constexpr uint32_t accessToken = 0; + constexpr int32_t extensionType = 3; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + auto result = client->StopRemoteExtensionAbility(want, callerUid, accessToken, extensionType); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest StopRemoteExtensionAbility_0200 end"; +} + /** * @tc.number: SetMissionContinueState_0100 * @tc.name: SetMissionContinueState @@ -781,4 +1155,21 @@ HWTEST_F(DistributedClientTest, SetMissionContinueState_0100, TestSize.Level3) EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); } GTEST_LOG_(INFO) << "DistributedClientTest SetMissionContinueState_0100 end"; +} + +/** + * @tc.number: SetMissionContinueState_0200 + * @tc.name: SetMissionContinueState + * @tc.desc: SetMissionContinueState Test, return INVALID_PARAMETERS_ERR. + */ +HWTEST_F(DistributedClientTest, SetMissionContinueState_0200, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "DistributedClientTest SetMissionContinueState_0200 start"; + auto client = std::make_shared(); + int32_t missionId = 0 ; + OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE; + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; + int32_t result = client->SetMissionContinueState(missionId, state); + EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest SetMissionContinueState_0200 end"; } \ No newline at end of file diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 6375d07741..93a72592f0 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -298,6 +298,10 @@ ErrCode AbilityManagerShellCommand::CreateMessageMap() KILL_PROCESS_KEEP_ALIVE, "error: keep alive process can not be killed.", }, + { + ERR_UNLOCK_SCREEN_FAILED_IN_DEVELOPER_MODE, + "error: unlock screen failed in developer mode." + } }; return OHOS::ERR_OK;