diff --git a/bundle.json b/bundle.json index c6dbfb47d0..d9bb30398c 100644 --- a/bundle.json +++ b/bundle.json @@ -77,6 +77,7 @@ "jsoncpp", "kv_store", "libuv", + "media_library", "memmgr", "memory_utils", "napi", @@ -93,7 +94,6 @@ "sandbox_manager", "screenlock_mgr", "storage_service", - "skia", "toolchain", "webview", "window_manager", @@ -274,6 +274,14 @@ }, "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:extensionkit_native" }, + { + "header": { + "header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/", + "header_files": [ + ] + }, + "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:abilitykit_utils" + }, { "header": { "header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/", diff --git a/frameworks/js/napi/ability_auto_startup_callback/BUILD.gn b/frameworks/js/napi/ability_auto_startup_callback/BUILD.gn index 3633bb1e8b..5af0b5ef66 100644 --- a/frameworks/js/napi/ability_auto_startup_callback/BUILD.gn +++ b/frameworks/js/napi/ability_auto_startup_callback/BUILD.gn @@ -42,13 +42,9 @@ ohos_shared_library("autostartupcallback") { "c_utils:utils", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] if (ability_runtime_graphics) { diff --git a/frameworks/js/napi/ability_auto_startup_manager/BUILD.gn b/frameworks/js/napi/ability_auto_startup_manager/BUILD.gn index 49131cffa7..2ee89dbcb1 100644 --- a/frameworks/js/napi/ability_auto_startup_manager/BUILD.gn +++ b/frameworks/js/napi/ability_auto_startup_manager/BUILD.gn @@ -41,18 +41,15 @@ ohos_shared_library("autostartupmanager") { ] external_deps = [ - # "ability_base:session_info", "access_token:libtokenid_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "graphic_2d:2d_graphics", "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", - # "skia:skia_canvaskit", ] relative_install_dir = "module/app/ability" diff --git a/frameworks/js/napi/featureAbility/BUILD.gn b/frameworks/js/napi/featureAbility/BUILD.gn index 820aec0c79..83f776f82b 100644 --- a/frameworks/js/napi/featureAbility/BUILD.gn +++ b/frameworks/js/napi/featureAbility/BUILD.gn @@ -15,13 +15,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("featureability") { - include_dirs = [ - "./", - "${relational_store_napi_path}/common/include", - "${relational_store_napi_path}/dataability/include", - "${relational_store_napi_path}/rdb/include", - "${relational_store_base_path}/frameworks/common/include", - ] + include_dirs = [ "./" ] sources = [ "feature_ability.cpp", @@ -54,14 +48,9 @@ ohos_shared_library("featureability") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "ets_runtime:libark_jsruntime", - "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "ipc:ipc_napi", - "kv_store:distributeddata_inner", - "data_share:datashare_provider", "libuv:uv", "napi:ace_napi", ] @@ -77,25 +66,24 @@ ohos_shared_library("featureability") { ] } - # if (ability_runtime_relational) { - # include_dirs += [ - # "${relational_store_napi_path}/common/include", - # "${relational_store_napi_path}/dataability/include", - # "${relational_store_napi_path}/rdb/include", - # ] - # sources += [ - # "${relational_store_napi_path}/common/src/js_utils.cpp", - # "${relational_store_napi_path}/dataability/src/napi_data_ability_predicates.cpp", - # "${relational_store_napi_path}/rdb/src/napi_rdb_js_utils.cpp", - # "${relational_store_napi_path}/rdb/src/napi_result_set.cpp", - # ] - # external_deps += [ - # "kv_store:distributeddata_mgr", - # "relational_store:native_dataability", - # "relational_store:native_rdb", - # "relational_store:rdb_data_share_adapter", - # ] - # } + if (ability_runtime_relational) { + include_dirs += [ "data_ability/include" ] + sources += [ + "data_ability/js_utils.cpp", + "data_ability/napi_data_ability_predicates.cpp", + "data_ability/napi_rdb_js_utils.cpp", + "data_ability/napi_result_set.cpp", + ] + external_deps += [ + "ets_runtime:libark_jsruntime", + "eventhandler:libeventhandler", + "kv_store:distributeddata_mgr", + "relational_store:native_appdatafwk", + "relational_store:native_dataability", + "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", + ] + } cflags_cc = [] if (os_dlp_part_enabled) { cflags_cc += [ "-DWITH_DLP" ] diff --git a/frameworks/js/napi/featureAbility/data_ability/include/js_utils.h b/frameworks/js/napi/featureAbility/data_ability/include/js_utils.h new file mode 100644 index 0000000000..920cfd17bc --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/js_utils.h @@ -0,0 +1,363 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTEDDATAMGR_APPDATAMGR_JSUTILS_H +#define DISTRIBUTEDDATAMGR_APPDATAMGR_JSUTILS_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace AppDataMgrJsKit { +namespace JSUtils { +#define DECLARE_JS_PROPERTY(env, key, value) \ + napi_property_descriptor(DECLARE_NAPI_DEFAULT_PROPERTY((key), Convert2JSValue((env), (value)))) + +#define ASSERT(condition, message, retVal) \ + do { \ + if (!(condition)) { \ + LOG_ERROR("test (" #condition ") failed: " message); \ + return retVal; \ + } \ + } while (0) +static constexpr int OK = 0; +static constexpr int ERR = -1; +static constexpr uint32_t ASYNC_RST_SIZE = 2; +static constexpr uint32_t DEFAULT_VALUE_LENGTH = 1024; +static constexpr uint32_t MAX_VALUE_LENGTH = 1024 * 1024 * 8; // the max length of all kand of out string value +static constexpr uint32_t SYNC_RESULT_ELEMENT_NUM = 2; +struct JsFeatureSpace { + const char *spaceName; + const char *nameBase64; + bool isComponent; +}; + +void SetHapVersion(int32_t hapversion); +int32_t GetHapVersion(); + +int32_t Convert2Value(napi_env env, napi_value jsValue, napi_value &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, bool &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, double &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, int64_t &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::string &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::vector &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::vector &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::monostate &value); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::map &output); +int32_t Convert2Value(napi_env env, napi_value jsValue, std::map &output); + +bool IsNull(napi_env env, napi_value value); + +bool Equal(napi_env env, napi_ref ref, napi_value value); + +template +int32_t Convert2Value(napi_env env, napi_value jsValue, T &output); + +template +int32_t Convert2ValueExt(napi_env env, napi_value jsValue, T &output); + +int32_t Convert2ValueExt(napi_env env, napi_value jsValue, uint32_t &output); +int32_t Convert2ValueExt(napi_env env, napi_value jsValue, int32_t &output); +int32_t Convert2ValueExt(napi_env env, napi_value jsValue, int64_t &output); + +template +int32_t Convert2Value(napi_env env, napi_value jsValue, std::vector &value); + +template +int32_t Convert2Value(napi_env env, napi_value jsValue, std::map &value); + +template +int32_t Convert2Value(napi_env env, napi_value jsValue, std::variant &value); + +using Descriptor = std::function()>; +const std::optional GetJsFeatureSpace(const std::string &name); +/* napi_define_class wrapper */ +napi_value DefineClass(napi_env env, const std::string &spaceName, const std::string &className, + const Descriptor &descriptor, napi_callback ctor); +napi_value GetClass(napi_env env, const std::string &spaceName, const std::string &className); +std::string Convert2String(napi_env env, napi_value jsStr); + +int32_t Convert2JSValue(napi_env env, std::string value, napi_value &output); +int32_t Convert2JSValue(napi_env env, bool value, napi_value &output); +int32_t Convert2JSValue(napi_env env, double value, napi_value &output); + +napi_value Convert2JSValue(napi_env env, const std::string &value); +napi_value Convert2JSValue(napi_env env, const std::vector &value); +napi_value Convert2JSValue(napi_env env, const std::vector &value); +napi_value Convert2JSValue(napi_env env, int32_t value); +napi_value Convert2JSValue(napi_env env, uint32_t value); +napi_value Convert2JSValue(napi_env env, int64_t value); +napi_value Convert2JSValue(napi_env env, double value); +napi_value Convert2JSValue(napi_env env, bool value); +napi_value Convert2JSValue(napi_env env, const std::map &value); +napi_value Convert2JSValue(napi_env env, const std::monostate &value); + +template +napi_value Convert2JSValue(napi_env env, const T &value); + +template +napi_value Convert2JSValue(napi_env env, const std::vector &value); + +template +napi_value Convert2JSValue(napi_env env, const std::map &value); + +template +napi_value Convert2JSValue(napi_env env, const std::tuple &value); + +template +napi_value Convert2JSValue(napi_env env, const std::variant &value); + +template +std::string ToString(const T &key); + +template +std::enable_if_t, std::string> ConvertMapKey(const K &key) +{ + return ToString(key); +} + +template +std::enable_if_t, const std::string &> ConvertMapKey(const K &key) +{ + return key; +} + +template +int32_t GetCPPValue(napi_env env, napi_value jsValue, T &value) +{ + return napi_invalid_arg; +} + +template +int32_t GetCPPValue(napi_env env, napi_value jsValue, T &value) +{ + First cValue; + auto ret = Convert2Value(env, jsValue, cValue); + if (ret == napi_ok) { + value = cValue; + return ret; + } + return GetCPPValue(env, jsValue, value); +} + +template +napi_value GetJSValue(napi_env env, const T &value) +{ + return nullptr; +} + +template +napi_value GetJSValue(napi_env env, const T &value) +{ + auto *val = std::get_if(&value); + if (val != nullptr) { + return Convert2JSValue(env, *val); + } + return GetJSValue(env, value); +} + +std::pair GetInnerValue(napi_env env, napi_value in, const std::string &prop, bool optional); + +template +inline std::enable_if_t || std::is_same_v, int32_t> GetNamedProperty( + napi_env env, napi_value in, const std::string &prop, T &value, bool optional = false) +{ + auto [status, jsValue] = GetInnerValue(env, in, prop, optional); + if (jsValue == nullptr) { + return status; + } + return Convert2ValueExt(env, jsValue, value); +}; + +template +inline std::enable_if_t && !std::is_same_v, int32_t> GetNamedProperty( + napi_env env, napi_value in, const std::string &prop, T &value, bool optional = false) +{ + auto [status, jsValue] = GetInnerValue(env, in, prop, optional); + if (jsValue == nullptr) { + return status; + } + return Convert2Value(env, jsValue, value); +}; + +template +inline int32_t SetNamedProperty(napi_env env, napi_value in, const std::string &prop, T value) +{ + return napi_set_named_property(env, in, prop.c_str(), Convert2JSValue(env, value)); +}; + +napi_value ToJsObject(napi_env env, napi_value sendableValue); +napi_value ToJsArray(napi_env env, napi_value sendableValue); +napi_value ToJsTypedArray(napi_env env, napi_value sendableValue); +napi_value Convert2JSValue(napi_env env, napi_value sendableValue); +} // namespace JSUtils + +template +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::vector &value) +{ + bool isArray = false; + napi_is_array(env, jsValue, &isArray); + if (!isArray) { + return napi_invalid_arg; + } + + uint32_t arrLen = 0; + napi_get_array_length(env, jsValue, &arrLen); + if (arrLen == 0) { + return napi_ok; + } + + for (size_t i = 0; i < arrLen; ++i) { + napi_value element; + napi_get_element(env, jsValue, i, &element); + T item; + auto status = Convert2Value(env, element, item); + if (status != napi_ok) { + return napi_invalid_arg; + } + value.push_back(std::move(item)); + } + return napi_ok; +} + +template +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::map &value) +{ + napi_value jsMapList = nullptr; + uint32_t jsCount = 0; + napi_status status = napi_get_property_names(env, jsValue, &jsMapList); + if (status != napi_ok) { + return napi_invalid_arg; + } + status = napi_get_array_length(env, jsMapList, &jsCount); + if (status != napi_ok || jsCount <= 0) { + return napi_invalid_arg; + } + napi_value jsKey = nullptr; + napi_value jsVal = nullptr; + for (uint32_t index = 0; index < jsCount; index++) { + status = napi_get_element(env, jsMapList, index, &jsKey); + if (status != napi_ok) { + return napi_invalid_arg; + } + std::string key; + int ret = Convert2Value(env, jsKey, key); + if (status != napi_ok) { + return napi_invalid_arg; + } + status = napi_get_property(env, jsValue, jsKey, &jsVal); + if (status != napi_ok || jsVal == nullptr) { + return napi_invalid_arg; + } + T val; + ret = Convert2Value(env, jsVal, val); + if (status != napi_ok) { + return napi_invalid_arg; + } + value.insert(std::pair(key, val)); + } + return napi_ok; +} + +template +napi_value JSUtils::Convert2JSValue(napi_env env, const std::map &value) +{ + napi_value jsValue; + napi_status status = napi_create_object(env, &jsValue); + if (status != napi_ok) { + return nullptr; + } + + for (const auto &[key, val] : value) { + const std::string &name = ConvertMapKey(key); + status = napi_set_named_property(env, jsValue, name.c_str(), Convert2JSValue(env, val)); + if (status != napi_ok) { + return nullptr; + } + } + return jsValue; +} + +template +napi_value JSUtils::Convert2JSValue(napi_env env, const std::tuple &value) +{ + napi_value jsValue; + napi_status status = napi_create_object(env, &jsValue); + if (status != napi_ok) { + return nullptr; + } + napi_value code = Convert2JSValue(env, std::get<0>(value)); + napi_value description = Convert2JSValue(env, std::get<1>(value)); + napi_value val = Convert2JSValue(env, std::get<2>(value)); + if (description == nullptr || val == nullptr) { + return nullptr; + } + napi_set_named_property(env, jsValue, "code", code); + napi_set_named_property(env, jsValue, "description", description); + napi_set_named_property(env, jsValue, "value", val); + return jsValue; +} + +template +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::variant &value) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok) { + return napi_invalid_arg; + } + if (type == napi_undefined) { + return napi_generic_failure; + } + + return GetCPPValue(env, jsValue, value); +} + +template +napi_value JSUtils::Convert2JSValue(napi_env env, const std::vector &value) +{ + napi_value jsValue; + napi_status status = napi_create_array_with_length(env, value.size(), &jsValue); + if (status != napi_ok) { + return nullptr; + } + + for (size_t i = 0; i < value.size(); ++i) { + napi_set_element(env, jsValue, i, Convert2JSValue(env, value[i])); + } + return jsValue; +} + +template +napi_value JSUtils::Convert2JSValue(napi_env env, const std::variant &value) +{ + return GetJSValue(env, value); +} +} // namespace AppDataMgrJsKit +} // namespace OHOS +#endif // DISTRIBUTEDDATAMGR_APPDATAMGR_JSUTILS_H \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_async_proxy.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_async_proxy.h new file mode 100644 index 0000000000..d04c84b58c --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_async_proxy.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PREFERENCES_JSKIT_NAPI_ASYNC_PROXY_H +#define PREFERENCES_JSKIT_NAPI_ASYNC_PROXY_H +#include + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "securec.h" + +namespace OHOS { +namespace AppDataMgrJsKit { +constexpr int MAX_INPUT_COUNT = 10; +constexpr int OK = 0; +constexpr int ERR = -1; + +// T inherits AysncContext +template class NapiAsyncProxy { +public: + constexpr static int RESULT_COUNT = 2; + using InputParser = void (*)(const napi_env &, const napi_value &, T *); + using NapiAsyncExecute = int (*)(T *); + using NapiAsyncComplete = int (*)(T *, napi_value &); + + // AsyncContext base + struct AysncContext { + AysncContext() + { + } + virtual ~AysncContext() + { + if (env == nullptr) { + return; + } + napi_delete_async_work(env, work); + napi_delete_reference(env, callbackRef); + } + napi_env env = nullptr; + napi_callback_info info = nullptr; + napi_async_work work = nullptr; + napi_deferred deferred = nullptr; + napi_ref callbackRef = nullptr; + NapiAsyncExecute execFunc = nullptr; + int execStatus = ERR; + NapiAsyncComplete completeFunc = nullptr; + void *boundObj = nullptr; + }; + +public: + void Init(napi_env env, napi_callback_info info) + { + asyncContext = new T(); + if (asyncContext == nullptr) { + return; + } + asyncContext->env = env; + asyncContext->info = info; + } + + ~NapiAsyncProxy() + { + if (asyncContext == nullptr) { + return; + } + + delete asyncContext; + asyncContext = nullptr; + } + + static void DefParserThis(const napi_env &env, const napi_value &self, T *context) + { + napi_unwrap(env, self, &context->boundObj); + } + + void ParseInputs(const std::vector &parsers, InputParser parserThis = DefParserThis) + { + if (asyncContext == nullptr) { + return; + } + + napi_value thisObj = nullptr; + size_t argc = parsers.size() + 1; + napi_value args[MAX_INPUT_COUNT] = { 0 }; + napi_get_cb_info(asyncContext->env, asyncContext->info, &argc, args, &thisObj, nullptr); + for (size_t i = 0; i < argc && argc <= MAX_INPUT_COUNT; i++) { + if (i >= parsers.size()) { + napi_valuetype valueType = napi_undefined; + napi_typeof(asyncContext->env, args[i], &valueType); + if (valueType == napi_function) { + napi_create_reference(asyncContext->env, args[i], 1, &asyncContext->callbackRef); + } + break; + } + auto *parserFunction = parsers[i]; + if (parserFunction != nullptr) { + parserFunction(asyncContext->env, args[i], this->asyncContext); + } + } + parserThis(asyncContext->env, thisObj, asyncContext); + } + + napi_value DoAsyncWork(std::string resourceName, NapiAsyncExecute execFunc, NapiAsyncComplete completeFunc) + { + if (asyncContext == nullptr) { + return nullptr; + } + + napi_value ret = nullptr; + if (asyncContext->callbackRef == nullptr) { + napi_create_promise(asyncContext->env, &asyncContext->deferred, &ret); + } else { + napi_get_undefined(asyncContext->env, &ret); + } + + napi_value resource = nullptr; + napi_create_string_utf8(asyncContext->env, resourceName.c_str(), NAPI_AUTO_LENGTH, &resource); + asyncContext->execFunc = execFunc; + asyncContext->completeFunc = completeFunc; + NAPI_CALL_BASE(asyncContext->env, napi_create_async_work(asyncContext->env, nullptr, resource, + [](napi_env env, void *data) { + T *context = (T *)data; + context->execStatus = context->execFunc(context); + }, + [](napi_env env, napi_status status, void *data) { + T *context = (T *)data; + napi_value output = nullptr; + int completeStatus = context->completeFunc(context, output); + napi_value result[RESULT_COUNT] = { 0 }; + if (context->execStatus == OK && completeStatus == OK) { + napi_get_undefined(env, &result[0]); + result[1] = output; + } else { + napi_value message = nullptr; + napi_create_string_utf8(env, "async call failed", NAPI_AUTO_LENGTH, &message); + napi_create_error(env, nullptr, message, &result[0]); + napi_get_undefined(env, &result[1]); + } + if (context->deferred) { + // promise + if (context->execStatus == OK && completeStatus == OK) { + napi_resolve_deferred(env, context->deferred, result[1]); + } else { + napi_reject_deferred(env, context->deferred, result[0]); + } + } else { + // callback + napi_value callback = nullptr; + napi_get_reference_value(env, context->callbackRef, &callback); + napi_value callbackResult = nullptr; + napi_call_function(env, nullptr, callback, RESULT_COUNT, result, &callbackResult); + } + delete context; + }, + (void *)asyncContext, &asyncContext->work), ret); + NAPI_CALL_BASE(asyncContext->env, napi_queue_async_work(asyncContext->env, asyncContext->work), ret); + return ret; + } + +private: + T *asyncContext; +}; +} // namespace AppDataMgrJsKit +} // namespace OHOS +#endif diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_data_ability_predicates.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_data_ability_predicates.h new file mode 100644 index 0000000000..b9044f1166 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_data_ability_predicates.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DATAABILITY_JSKIT_NAPI_DATA_ABILITY_PREDICATES_H +#define DATAABILITY_JSKIT_NAPI_DATA_ABILITY_PREDICATES_H + +#include +#include "data_ability_predicates.h" +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace DataAbilityJsKit { +class DataAbilityPredicatesProxy { +public: + static void Init(napi_env env, napi_value exports); + static napi_value NewInstance(napi_env env, std::shared_ptr value); + static std::shared_ptr GetNativePredicates( + const napi_env env, const napi_value arg); + static void Destructor(napi_env env, void *nativeObject, void *finalize_hint); + + DataAbilityPredicatesProxy(); + std::shared_ptr GetPredicates() const; + +private: + ~DataAbilityPredicatesProxy(); + + static napi_value New(napi_env env, napi_callback_info info); + static std::shared_ptr GetNativePredicates(napi_env env, + napi_callback_info info); + static napi_value EqualTo(napi_env env, napi_callback_info info); + static napi_value NotEqualTo(napi_env env, napi_callback_info info); + static napi_value BeginWrap(napi_env env, napi_callback_info info); + static napi_value EndWrap(napi_env env, napi_callback_info info); + static napi_value Or(napi_env env, napi_callback_info info); + static napi_value And(napi_env env, napi_callback_info info); + static napi_value Contains(napi_env env, napi_callback_info info); + static napi_value BeginsWith(napi_env env, napi_callback_info info); + static napi_value EndsWith(napi_env env, napi_callback_info info); + static napi_value IsNull(napi_env env, napi_callback_info info); + static napi_value IsNotNull(napi_env env, napi_callback_info info); + static napi_value Like(napi_env env, napi_callback_info info); + static napi_value Glob(napi_env env, napi_callback_info info); + static napi_value Between(napi_env env, napi_callback_info info); + static napi_value NotBetween(napi_env env, napi_callback_info info); + static napi_value GreaterThan(napi_env env, napi_callback_info info); + static napi_value LessThan(napi_env env, napi_callback_info info); + static napi_value GreaterThanOrEqualTo(napi_env env, napi_callback_info info); + static napi_value LessThanOrEqualTo(napi_env env, napi_callback_info info); + static napi_value OrderByAsc(napi_env env, napi_callback_info info); + static napi_value OrderByDesc(napi_env env, napi_callback_info info); + static napi_value Distinct(napi_env env, napi_callback_info info); + static napi_value Limit(napi_env env, napi_callback_info info); + static napi_value Offset(napi_env env, napi_callback_info info); + static napi_value GroupBy(napi_env env, napi_callback_info info); + static napi_value IndexedBy(napi_env env, napi_callback_info info); + static napi_value In(napi_env env, napi_callback_info info); + static napi_value NotIn(napi_env env, napi_callback_info info); + static napi_value Clear(napi_env env, napi_callback_info info); + static napi_value IsRawSelection(napi_env env, napi_callback_info info); + static napi_value GetWhereClause(napi_env env, napi_callback_info info); + static napi_value SetWhereClause(napi_env env, napi_callback_info info); + static napi_value GetWhereArgs(napi_env env, napi_callback_info info); + static napi_value SetWhereArgs(napi_env env, napi_callback_info info); + static napi_value GetOrder(napi_env env, napi_callback_info info); + static napi_value SetOrder(napi_env env, napi_callback_info info); + static napi_value GetLimit(napi_env env, napi_callback_info info); + static napi_value GetOffset(napi_env env, napi_callback_info info); + static napi_value IsDistinct(napi_env env, napi_callback_info info); + static napi_value GetGroup(napi_env env, napi_callback_info info); + static napi_value GetIndex(napi_env env, napi_callback_info info); + static napi_value IsNeedAnd(napi_env env, napi_callback_info info); + static napi_value IsSorted(napi_env env, napi_callback_info info); + std::shared_ptr predicates_; +}; +} // namespace DataAbilityJsKit +} // namespace OHOS + +EXTERN_C_START +__attribute__((visibility("default"))) + napi_value NAPI_OHOS_Data_DataAbilityJsKit_DataAbilityPredicatesProxy_NewInstance(napi_env env, + OHOS::NativeRdb::DataAbilityPredicates *predicates); + +__attribute__((visibility("default"))) OHOS::NativeRdb::DataAbilityPredicates * +NAPI_OHOS_Data_DataAbilityJsKit_DataAbilityPredicatesProxy_GetNativeObject( + const napi_env env, const napi_value arg); +EXTERN_C_END +#endif // DATAABILITY_JSKIT_NAPI_DATA_ABILITY_PREDICATES_H \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_predicates_utils.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_predicates_utils.h new file mode 100644 index 0000000000..08a6c6e666 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_predicates_utils.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APPDATAMGR_NAPI_PREDICATES_UTILS_H +#define APPDATAMGR_NAPI_PREDICATES_UTILS_H + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace DataAbilityJsKit { +napi_value InitPredicatesUtils(napi_env env, napi_value info); +#define RDB_CHECK_RETURN_NULLPTR(assertion, message) \ + do { \ + if (!(assertion)) { \ + LOG_ERROR("%{public}s", message); \ + return nullptr; \ + } \ + } while (0) +} // namespace DataAbilityJsKit +} // namespace OHOS +#endif // APPDATAMGR_NAPI_PREDICATES_UTILS_H diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_error.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_error.h new file mode 100644 index 0000000000..0f7e7cfb20 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_error.h @@ -0,0 +1,213 @@ +/* + * 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. + */ +#ifndef RDB_JS_NAPI_ERROR_H +#define RDB_JS_NAPI_ERROR_H + +#include "logger.h" + +namespace OHOS { +namespace AppDataMgrJsKit { +constexpr int MAX_INPUT_COUNT = 10; +constexpr int OK = 0; +constexpr int ERR = -1; +constexpr int APIVERSION_V9 = 9; +constexpr int APIVERSION_8 = 8; + +constexpr int E_PARAM_ERROR = 401; +constexpr int E_INNER_ERROR = 14800000; + +constexpr int E_DB_INVALID = 14800010; +constexpr int E_DB_CORRUPTED = 14800011; +constexpr int E_RESULT_GET_ERROR = 14800013; +constexpr int E_RESULT_GOTO_ERROR = 14800012; + +#define RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, retVal, version) \ + do { \ + if (!(assertion)) { \ + if ((error) == nullptr) { \ + LOG_ERROR("throw error: error message is empty,version= %{public}d", version); \ + napi_throw_error((env), nullptr, "error message is empty"); \ + return retVal; \ + } \ + if (((version) > (APIVERSION_8)) || (((error)->GetCode()) == (401))) { \ + LOG_ERROR("throw error: code = %{public}d , message = %{public}s, version= %{public}d", \ + (error)->GetCode(), (error)->GetMessage().c_str(), version); \ + napi_throw_error((env), std::to_string((error)->GetCode()).c_str(), (error)->GetMessage().c_str()); \ + return retVal; \ + } \ + LOG_ERROR("nothrow error: code = %{public}d , message = %{public}s, version= %{public}d", \ + (error)->GetCode(), (error)->GetMessage().c_str(), version); \ + } \ + } while (0) + +#define RDB_REVT_NOTHING + +#define RDB_NAPI_ASSERT_FROMV9(env, assertion, error, version) \ + RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, nullptr, version) + +#define RDB_NAPI_ASSERT_RETURN_VOID_FROMV9(env, assertion, error, version) \ + RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, NAPI_RETVAL_NOTHING, version) + +#define RDB_ASYNC_PARAM_CHECK_FUNCTION(theCall) \ + do { \ + int err = (theCall); \ + if (err != OK) { \ + return err; \ + } \ + } while (0) + +#define RDB_CHECK_RETURN_NULLPTR(assertion, message) \ + do { \ + if (!(assertion)) { \ + LOG_ERROR("%{public}s", message); \ + return nullptr; \ + } \ + } while (0) + +#define RDB_CHECK_RETURN_VOID(assertion, message) \ + do { \ + if (!(assertion)) { \ + LOG_ERROR("%{public}s", message); \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_CORE(assertion, theCall, revt) \ + do { \ + if (!(assertion)) { \ + theCall; \ + return revt; \ + } \ + } while (0) + +#define CHECK_RETURN_ERR(assertion) \ + CHECK_RETURN_CORE(assertion, RDB_REVT_NOTHING, ERR) + +#define RDB_CHECK_RETURN_CALL_RESULT(assertion, theCall) \ + do { \ + if (!(assertion)) { \ + (theCall); \ + return ERR; \ + } \ + } while (0) + +class Error { +public: + virtual ~Error(){}; + virtual std::string GetMessage() = 0; + virtual int GetCode() = 0; +}; + +class InnerError : public Error { +public: + InnerError() = default; + std::string GetMessage() override + { + return "System error."; + }; + int GetCode() override + { + return E_INNER_ERROR; + }; +}; + +class ParamTypeError : public Error { +public: + ParamTypeError(const std::string &name, const std::string &wantType) : name(name), wantType(wantType){}; + std::string GetMessage() override + { + return "Parameter error. The type of '" + name + "' must be " + wantType; + }; + int GetCode() override + { + return E_PARAM_ERROR; + }; + +private: + std::string name; + std::string wantType; +}; + +class ParamNumError : public Error { +public: + ParamNumError(const std::string &wantNum) : wantNum(wantNum){}; + std::string GetMessage() override + { + return "Parameter error. Need " + wantNum + " parameters!"; + }; + int GetCode() override + { + return E_PARAM_ERROR; + }; + +private: + std::string wantNum; +}; + +class DbInvalidError : public Error { +public: + DbInvalidError() = default; + std::string GetMessage() override + { + return "Failed open database, invalid database name."; + }; + int GetCode() override + { + return E_DB_INVALID; + }; +}; + +class DbCorruptedError : public Error { +public: + DbCorruptedError() = default; + std::string GetMessage() override + { + return "Failed open database, database corrupted."; + }; + int GetCode() override + { + return E_DB_CORRUPTED; + }; +}; + +class ResultGetError : public Error { +public: + ResultGetError() = default; + std::string GetMessage() override + { + return "The column value is null or the column type is incompatible."; + }; + int GetCode() override + { + return E_RESULT_GET_ERROR; + }; +}; + +class ResultGotoError : public Error { +public: + ResultGotoError() = default; + std::string GetMessage() override + { + return "The result set is empty or the specified location is invalid."; + }; + int GetCode() override + { + return E_RESULT_GOTO_ERROR; + }; +}; +} // namespace AppDataMgrJsKit +} // namespace OHOS + +#endif // RDB_JS_NAPI_ERROR_H diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_js_utils.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_js_utils.h new file mode 100644 index 0000000000..cb22f0e9d0 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_js_utils.h @@ -0,0 +1,42 @@ +/* + * 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 RDB_JSKIT_NAPI_RDB_JS_UTILS_H +#define RDB_JSKIT_NAPI_RDB_JS_UTILS_H +#include "asset_value.h" +#include "js_utils.h" +#include "result_set.h" +#include "value_object.h" +namespace OHOS::AppDataMgrJsKit { +namespace JSUtils { +using Asset = OHOS::NativeRdb::AssetValue; +using RowEntity = OHOS::NativeRdb::RowEntity; +using ValueObject = OHOS::NativeRdb::ValueObject; +using BigInt = OHOS::NativeRdb::BigInteger; +template<> +int32_t Convert2Value(napi_env env, napi_value input, Asset &output); +template<> +napi_value Convert2JSValue(napi_env env, const Asset &value); +template<> +napi_value Convert2JSValue(napi_env env, const RowEntity &value); +template<> +int32_t Convert2Value(napi_env env, napi_value jsValue, ValueObject &valueObject); +template<> +napi_value Convert2JSValue(napi_env env, const BigInt &value); +template<> +int32_t Convert2Value(napi_env env, napi_value jsValue, BigInt &value); +}; // namespace JSUtils +} // namespace OHOS::AppDataMgrJsKit +#endif // RDB_JSKIT_NAPI_RDB_JS_UTILS_H diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_predicates.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_predicates.h new file mode 100644 index 0000000000..81ba767f58 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_predicates.h @@ -0,0 +1,113 @@ +/* + * 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. + */ + +#ifndef RDB_JSKIT_NAPI_RDB_PREDICATES_H +#define RDB_JSKIT_NAPI_RDB_PREDICATES_H + +#include + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi_rdb_error.h" +#include "rdb_predicates.h" + +namespace OHOS { +namespace RdbJsKit { +class RdbPredicatesProxy { +public: + static void Init(napi_env env, napi_value exports); + static napi_value NewInstance( + napi_env env, std::shared_ptr value, int version = AppDataMgrJsKit::APIVERSION_8); + static void Destructor(napi_env env, void *nativeObject, void *finalize_hint); + + explicit RdbPredicatesProxy(std::string &tableName); + std::shared_ptr GetPredicates() const; + int apiversion = AppDataMgrJsKit::APIVERSION_8; + +private: + ~RdbPredicatesProxy(); + + static napi_value New(napi_env env, napi_callback_info info); + static napi_value NewV9(napi_env env, napi_callback_info info); + static napi_value InnerNew(napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_8); + static std::shared_ptr GetNativePredicates(napi_env env, napi_callback_info info); + + static RdbPredicatesProxy *ParseFieldArrayByName(napi_env env, napi_callback_info info, napi_value &thiz, + std::vector &fieldarray, const std::string fieldName, const std::string fieldType); + static RdbPredicatesProxy *ParseFieldByName( + napi_env env, napi_callback_info info, napi_value &thiz, std::string &field, const std::string fieldName); + static RdbPredicatesProxy *ParseInt32FieldByName( + napi_env env, napi_callback_info info, napi_value &thiz, int32_t &field, const std::string fieldName); + static RdbPredicatesProxy *ParseFieldAndValueArray(napi_env env, napi_callback_info info, napi_value &thiz, + std::string &field, std::vector &value, const std::string valueType); + static RdbPredicatesProxy *ParseFieldAndValue(napi_env env, napi_callback_info info, napi_value &thiz, + std::string &field, NativeRdb::ValueObject &value, const std::string valueType); + static RdbPredicatesProxy *ParseFieldAndStringValue(napi_env env, napi_callback_info info, napi_value &thiz, + std::string &field, std::string &value, const std::string valueType); + static RdbPredicatesProxy *ParseFieldLowAndHigh(napi_env env, napi_callback_info info, napi_value &thiz, + std::string &field, NativeRdb::ValueObject &low, NativeRdb::ValueObject &High); + + static napi_value EqualTo(napi_env env, napi_callback_info info); + static napi_value NotEqualTo(napi_env env, napi_callback_info info); + static napi_value BeginWrap(napi_env env, napi_callback_info info); + static napi_value EndWrap(napi_env env, napi_callback_info info); + static napi_value Or(napi_env env, napi_callback_info info); + static napi_value And(napi_env env, napi_callback_info info); + static napi_value Contains(napi_env env, napi_callback_info info); + static napi_value BeginsWith(napi_env env, napi_callback_info info); + static napi_value EndsWith(napi_env env, napi_callback_info info); + static napi_value IsNull(napi_env env, napi_callback_info info); + static napi_value IsNotNull(napi_env env, napi_callback_info info); + static napi_value Like(napi_env env, napi_callback_info info); + static napi_value Glob(napi_env env, napi_callback_info info); + static napi_value Between(napi_env env, napi_callback_info info); + static napi_value NotBetween(napi_env env, napi_callback_info info); + static napi_value GreaterThan(napi_env env, napi_callback_info info); + static napi_value LessThan(napi_env env, napi_callback_info info); + static napi_value GreaterThanOrEqualTo(napi_env env, napi_callback_info info); + static napi_value LessThanOrEqualTo(napi_env env, napi_callback_info info); + static napi_value OrderByAsc(napi_env env, napi_callback_info info); + static napi_value OrderByDesc(napi_env env, napi_callback_info info); + static napi_value Distinct(napi_env env, napi_callback_info info); + static napi_value Limit(napi_env env, napi_callback_info info); + static napi_value Offset(napi_env env, napi_callback_info info); + static napi_value GroupBy(napi_env env, napi_callback_info info); + static napi_value IndexedBy(napi_env env, napi_callback_info info); + static napi_value In(napi_env env, napi_callback_info info); + static napi_value NotIn(napi_env env, napi_callback_info info); + static napi_value Using(napi_env env, napi_callback_info info); + static napi_value Clear(napi_env env, napi_callback_info info); + static napi_value CrossJoin(napi_env env, napi_callback_info info); + static napi_value LeftOuterJoin(napi_env env, napi_callback_info info); + static napi_value GetJoinCount(napi_env env, napi_callback_info info); + static napi_value SetJoinConditions(napi_env env, napi_callback_info info); + static napi_value SetJoinTableNames(napi_env env, napi_callback_info info); + static napi_value SetJoinTypes(napi_env env, napi_callback_info info); + static napi_value SetJoinCount(napi_env env, napi_callback_info info); + static napi_value GetJoinTypes(napi_env env, napi_callback_info info); + static napi_value GetJoinTableNames(napi_env env, napi_callback_info info); + static napi_value GetJoinConditions(napi_env env, napi_callback_info info); + static napi_value InnerJoin(napi_env env, napi_callback_info info); + static napi_value On(napi_env env, napi_callback_info info); + static napi_value InDevices(napi_env env, napi_callback_info info); + static napi_value InAllDevices(napi_env env, napi_callback_info info); + + std::shared_ptr predicates_; +}; +} // namespace RdbJsKit +} // namespace OHOS + +#endif // RDB_JSKIT_NAPI_RDB_PREDICATES_H diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_trace.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_trace.h new file mode 100644 index 0000000000..0fbbb1888b --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_rdb_trace.h @@ -0,0 +1,27 @@ +/* + * 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. + */ +#ifndef DISTRIBUTEDDATAMGR_NAPI_RDB_TRACE_H +#define DISTRIBUTEDDATAMGR_NAPI_RDB_TRACE_H + +#define DO_NOTHING + +#ifdef RDB_TRACE_ON +#include "hitrace.h" +#define DISTRIBUTED_DATA_HITRACE(trace) HiTrace hitrace(trace) +#else +#define DISTRIBUTED_DATA_HITRACE(trace) DO_NOTHING +#endif + +#endif \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/include/napi_result_set.h b/frameworks/js/napi/featureAbility/data_ability/include/napi_result_set.h new file mode 100644 index 0000000000..4ad567b702 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/include/napi_result_set.h @@ -0,0 +1,92 @@ +/* + * 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. + */ + +#ifndef RDB_JSKIT_NAPI_RESULT_SET_H +#define RDB_JSKIT_NAPI_RESULT_SET_H + +#include + +#include "abs_shared_result_set.h" +#include "js_proxy.h" +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi_rdb_error.h" +#include "result_set_bridge.h" + +namespace OHOS { +namespace RdbJsKit { +class ResultSetProxy final : public JSProxy::JSEntity { +public: + ResultSetProxy() = default; + ~ResultSetProxy(); + ResultSetProxy(std::shared_ptr resultSet); + ResultSetProxy &operator=(std::shared_ptr resultSet); + static napi_value NewInstance(napi_env env, std::shared_ptr resultSet, + int version = AppDataMgrJsKit::APIVERSION_8); + static napi_value NewInstance(napi_env env, std::shared_ptr resultSet, + int version = AppDataMgrJsKit::APIVERSION_8); + static std::shared_ptr GetNativeObject(const napi_env env, const napi_value arg); + static napi_value GetConstructor(napi_env env, int version); + std::shared_ptr Create() override; + int apiversion = AppDataMgrJsKit::APIVERSION_8; + +private: + static ResultSetProxy *GetInnerResultSet(napi_env env, napi_callback_info info, int &version); + static ResultSetProxy *ParseInt32FieldByName( + napi_env env, napi_callback_info info, int32_t &field, const std::string& fieldName); + static ResultSetProxy *ParseFieldByName(napi_env env, napi_callback_info info, std::string &field); + + static napi_value InnerInitialize( + napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_8); + static napi_value Initialize(napi_env env, napi_callback_info info); + static napi_value InitializeV9(napi_env env, napi_callback_info info); + static napi_value GetAllColumnNames(napi_env env, napi_callback_info info); + static napi_value GoToRow(napi_env env, napi_callback_info info); + static napi_value GetColumnCount(napi_env env, napi_callback_info info); + static napi_value GetLong(napi_env env, napi_callback_info info); + static napi_value GetColumnType(napi_env env, napi_callback_info info); + static napi_value GoTo(napi_env env, napi_callback_info info); + static napi_value GetColumnIndex(napi_env env, napi_callback_info info); + static napi_value GetInt(napi_env env, napi_callback_info info); + static napi_value GetColumnName(napi_env env, napi_callback_info info); + static napi_value Close(napi_env env, napi_callback_info info); + static napi_value GetRowCount(napi_env env, napi_callback_info info); + static napi_value GetRowIndex(napi_env env, napi_callback_info info); + static napi_value IsEnded(napi_env env, napi_callback_info info); + static napi_value IsBegin(napi_env env, napi_callback_info info); + static napi_value GoToFirstRow(napi_env env, napi_callback_info info); + static napi_value GoToLastRow(napi_env env, napi_callback_info info); + static napi_value GoToNextRow(napi_env env, napi_callback_info info); + static napi_value GoToPreviousRow(napi_env env, napi_callback_info info); + static napi_value IsAtFirstRow(napi_env env, napi_callback_info info); + static napi_value IsAtLastRow(napi_env env, napi_callback_info info); + static napi_value GetBlob(napi_env env, napi_callback_info info); + static napi_value GetString(napi_env env, napi_callback_info info); + static napi_value GetDouble(napi_env env, napi_callback_info info); + static napi_value IsColumnNull(napi_env env, napi_callback_info info); + static napi_value IsClosed(napi_env env, napi_callback_info info); + + static napi_value GetSharedBlockName(napi_env env, napi_callback_info info); + static napi_value GetSharedBlockAshmemFd(napi_env env, napi_callback_info info); + + std::shared_ptr sharedResultSet_; + + std::string sharedBlockName_; + int32_t sharedBlockAshmemFd_ = -1; +}; +} // namespace RdbJsKit +} // namespace OHOS +#endif // RDB_JSKIT_NAPI_RESULT_SET_H \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/js_utils.cpp b/frameworks/js/napi/featureAbility/data_ability/js_utils.cpp new file mode 100644 index 0000000000..53ecd2d4de --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/js_utils.cpp @@ -0,0 +1,716 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "JSUtils" + +#include "js_utils.h" + +#include + +#include "js_native_api_types.h" +#include "logger.h" +#include "securec.h" +using namespace OHOS::Rdb; + +#define CHECK_RETURN_RET(assertion, message, revt) \ + do { \ + if (!(assertion)) { \ + LOG_WARN("assertion (" #assertion ") failed: " message); \ + return revt; \ + } \ + } while (0) + +namespace OHOS { +namespace AppDataMgrJsKit { +namespace JSUtils { + static int32_t g_hapVersion = -1; // the current apiVersion of hap +} + +static constexpr JSUtils::JsFeatureSpace FEATURE_NAME_SPACES[] = { + { "ohos.data.cloudData", "ZGF0YS5jbG91ZERhdGE=", true }, + { "ohos.data.dataAbility", "ZGF0YS5kYXRhQWJpbGl0eQ==", true }, + { "ohos.data.dataShare", "ZGF0YS5kYXRhU2hhcmU=", false }, + { "ohos.data.distributedDataObject", "ZGF0YS5kaXN0cmlidXRlZERhdGFPYmplY3Q=", false }, + { "ohos.data.distributedKVStore", "ZGF0YS5kaXN0cmlidXRlZEtWU3RvcmU=", false }, + { "ohos.data.rdb", "ZGF0YS5yZGI=", true }, + { "ohos.data.relationalStore", "ZGF0YS5yZWxhdGlvbmFsU3RvcmU=", true }, +}; + +void JSUtils::SetHapVersion(int32_t hapversion) +{ + g_hapVersion = hapversion; +} + +int32_t JSUtils::GetHapVersion() +{ + return g_hapVersion; +} + +const std::optional JSUtils::GetJsFeatureSpace(const std::string &name) +{ + auto jsFeature = JsFeatureSpace{ name.data(), nullptr, false }; + auto iter = std::lower_bound(FEATURE_NAME_SPACES, + FEATURE_NAME_SPACES + sizeof(FEATURE_NAME_SPACES) / sizeof(FEATURE_NAME_SPACES[0]), jsFeature, + [](const JsFeatureSpace &JsFeatureSpace1, const JsFeatureSpace &JsFeatureSpace2) { + return strcmp(JsFeatureSpace1.spaceName, JsFeatureSpace2.spaceName) < 0; + }); + if (iter < FEATURE_NAME_SPACES + sizeof(FEATURE_NAME_SPACES) / sizeof(FEATURE_NAME_SPACES[0]) && + strcmp(iter->spaceName, name.data()) == 0) { + return *iter; + } + return std::nullopt; +} + +std::pair JSUtils::GetInnerValue( + napi_env env, napi_value in, const std::string &prop, bool optional) +{ + bool hasProp = false; + napi_status status = napi_has_named_property(env, in, prop.c_str(), &hasProp); + if (status != napi_ok) { + return std::make_pair(napi_generic_failure, nullptr); + } + if (!hasProp) { + status = optional ? napi_ok : napi_generic_failure; + return std::make_pair(status, nullptr); + } + napi_value inner = nullptr; + status = napi_get_named_property(env, in, prop.c_str(), &inner); + if (status != napi_ok || inner == nullptr) { + return std::make_pair(napi_generic_failure, nullptr); + } + if (optional && JSUtils::IsNull(env, inner)) { + return std::make_pair(napi_ok, nullptr); + } + return std::make_pair(napi_ok, inner); +} + +std::string JSUtils::Convert2String(napi_env env, napi_value jsStr) +{ + std::string value = ""; // TD: need to check everywhere in use whether empty is work well. + JSUtils::Convert2Value(env, jsStr, value); + return value; +} + +int32_t JSUtils::Convert2ValueExt(napi_env env, napi_value jsValue, uint32_t &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_number) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + status = napi_get_value_uint32(env, jsValue, &output); + if (status != napi_ok) { + LOG_DEBUG("napi_get_value_uint32 failed, status = %{public}d", status); + return status; + } + return status; +} + +int32_t JSUtils::Convert2ValueExt(napi_env env, napi_value jsValue, int32_t &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_number) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + status = napi_get_value_int32(env, jsValue, &output); + if (status != napi_ok) { + LOG_DEBUG("napi_get_value_int32 failed, status = %{public}d", status); + return status; + } + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, napi_value &output) +{ + output = jsValue; + return napi_ok; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, bool &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_boolean) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + bool bValue = false; + status = napi_get_value_bool(env, jsValue, &bValue); + if (status != napi_ok) { + LOG_ERROR("napi_get_value_bool failed, status = %{public}d", status); + return status; + } + output = bValue; + return status; +} + +int32_t JSUtils::Convert2ValueExt(napi_env env, napi_value jsValue, int64_t &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_number) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + status = napi_get_value_int64(env, jsValue, &output); + if (status != napi_ok) { + LOG_DEBUG("napi_get_value_int64 failed, status = %{public}d", status); + return status; + } + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, double &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_number) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + double number = 0.0; + status = napi_get_value_double(env, jsValue, &number); + if (status != napi_ok) { + LOG_DEBUG("napi_get_value_double failed, status = %{public}d", status); + return status; + } + output = number; + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, int64_t &output) +{ + return napi_invalid_arg; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::vector &output) +{ + bool isTypedArray = false; + napi_is_typedarray(env, jsValue, &isTypedArray); + if (!isTypedArray) { + return napi_invalid_arg; + } + + napi_typedarray_type type; + napi_value input_buffer = nullptr; + size_t byte_offset = 0; + size_t length = 0; + void *tmp = nullptr; + auto status = napi_get_typedarray_info(env, jsValue, &type, &length, &tmp, &input_buffer, &byte_offset); + if (status != napi_ok || type != napi_float32_array) { + return napi_invalid_arg; + } + + output = (tmp != nullptr + ? std::vector(static_cast(tmp), static_cast(tmp) + length / sizeof(float)) + : std::vector()); + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::string &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_string) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + size_t buffSize = 0; + napi_get_value_string_utf8(env, jsValue, nullptr, 0, &buffSize); + + // cut down with 0 if more than MAX_VALUE_LENGTH + if (buffSize >= JSUtils::MAX_VALUE_LENGTH - 1) { + buffSize = JSUtils::MAX_VALUE_LENGTH - 1; + } + std::unique_ptr buffer = std::make_unique(buffSize + 1); + if (!buffer) { + LOG_ERROR("buffer data is nullptr."); + return napi_invalid_arg; + } + status = napi_get_value_string_utf8(env, jsValue, buffer.get(), buffSize + 1, &buffSize); + if (status != napi_ok) { + LOG_ERROR("napi_get_value_string_utf8 failed, status = %{public}d", status); + return status; + } + output = std::string(buffer.get()); + + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::vector &output) +{ + bool isTypedArray = false; + napi_is_typedarray(env, jsValue, &isTypedArray); + if (!isTypedArray) { + return napi_invalid_arg; + } + + napi_typedarray_type type; + napi_value input_buffer = nullptr; + size_t byte_offset = 0; + size_t length = 0; + void *tmp = nullptr; + auto status = napi_get_typedarray_info(env, jsValue, &type, &length, &tmp, &input_buffer, &byte_offset); + if (status != napi_ok || type != napi_uint8_array) { + return napi_invalid_arg; + } + + output = (tmp != nullptr ? std::vector(static_cast(tmp), static_cast(tmp) + length) + : std::vector()); + return status; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::monostate &value) +{ + napi_value tempValue = nullptr; + napi_get_null(env, &tempValue); + bool equal = false; + napi_strict_equals(env, jsValue, tempValue, &equal); + if (equal) { + value = std::monostate(); + return napi_ok; + } + LOG_DEBUG("jsValue is not null."); + return napi_invalid_arg; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::map &output) +{ + LOG_DEBUG("napi_value -> std::map "); + output.clear(); + napi_value jsMapList = nullptr; + uint32_t jsCount = 0; + napi_status status = napi_get_property_names(env, jsValue, &jsMapList); + CHECK_RETURN_RET(status == napi_ok, "get_property_names failed", napi_invalid_arg); + status = napi_get_array_length(env, jsMapList, &jsCount); + LOG_DEBUG("jsCOUNT: %{public}d", jsCount); + CHECK_RETURN_RET(status == napi_ok && jsCount > 0, "get_map failed", napi_invalid_arg); + napi_value jsKey = nullptr; + napi_value jsVal = nullptr; + for (uint32_t index = 0; index < jsCount; index++) { + status = napi_get_element(env, jsMapList, index, &jsKey); + CHECK_RETURN_RET(status == napi_ok && jsKey != nullptr, "no element", napi_invalid_arg); + std::string key; + int ret = Convert2Value(env, jsKey, key); + CHECK_RETURN_RET(ret == napi_ok, "convert key failed", ret); + status = napi_get_property(env, jsValue, jsKey, &jsVal); + CHECK_RETURN_RET(status == napi_ok && jsVal != nullptr, "no element", napi_invalid_arg); + int32_t val; + ret = Convert2ValueExt(env, jsVal, val); + CHECK_RETURN_RET(ret == napi_ok, "convert val failed", ret); + output.insert(std::pair(key, val)); + } + return napi_ok; +} + +int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::map &output) +{ + LOG_DEBUG("napi_value -> std::map "); + output.clear(); + napi_value jsMapList = nullptr; + uint32_t jsCount = 0; + napi_status status = napi_get_property_names(env, jsValue, &jsMapList); + CHECK_RETURN_RET(status == napi_ok, "get_property_names failed", napi_invalid_arg); + status = napi_get_array_length(env, jsMapList, &jsCount); + LOG_DEBUG("jsCount: %{public}d", jsCount); + CHECK_RETURN_RET(status == napi_ok && jsCount > 0, "get_map failed", napi_invalid_arg); + napi_value jsKey = nullptr; + napi_value jsVal = nullptr; + for (uint32_t index = 0; index < jsCount; index++) { + status = napi_get_element(env, jsMapList, index, &jsKey); + CHECK_RETURN_RET(status == napi_ok && jsKey != nullptr, "no element", napi_invalid_arg); + std::string key; + int ret = Convert2Value(env, jsKey, key); + CHECK_RETURN_RET(ret == napi_ok, "convert key failed", ret); + status = napi_get_property(env, jsValue, jsKey, &jsVal); + CHECK_RETURN_RET(status == napi_ok && jsVal != nullptr, "no element", napi_invalid_arg); + bool val; + ret = Convert2Value(env, jsVal, val); + CHECK_RETURN_RET(ret == napi_ok, "convert val failed", ret); + output.insert(std::pair(key, val)); + } + return napi_ok; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, const std::string &value) +{ + napi_value jsValue = nullptr; + if (napi_create_string_utf8(env, value.c_str(), value.size(), &jsValue) != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, const std::vector &value) +{ + napi_value jsValue = nullptr; + void *native = nullptr; + napi_value buffer = nullptr; + napi_status status = napi_create_arraybuffer(env, value.size(), &native, &buffer); + if (status != napi_ok) { + return nullptr; + } + for (size_t i = 0; i < value.size(); i++) { + *(static_cast(native) + i) = value[i]; + } + status = napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, int32_t value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_create_int32(env, value, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, uint32_t value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_create_uint32(env, value, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, int64_t value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_create_int64(env, value, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, double value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_create_double(env, value, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, bool value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_get_boolean(env, value, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, const std::vector &value) +{ + napi_value jsValue = nullptr; + float *native = nullptr; + napi_value buffer = nullptr; + napi_status status = napi_create_arraybuffer(env, value.size() * sizeof(float), (void **)&native, &buffer); + if (status != napi_ok) { + return nullptr; + } + if (native == nullptr) { + return nullptr; + } + for (size_t i = 0; i < value.size(); i++) { + *(native + i) = value[i]; + } + status = napi_create_typedarray(env, napi_float32_array, value.size(), buffer, 0, &jsValue); + if (status != napi_ok) { + return nullptr; + } + return jsValue; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, const std::map &value) +{ + napi_value jsValue = nullptr; + napi_status status = napi_create_array_with_length(env, value.size(), &jsValue); + if (status != napi_ok) { + return nullptr; + } + + int index = 0; + for (const auto &[device, result] : value) { + napi_value jsElement = nullptr; + status = napi_create_array_with_length(env, SYNC_RESULT_ELEMENT_NUM, &jsElement); + if (status != napi_ok) { + return nullptr; + } + napi_set_element(env, jsElement, 0, Convert2JSValue(env, device)); + napi_set_element(env, jsElement, 1, Convert2JSValue(env, result)); + napi_set_element(env, jsValue, index++, jsElement); + } + + return jsValue; +} + +int32_t JSUtils::Convert2JSValue(napi_env env, std::string value, napi_value &output) +{ + std::string tempStr = std::string(value); + if (napi_create_string_utf8(env, tempStr.c_str(), tempStr.size(), &output) != napi_ok) { + LOG_ERROR("Convert2JSValue create JS string failed."); + return ERR; + } + return napi_ok; +} + +int32_t JSUtils::Convert2JSValue(napi_env env, bool value, napi_value &output) +{ + if (napi_get_boolean(env, value, &output) != napi_ok) { + LOG_ERROR("Convert2JSValue create JS bool failed."); + return ERR; + } + return napi_ok; +} + +int32_t JSUtils::Convert2JSValue(napi_env env, double value, napi_value &output) +{ + if (napi_create_double(env, value, &output) != napi_ok) { + LOG_ERROR("Convert2JSValue create JS double failed."); + return ERR; + } + return napi_ok; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, const std::monostate &value) +{ + napi_value result = nullptr; + napi_get_null(env, &result); + return result; +} + +bool JSUtils::IsNull(napi_env env, napi_value value) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, value, &type); + return status == napi_ok && (type == napi_undefined || type == napi_null); +} + +napi_value JSUtils::DefineClass(napi_env env, const std::string &spaceName, const std::string &className, + const Descriptor &descriptor, napi_callback ctor) +{ + auto featureSpace = GetJsFeatureSpace(spaceName); + if (!featureSpace.has_value() || !featureSpace->isComponent) { + return nullptr; + } + auto constructor = GetClass(env, spaceName, className); + if (constructor != nullptr) { + return constructor; + } + auto rootPropName = std::string(featureSpace->nameBase64); + napi_value root = nullptr; + bool hasRoot = false; + napi_value global = nullptr; + napi_get_global(env, &global); + napi_has_named_property(env, global, rootPropName.c_str(), &hasRoot); + if (hasRoot) { + napi_get_named_property(env, global, rootPropName.c_str(), &root); + } else { + napi_create_object(env, &root); + napi_set_named_property(env, global, rootPropName.c_str(), root); + } + + std::string propName = "constructor_of_" + className; + bool hasProp = false; + napi_has_named_property(env, root, propName.c_str(), &hasProp); + if (hasProp) { + napi_get_named_property(env, root, propName.c_str(), &constructor); + if (constructor != nullptr) { + LOG_DEBUG("got %{public}s from %{public}s", propName.c_str(), featureSpace->spaceName); + return constructor; + } + hasProp = false; // no constructor. + } + auto properties = descriptor(); + NAPI_CALL(env, napi_define_class(env, className.c_str(), className.size(), ctor, nullptr, properties.size(), + properties.data(), &constructor)); + NAPI_ASSERT(env, constructor != nullptr, "napi_define_class failed!"); + + if (!hasProp) { + napi_set_named_property(env, root, propName.c_str(), constructor); + LOG_DEBUG("save %{public}s to %{public}s", propName.c_str(), featureSpace->spaceName); + } + return constructor; +} + +napi_value JSUtils::GetClass(napi_env env, const std::string &spaceName, const std::string &className) +{ + auto featureSpace = GetJsFeatureSpace(spaceName); + if (!featureSpace.has_value()) { + return nullptr; + } + auto rootPropName = std::string(featureSpace->nameBase64); + napi_value root = nullptr; + napi_value global = nullptr; + napi_get_global(env, &global); + bool hasRoot; + napi_has_named_property(env, global, rootPropName.c_str(), &hasRoot); + if (!hasRoot) { + return nullptr; + } + napi_get_named_property(env, global, rootPropName.c_str(), &root); + std::string propName = "constructor_of_" + className; + napi_value constructor = nullptr; + bool hasProp = false; + napi_has_named_property(env, root, propName.c_str(), &hasProp); + if (!hasProp) { + return nullptr; + } + napi_get_named_property(env, root, propName.c_str(), &constructor); + if (constructor != nullptr) { + LOG_DEBUG("got %{public}s from %{public}s", propName.c_str(), featureSpace->spaceName); + return constructor; + } + hasProp = false; // no constructor. + return constructor; +} + +bool JSUtils::Equal(napi_env env, napi_ref ref, napi_value value) +{ + napi_value callback = nullptr; + napi_get_reference_value(env, ref, &callback); + + bool isEquals = false; + napi_strict_equals(env, value, callback, &isEquals); + return isEquals; +} + +napi_value JSUtils::ToJsObject(napi_env env, napi_value sendableValue) +{ + LOG_DEBUG("sendableObject -> jsObject"); + napi_value keys = nullptr; + napi_status status = napi_get_all_property_names(env, sendableValue, napi_key_own_only, + static_cast(napi_key_enumerable | napi_key_skip_symbols), napi_key_numbers_to_strings, &keys); + ASSERT(status == napi_ok, "napi_get_all_property_names failed", nullptr); + uint32_t length = 0; + status = napi_get_array_length(env, keys, &length); + ASSERT(status == napi_ok, "napi_get_array_length failed", nullptr); + std::vector descriptors; + // keysHold guarantees that the string address is valid before create the sendable object. + std::vector keysHold(length, ""); + for (uint32_t i = 0; i < length; ++i) { + napi_value key = nullptr; + status = napi_get_element(env, keys, i, &key); + ASSERT(status == napi_ok, "napi_get_element failed", nullptr); + JSUtils::Convert2Value(env, key, keysHold[i]); + napi_value value = nullptr; + status = napi_get_named_property(env, sendableValue, keysHold[i].c_str(), &value); + ASSERT(status == napi_ok, "napi_get_named_property failed", nullptr); + descriptors.emplace_back(DECLARE_JS_PROPERTY(env, keysHold[i].c_str(), value)); + } + napi_value jsObject = nullptr; + status = napi_create_object_with_properties(env, &jsObject, descriptors.size(), descriptors.data()); + ASSERT(status == napi_ok, "napi_create_object_with_properties failed", nullptr); + return jsObject; +} + +napi_value JSUtils::ToJsArray(napi_env env, napi_value sendableValue) +{ + LOG_DEBUG("sendableArray -> jsArray"); + uint32_t arrLen = 0; + napi_status status = napi_get_array_length(env, sendableValue, &arrLen); + ASSERT(status == napi_ok, "napi_get_array_length failed", nullptr); + napi_value jsArray = nullptr; + status = napi_create_array_with_length(env, arrLen, &jsArray); + ASSERT(status == napi_ok, "napi_create_array_with_length failed", nullptr); + for (size_t i = 0; i < arrLen; ++i) { + napi_value element; + status = napi_get_element(env, sendableValue, i, &element); + ASSERT(status == napi_ok, "napi_get_element failed", nullptr); + status = napi_set_element(env, jsArray, i, Convert2JSValue(env, element)); + ASSERT(status == napi_ok, "napi_set_element failed", nullptr); + } + return jsArray; +} + +napi_value JSUtils::ToJsTypedArray(napi_env env, napi_value sendableValue) +{ + LOG_DEBUG("sendableTypedArray -> jsTypedArray"); + napi_typedarray_type type; + size_t length = 0; + void *tmp = nullptr; + napi_status status = napi_get_typedarray_info(env, sendableValue, &type, &length, &tmp, nullptr, nullptr); + ASSERT(status == napi_ok, "napi_get_typedarray_info failed", nullptr); + + if (type != napi_uint8_array && type != napi_float32_array) { + LOG_ERROR("type is invalid %{public}d", type); + return nullptr; + } + napi_value jsTypedArray = nullptr; + void *native = nullptr; + napi_value buffer = nullptr; + status = napi_create_arraybuffer(env, length, (void **)&native, &buffer); + ASSERT(status == napi_ok, "napi_create_arraybuffer failed", nullptr); + if (length > 0) { + errno_t result = memcpy_s(native, length, tmp, length); + if (result != EOK) { + LOG_ERROR("memcpy_s failed, result is %{public}d", result); + return nullptr; + } + } + auto size = (type == napi_uint8_array) ? length : length / sizeof(float); + status = napi_create_typedarray(env, type, size, buffer, 0, &jsTypedArray); + ASSERT(status == napi_ok, "napi_create_typedarray failed", nullptr); + return jsTypedArray; +} + +napi_value JSUtils::Convert2JSValue(napi_env env, napi_value sendableValue) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, sendableValue, &type); + ASSERT(status == napi_ok, "napi_typeof failed", nullptr); + if (type != napi_object) { + return sendableValue; + } + bool result = false; + status = napi_is_sendable(env, sendableValue, &result); + ASSERT(status == napi_ok, "napi_is_sendable failed", nullptr); + if (!result) { + return sendableValue; + } + + status = napi_is_array(env, sendableValue, &result); + ASSERT(status == napi_ok, "napi_is_array failed", nullptr); + if (result) { + return ToJsArray(env, sendableValue); + } + status = napi_is_typedarray(env, sendableValue, &result); + ASSERT(status == napi_ok, "napi_is_typedarray failed", nullptr); + if (result) { + return ToJsTypedArray(env, sendableValue); + } + return ToJsObject(env, sendableValue); +} +} // namespace AppDataMgrJsKit +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/napi_data_ability_predicates.cpp b/frameworks/js/napi/featureAbility/data_ability/napi_data_ability_predicates.cpp new file mode 100644 index 0000000000..93d528a012 --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/napi_data_ability_predicates.cpp @@ -0,0 +1,815 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "DataAbilityPredicatesProxy" +#include "napi_data_ability_predicates.h" + +#include "js_utils.h" +#include "logger.h" +#include "napi_async_proxy.h" +#include "napi_predicates_utils.h" + +using namespace OHOS::Rdb; +using namespace OHOS::NativeRdb; +using namespace OHOS::AppDataMgrJsKit; + +namespace OHOS { +namespace DataAbilityJsKit { +static __thread napi_ref constructor_ = nullptr; + +void DataAbilityPredicatesProxy::Init(napi_env env, napi_value exports) +{ + LOG_INFO("Init DataAbilityPredicatesProxy"); + napi_property_descriptor descriptors[] = { + DECLARE_NAPI_FUNCTION("equalTo", EqualTo), + DECLARE_NAPI_FUNCTION("notEqualTo", NotEqualTo), + DECLARE_NAPI_FUNCTION("beginWrap", BeginWrap), + DECLARE_NAPI_FUNCTION("endWrap", EndWrap), + DECLARE_NAPI_FUNCTION("or", Or), + DECLARE_NAPI_FUNCTION("and", And), + DECLARE_NAPI_FUNCTION("contains", Contains), + DECLARE_NAPI_FUNCTION("beginsWith", BeginsWith), + DECLARE_NAPI_FUNCTION("endsWith", EndsWith), + DECLARE_NAPI_FUNCTION("isNull", IsNull), + DECLARE_NAPI_FUNCTION("isNotNull", IsNotNull), + DECLARE_NAPI_FUNCTION("like", Like), + DECLARE_NAPI_FUNCTION("glob", Glob), + DECLARE_NAPI_FUNCTION("between", Between), + DECLARE_NAPI_FUNCTION("notBetween", NotBetween), + DECLARE_NAPI_FUNCTION("greaterThan", GreaterThan), + DECLARE_NAPI_FUNCTION("lessThan", LessThan), + DECLARE_NAPI_FUNCTION("greaterThanOrEqualTo", GreaterThanOrEqualTo), + DECLARE_NAPI_FUNCTION("lessThanOrEqualTo", LessThanOrEqualTo), + DECLARE_NAPI_FUNCTION("orderByAsc", OrderByAsc), + DECLARE_NAPI_FUNCTION("orderByDesc", OrderByDesc), + DECLARE_NAPI_FUNCTION("distinct", Distinct), + DECLARE_NAPI_FUNCTION("limitAs", Limit), + DECLARE_NAPI_FUNCTION("offsetAs", Offset), + DECLARE_NAPI_FUNCTION("groupBy", GroupBy), + DECLARE_NAPI_FUNCTION("indexedBy", IndexedBy), + DECLARE_NAPI_FUNCTION("in", In), + DECLARE_NAPI_FUNCTION("notIn", NotIn), + DECLARE_NAPI_FUNCTION("clear", Clear), + DECLARE_NAPI_FUNCTION("isRawSelection", IsRawSelection), + DECLARE_NAPI_GETTER_SETTER("whereClause", GetWhereClause, SetWhereClause), + DECLARE_NAPI_GETTER_SETTER("whereArgs", GetWhereArgs, SetWhereArgs), + DECLARE_NAPI_GETTER_SETTER("order", GetOrder, SetOrder), + DECLARE_NAPI_GETTER("limit", GetLimit), + DECLARE_NAPI_GETTER("offset", GetOffset), + DECLARE_NAPI_GETTER("isDistinct", IsDistinct), + DECLARE_NAPI_GETTER("group", GetGroup), + DECLARE_NAPI_GETTER("index", GetIndex), + DECLARE_NAPI_GETTER("isNeedAnd", IsNeedAnd), + DECLARE_NAPI_GETTER("isSorted", IsSorted), + }; + + napi_value cons = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "DataAbilityPredicates", NAPI_AUTO_LENGTH, New, nullptr, + sizeof(descriptors) / sizeof(napi_property_descriptor), descriptors, &cons)); + + NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructor_)); + + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "DataAbilityPredicates", cons)); +} + +napi_value DataAbilityPredicatesProxy::New(napi_env env, napi_callback_info info) +{ + napi_value new_target = nullptr; + NAPI_CALL(env, napi_get_new_target(env, info, &new_target)); + bool is_constructor = (new_target != nullptr); + + napi_value thiz = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr)); + + if (is_constructor) { + auto *proxy = new (std::nothrow) DataAbilityPredicatesProxy(); + if (proxy == nullptr) { + LOG_ERROR("DataAbilityPredicatesProxy::New new failed, proxy is nullptr."); + return nullptr; + } + napi_status status = napi_wrap(env, thiz, proxy, DataAbilityPredicatesProxy::Destructor, nullptr, nullptr); + if (status != napi_ok) { + LOG_ERROR("DataAbilityPredicatesProxy::New napi_wrap failed! napi_status:%{public}d!", status); + delete proxy; + return nullptr; + } + return thiz; + } + + napi_value cons = nullptr; + NAPI_CALL(env, napi_get_reference_value(env, constructor_, &cons)); + + napi_value output = nullptr; + NAPI_CALL(env, napi_new_instance(env, cons, 0, nullptr, &output)); + + return output; +} + +napi_value DataAbilityPredicatesProxy::NewInstance( + napi_env env, std::shared_ptr value) +{ + napi_value cons = nullptr; + napi_status status = napi_get_reference_value(env, constructor_, &cons); + if (status != napi_ok) { + LOG_ERROR("DataAbilityPredicatesProxy get constructor failed! napi_status:%{public}d!", status); + return nullptr; + } + + napi_value instance = nullptr; + status = napi_new_instance(env, cons, 0, nullptr, &instance); + if (status != napi_ok) { + LOG_ERROR("DataAbilityPredicatesProxy napi_new_instance failed! napi_status:%{public}d!", status); + return nullptr; + } + + DataAbilityPredicatesProxy *proxy = nullptr; + status = napi_unwrap(env, instance, reinterpret_cast(&proxy)); + if (status != napi_ok) { + LOG_ERROR("DataAbilityPredicatesProxy native instance is nullptr! napi_status:%{public}d!", status); + return instance; + } + proxy->predicates_ = std::move(value); + return instance; +} + +std::shared_ptr DataAbilityPredicatesProxy::GetNativePredicates( + const napi_env env, const napi_value arg) +{ + if (arg == nullptr) { + LOG_ERROR("DataAbilityPredicatesProxy arg is null."); + return nullptr; + } + DataAbilityPredicatesProxy *proxy = nullptr; + napi_unwrap(env, arg, reinterpret_cast(&proxy)); + if (proxy == nullptr) { + LOG_ERROR("DataAbilityPredicatesProxy proxy is null."); + return nullptr; + } + return proxy->predicates_; +} + +void DataAbilityPredicatesProxy::Destructor(napi_env env, void *nativeObject, void *) +{ + DataAbilityPredicatesProxy *proxy = static_cast(nativeObject); + delete proxy; +} + +DataAbilityPredicatesProxy::~DataAbilityPredicatesProxy() +{ +} + +DataAbilityPredicatesProxy::DataAbilityPredicatesProxy() : predicates_(new DataAbilityPredicates()) +{ +} + +std::shared_ptr DataAbilityPredicatesProxy::GetNativePredicates( + napi_env env, napi_callback_info info) +{ + DataAbilityPredicatesProxy *predicatesProxy = nullptr; + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); + if (predicatesProxy == nullptr) { + return nullptr; + } + return predicatesProxy->predicates_; +} + +napi_value DataAbilityPredicatesProxy::EqualTo(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::EqualTo Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->EqualTo(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::NotEqualTo(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::NotEqualTo Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->NotEqualTo(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::BeginWrap(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->BeginWrap(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::EndWrap(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->EndWrap(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Or(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Or(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::And(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->And(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Contains(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Contains Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + std::string value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Contains(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::BeginsWith(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::BeginsWith Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + std::string value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->BeginsWith(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::EndsWith(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::EndsWith Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + std::string value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->EndsWith(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::IsNull(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::IsNull Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->IsNull(field); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::IsNotNull(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::IsNotNull Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->IsNotNull(field); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Like(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Like Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + std::string value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Like(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Glob(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Glob Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + std::string value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Glob(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Between(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 3; + // 3 represents the number of parameters + napi_value args[3] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Between Invalid argvs!"); + std::string field; + // args[0] represents the first parameter + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject low; + // args[1] represents the second parameter + JSUtils::Convert2Value(env, args[1], low); + ValueObject high; + // args[2] represents the third parameter + JSUtils::Convert2Value(env, args[2], high); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Between(field, low, high); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::NotBetween(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 3; + // 3 represents the number of parameters + napi_value args[3] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::NotBetween Invalid argvs!"); + std::string field; + // args[0] represents the first parameter + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject low; + // args[1] represents the second parameter + JSUtils::Convert2Value(env, args[1], low); + ValueObject high; + // args[2] represents the third parameter + JSUtils::Convert2Value(env, args[2], high); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->NotBetween(field, low, high); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GreaterThan(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::GreaterThan Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->GreaterThan(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::LessThan(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::LessThan Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->LessThan(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GreaterThanOrEqualTo(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::GreaterThanOrEqualTo Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->GreaterThanOrEqualTo(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::LessThanOrEqualTo(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::LessThanOrEqualTo Invalid argvs!"); + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + ValueObject value; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[1], value) == napi_ok, "the value is invalid"); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->LessThanOrEqualTo(field, value); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::OrderByAsc(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::OrderByAsc Invalid argvs!"); + + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->OrderByAsc(field); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::OrderByDesc(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::OrderByDesc Invalid argvs!"); + + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->OrderByDesc(field); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Distinct(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Distinct(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Limit(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Limit Invalid argvs!"); + + int32_t limit = 0; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2ValueExt(env, args[0], limit) == napi_ok, "the limit is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Limit(limit); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Offset(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::Offset Invalid argvs!"); + + int32_t offset = 0; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2ValueExt(env, args[0], offset) == napi_ok, "the offset is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Offset(offset); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GroupBy(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::GroupBy Invalid argvs!"); + + std::vector fields = {}; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], fields) == napi_ok, "the fields is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->GroupBy(fields); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::IndexedBy(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::IndexedBy Invalid argvs!"); + + std::string indexName; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], indexName) == napi_ok, "the indexName is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->IndexedBy(indexName); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::In(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::In Invalid argvs!"); + + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + + std::vector values; + NAPI_ASSERT(env, JSUtils::Convert2Value(env, args[1], values) == napi_ok, "Invalid values!"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->In(field, values); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::NotIn(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 2; + napi_value args[2] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::NotIn Invalid argvs!"); + + std::string field; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], field) == napi_ok, "the field is invalid"); + + std::vector values; + NAPI_ASSERT(env, JSUtils::Convert2Value(env, args[1], values) == napi_ok, "Invalid values"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->NotIn(field, values); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::Clear(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->Clear(); + return thiz; +} + +napi_value DataAbilityPredicatesProxy::IsRawSelection(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + bool out = nativePredicates->IsRawSelection(); + return JSUtils::Convert2JSValue(env, out); +} + +std::shared_ptr DataAbilityPredicatesProxy::GetPredicates() const +{ + return this->predicates_; +} + +napi_value DataAbilityPredicatesProxy::GetWhereClause(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + auto ret = nativePredicates->GetWhereClause(); + return JSUtils::Convert2JSValue(env, ret); +} + +napi_value DataAbilityPredicatesProxy::SetWhereClause(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::SetWhereClause Invalid argvs!"); + + std::string whereClause; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], whereClause) == napi_ok, "whereClause is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->SetWhereClause(whereClause); + + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GetWhereArgs(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + auto ret = nativePredicates->GetWhereArgs(); + return JSUtils::Convert2JSValue(env, ret); +} + +napi_value DataAbilityPredicatesProxy::SetWhereArgs(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::SetWhereArgs Invalid argvs!"); + + std::vector whereArgs; + NAPI_ASSERT(env, JSUtils::Convert2Value(env, args[0], whereArgs) == napi_ok, "Invalid whereArgs!"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->SetWhereArgs(whereArgs); + + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GetOrder(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + auto ret = nativePredicates->GetOrder(); + return JSUtils::Convert2JSValue(env, ret); +} + +napi_value DataAbilityPredicatesProxy::SetOrder(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); + NAPI_ASSERT(env, argc > 0, "DataAbilityPredicatesProxy::SetOrder Invalid argvs!"); + + std::string order; + RDB_CHECK_RETURN_NULLPTR(JSUtils::Convert2Value(env, args[0], order) != napi_ok, "the order is invalid"); + + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + nativePredicates->SetOrder(order); + + return thiz; +} + +napi_value DataAbilityPredicatesProxy::GetLimit(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + return JSUtils::Convert2JSValue(env, nativePredicates->GetLimit()); +} + +napi_value DataAbilityPredicatesProxy::GetOffset(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + return JSUtils::Convert2JSValue(env, nativePredicates->GetOffset()); +} + +napi_value DataAbilityPredicatesProxy::IsDistinct(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + return JSUtils::Convert2JSValue(env, nativePredicates->IsDistinct()); +} + +napi_value DataAbilityPredicatesProxy::GetGroup(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + auto ret = nativePredicates->GetGroup(); + return JSUtils::Convert2JSValue(env, ret); +} + +napi_value DataAbilityPredicatesProxy::GetIndex(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + auto ret = nativePredicates->GetIndex(); + return JSUtils::Convert2JSValue(env, ret); +} + +napi_value DataAbilityPredicatesProxy::IsNeedAnd(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + return JSUtils::Convert2JSValue(env, nativePredicates->IsNeedAnd()); +} + +napi_value DataAbilityPredicatesProxy::IsSorted(napi_env env, napi_callback_info info) +{ + auto nativePredicates = GetNativePredicates(env, info); + RDB_CHECK_RETURN_NULLPTR(nativePredicates != nullptr, "GetNativePredicates return nullptr"); + return JSUtils::Convert2JSValue(env, nativePredicates->IsSorted()); +} +} // namespace DataAbilityJsKit +} // namespace OHOS + +EXTERN_C_START +__attribute__((visibility("default"))) + napi_value NAPI_OHOS_Data_DataAbilityJsKit_DataAbilityPredicatesProxy_NewInstance( + napi_env env, OHOS::NativeRdb::DataAbilityPredicates *predicates) +{ + return OHOS::DataAbilityJsKit::DataAbilityPredicatesProxy::NewInstance( + env, std::shared_ptr(predicates)); +} + +__attribute__((visibility("default"))) OHOS::NativeRdb::DataAbilityPredicates * +NAPI_OHOS_Data_DataAbilityJsKit_DataAbilityPredicatesProxy_GetNativeObject(const napi_env env, const napi_value arg) +{ + auto predicates = OHOS::DataAbilityJsKit::DataAbilityPredicatesProxy::GetNativePredicates(env, arg); + return predicates.get(); +} +EXTERN_C_END \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/napi_rdb_js_utils.cpp b/frameworks/js/napi/featureAbility/data_ability/napi_rdb_js_utils.cpp new file mode 100644 index 0000000000..f346f757bd --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/napi_rdb_js_utils.cpp @@ -0,0 +1,118 @@ +/* + * 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. + */ +#define LOG_TAG "NapiRdbJsUtils" +#include "napi_rdb_js_utils.h" + +#include "logger.h" +#include "result_set.h" + +namespace OHOS::AppDataMgrJsKit { +namespace JSUtils { +using namespace OHOS::Rdb; +using namespace NativeRdb; + +template<> +int32_t Convert2Value(napi_env env, napi_value jsValue, Asset &output) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_object) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "version", output.version), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "name", output.name), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "uri", output.uri), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "createTime", output.createTime), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "modifyTime", output.modifyTime), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "size", output.size), napi_invalid_arg); + NAPI_CALL_BASE(env, GetNamedProperty(env, jsValue, "hash", output.hash), napi_invalid_arg); + return napi_ok; +} + +template<> +napi_value Convert2JSValue(napi_env env, const Asset &value) +{ + napi_value object = nullptr; + NAPI_CALL_BASE(env, napi_create_object(env, &object), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "version", value.version), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "name", value.name), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "uri", value.uri), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "createTime", value.createTime), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "modifyTime", value.modifyTime), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "size", value.size), object); + NAPI_CALL_BASE(env, SetNamedProperty(env, object, "hash", value.hash), object); + return object; +} + +template<> +napi_value Convert2JSValue(napi_env env, const RowEntity &rowEntity) +{ + napi_value ret = nullptr; + NAPI_CALL(env, napi_create_object(env, &ret)); + auto &values = rowEntity.Get(); + for (auto const &[key, object] : values) { + napi_value value = JSUtils::Convert2JSValue(env, object.value); + NAPI_CALL(env, napi_set_named_property(env, ret, key.c_str(), value)); + } + return ret; +} + +template<> +int32_t Convert2Value(napi_env env, napi_value jsValue, ValueObject &valueObject) +{ + auto status = Convert2Value(env, jsValue, valueObject.value); + if (status != napi_ok) { + return napi_invalid_arg; + } + return napi_ok; +} + +template<> +napi_value Convert2JSValue(napi_env env, const BigInt& value) +{ + napi_value val = nullptr; + napi_status status = napi_create_bigint_words(env, value.Sign(), value.Size(), value.TrueForm(), &val); + if (status != napi_ok) { + return nullptr; + } + return val; +} + +template<> +int32_t Convert2Value(napi_env env, napi_value jsValue, BigInt& value) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, jsValue, &type); + if (status != napi_ok || type != napi_bigint) { + return napi_invalid_arg; + } + int sign = 0; + size_t count = 0; + status = napi_get_value_bigint_words(env, jsValue, nullptr, &count, nullptr); + if (status != napi_ok) { + return napi_bigint_expected; + } + std::vector words(count, 0); + status = napi_get_value_bigint_words(env, jsValue, &sign, &count, words.data()); + if (status != napi_ok) { + return napi_bigint_expected; + } + value = BigInteger(sign, std::move(words)); + return napi_ok; +} +}; // namespace JSUtils +} // namespace OHOS::AppDataMgrJsKit \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/data_ability/napi_result_set.cpp b/frameworks/js/napi/featureAbility/data_ability/napi_result_set.cpp new file mode 100644 index 0000000000..1f12bd438e --- /dev/null +++ b/frameworks/js/napi/featureAbility/data_ability/napi_result_set.cpp @@ -0,0 +1,640 @@ +/* + * 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. + */ +#define LOG_TAG "ResultSetProxy" +#include "napi_result_set.h" + +#include + +#include "js_utils.h" +#include "logger.h" +#include "napi_rdb_error.h" +#include "napi_rdb_trace.h" +#include "rdb_errno.h" + +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) +#include "abs_shared_result_set.h" +#include "rdb_result_set_bridge.h" +#include "shared_block.h" +#include "string_ex.h" +#endif + +using namespace OHOS::Rdb; +using namespace OHOS::NativeRdb; +using namespace OHOS::AppDataMgrJsKit; + +namespace OHOS { +namespace RdbJsKit { +static napi_ref __thread ctorRef_ = nullptr; +static napi_ref __thread ctorRefV9_ = nullptr; +static const int E_OK = 0; + +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) +napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr resultSet, int version) +{ + auto instance = NewInstance(env, std::static_pointer_cast(resultSet), version); + ResultSetProxy *proxy = nullptr; + auto status = napi_unwrap(env, instance, reinterpret_cast(&proxy)); + if (proxy == nullptr) { + LOG_ERROR("NewInstance native instance is nullptr! code:%{public}d!", status); + return instance; + } + + if (resultSet != nullptr && resultSet->GetBlock() != nullptr) { + proxy->sharedBlockName_ = resultSet->GetBlock()->Name(); + proxy->sharedBlockAshmemFd_ = resultSet->GetBlock()->GetFd(); + } + proxy->sharedResultSet_ = resultSet; + return instance; +} +#endif + +napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr resultSet, int version) +{ + napi_value cons = GetConstructor(env, version); + if (cons == nullptr) { + LOG_ERROR("NewInstance GetConstructor is nullptr!"); + return nullptr; + } + napi_value instance = nullptr; + napi_status status = napi_new_instance(env, cons, 0, nullptr, &instance); + if (status != napi_ok) { + LOG_ERROR("NewInstance napi_new_instance failed! code:%{public}d!", status); + return nullptr; + } + + ResultSetProxy *proxy = nullptr; + status = napi_unwrap(env, instance, reinterpret_cast(&proxy)); + if (proxy == nullptr) { + LOG_ERROR("NewInstance native instance is nullptr! code:%{public}d!", status); + return instance; + } + *proxy = std::move(resultSet); + return instance; +} + +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) +std::shared_ptr ResultSetProxy::GetNativeObject( + napi_env const env, napi_value const arg) +{ + if (arg == nullptr) { + LOG_ERROR("ResultSetProxy GetNativeObject arg is null."); + return nullptr; + } + ResultSetProxy *proxy = nullptr; + napi_unwrap(env, arg, reinterpret_cast(&proxy)); + if (proxy == nullptr || proxy->sharedResultSet_ == nullptr) { + LOG_ERROR("ResultSetProxy GetNativeObject proxy or sharedResultSet_ is null."); + return nullptr; + } + return proxy->sharedResultSet_; +} + +std::shared_ptr ResultSetProxy::Create() +{ + auto instance = GetInstance(); + if (instance == nullptr) { + LOG_ERROR("resultSet_ is null."); + return nullptr; + } + SetInstance(nullptr); + return std::make_shared(instance); +} +#endif + +napi_value ResultSetProxy::GetConstructor(napi_env env, int version) +{ + napi_value cons = nullptr; + if (version > APIVERSION_8 && ctorRefV9_ != nullptr) { + NAPI_CALL(env, napi_get_reference_value(env, ctorRefV9_, &cons)); + return cons; + } + if (version == APIVERSION_8 && ctorRef_ != nullptr) { + NAPI_CALL(env, napi_get_reference_value(env, ctorRef_, &cons)); + return cons; + } + + napi_property_descriptor clzDes[] = { + DECLARE_NAPI_FUNCTION("goToRow", GoToRow), + DECLARE_NAPI_FUNCTION("getLong", GetLong), + DECLARE_NAPI_FUNCTION("getColumnType", GetColumnType), + DECLARE_NAPI_FUNCTION("goTo", GoTo), + DECLARE_NAPI_FUNCTION("getColumnIndex", GetColumnIndex), + DECLARE_NAPI_FUNCTION("getInt", GetInt), + DECLARE_NAPI_FUNCTION("getColumnName", GetColumnName), + DECLARE_NAPI_FUNCTION("close", Close), + DECLARE_NAPI_FUNCTION("goToFirstRow", GoToFirstRow), + DECLARE_NAPI_FUNCTION("goToLastRow", GoToLastRow), + DECLARE_NAPI_FUNCTION("goToNextRow", GoToNextRow), + DECLARE_NAPI_FUNCTION("goToPreviousRow", GoToPreviousRow), + DECLARE_NAPI_FUNCTION("getBlob", GetBlob), + DECLARE_NAPI_FUNCTION("getString", GetString), + DECLARE_NAPI_FUNCTION("getDouble", GetDouble), + DECLARE_NAPI_FUNCTION("isColumnNull", IsColumnNull), + + DECLARE_NAPI_GETTER("columnNames", GetAllColumnNames), + DECLARE_NAPI_GETTER("columnCount", GetColumnCount), + DECLARE_NAPI_GETTER("isEnded", IsEnded), + DECLARE_NAPI_GETTER("isStarted", IsBegin), + DECLARE_NAPI_GETTER("isClosed", IsClosed), + DECLARE_NAPI_GETTER("rowCount", GetRowCount), + DECLARE_NAPI_GETTER("rowIndex", GetRowIndex), + DECLARE_NAPI_GETTER("isAtFirstRow", IsAtFirstRow), + DECLARE_NAPI_GETTER("isAtLastRow", IsAtLastRow), + }; + + if (version > APIVERSION_8) { + NAPI_CALL(env, napi_define_class(env, "ResultSetV9", NAPI_AUTO_LENGTH, InitializeV9, nullptr, + sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons)); + NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRefV9_)); + return cons; + } + + NAPI_CALL(env, napi_define_class(env, "ResultSet", NAPI_AUTO_LENGTH, Initialize, nullptr, + sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons)); + NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRef_)); + return cons; +} + +napi_value ResultSetProxy::InnerInitialize(napi_env env, napi_callback_info info, int version) +{ + napi_value self = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr)); + auto *proxy = new (std::nothrow) ResultSetProxy(); + if (proxy == nullptr) { + LOG_ERROR("ResultSetProxy::InnerInitialize new failed, proxy is nullptr."); + return nullptr; + } + proxy->apiversion = version; + auto finalize = [](napi_env env, void *data, void *hint) { + ResultSetProxy *proxy = reinterpret_cast(data); + delete proxy; + }; + napi_status status = napi_wrap(env, self, proxy, finalize, nullptr, nullptr); + if (status != napi_ok) { + LOG_ERROR("ResultSetProxy napi_wrap failed! code:%{public}d!, version:%{public}d.", status, version); + finalize(env, proxy, nullptr); + return nullptr; + } + return self; +} + +napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info) +{ + return InnerInitialize(env, info, APIVERSION_8); +} + +napi_value ResultSetProxy::InitializeV9(napi_env env, napi_callback_info info) +{ + return InnerInitialize(env, info, APIVERSION_V9); +} + +ResultSetProxy::~ResultSetProxy() +{ + LOG_DEBUG("ResultSetProxy destructor!"); +} + +ResultSetProxy::ResultSetProxy(std::shared_ptr resultSet) +{ + if (GetInstance() == resultSet) { + return; + } + SetInstance(std::move(resultSet)); +} + +ResultSetProxy &ResultSetProxy::operator=(std::shared_ptr resultSet) +{ + if (GetInstance() == resultSet) { + return *this; + } + SetInstance(std::move(resultSet)); + return *this; +} + +ResultSetProxy *ResultSetProxy::GetInnerResultSet(napi_env env, napi_callback_info info, int &version) +{ + ResultSetProxy *resultSetProxy = nullptr; + napi_value self = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr); + napi_unwrap(env, self, reinterpret_cast(&resultSetProxy)); + RDB_NAPI_ASSERT_FROMV9(env, resultSetProxy && resultSetProxy->GetInstance(), std::make_shared(), + resultSetProxy->apiversion); + + version = resultSetProxy->apiversion; + return resultSetProxy; +} + +ResultSetProxy *ResultSetProxy::ParseInt32FieldByName( + napi_env env, napi_callback_info info, int32_t &field, const std::string& name) +{ + DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); + napi_value self = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &self, nullptr); + ResultSetProxy *resultSetProxy = nullptr; + napi_unwrap(env, self, reinterpret_cast(&resultSetProxy)); + RDB_NAPI_ASSERT_FROMV9(env, resultSetProxy && resultSetProxy->GetInstance(), + std::make_shared("resultSet", "not null"), resultSetProxy->apiversion); + RDB_NAPI_ASSERT_FROMV9( + env, argc == 1, std::make_shared("1"), resultSetProxy->apiversion); + + napi_status status = napi_get_value_int32(env, args[0], &field); + RDB_NAPI_ASSERT_FROMV9( + env, status == napi_ok, std::make_shared(name, "a number."), resultSetProxy->apiversion); + return resultSetProxy; +} + +ResultSetProxy *ResultSetProxy::ParseFieldByName(napi_env env, napi_callback_info info, std::string &field) +{ + napi_value self = nullptr; + size_t argc = 1; + napi_value args[1] = { 0 }; + napi_get_cb_info(env, info, &argc, args, &self, nullptr); + ResultSetProxy *resultSetProxy = nullptr; + napi_unwrap(env, self, reinterpret_cast(&resultSetProxy)); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + RDB_NAPI_ASSERT_FROMV9( + env, argc == 1, std::make_shared("1"), resultSetProxy->apiversion); + + field = JSUtils::Convert2String(env, args[0]); + return resultSetProxy; +} + +napi_value ResultSetProxy::GetAllColumnNames(napi_env env, napi_callback_info info) +{ + std::vector colNames; + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetAllColumnNames(colNames); + if (errCode != E_OK) { + LOG_ERROR("GetAllColumnNames failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, colNames); +} + +napi_value ResultSetProxy::GoToRow(napi_env env, napi_callback_info info) +{ + int32_t position; + auto resultSetProxy = ParseInt32FieldByName(env, info, position, "position"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoToRow(position); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::GetColumnCount(napi_env env, napi_callback_info info) +{ + int32_t count = 0; + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetColumnCount(count); + if (errCode != E_OK) { + LOG_ERROR("GetColumnCount failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, count); +} + +napi_value ResultSetProxy::GetLong(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + int64_t result; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetLong(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetColumnType(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + ColumnType columnType; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetColumnType(columnIndex, columnType); + if (errCode != E_OK) { + LOG_ERROR("GetColumnType failed code:%{public}d, version:%{public}d.", errCode, resultSetProxy->apiversion); + } + return JSUtils::Convert2JSValue(env, int32_t(columnType)); +} + +napi_value ResultSetProxy::GoTo(napi_env env, napi_callback_info info) +{ + int32_t offset; + auto resultSetProxy = ParseInt32FieldByName(env, info, offset, "offset"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoTo(offset); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::GetColumnIndex(napi_env env, napi_callback_info info) +{ + std::string input; + int32_t result = -1; + auto resultSetProxy = ParseFieldByName(env, info, input); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetColumnIndex(input, result); + if (errCode != E_OK) { + LOG_ERROR("GetColumnIndex failed code:%{public}d, version:%{public}d.", errCode, resultSetProxy->apiversion); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetInt(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + int32_t result; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetInt(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetColumnName(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + std::string result; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetColumnName(columnIndex, result); + if (errCode != E_OK) { + LOG_ERROR("GetColumnName failed code:%{public}d, version:%{public}d.", errCode, resultSetProxy->apiversion); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::Close(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->Close(); + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + napi_value result = nullptr; + napi_get_null(env, &result); + return result; +} + +napi_value ResultSetProxy::GetRowCount(napi_env env, napi_callback_info info) +{ + int version = 0; + ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int32_t result; + int errCode = resultSetProxy->GetInstance()->GetRowCount(result); + if (errCode != E_OK) { + LOG_ERROR("GetRowCount failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetRowIndex(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int32_t result; + int errCode = resultSetProxy->GetInstance()->GetRowIndex(result); + if (errCode != E_OK) { + LOG_ERROR("GetRowIndex failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::IsEnded(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + bool result = false; + int errCode = resultSetProxy->GetInstance()->IsEnded(result); + if (errCode != E_OK) { + LOG_ERROR("IsEnded failed code:%{public}d, version:%{public}d.", errCode, version); + result = true; + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::IsBegin(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + bool result = false; + int errCode = resultSetProxy->GetInstance()->IsStarted(result); + if (errCode != E_OK) { + LOG_ERROR("IsBegin failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GoToFirstRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoToFirstRow(); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::GoToLastRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoToLastRow(); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::GoToNextRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoToNextRow(); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::GoToPreviousRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GoToPreviousRow(); + return JSUtils::Convert2JSValue(env, (errCode == E_OK)); +} + +napi_value ResultSetProxy::IsAtFirstRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + bool result = false; + int errCode = resultSetProxy->GetInstance()->IsAtFirstRow(result); + if (errCode != E_OK) { + LOG_ERROR("IsAtFirstRow failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::IsAtLastRow(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + bool result = false; + int errCode = resultSetProxy->GetInstance()->IsAtLastRow(result); + if (errCode != E_OK) { + LOG_ERROR("IsAtLastRow failed code:%{public}d, version:%{public}d.", errCode, version); + } + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetBlob(napi_env env, napi_callback_info info) +{ + DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); + int32_t columnIndex; + std::vector result; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetBlob(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetString(napi_env env, napi_callback_info info) +{ + DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); + int32_t columnIndex; + std::string result; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetString(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::GetDouble(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + double result = 0.0; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->GetDouble(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + return JSUtils::Convert2JSValue(env, result); +} + +napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info) +{ + int32_t columnIndex; + bool result = false; + auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex"); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int errCode = resultSetProxy->GetInstance()->IsColumnNull(columnIndex, result); + int version = resultSetProxy->apiversion; + RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared(), version); + napi_value output = nullptr; + napi_get_boolean(env, result, &output); + return output; +} + +napi_value ResultSetProxy::IsClosed(napi_env env, napi_callback_info info) +{ + int version = 0; + auto resultSetProxy = GetInnerResultSet(env, info, version); + RDB_CHECK_RETURN_NULLPTR(resultSetProxy && resultSetProxy->GetInstance(), "Proxy or instance is nullptr"); + + int result = resultSetProxy->GetInstance()->IsClosed(); + napi_value output = nullptr; + napi_get_boolean(env, result, &output); + return output; +} + +napi_value ResultSetProxy::GetSharedBlockName(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr)); + + ResultSetProxy *proxy; + NAPI_CALL(env, napi_unwrap(env, thiz, reinterpret_cast(&proxy))); + RDB_CHECK_RETURN_NULLPTR(proxy != nullptr, + "ResultSetProxy::GetSharedBlockName proxy is nullptr"); + + return JSUtils::Convert2JSValue(env, proxy->sharedBlockName_); +} + +napi_value ResultSetProxy::GetSharedBlockAshmemFd(napi_env env, napi_callback_info info) +{ + napi_value thiz = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr)); + + ResultSetProxy *proxy; + NAPI_CALL(env, napi_unwrap(env, thiz, reinterpret_cast(&proxy))); + RDB_CHECK_RETURN_NULLPTR(proxy != nullptr, + "ResultSetProxy::GetSharedBlockAshmemFd proxy is nullptr"); + + return JSUtils::Convert2JSValue(env, proxy->sharedBlockAshmemFd_); +} +} // namespace RdbJsKit +} // namespace OHOS + +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) + +__attribute__((visibility("default"))) napi_value NewCInstance(napi_env env, + napi_value arg) asm("NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_NewInstance"); +napi_value NewCInstance(napi_env env, std::shared_ptr resultSet) +{ + return OHOS::RdbJsKit::ResultSetProxy::NewInstance(env, resultSet); +} + +__attribute__((visibility("default"))) std::shared_ptr GetCObject(napi_env env, + napi_value arg) asm("NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_GetNativeObject"); +std::shared_ptr GetCObject(napi_env env, napi_value arg) +{ + return OHOS::RdbJsKit::ResultSetProxy::GetNativeObject(env, arg); +} +#endif \ No newline at end of file diff --git a/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp b/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp index a6727390b4..5549931254 100644 --- a/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp @@ -1714,7 +1714,7 @@ void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status) (abilityName == obj.first.want.GetElement().GetAbilityName()); }); if (item != connects_.end()) { - // match deviceid & bundlename && abilityname + // match deviceId & bundlename && abilityname connects_.erase(item); TAG_LOGI(AAFwkTag::JSNAPI, "erase connects_.size:%{public}zu", connects_.size()); } diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index 7b4b47de10..0773ea0e18 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -57,17 +57,12 @@ ohos_shared_library("napi_common") { "common_event_service:cesfwk_innerkits", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", - # "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_napi", "json:nlohmann_json_static", "libuv:uv", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] public_external_deps = [ diff --git a/frameworks/js/napi/js_child_process_manager/BUILD.gn b/frameworks/js/napi/js_child_process_manager/BUILD.gn index acd710348f..09ce5c6b0b 100644 --- a/frameworks/js/napi/js_child_process_manager/BUILD.gn +++ b/frameworks/js/napi/js_child_process_manager/BUILD.gn @@ -34,17 +34,12 @@ ohos_shared_library("childprocessmanager_napi") { ] external_deps = [ - # "ability_base:session_info", - # "ability_base:want", - # "bundle_framework:appexecfwk_base", "c_utils:utils", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_core", - # "jsoncpp:jsoncpp", "napi:ace_napi", - # "resource_management:global_resmgr", ] if (ability_runtime_graphics) { diff --git a/frameworks/js/napi/js_dialog_session/BUILD.gn b/frameworks/js/napi/js_dialog_session/BUILD.gn index 237aa5ca99..c901bb73a3 100644 --- a/frameworks/js/napi/js_dialog_session/BUILD.gn +++ b/frameworks/js/napi/js_dialog_session/BUILD.gn @@ -37,7 +37,6 @@ ohos_shared_library("dialogsession_napi") { } external_deps = [ "ability_base:extractortool", - # "ability_base:session_info", "ability_base:want", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", @@ -45,19 +44,12 @@ ohos_shared_library("dialogsession_napi") { "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", "ffrt:libffrt", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", - # "image_framework:image_native", "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - # "json:nlohmann_json_static", - # "jsoncpp:jsoncpp", "napi:ace_napi", - # "resource_management:global_resmgr", "samgr:samgr_proxy", - # "skia:skia_canvaskit", ] cflags_cc = [] diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.h b/frameworks/js/napi/mission_manager/distributed_mission_manager.h index c5760591dd..a2195a3ae7 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.h +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.h @@ -284,7 +284,7 @@ enum ErrorCode { */ MISSION_FOR_CONTINUING_IS_NOT_ALIVE = 29360224, /* - * Result(29360144) for get local deviceid fail. + * Result(29360144) for get local deviceId fail. */ GET_LOCAL_DEVICE_ERR = 29360144, /** diff --git a/frameworks/js/napi/particleAbility/BUILD.gn b/frameworks/js/napi/particleAbility/BUILD.gn index 8872302bf2..ac9ca67d20 100644 --- a/frameworks/js/napi/particleAbility/BUILD.gn +++ b/frameworks/js/napi/particleAbility/BUILD.gn @@ -18,10 +18,6 @@ ohos_shared_library("particleability") { include_dirs = [ "${ability_runtime_napi_path}/featureAbility", "${ability_runtime_services_path}/common/include", - "${relational_store_napi_path}/common/include", - "${relational_store_napi_path}/dataability/include", - "${relational_store_napi_path}/rdb/include", - "${relational_store_base_path}/frameworks/common/include", ] sources = [ @@ -56,38 +52,33 @@ ohos_shared_library("particleability") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "ets_runtime:libark_jsruntime", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", "jsoncpp:jsoncpp", - "kv_store:distributeddata_inner", - "data_share:datashare_provider", "libuv:uv", "napi:ace_napi", "node:node_header_notice", - "relational_store:native_dataability", ] - # if (ability_runtime_relational) { - # include_dirs += [ - # "${relational_store_napi_path}/common/include", - # "${relational_store_napi_path}/dataability/include", - # "${relational_store_napi_path}/rdb/include", - # ] - # sources += [ - # "${relational_store_napi_path}/common/src/js_utils.cpp", - # "${relational_store_napi_path}/dataability/src/napi_data_ability_predicates.cpp", - # "${relational_store_napi_path}/rdb/src/napi_rdb_js_utils.cpp", - # "${relational_store_napi_path}/rdb/src/napi_result_set.cpp", - # ] - # external_deps += [ - # "kv_store:distributeddata_mgr", - # "relational_store:native_dataability", - # "relational_store:native_rdb", - # "relational_store:rdb_data_share_adapter", - # ] - # } + if (ability_runtime_relational) { + include_dirs += [ "../featureAbility/data_ability/include" ] + sources += [ + "../featureAbility/data_ability/js_utils.cpp", + "../featureAbility/data_ability/napi_data_ability_predicates.cpp", + "../featureAbility/data_ability/napi_rdb_js_utils.cpp", + "../featureAbility/data_ability/napi_result_set.cpp", + ] + external_deps += [ + "ets_runtime:libark_jsruntime", + "eventhandler:libeventhandler", + "kv_store:distributeddata_mgr", + "relational_store:native_appdatafwk", + "relational_store:native_dataability", + "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", + ] + } cflags_cc = [] if (os_dlp_part_enabled) { diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index 93e2442d87..ec73d741db 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -87,16 +87,10 @@ ohos_shared_library("ability_context_native") { "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", "faultloggerd:libdfx_dumpcatcher", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", - # "image_framework:image_native", "ipc:ipc_core", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", - # "window_manager:libwm", ] public_external_deps = [ "ability_base:extractortool", diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index 4d01338113..8ecd2fa4a5 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -402,7 +402,7 @@ ErrCode AbilityContextImpl::ConnectAbility(const AAFwk::Want& want, const sptrname.c_str(), want.GetElement().GetAbilityName().c_str()); ErrCode ret = ConnectionManager::GetInstance().ConnectAbility(token_, want, connectCallback); if (ret != ERR_OK) { @@ -440,7 +440,7 @@ void AbilityContextImpl::DisconnectAbility(const AAFwk::Want& want, const sptr& connectCallback, int32_t accountId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::CONTEXT, "DisconnectAbility called, caller:%{public}s, target:%{public}s", + TAG_LOGI(AAFwkTag::CONTEXT, "DisconnectAbility, caller:%{public}s, target:%{public}s", abilityInfo_ == nullptr ? "" : abilityInfo_->name.c_str(), want.GetElement().GetAbilityName().c_str()); ErrCode ret = ConnectionManager::GetInstance().DisconnectAbility(token_, want, connectCallback, accountId); diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 556ef897ba..bf16b6ddc3 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -137,12 +137,10 @@ ohos_shared_library("abilitykit_utils") { sources = [ "${ability_runtime_native_path}/ability/native/ability_handler.cpp", "${ability_runtime_native_path}/ability/native/ability_local_record.cpp", - "${ability_runtime_native_path}/ability/native/application_configuration_manager.cpp", "${ability_runtime_native_path}/ability/native/configuration_utils.cpp", - "${ability_runtime_native_path}/ability/native/resource_config_helper.cpp", ] - deps = [] + deps = [ ":configuration_helper" ] configs = [ ":abilitykit_utils_exceptions" ] @@ -162,7 +160,6 @@ ohos_shared_library("abilitykit_utils") { "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] public_external_deps = [ @@ -178,7 +175,6 @@ ohos_shared_library("abilitykit_utils") { "window_manager:libwm", ] public_external_deps += [ - # "form_fwk:form_manager", "graphic_2d:color_manager", "image_framework:image_native", "window_manager:libdm", @@ -191,6 +187,68 @@ ohos_shared_library("abilitykit_utils") { part_name = "ability_runtime" } +ohos_shared_library("configuration_helper") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + branch_protector_ret = "pac_ret" + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/wantagent/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ + "${ability_runtime_native_path}/ability/native/application_configuration_manager.cpp", + "${ability_runtime_native_path}/ability/native/resource_config_helper.cpp", + ] + + deps = [] + + external_deps = [ + "ability_base:configuration", + "ability_base:want", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "ipc:ipc_napi", + "json:nlohmann_json_static", + "jsoncpp:jsoncpp", + "napi:ace_napi", + "resource_management:global_resmgr", + ] + + if (ability_runtime_graphics) { + external_deps += [ + "ability_base:session_info", + "graphic_2d:color_manager", + "icu:shared_icuuc", + "image_framework:image_native", + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwmutil", + ] + } + + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_shared_library("abilitykit_native") { branch_protector_ret = "pac_ret" @@ -242,6 +300,7 @@ ohos_shared_library("abilitykit_native") { ] deps = [ + ":configuration_helper", ":continuation_ipc", ":extension_blocklist_config", ":ui_service_extension_connection", @@ -358,7 +417,6 @@ ohos_shared_library("abilitykit_native") { ] public_external_deps += [ - # "form_fwk:form_manager", "window_manager:libdm", ] } @@ -379,6 +437,7 @@ config("extensionkit_public_config") { "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime", "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_services_path}/common/include", ] if (ability_runtime_graphics) { @@ -414,6 +473,7 @@ ohos_shared_library("extensionkit_native") { public_configs = [ ":extensionkit_public_config" ] deps = [ + ":configuration_helper", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/runtime:runtime", @@ -428,15 +488,12 @@ ohos_shared_library("extensionkit_native") { "common_event_service:cesfwk_innerkits", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", "json:nlohmann_json_static", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] public_deps = [ ":abilitykit_utils" ] @@ -450,7 +507,6 @@ ohos_shared_library("extensionkit_native") { if (ability_runtime_graphics) { external_deps += [ "ability_base:session_info" ] public_external_deps += [ - # "form_fwk:form_manager", "graphic_2d:color_manager", "image_framework:image_native", "window_manager:libdm", @@ -493,16 +549,11 @@ ohos_shared_library("insight_intent_executor") { "c_utils:utils", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", - # "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_napi", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] subsystem_name = "ability" @@ -559,6 +610,7 @@ ohos_shared_library("uiabilitykit_native") { deps = [ ":abilitykit_native", + ":configuration_helper", ":continuation_ipc", ":ui_extension", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", @@ -632,7 +684,6 @@ ohos_shared_library("uiabilitykit_native") { "window_manager:windowstage_kit", ] public_external_deps += [ - # "form_fwk:form_manager", "graphic_2d:color_manager", "image_framework:image_native", "window_manager:libdm", @@ -784,7 +835,6 @@ ohos_shared_library("form_extension_module") { if (ability_runtime_graphics) { public_external_deps = [ "form_fwk:fmskit_provider_client", - # "form_fwk:form_manager", "window_manager:libdm", ] } @@ -1047,21 +1097,17 @@ ohos_shared_library("ui_service_extension_module") { if (ability_runtime_graphics) { external_deps += [ "ace_engine:ace_uicontent", - # "form_fwk:form_manager", "image_framework:image", "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", "window_manager:scene_session", "window_manager:session_manager_lite", - # "window_manager:window_native_kit", - # "window_manager:windowstage_kit", ] public_external_deps = [ "form_fwk:fmskit_native", "form_fwk:fmskit_provider_client", - # "form_fwk:form_manager", "window_manager:libdm", "window_manager:libwmutil", "window_manager:window_native_kit", @@ -1107,19 +1153,13 @@ ohos_shared_library("continuation_ipc") { ] external_deps = [ - # "ability_base:session_info", "ability_base:want", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", - # "graphic_2d:2d_graphics", "hilog:libhilog", "ipc:ipc_core", - # "json:nlohmann_json_static", - # "node:node_header_notice", "resource_management:global_resmgr", - # "skia:skia_canvaskit", - # "window_manager:libwm", ] public_external_deps = [ # "accessibility:accessibility_common", @@ -1181,7 +1221,6 @@ ohos_shared_library("data_ability_helper") { if (ability_runtime_graphics) { public_external_deps = [ "form_fwk:fmskit_provider_client", - # "form_fwk:form_manager", "window_manager:libdm", ] } @@ -1225,7 +1264,6 @@ ohos_shared_library("service_extension_module") { ] public_external_deps = [ "form_fwk:fmskit_provider_client", - # "form_fwk:form_manager", "window_manager:libdm", ] } @@ -1435,7 +1473,6 @@ ohos_shared_library("ui_extension_module") { "window_manager:libwm", ] if (ability_runtime_graphics) { - # external_deps += [ "form_fwk:form_manager" ] external_deps += [ ] } @@ -1577,7 +1614,6 @@ ohos_shared_library("share_extension_module") { if (ability_runtime_graphics) { external_deps += [ - # "form_fwk:form_manager", "window_manager:libwm", ] } @@ -1643,7 +1679,6 @@ ohos_shared_library("action_extension_module") { if (ability_runtime_graphics) { external_deps += [ - # "form_fwk:form_manager", "window_manager:libwm", ] } @@ -1906,7 +1941,6 @@ ohos_shared_library("auto_fill_extension_module") { "window_manager:libwm", ] if (ability_runtime_graphics) { - # external_deps += [ "form_fwk:form_manager" ] external_deps += [ ] } diff --git a/frameworks/native/ability/native/ability_impl.cpp b/frameworks/native/ability/native/ability_impl.cpp index f65183f602..490e4c8980 100644 --- a/frameworks/native/ability/native/ability_impl.cpp +++ b/frameworks/native/ability/native/ability_impl.cpp @@ -31,11 +31,6 @@ namespace OHOS { using AbilityRuntime::FreezeUtil; namespace AppExecFwk { -namespace { -const std::string PERMISSION_KEY = "ohos.user.grant.permission"; -const std::string GRANTED_RESULT_KEY = "ohos.user.grant.permission.result"; -} - void AbilityImpl::Init(const std::shared_ptr &application, const std::shared_ptr &record, std::shared_ptr &ability, diff --git a/frameworks/native/ability/native/ability_local_record.cpp b/frameworks/native/ability/native/ability_local_record.cpp index d6a715ad5e..4787d099be 100644 --- a/frameworks/native/ability/native/ability_local_record.cpp +++ b/frameworks/native/ability/native/ability_local_record.cpp @@ -19,8 +19,9 @@ namespace OHOS { namespace AppExecFwk { -AbilityLocalRecord::AbilityLocalRecord(const std::shared_ptr &info, const sptr &token) - : abilityInfo_(info), token_(token) {} +AbilityLocalRecord::AbilityLocalRecord(const std::shared_ptr &info, const sptr &token, + const std::shared_ptr &want, int32_t abilityRecordId) + : abilityInfo_(info), token_(token), want_(want), abilityRecordId_(abilityRecordId) {} AbilityLocalRecord::~AbilityLocalRecord() {} @@ -29,31 +30,16 @@ const std::shared_ptr &AbilityLocalRecord::GetAbilityInfo() return abilityInfo_; } -const std::shared_ptr &AbilityLocalRecord::GetEventHandler() -{ - return handler_; -} - -void AbilityLocalRecord::SetEventHandler(const std::shared_ptr &handler) -{ - handler_ = handler; -} - -const std::shared_ptr &AbilityLocalRecord::GetEventRunner() -{ - return runner_; -} - -void AbilityLocalRecord::SetEventRunner(const std::shared_ptr &runner) -{ - runner_ = runner; -} - const sptr &AbilityLocalRecord::GetToken() { return token_; } +int32_t AbilityLocalRecord::GetAbilityRecordId() const +{ + return abilityRecordId_; +} + const sptr &AbilityLocalRecord::GetAbilityThread() { return abilityThread_; @@ -64,11 +50,6 @@ void AbilityLocalRecord::SetAbilityThread(const sptr &abilityThre abilityThread_ = abilityThread; } -void AbilityLocalRecord::SetWant(const std::shared_ptr &want) -{ - want_ = want; -} - const std::shared_ptr &AbilityLocalRecord::GetWant() { return want_; diff --git a/frameworks/native/ability/native/continuation/remote_register_service/continuation_register_manager.cpp b/frameworks/native/ability/native/continuation/remote_register_service/continuation_register_manager.cpp index 2353301661..ec4792526f 100644 --- a/frameworks/native/ability/native/continuation/remote_register_service/continuation_register_manager.cpp +++ b/frameworks/native/ability/native/continuation/remote_register_service/continuation_register_manager.cpp @@ -68,7 +68,7 @@ void ContinuationRegisterManager::Unregister(int token, const std::shared_ptrGetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - mainRunner == nullptr ? abilityRecord->SetEventRunner(runner_) : abilityRecord->SetEventRunner(mainRunner); abilityRecord->SetAbilityThread(this); HandleAttachInner(application, abilityRecord); } @@ -267,7 +265,7 @@ void ExtensionAbilityThread::HandleExtensionTransaction( const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::EXT, "%{public}s Begin", __func__); + TAG_LOGD(AAFwkTag::EXT, "%{public}s", __func__); if (extensionImpl_ == nullptr) { TAG_LOGE(AAFwkTag::EXT, "null extensionImpl_"); return; diff --git a/frameworks/native/ability/native/fa_ability_thread.cpp b/frameworks/native/ability/native/fa_ability_thread.cpp index 05f025e026..75166a0c06 100644 --- a/frameworks/native/ability/native/fa_ability_thread.cpp +++ b/frameworks/native/ability/native/fa_ability_thread.cpp @@ -285,8 +285,6 @@ void FAAbilityThread::Attach(const std::shared_ptr } currentAbility_.reset(ability); token_ = abilityRecord->GetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(mainRunner); abilityRecord->SetAbilityThread(this); std::shared_ptr abilityObject = currentAbility_; std::shared_ptr contextDeal = @@ -356,8 +354,6 @@ void FAAbilityThread::AttachExtension(const std::shared_ptrGetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(mainRunner); abilityRecord->SetAbilityThread(this); extensionImpl_ = std::make_shared(); if (extensionImpl_ == nullptr) { @@ -405,8 +401,6 @@ void FAAbilityThread::AttachExtension(const std::shared_ptrGetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(runner_); abilityRecord->SetAbilityThread(this); extensionImpl_ = std::make_shared(); if (extensionImpl_ == nullptr) { @@ -460,8 +454,6 @@ void FAAbilityThread::Attach(const std::shared_ptr } currentAbility_.reset(ability); token_ = abilityRecord->GetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(runner_); abilityRecord->SetAbilityThread(this); std::shared_ptr abilityObject = currentAbility_; std::shared_ptr contextDeal = diff --git a/frameworks/native/ability/native/new_ability_impl.cpp b/frameworks/native/ability/native/new_ability_impl.cpp index 5168b72937..d20e051da3 100644 --- a/frameworks/native/ability/native/new_ability_impl.cpp +++ b/frameworks/native/ability/native/new_ability_impl.cpp @@ -25,13 +25,6 @@ namespace OHOS { using AbilityRuntime::FreezeUtil; namespace AppExecFwk { using AbilityManagerClient = OHOS::AAFwk::AbilityManagerClient; -/** - * @brief Handling the life cycle switching of NewAbility. - * - * @param want Indicates the structure containing information about the ability. - * @param targetState The life cycle state to switch to. - * - */ void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState, sptr sessionInfo) @@ -72,10 +65,10 @@ void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Lif void NewAbilityImpl::HandleShareData(const int32_t &uniqueId) { - TAG_LOGI(AAFwkTag::ABILITY, "begin sourceState:%{public}d", lifecycleState_); WantParams wantParam; int32_t resultCode = Share(wantParam); - TAG_LOGI(AAFwkTag::ABILITY, "wantParam size: %{public}d", wantParam.Size()); + TAG_LOGI(AAFwkTag::ABILITY, "begin sourceState:%{public}d, wantParam size:%{public}d", + lifecycleState_, wantParam.Size()); AbilityManagerClient::GetInstance()->ShareDataDone(token_, resultCode, uniqueId, wantParam); } @@ -89,15 +82,6 @@ void NewAbilityImpl::AbilityTransactionCallback(const AbilityLifeCycleState &sta } } -/** - * @brief Handling the life cycle switching of NewAbility in switch. - * - * @param want Indicates the structure containing information about the ability. - * @param targetState The life cycle state to switch to. - * - * @return return true if need notify ams, otherwise return false. - * - */ bool NewAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index d2c23c1327..23a64db970 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -140,8 +140,6 @@ void UIAbilityThread::Attach(const std::shared_ptr ability->SetAbilityRecordId(abilityRecord->GetAbilityRecordId()); currentAbility_.reset(ability); token_ = abilityRecord->GetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(mainRunner); abilityRecord->SetAbilityThread(this); std::shared_ptr abilityObject = currentAbility_; std::shared_ptr contextDeal = @@ -212,8 +210,6 @@ void UIAbilityThread::Attach(const std::shared_ptr ability->SetAbilityRecordId(abilityRecord->GetAbilityRecordId()); currentAbility_.reset(ability); token_ = abilityRecord->GetToken(); - abilityRecord->SetEventHandler(abilityHandler_); - abilityRecord->SetEventRunner(runner_); abilityRecord->SetAbilityThread(this); std::shared_ptr abilityObject = currentAbility_; std::shared_ptr contextDeal = diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 5a60989f55..8aaad2e862 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -158,6 +158,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", @@ -313,11 +314,8 @@ ohos_shared_library("app_context") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "ets_runtime:libark_jsruntime", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", - # "image_framework:image_native", "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", @@ -325,7 +323,6 @@ ohos_shared_library("app_context") { "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", - # "skia:skia_canvaskit", ] public_external_deps = [ "ability_base:configuration", @@ -391,7 +388,6 @@ ohos_shared_library("app_context_utils") { "bundle_framework:appexecfwk_core", "c_utils:utils", "ets_runtime:libark_jsruntime", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", @@ -400,7 +396,6 @@ ohos_shared_library("app_context_utils") { "napi:ace_napi", "resource_management:global_resmgr", "resource_management:resmgr_napi_core", - # "skia:skia_canvaskit", ] public_external_deps = [ "ability_base:configuration" ] if (ability_runtime_graphics) { diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index 3e64de339a..d95edf3f7e 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -196,6 +196,19 @@ ErrCode BundleMgrHelper::GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, return bundleMgr->GetSandboxHapModuleInfo(abilityInfo, appIndex, userId, hapModuleInfo); } +std::string BundleMgrHelper::GetAppIdByBundleName(const std::string &bundleName, const int32_t userId) +{ + TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "GetAppIdByBundleName called"); + auto bundleMgr = Connect(); + if (bundleMgr == nullptr) { + TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect."); + return ""; + } + + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + return bundleMgr->GetAppIdByBundleName(bundleName, userId); +} + sptr BundleMgrHelper::Connect() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/frameworks/native/appkit/app/ability_record_mgr.cpp b/frameworks/native/appkit/app/ability_record_mgr.cpp index 24ed12757c..fd4d7867a5 100644 --- a/frameworks/native/appkit/app/ability_record_mgr.cpp +++ b/frameworks/native/appkit/app/ability_record_mgr.cpp @@ -41,32 +41,6 @@ void AbilityRecordMgr::SetToken(const sptr &token) tokens_ = token; } -/** - * @brief Set the eventRunner of abilitythread to the AbilityRecordMgr. - * - * @param eventRunner The runner of the abilitythread. - * - */ -void AbilityRecordMgr::SetEventRunner(const std::shared_ptr &eventRunner) -{ - if (eventRunner == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "eventRunner is nullptr"); - return; - } - sptr token = GetToken(); - if (token == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "token is nullptr"); - return; - } - - std::shared_ptr abilityInstance = GetAbilityItem(token); - if (abilityInstance != nullptr) { - abilityInstance->SetEventRunner(eventRunner); - } else { - TAG_LOGW(AAFwkTag::APPKIT, "ability record not exist"); - } -} - /** * @brief Save the token and abilityRecord to the AbilityRecordMgr. * diff --git a/frameworks/native/appkit/app/application_cleaner.cpp b/frameworks/native/appkit/app/application_cleaner.cpp index 2740f2309c..4acf00f506 100644 --- a/frameworks/native/appkit/app/application_cleaner.cpp +++ b/frameworks/native/appkit/app/application_cleaner.cpp @@ -44,7 +44,7 @@ static const int RESULT_ERR = -1; static const char TASK_NAME[] = "ApplicationCleaner::ClearTempData"; static constexpr uint64_t DELAY = 5000000; //5s -constexpr int64_t ONEHUNDRED_MB = 50 * 1024; +constexpr int64_t MAX_FILE_SIZE = 50 * 1024; } // namespace void ApplicationCleaner::RenameTempData() { @@ -97,7 +97,7 @@ void ApplicationCleaner::ClearTempData() } }; - if (CheckFileSize(rootDir, ONEHUNDRED_MB)) { + if (CheckFileSize(rootDir)) { ffrt::submit(cleanTemp); } else { ffrt::task_attr attr; @@ -107,7 +107,7 @@ void ApplicationCleaner::ClearTempData() } } -bool ApplicationCleaner::CheckFileSize(const std::vector bundlePath, const int64_t maxFileSize) +bool ApplicationCleaner::CheckFileSize(const std::vector &bundlePath) { int64_t fileSize = 0; @@ -118,12 +118,7 @@ bool ApplicationCleaner::CheckFileSize(const std::vector bundlePath } fileSize += fileInfo.st_size; } - - if (fileSize > maxFileSize) { - return false; -} - - return true; + return (fileSize <= MAX_FILE_SIZE); } int ApplicationCleaner::GetRootPath(std::vector &rootPath) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 82474fae46..9683f3e173 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -706,9 +706,7 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptr abilityInfo = std::make_shared(info); - auto abilityRecord = std::make_shared(abilityInfo, token); - abilityRecord->SetWant(want); - abilityRecord->SetAbilityRecordId(abilityRecordId); + auto abilityRecord = std::make_shared(abilityInfo, token, want, abilityRecordId); auto tmpWatchdog = watchdog_; if (tmpWatchdog != nullptr) { tmpWatchdog->SetBgWorkingThreadStatus(IsBgWorkingThread(info)); @@ -1370,7 +1368,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con std::vector localPaths; ChangeToLocalPath(bundleName, appInfo.moduleSourceDirs, localPaths); LoadAbilityLibrary(localPaths); - LoadNativeLiabrary(bundleInfo, appInfo.nativeLibraryPath); + LoadNativeLibrary(bundleInfo, appInfo.nativeLibraryPath); #ifdef SUPPORT_SCREEN } else if (Ace::AceForwardCompatibility::PipelineChanged()) { std::vector localPaths; @@ -1817,7 +1815,7 @@ void MainThread::CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::st } } -void MainThread::LoadNativeLiabrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath) +void MainThread::LoadNativeLibrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath) { CalcNativeLiabraryEntries(bundleInfo, nativeLibraryPath); if (nativeFileEntries_.empty()) { diff --git a/frameworks/native/insight_intent/insight_intent_context/BUILD.gn b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn index 55848da0d5..eed96d7eae 100644 --- a/frameworks/native/insight_intent/insight_intent_context/BUILD.gn +++ b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn @@ -41,19 +41,14 @@ ohos_shared_library("insightintentcontext") { ] external_deps = [ - # "ability_base:session_info", "ability_base:want", "c_utils:utils", "ets_runtime:libark_jsruntime", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", - # "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_single", "napi:ace_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] subsystem_name = "ability" diff --git a/frameworks/simulator/ability_simulator/include/js_application_context_utils.h b/frameworks/simulator/ability_simulator/include/js_application_context_utils.h index ca2bb44399..a35196f033 100644 --- a/frameworks/simulator/ability_simulator/include/js_application_context_utils.h +++ b/frameworks/simulator/ability_simulator/include/js_application_context_utils.h @@ -54,6 +54,7 @@ public: static napi_value GetRunningProcessInformation(napi_env env, napi_callback_info info); static napi_value CreateJsApplicationContext(napi_env env, const std::shared_ptr &context); static napi_value SetSupportedProcessCacheSelf(napi_env env, napi_callback_info info); + static napi_value SetColorMode(napi_env env, napi_callback_info info); napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo& info); napi_value OnGetTempDir(napi_env env, NapiCallbackInfo& info); diff --git a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp index e926daeed4..df7a13537a 100644 --- a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp +++ b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp @@ -34,6 +34,11 @@ napi_value JsApplicationContextUtils::CreateBundleContext(napi_env env, napi_cal return nullptr; } +napi_value JsApplicationContextUtils::SetColorMode(napi_env env, napi_callback_info info) +{ + return nullptr; +} + napi_value JsApplicationContextUtils::SwitchArea(napi_env env, napi_callback_info info) { GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnSwitchArea, APPLICATION_CONTEXT_NAME); @@ -355,6 +360,7 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_ JsApplicationContextUtils::GetRunningProcessInformation); BindNativeFunction(env, object, "getRunningProcessInformation", MD_NAME, JsApplicationContextUtils::GetRunningProcessInformation); + BindNativeFunction(env, object, "setColorMode", MD_NAME, JsApplicationContextUtils::SetColorMode); } } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 0085c074da..46e34cf5a1 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -87,7 +87,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp", "${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp", "${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_listener_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_listener_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/open_link/open_link_options.cpp", "${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_stub.cpp", @@ -137,21 +137,14 @@ ohos_shared_library("ability_manager") { "common_event_service:cesfwk_innerkits", "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - # "image_framework:image_native", - # "input:libmmi-client", "ipc:ipc_core", "ipc:ipc_napi", "jsoncpp:jsoncpp", "relational_store:native_dataability", - # "relational_store:native_rdb", - # "resource_management:global_resmgr", "samgr:samgr_proxy", - # "skia:skia_canvaskit", ] if (host_cpu != "arm64") { @@ -240,17 +233,15 @@ ohos_shared_library("mission_info") { branch_protector_ret = "pac_ret" sources = [ - "${ability_runtime_services_path}/abilitymgr/src/mission_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_snapshot.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_snapshot.cpp", ] public_configs = [ ":ability_manager_public_config" ] external_deps = [ "c_utils:utils", - # "graphic_2d:2d_graphics", "ipc:ipc_core", - # "skia:skia_canvaskit", ] public_external_deps = [ "ability_base:configuration", @@ -281,13 +272,9 @@ ohos_shared_library("ability_manager_c") { "ability_base:session_info", "c_utils:utils", "ets_runtime:libark_jsruntime", - # "form_fwk:form_manager", - # "graphic_2d:2d_graphics", "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_napi", - # "resource_management:global_resmgr", - # "skia:skia_canvaskit", ] innerapi_tags = [ "platformsdk" ] subsystem_name = "ability" diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index b9966d0c2a..839032fb2e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -512,7 +512,7 @@ public: int32_t userId = DEFAULT_INVAL_VALUE); /** - * ConnectUIServiceExtesnionAbility, connect session with uiService ability. + * ConnectUIServiceExtensionAbility, connect session with uiService ability. * * @param want, Special want for uiService type's ability. * @param connect, Callback used to notify caller the result of connecting or disconnecting. @@ -672,7 +672,7 @@ public: /** * notify continuation complete to dms. * @param deviceId, source device which start a continuation. - * @param sessionId, represent a continuaion. + * @param sessionId, represent a continuation. * @param isSuccess, continuation result. * @return */ @@ -721,7 +721,7 @@ public: void SetLockedState(int32_t sessionId, bool lockedState); /** - * @brief Register mission listener to ams. + * @brief Register mission listener to ability mgr. * @param listener The handler of listener. * * @return Returns ERR_OK on success, others on failure. @@ -729,7 +729,7 @@ public: ErrCode RegisterMissionListener(sptr listener); /** - * @brief UnRegister mission listener from ams. + * @brief UnRegister mission listener from ability mgr. * @param listener The handler of listener. * * @return Returns ERR_OK on success, others on failure. @@ -773,8 +773,8 @@ public: ErrCode UnRegisterMissionListener(const std::string &deviceId, sptr listener); /** - * @brief Get mission infos from ams. - * @param deviceId local or remote deviceid. + * @brief Get mission infos from ability mgr. + * @param deviceId local or remote deviceId. * @param numMax max number of missions. * @param missionInfos mission info result. * @@ -784,9 +784,9 @@ public: /** * @brief Get mission info by id. - * @param deviceId local or remote deviceid. + * @param deviceId local or remote deviceId. * @param missionId Id of target mission. - * @param missionInfo mision info of target mission. + * @param missionInfo mission info of target mission. * * @return Returns ERR_OK on success, others on failure. */ @@ -794,7 +794,7 @@ public: /** * @brief Get the Mission Snapshot Info object - * @param deviceId local or remote deviceid. + * @param deviceId local or remote deviceId. * @param missionId Id of target mission. * @param snapshot snapshot of target mission. * @param isLowResolution get low resolution snapshot. @@ -1022,7 +1022,7 @@ public: * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb. * * @param sessionInfo the session info of the ability to terminate. - * @param isPrepareTerminate the result of ability onPrepareToTermiante. + * @param isPrepareTerminate the result of ability onPrepareToTerminate. * @return Returns ERR_OK on success, others on failure. */ ErrCode PrepareTerminateAbilityBySCB(sptr sessionInfo, bool &isPrepareTerminate); @@ -1030,7 +1030,7 @@ public: /** * Set mission continue state of this ability. * - * @param token Indidate token of ability. + * @param token Indicate token of ability. * @param state the mission continuation state of this ability. * @return Returns ERR_OK if success. */ @@ -1041,8 +1041,8 @@ public: /** * Set mission label of this ability. * - * @param abilityToken Indidate token of ability. - * @param label Indidate the label showed of the ability in recent missions. + * @param abilityToken Indicate token of ability. + * @param label Indicate the label showed of the ability in recent missions. * @return Returns ERR_OK on success, others on failure. */ ErrCode SetMissionLabel(sptr abilityToken, const std::string &label); @@ -1050,8 +1050,8 @@ public: /** * Set mission icon of this ability. * - * @param abilityToken Indidate token of ability. - * @param icon Indidate the icon showed of the ability in recent missions. + * @param abilityToken Indicate token of ability. + * @param icon Indicate the icon showed of the ability in recent missions. * @return Returns ERR_OK on success, others on failure. */ ErrCode SetMissionIcon(sptr abilityToken, @@ -1060,7 +1060,7 @@ public: /** * Register the WindowManagerService handler * - * @param handler Indidate handler of WindowManagerService. + * @param handler Indicate handler of WindowManagerService. * @return ErrCode Returns ERR_OK on success, others on failure. */ ErrCode RegisterWindowManagerServiceHandler(sptr handler, @@ -1069,14 +1069,14 @@ public: /** * WindowManager notification AbilityManager after the first frame is drawn. * - * @param abilityToken Indidate token of ability. + * @param abilityToken Indicate token of ability. */ void CompleteFirstFrameDrawing(sptr abilityToken); /** * WindowManager notification AbilityManager after the first frame is drawn. * - * @param sessionId Indidate session id. + * @param sessionId Indicate session id. */ void CompleteFirstFrameDrawing(int32_t sessionId); @@ -1596,6 +1596,16 @@ public: */ ErrCode BlockAllAppStart(bool flag); + /** + * update associate config list by rss. + * + * @param configs The rss config info. + * @param exportConfigs The rss export config info. + * @param flag UPDATE_CONFIG_FLAG_COVER is cover config, UPDATE_CONFIG_FLAG_APPEND is append config. + */ + ErrCode UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag); + private: AbilityManagerClient(); DISALLOW_COPY_AND_MOVE(AbilityManagerClient); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 386f4834e2..1c22cb525d 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -336,7 +336,7 @@ public: * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartExtensionAbility( + virtual int32_t StartExtensionAbility( const Want &want, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, @@ -597,7 +597,7 @@ public: * @param userId, Designation User ID. * @return Returns ERR_OK on success, others on failure. */ - virtual int ConnectAbility( + virtual int32_t ConnectAbility( const Want &want, const sptr &connect, const sptr &callerToken, @@ -613,7 +613,7 @@ public: * @param userId, the service user ID. * @return Returns ERR_OK on success, others on failure. */ - virtual int ConnectAbilityCommon( + virtual int32_t ConnectAbilityCommon( const Want &want, const sptr &connect, const sptr &callerToken, @@ -863,36 +863,108 @@ public: return; } + /** + * @brief Register mission listener to ability mgr. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterMissionListener(const sptr &listener) = 0; + /** + * @brief UnRegister mission listener from ability mgr. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int UnRegisterMissionListener(const sptr &listener) = 0; + /** + * @brief Get mission infos from ability mgr. + * @param deviceId local or remote deviceId. + * @param numMax max number of missions. + * @param missionInfos mission info result. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionInfos( const std::string &deviceId, int32_t numMax, std::vector &missionInfos) = 0; + /** + * @brief Get mission info by id. + * @param deviceId local or remote deviceId. + * @param missionId Id of target mission. + * @param missionInfo mission info of target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionInfo(const std::string &deviceId, int32_t missionId, MissionInfo &missionInfo) = 0; + /** + * @brief Get the Mission Snapshot Info object + * @param deviceId local or remote deviceId. + * @param missionId Id of target mission. + * @param snapshot snapshot of target mission. + * @param isLowResolution get low resolution snapshot. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot, bool isLowResolution) = 0; + /** + * @brief Clean mission by id. + * @param missionId Id of target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int CleanMission(int32_t missionId) = 0; + /** + * @brief Clean all missions in system. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int CleanAllMissions() = 0; virtual int MoveMissionToFront(int32_t missionId) = 0; + /** + * @brief Move a mission to front. + * @param missionId Id of target mission. + * @param startOptions Special startOptions for target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) = 0; + /** + * Move missions to front + * @param missionIds Ids of target missions + * @param topMissionId Indicate which mission will be moved to top, if set to -1, missions' order won't change + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionsToForeground(const std::vector& missionIds, int32_t topMissionId) { return 0; } + /** + * Move missions to background + * @param missionIds Ids of target missions + * @param result The result of move missions to background, and the array is sorted by zOrder + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionsToBackground(const std::vector& missionIds, std::vector& result) { return 0; } + /** + * @brief Register session handler. + * @param object The handler. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterSessionHandler(const sptr &object) { return 0; @@ -925,10 +997,29 @@ public: */ virtual int ReleaseCall(const sptr &connect, const AppExecFwk::ElementName &element) = 0; + /** + * @brief start user. + * @param accountId accountId. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StartUser(int userId, sptr callback) = 0; + /** + * @brief stop user. + * @param accountId accountId. + * @param callback callback. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StopUser(int userId, const sptr &callback) = 0; + /** + * @brief logout user. + * @param accountId accountId. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int LogoutUser(int32_t userId) { return 0; @@ -956,7 +1047,7 @@ public: /** * Register the WindowManagerService handler * - * @param handler Indidate handler of WindowManagerService. + * @param handler Indicate handler of WindowManagerService. * @return ErrCode Returns ERR_OK on success, others on failure. */ virtual int RegisterWindowManagerServiceHandler(const sptr& handler, @@ -968,14 +1059,14 @@ public: /** * WindowManager notification AbilityManager after the first frame is drawn. * - * @param abilityToken Indidate token of ability. + * @param abilityToken Indicate token of ability. */ virtual void CompleteFirstFrameDrawing(const sptr &abilityToken) = 0; /** * WindowManager notification AbilityManager after the first frame is drawn. * - * @param sessionId Indidate session id. + * @param sessionId Indicate session id. */ virtual void CompleteFirstFrameDrawing(int32_t sessionId) {} @@ -1025,11 +1116,29 @@ public: } #endif - + /** + * @brief Get the ability running information. + * + * @param info Ability running information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetAbilityRunningInfos(std::vector &info) = 0; + /** + * @brief Get the extension running information. + * + * @param upperLimit The maximum limit of information wish to get. + * @param info Extension running information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetExtensionRunningInfos(int upperLimit, std::vector &info) = 0; + /** + * @brief Get running process information. + * + * @param info Running process information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetProcessRunningInfos(std::vector &info) = 0; /** @@ -1048,6 +1157,13 @@ public: */ virtual int StopSyncRemoteMissions(const std::string &devId) = 0; + /** + * @brief Register mission listener to ability manager service. + * @param deviceId The remote device Id. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterMissionListener(const std::string &deviceId, const sptr &listener) = 0; virtual int RegisterOnListener(const std::string &type, const sptr &listener) @@ -1086,8 +1202,23 @@ public: */ virtual int RegisterSnapshotHandler(const sptr& handler) = 0; + /** + * @brief start user test. + * @param want the want of the ability user test to start. + * @param observer test observer callback. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StartUserTest(const Want &want, const sptr &observer) = 0; + /** + * @brief Finish user test. + * @param msg user test message. + * @param resultCode user test result Code. + * @param bundleName user test bundleName. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) = 0; /** @@ -1197,6 +1328,11 @@ public: virtual void ScheduleRecoverAbility(const sptr &token, int32_t reason, const Want *want = nullptr) {}; + /** + * @brief Schedule clear recovery page stack. + * + * @param bundleName application bundleName. + */ virtual void ScheduleClearRecoveryPageStack() {}; /** @@ -1746,6 +1882,19 @@ public: { return 0; } + + /** + * update associate config list by rss. + * + * @param configs The rss config info. + * @param exportConfigs The rss export config info. + * @param flag UPDATE_CONFIG_FLAG_COVER is cover config, UPDATE_CONFIG_FLAG_APPEND is append config. + */ + virtual int32_t UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 417ab427e1..9a13e7599c 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -558,6 +558,9 @@ enum class AbilityManagerInterfaceCode { // ipc for block all apps from starting BLOCK_ALL_APP_START = 6119, + + // update associate config list + UPDATE_ASSOCIATE_CONFIG_LIST = 6120, }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/continuation/remote_register_service_interface.h b/interfaces/inner_api/ability_manager/include/continuation/remote_register_service_interface.h index 7346d4b6e7..ad05df1d87 100644 --- a/interfaces/inner_api/ability_manager/include/continuation/remote_register_service_interface.h +++ b/interfaces/inner_api/ability_manager/include/continuation/remote_register_service_interface.h @@ -52,7 +52,7 @@ public: * notify continuation status to controlcenter continuation register service. * * @param registerToken token from register. - * @param deviceId deviceid. + * @param deviceId deviceId. * @param status device status. */ virtual bool UpdateConnectStatus(int registerToken, const std::string &deviceId, int status) = 0; diff --git a/interfaces/inner_api/ability_manager/include/process_options.h b/interfaces/inner_api/ability_manager/include/process_options.h index 17a26e7c9f..fe62eedd5d 100644 --- a/interfaces/inner_api/ability_manager/include/process_options.h +++ b/interfaces/inner_api/ability_manager/include/process_options.h @@ -25,6 +25,7 @@ enum class ProcessMode { NEW_PROCESS_ATTACH_TO_PARENT = 1, NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM = 2, ATTACH_TO_STATUS_BAR_ITEM = 3, + NO_ATTACHMENT = 99, END }; @@ -49,6 +50,7 @@ public: static bool IsNewProcessMode(ProcessMode value); static bool IsAttachToStatusBarMode(ProcessMode value); static bool IsValidProcessMode(ProcessMode value); + static bool IsNoAttachmentMode(ProcessMode value); ProcessMode processMode = ProcessMode::UNSPECIFIED; StartupVisibility startupVisibility = StartupVisibility::UNSPECIFIED; diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 3881341c36..bb1a578108 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -151,7 +151,6 @@ ohos_shared_library("app_manager") { "bundle_framework:appexecfwk_base", "image_framework:image_native", "relational_store:native_rdb", - "skia:skia_canvaskit", ] if (background_task_mgr_continuous_task_enable) { diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index ee2036054d..2acce57ba4 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -103,8 +103,19 @@ public: */ virtual void KillProcessesByUserId(int32_t userId) = 0; + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + */ virtual void KillProcessesByPids(std::vector &pids) {} + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ virtual void AttachPidToParent(const sptr &token, const sptr &callerToken) {} /** @@ -174,23 +185,73 @@ public: return ERR_OK; } + /** + * Ability attach timeout. If start ability encounter failure, attach timeout to terminate. + * + * @param token Ability identify. + */ virtual void AbilityAttachTimeOut(const sptr &token) = 0; + /** + * Prepare terminate. + * + * @param token Ability identify. + * @param clearMissionFlag Clear mission flag. + */ virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) = 0; + /** + * Get running process information by ability token. + * + * @param token Ability identify. + * @param info Running process info. + */ virtual void GetRunningProcessInfoByToken( const sptr &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0; + /** + * Set AbilityForegroundingFlag of an app-record to true. + * + * @param pid, pid. + * + */ virtual void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) = 0; + /** + * Start specified ability. + * + * @param want Want contains information of the ability to start. + * @param abilityInfo Ability information. + * @param requestId request id to callback + */ virtual void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) = 0; + /** + * Register response of start specified ability. + * + * @param response Response of start specified ability. + */ virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response) = 0; + /** + * Start specified process. + * + * @param want Want contains information wish to start. + * @param abilityInfo Ability information. + * @param requestId for callback + */ virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) = 0; + /** + * Get application info by process id. + * + * @param pid Process id. + * @param application Application information got. + * @param debug Whether IsDebugApp. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) = 0; /** @@ -307,6 +368,7 @@ public: * @brief Set resident process enable status. * @param bundleName The application bundle name. * @param enable The current updated enable status. + * @param uid indicates user, 0 for all users */ virtual void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) {}; @@ -318,8 +380,8 @@ public: virtual void ClearProcessByToken(sptr token) {} /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ virtual bool IsMemorySizeSufficent() = 0; @@ -368,6 +430,9 @@ public: return false; } + /** + * Whether a process is attached, refer to AttachApplication + */ virtual bool IsProcessAttached(sptr token) { return false; diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 745d101432..86a94f4b82 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -93,8 +93,19 @@ public: */ virtual void KillProcessesByUserId(int32_t userId) override; + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + */ virtual void KillProcessesByPids(std::vector &pids) override; + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ virtual void AttachPidToParent(const sptr &token, const sptr &callerToken) override; /** @@ -157,15 +168,47 @@ public: virtual int KillApplicationSelf(const bool clearPageStack = false) override; + /** + * Get application info by process id. + * + * @param pid Process id. + * @param application Application information got. + * @param debug Whether IsDebugApp. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override; + /** + * Record process exit reason to appRunningRecord + * @param pid pid + * @param reason reason enum + * @param exitMsg exitMsg + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) override; + /** + * Ability attach timeout. If start ability encounter failure, attach timeout to terminate. + * + * @param token Ability identify. + */ virtual void AbilityAttachTimeOut(const sptr &token) override; + /** + * Prepare terminate. + * + * @param token Ability identify. + * @param clearMissionFlag Clear mission flag. + */ virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) override; + /** + * Get running process information by ability token. + * + * @param token Ability identify. + * @param info Running process info. + */ void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info) override; /** @@ -176,11 +219,30 @@ public: */ void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override; + /** + * Start specified ability. + * + * @param want Want contains information of the ability to start. + * @param abilityInfo Ability information. + * @param requestId request id to callback + */ virtual void StartSpecifiedAbility( const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) override; + /** + * Register response of start specified ability. + * + * @param response Response of start specified ability. + */ virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response) override; + /** + * Start specified process. + * + * @param want Want contains information wish to start. + * @param abilityInfo Ability information. + * @param requestId for callback + */ virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) override; @@ -268,6 +330,7 @@ public: * @brief Set resident process enable status. * @param bundleName The application bundle name. * @param enable The current updated enable status. + * @param uid indicates user, 0 for all users */ void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) override; @@ -279,8 +342,8 @@ public: virtual void ClearProcessByToken(sptr token) override; /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ virtual bool IsMemorySizeSufficent() override; @@ -320,6 +383,9 @@ public: */ virtual bool IsProcessContainsOnlyUIAbility(const pid_t pid) override; + /** + * Whether a process is attached, refer to AttachApplication + */ virtual bool IsProcessAttached(sptr token) override; virtual bool IsAppKilling(sptr token) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 7aefcf17b9..52a2e5a3a5 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -126,8 +126,19 @@ public: */ virtual AppMgrResultCode KillProcessesByUserId(int32_t userId); + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + */ virtual AppMgrResultCode KillProcessesByPids(std::vector &pids); + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ virtual AppMgrResultCode AttachPidToParent(const sptr &token, const sptr &callerToken); @@ -236,10 +247,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, @@ -303,7 +314,7 @@ public: /** * GetConfiguration * - * @param info, configuration. + * @param info to retrieve configuration data. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetConfiguration(Configuration& config); @@ -362,7 +373,7 @@ public: /** * Update config by bundle name. * - * @param config Application enviroment change parameters. + * @param config Application environment change parameters. * @param name Application bundle name. * @return Returns ERR_OK on success, others on failure. */ @@ -403,8 +414,9 @@ public: /** * Start specified ability. * - * @param want Want contains information wish to start. + * @param want Want contains information of the ability to start. * @param abilityInfo Ability information. + * @param requestId request id to callback */ virtual void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); @@ -421,6 +433,7 @@ public: * * @param want Want contains information wish to start. * @param abilityInfo Ability information. + * @param requestId for callback */ virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); @@ -453,10 +466,10 @@ public: /** * Start nweb render process, called by nweb host. * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param crashFd, crash signal file descriptior. + * @param renderParam, params passed to renderProcess. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. * @param renderPid, created render pid. * @return Returns ERR_OK on success, others on failure. */ @@ -465,7 +478,7 @@ public: int32_t crashFd, pid_t &renderPid, bool isGPU = false); /** - * Render process call this to attach app manager service. + * Render process call this to attach to app manager service. * * @param renderScheduler, scheduler of render process. */ @@ -491,12 +504,9 @@ public: int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); /** - * Get application info by process id. + * start native process for debugger. * - * @param pid Process id. - * @param application Application information got. - * @param debug Whether IsDebugApp. - * @return Returns ERR_OK on success, others on failure. + * @param want param to start a process. */ int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); @@ -646,6 +656,7 @@ public: * @brief Set resident process enable status. * @param bundleName The application bundle name. * @param enable The current updated enable status. + * @param uid indicates user, 0 for all users */ void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid); @@ -711,12 +722,34 @@ public: */ bool IsFinalAppProcess(); + /** + * Register render state observer. + * @param observer Render process state observer. + * @return Returns ERR_OK on success, others on failure. + */ int32_t RegisterRenderStateObserver(const sptr &observer); + /** + * Unregister render state observer. + * @param observer Render process state observer. + * @return Returns ERR_OK on success, others on failure. + */ int32_t UnregisterRenderStateObserver(const sptr &observer); + /** + * Update render state. + * @param renderPid Render pid. + * @param state foreground or background state. + * @return Returns ERR_OK on success, others on failure. + */ int32_t UpdateRenderState(pid_t renderPid, int32_t state); + /** + * Get appRunningUniqueId by pid. + * @param pid pid. + * @param appRunningUniqueId appRunningUniqueId. + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId); /** @@ -738,15 +771,15 @@ public: int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector &providerPids); /** - * @brief Notify memory size state changed to sufficient or insufficent. - * @param isMemorySizeSufficent Indicates the memory size state. + * @brief Notify memory size state changed to sufficient or insufficient. + * @param isMemorySizeSufficient Indicates the memory size state. * @return Returns ERR_OK on success, others on failure. */ - int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent); + int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient); /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ bool IsMemorySizeSufficent() const; @@ -771,10 +804,16 @@ public: virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, AppExecFwk::PreloadMode preloadMode, int32_t appIndex = 0); + /** + * @brief set support process cache by self + */ int32_t SetSupportedProcessCacheSelf(bool isSupport); int32_t SetSupportedProcessCache(int32_t pid, bool isSupport); + /** + * set browser channel for caller + */ void SaveBrowserChannel(sptr browser); /** @@ -793,8 +832,14 @@ public: */ virtual AppMgrResultCode AttachedToStatusBar(const sptr &token); + /** + * Notify that the process depends on web by itself. + */ int32_t NotifyProcessDependedOnWeb(); + /** + * Kill process depended on web by sa. + */ void KillProcessDependedOnWeb(); /** @@ -826,6 +871,9 @@ public: */ bool IsProcessContainsOnlyUIAbility(const pid_t pid); + /** + * Whether a process is attached, refer to AttachApplication + */ bool IsProcessAttached(sptr token) const; bool IsAppKilling(sptr token) const; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index ba13c3b721..c76c56ce84 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -160,10 +160,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, @@ -332,6 +332,13 @@ public: */ virtual int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) = 0; + /** + * Schedule accept want done. + * + * @param recordId Application record. + * @param want Want. + * @param flag flag get from OnAcceptWant. + */ virtual void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag) = 0; virtual void ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want, @@ -356,10 +363,10 @@ public: /** * Start nweb render process, called by nweb host. * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param crashFd, crash signal file descriptior. + * @param renderParam, params passed to renderProcess. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. * @param renderPid, created render pid. * @param isGPU, is or not gpu process * @return Returns ERR_OK on success, others on failure. @@ -384,14 +391,46 @@ public: */ virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) = 0; + /** + * GetConfiguration + * + * @param info to retrieve configuration data. + * @return ERR_OK ,return back success,others fail. + */ virtual int32_t GetConfiguration(Configuration& config) = 0; + /** + * UpdateConfiguration, ANotify application update system environment changes. + * + * @param config System environment change parameters. + * @param userId configuration for the user + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) = 0; + /** + * Update config by bundle name. + * + * @param config Application environment change parameters. + * @param name Application bundle name. + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) = 0; + /** + * Register configuration observer. + * + * @param observer Configuration observer. When configuration changed, observer will be called. + * @return Returns RESULT_OK on success, others on failure. + */ virtual int32_t RegisterConfigurationObserver(const sptr &observer) = 0; + /** + * Unregister configuration observer. + * + * @param observer Configuration observer. + * @return Returns RESULT_OK on success, others on failure. + */ virtual int32_t UnregisterConfigurationObserver(const sptr &observer) = 0; /** @@ -407,7 +446,7 @@ public: * * @param bundleName Bundle name * @param callback called when LoadPatch finished. - * @return Returns 0 on success, error code on failure. + * @return Returns ERR_OK on success, error code on failure. */ virtual int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) = 0; @@ -416,7 +455,7 @@ public: * * @param bundleName Bundle name * @param callback called when HotReload finished. - * @return Returns 0 on success, error code on failure. + * @return Returns ERR_OK on success, error code on failure. */ virtual int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) = 0; @@ -425,7 +464,7 @@ public: * * @param bundleName Bundle name * @param callback called when UnloadPatch finished. - * @return Returns 0 on success, error code on failure. + * @return Returns ERR_OK on success, error code on failure. */ virtual int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) = 0; @@ -476,6 +515,11 @@ public: */ virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) = 0; + /** + * start native process for debugger. + * + * @param want param to start a process. + */ virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) = 0; /** @@ -673,6 +717,12 @@ public: */ virtual int32_t UpdateRenderState(pid_t renderPid, int32_t state) = 0; + /** + * @brief mark a process which is going restart. + * @param bundleName the bundleName of the process. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t SignRestartAppFlag(const std::string &bundleName) { return 0; @@ -694,7 +744,7 @@ public: * If specified pid mismatch UIExtensionAbility type, return empty vector. * @param pid Process id. * @param hostPids All host process id. - * @return Returns 0 on success, others on failure. + * @return Returns ERR_OK on success, others on failure. */ virtual int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector &hostPids) { @@ -706,7 +756,7 @@ public: * If specified hostPid didn't start any UIExtensionAbility, return empty vector. * @param hostPid Host process id. * @param providerPids All provider process id started by specified hostPid. - * @return Returns 0 on success, others on failure. + * @return Returns ERR_OK on success, others on failure. */ virtual int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector &providerPids) { @@ -714,17 +764,20 @@ public: } /** - * @brief Notify memory size state changed to sufficient or insufficent. - * @param isMemorySizeSufficent Indicates the memory size state. + * @brief Notify memory size state changed to sufficient or insufficient. + * @param isMemorySizeSufficient Indicates the memory size state. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) + virtual int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) { return 0; } + /** + * @brief set support process cache by self + */ virtual int32_t SetSupportedProcessCacheSelf(bool isSupport) = 0; - + virtual int32_t SetSupportedProcessCache(int32_t pid, bool isSupport) = 0; /** @@ -744,6 +797,9 @@ public: virtual int32_t StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, const sptr &callback) = 0; + /** + * set browser channel for caller + */ virtual void SaveBrowserChannel(sptr browser) = 0; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index cae03fc441..c016732a40 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -137,10 +137,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, @@ -309,6 +309,13 @@ public: virtual int FinishUserTest( const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; + /** + * Schedule accept want done. + * + * @param recordId Application record. + * @param want Want. + * @param flag flag get from OnAcceptWant. + */ virtual void ScheduleAcceptWantDone( const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; @@ -334,10 +341,10 @@ public: /** * Start nweb render process, called by nweb host. * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param crashFd, crash signal file descriptior. + * @param renderParam, params passed to renderProcess. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. * @param renderPid, created render pid. * @param isGPU, is or not GPU process * @return Returns ERR_OK on success, others on failure. @@ -396,8 +403,21 @@ public: virtual int32_t UnregisterConfigurationObserver(const sptr &observer) override; + /** + * @brief Get the running state of application by bundle name. + * + * @param bundleName Bundle name + * @return Returns true if process is running, false if process isn't running. + */ bool GetAppRunningStateByBundleName(const std::string &bundleName) override; + /** + * @brief Notify application load patch. + * + * @param bundleName Bundle name + * @param callback called when LoadPatch finished. + * @return Returns ERR_OK on success, error code on failure. + */ int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) override; @@ -417,6 +437,11 @@ public: */ virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override; + /** + * start native process for debugger. + * + * @param want param to start a process. + */ virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override; /** @@ -603,8 +628,20 @@ public: */ virtual int32_t UpdateRenderState(pid_t renderPid, int32_t state) override; + /** + * @brief mark a process which is going restart. + * @param bundleName the bundleName of the process. + * + * @return Returns ERR_OK on success, others on failure. + */ int32_t SignRestartAppFlag(const std::string &bundleName) override; + /** + * Get appRunningUniqueId by pid. + * @param pid pid. + * @param appRunningUniqueId appRunningUniqueId. + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId) override; /* @@ -626,11 +663,11 @@ public: int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector &providerPids) override; /** - * @brief Notify memory size state changed to sufficient or insufficent. - * @param isMemorySizeSufficent Indicates the memory size state. + * @brief Notify memory size state changed to sufficient or insufficient. + * @param isMemorySizeSufficient Indicates the memory size state. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) override; + virtual int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) override; /** * Set application assertion pause state. @@ -639,10 +676,16 @@ public: */ void SetAppAssertionPauseState(bool flag) override; + /** + * @brief set support process cache by self + */ int32_t SetSupportedProcessCacheSelf(bool isSupport) override; int32_t SetSupportedProcessCache(int32_t pid, bool isSupport) override; + /** + * set browser channel for caller + */ virtual void SaveBrowserChannel(sptr browser) override; /** @@ -663,10 +706,19 @@ public: int32_t StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, const sptr &callback) override; + /** + * Notify that the process depends on web by itself. + */ virtual int32_t NotifyProcessDependedOnWeb() override; + /** + * Kill process depended on web by sa. + */ virtual void KillProcessDependedOnWeb() override; + /** + * Restart resident process depended on web. + */ virtual void RestartResidentProcessDependedOnWeb() override; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index 3fe83c0cdb..71176612d9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -134,6 +134,14 @@ public: */ virtual void ScheduleAbilityStage(const HapModuleInfo &) = 0; + /** + * Notify application to launch ability. + * + * @param ability The ability info. + * @param token The ability token. + * @param want The want to start the ability. + * @param token The ability token. + */ virtual void ScheduleLaunchAbility(const AbilityInfo &, const sptr &, const std::shared_ptr &want, int32_t abilityRecordId) = 0; @@ -172,8 +180,19 @@ public: */ virtual void ScheduleProcessSecurityExit() = 0; + /** + * scheduleClearPageStack, call scheduleClearPageStack() through proxy project, + * Notify application clear recovery page stack. + * + */ virtual void ScheduleClearPageStack() = 0; + /** + * @brief Schedule the given module the onAcceptWant lifecycle call. + * + * @param want the param passed to onAcceptWant lifecycle. + * @param want the moduleName of which being scheduled. + */ virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) = 0; virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) = 0; @@ -183,6 +202,7 @@ public: * * @param bundleName Bundle name * @param callback called when LoadPatch finished. + * @param recordId callback data * @return Returns 0 on success, error code on failure. */ virtual int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, @@ -192,6 +212,7 @@ public: * @brief Notify application reload page. * * @param callback called when HotReload finished. + * @param recordId callback data * @return Returns 0 on success, error code on failure. */ virtual int32_t ScheduleNotifyHotReloadPage(const sptr &callback, const int32_t recordId) = 0; @@ -201,6 +222,7 @@ public: * * @param bundleName Bundle name * @param callback called when UnloadPatch finished. + * @param recordId callback data * @return Returns 0 on success, error code on failure. */ virtual int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, @@ -264,6 +286,11 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) = 0; + /** + * + * @brief Notify application to prepare for process caching. + * + */ virtual void ScheduleCacheProcess() = 0; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index d05892069e..ed481f8222 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -173,25 +173,80 @@ public: */ virtual void ScheduleProcessSecurityExit() override; + /** + * scheduleClearPageStack, call scheduleClearPageStack() through proxy project, + * Notify application clear recovery page stack. + * + */ virtual void ScheduleClearPageStack() override; + /** + * @brief Schedule the given module the onAcceptWant lifecycle call. + * + * @param want the param passed to onAcceptWant lifecycle. + * @param want the moduleName of which being scheduled. + */ virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override; + /** + * @brief Notify application load patch. + * + * @param bundleName Bundle name + * @param callback called when LoadPatch finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback, const int32_t recordId) override; + /** + * @brief Notify application reload page. + * + * @param callback called when HotReload finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t ScheduleNotifyHotReloadPage(const sptr &callback, const int32_t recordId) override; + /** + * @brief Notify application unload patch. + * + * @param bundleName Bundle name + * @param callback called when UnloadPatch finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback, const int32_t recordId) override; + /** + * @brief Schedule Notify App Fault Data. + * + * @param faultData fault data + * @return Returns ERR_OK on success, error code on failure. + */ int32_t ScheduleNotifyAppFault(const FaultData &faultData) override; + /** + * @brief Notify NativeEngine GC of status change. + * + * @param state GC state + * @param pid pid + * + * @return Is the status change completed. + */ virtual int32_t ScheduleChangeAppGcState(int32_t state) override; + /** + * @brief Attach app debug. + */ void AttachAppDebug() override; + + /** + * @brief Detach app debug. + */ void DetachAppDebug() override; /** @@ -224,6 +279,9 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) override; + /** + * @brief Notify application to prepare for process caching. + */ virtual void ScheduleCacheProcess() override; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h index 8347143e64..3ddf984b05 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/application_state_observer_proxy.h @@ -100,6 +100,11 @@ public: */ virtual void OnAppStateChanged(const AppStateData &appStateData) override; + /** + * Called when one process is reused. + * + * @param processData Process data. + */ virtual void OnProcessReused(const ProcessData &processData) override; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h b/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h index b65fd55126..71a415efb0 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h +++ b/interfaces/inner_api/app_manager/include/appmgr/iapplication_state_observer.h @@ -101,6 +101,11 @@ public: */ virtual void OnAppStateChanged(const AppStateData &appStateData) {} + /** + * Called when one process is reused. + * + * @param processData Process data. + */ virtual void OnProcessReused(const ProcessData &processData) {} /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/irender_scheduler.h b/interfaces/inner_api/app_manager/include/appmgr/irender_scheduler.h index 35c114587a..9e22fc9d83 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/irender_scheduler.h +++ b/interfaces/inner_api/app_manager/include/appmgr/irender_scheduler.h @@ -31,9 +31,9 @@ public: /** * Notify Browser's fd to render process. * - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param crashFd, crash signal file descriptior. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. */ virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd, int32_t crashFd, sptr browser) = 0; diff --git a/interfaces/inner_api/app_manager/include/appmgr/irender_state_observer.h b/interfaces/inner_api/app_manager/include/appmgr/irender_state_observer.h index 8095479678..e1c64c8d34 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/irender_state_observer.h +++ b/interfaces/inner_api/app_manager/include/appmgr/irender_state_observer.h @@ -25,6 +25,11 @@ class IRenderStateObserver : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IRenderStateObserver"); + /** + * Called when one render process's state changes. + * + * @param renderStateData retrieved state data. + */ virtual void OnRenderStateChanged(const RenderStateData &renderStateData) = 0; enum { diff --git a/interfaces/inner_api/app_manager/include/appmgr/istart_specified_ability_response.h b/interfaces/inner_api/app_manager/include/appmgr/istart_specified_ability_response.h index a8327e41f4..0a36cea2a7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/istart_specified_ability_response.h +++ b/interfaces/inner_api/app_manager/include/appmgr/istart_specified_ability_response.h @@ -26,8 +26,19 @@ class IStartSpecifiedAbilityResponse : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.startSpecifiedAbilityResponse"); + /** + * @brief called when the module's onAcceptWant done to notify ability mgr to continue + * @param want request param being accepted + * @param flag specified flag return by application + * @param requestId a number represents a request + */ virtual void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag, int32_t requestId) = 0; + /** + * @brief called when the module's onAcceptWant happens time out + * @param want request param + * @param requestId a number represents a request + */ virtual void OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId) = 0; virtual void OnNewProcessRequestResponse(const AAFwk::Want &want, const std::string &flag, diff --git a/interfaces/inner_api/app_manager/include/appmgr/render_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/render_scheduler_proxy.h index 5465ad97b8..46204b5b45 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/render_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/render_scheduler_proxy.h @@ -35,9 +35,9 @@ public: /** * Notify Browser's fd to render process. * - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param crashFd, crash signal file descriptior. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. */ virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd, int32_t crashFd, sptr browser) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/render_state_observer_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/render_state_observer_proxy.h index d34302df03..024f708222 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/render_state_observer_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/render_state_observer_proxy.h @@ -26,6 +26,11 @@ public: explicit RenderStateObserverProxy(const sptr &impl); virtual ~RenderStateObserverProxy() = default; + /** + * Called when one render process's state changes. + * + * @param renderStateData retrieved state data. + */ virtual void OnRenderStateChanged(const RenderStateData &renderStateData) override; private: bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/inner_api/app_manager/include/appmgr/start_specified_ability_response_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/start_specified_ability_response_proxy.h index c9b72bfe99..b62cea6940 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/start_specified_ability_response_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/start_specified_ability_response_proxy.h @@ -25,9 +25,20 @@ public: explicit StartSpecifiedAbilityResponseProxy(const sptr &impl); virtual ~StartSpecifiedAbilityResponseProxy() = default; + /** + * @brief called when the module's onAcceptWant done to notify ability mgr to continue + * @param want request param being accepted + * @param flag specified flag return by application + * @param requestId a number represents a request + */ virtual void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag, int32_t requestId) override; + /** + * @brief called when the module's onAcceptWant happens time out + * @param want request param + * @param requestId a number represents a request + */ virtual void OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId) override; virtual void OnNewProcessRequestResponse(const AAFwk::Want &want, const std::string &flag, diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 0424fd2884..36c73d925b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -1197,14 +1197,14 @@ int32_t AppMgrClient::GetAllUIExtensionProviderPid(pid_t hostPid, std::vectorGetAllUIExtensionProviderPid(hostPid, providerPids); } -int32_t AppMgrClient::NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) +int32_t AppMgrClient::NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } - return service->NotifyMemorySizeStateChanged(isMemorySizeSufficent); + return service->NotifyMemorySizeStateChanged(isMemorySizeSufficient); } bool AppMgrClient::IsMemorySizeSufficent() const diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index c004d04055..29bd162e0b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -1826,13 +1826,13 @@ int32_t AppMgrProxy::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector { @@ -491,15 +487,6 @@ protected: std::mutex notifyForegroundLock_; private: - typedef enum { - START, - INACTIVE, - ACTIVE, - BACKGROUND, - FOREGROUND, - STOP, - } Action; - std::shared_ptr applicationImpl_; std::shared_ptr contextDeal_; bool hasSaveData_ = false; diff --git a/interfaces/kits/native/ability/native/ability_local_record.h b/interfaces/kits/native/ability/native/ability_local_record.h index 0689b7c430..e9af2de92a 100644 --- a/interfaces/kits/native/ability/native/ability_local_record.h +++ b/interfaces/kits/native/ability/native/ability_local_record.h @@ -19,16 +19,13 @@ #include #include "iremote_object.h" -#include "event_runner.h" #include "ability_info.h" -#include "application_info.h" #include "refbase.h" #include "want.h" namespace OHOS { namespace AppExecFwk { class AbilityThread; -class AbilityImpl; class AbilityLocalRecord { public: /** @@ -36,7 +33,8 @@ public: * default constructor * */ - AbilityLocalRecord(const std::shared_ptr &info, const sptr &token); + AbilityLocalRecord(const std::shared_ptr &info, const sptr &token, + const std::shared_ptr &want, int32_t abilityRecordId); /** * @@ -52,48 +50,13 @@ public: */ const std::shared_ptr &GetAbilityInfo(); - /** - * @description: Get an EventHandler in an ability. - * - * @return Returns a pointer to EventHandler - */ - const std::shared_ptr &GetEventHandler(); - - /** - * @description: Set an EventHandler in an ability. - * @param handler EventHandler object - * @return None. - */ - void SetEventHandler(const std::shared_ptr &handler); - - /** - * @description: Get an EventRunner in an ability. - * - * @return Returns a pointer to EventRunner - */ - const std::shared_ptr &GetEventRunner(); - - /** - * @description: Set an EventRunner in an ability. - * @param runner EventHandler object - * @return None. - */ - void SetEventRunner(const std::shared_ptr &runner); - /** * @description: Gets the identity of the ability * @return return the identity of the ability. */ const sptr &GetToken(); - int32_t GetAbilityRecordId() const - { - return abilityRecordId_; - } - void SetAbilityRecordId(int32_t abilityRecordId) - { - abilityRecordId_ = abilityRecordId; - } + int32_t GetAbilityRecordId() const; /** * @description: Obtains the information based on ability thread. @@ -113,14 +76,11 @@ public: const std::shared_ptr &GetWant(); private: std::shared_ptr abilityInfo_ = nullptr; - sptr token_; - int32_t abilityRecordId_ = 0; - std::shared_ptr runner_ = nullptr; - std::shared_ptr handler_ = nullptr; - std::shared_ptr abilityImpl_ = nullptr; // store abilityImpl - sptr abilityThread_; + sptr token_ = nullptr; std::shared_ptr want_ = nullptr; + int32_t abilityRecordId_ = 0; + sptr abilityThread_; }; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_ABILITY_LOCAL_RECORD_H +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_LOCAL_RECORD_H diff --git a/interfaces/kits/native/ability/native/ability_thread.h b/interfaces/kits/native/ability/native/ability_thread.h index b1c5f293be..3ad1873200 100644 --- a/interfaces/kits/native/ability/native/ability_thread.h +++ b/interfaces/kits/native/ability/native/ability_thread.h @@ -18,6 +18,7 @@ #include "ability_scheduler_stub.h" #include "context.h" +#include "event_runner.h" #include "ohos_application.h" namespace OHOS { diff --git a/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_register_manager.h b/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_register_manager.h index 061940f533..2a1b11c1f9 100644 --- a/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_register_manager.h +++ b/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_register_manager.h @@ -51,7 +51,7 @@ public: * notify continuation status to controlcenter continuation register service. * * @param token token from register. - * @param deviceId deviceid. + * @param deviceId deviceId. * @param status device status. * @param requestCallback callback for this request, -1 means failed, otherwise successed. */ diff --git a/interfaces/kits/native/ability/native/continuation/remote_register_service/remote_register_service_proxy.h b/interfaces/kits/native/ability/native/continuation/remote_register_service/remote_register_service_proxy.h index efdce3edec..33a2d3c395 100644 --- a/interfaces/kits/native/ability/native/continuation/remote_register_service/remote_register_service_proxy.h +++ b/interfaces/kits/native/ability/native/continuation/remote_register_service/remote_register_service_proxy.h @@ -51,7 +51,7 @@ public: * notify continuation status to controlcenter continuation register service. * * @param registerToken token from register. - * @param deviceId deviceid. + * @param deviceId deviceId. * @param status device status. */ virtual bool UpdateConnectStatus(int registerToken, const std::string &deviceId, int status) override; diff --git a/interfaces/kits/native/ability/native/new_ability_impl.h b/interfaces/kits/native/ability/native/new_ability_impl.h index d445102f2a..50013b54dc 100644 --- a/interfaces/kits/native/ability/native/new_ability_impl.h +++ b/interfaces/kits/native/ability/native/new_ability_impl.h @@ -20,10 +20,6 @@ namespace OHOS { namespace AppExecFwk { -class Ability; -class AbilityHandler; -class AbilityLocalRecord; -class AbilityImpl; class NewAbilityImpl final : public AbilityImpl { public: /** diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index c0fadbc03c..e0ca6ad6d1 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -41,6 +41,7 @@ public: ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, HapModuleInfo &hapModuleInfo); bool GetBundleInfo(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId); + std::string GetAppIdByBundleName(const std::string &bundleName, const int32_t userId); bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo); std::string GetAbilityLabel(const std::string &bundleName, const std::string &abilityName); std::string GetAppType(const std::string &bundleName); diff --git a/interfaces/kits/native/appkit/app/ability_record_mgr.h b/interfaces/kits/native/appkit/app/ability_record_mgr.h index 14e9f575e2..99fc3d1cc2 100644 --- a/interfaces/kits/native/appkit/app/ability_record_mgr.h +++ b/interfaces/kits/native/appkit/app/ability_record_mgr.h @@ -28,14 +28,6 @@ public: AbilityRecordMgr() = default; ~AbilityRecordMgr() = default; - /** - * @brief Set the eventRunner of abilitythread to the AbilityRecordMgr. - * - * @param eventRunner The runner of the abilitythread. - * - */ - void SetEventRunner(const std::shared_ptr &eventRunner); - /** * @brief Get the token witch is set to the AbilityRecordMgr. * diff --git a/interfaces/kits/native/appkit/app/application_cleaner.h b/interfaces/kits/native/appkit/app/application_cleaner.h index 204db2febc..431e713d9a 100644 --- a/interfaces/kits/native/appkit/app/application_cleaner.h +++ b/interfaces/kits/native/appkit/app/application_cleaner.h @@ -42,7 +42,7 @@ private: int GetObsoleteBundleTempPath(const std::vector &rootPath, std::vector &tempPath); bool RemoveDir(const std::string &tempPath); void TraverseObsoleteTempDirectory(const std::string ¤tPath, std::vector &tempDirs); - bool CheckFileSize(const std::vector bundlePath, const int64_t maxFileSize); + bool CheckFileSize(const std::vector &bundlePath); private: std::shared_ptr context_ = nullptr; diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 79e1694134..94582d35fa 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -674,7 +674,7 @@ private: void LoadAceAbilityLibrary(); void CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); - void LoadNativeLiabrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); + void LoadNativeLibrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); void LoadAppDetailAbilityLibrary(std::string &nativeLibraryPath); diff --git a/service_router_framework/services/srms/BUILD.gn b/service_router_framework/services/srms/BUILD.gn index 0d6c194c11..d5689fb71a 100755 --- a/service_router_framework/services/srms/BUILD.gn +++ b/service_router_framework/services/srms/BUILD.gn @@ -63,14 +63,12 @@ ohos_shared_library("libsrms") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", - # "graphic_2d:2d_graphics", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", "os_account:os_account_innerkits", "safwk:system_ability_fwk", "samgr:samgr_proxy", - # "skia:skia_canvaskit", ] defines = [ "ACCOUNT_ENABLE" ] diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 83ebed2a54..8cd3fa6682 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -33,6 +33,7 @@ config("abilityms_config") { "include/", "include/data_ability", "include/dialog_session/", + "include/mission/", "include/rdb/", "include/screen_lock/", "include/utils/", @@ -111,6 +112,7 @@ ohos_shared_library("abilityms") { include_dirs = [ "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_service_extension_ability/connection", + "${ability_runtime_services_path}/abilitymgr/include/mission", ] deps = [ ":wantagent_manager", @@ -156,7 +158,6 @@ ohos_shared_library("abilityms") { "dsoftbus:softbus_client", "eventhandler:libeventhandler", "ffrt:libffrt", - # "graphic_2d:color_manager", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", @@ -171,7 +172,6 @@ ohos_shared_library("abilityms") { "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", - # "resource_management:global_resmgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libmodal_system_ui_extension_client", @@ -337,6 +337,7 @@ ohos_shared_library("mission_list") { "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_services_path}/abilitymgr/data_ability/include", "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_services_path}/abilitymgr/include/mission", "${ability_runtime_services_path}/common/include", "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_utils_path}/global/constant", @@ -362,11 +363,11 @@ ohos_shared_library("mission_list") { } sources = [ - "src/mission.cpp", - "src/mission_data_storage.cpp", - "src/mission_info_mgr.cpp", - "src/mission_list.cpp", - "src/mission_list_manager.cpp", + "src/mission/mission.cpp", + "src/mission/mission_data_storage.cpp", + "src/mission/mission_info_mgr.cpp", + "src/mission/mission_list.cpp", + "src/mission/mission_list_manager.cpp", "src/task_data_persistence_mgr.cpp", ] diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 8575f56356..306ffc829c 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -85,8 +85,8 @@ abilityms_files = [ "src/call_container.cpp", "src/call_record.cpp", "src/inner_mission_info.cpp", - "src/mission_listener_controller.cpp", - "src/mission_listener_proxy.cpp", + "src/mission/mission_listener_controller.cpp", + "src/mission/mission_listener_proxy.cpp", "src/rdb/ability_resident_process_rdb.cpp", "src/rdb/parser_util.cpp", "src/rdb/rdb_data_manager.cpp", diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index d707b6ccfc..d59c1c9579 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -69,7 +69,7 @@ public: * @param abilityRequest, the request of the service ability to start. * @return Returns ERR_OK on success, others on failure. */ - int StartAbility(const AbilityRequest &abilityRequest); + int32_t StartAbility(const AbilityRequest &abilityRequest); /** * TerminateAbility with token and result want. @@ -97,7 +97,7 @@ public: * @param connectInfo the connect info. * @return Returns ERR_OK on success, others on failure. */ - int ConnectAbilityLocked(const AbilityRequest &abilityRequest, const sptr &connect, + int32_t ConnectAbilityLocked(const AbilityRequest &abilityRequest, const sptr &connect, const sptr &callerToken, sptr sessionInfo = nullptr, sptr connectInfo = nullptr); @@ -207,12 +207,12 @@ public: AbilityCommand abilityCmd); /** - * GetUIExtensioBySessionInfo. + * GetUIExtensionBySessionInfo. * * @param sessionToken, service ability's session token. * @return Returns AbilityRecord shared_ptr. */ - std::shared_ptr GetUIExtensioBySessionInfo(const sptr &sessionInfo); + std::shared_ptr GetUIExtensionBySessionInfo(const sptr &sessionInfo); std::shared_ptr GetExtensionByTokenFromServiceMap(const sptr &token); std::shared_ptr GetExtensionByTokenFromAbilityCache(const sptr &token); @@ -340,7 +340,7 @@ private: * @param abilityRequest, the request of the service ability to start. * @return Returns ERR_OK on success, others on failure. */ - int StartAbilityLocked(const AbilityRequest &abilityRequest); + int32_t StartAbilityLocked(const AbilityRequest &abilityRequest); /** * TerminateAbilityLocked with token and result want. @@ -577,7 +577,7 @@ private: void HandleUIExtWindowDiedTask(const sptr &remote); /** - * Post an extension's disconnect task, auto disconnect when extension conected timeout. + * Post an extension's disconnect task, auto disconnect when extension connected timeout. */ void PostExtensionDelayDisconnectTask(const std::shared_ptr &connectRecord); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index f7f546420d..51321dae55 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -255,7 +255,7 @@ public: * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartExtensionAbility( + virtual int32_t StartExtensionAbility( const Want &want, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, @@ -695,26 +695,84 @@ public: virtual void SetLockedState(int32_t sessionId, bool lockedState) override; + /** + * @brief Register mission listener to ability mgr. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterMissionListener(const sptr &listener) override; + /** + * @brief UnRegister mission listener from ability mgr. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int UnRegisterMissionListener(const sptr &listener) override; + /** + * @brief Get mission infos from ability mgr. + * @param deviceId local or remote deviceId. + * @param numMax max number of missions. + * @param missionInfos mission info result. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax, std::vector &missionInfos) override; + /** + * @brief Get mission info by id. + * @param deviceId local or remote deviceId. + * @param missionId Id of target mission. + * @param missionInfo mission info of target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfos) override; + /** + * @brief Clean mission by id. + * @param missionId Id of target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int CleanMission(int32_t missionId) override; + /** + * @brief Clean all missions in system. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int CleanAllMissions() override; virtual int MoveMissionToFront(int32_t missionId) override; + /** + * @brief Move a mission to front. + * @param missionId Id of target mission. + * @param startOptions Special startOptions for target mission. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; + /** + * Move missions to front + * @param missionIds Ids of target missions + * @param topMissionId Indicate which mission will be moved to top, if set to -1, missions' order won't change + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionsToForeground(const std::vector& missionIds, int32_t topMissionId) override; + /** + * Move missions to background + * @param missionIds Ids of target missions + * @param result The result of move missions to background, and the array is sorted by zOrder + * @return Returns ERR_OK on success, others on failure. + */ virtual int MoveMissionsToBackground(const std::vector& missionIds, std::vector& result) override; @@ -747,10 +805,29 @@ public: virtual int ReleaseCall( const sptr &connect, const AppExecFwk::ElementName &element) override; + /** + * @brief start user. + * @param accountId accountId. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StartUser(int userId, sptr callback) override; + /** + * @brief stop user. + * @param accountId accountId. + * @param callback callback. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StopUser(int userId, const sptr &callback) override; + /** + * @brief logout user. + * @param accountId accountId. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int LogoutUser(int32_t userId) override; virtual int SetMissionContinueState(const sptr &token, const AAFwk::ContinueState &state) override; @@ -781,13 +858,38 @@ public: virtual int UnregisterAbilityFirstFrameStateObserver( const sptr &observer) override; #endif - + /** + * @brief Get the ability running information. + * + * @param info Ability running information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetAbilityRunningInfos(std::vector &info) override; + /** + * @brief Get the extension running information. + * + * @param upperLimit The maximum limit of information wish to get. + * @param info Extension running information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetExtensionRunningInfos(int upperLimit, std::vector &info) override; + /** + * @brief Get running process information. + * + * @param info Running process information. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetProcessRunningInfos(std::vector &info) override; + /** + * @brief Register mission listener to ability manager service. + * @param deviceId The remote device Id. + * @param listener The handler of listener. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterMissionListener(const std::string &deviceId, const sptr &listener) override; @@ -816,13 +918,41 @@ public: */ virtual bool IsRunningInStabilityTest() override; + /** + * @brief Register the snapshot handler + * @param handler snapshot handler + * @return ErrCode Returns ERR_OK on success, others on failure. + */ virtual int RegisterSnapshotHandler(const sptr& handler) override; + /** + * @brief Get the Mission Snapshot Info object + * @param deviceId local or remote deviceId. + * @param missionId Id of target mission. + * @param snapshot snapshot of target mission. + * @param isLowResolution get low resolution snapshot. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot, bool isLowResolution) override; + /** + * @brief start user test. + * @param want the want of the ability user test to start. + * @param observer test observer callback. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int StartUserTest(const Want &want, const sptr &observer) override; + /** + * @brief Finish user test. + * @param msg user test message. + * @param resultCode user test result Code. + * @param bundleName user test bundleName. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int FinishUserTest( const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; @@ -929,6 +1059,11 @@ public: virtual void ScheduleRecoverAbility(const sptr &token, int32_t reason, const Want *want = nullptr) override; + /** + * @brief Schedule clear recovery page stack. + * + * @param bundleName application bundleName. + */ virtual void ScheduleClearRecoveryPageStack() override; /** @@ -1086,10 +1221,17 @@ public: * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb. * * @param sessionInfo the session info of the ability to start. - * @param isPrepareTerminate the result of ability onPrepareToTermiante. + * @param isPrepareTerminate the result of ability onPrepareToTerminate. * @return Returns ERR_OK on success, others on failure. */ virtual int PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isPrepareTerminate) override; + + /** + * @brief Register session handler. + * @param object The handler. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int RegisterSessionHandler(const sptr &object) override; /** @@ -1347,6 +1489,16 @@ public: */ virtual int32_t BlockAllAppStart(bool flag) override; + /** + * update associate config list by rss. + * + * @param configs The rss config info. + * @param exportConfigs The rss export config info. + * @param flag UPDATE_CONFIG_FLAG_COVER is cover config, UPDATE_CONFIG_FLAG_APPEND is append config. + */ + virtual int32_t UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); @@ -1357,6 +1509,8 @@ private: MessageOption& option); int CheckUISessionParams(MessageParcel &data, const sptr &callerToken, const sptr &sessionInfo, int32_t userId, int requestCode); + bool UpdateAssociateConfigInner(const std::map>& configs, + MessageParcel& data); private: static inline BrokerDelegator delegator_; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 9ced8c4761..9b1b69e6ed 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -85,7 +85,6 @@ constexpr int32_t U0_USER_ID = 0; constexpr int32_t INVALID_USER_ID = -1; constexpr const char* KEY_SESSION_ID = "com.ohos.param.sessionId"; using OHOS::AppExecFwk::IAbilityController; -class PendingWantManager; struct StartAbilityInfo; class WindowFocusChangedListener; @@ -400,14 +399,14 @@ public: * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartExtensionAbility( + virtual int32_t StartExtensionAbility( const Want &want, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; /** - * Requset modal UIExtension with want, send want to ability manager service. + * Request modal UIExtension with want, send want to ability manager service. * * @param want, the want contains ability info about caller and called. * @return Returns ERR_OK on success, others on failure. @@ -583,13 +582,13 @@ public: * @param userId, Designation User ID. * @return Returns ERR_OK on success, others on failure. */ - virtual int ConnectAbility( + virtual int32_t ConnectAbility( const Want &want, const sptr &connect, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE) override; - virtual int ConnectAbilityCommon( + virtual int32_t ConnectAbilityCommon( const Want &want, const sptr &connect, const sptr &callerToken, @@ -653,7 +652,7 @@ public: /** * NotifyCompleteContinuation, notify continuation complete to dms. * @param deviceId, source device which start a continuation. - * @param sessionId, represent a continuaion. + * @param sessionId, represent a continuation. * @param isSuccess, continuation result. * @return */ @@ -1032,7 +1031,7 @@ public: bool isImplicit = false, bool isUIAbilityOnly = false); - int StartExtensionAbilityInner( + int32_t StartExtensionAbilityInner( const Want &want, const sptr &callerToken, int32_t userId, @@ -1558,7 +1557,7 @@ public: * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb. * * @param sessionInfo the session info of the ability to start. - * @param isTerminate the result of ability onPrepareToTermiante. + * @param isTerminate the result of ability onPrepareToTerminate. * @return Returns ERR_OK on success, others on failure. */ virtual int PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) override; @@ -1787,6 +1786,9 @@ public: int32_t TerminateMission(int32_t missionId) override; + int32_t UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) override; + int32_t BlockAllAppStart(bool flag) override; int32_t StartUIAbilityBySCBDefaultCommon(AbilityRequest &abilityRequest, sptr sessionInfo, @@ -1838,8 +1840,17 @@ protected: void NotifyStartResidentProcess(std::vector &bundleInfos) override; + /** + * @brief Notify abilityms app process pre cache + * @param pid process pid. + * @param userId userId Designation User ID. + */ void NotifyAppPreCache(int32_t pid, int32_t userId) override; + /** + * @brief Notify abilityms app process OnRemoteDied + * @param abilityTokens abilities in died process. + */ void OnAppRemoteDied(const std::vector> &abilityTokens) override; private: @@ -1862,7 +1873,7 @@ private: */ void StartHighestPriorityAbility(int32_t userId, bool isBoot); /** - * connet bms. + * connect bms. * */ void ConnectBmsService(); @@ -1888,7 +1899,7 @@ private: int32_t PreStartInner(const FreeInstallInfo& taskInfo); void RemovePreStartSession(const std::string& sessionId); - int ConnectLocalAbility( + int32_t ConnectLocalAbility( const Want &want, const int32_t userId, const sptr &connect, @@ -1928,7 +1939,7 @@ private: int StartRemoteAbilityByCall(const Want &want, const sptr &callerToken, const sptr &connect); int ReleaseRemoteAbility(const sptr &connect, const AppExecFwk::ElementName &element); - void ForceTerminateSerivceExtensionByPid(int32_t pid, int32_t userId); + void ForceTerminateServiceExtensionByPid(int32_t pid, int32_t userId); void DumpInner(const std::string &args, std::vector &info); void DumpMissionInner(const std::string &args, std::vector &info); @@ -2284,16 +2295,16 @@ private: void ReportCleanSession(const sptr &sessionInfo, const std::shared_ptr &abilityRecord, int32_t errCode); - + void SendStartAbilityOtherExtensionEvent(const AppExecFwk::AbilityInfo& abilityInfo, const Want& want, uint32_t specifyTokenId); - + void SetMinimizedDuringFreeInstall(const sptr& sessionInfo); /** * @brief Check debug app in developer mode. * @param applicationInfo. The application info. - * @return Returns ture or false. + * @return Returns true or false. */ bool CheckDebugAppNotInDeveloperMode(const AppExecFwk::ApplicationInfo &applicationInfo); @@ -2305,7 +2316,6 @@ private: void ShowDeveloperModeDialog(const std::string &bundleName, const std::string &abilityName); constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; - constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; std::shared_ptr taskHandler_; std::shared_ptr eventHandler_; @@ -2359,6 +2369,7 @@ private: std::shared_ptr abilityAutoStartupService_; + std::mutex whiteListMutex_; std::map> whiteListMap_; std::list exportWhiteList_; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 334976eb52..d29110c3d8 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -350,6 +350,7 @@ private: int32_t OpenLinkInner(MessageParcel &data, MessageParcel &reply); int32_t TerminateMissionInner(MessageParcel &data, MessageParcel &reply); int32_t BlockAllAppStartInner(MessageParcel &data, MessageParcel &reply); + int32_t UpdateAssociateConfigListInner(MessageParcel &data, MessageParcel &reply); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index cd71034999..1c8216e117 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -596,10 +596,12 @@ public: bool GrantUriPermissionForServiceExtension(); + bool GrantUriPermissionForUIExtension(); + /** * check whether the ability is launcher. * - * @return true : lanucher ,false: not lanucher + * @return true : launcher ,false: not launcher */ bool IsLauncherAbility() const; @@ -921,7 +923,7 @@ public: void DumpService(std::vector &info, std::vector ¶ms, bool isClient = false) const; /** - * set aconnect remote object. + * set connect remote object. * */ void SetConnRemoteObject(const sptr &remoteObject); @@ -1159,8 +1161,6 @@ private: void DumpUIExtensionPid(std::vector &info, bool isUIExtension) const; - bool GetUriListFromWant(Want &want, std::vector &uriVec); - void PublishFileOpenEvent(const Want &want); void SetDebugAppByWaitingDebugFlag(); @@ -1194,7 +1194,7 @@ private: void StartingWindowTask(bool isRecent, bool isCold, const AbilityRequest &abilityRequest, std::shared_ptr &startOptions); - void StartingWindowColdTask(bool isRecnet, const AbilityRequest &abilityRequest, + void StartingWindowColdTask(bool isRecent, const AbilityRequest &abilityRequest, std::shared_ptr &startOptions); void PostCancelStartingWindowColdTask(); void StartingWindowHot(const std::shared_ptr &startOptions, const std::shared_ptr &want, @@ -1242,14 +1242,14 @@ private: */ bool isAbilityForegrounding_ = false; - // service(ability) can be connected by multi-pages(abilites), so need to store this service's connections + // service(ability) can be connected by multi-pages(abilities), so need to store this service's connections mutable ffrt::mutex connRecordListMutex_; std::list> connRecordList_ = {}; // service(ability) onConnect() return proxy of service ability sptr connRemoteObject_ = {}; int startId_ = 0; // service(ability) start id - // page(ability) can be started by multi-pages(abilites), so need to store this ability's caller + // page(ability) can be started by multi-pages(abilities), so need to store this ability's caller std::list> callerList_ = {}; bool isUninstall_ = false; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 136df08fef..3d9f5ccf08 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -94,8 +94,17 @@ public: virtual void NotifyStartResidentProcess(std::vector &bundleInfos) {} + /** + * @brief Notify abilityms app process pre cache + * @param pid process pid. + * @param userId userId Designation User ID. + */ virtual void NotifyAppPreCache(int32_t pid, int32_t userId) {} + /** + * @brief Notify abilityms app process OnRemoteDied + * @param abilityTokens abilities in died process. + */ virtual void OnAppRemoteDied(const std::vector> &abilityTokens) {} }; @@ -197,8 +206,19 @@ public: */ void KillProcessesByUserId(int32_t userId); + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + */ void KillProcessesByPids(std::vector &pids); + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ void AttachPidToParent(const sptr &token, const sptr &callerToken); /** @@ -259,12 +279,36 @@ public: */ int UpdateApplicationInfoInstalled(const std::string &bundleName, const int32_t uid); + /** + * Ability attach timeout. If start ability encounter failure, attach timeout to terminate. + * + * @param token Ability identify. + */ void AttachTimeOut(const sptr &token); + /** + * Prepare terminate. + * + * @param token Ability identify. + * @param clearMissionFlag Clear mission flag. + */ void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); + /** + * Get running process information by ability token. + * + * @param token Ability identify. + * @param info Running process info. + */ void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info); + /** + * Get running process information by pid. + * + * @param pid process id. + * @param info Output parameters, return runningProcessInfo. + * @return Returns ERR_OK on success, others on failure. + */ void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const; /** @@ -280,10 +324,31 @@ public: */ void StartupResidentProcess(const std::vector &bundleInfos); + /** + * Start specified ability. + * + * @param want Want contains information of the ability to start. + * @param abilityInfo Ability information. + * @param requestId request id to callback + */ void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); + + /** + * @brief Get running process information. + * + * @param info Running process information. + * @return Returns ERR_OK on success, others on failure. + */ int GetProcessRunningInfos(std::vector &info); + /** + * Start specified process. + * + * @param want Want contains information wish to start. + * @param abilityInfo Ability information. + * @param requestId for callback + */ void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); @@ -303,6 +368,14 @@ public: */ int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName); + /** + * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project. + * Obtains information about application processes that are running on the device. + * + * @param info, app name in Application record. + * @param userId, user Id in Application record. + * @return ERR_OK ,return back success,others fail. + */ int GetProcessRunningInfosByUserId(std::vector &info, int32_t userId); std::string ConvertAppState(const AppState &state); @@ -314,6 +387,12 @@ public: */ int UpdateConfiguration(const AppExecFwk::Configuration &config); + /** + * GetConfiguration + * + * @param info to retrieve configuration data. + * @return ERR_OK ,return back success,others fail. + */ int GetConfiguration(AppExecFwk::Configuration &config); /** @@ -438,8 +517,8 @@ public: void ClearProcessByToken(sptr token) const; /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ virtual bool IsMemorySizeSufficent() const; @@ -450,6 +529,11 @@ public: */ void AttachedToStatusBar(const sptr &token); + /** + * Temporarily block the process cache feature. + * + * @param pids the pids of the processes that should be blocked. + */ void BlockProcessCacheByPids(const std::vector& pids); /** @@ -460,6 +544,12 @@ public: */ bool CleanAbilityByUserRequest(const sptr &token); + /** + * whether killed for upgrade web. + * + * @param bundleName the bundle name is killed for upgrade web. + * @return Returns true is killed for upgrade web, others return false. + */ bool IsKilledForUpgradeWeb(const std::string &bundleName); /** @@ -501,8 +591,17 @@ protected: */ 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; - + + /** + * @brief Notify abilityms app process pre cache + * @param pid process pid. + * @param userId userId Designation User ID. + */ virtual void NotifyAppPreCache(int32_t pid, int32_t userId) override; private: diff --git a/services/abilitymgr/include/lifecycle_deal.h b/services/abilitymgr/include/lifecycle_deal.h index b9e4077fcc..ceb2e4c13a 100644 --- a/services/abilitymgr/include/lifecycle_deal.h +++ b/services/abilitymgr/include/lifecycle_deal.h @@ -47,16 +47,37 @@ public: */ void Activate(const Want &want, LifeCycleStateInfo &stateInfo); void Inactivate(const Want &want, LifeCycleStateInfo &stateInfo, sptr sessionInfo = nullptr); + /** + * schedule ability life cycle to background + */ void MoveToBackground(const Want &want, LifeCycleStateInfo &stateInfo); + /** + * schedule ability onConnect + */ void ConnectAbility(const Want &want); + /** + * schedule ability onDisconnect + */ void DisconnectAbility(const Want &want); + /** + * schedule ability onDestroy + */ void Terminate(const Want &want, LifeCycleStateInfo &stateInfo, sptr sessionInfo = nullptr); + /** + * schedule ability onRequest + */ void CommandAbility(const Want &want, bool reStart, int startId); void CommandAbilityWindow(const Want &want, const sptr &sessionInfo, WindowCommand winCmd); void SaveAbilityState(); void RestoreAbilityState(const PacMap &inState); + /** + * schedule ability life cycle to foreground + */ void ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo, sptr sessionInfo = nullptr); + /** + * schedule ability life cycle to background + */ void BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo, sptr sessionInfo = nullptr); void ContinueAbility(const std::string& deviceId, uint32_t versionCode); diff --git a/services/abilitymgr/include/mission.h b/services/abilitymgr/include/mission/mission.h similarity index 100% rename from services/abilitymgr/include/mission.h rename to services/abilitymgr/include/mission/mission.h diff --git a/services/abilitymgr/include/mission_data_storage.h b/services/abilitymgr/include/mission/mission_data_storage.h similarity index 100% rename from services/abilitymgr/include/mission_data_storage.h rename to services/abilitymgr/include/mission/mission_data_storage.h diff --git a/services/abilitymgr/include/mission_info_mgr.h b/services/abilitymgr/include/mission/mission_info_mgr.h similarity index 100% rename from services/abilitymgr/include/mission_info_mgr.h rename to services/abilitymgr/include/mission/mission_info_mgr.h diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission/mission_list.h similarity index 100% rename from services/abilitymgr/include/mission_list.h rename to services/abilitymgr/include/mission/mission_list.h diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission/mission_list_manager.h similarity index 100% rename from services/abilitymgr/include/mission_list_manager.h rename to services/abilitymgr/include/mission/mission_list_manager.h diff --git a/services/abilitymgr/include/mission_list_manager_interface.h b/services/abilitymgr/include/mission/mission_list_manager_interface.h similarity index 100% rename from services/abilitymgr/include/mission_list_manager_interface.h rename to services/abilitymgr/include/mission/mission_list_manager_interface.h diff --git a/services/abilitymgr/include/mission_listener_controller.h b/services/abilitymgr/include/mission/mission_listener_controller.h similarity index 100% rename from services/abilitymgr/include/mission_listener_controller.h rename to services/abilitymgr/include/mission/mission_listener_controller.h diff --git a/services/abilitymgr/include/resident_process_manager.h b/services/abilitymgr/include/resident_process_manager.h index 0a91d6c9ba..dfa81fe9ea 100644 --- a/services/abilitymgr/include/resident_process_manager.h +++ b/services/abilitymgr/include/resident_process_manager.h @@ -66,12 +66,33 @@ public: * @return Returns ERR_OK on success, others on failure. */ int32_t SetResidentProcessEnabled(const std::string &bundleName, const std::string &callerName, bool updateEnable); + + /** + * start empty resident processes. + * + * @param bundleInfos bundles of resident processes. + */ void StartResidentProcess(const std::vector &bundleInfos); + /** + * If bundle has right main element, start the main element + */ void StartResidentProcessWithMainElement(std::vector &bundleInfos, int32_t userId); + /** + * Once one process created, query keepalive status from db and update then + */ void OnAppStateChanged(const AppInfo &info); + /** + * Before starting a resident element, store it. + */ int32_t PutResidentAbility(const std::string &bundleName, const std::string &abilityName, int32_t userId); bool IsResidentAbility(const std::string &bundleName, const std::string &abilityName, int32_t userId); + /** + * After a resident element being started, remove it + */ void RemoveResidentAbility(int32_t residentId); + /** + * query resident bundles for user + */ bool GetResidentBundleInfosForUser(std::vector &bundleInfos, int32_t userId); void StartFailedResidentAbilities(); private: diff --git a/services/abilitymgr/include/uri_utils.h b/services/abilitymgr/include/uri_utils.h index 0d470589d1..cca3bfdc06 100644 --- a/services/abilitymgr/include/uri_utils.h +++ b/services/abilitymgr/include/uri_utils.h @@ -37,6 +37,12 @@ public: std::vector GetPermissionedUriList(const std::vector &uriVec, const std::vector &checkResults, Want &want); + bool GetUriListFromWant(Want &want, std::vector &uriVec); + + bool IsGrantUriPermissionFlag(const Want &want); + + void CheckUriPermissionForServiceExtension(Want &want, AppExecFwk::ExtensionAbilityType extensionAbilityType); + private: UriUtils(); ~UriUtils(); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 34e2bfc919..1b7202be77 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -66,6 +66,7 @@ const int32_t AUTO_DISCONNECT_INFINITY = -1; constexpr const char* FROZEN_WHITE_DIALOG = "com.huawei.hmos.huaweicast"; constexpr char BUNDLE_NAME_DIALOG[] = "com.ohos.amsdialog"; constexpr char ABILITY_NAME_ASSERT_FAULT_DIALOG[] = "AssertFaultDialog"; +constexpr const char* WANT_PARAMS_APP_RESTART_FLAG = "ohos.aafwk.app.restart"; const std::string XIAOYI_BUNDLE_NAME = "com.huawei.hmos.vassistant"; @@ -807,7 +808,6 @@ int AbilityConnectManager::AttachAbilityThreadLocked( void AbilityConnectManager::OnAbilityRequestDone(const sptr &token, const int32_t state) { TAG_LOGD(AAFwkTag::ABILITYMGR, "state: %{public}d", state); - std::lock_guard guard(serialMutex_); AppAbilityState abilityState = DelayedSingleton::GetInstance()->ConvertToAppAbilityState(state); if (abilityState == AppAbilityState::ABILITY_STATE_FOREGROUND) { auto abilityRecord = GetExtensionByTokenFromServiceMap(token); @@ -822,6 +822,8 @@ void AbilityConnectManager::OnAbilityRequestDone(const sptr &toke } std::string element = abilityRecord->GetURI(); TAG_LOGD(AAFwkTag::ABILITYMGR, "Ability is %{public}s, start to foreground.", element.c_str()); + abilityRecord->GrantUriPermissionForUIExtension(); + std::lock_guard guard(serialMutex_); abilityRecord->ForegroundUIExtensionAbility(); } } @@ -1209,6 +1211,7 @@ void AbilityConnectManager::CompleteCommandAbility(std::shared_ptrGetURI()); if (abilityRecord->NeedConnectAfterCommand()) { + abilityRecord->UpdateConnectWant(); ConnectAbility(abilityRecord); } } @@ -1307,7 +1310,7 @@ std::shared_ptr AbilityConnectManager::GetExtensionByIdFromTermin return nullptr; } -std::shared_ptr AbilityConnectManager::GetUIExtensioBySessionInfo( +std::shared_ptr AbilityConnectManager::GetUIExtensionBySessionInfo( const sptr &sessionInfo) { CHECK_POINTER_AND_RETURN(sessionInfo, nullptr); @@ -2353,6 +2356,8 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr return; } + requestInfo.want.SetParam(WANT_PARAMS_APP_RESTART_FLAG, true); + // restart other resident ability if (abilityRecord->CanRestartResident()) { requestInfo.restartCount = abilityRecord->GetRestartCount(); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 01d6fcba3b..b715ff6415 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -2036,5 +2036,14 @@ ErrCode AbilityManagerClient::BlockAllAppStart(bool flag) CHECK_POINTER_RETURN_INVALID_VALUE(abms); return abms->BlockAllAppStart(flag); } + +ErrCode AbilityManagerClient::UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->UpdateAssociateConfigList(configs, exportConfigs, flag); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index df93f425df..66865f0b8c 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -35,6 +35,7 @@ namespace { using AutoStartupInfo = AbilityRuntime::AutoStartupInfo; constexpr int32_t CYCLE_LIMIT = 1000; constexpr int32_t MAX_AUTO_STARTUP_COUNT = 100; +constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100; bool AbilityManagerProxy::WriteInterfaceToken(MessageParcel &data) { if (!data.WriteInterfaceToken(AbilityManagerProxy::GetDescriptor())) { @@ -610,7 +611,7 @@ int AbilityManagerProxy::StartAbilityOnlyUIAbility(const Want &want, const sptr< return reply.ReadInt32(); } -int AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr &callerToken, +int32_t AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr &callerToken, int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -5611,5 +5612,82 @@ int32_t AbilityManagerProxy::BlockAllAppStart(bool flag) return reply.ReadInt32(); } + +int32_t AbilityManagerProxy::UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return IPC_PROXY_ERR; + } + + if (!UpdateAssociateConfigInner(configs, data)) { + return INNER_ERR; + } + + int32_t size = static_cast(exportConfigs.size()); + if (size > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "export configs size too large"); + return INNER_ERR; + } + if (!data.WriteInt32(size)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write export configs size fail"); + return INNER_ERR; + } + for (const auto& config : exportConfigs) { + if (!data.WriteString(config)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write export config item fail"); + return INNER_ERR; + } + } + if (!data.WriteInt32(flag)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail"); + return INNER_ERR; + } + auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_ASSOCIATE_CONFIG_LIST, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + +bool AbilityManagerProxy::UpdateAssociateConfigInner(const std::map>& configs, + MessageParcel& data) +{ + int32_t size = static_cast(configs.size()); + if (size > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "configs size too large"); + return false; + } + if (!data.WriteInt32(size)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write configs size fail"); + return false; + } + for (const auto& config : configs) { + if (!data.WriteString(config.first)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write config key fail"); + return false; + } + size = static_cast(config.second.size()); + if (size > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "config size too large"); + return false; + } + if (!data.WriteInt32(size)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item size fail"); + return false; + } + for (const auto& item : config.second) { + if (!data.WriteString(item)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item fail"); + return false; + } + } + } + return true; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 0524d58061..f9ee11d050 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -58,6 +58,7 @@ #include "restart_app_manager.h" #include "scene_board_judgement.h" #include "server_constant.h" +#include "session_manager_lite.h" #include "softbus_bus_center.h" #include "start_ability_handler/start_ability_sandbox_savefile.h" #include "start_ability_utils.h" @@ -72,6 +73,7 @@ #include "view_data.h" #include "xcollie/watchdog.h" #include "config_policy_utils.h" +#include "uri_utils.h" #include "utils/ability_permission_util.h" #include "utils/dump_utils.h" #include "utils/extension_permissions_util.h" @@ -128,12 +130,18 @@ constexpr const char* PREPARE_TERMINATE_ENABLE_PARAMETER = "persist.sys.prepare_ // UIExtension type constexpr const char* UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; constexpr const char* UIEXTENSION_TARGET_TYPE_KEY = "ability.want.params.uiExtensionTargetType"; +<<<<<<< HEAD // constexpr const char* SYSTEM_SHARE = "share"; // constexpr const char* SYSTEM_SHARE_TYPE = "sysPicker/share"; // Share picker params constexpr char SHARE_PICKER_DIALOG_BUNDLE_NAME_KEY[] = "const.system.sharePicker.bundleName"; constexpr char SHARE_PICKER_DIALOG_ABILITY_NAME_KEY[] = "const.system.sharePicker.abilityName"; // constexpr char SHARE_PICKER_UIEXTENSION_NAME_KEY[] = "const.system.sharePicker.UIExtensionAbilityName"; +======= +// Share picker params +constexpr char SHARE_PICKER_DIALOG_BUNDLE_NAME_KEY[] = "const.system.sharePicker.bundleName"; +constexpr char SHARE_PICKER_DIALOG_ABILITY_NAME_KEY[] = "const.system.sharePicker.abilityName"; +>>>>>>> upstream/master constexpr char SHARE_PICKER_DIALOG_DEFAULY_BUNDLE_NAME[] = "com.ohos.sharepickerdialog"; constexpr char SHARE_PICKER_DIALOG_DEFAULY_ABILITY_NAME[] = "PickerDialog"; constexpr char TOKEN_KEY[] = "ohos.ability.params.token"; @@ -153,14 +161,15 @@ constexpr const char* DMS_PERSISTENT_ID = "ohos.dms.persistentId"; constexpr const char* DEBUG_APP = "debugApp"; constexpr const char* NATIVE_DEBUG = "nativeDebug"; -constexpr const char* AUTO_FILL_PASSWORD_TPYE = "autoFill/password"; -constexpr const char* AUTO_FILL_SMART_TPYE = "autoFill/smart"; +constexpr const char* AUTO_FILL_PASSWORD_TYPE = "autoFill/password"; +constexpr const char* AUTO_FILL_SMART_TYPE = "autoFill/smart"; constexpr size_t INDEX_ZERO = 0; constexpr size_t INDEX_ONE = 1; constexpr size_t INDEX_TWO = 2; constexpr size_t ARGC_THREE = 3; constexpr static char WANT_PARAMS_VIEW_DATA_KEY[] = "ohos.ability.params.viewData"; constexpr const char* WANT_PARAMS_HOST_WINDOW_ID_KEY = "ohos.extra.param.key.hostwindowid"; +constexpr const char* WANT_PARAMS_APP_RESTART_FLAG = "ohos.aafwk.app.restart"; constexpr int32_t FOUNDATION_UID = 5523; constexpr const char* FRS_BUNDLE_NAME = "com.ohos.formrenderservice"; @@ -177,6 +186,10 @@ constexpr char ASSERT_FAULT_DETAIL[] = "assertFaultDialogDetail"; constexpr char PRODUCT_ASSERT_FAULT_DIALOG_ENABLED[] = "persisit.sys.abilityms.support_assert_fault_dialog"; constexpr const char* ABILITYMS_ENABLE_UISERVICE = "const.abilityms.enable_uiservice"; +constexpr int32_t RESOURCE_SCHEDULE_UID = 1096; +constexpr int32_t UPDATE_CONFIG_FLAG_COVER = 1; +constexpr int32_t UPDATE_CONFIG_FLAG_APPEND = 2; + const std::unordered_set COMMON_PICKER_TYPE = { "share", "action" }; @@ -650,7 +663,7 @@ int AbilityManagerService::StartAbilityByUIContentSession(const Want &want, cons } if (token != sessionInfo->callerToken) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken unequal to top ablity token"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken unequal to top ability token"); return NOT_TOP_ABILITY; } AbilityUtil::RemoveInstanceKey(const_cast(want)); @@ -685,7 +698,7 @@ int AbilityManagerService::StartAbilityByUIContentSession(const Want &want, cons } if (token != sessionInfo->callerToken) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken unequal to top ablity token"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken unequal to top ability token"); return NOT_TOP_ABILITY; } return StartAbility(want, startOptions, callerToken, userId, requestCode); @@ -1120,6 +1133,9 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr 0 && callerToken != nullptr) { // for sa specify tokenId and caller token UpdateCallerInfoFromToken(abilityRequest.want, callerToken); @@ -1284,6 +1300,8 @@ int AbilityManagerService::StartAbilityByConnectManager(const Want& want, const TAG_LOGD(AAFwkTag::ABILITYMGR, "Start service or extension, name is %{public}s.", abilityInfo.name.c_str()); ReportEventToRSS(abilityInfo, callerToken); InsightIntentExecuteParam::RemoveInsightIntent(const_cast(want)); + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(const_cast(abilityRequest.want), + abilityRequest.abilityInfo.extensionAbilityType); return connectManager->StartAbility(abilityRequest); } @@ -1761,6 +1779,9 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); return result; } + if (!UriUtils::GetInstance().CheckNonImplicitShareFileUri(abilityRequest)) { + return ERR_SHARE_FILE_URI_NON_IMPLICITLY; + } if (!isStartAsCaller) { TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); @@ -2022,6 +2043,8 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const TAG_LOGD(AAFwkTag::ABILITYMGR, "request dialog service, start service extension,name is %{public}s.", abilityInfo.name.c_str()); ReportEventToRSS(abilityInfo, callerToken); + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(abilityRequest.want, + abilityRequest.abilityInfo.extensionAbilityType); return connectManager->StartAbility(abilityRequest); } @@ -2615,7 +2638,7 @@ void AbilityManagerService::ReportEventToRSS(const AppExecFwk::AbilityInfo &abil }); } -int AbilityManagerService::StartExtensionAbility(const Want &want, const sptr &callerToken, +int32_t AbilityManagerService::StartExtensionAbility(const Want &want, const sptr &callerToken, int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -2767,7 +2790,7 @@ int AbilityManagerService::ChangeUIAbilityVisibilityBySCB(sptr sess return uiAbilityManager->ChangeUIAbilityVisibilityBySCB(sessionInfo, isShow); } -int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sptr &callerToken, +int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sptr &callerToken, int32_t userId, AppExecFwk::ExtensionAbilityType extensionType, bool checkSystemCaller, bool isImplicit, bool isDlp, bool isStartAsCaller) { @@ -2786,6 +2809,8 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp result = CheckDlpForExtension(want, callerToken, userId, eventInfo, EventName::START_EXTENSION_ERROR); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "CheckDlpForExtension error"); + eventInfo.errCode = result; + EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } #endif // WITH_DLP @@ -2800,6 +2825,8 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp int32_t validUserId = GetValidUserId(userId); int32_t appIndex = 0; if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) { + eventInfo.errCode = ERR_APP_CLONE_INDEX_INVALID; + EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_APP_CLONE_INDEX_INVALID; } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken, true); @@ -2811,13 +2838,13 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ null or doProcess error"); eventInfo.errCode = result; - SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); + EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } if (!JudgeMultiUserConcurrency(validUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "multi-user non-concurrent unsatisfied"); - eventInfo.errCode = ERR_INVALID_VALUE; + eventInfo.errCode = ERR_CROSS_USER; EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_CROSS_USER; } @@ -2851,7 +2878,6 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp TAG_LOGD(AAFwkTag::ABILITYMGR, "userId is : %{public}d, singleton is : %{public}d", validUserId, static_cast(abilityInfo.applicationInfo.singleton)); -#ifdef WITH_DLP result = isDlp ? IN_PROCESS_CALL( CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, isImplicit, isStartAsCaller)) : CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, isImplicit, isStartAsCaller); @@ -2861,7 +2887,6 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } -#endif // WITH_DLP AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), false, callerToken, std::make_shared(abilityInfo), false, appIndex); @@ -2869,6 +2894,8 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "afterCheckExecuter_ null or doProcess error"); + eventInfo.errCode = result; + EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } @@ -2882,8 +2909,11 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp if (!isStartAsCaller) { UpdateCallerInfo(abilityRequest.want, callerToken); } + TAG_LOGD(AAFwkTag::ABILITYMGR, "Start extension begin, name is %{public}s.", abilityInfo.name.c_str()); SetAbilityRequestSessionInfo(abilityRequest, extensionType); + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(abilityRequest.want, + abilityRequest.abilityInfo.extensionAbilityType); eventInfo.errCode = connectManager->StartAbility(abilityRequest); if (eventInfo.errCode != ERR_OK) { EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); @@ -2952,9 +2982,9 @@ void AbilityManagerService::SetAutoFillElementName(const sptr &exte TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); CHECK_POINTER_IS_NULLPTR(extensionSessionInfo); std::vector argList; - if (extensionSessionInfo->want.GetStringParam(UIEXTENSION_TYPE_KEY) == AUTO_FILL_PASSWORD_TPYE) { + if (extensionSessionInfo->want.GetStringParam(UIEXTENSION_TYPE_KEY) == AUTO_FILL_PASSWORD_TYPE) { SplitStr(KEY_AUTO_FILL_ABILITY, "/", argList); - } else if (extensionSessionInfo->want.GetStringParam(UIEXTENSION_TYPE_KEY) == AUTO_FILL_SMART_TPYE) { + } else if (extensionSessionInfo->want.GetStringParam(UIEXTENSION_TYPE_KEY) == AUTO_FILL_SMART_TYPE) { SplitStr(KEY_SMART_AUTO_FILL_ABILITY, "/", argList); } else { TAG_LOGW(AAFwkTag::ABILITYMGR, "not autofill"); @@ -3040,6 +3070,8 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte int32_t result = DelayedSingleton::GetInstance()->CheckAndUpdateWant( extensionSessionInfo->want, AppExecFwk::ExecuteMode::UI_EXTENSION_ABILITY); if (result != ERR_OK) { + eventInfo.errCode = ERR_INVALID_VALUE; + EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } } @@ -3116,6 +3148,9 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return result; } + if (!UriUtils::GetInstance().CheckNonImplicitShareFileUri(abilityRequest)) { + return ERR_SHARE_FILE_URI_NON_IMPLICITLY; + } abilityRequest.extensionType = abilityRequest.abilityInfo.extensionAbilityType; auto abilityInfo = abilityRequest.abilityInfo; @@ -3162,6 +3197,8 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte } ReportEventToRSS(abilityRequest.abilityInfo, abilityRequest.callerToken); TAG_LOGD(AAFwkTag::ABILITYMGR, "name:%{public}s", abilityInfo.name.c_str()); + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(abilityRequest.want, + abilityRequest.abilityInfo.extensionAbilityType); eventInfo.errCode = connectManager->StartAbility(abilityRequest); if (eventInfo.errCode != ERR_OK) { EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); @@ -3583,7 +3620,11 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr &sessionI (void)DelayedSingleton::GetInstance()-> DeleteAbilityRecoverInfo(abilityInfo.applicationInfo.accessTokenId, abilityInfo.moduleName, abilityName); } - + bool forceKillProcess = ResSchedUtil::GetInstance().CheckShouldForceKillProcess(abilityRecord->GetPid()); + if (!forceKillProcess) { + IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton::GetInstance()->SetProcessCacheStatus( + abilityRecord->GetPid(), true)); + } EventInfo eventInfo; eventInfo.bundleName = abilityRecord->GetAbilityInfo().bundleName; eventInfo.abilityName = abilityRecord->GetAbilityInfo().name; @@ -3869,13 +3910,13 @@ int AbilityManagerService::MinimizeUIAbilityBySCB(const sptr &sessi return uiAbilityManager->MinimizeUIAbility(abilityRecord, fromUser, sceneFlag); } -int AbilityManagerService::ConnectAbility( +int32_t AbilityManagerService::ConnectAbility( const Want &want, const sptr &connect, const sptr &callerToken, int32_t userId) { return ConnectAbilityCommon(want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId); } -int AbilityManagerService::ConnectAbilityCommon( +int32_t AbilityManagerService::ConnectAbilityCommon( const Want &want, const sptr &connect, const sptr &callerToken, AppExecFwk::ExtensionAbilityType extensionType, int32_t userId, bool isQueryExtensionOnly) { @@ -4108,7 +4149,7 @@ int AbilityManagerService::DisconnectAbility(sptr connect) return err; } -int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t userId, +int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t userId, const sptr &connect, const sptr &callerToken, AppExecFwk::ExtensionAbilityType extensionType, const sptr &sessionInfo, bool isQueryExtensionOnly, sptr connectInfo) @@ -4140,6 +4181,9 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u TAG_LOGE(AAFwkTag::ABILITYMGR, "generate request error"); return result; } + if (!UriUtils::GetInstance().CheckNonImplicitShareFileUri(abilityRequest)) { + return ERR_SHARE_FILE_URI_NON_IMPLICITLY; + } result = CheckPermissionForUIService(extensionType, want, abilityRequest); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "checkPermissionForUIService failed"); @@ -4230,6 +4274,8 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u SetAbilityRequestSessionInfo(abilityRequest, targetExtensionType); ReportEventToRSS(abilityInfo, callerToken); + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(const_cast(abilityRequest.want), + abilityRequest.abilityInfo.extensionAbilityType); return connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken, sessionInfo, connectInfo); } @@ -6220,7 +6266,10 @@ int AbilityManagerService::GenerateAbilityRequest(const Want &want, int requestC } if (ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(request.abilityInfo.applicationInfo)) { - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + // service and extension do not show dialog. + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && + !(request.abilityInfo.type == AppExecFwk::AbilityType::SERVICE || + request.abilityInfo.type == AppExecFwk::AbilityType::EXTENSION)) { ModalSystemDialogUtil::ShowDeveloperModeDialog(request.abilityInfo.bundleName, request.abilityInfo.name); } TAG_LOGE(AAFwkTag::ABILITYMGR, "not developer mode"); @@ -6274,11 +6323,9 @@ int32_t AbilityManagerService::InitialAbilityRequest(AbilityRequest &request, request.appInfo = request.abilityInfo.applicationInfo; request.uid = request.appInfo.uid; TAG_LOGD(AAFwkTag::ABILITYMGR, - "GenerateExtensionAbilityRequest end, app name: %{public}s, bundle name: %{public}s, uid: %{public}d.", - request.appInfo.name.c_str(), request.appInfo.bundleName.c_str(), request.uid); + "GenerateExtensionAbilityRequest end, app name:%{public}s, bundle name:%{public}s, uid:%{public}d, moduleName:%{public}s", + request.appInfo.name.c_str(), request.appInfo.bundleName.c_str(), request.uid, request.abilityInfo.moduleName.c_str()); - TAG_LOGD(AAFwkTag::ABILITYMGR, - "GenerateExtensionAbilityRequest, moduleName: %{public}s.", request.abilityInfo.moduleName.c_str()); request.want.SetModuleName(request.abilityInfo.moduleName); return ERR_OK; @@ -7939,6 +7986,8 @@ void AbilityManagerService::StartSwitchUserDialogInner(const Want &want, int32_t } } + UriUtils::GetInstance().CheckUriPermissionForServiceExtension(abilityRequest.want, + abilityRequest.abilityInfo.extensionAbilityType); eventInfo.errCode = connectManager->StartAbility(abilityRequest); if (eventInfo.errCode != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "eventInfo errCode:%{public}d", eventInfo.errCode); @@ -8346,6 +8395,7 @@ void AbilityManagerService::UpdateCallerInfo(Want& want, const sptrGetCallerInfo(); @@ -8492,6 +8544,7 @@ bool AbilityManagerService::UpdateAsCallerInfoFromDialog(Want& want) want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, callerBundleName); want.SetParam(Want::PARAM_RESV_CALLER_ABILITY_NAME, callerAbilityName); want.RemoveParam(Want::PARAM_RESV_CALLER_NATIVE_NAME); + want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG); if (callerBundleName == "") { want.SetParam(Want::PARAM_RESV_CALLER_NATIVE_NAME, dialogCallerWant.GetStringParam(Want::PARAM_RESV_CALLER_NATIVE_NAME)); @@ -8518,6 +8571,7 @@ void AbilityManagerService::UpdateCallerInfoFromToken(Want& want, const sptrGetAbilityInfo().bundleName; want.RemoveParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME); @@ -8601,7 +8655,7 @@ int AbilityManagerService::CheckStaticCfgPermissionForAbility(const AppExecFwk:: return AppExecFwk::Constants::PERMISSION_GRANTED; } - for (auto permission : abilityInfo.permissions) { + for (const auto &permission : abilityInfo.permissions) { if (AccessTokenKit::VerifyAccessToken(tokenId, permission, false) != AppExecFwk::Constants::PERMISSION_GRANTED) { TAG_LOGE(AAFwkTag::ABILITYMGR, "verify access token fail, permission:%{public}s", @@ -9535,9 +9589,8 @@ int AbilityManagerService::CheckCallOtherExtensionPermission(const AbilityReques return ERR_OK; } - const std::string fileAccessPermission = "ohos.permission.FILE_ACCESS_MANAGER"; if (extensionType == AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION && - AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(fileAccessPermission)) { + AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(PermissionConstants::PERMISSION_FILE_ACCESS_MANAGER)) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Temporary, FILEACCESS_EXTENSION use serviceExtension start-up rule."); return CheckCallServiceExtensionPermission(abilityRequest); } @@ -10367,7 +10420,7 @@ void AbilityManagerService::GetConnectManagerAndUIExtensionBySessionInfo(const s TAG_LOGD(AAFwkTag::ABILITYMGR, "userId=%{public}d", userId); connectManager = GetConnectManagerByUserId(userId); if (connectManager) { - targetAbility = connectManager->GetUIExtensioBySessionInfo(sessionInfo); + targetAbility = connectManager->GetUIExtensionBySessionInfo(sessionInfo); } else { TAG_LOGW(AAFwkTag::ABILITYMGR, "connectManager null, userId:%{public}d", userId); } @@ -10375,7 +10428,7 @@ void AbilityManagerService::GetConnectManagerAndUIExtensionBySessionInfo(const s TAG_LOGD(AAFwkTag::ABILITYMGR, "try to find UIExtension in user0"); connectManager = GetConnectManagerByUserId(U0_USER_ID); if (connectManager) { - targetAbility = connectManager->GetUIExtensioBySessionInfo(sessionInfo); + targetAbility = connectManager->GetUIExtensionBySessionInfo(sessionInfo); } else { TAG_LOGW(AAFwkTag::ABILITYMGR, "connectManager null, userId:0"); } @@ -10532,7 +10585,8 @@ int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const Start (startOptions.processOptions->startupVisibility == StartupVisibility::STARTUP_HIDE); bool hasStartBackgroundAbilityPermission = PermissionVerification::GetInstance()-> VerifyStartUIAbilityToHiddenPermission(); - bool canStartupHide = (isStartupVisibilityHide && hasStartBackgroundAbilityPermission); + bool canStartupHide = (ProcessOptions::IsNoAttachmentMode(startOptions.processOptions->processMode) && + isStartupVisibilityHide && hasStartBackgroundAbilityPermission); if (!CheckCallingTokenId(element.GetBundleName(), userId, appIndex) && !canStartupHide) { TAG_LOGE(AAFwkTag::ABILITYMGR, "not self application and has no start background ability permission"); @@ -10946,7 +11000,7 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vector> &abilityTokens) @@ -11604,6 +11658,7 @@ void AbilityManagerService::ReportPreventStartAbilityResult(const AppExecFwk::Ab bool AbilityManagerService::IsInWhiteList(const std::string &callerBundleName, const std::string &calleeBundleName, const std::string &calleeAbilityName) { + std::lock_guard locker(whiteListMutex_); std::map>::iterator iter = whiteListMap_.find(callerBundleName); std::string uri = calleeBundleName + "/" + calleeAbilityName; if (iter != whiteListMap_.end()) { @@ -11625,6 +11680,7 @@ bool AbilityManagerService::ParseJsonFromBoot(const std::string &relativePath) if (ParseJsonValueFromFile(jsonObj, absolutePath) != ERR_OK) { return false; } + std::lock_guard locker(whiteListMutex_); nlohmann::json whiteListJsonList = jsonObj[WHITE_LIST]; for (const auto& [key, value] : whiteListJsonList.items()) { if (!value.is_array()) { @@ -12002,6 +12058,9 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses TAG_LOGE(AAFwkTag::ABILITYMGR, "Generate ability request local error"); return result; } + if (!UriUtils::GetInstance().CheckNonImplicitShareFileUri(abilityRequest)) { + return ERR_SHARE_FILE_URI_NON_IMPLICITLY; + } if (specifyTokenId > 0 && callerToken != nullptr) { // for sa specify tokenId and caller token UpdateCallerInfoFromToken(abilityRequest.want, callerToken); @@ -12179,7 +12238,7 @@ int32_t AbilityManagerService::CleanUIAbilityBySCB(const sptr &sess return errCode; } -void AbilityManagerService::ForceTerminateSerivceExtensionByPid(int32_t pid, int32_t userId) +void AbilityManagerService::ForceTerminateServiceExtensionByPid(int32_t pid, int32_t userId) { std::vector> tokens; IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton::GetInstance()->GetAbilityRecordsByProcessID( @@ -12191,7 +12250,7 @@ void AbilityManagerService::ForceTerminateSerivceExtensionByPid(int32_t pid, int if (abilityRecord && abilityRecord->GetAbilityInfo().extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "app ForceTerminateSerivceExtensionByPid, pid is %{public}d", pid); + TAG_LOGI(AAFwkTag::ABILITYMGR, "app ForceTerminateServiceExtensionByPid, pid is %{public}d", pid); connectManager->TerminateAbility(token); } } @@ -12228,7 +12287,7 @@ void AbilityManagerService::SendStartAbilityOtherExtensionEvent(const AppExecFwk { if (abilityInfo.type != AppExecFwk::AbilityType::EXTENSION || abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE) { - return; + return; } EventInfo eventInfo; eventInfo.bundleName = abilityInfo.bundleName; @@ -12256,26 +12315,32 @@ void AbilityManagerService::SendStartAbilityOtherExtensionEvent(const AppExecFwk void AbilityManagerService::SetAbilityRequestSessionInfo(AbilityRequest &abilityRequest, AppExecFwk::ExtensionAbilityType extensionType) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "called"); if (extensionType != AppExecFwk::ExtensionAbilityType::UI_SERVICE) { return; } + abilityRequest.want.RemoveParam(WANT_PARAMS_HOST_WINDOW_ID_KEY); auto callerAbilityRecord = Token::GetAbilityRecordByToken(abilityRequest.callerToken); - if (callerAbilityRecord == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "SetAbilityRequestSessionInfo, callerAbilityRecord null"); - return; - } + CHECK_POINTER_LOG(callerAbilityRecord, "callerAbilityRecord is nullptr"); sptr callerSessionInfo = callerAbilityRecord->GetSessionInfo(); - if (callerSessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "SetAbilityRequestSessionInfo, callerSessionInfo null"); - return; - } + CHECK_POINTER_LOG(callerSessionInfo, "callerSessionInfo is nullptr"); + if (callerAbilityRecord->GetAbilityInfo().type == AbilityType::PAGE) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "SetAbilityRequestSessionInfo, caller is UIAbility"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "UIAbility Caller"); abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, callerSessionInfo->persistentId); - return; + } else if (AAFwk::UIExtensionUtils::IsUIExtension(callerAbilityRecord->GetAbilityInfo().extensionAbilityType)) { + int32_t mainWindowId = -1; + auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance(). + GetSceneSessionManagerLiteProxy(); + CHECK_POINTER_LOG(sceneSessionManager, "sceneSessionManager is nullptr"); + auto err = sceneSessionManager->GetRootMainWindowId(static_cast(callerSessionInfo->hostWindowId),mainWindowId); + TAG_LOGI(AAFwkTag::ABILITYMGR, "callerSessionInfo->hostWindowId = %{public}d, mainWindowId = %{public}d, err = %{public}d", + callerSessionInfo->hostWindowId, mainWindowId, err); + abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, mainWindowId); + } else { + abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, 0); } - abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, 0); } int32_t AbilityManagerService::TerminateMission(int32_t missionId) @@ -12300,6 +12365,11 @@ int32_t AbilityManagerService::BlockAllAppStart(bool flag) HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); + if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not supported device"); + return ERR_PERMISSION_DENIED; + } + if (!PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission verification failed"); return ERR_PERMISSION_DENIED; @@ -12312,8 +12382,36 @@ int32_t AbilityManagerService::BlockAllAppStart(bool flag) bool AbilityManagerService::ShouldBlockAllAppStart() { + if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) { + return false; + } + std::unique_lock lock(shouldBlockAllAppStartMutex_); return shouldBlockAllAppStart_; } + +int32_t AbilityManagerService::UpdateAssociateConfigList(const std::map>& configs, + const std::list& exportConfigs, int32_t flag) +{ + if (IPCSkeleton::GetCallingUid() != RESOURCE_SCHEDULE_UID) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Update associate config, current process not rss process"); + return CHECK_PERMISSION_FAILED; + } + std::lock_guard locker(whiteListMutex_); + if (flag == UPDATE_CONFIG_FLAG_COVER) { + whiteListMap_ = configs; + exportWhiteList_ = exportConfigs; + } else if (flag == UPDATE_CONFIG_FLAG_APPEND) { + for (const auto& config : configs) { + for (const auto& item : config.second) { + whiteListMap_[config.first].push_back(item); + } + } + for (const auto& config : exportConfigs) { + exportWhiteList_.push_back(config); + } + } + return ERR_OK; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index b5a3dc8a02..cbeaff74b8 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -29,6 +29,7 @@ namespace { const std::u16string extensionDescriptor = u"ohos.aafwk.ExtensionManager"; constexpr int32_t CYCLE_LIMIT = 1000; constexpr int32_t MAX_KILL_PROCESS_PID_COUNT = 100; +constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100; } // namespace AbilityManagerStub::AbilityManagerStub() {} @@ -757,6 +758,9 @@ int AbilityManagerStub::OnRemoteRequestInnerNineteenth(uint32_t code, MessagePar if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_ALL_APP_START) { return BlockAllAppStartInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::UPDATE_ASSOCIATE_CONFIG_LIST) { + return UpdateAssociateConfigListInner(data, reply); + } return ERR_CODE_NOT_EXIST; } @@ -4046,5 +4050,44 @@ int32_t AbilityManagerStub::BlockAllAppStartInner(MessageParcel &data, MessagePa } return ERR_OK; } + +int32_t AbilityManagerStub::UpdateAssociateConfigListInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t size = data.ReadInt32(); + if (size > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "config size error"); + return ERR_INVALID_VALUE; + } + std::map> configs; + for (int32_t i = 0; i < size; ++i) { + std::string key = data.ReadString(); + int32_t itemSize = data.ReadInt32(); + if (itemSize > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "config size error"); + return ERR_INVALID_VALUE; + } + configs.emplace(key, std::list()); + for (int32_t j = 0; j < itemSize; ++j) { + configs[key].push_back(data.ReadString()); + } + } + + std::list exportConfigs; + size = data.ReadInt32(); + if (size > MAX_UPDATE_CONFIG_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "config size error"); + return ERR_INVALID_VALUE; + } + for (int32_t i = 0; i < size; ++i) { + exportConfigs.push_back(data.ReadString()); + } + int32_t flag = data.ReadInt32(); + int32_t result = UpdateAssociateConfigList(configs, exportConfigs, flag); + if (result != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "update associate config fail"); + } + reply.WriteInt32(result); + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 2226bcfc00..4b33966676 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -400,16 +400,22 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag) } } +bool AbilityRecord::GrantUriPermissionForUIExtension() +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "GrantUriPermissionForUIExtension:: called."); + if (UIExtensionUtils::IsUIExtension(abilityInfo_.extensionAbilityType)) { + std::lock_guard guard(wantLock_); + GrantUriPermission(want_, abilityInfo_.applicationInfo.bundleName, false, 0); + return true; + } + return false; +} + void AbilityRecord::ForegroundUIExtensionAbility(uint32_t sceneFlag) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "ability:%{public}s", GetURI().c_str()); CHECK_POINTER(lifecycleDeal_); - // grant uri permission - { - std::lock_guard guard(wantLock_); - GrantUriPermission(want_, abilityInfo_.applicationInfo.bundleName, false, 0); - } // schedule active after updating AbilityState and sending timeout message to avoid ability async callback // earlier than above actions. @@ -1816,7 +1822,7 @@ void AbilityRecord::SendSandboxSavefileResult(const Want &want, int resultCode, } } } else { - TAG_LOGW(AAFwkTag::ABILITYMGR, "uri illigal for request: %{public}d", requestCode); + TAG_LOGW(AAFwkTag::ABILITYMGR, "uri illegal for request: %{public}d", requestCode); } auto scheduler = scheduler_; @@ -3178,36 +3184,6 @@ void AbilityRecord::DumpAbilityInfoDone(std::vector &infos) dumpCondition_.notify_all(); } -bool AbilityRecord::GetUriListFromWant(Want &want, std::vector &uriVec) -{ - auto uriStr = want.GetUri().ToString(); - uriVec = want.GetStringArrayParam(AbilityConfig::PARAMS_STREAM); - if (uriVec.empty() && uriStr.empty()) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "uriVec empty."); - return false; - } - // process param stream - auto paramStreamUriCount = uriVec.size(); - if (uriStr.empty() && paramStreamUriCount > MAX_URI_COUNT) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "uri empty, paream stream counts: %{public}zu", paramStreamUriCount); - uriVec.resize(MAX_URI_COUNT); - want.RemoveParam(AbilityConfig::PARAMS_STREAM); - want.SetParam(AbilityConfig::PARAMS_STREAM, uriVec); - return true; - } - if (!uriStr.empty() && paramStreamUriCount > MAX_URI_COUNT - 1) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "paream stream counts: %{public}zu", paramStreamUriCount); - uriVec.resize(MAX_URI_COUNT - 1); - want.RemoveParam(AbilityConfig::PARAMS_STREAM); - want.SetParam(AbilityConfig::PARAMS_STREAM, uriVec); - } - // process uri - if (!uriStr.empty()) { - uriVec.insert(uriVec.begin(), uriStr); - } - return true; -} - void AbilityRecord::PublishFileOpenEvent(const Want &want) { auto wangUri = want.GetUri(); @@ -3256,7 +3232,7 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName, return; } - if ((want.GetFlags() & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) == 0) { + if (!UriUtils::GetInstance().IsGrantUriPermissionFlag(want)) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Do not call uriPermissionMgr."); return; } @@ -3265,7 +3241,7 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName, return; } std::vector uriVec; - if (!GetUriListFromWant(want, uriVec)) { + if (!UriUtils::GetInstance().GetUriListFromWant(want, uriVec)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "get uri list failed"); return; } @@ -3292,9 +3268,22 @@ void AbilityRecord::GrantUriPermissionInner(Want &want, std::vector return; } uint32_t flag = want.GetFlags(); - auto checkResults = IN_PROCESS_CALL(UriPermissionManagerClient::GetInstance().CheckUriAuthorization( - uriVec, flag, callerTokenId)); - auto permissionUris = UriUtils::GetInstance().GetPermissionedUriList(uriVec, checkResults, want); + std::vector permissionUris; + if (abilityInfo_.extensionAbilityType != AppExecFwk::ExtensionAbilityType::SERVICE && + abilityInfo_.extensionAbilityType != AppExecFwk::ExtensionAbilityType::UI_SERVICE) { + auto checkResults = IN_PROCESS_CALL(UriPermissionManagerClient::GetInstance().CheckUriAuthorization( + uriVec, flag, callerTokenId)); + permissionUris = UriUtils::GetInstance().GetPermissionedUriList(uriVec, checkResults, want); + } else { + TAG_LOGI(AAFwkTag::ABILITYMGR, "target is Service Extension."); + // for service extension, uri permission checked ahead + for (auto &uriStr: uriVec) { + Uri uri(uriStr); + if (uri.GetScheme() == "file") { + permissionUris.emplace_back(uri); + } + } + } if (permissionUris.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "uris not permissioned."); return; diff --git a/services/abilitymgr/src/mission.cpp b/services/abilitymgr/src/mission/mission.cpp similarity index 100% rename from services/abilitymgr/src/mission.cpp rename to services/abilitymgr/src/mission/mission.cpp diff --git a/services/abilitymgr/src/mission_data_storage.cpp b/services/abilitymgr/src/mission/mission_data_storage.cpp similarity index 100% rename from services/abilitymgr/src/mission_data_storage.cpp rename to services/abilitymgr/src/mission/mission_data_storage.cpp diff --git a/services/abilitymgr/src/mission_info.cpp b/services/abilitymgr/src/mission/mission_info.cpp similarity index 100% rename from services/abilitymgr/src/mission_info.cpp rename to services/abilitymgr/src/mission/mission_info.cpp diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission/mission_info_mgr.cpp similarity index 100% rename from services/abilitymgr/src/mission_info_mgr.cpp rename to services/abilitymgr/src/mission/mission_info_mgr.cpp diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission/mission_list.cpp similarity index 100% rename from services/abilitymgr/src/mission_list.cpp rename to services/abilitymgr/src/mission/mission_list.cpp diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission/mission_list_manager.cpp similarity index 100% rename from services/abilitymgr/src/mission_list_manager.cpp rename to services/abilitymgr/src/mission/mission_list_manager.cpp diff --git a/services/abilitymgr/src/mission_listener_controller.cpp b/services/abilitymgr/src/mission/mission_listener_controller.cpp similarity index 100% rename from services/abilitymgr/src/mission_listener_controller.cpp rename to services/abilitymgr/src/mission/mission_listener_controller.cpp diff --git a/services/abilitymgr/src/mission_listener_proxy.cpp b/services/abilitymgr/src/mission/mission_listener_proxy.cpp similarity index 100% rename from services/abilitymgr/src/mission_listener_proxy.cpp rename to services/abilitymgr/src/mission/mission_listener_proxy.cpp diff --git a/services/abilitymgr/src/mission_listener_stub.cpp b/services/abilitymgr/src/mission/mission_listener_stub.cpp similarity index 100% rename from services/abilitymgr/src/mission_listener_stub.cpp rename to services/abilitymgr/src/mission/mission_listener_stub.cpp diff --git a/services/abilitymgr/src/mission_snapshot.cpp b/services/abilitymgr/src/mission/mission_snapshot.cpp similarity index 100% rename from services/abilitymgr/src/mission_snapshot.cpp rename to services/abilitymgr/src/mission/mission_snapshot.cpp diff --git a/services/abilitymgr/src/process_options.cpp b/services/abilitymgr/src/process_options.cpp index b9bb380d6d..04f64c6c8d 100644 --- a/services/abilitymgr/src/process_options.cpp +++ b/services/abilitymgr/src/process_options.cpp @@ -93,5 +93,10 @@ bool ProcessOptions::IsValidProcessMode(ProcessMode value) { return (value > ProcessMode::UNSPECIFIED) && (value < ProcessMode::END); } + +bool ProcessOptions::IsNoAttachmentMode(ProcessMode value) +{ + return (value == ProcessMode::NO_ATTACHMENT); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 69e99e112e..c76f9bfb7b 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -357,11 +357,12 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a } auto sessionInfo = CreateSessionInfo(abilityRequest); sessionInfo->requestCode = abilityRequest.requestCode; - sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); - auto instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); - if (!instanceKey.empty()) { - sessionInfo->instanceKey = instanceKey; + auto isCreating = abilityRequest.want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); + if (abilityInfo.applicationInfo.multiAppMode.multiAppModeType != AppExecFwk::MultiAppModeType::MULTI_INSTANCE || + !isCreating) { + sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); } + sessionInfo->instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); sessionInfo->userId = userId_; sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); TAG_LOGI( @@ -2516,7 +2517,8 @@ int UIAbilityLifecycleManager::ChangeAbilityVisibility(sptr token auto sessionInfo = abilityRecord->GetSessionInfo(); CHECK_POINTER_AND_RETURN(sessionInfo, ERR_INVALID_VALUE); if (sessionInfo->processOptions == nullptr || - !ProcessOptions::IsAttachToStatusBarMode(sessionInfo->processOptions->processMode)) { + (!ProcessOptions::IsAttachToStatusBarMode(sessionInfo->processOptions->processMode) && + !ProcessOptions::IsNoAttachmentMode(sessionInfo->processOptions->processMode))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "process options check failed"); return ERR_START_OPTIONS_CHECK_FAILED; } diff --git a/services/abilitymgr/src/uri_utils.cpp b/services/abilitymgr/src/uri_utils.cpp index 2eb32fc138..00f08b3be2 100644 --- a/services/abilitymgr/src/uri_utils.cpp +++ b/services/abilitymgr/src/uri_utils.cpp @@ -16,6 +16,7 @@ #include "uri_utils.h" #include "ability_config.h" +#include "extension_ability_info.h" #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" #include "uri_permission_manager_client.h" @@ -115,7 +116,7 @@ bool UriUtils::CheckNonImplicitShareFileUri(const AbilityRequest &abilityRequest if (abilityRequest.appInfo.apiTargetVersion % API_VERSION_MOD <= API12) { return true; } - if (abilityRequest.want.GetElement().GetAbilityName().empty()) { + if (abilityRequest.want.GetElement().GetBundleName().empty()) { return true; } bool isFileUri = !abilityRequest.want.GetUriString().empty() && abilityRequest.want.GetUri().GetScheme() == "file"; @@ -172,5 +173,65 @@ std::vector UriUtils::GetPermissionedUriList(const std::vector return permissionedUris; } +bool UriUtils::GetUriListFromWant(Want &want, std::vector &uriVec) +{ + auto uriStr = want.GetUri().ToString(); + uriVec = want.GetStringArrayParam(AbilityConfig::PARAMS_STREAM); + if (uriVec.empty() && uriStr.empty()) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "uriVec empty."); + return false; + } + // process param stream + auto paramStreamUriCount = uriVec.size(); + if (uriStr.empty() && paramStreamUriCount > MAX_URI_COUNT) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "uri empty, paream stream counts: %{public}zu", paramStreamUriCount); + uriVec.resize(MAX_URI_COUNT); + want.RemoveParam(AbilityConfig::PARAMS_STREAM); + want.SetParam(AbilityConfig::PARAMS_STREAM, uriVec); + } + if (!uriStr.empty() && paramStreamUriCount > MAX_URI_COUNT - 1) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "paream stream counts: %{public}zu", paramStreamUriCount); + uriVec.resize(MAX_URI_COUNT - 1); + want.RemoveParam(AbilityConfig::PARAMS_STREAM); + want.SetParam(AbilityConfig::PARAMS_STREAM, uriVec); + } + // process uri + if (!uriStr.empty()) { + uriVec.insert(uriVec.begin(), uriStr); + } + return true; +} + +bool UriUtils::IsGrantUriPermissionFlag(const Want &want) +{ + return ((want.GetFlags() & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) != 0); +} + +void UriUtils::CheckUriPermissionForServiceExtension(Want &want, AppExecFwk::ExtensionAbilityType extensionAbilityType) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "CheckUriPermissionForServiceExtension called."); + if (extensionAbilityType != AppExecFwk::ExtensionAbilityType::SERVICE && + extensionAbilityType != AppExecFwk::ExtensionAbilityType::UI_SERVICE) { + return; + } + uint32_t flag = want.GetFlags(); + if (!IsGrantUriPermissionFlag(want)) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "No grant uri flag: %{public}u.", flag); + return; + } + std::vector uriVec; + if (!UriUtils::GetUriListFromWant(want, uriVec)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "No file uri neet grant."); + return; + } + auto callerTokenId = want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0); + // check uri permission + auto checkResults = IN_PROCESS_CALL(UriPermissionManagerClient::GetInstance().CheckUriAuthorization( + uriVec, flag, callerTokenId)); + // remove unpermissioned uri from want + UriUtils::GetInstance().GetPermissionedUriList(uriVec, checkResults, want); + return; +} + } // AAFwk } // OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/utils/ability_permission_util.cpp b/services/abilitymgr/src/utils/ability_permission_util.cpp index c10fee1387..25f7ed24a5 100644 --- a/services/abilitymgr/src/utils/ability_permission_util.cpp +++ b/services/abilitymgr/src/utils/ability_permission_util.cpp @@ -21,6 +21,7 @@ #include "app_utils.h" #include "accesstoken_kit.h" #include "hitrace_meter.h" +#include "implicit_start_processor.h" #include "insight_intent_execute_param.h" #include "ipc_skeleton.h" #include "multi_instance_utils.h" @@ -110,6 +111,9 @@ bool AbilityPermissionUtil::IsDominateScreen(const Want &want, bool isPendingWan int32_t AbilityPermissionUtil::CheckMultiInstanceAndAppClone(Want &want, int32_t userId, int32_t appIndex, sptr callerToken) { + if (ImplicitStartProcessor::IsImplicitStartAction(want)) { + return ERR_OK; + } auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); auto isCreating = want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); AppExecFwk::ApplicationInfo appInfo; diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 39967e788d..15eb0e2c8c 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -329,7 +329,7 @@ std::map> AppfreezeManager::BinderParser(std::ifstream& fin, continue; } - if (line.find("async") != std::string::npos) { + if (line.find("async\t") != std::string::npos) { continue; } diff --git a/services/appmgr/include/ability_running_record.h b/services/appmgr/include/ability_running_record.h index f79a607149..9eb2178422 100644 --- a/services/appmgr/include/ability_running_record.h +++ b/services/appmgr/include/ability_running_record.h @@ -75,6 +75,12 @@ public: * @return Returns the ability token. */ const sptr &GetToken() const; + + /** + * @brief Obtains the record id of the ability. + * + * @return Returns the ability record id. + */ int32_t GetAbilityRecordId() const { return abilityRecordId_; @@ -116,7 +122,16 @@ public: void SetEventId(const int64_t eventId); int64_t GetEventId() const; + /** + * @brief SetOwnerUserId set the owner of the ability. + */ void SetOwnerUserId(int32_t ownerUserId); + + /** + * @brief GetOwnerUserId get the owner of the ability. + * + * @return Return the owner's userId. + */ int32_t GetOwnerUserId() const; void SetIsSingleUser(bool flag); bool IsSingleUser() const; @@ -126,6 +141,12 @@ public: int32_t GetUIExtensionAbilityId() const; void SetUserRequestCleaningStatus(); bool IsUserRequestCleaning() const; + + /** + * @brief Whether the ability is scene board. + * + * @return Returns whether the ability is scene board. + */ bool IsSceneBoard() const; private: diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index e0ba147d3e..657f287540 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -107,8 +107,19 @@ public: */ virtual void KillProcessesByUserId(int32_t userId) override; + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + */ virtual void KillProcessesByPids(std::vector &pids) override; + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ virtual void AttachPidToParent(const sptr &token, const sptr &callerToken) override; /** @@ -168,16 +179,54 @@ public: */ virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override; + /** + * KillApplicationSelf, this allows app to terminate itself. + * + * @param clearPageStack, the flag indicates if ClearPageStack lifecycle should be scheduled. + * @return ERR_OK for success call, others for failure. + */ virtual int KillApplicationSelf(const bool clearPageStack = false) override; + /** + * Get application info by process id. + * + * @param pid Process id. + * @param application Application information got. + * @param debug Whether IsDebugApp. + * @return Returns ERR_OK on success, others on failure. + */ int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override; + /** + * Record process exit reason to appRunningRecord + * @param pid pid + * @param reason reason enum + * @param exitMsg exitMsg + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) override; + /** + * AbilityAttachTimeOut, called by ability manager service when an ability is loaded timeout. + * + * @param token indicates the token of the ability which is timeout. + */ virtual void AbilityAttachTimeOut(const sptr &token) override; + /** + * PrepareTerminate, called before terminating one ability by ability manager service to notify application. + * + * @param token indicates the token of the ability to be terminated. + * @param clearMissionFlag indicates whether it is caused by cleaning mission. + */ virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) override; + /** + * GetRunningProcessInfoByToken, get process info for one ability. + * + * @param token indicates the token of the ability requested. + * @param info output of the information. + */ virtual void GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) override; @@ -189,18 +238,50 @@ public: */ void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override; + /** + * Start specified ability. + * + * @param want Want contains information of the ability to start. + * @param abilityInfo Ability information. + * @param requestId request id to callback + */ virtual void StartSpecifiedAbility( const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) override; + /** + * Register response of start specified ability. + * + * @param response Response of start specified ability. + */ virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response) override; + /** + * Start specified process. + * + * @param want Want contains information wish to start. + * @param abilityInfo Ability information. + * @param requestId for callback + */ virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) override; + /** + * SetCurrentUserId, set the userid to app mgr by ability mgr when switching to another user. + * + * @param userId the new user. + */ virtual void SetCurrentUserId(const int32_t userId) override; virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override; + /** + * GetBundleNameByPid, get bundleName and uid of a process. + * + * @param pid input param indicates the pid of the process. + * @param bundleName output for bundleName. + * @param uid output for uid. + * @return ERR_OK for success call, others for failure. + */ virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; /** @@ -281,6 +362,7 @@ public: * @brief Set resident process enable status. * @param bundleName The application bundle name. * @param enable The current updated enable status. + * @param uid indicates user, 0 for all users */ void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) override; @@ -292,8 +374,8 @@ public: virtual void ClearProcessByToken(sptr token) override; /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ virtual bool IsMemorySizeSufficent() override; @@ -328,6 +410,9 @@ public: */ virtual bool IsProcessContainsOnlyUIAbility(const pid_t pid) override; + /** + * Whether a process is attached, refer to AttachApplication + */ virtual bool IsProcessAttached(sptr token) override; virtual bool IsAppKilling(sptr token) override; diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index ce65133609..568b26b85f 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -163,7 +163,7 @@ public: void ScheduleProcessSecurityExit(); /** - * cheduleClearPageStack, call cheduleClearPageStack() through proxy project, + * scheduleClearPageStack, call scheduleClearPageStack() through proxy project, * Notify application clear recovery page stack. * * @return @@ -184,6 +184,12 @@ public: */ sptr GetApplicationClient() const; + /** + * @brief Schedule the given module the onAcceptWant lifecycle call. + * + * @param want the param passed to onAcceptWant lifecycle. + * @param want the moduleName of which being scheduled. + */ void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); @@ -196,14 +202,43 @@ public: */ int32_t UpdateConfiguration(const Configuration &config); + /** + * @brief Notify application load patch. + * + * @param bundleName Bundle name + * @param callback called when LoadPatch finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback, const int32_t recordId); + /** + * @brief Notify application reload page. + * + * @param callback called when HotReload finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t NotifyHotReloadPage(const sptr &callback, const int32_t recordId); + /** + * @brief Notify application unload patch. + * + * @param bundleName Bundle name + * @param callback called when UnloadPatch finished. + * @param recordId callback data + * @return Returns 0 on success, error code on failure. + */ int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback, const int32_t recordId); + /** + * Notify Fault Data + * + * @param faultData the fault data. + * @return Returns ERR_OK on success, others on failure. + */ int32_t NotifyAppFault(const FaultData &faultData); /** @@ -215,7 +250,18 @@ public: */ int32_t ChangeAppGcState(int32_t state); + /** + * @brief attach to a process to debug. + * + * @return ERR_OK, return back success, others fail. + */ int32_t AttachAppDebug(); + + /** + * @brief detach a debugging process. + * + * @return ERR_OK, return back success, others fail. + */ int32_t DetachAppDebug(); /** @@ -233,9 +279,6 @@ public: /** * Notifies the application of process caching. - * - * - * @return */ void ScheduleCacheProcess(); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 7290b87bff..9f8654c168 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -60,7 +60,7 @@ public: virtual ~AppMgrService() override; // the function about application - // attach the application to ams, then ams can control it. + // attach the application to ability mgr, then ability mgr can control it. /** * AttachApplication, call AttachApplication() through proxy object, * get all the information needed to start the Application (data related to the Application ). @@ -162,10 +162,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, @@ -330,32 +330,105 @@ public: */ int Dump(int fd, const std::vector& args) override; + /** + * @brief called when the abilityStage's onAcceptWant lifecycle completed. + * @param recordId record id of the ability. + * @param want want has been accepted. + * @param flag flag get from OnAcceptWant. + */ virtual void ScheduleAcceptWantDone( const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; virtual void ScheduleNewProcessRequestDone( const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; + /** + * Get the token of ability records by process ID. + * + * @param pid The process id. + * @param tokens The token of ability records. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; + /** + * Prestart nwebspawn process. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int PreStartNWebSpawnProcess() override; + /** + * Start nweb render process, called by nweb host. + * + * @param renderParam, params passed to renderProcess. + * @param ipcFd, ipc file descriptor for web browser and render process. + * @param sharedFd, shared memory file descriptor. + * @param crashFd, crash signal file descriptor. + * @param renderPid, created render pid. + * @param isGPU, is or not gpu process + * @return Returns ERR_OK on success, others on failure. + */ virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, int32_t sharedFd, int32_t crashFd, pid_t &renderPid, bool isGPU = false) override; + /** + * Render process call this to attach to app manager service. + * + * @param renderScheduler scheduler of render process. + */ virtual void AttachRenderProcess(const sptr &shceduler) override; + /** + * Get render process termination status, called by nweb host. + * + * @param renderPid, target render pid. + * @param status, termination status of the render process. + * @return Returns ERR_OK on success, others on failure. + */ virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override; + /** + * GetConfiguration + * + * @param info to retrieve configuration data. + * @return ERR_OK ,return back success,others fail. + */ virtual int32_t GetConfiguration(Configuration& config) override; + /** + * UpdateConfiguration, ANotify application update system environment changes. + * + * @param config System environment change parameters. + * @param userId configuration for the user + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override; + /** + * Update config by bundle name. + * + * @param config Application environment change parameters. + * @param name Application bundle name. + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) override; + /** + * @brief register a configuration observer which will receive notifies when updated. + * @param observer the configuration observer to receive notify. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t RegisterConfigurationObserver(const sptr &observer) override; + /** + * @brief unregister a configuration observer registered before. + * @param observer the configuration observer registered before. + * + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t UnregisterConfigurationObserver(const sptr &observer) override; /** @@ -372,12 +445,39 @@ public: */ virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override; + /** + * @brief Get the running state of application by bundle name. + * + * @param bundleName Bundle name + * @return Returns true if process is running, false if process isn't running. + */ bool GetAppRunningStateByBundleName(const std::string &bundleName) override; + /** + * @brief Notify application load patch. + * + * @param bundleName Bundle name + * @param callback called when LoadPatch finished. + * @return Returns ERR_OK on success, error code on failure. + */ int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; + /** + * @brief Notify application reload page. + * + * @param bundleName Bundle name + * @param callback called when HotReload finished. + * @return Returns ERR_OK on success, error code on failure. + */ int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) override; + /** + * @brief Notify application unload patch. + * + * @param bundleName Bundle name + * @param callback called when UnloadPatch finished. + * @return Returns ERR_OK on success, error code on failure. + */ int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE @@ -393,6 +493,11 @@ public: */ virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override; + /** + * start native process for debugger. + * + * @param want param to start a process. + */ virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override; /** @@ -540,28 +645,89 @@ public: */ void ExitChildProcessSafely() override; + /** + * @brief register a render process state observer to receive change. + * @param observer the render process state observer to receive notify. + * + * @return Returns ERR_OK on success, others on failure. + */ int32_t RegisterRenderStateObserver(const sptr &observer) override; + /** + * @brief unregister a render process state observer registered before. + * @param observer the render process state observer registered before. + * + * @return Returns ERR_OK on success, others on failure. + */ int32_t UnregisterRenderStateObserver(const sptr &observer) override; + /** + * @brief update a render process state. + * @param renderPid the pid of the render process to be updated. + * @param state the new state value of the render process. + * + * @return Returns ERR_OK on success, others on failure. + */ int32_t UpdateRenderState(pid_t renderPid, int32_t state) override; + /** + * @brief mark a process which is going restart. + * @param bundleName the bundleName of the process. + * + * @return Returns ERR_OK on success, others on failure. + */ int32_t SignRestartAppFlag(const std::string &bundleName) override; + /** + * Get appRunningUniqueId by pid. + * @param pid pid. + * @param appRunningUniqueId appRunningUniqueId. + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId) override; + /* + * Get all uiextension root host process id, need apply permission ohos.permission.GET_RUNNING_INFO. + * If specified pid mismatch UIExtensionAbility type, return empty vector. + * @param pid Process id. + * @param hostPids All host process id. + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector &hostPids) override; + /** + * Get all uiextension provider process id, need apply permission ohos.permission.GET_RUNNING_INFO. + * If specified hostPid didn't start any UIExtensionAbility, return empty vector. + * @param hostPid Host process id. + * @param providerPids All provider process id started by specified hostPid. + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector &providerPids) override; - int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) override; + /** + * @brief Notify memory size state changed to sufficient or insufficient. + * @param isMemorySizeSufficient Indicates the memory size state. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) override; + /** + * Set application assertion pause state. + * + * @param flag assertion pause state. + */ void SetAppAssertionPauseState(bool flag) override; + /** + * @brief set support process cache by self + */ int32_t SetSupportedProcessCacheSelf(bool isSupport) override; - + int32_t SetSupportedProcessCache(int32_t pid, bool isSupport) override; + /** + * set browser channel for caller + */ virtual void SaveBrowserChannel(sptr browser) override; /** @@ -581,10 +747,19 @@ public: int32_t StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, const sptr &callback) override; + /** + * Notify that the process depends on web by itself. + */ virtual int32_t NotifyProcessDependedOnWeb() override; + /** + * Kill process depended on web by sa. + */ virtual void KillProcessDependedOnWeb() override; + /** + * Restart resident process depended on web. + */ virtual void RestartResidentProcessDependedOnWeb() override; private: /** diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index b24c754bc9..08181b9c76 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -183,8 +183,20 @@ public: */ virtual void KillProcessesByUserId(int32_t userId); + /** + * KillProcessesByPids, only in process call is allowed, + * kill the processes by pid list given. + * + * @param pids, the pid list of processes are going to be killed. + * @return + */ virtual void KillProcessesByPids(std::vector &pids); + /** + * Set child and parent relationship + * @param token child process + * @param callerToken parent process + */ virtual void AttachPidToParent(const sptr &token, const sptr &callerToken); /** @@ -291,6 +303,12 @@ public: */ virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid); + /** + * KillApplicationSelf, this allows app to terminate itself. + * + * @param clearPageStack, the flag indicates if ClearPageStack lifecycle should be scheduled. + * @return ERR_OK for success call, others for failure. + */ virtual int32_t KillApplicationSelf(const bool clearPageStack = false); /** @@ -351,10 +369,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, @@ -473,6 +491,11 @@ public: */ int32_t IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning); + /** + * start native process for debugger. + * + * @param want param to start a process. + */ int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); std::shared_ptr CreateAppRunningRecord( @@ -608,8 +631,19 @@ public: eventHandler_ = eventHandler; } + /** + * HandleAbilityAttachTimeOut, called by ability manager service when an ability is loaded timeout. + * + * @param token indicates the token of the ability which is timeout. + */ void HandleAbilityAttachTimeOut(const sptr &token); + /** + * PrepareTerminate, called before terminating one ability by ability manager service to notify application. + * + * @param token indicates the token of the ability to be terminated. + * @param clearMissionFlag indicates whether it is caused by cleaning mission. + */ void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); void OnAppStateChanged(const std::shared_ptr &appRecord, const ApplicationState state, @@ -619,6 +653,12 @@ public: void OnAppStopped(const std::shared_ptr &appRecord); + /** + * GetRunningProcessInfoByToken, get process info for one ability. + * + * @param token indicates the token of the ability requested. + * @param info output of the information. + */ void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info); int32_t GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const; @@ -715,14 +755,34 @@ public: int FinishUserTest( const std::string &msg, const int64_t &resultCode, const std::string &bundleName, const pid_t &pid); + /** + * Start specified ability. + * + * @param want Want contains information of the ability to start. + * @param abilityInfo Ability information. + * @param requestId request id to callback + */ void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); + /** + * Start specified process. + * + * @param want Want contains information wish to start. + * @param abilityInfo Ability information. + * @param requestId for callback + */ void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0); void RegisterStartSpecifiedAbilityResponse(const sptr &response); + /** + * @brief called when the abilityStage's onAcceptWant lifecycle completed. + * @param recordId record id of the ability. + * @param want want has been accepted. + * @param flag flag get from OnAcceptWant. + */ void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); void ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); @@ -759,6 +819,13 @@ public: int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); + /** + * Record process exit reason to appRunningRecord + * @param pid pid + * @param reason reason enum + * @param exitMsg exitMsg + * @return Returns ERR_OK on success, others on failure. + */ int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg); /** @@ -773,8 +840,21 @@ public: int32_t KillProcessByPid(const pid_t pid, const std::string& reason = "foundation"); + /** + * @brief Get the running state of application by bundle name. + * + * @param bundleName Bundle name + * @return Returns true if process is running, false if process isn't running. + */ bool GetAppRunningStateByBundleName(const std::string &bundleName); + /** + * @brief Notify application load patch. + * + * @param bundleName Bundle name + * @param callback called when LoadPatch finished. + * @return Returns ERR_OK on success, error code on failure. + */ int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback); int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback); @@ -1101,28 +1181,60 @@ public: bool IsFinalAppProcessByBundleName(const std::string &bundleName); /** - * @brief Notify memory size state changed to sufficient or insufficent. - * @param isMemorySizeSufficent Indicates the memory size state. + * @brief Notify memory size state changed to sufficient or insufficient. + * @param isMemorySizeSufficient Indicates the memory size state. * @return Returns ERR_OK on success, others on failure. */ - int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent); + int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient); /** - * whether memory size is sufficent. - * @return Returns true is sufficent memory size, others return false. + * whether memory size is sufficient. + * @return Returns true is sufficient memory size, others return false. */ - bool IsMemorySizeSufficent(); + bool IsMemorySizeSufficient(); + /** + * Register render state observer. + * @param observer Render process state observer. + * @return Returns ERR_OK on success, others on failure. + */ int32_t RegisterRenderStateObserver(const sptr &observer); + /** + * Unregister render state observer. + * @param observer Render process state observer. + * @return Returns ERR_OK on success, others on failure. + */ int32_t UnregisterRenderStateObserver(const sptr &observer); + /** + * Update render state. + * @param renderPid Render pid. + * @param state foreground or background state. + * @return Returns ERR_OK on success, others on failure. + */ int32_t UpdateRenderState(pid_t renderPid, int32_t state); + /** + * Mark processes of a bundleName as the app is going to be restarted. + */ int32_t SignRestartAppFlag(const std::string &bundleName); + /** + * Set application assertion pause state. + * + * @param flag assertion pause state. + */ void SetAppAssertionPauseState(bool flag); + /** + * @brief A process can config itself to keep alive or not. + * when one process started, this method will be called from ability mgr with data selected from db. + * + * @param bundleName processed of witch to be configed + * @param enable config value + * @param uid indicates user, 0 for all users + */ void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid); int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId); @@ -1145,12 +1257,19 @@ public: virtual int DumpFfrt(const std::vector& pids, std::string& result); + /** + * @brief set support process cache by self + */ int32_t SetSupportedProcessCacheSelf(bool isSupport); int32_t SetSupportedProcessCache(int32_t pid, bool isSupport); void OnAppCacheStateChanged(const std::shared_ptr &appRecord, ApplicationState state); + /** + * set browser channel for caller + * @param hostPid caller pid + */ virtual void SaveBrowserChannel(const pid_t hostPid, sptr browser); bool IsAppProcessesAllCached(const std::string &bundleName, int32_t uid, @@ -1168,7 +1287,10 @@ public: void SetSceneBoardAttachFlag(bool flag); - void CacheLoadAbilityTask(const LoadAbilityTaskFunc& func); + /** + * Scene board has the highest priority. If Scene board is loading cache other apps' request. + */ + void CacheLoadAbilityTask(const LoadAbilityTaskFunc&& func); void SubmitCacheLoadAbilityTask(); /** @@ -1189,14 +1311,32 @@ public: bool CleanAbilityByUserRequest(const sptr &token); + /** + * whether killed for upgrade web. + * + * @param bundleName the bundle name is killed for upgrade web. + * @return Returns true is killed for upgrade web, others return false. + */ bool IsKilledForUpgradeWeb(const std::string &bundleName) const; bool IsProcessContainsOnlyUIAbility(const pid_t pid); + /** + * Whether a process is attached, refer to AttachApplication + */ bool IsProcessAttached(sptr token) const; + /** + * Is a process of a ability will be killed + * @param indicates the ability + */ bool IsAppKilling(sptr token) const; + /** + * @brief Notify abilityms app process pre cache + * @param pid process pid. + * @param userId userId Designation User ID. + */ void NotifyAppPreCache(int32_t pid, int32_t userId); /** @@ -1208,8 +1348,18 @@ public: */ virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector &pidList); + /** + * Register KIA interceptor. + * @param interceptor KIA interceptor. + * @return Returns ERR_OK on success, others on failure. + */ virtual int32_t RegisterKiaInterceptor(const sptr &interceptor); + /** + * Check if the given pid is a KIA process. + * @param pid process id. + * @return Returns true if it is a KIA process, false otherwise. + */ virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia); private: @@ -1220,25 +1370,43 @@ private: FaultData ConvertDataTypes(const AppFaultDataBySA &faultData); + /** + * Start a empty resident process + */ void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount, bool isEmptyKeepAliveApp); + /** + * If one app needs keepalive and dies, restart the app again + */ void RestartResidentProcess(std::shared_ptr appRecord); bool CheckLoadAbilityConditions(const sptr &token, const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo); + /** + * query bundle info for the given bundleName + */ bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo); bool GenerateRenderUid(int32_t &renderUid); + /** + * Build a process's name for service extension + */ void MakeServiceExtProcessName(const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo, std::string &processName) const; + /** + * Build a process's name for the info given + */ void MakeProcessName(const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo, const HapModuleInfo &hapModuleInfo, int32_t appIndex, const std::string &specifiedProcessFlag, std::string &processName) const; + /** + * Build a process's name based on the info given + */ void MakeProcessName(const std::shared_ptr &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName) const; @@ -1360,9 +1528,20 @@ private: void InitGlobalConfiguration(); + /** + * @brief Another way of GetRunningProcess, only one item will be filled into the info + */ void GetRunningProcesses(const std::shared_ptr &appRecord, std::vector &info); + /** + * @brief Retrieve a process's running info + */ void GetRunningProcess(const std::shared_ptr &appRecord, RunningProcessInfo &info); + /** + * @brief query a process's render process info + * @param appRecord the main process + * @param info to retrieve render process info + */ void GetRenderProcesses(const std::shared_ptr &appRecord, std::vector &info); void GetChildrenProcesses(const std::shared_ptr &appRecord, std::vector &info); @@ -1379,10 +1558,16 @@ private: bool VerifyAPL() const; + /** + * Register a focus listener to window manager + */ void RegisterFocusListener(); static void PointerDeviceEventCallback(const char *key, const char *value, void *context); + /** + * Verify whether the caller has the permission to kill processes of a bundleName. + */ int VerifyKillProcessPermission(const std::string &bundleName) const; int32_t VerifyKillProcessPermissionCommon() const; @@ -1404,6 +1589,10 @@ private: void OnChildProcessRemoteDied(const wptr &remote); + /** + * kill all child processed of a main process + * @param appRecord indicates the main process + */ void KillChildProcess(const std::shared_ptr &appRecord); void KillAttachedChildProcess(const std::shared_ptr &appRecord); @@ -1431,6 +1620,11 @@ private: bool CheckGetRunningInfoPermission() const; + /** + * kill all processes of a bundleName + * @param bundleName bundleName of which to be killed + * @param clearPageStack should schedule clearPage lifecycle + */ int32_t KillApplicationByBundleName( const std::string &bundleName, const bool clearPageStack = false); @@ -1454,6 +1648,10 @@ private: void RemoveRunningSharedBundleList(const std::string &bundleName); + /** + * kill one process's render process + * @param appRecord the main process + */ void KillRenderProcess(const std::shared_ptr &appRecord); void SetOverlayInfo(const std::string& bundleName, const int32_t userId, AppSpawnStartMsg& startMsg); @@ -1466,8 +1664,8 @@ private: void ProcessAppDebug(const std::shared_ptr &appRecord, const bool &isDebugStart); AppDebugInfo MakeAppDebugInfo(const std::shared_ptr &appRecord, const bool &isDebugStart); - int32_t NotifyAbilitysDebugChange(const std::string &bundleName, const bool &isAppDebug); - int32_t NotifyAbilitysAssertDebugChange(const std::shared_ptr &appRecord, bool isAssertDebug); + int32_t NotifyAbilitiesDebugChange(const std::string &bundleName, const bool &isAppDebug); + int32_t NotifyAbilitiesAssertDebugChange(const std::shared_ptr &appRecord, bool isAssertDebug); void SetProcessJITState(const std::shared_ptr appRecord); @@ -1518,6 +1716,9 @@ private: const std::shared_ptr &appInfo, const std::string &processName, AppSpawnStartMsg &startMsg); + /** + * Build message body for app spawn + */ int32_t CreateStartMsg(const std::string &processName, uint32_t startFlags, const int uid, const BundleInfo &bundleInfo, const int32_t bundleIndex, BundleType bundleType, AppSpawnStartMsg &startMsg, std::shared_ptr want, const std::string &moduleName = "", const std::string &abilityName = "", @@ -1534,10 +1735,20 @@ private: void SetAppInfo(const BundleInfo &bundleInfo, AppSpawnStartMsg &startMsg); + /** + * Query ability for one want param + */ bool CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo); + /** + * Build event info for one app record + */ AAFwk::EventInfo BuildEventInfo(std::shared_ptr appRecord) const; + /** + * @brief Call the callbacks to notify one process should go dying due fatal error. + * @param appRecord indicates the process is going to die. + */ void NotifyAppAttachFailed(std::shared_ptr appRecord); private: /** @@ -1605,7 +1816,7 @@ private: sptr windowVisibilityChangedListener_; sptr windowPidVisibilityChangedListener_; #endif //SUPPORT_SCREEN - std::vector> restartResedentTaskList_; + std::vector> restartResidentTaskList_; std::map> runningSharedBundleList_; std::map waitingDebugBundleList_; ffrt::mutex waitingDebugLock_; @@ -1617,7 +1828,7 @@ private: int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS; sptr abilityDebugResponse_; std::shared_ptr appDebugManager_; - ffrt::mutex killpedProcessMapLock_; + ffrt::mutex killedProcessMapLock_; mutable std::map killedProcessMap_; ffrt::mutex startChildProcessLock_; std::vector serviceExtensionWhiteList_; diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index a3eb1c4ed6..9016b85ea2 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -79,11 +79,11 @@ public: * CheckAppRunningRecordIsExist, Check whether the process of the app exists by bundle name and process Name. * * @param bundleName, Indicates the bundle name of the bundle.. - * @param ablityName, ablity name. + * @param abilityName, ability name. * * @return true if exist. */ - bool CheckAppRunningRecordIsExist(const std::string &bundleName, const std::string &ablityName); + bool CheckAppRunningRecordIsExist(const std::string &bundleName, const std::string &abilityName); #endif /** diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 3c8b82fef4..92cb428235 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -308,15 +308,39 @@ public: */ sptr GetApplicationClient() const; + /** + * @brief Load a module and schedule the stage's lifecycle + * @param appInfo app info + * @param abilityInfo ability info + * @param token the ability's token + * @param hapModuleInfo module info + * @param want starting ability param + * @param abilityRecordId the record id of the ability + */ void AddModule(std::shared_ptr appInfo, std::shared_ptr abilityInfo, sptr token, const HapModuleInfo &hapModuleInfo, std::shared_ptr want, int32_t abilityRecordId); + /** + * @brief Batch adding modules whose stages will be loaded + * @param appInfo app info + * @param moduleInfos list of modules to be added + */ void AddModules(const std::shared_ptr &appInfo, const std::vector &moduleInfos); + /** + * @brief Search a module record by bundleName and moduleName + * @param bundleName bundleName of the module + * @param moduleName moduleName of the module + * @return the module record matched the params or null + */ std::shared_ptr GetModuleRecordByModuleName( - const std::string bundleName, const std::string &moduleName); + const std::string &bundleName, const std::string &moduleName); + /** + * @brief Get one ability's module record + * @param token represents the ability + */ std::shared_ptr GetModuleRunningRecordByToken(const sptr &token) const; std::shared_ptr GetModuleRunningRecordByTerminateLists(const sptr &token) const; @@ -446,7 +470,7 @@ public: * * @param token, the unique identification to the ability. * - * @return + * @return ability running record */ std::shared_ptr GetAbilityRunningRecordByToken(const sptr &token) const; @@ -528,27 +552,69 @@ public: int64_t GetEventId() const; + /** + * When the one process has no ability, it will go dying. + */ bool IsLastAbilityRecord(const sptr &token); bool IsLastPageAbilityRecord(const sptr &token); bool ExtensionAbilityRecordExists(); + /** + * @brief indicates one process will go dying. + * Then the process won't be reused. + */ void SetTerminating(); + /** + * @brief Whether the process is dying. + */ bool IsTerminating(); + /** + * @brief Whether the process should keep alive. + */ bool IsKeepAliveApp() const; + /** + * @brief Whether the process can keep empty alive. + */ bool IsEmptyKeepAliveApp() const; + /** + * @brief Whether the process is main process. + */ bool IsMainProcess() const; + /** + * @brief indicates one process can stay alive without any abilities. + * One case is that the process's stages being loaded + * + * @param isEmptyKeepAliveApp new value + */ void SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp); + /** + * @brief A process can config itself to keep alive or not. + * when one process started, this method will be called from ability mgr with data selected from db. + * + * @param isKeepAliveEnable new value + */ void SetKeepAliveEnableState(bool isKeepAliveEnable); + + /** + * @brief roughly considered as a value from the process's bundle info. + * + * @param isKeepAliveBundle new value + */ void SetKeepAliveBundle(bool isKeepAliveBundle); + /** + * @brief only the bundle's main process can stay alive. + * + * @param isMainProcess new value + */ void SetMainProcess(bool isMainProcess); void SetSingleton(bool isSingleton); @@ -594,21 +660,48 @@ public: void SetProcessAndExtensionType(const std::shared_ptr &abilityInfo); void SetSpecifiedAbilityFlagAndWant(int requestId, const AAFwk::Want &want, const std::string &moduleName); void SetScheduleNewProcessRequestState(int32_t requestId, const AAFwk::Want &want, const std::string &moduleName); + /** + * Is processing new process request + */ bool IsNewProcessRequest() const; + /** + * Is processing specified ability request + */ bool IsStartSpecifiedAbility() const; + /** + * Get the specified requestId, -1 for none specified + */ int32_t GetSpecifiedRequestId() const; + /** + * Called when one specified request is finished to set the request id to -1 + */ void ResetSpecifiedRequestId(); + /** + * call the scheduler to go acceptWant procedure + */ void ScheduleAcceptWant(const std::string &moduleName); + /** + * Called when acceptWant complete + */ void ScheduleAcceptWantDone(); void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); void ScheduleNewProcessRequestDone(); void ApplicationTerminated(); + /** + * Get the want param for specified request + */ AAFwk::Want GetSpecifiedWant() const; AAFwk::Want GetNewProcessRequestWant() const; int32_t GetNewProcessRequestId() const; void ResetNewProcessRequestId(); void SetDebugApp(bool isDebugApp); + /** + * Indicate whether the process is a debugging one + */ bool IsDebugApp(); + /** + * debug flag or assert flag is set + */ bool IsDebugging() const; void SetErrorInfoEnhance(const bool errorInfoEnhance); void SetNativeDebug(bool isNativeDebug); @@ -680,12 +773,18 @@ public: ExtensionAbilityType GetExtensionType() const; ProcessType GetProcessType() const; + /** + * Notify Fault Data + * + * @param faultData the fault data. + * @return Returns ERR_OK on success, others on failure. + */ int32_t NotifyAppFault(const FaultData &faultData); #ifdef SUPPORT_SCREEN void ChangeWindowVisibility(const sptr &info); void OnWindowVisibilityChanged(const std::vector> &windowVisibilityInfos); #endif //SUPPORT_SCREEN - bool IsAbilitytiesBackground(); + bool IsAbilitiesBackground(); inline void SetAbilityForegroundingFlag() { @@ -930,7 +1029,6 @@ private: std::shared_ptr appInfo_ = nullptr; // the application's info of this process int32_t appRecordId_ = 0; - std::string appName_; std::string processName_; // the name of this process std::string specifiedProcessFlag_; // the flag of specified Process int64_t eventId_ = 0; diff --git a/services/appmgr/include/child_process_record.h b/services/appmgr/include/child_process_record.h index cdc00f3f48..50e30d6a61 100644 --- a/services/appmgr/include/child_process_record.h +++ b/services/appmgr/include/child_process_record.h @@ -78,6 +78,7 @@ private: std::string processName_; std::string srcEntry_; std::string entryFunc_; + std::map fds_; std::weak_ptr hostRecord_; sptr scheduler_ = nullptr; sptr deathRecipient_ = nullptr; diff --git a/services/appmgr/include/exit_resident_process_manager.h b/services/appmgr/include/exit_resident_process_manager.h index 5bd0d39b17..a6d5381ee0 100644 --- a/services/appmgr/include/exit_resident_process_manager.h +++ b/services/appmgr/include/exit_resident_process_manager.h @@ -44,7 +44,7 @@ class ExitResidentProcessManager { public: static ExitResidentProcessManager &GetInstance(); ~ExitResidentProcessManager(); - bool IsMemorySizeSufficent() const; + bool IsMemorySizeSufficient() const; bool RecordExitResidentBundleName(const std::string &bundleName, int32_t uid); void RecordExitResidentBundleDependedOnWeb(const std::string &bundleName, int32_t uid); int32_t HandleMemorySizeInSufficent(); diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index f2dadb444c..137d6fbd6b 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -90,7 +90,7 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr &abilityInf // cache other application load ability task before scene board attach if (!amsMgrServiceInner_->GetSceneBoardAttachFlag() && abilityInfo->bundleName != SCENE_BOARD_BUNDLE_NAME) { - amsMgrServiceInner_->CacheLoadAbilityTask(loadAbilityFunc); + amsMgrServiceInner_->CacheLoadAbilityTask(std::move(loadAbilityFunc)); return; } if (abilityInfo->bundleName == SCENE_BOARD_BUNDLE_NAME && abilityInfo->name == SCENEBOARD_ABILITY_NAME) { @@ -629,7 +629,7 @@ bool AmsMgrScheduler::IsMemorySizeSufficent() TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); return true; } - return amsMgrServiceInner_->IsMemorySizeSufficent(); + return amsMgrServiceInner_->IsMemorySizeSufficient(); } void AmsMgrScheduler::AttachedToStatusBar(const sptr &token) diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index c5622fa46d..a6f9dbbd89 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -60,8 +60,11 @@ constexpr const char* TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTa constexpr const char* TASK_APPLICATION_BACKGROUNDED = "ApplicationBackgroundedTask"; constexpr const char* TASK_APPLICATION_TERMINATED = "ApplicationTerminatedTask"; constexpr const char* TASK_ABILITY_CLEANED = "AbilityCleanedTask"; +<<<<<<< HEAD // constexpr const char* TASK_ADD_APP_DEATH_RECIPIENT = "AddAppRecipientTask"; // constexpr const char* TASK_CLEAR_UP_APPLICATION_DATA = "ClearUpApplicationDataTask"; +======= +>>>>>>> upstream/master constexpr const char* TASK_STARTUP_RESIDENT_PROCESS = "StartupResidentProcess"; constexpr const char* TASK_ADD_ABILITY_STAGE_DONE = "AddAbilityStageDone"; constexpr const char* TASK_START_USER_TEST_PROCESS = "StartUserTestProcess"; @@ -1510,14 +1513,14 @@ int32_t AppMgrService::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector

GetAllUIExtensionProviderPid(hostPid, providerPids); } -int32_t AppMgrService::NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) +int32_t AppMgrService::NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) { if (!IsReady()) { TAG_LOGE(AAFwkTag::APPMGR, "not ready"); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->NotifyMemorySizeStateChanged(isMemorySizeSufficent); + return appMgrServiceInner_->NotifyMemorySizeStateChanged(isMemorySizeSufficient); } int32_t AppMgrService::SetSupportedProcessCacheSelf(bool isSupport) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 183e1196be..4d2bd072b4 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2249,7 +2249,7 @@ int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid, const std::string& eventInfo.versionCode = applicationInfo->versionCode; } if (ret >= 0) { - std::lock_guard lock(killpedProcessMapLock_); + std::lock_guard lock(killedProcessMapLock_); int64_t killTime = std::chrono::duration_cast(std::chrono:: system_clock::now().time_since_epoch()).count(); killedProcessMap_.emplace(killTime, appRecord->GetProcessName()); @@ -2600,7 +2600,7 @@ void AppMgrServiceInner::KillProcessByAbilityToken(const sptr &to // before exec ScheduleProcessSecurityExit return // The resident process won't let him die - if (appRecord->IsKeepAliveApp() && IsMemorySizeSufficent()) { + if (appRecord->IsKeepAliveApp() && IsMemorySizeSufficient()) { return; } @@ -3469,7 +3469,7 @@ bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr(std::chrono:: system_clock::now().time_since_epoch()).count(); for (auto iter = killedProcessMap_.begin(); iter != killedProcessMap_.end();) { @@ -3948,9 +3948,9 @@ void AppMgrServiceInner::RestartResidentProcess(std::shared_ptr &appRunningRecord) { return (appRecord != nullptr && appRecord->GetBundleName() == appRunningRecord->GetBundleName()); }; - auto findIter = find_if(restartResedentTaskList_.begin(), restartResedentTaskList_.end(), findRestartResidentTask); - if (findIter != restartResedentTaskList_.end()) { - restartResedentTaskList_.erase(findIter); + auto findIter = find_if(restartResidentTaskList_.begin(), restartResidentTaskList_.end(), findRestartResidentTask); + if (findIter != restartResidentTaskList_.end()) { + restartResidentTaskList_.erase(findIter); } if (!CheckRemoteClient() || !appRecord || !appRunningManager_) { @@ -3961,8 +3961,11 @@ void AppMgrServiceInner::RestartResidentProcess(std::shared_ptrGetBundleManagerHelper(); BundleInfo bundleInfo; auto userId = GetUserIdByUid(appRecord->GetUid()); + auto flags = BundleFlag::GET_BUNDLE_DEFAULT | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION; if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo( - appRecord->GetBundleName(), BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { + appRecord->GetBundleName(), + static_cast(flags), + bundleInfo, userId))) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail"); return; } @@ -6344,7 +6347,7 @@ int32_t AppMgrServiceInner::AttachAppDebug(const std::string &bundleName) appDebugManager_->StartDebug(debugInfos); } - NotifyAbilitysDebugChange(bundleName, true); + NotifyAbilitiesDebugChange(bundleName, true); return ERR_OK; } @@ -6370,7 +6373,7 @@ int32_t AppMgrServiceInner::DetachAppDebug(const std::string &bundleName) } } - NotifyAbilitysDebugChange(bundleName, false); + NotifyAbilitiesDebugChange(bundleName, false); return ERR_OK; } @@ -6582,7 +6585,7 @@ int32_t AppMgrServiceInner::RegisterAbilityDebugResponse(const sptr &appRecord, bool isAssertDebug) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); @@ -6682,10 +6685,10 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptrGetBundleName()) && ExitResidentProcessManager::GetInstance().RecordExitResidentBundleName(appRecord->GetBundleName(), appRecord->GetUid())) { - TAG_LOGI(AAFwkTag::APPMGR, "memory size insufficent"); + TAG_LOGI(AAFwkTag::APPMGR, "memory size insufficient"); return; } - TAG_LOGI(AAFwkTag::APPMGR, "memory size sufficent"); + TAG_LOGI(AAFwkTag::APPMGR, "memory size sufficient"); auto restartProcess = [appRecord, innerService = shared_from_this()]() { innerService->RestartResidentProcess(appRecord); }; @@ -6700,13 +6703,13 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptrGetBundleName() == appRunningRecord->GetBundleName()); }; - auto findIter = find_if(restartResedentTaskList_.begin(), restartResedentTaskList_.end(), + auto findIter = find_if(restartResidentTaskList_.begin(), restartResidentTaskList_.end(), findRestartResidentTask); - if (findIter != restartResedentTaskList_.end()) { + if (findIter != restartResidentTaskList_.end()) { TAG_LOGW(AAFwkTag::APPMGR, "reboot task already registered"); return; } - restartResedentTaskList_.emplace_back(appRecord); + restartResidentTaskList_.emplace_back(appRecord); TAG_LOGD(AAFwkTag::APPMGR, "Post restart resident process delay task."); taskHandler_->SubmitTask(restartProcess, "RestartResidentProcessDelayTask", RESTART_INTERVAL_TIME); } @@ -7372,7 +7375,7 @@ void AppMgrServiceInner::SetAppAssertionPauseState(bool flag) flag ? appDebugManager_->StartDebug(debugInfos) : appDebugManager_->StopDebug(debugInfos); } - NotifyAbilitysAssertDebugChange(appRecord, flag); + NotifyAbilitiesAssertDebugChange(appRecord, flag); } int32_t AppMgrServiceInner::UpdateRenderState(pid_t renderPid, int32_t state) @@ -7477,10 +7480,10 @@ int32_t AppMgrServiceInner::GetAllUIExtensionProviderPid(pid_t hostPid, std::vec return appRunningManager_->GetAllUIExtensionProviderPid(hostPid, providerPids); } -int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) +int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) { - TAG_LOGI(AAFwkTag::APPMGR, "isMemorySizeSufficent: %{public}d", - isMemorySizeSufficent); + TAG_LOGI(AAFwkTag::APPMGR, "isMemorySizeSufficient: %{public}d", + isMemorySizeSufficient); bool isMemmgrCall = AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission( MEMMGR_PROC_NAME); bool isSupportCall = OHOS::system::GetBoolParameter(SUPPORT_CALL_NOTIFY_MEMORY_CHANGED, false); @@ -7489,7 +7492,7 @@ int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSuffic return ERR_PERMISSION_DENIED; } - if (!isMemorySizeSufficent) { + if (!isMemorySizeSufficient) { auto ret = ExitResidentProcessManager::GetInstance().HandleMemorySizeInSufficent(); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "handleMemorySizeInSufficent fail, ret: %{public}d", ret); @@ -7517,9 +7520,9 @@ int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSuffic return ERR_OK; } -bool AppMgrServiceInner::IsMemorySizeSufficent() +bool AppMgrServiceInner::IsMemorySizeSufficient() { - return ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent(); + return ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient(); } void AppMgrServiceInner::NotifyAppPreCache(int32_t pid, int32_t userId) @@ -7738,10 +7741,10 @@ int32_t AppMgrServiceInner::StartNativeChildProcess(const pid_t hostPid, const s return StartChildProcessImpl(nativeChildRecord, appRecord, dummyChildPid, args, options); } -void AppMgrServiceInner::CacheLoadAbilityTask(const LoadAbilityTaskFunc& func) +void AppMgrServiceInner::CacheLoadAbilityTask(const LoadAbilityTaskFunc&& func) { std::lock_guard lock(loadTaskListMutex_); - loadAbilityTaskFuncList_.emplace_back(func); + loadAbilityTaskFuncList_.emplace_back(std::move(func)); } void AppMgrServiceInner::SubmitCacheLoadAbilityTask() diff --git a/services/appmgr/src/app_preloader.cpp b/services/appmgr/src/app_preloader.cpp index e45b221e52..e610fbb3f5 100644 --- a/services/appmgr/src/app_preloader.cpp +++ b/services/appmgr/src/app_preloader.cpp @@ -134,8 +134,10 @@ bool AppPreloader::GetBundleAndHapInfo(const std::string &bundleName, int32_t us return false; } - if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, - userId))) { + auto flags = BundleFlag::GET_BUNDLE_DEFAULT | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION; + if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(bundleName, + static_cast(flags), + bundleInfo, userId))) { TAG_LOGE(AAFwkTag::APPMGR, "GetBundleInfo failed"); return false; } diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index fbd793d90c..b171a67a93 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -166,7 +166,7 @@ std::shared_ptr AppRunningManager::CheckAppRunningRecordIsExis } #ifdef APP_NO_RESPONSE_DIALOG -bool AppRunningManager::CheckAppRunningRecordIsExist(const std::string &bundleName, const std::string &ablityName) +bool AppRunningManager::CheckAppRunningRecordIsExist(const std::string &bundleName, const std::string &abilityName) { std::lock_guard guard(runningRecordMapMutex_); if (appRunningRecordMap_.empty()) { @@ -183,7 +183,7 @@ bool AppRunningManager::CheckAppRunningRecordIsExist(const std::string &bundleNa const auto &abilityRunningRecordMap = appRecord->GetAbilities(); for (const auto &abilityItem : abilityRunningRecordMap) { const auto &abilityRunning = abilityItem.second; - if (abilityRunning && abilityRunning->GetName() == ablityName) { + if (abilityRunning && abilityRunning->GetName() == abilityName) { return true; } } @@ -283,7 +283,7 @@ bool AppRunningManager::ProcessExitByBundleName( // condition [!appRecord->IsKeepAliveApp()] Is to not kill the resident process. // Before using this method, consider whether you need. if (appRecord && (!appRecord->IsKeepAliveApp() || - !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent())) { + !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient())) { pid_t pid = appRecord->GetPriorityObject()->GetPid(); auto appInfoList = appRecord->GetAppInfoList(); auto isExist = [&bundleName](const std::shared_ptr &appInfo) { @@ -567,7 +567,7 @@ void AppRunningManager::HandleAbilityAttachTimeOut(const sptr &to } if ((isPage || appRecord->IsLastAbilityRecord(token)) && (!appRecord->IsKeepAliveApp() || - !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent())) { + !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient())) { appRecord->SetTerminating(); } @@ -601,7 +601,7 @@ void AppRunningManager::PrepareTerminate(const sptr &token, bool auto isLastAbility = clearMissionFlag ? appRecord->IsLastPageAbilityRecord(token) : appRecord->IsLastAbilityRecord(token); if (isLastAbility && (!appRecord->IsKeepAliveApp() || - !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent())) { + !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient())) { auto cacheProcMgr = DelayedSingleton::GetInstance(); if (cacheProcMgr != nullptr && cacheProcMgr->IsAppShouldCache(appRecord)) { cacheProcMgr->PenddingCacheProcess(appRecord); @@ -663,7 +663,7 @@ void AppRunningManager::TerminateAbility(const sptr &token, bool #endif //SUPPORT_SCREEN auto isLauncherApp = appRecord->GetApplicationInfo()->isLauncherApp; if (isLastAbility && (!appRecord->IsKeepAliveApp() || - !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent()) && !isLauncherApp) { + !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !isLauncherApp) { auto cacheProcMgr = DelayedSingleton::GetInstance(); if (cacheProcMgr != nullptr && cacheProcMgr->IsAppShouldCache(appRecord)) { cacheProcMgr->PenddingCacheProcess(appRecord); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index c86a018e1b..f31a2ed4a2 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -404,13 +404,13 @@ const std::string &AppRunningRecord::GetAppIdentifier() const const std::map, std::shared_ptr> AppRunningRecord::GetAbilities() { - std::map, std::shared_ptr> abilitysMap; + std::map, std::shared_ptr> abilitiesMap; auto moduleRecordList = GetAllModuleRecord(); for (const auto &moduleRecord : moduleRecordList) { auto abilities = moduleRecord->GetAbilities(); - abilitysMap.insert(abilities.begin(), abilities.end()); + abilitiesMap.insert(abilities.begin(), abilities.end()); } - return abilitysMap; + return abilitiesMap; } sptr AppRunningRecord::GetApplicationClient() const @@ -808,7 +808,7 @@ void AppRunningRecord::AddModule(std::shared_ptr appInfo, } std::shared_ptr AppRunningRecord::GetModuleRecordByModuleName( - const std::string bundleName, const std::string &moduleName) + const std::string &bundleName, const std::string &moduleName) { TAG_LOGD(AAFwkTag::APPMGR, "called"); auto moduleRecords = hapModules_.find(bundleName); @@ -1208,14 +1208,14 @@ void AppRunningRecord::AbilityTerminated(const sptr &token) EVENT_KEY_BUNDLE_NAME, appInfo->bundleName, EVENT_KEY_SUPPORT_STATE, state); if (moduleRecord->GetAbilities().empty() && (!IsKeepAliveApp() || AAFwk::UIExtensionUtils::IsUIExtension(GetExtensionType()) - || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent()) && !needCache) { + || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !needCache) { RemoveModuleRecord(moduleRecord, isExtensionDebug); } auto moduleRecordList = GetAllModuleRecord(); if (moduleRecordList.empty() && (!IsKeepAliveApp() || AAFwk::UIExtensionUtils::IsUIExtension(GetExtensionType()) - || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent()) && !isExtensionDebug + || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !isExtensionDebug && !needCache) { ScheduleTerminate(); } @@ -1981,7 +1981,7 @@ int32_t AppRunningRecord::NotifyAppFault(const FaultData &faultData) return appLifeCycleDeal_->NotifyAppFault(faultData); } -bool AppRunningRecord::IsAbilitytiesBackground() +bool AppRunningRecord::IsAbilitiesBackground() { std::lock_guard hapModulesLock(hapModulesLock_); for (const auto &iter : hapModules_) { @@ -2014,7 +2014,7 @@ void AppRunningRecord::ChangeWindowVisibility(const sptrwindowId_); if (iter != windowIds_.end() && info->visibilityState_ == OHOS::Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) { @@ -2063,7 +2063,7 @@ void AppRunningRecord::OnWindowVisibilityChanged( SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING); ScheduleForegroundRunning(); } - if (windowIds_.empty() && IsAbilitytiesBackground() && curState_ == ApplicationState::APP_STATE_FOREGROUND) { + if (windowIds_.empty() && IsAbilitiesBackground() && curState_ == ApplicationState::APP_STATE_FOREGROUND) { SetApplicationPendingState(ApplicationPendingState::BACKGROUNDING); ScheduleBackgroundRunning(); } @@ -2072,7 +2072,7 @@ void AppRunningRecord::OnWindowVisibilityChanged( if (!windowIds_.empty()) { SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING); } - if (windowIds_.empty() && IsAbilitytiesBackground()) { + if (windowIds_.empty() && IsAbilitiesBackground()) { SetApplicationPendingState(ApplicationPendingState::BACKGROUNDING); } } diff --git a/services/appmgr/src/child_process_record.cpp b/services/appmgr/src/child_process_record.cpp index 2e607d8720..327acb41d6 100644 --- a/services/appmgr/src/child_process_record.cpp +++ b/services/appmgr/src/child_process_record.cpp @@ -27,6 +27,7 @@ ChildProcessRecord::ChildProcessRecord(pid_t hostPid, const ChildProcessRequest hostRecord_(hostRecord), isStartWithDebug_(request.isStartWithDebug) { srcEntry_ = request.srcEntry; + fds_ = request.args.fds; if (childProcessType_ == CHILD_PROCESS_TYPE_NATIVE_ARGS) { auto pos = request.srcEntry.rfind(":"); if (pos != std::string::npos) { @@ -49,6 +50,9 @@ ChildProcessRecord::ChildProcessRecord(pid_t hostPid, const std::string &libName ChildProcessRecord::~ChildProcessRecord() { TAG_LOGD(AAFwkTag::APPMGR, "called"); + for (const auto &item : fds_) { + close(item.second); + } } std::shared_ptr ChildProcessRecord::CreateChildProcessRecord(pid_t hostPid, diff --git a/services/appmgr/src/exit_resident_process_manager.cpp b/services/appmgr/src/exit_resident_process_manager.cpp index 3760dc3594..fe24afb8c9 100644 --- a/services/appmgr/src/exit_resident_process_manager.cpp +++ b/services/appmgr/src/exit_resident_process_manager.cpp @@ -37,7 +37,7 @@ ExitResidentProcessManager &ExitResidentProcessManager::GetInstance() return instance; } -bool ExitResidentProcessManager::IsMemorySizeSufficent() const +bool ExitResidentProcessManager::IsMemorySizeSufficient() const { std::lock_guard lock(mutexLock_); return currentMemorySizeState_ == MemorySizeState::MEMORY_SIZE_SUFFICIENT; diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 935cc0c5a9..d9ddbef444 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -536,34 +536,22 @@ bool PermissionVerification::VerifyKillProcessDependedOnWebPermission() const bool PermissionVerification::VerifyBlockAllAppStartPermission() const { - if (!IsSACall()) { - TAG_LOGE(AAFwkTag::DEFAULT, "not SA call"); - return false; + if (IsSACall() && VerifyCallingPermission(PermissionConstants::PERMISSION_BLOCK_ALL_APP_START)) { + TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); + return true; } -#ifdef ENABLE_BLOCK_ALL_APP_START - if (!VerifyCallingPermission(PermissionConstants::PERMISSION_BLOCK_ALL_APP_START)) { - TAG_LOGE(AAFwkTag::DEFAULT, "no PERMISSION_BLOCK_ALL_APP_START"); - return false; - } -#endif - TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); - return true; + TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied"); + return false; } bool PermissionVerification::VerifyStartUIAbilityToHiddenPermission() const { - if (!IsSACall()) { - TAG_LOGE(AAFwkTag::DEFAULT, "not SA call"); - return false; + if (IsSACall() && VerifyCallingPermission(PermissionConstants::PERMISSION_START_UIABILITY_TO_HIDDEN)) { + TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); + return true; } -#ifdef ENABLE_BLOCK_ALL_APP_START - if (!VerifyCallingPermission(PermissionConstants::PERMISSION_START_UIABILITY_TO_HIDDEN)) { - TAG_LOGE(AAFwkTag::DEFAULT, "no PERMISSION_START_UIABILITY_TO_HIDDEN"); - return false; - } -#endif - TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); - return true; + TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied"); + return false; } } // namespace AAFwk } // namespace OHOS diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index b270156d40..185aa05d21 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -29,6 +29,7 @@ config("upms_config") { libupms_sources = [ "src/file_permission_manager.cpp", + "src/media_permission_manager.cpp", "src/tokenid_permission.cpp", "src/uri_permission_manager_service.cpp", "src/uri_permission_manager_stub_impl.cpp", @@ -77,14 +78,17 @@ ohos_shared_library("libupms") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "data_share:datashare_consumer", "eventhandler:libeventhandler", "graphic_2d:color_manager", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "image_framework:image_native", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "media_library:media_library_manager", "relational_store:native_dataability", "relational_store:native_rdb", "safwk:system_ability_fwk", @@ -140,10 +144,14 @@ ohos_static_library("libupms_static") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "data_share:datashare_consumer", "hilog:libhilog", + "hitrace:hitrace_meter", + "image_framework:image_native", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "media_library:media_library_manager", "safwk:system_ability_fwk", "samgr:samgr_proxy", "storage_service:storage_manager_sa_proxy", diff --git a/services/uripermmgr/include/media_permission_manager.h b/services/uripermmgr/include/media_permission_manager.h new file mode 100644 index 0000000000..3e25b62cf5 --- /dev/null +++ b/services/uripermmgr/include/media_permission_manager.h @@ -0,0 +1,50 @@ +/* + * 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_MEDIA_PERMISSION_MANAGER_H +#define OHOS_ABILITY_RUNTIME_MEDIA_PERMISSION_MANAGER_H + +#include +#include + +#include "media_library_manager.h" + +namespace OHOS { +namespace AAFwk { +class MediaPermissionManager { +public: + static MediaPermissionManager &GetInstance(); + + std::vector CheckUriPermission(const std::vector &uriVec, uint32_t callerTokenId, uint32_t flag); + + ~MediaPermissionManager() {}; + + MediaPermissionManager(const MediaPermissionManager &mediaPermissionManager) = delete; + + const MediaPermissionManager &operator=(const MediaPermissionManager &mediaPermissionManager) = delete; + +private: + std::mutex mutex_; + + MediaPermissionManager(); + + Media::MediaLibraryManager *GetMediaLibraryManager(); + + Media::MediaLibraryManager *mediaLibraryManager_ = nullptr; +}; + +} // OHOS +} // AAFwk +#endif // OHOS_ABILITY_RUNTIME_MEDIA_PERMISSION_MANAGER_H \ No newline at end of file diff --git a/services/uripermmgr/include/upms_policy_info.h b/services/uripermmgr/include/upms_policy_info.h index c5162682aa..ea4ae23e5e 100644 --- a/services/uripermmgr/include/upms_policy_info.h +++ b/services/uripermmgr/include/upms_policy_info.h @@ -16,9 +16,6 @@ #ifndef ABILITY_ABILITY_RUNTIME_UPMS_POLICY_INFO_H #define ABILITY_ABILITY_RUNTIME_UPMS_POLICY_INFO_H -#include -#include - namespace OHOS { namespace AAFwk { struct PolicyInfo final { diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 58b8240796..e4c84d58e2 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -120,7 +120,8 @@ private: int32_t CheckCalledBySandBox(); - bool CheckUriPermission(Uri uri, uint32_t flag, TokenIdPermission &tokenIdPermission); + std::vector CheckUriPermission(TokenIdPermission &tokenIdPermission, const std::vector &uriVec, + uint32_t flag); bool CheckUriTypeIsValid(Uri uri); @@ -134,11 +135,8 @@ private: void HandleUriPermission( uint64_t tokenId, unsigned int flag, std::vector &docsVec, bool isSystemAppCall); - int32_t CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, const Uri &uri, uint32_t flag); - - bool AccessMediaUriPermission(TokenIdPermission &tokenIdPermission, const Uri &uri, uint32_t flag); - - bool AccessDocsUriPermission(TokenIdPermission &tokenIdPermission, const Uri &uri, uint32_t flag); + void CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, const std::vector &uriVec, uint32_t flag, + std::vector &result); int32_t DeleteShareFile(uint32_t targetTokenId, const std::vector &uriVec); diff --git a/services/uripermmgr/include/uri_permission_utils.h b/services/uripermmgr/include/uri_permission_utils.h index 3251839c55..a0b9021ef9 100644 --- a/services/uripermmgr/include/uri_permission_utils.h +++ b/services/uripermmgr/include/uri_permission_utils.h @@ -33,6 +33,7 @@ public: static bool IsSystemAppCall(uint32_t tokenId); static bool CheckIsSystemAppByTokenId(uint32_t tokenId); static bool GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName); + static int32_t GetAppIdByBundleName(const std::string &bundleName, std::string &appId); static std::string GetCallerNameByTokenId(uint32_t callerTokenId); static int32_t GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId); static bool IsDocsCloudUri(Uri &uri); diff --git a/services/uripermmgr/src/media_permission_manager.cpp b/services/uripermmgr/src/media_permission_manager.cpp new file mode 100644 index 0000000000..7e67dd936d --- /dev/null +++ b/services/uripermmgr/src/media_permission_manager.cpp @@ -0,0 +1,117 @@ + +/* +* 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 "media_permission_manager.h" + +#include +#include + +#include "ability_manager_errors.h" +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "in_process_call_wrapper.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "uri_permission_utils.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { + +MediaPermissionManager& MediaPermissionManager::GetInstance() +{ + static MediaPermissionManager mediaPermissionManager; + return mediaPermissionManager; +} + +MediaPermissionManager::MediaPermissionManager() +{ + TAG_LOGI(AAFwkTag::URIPERMMGR, "MediaPermissionManager init."); + mediaLibraryManager_ = GetMediaLibraryManager(); +} + +Media::MediaLibraryManager *MediaPermissionManager::GetMediaLibraryManager() +{ + TAG_LOGI(AAFwkTag::URIPERMMGR, "GetMediaLibraryManager."); + std::lock_guard lock(mutex_); + if (mediaLibraryManager_) { + return mediaLibraryManager_; + } + TAG_LOGI(AAFwkTag::URIPERMMGR, "mediaLibraryManager is nullptr."); + mediaLibraryManager_ = Media::MediaLibraryManager::GetMediaLibraryManager(); + if (mediaLibraryManager_ == nullptr) { + TAG_LOGE(AAFwkTag::URIPERMMGR, "GetMediaLibraryManager failed."); + return mediaLibraryManager_; + } + mediaLibraryManager_->InitMediaLibraryManager(); + TAG_LOGI(AAFwkTag::URIPERMMGR, "InitMediaLibraryManager success!"); + return mediaLibraryManager_; +} + +std::vector MediaPermissionManager::CheckUriPermission(const std::vector &uriVec, + uint32_t callerTokenId, uint32_t flag) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + std::vector uriStrVec; + std::vector results; + for (auto &uri: uriVec) { + uriStrVec.emplace_back(uri.ToString()); + } + TAG_LOGI(AAFwkTag::URIPERMMGR, "Check photo uri permission start."); + flag &= (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION); + std::string appId = ""; + std::string bundleName; + if (!UPMSUtils::GetBundleNameByTokenId(callerTokenId, bundleName)) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "Get bundle name failed."); + results = std::vector(uriStrVec.size(), false); + return results; + } + if (UPMSUtils::GetAppIdByBundleName(bundleName, appId) != ERR_OK) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "Get appId by bundle failed."); + results = std::vector(uriStrVec.size(), false); + return results; + } + auto mediaLibraryManager = GetMediaLibraryManager(); + if (mediaLibraryManager == nullptr) { + TAG_LOGE(AAFwkTag::URIPERMMGR, "GetMediaLibraryManager failed."); + results = std::vector(uriStrVec.size(), false); + return results; + } + TAG_LOGI(AAFwkTag::URIPERMMGR, "CheckPhotoUriPermission start."); + auto ret = IN_PROCESS_CALL(mediaLibraryManager->CheckPhotoUriPermission(callerTokenId, appId, uriStrVec, + results, flag)); + TAG_LOGI(AAFwkTag::URIPERMMGR, "CheckPhotoUriPermission finished."); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::URIPERMMGR, "Check photo uri permission failed, ret is %{pubic}d", ret); + results = std::vector(uriStrVec.size(), false); + return results; + } + if (results.size() != uriStrVec.size()) { + TAG_LOGE(AAFwkTag::URIPERMMGR, "size of results is unexpected: %{public}zu", results.size()); + results = std::vector(uriStrVec.size(), false); + return results; + } + for (size_t i = 0; i < results.size(); i++) { + if (!results[i]) { + TAG_LOGE(AAFwkTag::URIPERMMGR, "No media permission, uri is %{private}s", uriStrVec[i].c_str()); + break; + } + } + return results; +} + +} // OHOS +} // AAFwk \ No newline at end of file diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index ebf13df32d..d5c135ea68 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -25,6 +25,7 @@ #include "in_process_call_wrapper.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "media_permission_manager.h" #include "parameter.h" #include "permission_constants.h" #include "permission_verification.h" @@ -351,7 +352,9 @@ int UriPermissionManagerStubImpl::GrantSingleUriPermission(const Uri &uri, unsig return ERR_CODE_INVALID_URI_TYPE; } TokenIdPermission tokenIdPermission(callerTokenId); - if (!CheckUriPermission(uri, flag, tokenIdPermission)) { + std::vector uriVec = { uri }; + auto checkResult = CheckUriPermission(tokenIdPermission, uriVec, flag); + if (!checkResult[0]) { TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s, callerTokenId:%{public}u", uri.ToString().c_str(), callerTokenId); UPMSUtils::SendShareUnPrivilegeUriEvent(callerTokenId, targetTokenId); @@ -405,24 +408,22 @@ int UriPermissionManagerStubImpl::GrantBatchUriPermission(const std::vector callerTokenId, targetTokenId, flag, abilityId); TokenIdPermission tokenIdPermission(callerTokenId); std::vector uriStrVec = {}; - bool checkUriPermissionFailedFlag = false; - for (const auto &uri : uriVec) { - if (!CheckUriTypeIsValid(uri)) { - TAG_LOGW(AAFwkTag::URIPERMMGR, "failed, uri:%{private}s", uri.ToString().c_str()); + auto checkResult = CheckUriPermission(tokenIdPermission, uriVec, flag); + int32_t noPermissionUriCount = 0; + for (size_t i = 0; i < checkResult.size(); i++) { + auto uriStr = uriVec[i].ToString(); + if (!checkResult[i]) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s", uriStr.c_str()); + noPermissionUriCount++; continue; } - if (!CheckUriPermission(uri, flag, tokenIdPermission)) { - TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s", uri.ToString().c_str()); - checkUriPermissionFailedFlag = true; - continue; - } - uriStrVec.emplace_back(uri.ToString()); + uriStrVec.emplace_back(uriStr); } - if (checkUriPermissionFailedFlag) { + if (noPermissionUriCount > 0) { UPMSUtils::SendShareUnPrivilegeUriEvent(callerTokenId, targetTokenId); } if (uriStrVec.empty()) { - TAG_LOGE(AAFwkTag::URIPERMMGR, "empty uri"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "all uri invalid or no permission"); return INNER_ERR; } return GrantBatchUriPermissionImpl(uriStrVec, flag, callerTokenId, targetTokenId, abilityId); @@ -648,35 +649,28 @@ int32_t UriPermissionManagerStubImpl::DeleteShareFile(uint32_t targetTokenId, co return ret; } -std::vector UriPermissionManagerStubImpl::CheckUriAuthorization(const std::vector &uriVec, +std::vector UriPermissionManagerStubImpl::CheckUriAuthorization(const std::vector &uriStrVec, uint32_t flag, uint32_t tokenId) { TAG_LOGI(AAFwkTag::URIPERMMGR, "tokenId:%{public}u, tokenName:%{public}s, flag:%{public}u, size of uris:%{public}zu", - tokenId, UPMSUtils::GetCallerNameByTokenId(tokenId).c_str(), flag, uriVec.size()); - std::vector result(uriVec.size(), false); + tokenId, UPMSUtils::GetCallerNameByTokenId(tokenId).c_str(), flag, uriStrVec.size()); if (!UPMSUtils::IsSAOrSystemAppCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "not SA/SystemApp"); + std::vector result(uriStrVec.size(), false); return result; } if ((flag & FLAG_READ_WRITE_URI) == 0) { TAG_LOGE(AAFwkTag::URIPERMMGR, "Flag invalid"); + std::vector result(uriStrVec.size(), false); return result; } - - TokenIdPermission tokenIdPermission(tokenId); - for (size_t i = 0; i < uriVec.size(); i++) { - Uri uri(uriVec[i]); - if (!CheckUriTypeIsValid(uri)) { - TAG_LOGW(AAFwkTag::URIPERMMGR, "uri:invalid, uri:%{private}s", uriVec[i].c_str()); - continue; - } - result[i] = CheckUriPermission(uri, flag, tokenIdPermission); - if (!result[i]) { - TAG_LOGW(AAFwkTag::URIPERMMGR, "CheckUriPermission failed, uri:%{private}s", uriVec[i].c_str()); - } + std::vector uriVec; + for (auto &uriStr: uriStrVec) { + uriVec.emplace_back(uriStr); } - return result; + TokenIdPermission tokenIdPermission(tokenId); + return CheckUriPermission(tokenIdPermission, uriVec, flag); } template @@ -811,83 +805,69 @@ void UriPermissionManagerStubImpl::HandleUriPermission( } } -bool UriPermissionManagerStubImpl::CheckUriPermission(Uri uri, uint32_t flag, TokenIdPermission &tokenIdPermission) +std::vector UriPermissionManagerStubImpl::CheckUriPermission(TokenIdPermission &tokenIdPermission, + const std::vector &uriVec, uint32_t flag) { - auto &&authority = uri.GetAuthority(); - TAG_LOGD(AAFwkTag::URIPERMMGR, "UriAuth:%{public}s", authority.c_str()); - if (uri.GetScheme() == "content") { - TAG_LOGI(AAFwkTag::URIPERMMGR, "content uri"); - return UPMSUtils::IsFoundationCall(); + auto tokenId = tokenIdPermission.GetTokenId(); + std::vector result(uriVec.size(), false); + std::vector mediaUris; + std::vector mediaUriIndexs; + bool isFoundationCall = UPMSUtils::IsFoundationCall(); + std::string callerBundleName; + UPMSUtils::GetBundleNameByTokenId(tokenId, callerBundleName); + for (size_t i = 0; i < uriVec.size(); i++) { + auto uri = uriVec[i]; + auto &&scheme = uri.GetScheme(); + if (scheme != "content" && scheme != "file") { + TAG_LOGW(AAFwkTag::URIPERMMGR, "invalid uri:%{private}s", uri.ToString().c_str()); + result[i] = false; + continue; + } + if (scheme == "content") { + result[i] = isFoundationCall; + continue; + } + auto &&authority = uri.GetAuthority(); + TAG_LOGD(AAFwkTag::URIPERMMGR, "UriAuth:%{public}s", authority.c_str()); + if (authority == "docs" && tokenIdPermission.VerifyFileAccessManagerPermission()) { + result[i] = true; + continue; + } + if (authority == "media") { + mediaUris.emplace_back(uri); + mediaUriIndexs.emplace_back(i); + continue; + } + result[i] = (authority == callerBundleName); } - if (authority == "docs") { - return AccessDocsUriPermission(tokenIdPermission, uri, flag); + if (!mediaUris.empty()) { + auto mediaUriResult = MediaPermissionManager::GetInstance().CheckUriPermission(mediaUris, tokenId, flag); + for (size_t i = 0; i < mediaUris.size(); i++) { + result[mediaUriIndexs[i]] = mediaUriResult[i]; + } } - if (authority == "media") { - return AccessMediaUriPermission(tokenIdPermission, uri, flag); - } - uint32_t authorityTokenId = 0; - if (UPMSUtils::GetTokenIdByBundleName(authority, 0, authorityTokenId) != ERR_OK) { - TAG_LOGE(AAFwkTag::URIPERMMGR, "Get tokenId of %{public}s failed", authority.c_str()); - return false; - } - if (tokenIdPermission.GetTokenId() == authorityTokenId) { - return true; - } - return CheckProxyUriPermission(tokenIdPermission, uri, flag); + CheckProxyUriPermission(tokenIdPermission, uriVec, flag, result); + return result; } -bool UriPermissionManagerStubImpl::AccessMediaUriPermission(TokenIdPermission &tokenIdPermission, - const Uri &uri, uint32_t flag) -{ - TAG_LOGD(AAFwkTag::URIPERMMGR, "Call"); - bool isWriteFlag = (flag & Want::FLAG_AUTH_WRITE_URI_PERMISSION) != 0; - auto innerUri = uri; - auto path = innerUri.GetPath(); - if (path.rfind("/Photo/", 0) == 0) { - if (tokenIdPermission.VerifyWriteImageVideoPermission()) { - return true; - } - if (!isWriteFlag && tokenIdPermission.VerifyReadImageVideoPermission()) { - return true; - } - TAG_LOGI(AAFwkTag::URIPERMMGR, "No IMAGEVIDEO Permission"); - return CheckProxyUriPermission(tokenIdPermission, uri, flag); - } - if (path.rfind("/Audio/", 0) == 0) { - if (tokenIdPermission.VerifyWriteAudioPermission()) { - return true; - } - if (!isWriteFlag && tokenIdPermission.VerifyReadAudioPermission()) { - return true; - } - TAG_LOGI(AAFwkTag::URIPERMMGR, "No AUDIO Permission"); - return CheckProxyUriPermission(tokenIdPermission, uri, flag); - } - TAG_LOGE(AAFwkTag::URIPERMMGR, "Media uri invalid, path:%{public}s", path.c_str()); - return false; -} - -bool UriPermissionManagerStubImpl::AccessDocsUriPermission(TokenIdPermission &tokenIdPermission, - const Uri &uri, uint32_t flag) -{ - TAG_LOGD(AAFwkTag::URIPERMMGR, "Call"); - if (tokenIdPermission.VerifyFileAccessManagerPermission()) { - return true; - } - TAG_LOGW(AAFwkTag::URIPERMMGR, "No FILE_ACCESS_MANAGER Permission"); - return CheckProxyUriPermission(tokenIdPermission, uri, flag); -} - -int32_t UriPermissionManagerStubImpl::CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, - const Uri &uri, uint32_t flag) +void UriPermissionManagerStubImpl::CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, + const std::vector &uriVec, uint32_t flag, std::vector &result) { TAG_LOGI(AAFwkTag::URIPERMMGR, "Call"); - auto tokenId = tokenIdPermission.GetTokenId(); - if (tokenIdPermission.VerifyProxyAuthorizationUriPermission() && VerifyUriPermission(uri, flag, tokenId)) { - return true; + if (uriVec.size() != result.size()) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "param size not equal"); + return; + } + auto tokenId = tokenIdPermission.GetTokenId(); + if (!tokenIdPermission.VerifyProxyAuthorizationUriPermission()) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "no proxy permission"); + return; + } + for (size_t i = 0; i < uriVec.size(); i++) { + if (!result[i]) { + result[i] = VerifyUriPermission(uriVec[i], flag, tokenId); + } } - TAG_LOGW(AAFwkTag::URIPERMMGR, "failed"); - return false; } bool UriPermissionManagerStubImpl::CheckUriTypeIsValid(Uri uri) diff --git a/services/uripermmgr/src/uri_permission_utils.cpp b/services/uripermmgr/src/uri_permission_utils.cpp index dcbee1ad11..70f74b8e57 100644 --- a/services/uripermmgr/src/uri_permission_utils.cpp +++ b/services/uripermmgr/src/uri_permission_utils.cpp @@ -195,6 +195,23 @@ bool UPMSUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName return false; } +int32_t UPMSUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId) +{ + TAG_LOGD(AAFwkTag::URIPERMMGR, "BundleName is %{public}s.", bundleName.c_str()); + auto bms = ConnectManagerHelper(); + if (bms == nullptr) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "The bundleMgrHelper is nullptr."); + return GET_BUNDLE_MANAGER_SERVICE_FAILED; + } + auto userId = GetCurrentAccountId(); + appId = IN_PROCESS_CALL(bms->GetAppIdByBundleName(bundleName, userId)); + if (appId.empty()) { + TAG_LOGW(AAFwkTag::URIPERMMGR, "Get appId by bundle name failed, userId is %{private}d", userId); + return INNER_ERR; + } + return ERR_OK; +} + std::string UPMSUtils::GetCallerNameByTokenId(uint32_t tokenId) { auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); diff --git a/test/fuzztest/abilitymgrappexitreasonhelper_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrappexitreasonhelper_fuzzer/BUILD.gn index 4d949191a5..64bda35f3d 100644 --- a/test/fuzztest/abilitymgrappexitreasonhelper_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrappexitreasonhelper_fuzzer/BUILD.gn @@ -32,6 +32,7 @@ ohos_fuzztest("AbilityMgrAppExitReasonHelperFuzzTest") { "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_services_path}/abilitymgr/include", "${ability_runtime_services_path}/abilitymgr/include/scene_board", + "${ability_runtime_services_path}/abilitymgr/include/mission", ] cflags = [ "-g", diff --git a/test/mock/frameworks_kits_test/DemoObServer/mock_ability_thread_for_data_observer.h b/test/mock/frameworks_kits_test/DemoObServer/mock_ability_thread_for_data_observer.h index 73c54cbabf..2ee30e7515 100644 --- a/test/mock/frameworks_kits_test/DemoObServer/mock_ability_thread_for_data_observer.h +++ b/test/mock/frameworks_kits_test/DemoObServer/mock_ability_thread_for_data_observer.h @@ -55,7 +55,7 @@ sptr MockCreateAbilityThread() sptr token = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(info->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index fb684aab95..61a1d28dc4 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -131,10 +131,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h index 237b12a33e..cad5c60673 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h @@ -113,10 +113,10 @@ public: /** * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. - * Obtains running isntance keys of multi-instance app that are running on the device. + * Obtains running instance keys of multi-instance app that are running on the device. * * @param bundlename, bundle name in Application record. - * @param instanceKeys, output instance keys of the multi-insatnce app. + * @param instanceKeys, output instance keys of the multi-instance app. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h index 7b54480d7e..087c80ccf0 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h @@ -70,7 +70,7 @@ public: MOCK_METHOD1(GetWaitingDebugApp, int32_t(std::vector &debugInfoList)); MOCK_METHOD1(IsWaitingDebugApp, bool(const std::string &bundleName)); MOCK_METHOD0(ClearNonPersistWaitingDebugFlag, void()); - MOCK_METHOD0(IsMemorySizeSufficent, bool()); + MOCK_METHOD0(IsMemorySizeSufficient, bool()); MOCK_METHOD4(StartNativeChildProcess, int32_t(const pid_t hostPid, const std::string &libName, int32_t childProcessCount, const sptr &callback)); void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t) diff --git a/test/moduletest/ability_test/ability_context_test.cpp b/test/moduletest/ability_test/ability_context_test.cpp index a195cedd4c..f687eed373 100644 --- a/test/moduletest/ability_test/ability_context_test.cpp +++ b/test/moduletest/ability_test/ability_context_test.cpp @@ -89,7 +89,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0100, Function std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -115,7 +115,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_DisconnectAbility_0100, Funct std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -142,7 +142,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StartAbility_0100, Function | std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); Want want; @@ -163,7 +163,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_TerminateAbility_0100, Functi std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); Want want; @@ -190,7 +190,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_TerminateAbility_0200, Functi std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -214,7 +214,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0100, Function | std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -243,7 +243,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0200, Function | std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); @@ -331,7 +331,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0300, Function std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); deal->SetAbilityInfo(abilityInfo); @@ -353,7 +353,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0300, Function | std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); @@ -555,7 +555,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfoType_0200, Func std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); @@ -602,7 +602,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetResourceManager_0200, Func std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); deal->SetAbilityInfo(abilityInfo); @@ -651,7 +651,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0300, Functi std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::SERVICE; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); deal->SetAbilityInfo(abilityInfo); @@ -896,7 +896,7 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_SetColorMode_0100, Function | std::shared_ptr application = std::make_shared(); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); std::shared_ptr deal = std::make_shared(); deal->SetAbilityInfo(abilityInfo); diff --git a/test/moduletest/ability_test/ability_test.cpp b/test/moduletest/ability_test/ability_test.cpp index 5ff98d231e..621773963e 100644 --- a/test/moduletest/ability_test/ability_test.cpp +++ b/test/moduletest/ability_test/ability_test.cpp @@ -93,8 +93,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0100, Function | M abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); usleep(AbilityBaseTest::TEST_WAIT_TIME); @@ -117,8 +116,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0200, Function | M abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); usleep(AbilityBaseTest::TEST_WAIT_TIME); @@ -154,8 +152,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0400, Function | M if (abilityToken != nullptr) { std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::PAGE; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); usleep(AbilityBaseTest::TEST_WAIT_TIME); @@ -177,8 +174,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0500, Function | M std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); usleep(AbilityBaseTest::TEST_WAIT_TIME); @@ -218,8 +214,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0600, Function | M abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -252,8 +247,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_Lifecycle_Test_0100, Function | MediumTe abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -283,8 +277,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0200, Function abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -315,8 +308,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0300, Function abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -350,8 +342,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0400, Function abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -384,8 +375,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0500, Function abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -420,8 +410,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0600, Function abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -457,8 +446,7 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_TerminateAbility_ForResult_Test_0100, Fu abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -527,8 +515,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0100, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_001 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -564,8 +551,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0200, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_002 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -601,8 +587,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0300, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0300 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -638,8 +623,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0400, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0400 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -675,8 +659,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0500, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_005 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -707,8 +690,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0600, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_006 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -739,8 +721,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0700, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_007 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -771,8 +752,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0800, Function | Med abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_008 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -803,8 +783,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_WMS_window_test_0100, Function | MediumTest abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_001 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -836,8 +815,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_WMS_window_test_0200, Function | MediumTest abilityInfo->type = AppExecFwk::AbilityType::PAGE; abilityInfo->name = ABILITY_NAME; abilityInfo->isNativeAbility = true; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_002 AbilityThreadMain"; AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -873,8 +851,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Launch_0100, Function | MediumT std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -906,8 +883,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0100, Function | MediumTe std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -939,8 +915,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0200, Function | MediumTe std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -972,8 +947,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0300, Function | MediumTe std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); @@ -1005,8 +979,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0400, Function | MediumTe std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->type = AppExecFwk::AbilityType::DATA; abilityInfo->name = "DemoAbility"; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index df152859e5..e148c1aaf3 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -200,6 +200,7 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/ability/native/distributed_ability_runtime", "${ability_runtime_innerkits_path}/dataobs_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/mission", ] cflags_cc = [] @@ -276,16 +277,16 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_services_path}/abilitymgr/src/ability_first_frame_state_observer_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/implicit_start_processor.cpp", "${ability_runtime_services_path}/abilitymgr/src/inner_mission_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_data_storage.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_info_mgr.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_list.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_list_manager.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_listener_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_listener_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_listener_stub.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_snapshot.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_data_storage.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_info_mgr.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_list.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_list_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_listener_controller.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_listener_proxy.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_listener_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/mission/mission_snapshot.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/system_dialog_scheduler.cpp", @@ -293,12 +294,10 @@ ohos_source_set("abilityms_test_source") { ] deps += [ "//third_party/libjpeg-turbo:turbojpeg_static" ] external_deps += [ - # "graphic_2d:2d_graphics", "i18n:intl_util", "icu:shared_icuuc", "image_framework:image_native", "input:libmmi-client", - # "skia:skia_canvaskit", "window_manager:libdm", "window_manager:libmodal_system_ui_extension_client", "window_manager:libwm", @@ -342,7 +341,9 @@ group("unittest") { "ability_first_frame_state_observer_stub_test:unittest", "ability_foreground_state_observer_proxy_test:unittest", "ability_foreground_state_observer_stub_test:unittest", + "ability_interceptor_second_test:unittest", "ability_interceptor_test:unittest", + "ability_interceptor_third_test:unittest", "ability_manager_client_branch_second_test:unittest", "ability_manager_client_branch_test:unittest", "ability_manager_event_subscriber_test:unittest", @@ -351,6 +352,7 @@ group("unittest") { "ability_manager_service_first_test:unittest", "ability_manager_service_fourth_test:unittest", "ability_manager_service_second_test:unittest", + "ability_manager_service_seventh_test:unittest", "ability_manager_service_sixth_test:unittest", "ability_manager_service_third_test:unittest", "ability_manager_stub_test:unittest", @@ -485,6 +487,7 @@ group("unittest") { "dataobs_mgr_stub_test:unittest", "deeplink_reserve_config_test:unittest", "dfr_test:unittest", + "dialog_session_manager_test:unittest", "dlp_state_item_test:unittest", "dlp_utils_test:unittest", "dummy_values_bucket_test:unittest", diff --git a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp index f9411bc6cf..dcc8631a4a 100644 --- a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp +++ b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp @@ -2453,7 +2453,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Start_Service_With_SessionInfo_001, Te abilityRequest_.sessionInfo = nullptr; WaitUntilTaskDone(TaskHandler()); - auto service = ConnectManager()->GetUIExtensioBySessionInfo(sessionInfo); + auto service = ConnectManager()->GetUIExtensionBySessionInfo(sessionInfo); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); } diff --git a/test/unittest/ability_extension_base_test/ability_extension_base_test.cpp b/test/unittest/ability_extension_base_test/ability_extension_base_test.cpp index db15e3be09..d2a7d45dfb 100644 --- a/test/unittest/ability_extension_base_test/ability_extension_base_test.cpp +++ b/test/unittest/ability_extension_base_test/ability_extension_base_test.cpp @@ -96,8 +96,7 @@ HWTEST_F(AbilityExtensionBaseTest, CreateAndInitContext_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "ExtensionBaseTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -127,8 +126,7 @@ HWTEST_F(AbilityExtensionBaseTest, GetContext_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "ExtensionBaseTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -157,8 +155,7 @@ HWTEST_F(AbilityExtensionBaseTest, OnConfigurationUpdated_0100, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "OnConfigurationUpdated start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -190,8 +187,7 @@ HWTEST_F(AbilityExtensionBaseTest, OnMemoryLevel_0100, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "OnMemoryLevel start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -222,8 +218,7 @@ HWTEST_F(AbilityExtensionBaseTest, SetExtensionCommon_0100, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "SetExtensionCommon start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); diff --git a/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp b/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp index 610ef4f108..8e9acd67dc 100644 --- a/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp +++ b/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp @@ -65,8 +65,7 @@ HWTEST_F(AbilityExtensionContextTest, GetAbilityInfo_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "ExtensionContextTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -98,8 +97,7 @@ HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "ExtensionContextTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -137,8 +135,7 @@ HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0200, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "ExtensionContextTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); diff --git a/test/unittest/ability_extension_test/ability_extension_test.cpp b/test/unittest/ability_extension_test/ability_extension_test.cpp index 7da1035311..b4495d4f01 100644 --- a/test/unittest/ability_extension_test/ability_extension_test.cpp +++ b/test/unittest/ability_extension_test/ability_extension_test.cpp @@ -182,8 +182,7 @@ HWTEST_F(AbilityExtensionTest, Init_0200, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "Init start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = nullptr; std::shared_ptr handler = std::make_shared(nullptr); sptr token = nullptr; @@ -206,8 +205,7 @@ HWTEST_F(AbilityExtensionTest, Init_0300, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "Init start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = nullptr; sptr token = nullptr; @@ -230,8 +228,7 @@ HWTEST_F(AbilityExtensionTest, Init_0400, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "Init start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = nullptr; @@ -254,8 +251,7 @@ HWTEST_F(AbilityExtensionTest, Init_0500, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "Init start"); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -280,8 +276,7 @@ HWTEST_F(AbilityExtensionTest, OnStart_0100, TestSize.Level1) Extension extension; // Init extension std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -319,8 +314,7 @@ HWTEST_F(AbilityExtensionTest, OnStop_0100, TestSize.Level1) Extension extension; // Init extension std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -346,8 +340,7 @@ HWTEST_F(AbilityExtensionTest, OnConnect_0100, TestSize.Level1) Extension extension; // Init extension std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -385,8 +378,7 @@ HWTEST_F(AbilityExtensionTest, OnDisconnect_0100, TestSize.Level1) Extension extension; // Init extension std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -424,8 +416,7 @@ HWTEST_F(AbilityExtensionTest, OnDisconnect_0200, TestSize.Level1) Extension extension; // Init extension std::shared_ptr info = std::make_shared(); - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); diff --git a/test/unittest/ability_interceptor_second_test/BUILD.gn b/test/unittest/ability_interceptor_second_test/BUILD.gn new file mode 100644 index 0000000000..384759c20b --- /dev/null +++ b/test/unittest/ability_interceptor_second_test/BUILD.gn @@ -0,0 +1,94 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_interceptor_second_test") { + module_out_path = module_output_path + cflags_cc = [] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + + sources = [ + # add mock file + "${ability_runtime_services_path}/abilitymgr/src/start_ability_utils.cpp", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "ability_interceptor_second_test.cpp", + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//third_party/libjpeg-turbo:turbojpeg_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":ability_interceptor_second_test" ] +} diff --git a/test/unittest/ability_interceptor_second_test/ability_interceptor_second_test.cpp b/test/unittest/ability_interceptor_second_test/ability_interceptor_second_test.cpp new file mode 100644 index 0000000000..ce89012d7d --- /dev/null +++ b/test/unittest/ability_interceptor_second_test/ability_interceptor_second_test.cpp @@ -0,0 +1,253 @@ +/* + * 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 +#define private public +#define protected public +#include "ability_manager_service.h" +#include "interceptor/disposed_rule_interceptor.h" +#undef private +#undef protected + +#include "bundlemgr/mock_bundle_manager.h" +#include "permission_constants.h" +#include "start_ability_utils.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace { +const std::string BUNDLE_NAME = "testBundle"; +constexpr const char* TEST_IS_FROM_PARENTCONTROL = "ohos.ability.isFromParentControl"; +constexpr const char* TEST_INTERCEPT_BUNDLE_NAME = "intercept_bundleName"; +} + +namespace OHOS { +namespace AAFwk { +class AbilityInterceptorSecondTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +public: +}; + +void AbilityInterceptorSecondTest::SetUpTestCase() +{ + GTEST_LOG_(INFO) << "AbilityInterceptorSecondTest SetUpTestCase called"; + AbilityManagerClient::GetInstance()->CleanAllMissions(); + OHOS::DelayedSingleton::DestroyInstance(); + + OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( + OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService()); +} + +void AbilityInterceptorSecondTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "AbilityInterceptorSecondTest TearDownTestCase called"; + OHOS::DelayedSingleton::DestroyInstance(); +} + +void AbilityInterceptorSecondTest::SetUp() +{} + +void AbilityInterceptorSecondTest::TearDown() +{} + +HWTEST_F(AbilityInterceptorSecondTest, CreateExecuter_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + EXPECT_NE(executer, nullptr); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_001 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + Want want; + ElementName element("", "com.test.disposedrule", "MainAbility", "entry"); + want.SetElement(element); + AppExecFwk::DisposedRule disposedRule; + disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_ABILITY; + bool result = executer->CheckDisposedRule(want, disposedRule); + EXPECT_EQ(result, true); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_002 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + Want want; + ElementName element("", "com.test.disposedrule", "MainAbility", "entry"); + want.SetElement(element); + AppExecFwk::DisposedRule disposedRule; + disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_ABILITY; + disposedRule.controlType = AppExecFwk::ControlType::DISALLOWED_LIST; + bool result = executer->CheckDisposedRule(want, disposedRule); + EXPECT_EQ(result, false); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_003 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName = "com.example.disposedruletest1"; + Want want; + want.SetBundle(bundleName); + DisposedRule disposedRule; + disposedRule.want = std::make_shared(); + disposedRule.want->SetBundle(bundleName); + ErrCode result = executer->StartNonBlockRule(want, disposedRule); + EXPECT_EQ(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_004 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName1 = "com.example.disposedruletest1"; + std::string bundleName2 = "com.example.disposedruletest2"; + Want want; + want.SetBundle(bundleName1); + DisposedRule disposedRule; + disposedRule.want = std::make_shared(); + disposedRule.want->SetBundle(bundleName2); + ErrCode result = executer->StartNonBlockRule(want, disposedRule); + EXPECT_NE(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_005 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName = "com.example.disposedruletest"; + Want want; + want.SetBundle(bundleName); + AbilityRequest abilityRequest; + auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + sptr callerToken = abilityRecord->GetToken(); + ErrCode result = executer->CreateModalUIExtension(want, callerToken); + EXPECT_EQ(result, INNER_ERR); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_006 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName = "com.test.disposedrule"; + Want want; + ElementName element("", "com.test.disposedrule", "MainAbility", "entry"); + want.SetElement(element); + DisposedRule disposedRule; + disposedRule.want = std::make_shared(); + disposedRule.want->SetParam(TEST_IS_FROM_PARENTCONTROL, true); + executer->SetInterceptInfo(want, disposedRule); + EXPECT_STREQ(disposedRule.want->GetStringParam(TEST_INTERCEPT_BUNDLE_NAME).c_str(), bundleName.c_str()); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_007 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName = "interceptor_callerBundleName"; + Want want; + want.SetBundle(bundleName); + int32_t userId = 10; + DisposedRule disposedRule; + int32_t appIndex = 0; + bool result = executer->CheckControl(want, userId, disposedRule, appIndex); + EXPECT_EQ(result, false); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityInterceptorSecondTest_DisposedRuleInterceptor_008 + * @tc.desc: DisposedRuleInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorSecondTest, DisposedRuleInterceptor_008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + std::shared_ptr executer = std::make_shared(); + std::string bundleName = "interceptor_callerBundleName"; + Want want; + want.SetBundle(bundleName); + int32_t userId = 10; + int32_t appIndex = 0; + DisposedRule disposedRule; + disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_APPLICATION; + disposedRule.controlType == AppExecFwk::ControlType::DISALLOWED_LIST; + executer->CheckDisposedRule(want, disposedRule); + bool result = executer->CheckControl(want, userId, disposedRule, appIndex); + EXPECT_EQ(result, false); + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_interceptor_third_test/BUILD.gn b/test/unittest/ability_interceptor_third_test/BUILD.gn new file mode 100644 index 0000000000..aa0393101c --- /dev/null +++ b/test/unittest/ability_interceptor_third_test/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2022-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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_interceptor_third_test") { + module_out_path = module_output_path + cflags_cc = [] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_services_path}/abilitymgr/include/interceptor", + ] + + sources = [ + # add mock file + "${ability_runtime_services_path}/abilitymgr/src/interceptor/ability_interceptor_executer.cpp", + "${ability_runtime_services_path}/abilitymgr/src/start_ability_utils.cpp", + "ability_interceptor_third_test.cpp", + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//third_party/libjpeg-turbo:turbojpeg_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":ability_interceptor_third_test" ] +} diff --git a/test/unittest/ability_interceptor_third_test/ability_interceptor_third_test.cpp b/test/unittest/ability_interceptor_third_test/ability_interceptor_third_test.cpp new file mode 100644 index 0000000000..454c0d6f95 --- /dev/null +++ b/test/unittest/ability_interceptor_third_test/ability_interceptor_third_test.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024-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 +#define private public +#define protected public +#include "ability_interceptor_executer.h" +#undef private +#undef protected + +#include "interceptor/crowd_test_interceptor.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AAFwk { +class AbilityInterceptorThirdTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +public: +}; + +void AbilityInterceptorThirdTest::SetUpTestCase() +{} + +void AbilityInterceptorThirdTest::TearDownTestCase() +{} + +void AbilityInterceptorThirdTest::SetUp() +{} + +void AbilityInterceptorThirdTest::TearDown() +{} + +/** + * @tc.name: AbilityInterceptorThirdTest_RemoveInterceptor_001 + * @tc.desc: CrowdTestInterceptor + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorThirdTest, RemoveInterceptor_001, TestSize.Level1) +{ + std::shared_ptr executer = std::make_shared(); + executer->AddInterceptor("CrowdTest", std::make_shared()); + auto resMap = executer->GetInterceptorMapCopy(); + EXPECT_EQ(resMap.size(), 1); + executer->RemoveInterceptor("CrowdTest"); + auto resMap2 = executer->GetInterceptorMapCopy(); + EXPECT_EQ(resMap2.size(), 0); +} + +/** + * @tc.name: AbilityInterceptorThirdTest_SetTaskHandler_001 + * @tc.desc: SetTaskHandler + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(AbilityInterceptorThirdTest, SetTaskHandler_001, TestSize.Level1) +{ + std::shared_ptr executer = std::make_shared(); + std::shared_ptr taskHandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("SetTaskHandler"); + executer->AddInterceptor("CrowdTest", std::make_shared()); + executer->SetTaskHandler(taskHandler); + auto resMap2 = executer->GetInterceptorMapCopy(); + EXPECT_EQ(resMap2.size(), 1); +} + +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_manager_service_fourth_test/BUILD.gn b/test/unittest/ability_manager_service_fourth_test/BUILD.gn index d067398fdb..4ffb560d14 100644 --- a/test/unittest/ability_manager_service_fourth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourth_test/BUILD.gn @@ -49,6 +49,8 @@ ohos_unittest("ability_manager_service_fourth_test") { "${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/modal_system_dialog/modal_system_dialog_ui_extension.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/modal_system_dialog_util.cpp", "${ability_runtime_services_path}/common/src/ffrt_task_handler_wrap.cpp", "${ability_runtime_services_path}/common/src/queue_task_handler_wrap.cpp", "${ability_runtime_services_path}/common/src/task_handler_wrap.cpp", diff --git a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp index 0d1ffd079f..a957363062 100644 --- a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp +++ b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp @@ -24,6 +24,8 @@ #include "mock_parameters.h" #include "ability_manager_service.h" #include "insight_intent_execute_manager.h" +#include "modal_system_dialog/modal_system_dialog_ui_extension.h" +#include "utils/modal_system_dialog_util.h" #undef private #undef protected #include "hilog_tag_wrapper.h" @@ -98,6 +100,63 @@ sptr AbilityManagerServiceFourthTest::MockToken(AbilityType abilityType) return abilityRecord->GetToken(); } +class IRemoteObjectMocker : public IRemoteObject { +public: + IRemoteObjectMocker() : IRemoteObject { u"IRemoteObjectMocker" } {} + + ~IRemoteObjectMocker() {} + + int32_t GetObjectRefCount() + { + return 0; + } + + int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + { + int32_t key = data.ReadInt32(); + std::string parameters = Str16ToStr8(data.ReadString16()); + std::string command = Str16ToStr8(data.ReadString16()); + if (command.compare("test") == 0) { + isSuccess_ = true; + return 0; + } + isSuccess_ = false; + return -1; + } + + bool IsProxyObject() const + { + return true; + } + + bool CheckObjectLegality() const + { + return true; + } + + bool AddDeathRecipient(const sptr& recipient) + { + return true; + } + + bool RemoveDeathRecipient(const sptr& recipient) + { + return true; + } + + sptr AsInterface() + { + return nullptr; + } + + int Dump(int fd, const std::vector& args) + { + return 0; + } + +public: + bool isSuccess_ = false; +}; /* * Feature: AbilityManagerService @@ -1423,5 +1482,74 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_003, Test TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_003 end"); } +/* + * Feature: AbilityManagerService + * Function: CheckDebugAppNotInDeveloperMode + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUtil CheckDebugAppNotInDeveloperMode + */ +HWTEST_F(AbilityManagerServiceFourthTest, CheckDebugAppNotInDeveloperMode_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckDebugAppNotInDeveloperMode start"); + bool srcDeveloperMode = OHOS::system::GetBoolParameter(DEVELOPER_MODE_STATE, false); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, false); + ApplicationInfo applicationInfo; + applicationInfo.appProvisionType = "release"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + applicationInfo.appProvisionType = "debug"; + EXPECT_TRUE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, true); + applicationInfo.appProvisionType = "release"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + applicationInfo.appProvisionType = "debug"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, srcDeveloperMode); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckDebugAppNotInDeveloperMode end"); +} + +/* + * Feature: AbilityManagerService + * Function: CreateModalUIExtension + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUIExtension CreateModalUIExtension + */ +HWTEST_F(AbilityManagerServiceFourthTest, ModalSystemDialogUIExtension_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ModalSystemDialogUIExtension_001 start"); + auto modalSystemDialog = std::make_shared(); + ASSERT_NE(modalSystemDialog, nullptr); + std::string commandStr = "test"; + auto result = modalSystemDialog->CreateModalUIExtension(commandStr); + EXPECT_FALSE(result); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ModalSystemDialogUIExtension_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: OnAbilityConnectDone + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUIExtension OnAbilityConnectDone + */ +HWTEST_F(AbilityManagerServiceFourthTest, OnAbilityConnectDone_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAbilityConnectDone_001 start"); + sptr dialogConnection( + new (std::nothrow) ModalSystemDialogUIExtension::DialogConnection("test")); + ASSERT_NE(dialogConnection, nullptr); + ElementName element("", "", "ability", ""); + dialogConnection->OnAbilityConnectDone(element, nullptr, 0); + sptr iRemoteObject = new IRemoteObjectMocker(); + dialogConnection->OnAbilityConnectDone(element, iRemoteObject, 0); + EXPECT_TRUE(iRemoteObject->isSuccess_); + dialogConnection->commandStr_ = ""; + dialogConnection->OnAbilityConnectDone(element, iRemoteObject, 0); + EXPECT_FALSE(iRemoteObject->isSuccess_); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAbilityConnectDone_001 end"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_seventh_test/BUILD.gn b/test/unittest/ability_manager_service_seventh_test/BUILD.gn new file mode 100644 index 0000000000..8037bbe972 --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/BUILD.gn @@ -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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_manager_service_seventh_test") { + module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + include_dirs = [ + "include/", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime/", + "${ability_runtime_path}/interfaces/inner_api/ability_manager/include", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/start_options.cpp", + "ability_manager_service_seventh_test.cpp", + "src/app_utils.cpp", + "src/mock_ability_manager_service.cpp", + "src/permission_verification.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:process_options", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":ability_manager_service_seventh_test" ] +} diff --git a/test/unittest/ability_manager_service_seventh_test/ability_manager_service_seventh_test.cpp b/test/unittest/ability_manager_service_seventh_test/ability_manager_service_seventh_test.cpp new file mode 100644 index 0000000000..733850b306 --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/ability_manager_service_seventh_test.cpp @@ -0,0 +1,338 @@ +/* + * 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 "mock_ability_manager_service.h" +#include "ability_manager_errors.h" +#include "app_utils.h" +#include "hilog_tag_wrapper.h" +#include "permission_verification.h" +#include "process_options.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +namespace OHOS { +namespace AAFwk { +namespace { +const char* START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation"; +} // namespace +class AbilityManagerServiceSeventhTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AbilityManagerServiceSeventhTest::SetUpTestCase() {} + +void AbilityManagerServiceSeventhTest::TearDownTestCase() {} + +void AbilityManagerServiceSeventhTest::SetUp() {} + +void AbilityManagerServiceSeventhTest::TearDown() {} + +/* + * Feature: AbilityManagerService + * Name: BlockAllAppStart_001 + * Function: BlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService BlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, BlockAllAppStart_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasBlockAllAppStartPermission = true; + AppUtils::isStartOptionsWithAnimation_ = true; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true); + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission(), true); + auto retCode = abilityMs_->BlockAllAppStart(true); + EXPECT_EQ(retCode, ERR_OK); + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, true); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: BlockAllAppStart_002 + * Function: BlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService BlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, BlockAllAppStart_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_002 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + AppUtils::isStartOptionsWithAnimation_ = false; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false); + auto retCode = abilityMs_->BlockAllAppStart(true); + EXPECT_EQ(retCode, ERR_PERMISSION_DENIED); + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, false); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: BlockAllAppStart_003 + * Function: BlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService BlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, BlockAllAppStart_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_003 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + AppUtils::isStartOptionsWithAnimation_ = true; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasBlockAllAppStartPermission = false; + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission(), false); + auto retCode = abilityMs_->BlockAllAppStart(true); + EXPECT_EQ(retCode, ERR_PERMISSION_DENIED); + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, false); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: BlockAllAppStart_004 + * Function: BlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService BlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, BlockAllAppStart_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_004 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasBlockAllAppStartPermission = true; + AppUtils::isStartOptionsWithAnimation_ = true; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true); + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission(), true); + auto retCode = abilityMs_->BlockAllAppStart(false); + EXPECT_EQ(retCode, ERR_OK); + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, false); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest BlockAllAppStart_004 end"); +} + +/* + * Feature: AbilityManagerService + * Name: ShouldBlockAllAppStart_001 + * Function: ShouldBlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService ShouldBlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, ShouldBlockAllAppStart_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + AppUtils::isStartOptionsWithAnimation_ = true; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true); + abilityMs_->shouldBlockAllAppStart_ = true; + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, true); + EXPECT_EQ(abilityMs_->ShouldBlockAllAppStart(), true); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: ShouldBlockAllAppStart_002 + * Function: ShouldBlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService ShouldBlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, ShouldBlockAllAppStart_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_002 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + AppUtils::isStartOptionsWithAnimation_ = false; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false); + EXPECT_EQ(abilityMs_->ShouldBlockAllAppStart(), false); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: ShouldBlockAllAppStart_003 + * Function: ShouldBlockAllAppStart + * SubFunction: NA + * FunctionPoints: AbilityManagerService ShouldBlockAllAppStart + */ +HWTEST_F(AbilityManagerServiceSeventhTest, ShouldBlockAllAppStart_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_003 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + AppUtils::isStartOptionsWithAnimation_ = true; + EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true); + abilityMs_->shouldBlockAllAppStart_ = false; + EXPECT_EQ(abilityMs_->shouldBlockAllAppStart_, false); + EXPECT_EQ(abilityMs_->ShouldBlockAllAppStart(), false); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest ShouldBlockAllAppStart_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_001 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasStartUIAbilityToHiddenPermission = true; + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyStartUIAbilityToHiddenPermission(), true); + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + startOptions.processOptions = std::make_shared(); + startOptions.processOptions->processMode = ProcessMode::NO_ATTACHMENT; + startOptions.processOptions->startupVisibility = StartupVisibility::STARTUP_HIDE; + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_002 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_002 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_003 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_003 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + startOptions.processOptions = std::make_shared(); + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_004 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_004 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasStartUIAbilityToHiddenPermission = true; + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyStartUIAbilityToHiddenPermission(), true); + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + startOptions.processOptions = std::make_shared(); + startOptions.processOptions->processMode = ProcessMode::NO_ATTACHMENT; + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_NOT_SELF_APPLICATION); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_004 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_005 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_005 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = 0; + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + startOptions.processOptions = std::make_shared(); + startOptions.processOptions->processMode = ProcessMode::NO_ATTACHMENT; + startOptions.processOptions->startupVisibility = StartupVisibility::STARTUP_HIDE; + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_NOT_SELF_APPLICATION); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_005 end"); +} + +/* + * Feature: AbilityManagerService + * Name: CheckProcessOptions_006 + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSeventhTest, CheckProcessOptions_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_006 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL; + PermissionVerification::hasStartUIAbilityToHiddenPermission = false; + EXPECT_EQ(PermissionVerification::GetInstance()->VerifyStartUIAbilityToHiddenPermission(), false); + Want want; + want.SetElementName("bundle", "ability"); + StartOptions startOptions; + startOptions.processOptions = std::make_shared(); + startOptions.processOptions->processMode = ProcessMode::NO_ATTACHMENT; + startOptions.processOptions->startupVisibility = StartupVisibility::STARTUP_HIDE; + auto retCode = abilityMs_->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(retCode, ERR_NOT_SELF_APPLICATION); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSeventhTest CheckProcessOptions_006 end"); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_manager_service_seventh_test/include/app_utils.h b/test/unittest/ability_manager_service_seventh_test/include/app_utils.h new file mode 100644 index 0000000000..0e115c4a3a --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/include/app_utils.h @@ -0,0 +1,38 @@ +/* + * 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_APP_UTILS_H +#define OHOS_ABILITY_RUNTIME_APP_UTILS_H + +#include "nocopyable.h" + +namespace OHOS { +namespace AAFwk { +class AppUtils { +public: + static AppUtils &GetInstance(); + static bool isStartOptionsWithAnimation_; + + ~AppUtils(); + bool IsStartOptionsWithAnimation(); + +private: + AppUtils(); + + DISALLOW_COPY_AND_MOVE(AppUtils); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H diff --git a/test/unittest/ability_manager_service_seventh_test/include/mock_ability_manager_service.h b/test/unittest/ability_manager_service_seventh_test/include/mock_ability_manager_service.h new file mode 100644 index 0000000000..6f5024c65c --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/include/mock_ability_manager_service.h @@ -0,0 +1,41 @@ +/* + * 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_ABILITY_MANAGER_SERVICE_H +#define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H + +#include "ffrt.h" +#include "start_options.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class AbilityManagerService + * AbilityManagerService provides a facility for managing ability life cycle. + */ +class AbilityManagerService : public std::enable_shared_from_this { +public: + int32_t BlockAllAppStart(bool flag); + int32_t CheckProcessOptions(const Want &want, const StartOptions &startOptions, int32_t userId); + bool ShouldBlockAllAppStart(); + +public: + ffrt::mutex shouldBlockAllAppStartMutex_; + bool shouldBlockAllAppStart_ = false; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H diff --git a/test/unittest/ability_manager_service_seventh_test/include/permission_verification.h b/test/unittest/ability_manager_service_seventh_test/include/permission_verification.h new file mode 100644 index 0000000000..2d1583891f --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/include/permission_verification.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H +#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H + +#include "singleton.h" + +namespace OHOS { +namespace AAFwk { +class PermissionVerification : public DelayedSingleton { +public: + PermissionVerification() = default; + ~PermissionVerification() = default; + + enum FLAG { + IS_SA_CALL = 1, + }; + + static bool hasBlockAllAppStartPermission; + static bool hasStartUIAbilityToHiddenPermission; + static int flag; + + bool IsSACall(); + + bool VerifyBlockAllAppStartPermission(); + + bool VerifyStartUIAbilityToHiddenPermission(); + +private: + DISALLOW_COPY_AND_MOVE(PermissionVerification); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H diff --git a/test/unittest/ability_manager_service_seventh_test/src/app_utils.cpp b/test/unittest/ability_manager_service_seventh_test/src/app_utils.cpp new file mode 100644 index 0000000000..aa27d97252 --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/src/app_utils.cpp @@ -0,0 +1,40 @@ +/* + * 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 "app_utils.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AAFwk { +bool AppUtils::isStartOptionsWithAnimation_ = false; + +AppUtils::~AppUtils() {} + +AppUtils::AppUtils() {} + +AppUtils &AppUtils::GetInstance() +{ + static AppUtils utils; + return utils; +} + +bool AppUtils::IsStartOptionsWithAnimation() +{ + TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isStartOptionsWithAnimation_); + return isStartOptionsWithAnimation_; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_manager_service_seventh_test/src/mock_ability_manager_service.cpp b/test/unittest/ability_manager_service_seventh_test/src/mock_ability_manager_service.cpp new file mode 100644 index 0000000000..2fb86a0334 --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/src/mock_ability_manager_service.cpp @@ -0,0 +1,78 @@ +/* + * 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 "mock_ability_manager_service.h" + +#include "ability_manager_errors.h" +#include "app_utils.h" +#include "hilog_tag_wrapper.h" +#include "permission_verification.h" +#include "process_options.h" + +namespace OHOS { +namespace AAFwk { +int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const StartOptions &startOptions, int32_t userId) +{ + if (startOptions.processOptions == nullptr || + !ProcessOptions::IsValidProcessMode(startOptions.processOptions->processMode)) { + return ERR_OK; + } + + TAG_LOGI(AAFwkTag::ABILITYMGR, "start ability with process options"); + + bool isStartupVisibilityHide = + (startOptions.processOptions->startupVisibility == StartupVisibility::STARTUP_HIDE); + bool hasStartBackgroundAbilityPermission = PermissionVerification::GetInstance()-> + VerifyStartUIAbilityToHiddenPermission(); + bool canStartupHide = (ProcessOptions::IsNoAttachmentMode(startOptions.processOptions->processMode) && + isStartupVisibilityHide && hasStartBackgroundAbilityPermission); + if (!canStartupHide) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not self application and has no start background ability permission"); + return ERR_NOT_SELF_APPLICATION; + } + + return ERR_OK; +} + +int32_t AbilityManagerService::BlockAllAppStart(bool flag) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); + + if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not supported device"); + return ERR_PERMISSION_DENIED; + } + + if (!PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission verification failed"); + return ERR_PERMISSION_DENIED; + } + + std::unique_lock lock(shouldBlockAllAppStartMutex_); + shouldBlockAllAppStart_ = flag; + return ERR_OK; +} + +bool AbilityManagerService::ShouldBlockAllAppStart() +{ + if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) { + return false; + } + + std::unique_lock lock(shouldBlockAllAppStartMutex_); + return shouldBlockAllAppStart_; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_manager_service_seventh_test/src/permission_verification.cpp b/test/unittest/ability_manager_service_seventh_test/src/permission_verification.cpp new file mode 100644 index 0000000000..56eeda753c --- /dev/null +++ b/test/unittest/ability_manager_service_seventh_test/src/permission_verification.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#include "permission_verification.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AAFwk { +int PermissionVerification::flag = 0; +bool PermissionVerification::hasBlockAllAppStartPermission = false; +bool PermissionVerification::hasStartUIAbilityToHiddenPermission = false; + +bool PermissionVerification::IsSACall() +{ + return (flag == FLAG::IS_SA_CALL); +} + +bool PermissionVerification::VerifyBlockAllAppStartPermission() +{ + if (IsSACall() && hasBlockAllAppStartPermission) { + TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); + return true; + } + TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied"); + return false; +} + +bool PermissionVerification::VerifyStartUIAbilityToHiddenPermission() +{ + if (IsSACall() && hasStartUIAbilityToHiddenPermission) { + TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted"); + return true; + } + TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied"); + return false; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_manager_service_sixth_test/BUILD.gn b/test/unittest/ability_manager_service_sixth_test/BUILD.gn index 1c2a99684a..a3e48cee87 100644 --- a/test/unittest/ability_manager_service_sixth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_sixth_test/BUILD.gn @@ -28,25 +28,39 @@ ohos_unittest("ability_manager_service_sixth_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime/", "${ability_runtime_path}/interfaces/inner_api/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/scene_board", + "${ability_runtime_test_path}/mock/common/include", "${ability_runtime_test_path}/mock/mock_sa_call", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "${ability_runtime_test_path}/mock/task_handler_wrap_mock/include", "${ability_runtime_test_path}/unittest/ability_manager_client_branch_test", + "mock/include", ] sources = [ "${ability_runtime_services_path}/abilitymgr/src/ability_connect_callback_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/sub_managers_helper.cpp", "${ability_runtime_test_path}/mock/task_handler_wrap_mock/src/mock_task_handler_wrap.cpp", "ability_manager_service_sixth_test.cpp", + "mock/src/mock_my_flag.cpp", + "mock/src/mock_permission_verification.cpp", ] configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:mission_info", + "${ability_runtime_innerkits_path}/ability_manager:process_options", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", + "${ability_runtime_path}/utils/global/freeze:freeze_util", + "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/abilitymgr:mission_list", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", @@ -66,14 +80,17 @@ ohos_unittest("ability_manager_service_sixth_test") { "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", + "kv_store:distributeddata_inner", ] if (ability_runtime_graphics) { external_deps += [ "window_manager:libwsutils", "window_manager:scene_session", + "window_manager:session_manager_lite", ] } } diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index 12231d0f81..7579756629 100644 --- a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp +++ b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp @@ -18,13 +18,22 @@ #define private public #define protected public #include "ability_manager_service.h" +#include "ability_record.h" +#include "mission_list_manager.h" +#include "ui_ability_lifecycle_manager.h" #undef private #undef protected #include "ability_manager_errors.h" #include "ability_manager_stub_mock_test.h" #include "hilog_tag_wrapper.h" +#include "mock_ability_token.h" +#include "mock_bundle_manager_service.h" +#include "mock_my_flag.h" +#include "mock_permission_verification.h" #include "mock_task_handler_wrap.h" +#include "process_options.h" +#include "scene_board_judgement.h" using namespace testing; using namespace testing::ext; @@ -40,6 +49,29 @@ namespace AAFwk { namespace { const int32_t USER_ID_U100 = 100; const int32_t APP_MEMORY_SIZE = 512; +constexpr const char* DEBUG_APP = "debugApp"; +const std::string TEST_BUNDLE_NAME = "testBundleName"; +const std::string TEST_ABILITY_NAME = "testAbilityName"; +const std::string CONTACTS_BUNDLE_NAME = "com.ohos.contacts"; +const std::string CONTACTS_ABILITY_NAME = "com.ohos.contacts.MainAbility"; +const std::string DEVICE_MANAGER_BUNDLE_NAME = "com.ohos.devicemanagerui"; +const std::string DEVICE_MANAGER_NAME = "com.ohos.devicemanagerui.MainAbility"; +const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; +const std::string AUTO_FILL_PASSWORD_TPYE = "autoFill/password"; +const std::string AUTO_FILL_SMART_TPYE = "autoFill/smart"; +const std::string AUTO_FILL_PASSWORD_ABILITY_NAME = "AutoFillAbility"; +const std::string AUTO_FILL_PASSWORD_BUNDLE_NAME = "com.ohos.passwordbox"; +const std::string AUTO_FILL_MODULE_NAME = "entry"; +const std::string AUTO_FILL_SMART_ABILITY_NAME = "TextAutoFillAbility"; +const std::string AUTO_FILL_SMART_BUNDLE_NAME = "com.ohos.textautofill"; +const int32_t MAIN_USER_ID = 100; +const std::string EMPTY_DEVICE_ID = ""; +constexpr const char* BUNDLE_NAME_LAUNCHER = "com.ohos.launcher"; +constexpr const char* BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; +constexpr const char* LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; +constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; +constexpr const char* BUNDLE_NAME_TEST = "com.huawei.hmos.passwordvault"; +constexpr const char* BUNDLE_NAME_SMART_TEST = "com.huawei.hms.textautofill"; } // namespace class AbilityManagerServiceSixthTest : public testing::Test { public: @@ -51,9 +83,12 @@ public: AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName, const std::string& appName, const std::string& bundleName, const std::string& moduleName); + std::shared_ptr MockAbilityManagerService(); + public: AbilityRequest abilityRequest_{}; Want want_{}; + AbilityStartSetting abilityStartSetting_; }; AbilityRequest AbilityManagerServiceSixthTest::GenerateAbilityRequest(const std::string& deviceName, @@ -83,6 +118,18 @@ AbilityRequest AbilityManagerServiceSixthTest::GenerateAbilityRequest(const std: return abilityRequest; } +std::shared_ptr AbilityManagerServiceSixthTest::MockAbilityManagerService() +{ + auto abilityMs = std::make_shared(); + auto taskHandler = MockTaskHandlerWrap::CreateQueueHandler("StartAbilityDetails_003"); + auto eventHandler = std::make_shared(taskHandler, abilityMs); + abilityMs->taskHandler_ = taskHandler; + abilityMs->interceptorExecuter_ = std::make_shared(); + abilityMs->afterCheckExecuter_ = std::make_shared(); + abilityMs->subManagersHelper_ = std::make_shared(taskHandler, eventHandler); + return abilityMs; +} + void AbilityManagerServiceSixthTest::SetUpTestCase() {} void AbilityManagerServiceSixthTest::TearDownTestCase() {} @@ -200,5 +247,626 @@ HWTEST_F(AbilityManagerServiceSixthTest, StartUIAbilityBySCBDefault_001, TestSiz EXPECT_EQ(abilityMs->StartUIAbilityBySCBDefault(sessionInfo, sceneFlag, isColdStart), RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartUIAbilityBySCBDefault_001 end"); } + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityDetails + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityDetails_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_001 start"); + auto abilityMs = std::make_shared(); + Want want; + want.SetParam(DEBUG_APP, true); + want.SetElementName(TEST_BUNDLE_NAME, ""); + + /** + * @tc.steps: step1. DEBUG app which is not exists + * @tc.expected: step1. expect RESOLVE_ABILITY_ERR + */ + auto ret = abilityMs->StartAbilityDetails(want, abilityStartSetting_, nullptr, -1, -1, false); + EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityDetails + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityDetails_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_0200 start"); + + Want want; + want.SetParam(DEBUG_APP, true); + want.SetElementName(CONTACTS_BUNDLE_NAME, CONTACTS_ABILITY_NAME); + auto abilityMs = std::make_shared(); + auto ret = abilityMs->StartAbilityDetails(want, abilityStartSetting_, nullptr, -1, -1, false); + + /** + * @tc.steps: step2. CONTACTS_BUNDLE_NAME + * @tc.expected: step2. expect ERR_NOT_IN_APP_PROVISION_MODE + */ + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); + } else { + EXPECT_EQ(ret, ERR_NOT_IN_APP_PROVISION_MODE); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_0200 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityDetails + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityDetails_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_002 start"); + auto abilityMs = std::make_shared(); + + /** + * @tc.steps: step1. interceptorExecuter_ is null + * @tc.expected: step1. expect return ERR_INVALID_VALUE when interceptorExecuter_ null + */ + Want want1; + want1.SetElementName(DEVICE_MANAGER_BUNDLE_NAME, DEVICE_MANAGER_NAME); + auto ret = abilityMs->StartAbilityDetails(want1, abilityStartSetting_, nullptr, MAIN_USER_ID, -1, false); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_002 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityDetails + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityDetails_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_003 start"); + + Want want; + want.SetElementName(CONTACTS_BUNDLE_NAME, CONTACTS_ABILITY_NAME); + auto abilityMs = MockAbilityManagerService(); + auto ret = abilityMs->StartAbilityDetails(want, abilityStartSetting_, nullptr, -1, -1, false); + + /** + * @tc.steps: step2. interceptorExecuter_ is inited, for CONTACTS_BUNDLE_NAME is sigeleton,usrid 0 + * @tc.expected: step2. expect missionListManager/uiAbilityManager null, return ERR_INVALID_VALUE + */ + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); + } else { + EXPECT_EQ(ret, ERR_INVALID_VALUE); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_003 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityInner + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityInner_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityInner_001 start"); + auto abilityMs = std::make_shared(); + abilityMs->taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("StartAbilityInner_001"); + abilityMs->interceptorExecuter_ = std::make_shared(); + abilityMs->afterCheckExecuter_ = std::make_shared(); + Want want; + want.SetElementName(CONTACTS_BUNDLE_NAME, CONTACTS_ABILITY_NAME); + auto ret = abilityMs->StartAbilityInner(want, nullptr, -1, false); + + /** + * @tc.steps: step2. interceptorExecuter_ is inited, for CONTACTS_BUNDLE_NAME is sigeleton,usrid 0 + * @tc.expected: step2. expect missionListManager/uiAbilityManager null, return ERR_INVALID_VALUE + */ + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); + } else { + EXPECT_EQ(ret, ERR_INVALID_VALUE); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityInner_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartAbilityDetails + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartAbilityInner + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityInner_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityInner_002 start"); + auto abilityMs = std::make_shared(); + + abilityMs->taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("StartAbilityInner_002"); + abilityMs->interceptorExecuter_ = std::make_shared(); + abilityMs->afterCheckExecuter_ = std::make_shared(); + Want want; + want.SetFlags(Want::FLAG_ABILITY_PREPARE_CONTINUATION); + auto ret = abilityMs->StartAbilityInner(want, nullptr, -1, false, -1, false, -1, true); + EXPECT_EQ(ret, ERR_INVALID_CONTINUATION_FLAG); + + /** + * @tc.steps: step2. interceptorExecuter_ is inited, for CONTACTS_BUNDLE_NAME is sigeleton,usrid 0 + * @tc.expected: step2. expect missionListManager/uiAbilityManager null, return ERR_INVALID_VALUE + */ + auto callerToken = sptr::MakeSptr(); + MyFlag::flag_ = MyFlag::IS_SA_CALL; + Want want2; + want2.SetElementName(CONTACTS_BUNDLE_NAME, CONTACTS_ABILITY_NAME); + ret = abilityMs->StartAbilityInner(want2, callerToken, -1, false, -1, true, 1, true); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); + } else { + EXPECT_EQ(ret, ERR_INVALID_VALUE); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityInner_002 end"); +} + +/* + * Feature: AbilityManagerService + * Function: SetAutoFillElementName + * SubFunction: NA + * FunctionPoints: AbilityManagerService SetAutoFillElementName + */ +HWTEST_F(AbilityManagerServiceSixthTest, SetAutoFillElementName_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest SetAutoFillElementName_001 start"); + auto abilityMs = std::make_shared(); + sptr extensionSessionInfo = sptr::MakeSptr(); + extensionSessionInfo->want.SetParam(UIEXTENSION_TYPE_KEY, AUTO_FILL_PASSWORD_TPYE); + abilityMs->SetAutoFillElementName(extensionSessionInfo); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(extensionSessionInfo->want.GetBundle(), BUNDLE_NAME_TEST); + EXPECT_EQ(extensionSessionInfo->want.GetModuleName(), AUTO_FILL_MODULE_NAME); + } else { + EXPECT_EQ(extensionSessionInfo->want.GetBundle(), AUTO_FILL_PASSWORD_BUNDLE_NAME); + EXPECT_EQ(extensionSessionInfo->want.GetModuleName(), AUTO_FILL_MODULE_NAME); + } + + extensionSessionInfo->want.SetParam(UIEXTENSION_TYPE_KEY, AUTO_FILL_SMART_TPYE); + abilityMs->SetAutoFillElementName(extensionSessionInfo); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(extensionSessionInfo->want.GetBundle(), BUNDLE_NAME_SMART_TEST); + EXPECT_EQ(extensionSessionInfo->want.GetModuleName(), AUTO_FILL_MODULE_NAME); + } else { + EXPECT_EQ(extensionSessionInfo->want.GetBundle(), AUTO_FILL_PASSWORD_BUNDLE_NAME); + EXPECT_EQ(extensionSessionInfo->want.GetModuleName(), AUTO_FILL_MODULE_NAME); + } + + extensionSessionInfo->want = Want(); + EXPECT_EQ(extensionSessionInfo->want.GetBundle(), ""); + EXPECT_EQ(extensionSessionInfo->want.GetModuleName(), ""); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest SetAutoFillElementName_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: CheckUIExtensionUsage + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckUIExtensionUsage + */ +HWTEST_F(AbilityManagerServiceSixthTest, CheckUIExtensionUsage_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckUIExtensionUsage_001 start"); + auto abilityMs = std::make_shared(); + AppExecFwk::UIExtensionUsage uiExtensionUsage = UIExtensionUsage::MODAL; + AppExecFwk::ExtensionAbilityType extensionType = ExtensionAbilityType::WINDOW; + auto ret = abilityMs->CheckUIExtensionUsage(uiExtensionUsage, extensionType); + EXPECT_EQ(ret, ERR_OK); + + MyFlag::flag_ = MyFlag::IS_SA_CALL; + uiExtensionUsage = UIExtensionUsage::EMBEDDED; + extensionType = AppExecFwk::ExtensionAbilityType::AUTO_FILL_PASSWORD; + ret = abilityMs->CheckUIExtensionUsage(uiExtensionUsage, extensionType); + EXPECT_EQ(ret, ERR_OK); + + extensionType = AppExecFwk::ExtensionAbilityType::SERVICE; + ret = abilityMs->CheckUIExtensionUsage(uiExtensionUsage, extensionType); + EXPECT_EQ(ret, ERR_OK); + + uiExtensionUsage = UIExtensionUsage::CONSTRAINED_EMBEDDED; + extensionType = AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER; + ret = abilityMs->CheckUIExtensionUsage(uiExtensionUsage, extensionType); + EXPECT_EQ(ret, ERR_OK); + + uiExtensionUsage = UIExtensionUsage::CONSTRAINED_EMBEDDED; + extensionType = AppExecFwk::ExtensionAbilityType::WINDOW; + ret = abilityMs->CheckUIExtensionUsage(uiExtensionUsage, extensionType); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckUIExtensionUsage_001 end"); + MyFlag::flag_ = 0; +} + +/* + * Feature: AbilityManagerService + * Function: CheckProcessOptions + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckProcessOptions + */ +HWTEST_F(AbilityManagerServiceSixthTest, CheckProcessOptions_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckProcessOptions_001 start"); + auto abilityMs = std::make_shared(); + + Want want; + StartOptions startOptions; + auto ret = abilityMs->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(ret, ERR_OK); + + startOptions.processOptions = std::make_shared(); + ret = abilityMs->CheckProcessOptions(want, startOptions, -1); + EXPECT_EQ(ret, ERR_OK); + + startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT; + ret = abilityMs->CheckProcessOptions(want, startOptions, -1); + if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + EXPECT_EQ(ret, ERR_CAPABILITY_NOT_SUPPORT); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckProcessOptions_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: PreStartFreeInstall + * SubFunction: NA + * FunctionPoints: AbilityManagerService PreStartFreeInstall + */ +HWTEST_F(AbilityManagerServiceSixthTest, PreStartFreeInstall_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest PreStartFreeInstall_001 start"); + Want want; + Want localWant; + uint32_t specifyTokenId { 0 }; + bool isStartAsCaller { false }; + auto callerToken = sptr::MakeSptr(); + auto abilityMs_ = std::make_shared(); + abilityMs_->freeInstallManager_ = std::make_shared(abilityMs_); + auto ret = abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + EXPECT_EQ(ret, ERR_OK); + + specifyTokenId = 1; + ret = abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + EXPECT_EQ(ret, ERR_OK); + + localWant.SetDeviceId("testDevice"); + specifyTokenId = 1; + callerToken = nullptr; + ret = abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + EXPECT_EQ(ret, ERR_OK); + + ret = abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, true, localWant); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest PreStartFreeInstall_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: CheckOptExtensionAbility + * SubFunction: NA + * FunctionPoints: AbilityManagerService CheckOptExtensionAbility + */ +HWTEST_F(AbilityManagerServiceSixthTest, CheckOptExtensionAbility_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckOptExtensionAbility_001 start"); + Want want; + AbilityRequest abilityRequest; + auto abilityMs_ = std::make_shared(); + AppExecFwk::ExtensionAbilityType extensionType = ExtensionAbilityType::FORM; + int32_t validUserId = 0; + bool isImplicit = false; + bool isStartAsCaller = true; + auto ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); + + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + extensionType = AppExecFwk::ExtensionAbilityType::SERVICE; + ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); + + extensionType = AppExecFwk::ExtensionAbilityType::SERVICE; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE; + abilityRequest.want.SetElementName(TEST_BUNDLE_NAME, CONTACTS_ABILITY_NAME); + ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_OK); + + extensionType = AppExecFwk::ExtensionAbilityType::DATASHARE; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::DATASHARE; + ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_OK); + + extensionType = AppExecFwk::ExtensionAbilityType::UI_SERVICE; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI_SERVICE; + ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_OK); + + isStartAsCaller = false; + extensionType = ExtensionAbilityType::FORM; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::FORM; + ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, + isImplicit, isStartAsCaller); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckOptExtensionAbility_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: StartExtensionAbility + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartExtensionAbility + */ +HWTEST_F(AbilityManagerServiceSixthTest, StartExtensionAbility_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartExtensionAbility_001 start"); + auto abilityMs = MockAbilityManagerService(); + Want want; + AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UI_SERVICE; + auto ret = abilityMs->StartExtensionAbility(want, nullptr, -1, extensionType); + EXPECT_EQ(ret, ERR_CAPABILITY_NOT_SUPPORT); + + extensionType = AppExecFwk::ExtensionAbilityType::VPN; + ret = abilityMs->StartExtensionAbility(want, nullptr, -1, extensionType); + EXPECT_EQ(ret, ERR_IMPLICIT_START_ABILITY_FAIL); // implicit start ability failed + + auto callerToken = sptr::MakeSptr(); // callerToken not null + ret = abilityMs->StartExtensionAbility(want, callerToken, -1, extensionType); + EXPECT_EQ(ret, ERR_INVALID_CALLER); // caller is not null,expect Invalid caller + + extensionType = AppExecFwk::ExtensionAbilityType::DATASHARE; + ret = abilityMs->StartExtensionAbility(want, nullptr, -1, extensionType); + EXPECT_EQ(ret, ERR_IMPLICIT_START_ABILITY_FAIL); // expect implicit start fail +} + +/* + * Feature: AbilityManagerService + * Function: RecordProcessExitReason + * SubFunction: NA + * FunctionPoints: AbilityManagerService RecordProcessExitReason + */ +HWTEST_F(AbilityManagerServiceSixthTest, RecordProcessExitReason_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest RecordProcessExitReason_001 start"); + auto abilityMs = MockAbilityManagerService(); + MyFlag::flag_ = 0; + ExitReason exitReason; + auto ret = abilityMs->RecordProcessExitReason(1, exitReason); + EXPECT_EQ(ret, ERR_PERMISSION_DENIED); + + MyFlag::flag_ = MyFlag::IS_SA_CALL; + ret = abilityMs->RecordProcessExitReason(1, exitReason); + EXPECT_EQ(ret, ERR_NAME_NOT_FOUND); // init process not record + + MyFlag::flag_ = MyFlag::IS_SHELL_CALL; + ret = abilityMs->RecordProcessExitReason(1, exitReason); + EXPECT_EQ(ret, ERR_NAME_NOT_FOUND); // init process not record + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest RecordProcessExitReason_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: AnonymizeDeviceId + * SubFunction: NA + * FunctionPoints: AbilityManagerService AnonymizeDeviceId + */ +HWTEST_F(AbilityManagerServiceSixthTest, AnonymizeDeviceId_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest AnonymizeDeviceId_001 start"); + auto abilityMs = MockAbilityManagerService(); + std::string deviceId; + auto ret = abilityMs->AnonymizeDeviceId(deviceId); + EXPECT_EQ(ret, EMPTY_DEVICE_ID); + + deviceId = std::string("1234567890"); + ret = abilityMs->AnonymizeDeviceId(deviceId); + EXPECT_EQ(ret, "123456******"); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest AnonymizeDeviceId_001 start"); +} + +/* + * Feature: AbilityManagerService + * Function: MinimizeAbility + * SubFunction: NA + * FunctionPoints: AbilityManagerService MinimizeAbility + */ +HWTEST_F(AbilityManagerServiceSixthTest, MinimizeAbility_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest MinimizeAbility_001 start"); + auto abilityMs = MockAbilityManagerService(); + bool fromUser = true; + auto ret = abilityMs->MinimizeAbility(nullptr, fromUser); + EXPECT_EQ(ret, ERR_INVALID_VALUE); // expect nullptr callerToken invalid + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + auto abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord->Init(); + auto token = abilityRecord->token_; + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + auto uiAbilityLifecycleManager = std::make_shared(); + uiAbilityLifecycleManager->sessionAbilityMap_.emplace(0, abilityRecord); + abilityMs->subManagersHelper_->uiAbilityManagers_.emplace(0, uiAbilityLifecycleManager); + } else { + auto missionListManager = std::make_shared(0); + missionListManager->terminateAbilityList_.emplace_back(abilityRecord); + abilityMs->subManagersHelper_->missionListManagers_.emplace(0, missionListManager); + ret = abilityMs->MinimizeAbility(token, fromUser); + EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); // expect ERR_WRONG_INTERFACE_CALL abilityRecord type not page + + abilityRecord->abilityInfo_.type = AppExecFwk::AbilityType::PAGE; + ret = abilityMs->MinimizeAbility(token, fromUser); + EXPECT_EQ(ret, ERR_INVALID_VALUE); // expect ERR_INVALID_VALUE + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest MinimizeAbility_001 start"); +} + +/* + * Feature: AbilityManagerService + * Function: TerminateAbility + * SubFunction: NA + * FunctionPoints: AbilityManagerService TerminateAbility + */ +HWTEST_F(AbilityManagerServiceSixthTest, TerminateAbility_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest TerminateAbility_001 start"); + auto abilityMs = MockAbilityManagerService(); + Want resultWant; + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + resultWant.SetElementName(BUNDLE_NAME_SCENEBOARD, SCENEBOARD_ABILITY_NAME); + } else { + resultWant.SetElementName(BUNDLE_NAME_LAUNCHER, LAUNCHER_ABILITY_NAME); + } + + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + auto abilityRecord = std::make_shared(resultWant, abilityInfo, applicationInfo); + abilityRecord->Init(); + auto token = abilityRecord->token_; + int resultCode = 0; + auto ret = abilityMs->TerminateAbility(nullptr, resultCode, &resultWant); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + + ret = abilityMs->TerminateAbility(token, resultCode, &resultWant); + EXPECT_EQ(ret, ERR_OK); + + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + resultWant.SetElementName(BUNDLE_NAME_SCENEBOARD, ""); + } else { + resultWant.SetElementName(BUNDLE_NAME_LAUNCHER, ""); + } + ret = abilityMs->TerminateAbility(token, resultCode, &resultWant); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest TerminateAbility_001 start"); +} + +/* + * Feature: AbilityManagerService + * Function: MinimizeUIAbilityBySCB + * SubFunction: NA + * FunctionPoints: AbilityManagerService MinimizeUIAbilityBySCB + */ +HWTEST_F(AbilityManagerServiceSixthTest, MinimizeUIAbilityBySCB_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest MinimizeUIAbilityBySCB_001 start"); + auto abilityMs = MockAbilityManagerService(); + auto ret = abilityMs->MinimizeUIAbilityBySCB(nullptr, false, 0); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + + auto sessionInfo = sptr::MakeSptr(); + ret = abilityMs->MinimizeUIAbilityBySCB(sessionInfo, false, 0); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + Want resultWant; + auto abilityRecord = std::make_shared(resultWant, abilityInfo, applicationInfo); + abilityRecord->Init(); + sessionInfo->sessionToken = abilityRecord->token_; + ret = abilityMs->MinimizeUIAbilityBySCB(sessionInfo, false, 0); + if (!abilityMs->IsCallerSceneBoard()) { + EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); + } else { + EXPECT_EQ(ret, ERR_INVALID_VALUE); + } + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest MinimizeUIAbilityBySCB_001 start"); +} + +/* + * Feature: AbilityManagerService + * Function: DumpState + * SubFunction: NA + * FunctionPoints: AbilityManagerService DumpState + */ +HWTEST_F(AbilityManagerServiceSixthTest, DumpState_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest DumpState_001 start"); + auto abilityMs = MockAbilityManagerService(); + std::string args; + std::vector info; + MyFlag::flag_ = 0; + abilityMs->DumpState(args, info); + EXPECT_TRUE(info.empty()); // permission deny + + MyFlag::flag_ = MyFlag::IS_SHELL_CALL; + args = std::string(""); + abilityMs->DumpState(args, info); + EXPECT_TRUE(info.empty()); // null string + args = std::string("-e"); + abilityMs->DumpState(args, info); // KEY_DUMP_SERVICE + EXPECT_TRUE(info.empty()); + args = std::string("-d"); + abilityMs->DumpState(args, info); // KEY_DUMP_DATA + args = std::string("-a"); // KEY_DUMP_ALL + abilityMs->DumpState(args, info); + args = std::string("-m"); // KEY_DUMP_MISSION + abilityMs->DumpState(args, info); + EXPECT_FALSE(info.empty()); + args = std::string("-m 999999999"); // KEY_DUMP_MISSION 999999999 means missionID + abilityMs->DumpState(args, info); + args = std::string("-L"); // KEY_DUMP_MISSION_LIST + abilityMs->DumpState(args, info); + args = std::string("-S"); + abilityMs->DumpState(args, info); + info.clear(); + args = std::string("-NAN"); // not exsist + abilityMs->DumpState(args, info); + EXPECT_TRUE(info.empty()); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest DumpState_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: DumpSysState + * SubFunction: NA + * FunctionPoints: AbilityManagerService DumpSysState + */ +HWTEST_F(AbilityManagerServiceSixthTest, DumpSysState_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest DumpSysState_001 start"); + auto abilityMs = MockAbilityManagerService(); + std::string args; + std::vector info; + MyFlag::flag_ = 0; + abilityMs->DumpSysState(args, info, false, true, 0); + EXPECT_TRUE(info.empty()); // permission deny + MyFlag::flag_ = MyFlag::IS_SHELL_CALL; + args = std::string(""); + abilityMs->DumpState(args, info); + EXPECT_TRUE(info.empty()); // null string + args = std::string("-a"); + abilityMs->DumpSysState(args, info, false, true, 0); // KEY_DUMP_SYS_ALL + EXPECT_FALSE(info.empty()); + info.clear(); + args = std::string("-p"); + abilityMs->DumpSysState(args, info, false, true, 0); // KEY_DUMP_SYS_PENDING + args = std::string("-r"); + abilityMs->DumpSysState(args, info, false, true, INT_MAX); // KEY_DUMP_SYS_PROCESS + info.clear(); + args = std::string("-d"); // KEY_DUMP_SYS_DATA + abilityMs->DumpSysState(args, info, false, true, INT_MAX); // int_max MEANS userid + args = std::string("--mission-list"); // KEY_DUMP_SYS_MISSION_LIST + abilityMs->DumpSysState(args, info, false, true, 0); + args = std::string("-i"); // KEY_DUMP_MISSION 999999999 means missionID + abilityMs->DumpSysState(args, info, false, true, 0); + info.clear(); + args = std::string("-NAN"); // not exsist + abilityMs->DumpSysState(args, info, false, true, 0); + EXPECT_TRUE(info.empty()); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest DumpSysState_001 end"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_sixth_test/mock/include/mock_my_flag.h b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_my_flag.h new file mode 100644 index 0000000000..2ee3eafe7f --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_my_flag.h @@ -0,0 +1,31 @@ +/* + * 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 MOCK_MY_FLAG_H +#define MOCK_MY_FLAG_H +namespace OHOS { +namespace AAFwk { +class MyFlag { +public: + enum FLAG { + IS_SA_CALL = 1, + IS_SHELL_CALL, + IS_SA_AND_SHELL_CALL, + }; + static int flag_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // MOCK_MY_FLAG_H \ No newline at end of file diff --git a/test/unittest/ability_manager_service_sixth_test/mock/include/mock_permission_verification.h b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_permission_verification.h new file mode 100644 index 0000000000..a2552bfa7b --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_permission_verification.h @@ -0,0 +1,102 @@ +/* + * 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_PERMISSION_VERIFICATION_H +#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H + +#include + +#include "ipc_skeleton.h" +#include "singleton.h" +#include "want.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { + +class PermissionVerification : public DelayedSingleton { +public: +struct VerificationInfo { + bool visible = false; + bool isBackgroundCall = true; + bool associatedWakeUp = false; + uint32_t accessTokenId = 0; + int32_t apiTargetVersion = 0; +}; + + PermissionVerification() = default; + ~PermissionVerification() = default; + + bool VerifyCallingPermission(const std::string &permissionName) const; + + bool IsSACall() const; + + bool IsShellCall() const; + + bool CheckSpecificSystemAbilityAccessPermission(const std::string &processName) const; + + bool VerifyRunningInfoPerm() const; + + bool VerifyControllerPerm() const; + + bool VerifyDlpPermission(Want &want) const; + + int VerifyAccountPermission() const; + + bool VerifyMissionPermission() const; + + int VerifyAppStateObserverPermission() const; + + int32_t VerifyUpdateConfigurationPerm() const; + + bool VerifyInstallBundlePermission() const; + + bool VerifyGetBundleInfoPrivilegedPermission() const; + + int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; + + int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; + + int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const; + + int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const; + + int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; + + unsigned int GetCallingTokenID() const; + + bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const; + + bool JudgeStartAbilityFromBackground(const bool isBackgroundCall) const; + + bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const; + + int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const; + + inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const + { + return IPCSkeleton::GetCallingTokenID() == accessTokenId; + } + + bool JudgeCallerIsAllowedToUseSystemAPI() const; + bool IsSystemAppCall() const; + + bool VerifyPrepareTerminatePermission() const; + + bool VerifySetProcessCachePermission() const; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/test/unittest/ability_manager_service_sixth_test/mock/src/mock_my_flag.cpp b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_my_flag.cpp new file mode 100644 index 0000000000..c509149c67 --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_my_flag.cpp @@ -0,0 +1,22 @@ +/* + * 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 "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +int MyFlag::flag_ = 0; +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_manager_service_sixth_test/mock/src/mock_permission_verification.cpp b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_permission_verification.cpp new file mode 100644 index 0000000000..53db0c7b7f --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_permission_verification.cpp @@ -0,0 +1,134 @@ +/* + * 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 "mock_permission_verification.h" + +namespace OHOS { +namespace AAFwk { + +bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::IsSACall() const +{ + return (MyFlag::flag_ & MyFlag::FLAG::IS_SA_CALL); +} +bool PermissionVerification::IsShellCall() const +{ + return (MyFlag::flag_ & MyFlag::FLAG::IS_SHELL_CALL); +} + +bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission(const std::string &processName) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyRunningInfoPerm() const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyControllerPerm() const +{ + return !!(MyFlag::flag_); +} +#ifdef WITH_DLP +bool PermissionVerification::VerifyDlpPermission(Want &want) const +{ + return !!(MyFlag::flag_); +} +#endif // WITH_DLP +int PermissionVerification::VerifyAccountPermission() const +{ + return MyFlag::flag_; +} +bool PermissionVerification::VerifyMissionPermission() const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::VerifyAppStateObserverPermission() const +{ + return MyFlag::flag_; +} +int32_t PermissionVerification::VerifyUpdateConfigurationPerm() const +{ + return static_cast(MyFlag::flag_); +} +bool PermissionVerification::VerifyInstallBundlePermission() const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckStartByCallPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +unsigned int PermissionVerification::GetCallingTokenID() const +{ + return static_cast(MyFlag::flag_); +} +bool PermissionVerification::JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::JudgeStartAbilityFromBackground(const bool isBackgroundCall) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const +{ + return true; +} +bool PermissionVerification::VerifyPrepareTerminatePermission() const +{ + return true; +} +bool PermissionVerification::IsSystemAppCall() const +{ + return true; +} + +bool PermissionVerification::VerifySetProcessCachePermission() const +{ + return true; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_permission_util_test/BUILD.gn b/test/unittest/ability_permission_util_test/BUILD.gn index 2fe8ef429c..65ccbf477d 100644 --- a/test/unittest/ability_permission_util_test/BUILD.gn +++ b/test/unittest/ability_permission_util_test/BUILD.gn @@ -19,27 +19,68 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_permission_util_test") { module_out_path = module_output_path - sources = [ "ability_permission_util_test.cpp" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime/", + "${ability_runtime_path}/interfaces/inner_api/ability_manager/include", + "${ability_runtime_test_path}/mock/ability_manager_collaborator", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/mock/mock_sa_call", + "${ability_runtime_test_path}/mock/prepare_terminate_callback", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include", + "${ability_runtime_test_path}/unittest/app_debug_listener_stub_test", + "mock/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + sources = [ + "ability_permission_util_test.cpp", + "mock/src/mock_my_flag.cpp", + "mock/src/mock_permission_verification.cpp", + ] + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "//third_party/googletest:gtest_main", ] external_deps = [ + "ability_base:base", + "ability_base:configuration", "ability_base:want", - "ability_runtime:app_manager", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "access_token:libaccesstoken_sdk", + "appspawn:appspawn_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", "ffrt:libffrt", + "hicollie:libhicollie", "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "jsoncpp:jsoncpp", + "kv_store:distributeddata_mgr", + "memory_utils:libmeminfo", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } diff --git a/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp b/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp index 34ec7c0655..827d742251 100644 --- a/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp +++ b/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp @@ -15,19 +15,31 @@ #include +#include "mock_permission_verification.h" #define private public -#include "ability_record.h" #include "utils/ability_permission_util.h" +#include "ability_info.h" +#include "ability_record.h" +#include "ability_util.h" +#include "accesstoken_kit.h" #include "app_utils.h" +#include "ipc_skeleton.h" +#include "running_process_info.h" +#include "permission_constants.h" +#include "permission_verification.h" #undef private #include "hilog_tag_wrapper.h" #include "parameters.h" using namespace testing; using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using AbilityRequest = OHOS::AAFwk::AbilityRequest; +using OHOS::AppExecFwk::AbilityType; +using OHOS::AAFwk::AbilityPermissionUtil; namespace OHOS { -namespace AAFwk { +namespace AbilityRuntime { class AbilityPermissionUtilTest : public testing::Test { public: static void SetUpTestCase(); @@ -56,11 +68,7 @@ HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndA bool isSupportMultiInstance = AppUtils::GetInstance().IsSupportMultiInstance(); std::string deviceType = OHOS::system::GetDeviceType(); TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str()); - if (deviceType == "2in1") { - EXPECT_EQ(result, RESOLVE_ABILITY_ERR); - } else { - EXPECT_EQ(result, ERR_OK); - } + EXPECT_EQ(result, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100 end"); } @@ -74,7 +82,10 @@ HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndA HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200 start"); + std::string bundleName = "com.ohos.test"; + std::string abilityName = "EntryAbility"; Want want; + want.SetElementName(bundleName, abilityName); std::string instanceKey = "app_instance_0"; want.SetParam(Want::APP_INSTANCE_KEY, instanceKey); auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 100, 0, nullptr); @@ -100,7 +111,10 @@ HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndA HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300 start"); + std::string bundleName = "com.ohos.test"; + std::string abilityName = "EntryAbility"; Want want; + want.SetElementName(bundleName, abilityName); want.SetParam(Want::CREATE_APP_INSTANCE_KEY, true); auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 100, 0, nullptr); @@ -311,5 +325,95 @@ HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceKeyF EXPECT_EQ(result, ERR_MULTI_INSTANCE_NOT_SUPPORTED); TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceKeyForExtension_0300 end"); } + +/** + * @tc.name: IsDominateScreen_0100 + * @tc.desc: IsDominateScreen_0100 Test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, IsDominateScreen_0100, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0100 start"); + + Want want; + bool isPendingWantCaller = true; + bool ret = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, isPendingWantCaller); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0100 end"); +} + +/** + * @tc.name: IsDominateScreen_0200 + * @tc.desc: IsDominateScreen_0200 Test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, IsDominateScreen_0200, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0200 start"); + + MyFlag::flag_ = 1; + Want want; + bool isPendingWantCaller = false; + bool ret = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, isPendingWantCaller); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0200 end"); +} + +/** + * @tc.name: IsDominateScreen_0300 + * @tc.desc: IsDominateScreen_0300 Test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, IsDominateScreen_0300, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0300 start"); + + MyFlag::flag_ = 2; + Want want; + bool isPendingWantCaller = false; + bool ret = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, isPendingWantCaller); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0300 end"); +} + +/** + * @tc.name: IsDominateScreen_0400 + * @tc.desc: IsDominateScreen_0400 Test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, IsDominateScreen_0400, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0400 start"); + + MyFlag::flag_ = 3; + Want want; + bool isPendingWantCaller = false; + bool ret = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, isPendingWantCaller); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0400 end"); +} + +/** + * @tc.name: IsDominateScreen_0500 + * @tc.desc: IsDominateScreen_0500 Test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, IsDominateScreen_0500, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0500 start"); + + MyFlag::flag_ = 3; + Want want; + want.SetParam("ohos.insightIntent.executeParam.name", true); + bool isPendingWantCaller = false; + bool ret = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, isPendingWantCaller); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil IsDominateScreen_0500 end"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_permission_util_test/mock/include/mock_my_flag.h b/test/unittest/ability_permission_util_test/mock/include/mock_my_flag.h new file mode 100644 index 0000000000..2ee3eafe7f --- /dev/null +++ b/test/unittest/ability_permission_util_test/mock/include/mock_my_flag.h @@ -0,0 +1,31 @@ +/* + * 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 MOCK_MY_FLAG_H +#define MOCK_MY_FLAG_H +namespace OHOS { +namespace AAFwk { +class MyFlag { +public: + enum FLAG { + IS_SA_CALL = 1, + IS_SHELL_CALL, + IS_SA_AND_SHELL_CALL, + }; + static int flag_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // MOCK_MY_FLAG_H \ No newline at end of file diff --git a/test/unittest/ability_permission_util_test/mock/include/mock_permission_verification.h b/test/unittest/ability_permission_util_test/mock/include/mock_permission_verification.h new file mode 100644 index 0000000000..4fcc914ac4 --- /dev/null +++ b/test/unittest/ability_permission_util_test/mock/include/mock_permission_verification.h @@ -0,0 +1,100 @@ +/* + * 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_PERMISSION_VERIFICATION_H +#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H + +#include "ipc_skeleton.h" +#include "singleton.h" +#include "want.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { + +class PermissionVerification : public DelayedSingleton { +public: +struct VerificationInfo { + bool visible = false; + bool isBackgroundCall = true; + bool associatedWakeUp = false; + uint32_t accessTokenId = 0; + int32_t apiTargetVersion = 0; +}; + + PermissionVerification() = default; + ~PermissionVerification() = default; + + bool VerifyCallingPermission(const std::string &permissionName) const; + + bool IsSACall() const; + + bool IsShellCall() const; + + bool CheckSpecificSystemAbilityAccessPermission() const; + + bool VerifyRunningInfoPerm() const; + + bool VerifyControllerPerm() const; + + bool VerifyDlpPermission(Want &want) const; + + int VerifyAccountPermission() const; + + bool VerifyMissionPermission() const; + + int VerifyAppStateObserverPermission() const; + + int32_t VerifyUpdateConfigurationPerm() const; + + bool VerifyInstallBundlePermission() const; + + bool VerifyGetBundleInfoPrivilegedPermission() const; + + int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; + + int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; + + int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const; + + int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const; + + int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; + + unsigned int GetCallingTokenID() const; + + bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const; + + bool JudgeStartAbilityFromBackground(const bool isBackgroundCall) const; + + bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const; + + int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const; + + inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const + { + return IPCSkeleton::GetCallingTokenID() == accessTokenId; + } + + bool JudgeCallerIsAllowedToUseSystemAPI() const; + bool IsSystemAppCall() const; + + bool VerifyPrepareTerminatePermission() const; + + bool VerifySetProcessCachePermission() const; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/test/unittest/ability_permission_util_test/mock/src/mock_my_flag.cpp b/test/unittest/ability_permission_util_test/mock/src/mock_my_flag.cpp new file mode 100644 index 0000000000..c509149c67 --- /dev/null +++ b/test/unittest/ability_permission_util_test/mock/src/mock_my_flag.cpp @@ -0,0 +1,22 @@ +/* + * 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 "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +int MyFlag::flag_ = 0; +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_permission_util_test/mock/src/mock_permission_verification.cpp b/test/unittest/ability_permission_util_test/mock/src/mock_permission_verification.cpp new file mode 100644 index 0000000000..6fbc5bcf3e --- /dev/null +++ b/test/unittest/ability_permission_util_test/mock/src/mock_permission_verification.cpp @@ -0,0 +1,133 @@ +/* + * 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 "mock_permission_verification.h" + +namespace OHOS { +namespace AAFwk { + +bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::IsSACall() const +{ + return (MyFlag::flag_ & MyFlag::FLAG::IS_SA_CALL); +} +bool PermissionVerification::IsShellCall() const +{ + return (MyFlag::flag_ & MyFlag::FLAG::IS_SHELL_CALL); +} +bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission() const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyRunningInfoPerm() const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyControllerPerm() const +{ + return !!(MyFlag::flag_); +} +#ifdef WITH_DLP +bool PermissionVerification::VerifyDlpPermission(Want &want) const +{ + return !!(MyFlag::flag_); +} +#endif // WITH_DLP +int PermissionVerification::VerifyAccountPermission() const +{ + return MyFlag::flag_; +} +bool PermissionVerification::VerifyMissionPermission() const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::VerifyAppStateObserverPermission() const +{ + return MyFlag::flag_; +} +int32_t PermissionVerification::VerifyUpdateConfigurationPerm() const +{ + return static_cast(MyFlag::flag_); +} +bool PermissionVerification::VerifyInstallBundlePermission() const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +int PermissionVerification::CheckStartByCallPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +unsigned int PermissionVerification::GetCallingTokenID() const +{ + return static_cast(MyFlag::flag_); +} +bool PermissionVerification::JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::JudgeStartAbilityFromBackground(const bool isBackgroundCall) const +{ + return !!(MyFlag::flag_); +} +bool PermissionVerification::JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const +{ + return !!(MyFlag::flag_); +} +int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const +{ + return MyFlag::flag_; +} +bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const +{ + return true; +} +bool PermissionVerification::VerifyPrepareTerminatePermission() const +{ + return true; +} +bool PermissionVerification::IsSystemAppCall() const +{ + return true; +} + +bool PermissionVerification::VerifySetProcessCachePermission() const +{ + return true; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_record_mgr_test/ability_record_mgr_test.cpp b/test/unittest/ability_record_mgr_test/ability_record_mgr_test.cpp index a6730d6206..dff5fb363a 100644 --- a/test/unittest/ability_record_mgr_test/ability_record_mgr_test.cpp +++ b/test/unittest/ability_record_mgr_test/ability_record_mgr_test.cpp @@ -97,29 +97,6 @@ HWTEST_F(AbilityRecordMgrTest, SetToken_0100, TestSize.Level0) GTEST_LOG_(INFO) << "AbilityRecordMgrTest SetToken_0100 end"; } -/** - * @tc.number: SetEventRunner_0100 - * @tc.name: SetEventRunner - * @tc.desc: SetEventRunner Test, return is not nullptr. - */ -HWTEST_F(AbilityRecordMgrTest, SetEventRunner_0100, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "AbilityRecordMgrTest SetEventRunner_0100 start"; - auto recordMgr = std::make_shared(); - EXPECT_NE(recordMgr, nullptr); - recordMgr->SetEventRunner(nullptr); - - std::shared_ptr runner = EventRunner::GetMainEventRunner(); - EXPECT_NE(runner, nullptr); - recordMgr->tokens_ = nullptr; - recordMgr->SetEventRunner(runner); - - sptr token = new (std::nothrow) AbilityMgrToken(); - recordMgr->SetToken(token); - recordMgr->SetEventRunner(runner); - GTEST_LOG_(INFO) << "AbilityRecordMgrTest SetEventRunner_0100 end"; -} - /** * @tc.number: AddAbilityRecord_0100 * @tc.name: AddAbilityRecord @@ -136,7 +113,7 @@ HWTEST_F(AbilityRecordMgrTest, AddAbilityRecord_0100, TestSize.Level0) token = new (std::nothrow) AbilityMgrToken(); recordMgr->AddAbilityRecord(token, nullptr); - auto abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); EXPECT_NE(abilityRecord, nullptr); recordMgr->AddAbilityRecord(token, abilityRecord); @@ -158,7 +135,7 @@ HWTEST_F(AbilityRecordMgrTest, RemoveAbilityRecord_0100, TestSize.Level0) recordMgr->RemoveAbilityRecord(token); token = new (std::nothrow) AbilityMgrToken(); - auto abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); recordMgr->AddAbilityRecord(token, abilityRecord); EXPECT_EQ(recordMgr->abilityRecords_.size(), 1); @@ -179,7 +156,7 @@ HWTEST_F(AbilityRecordMgrTest, GetRecordCount_0100, TestSize.Level0) EXPECT_EQ(recordMgr->GetRecordCount(), 0); sptr token = new (std::nothrow) AbilityMgrToken(); - auto abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); recordMgr->AddAbilityRecord(token, abilityRecord); EXPECT_EQ(recordMgr->GetRecordCount(), 1); GTEST_LOG_(INFO) << "AbilityRecordMgrTest GetRecordCount_0100 end"; @@ -198,7 +175,7 @@ HWTEST_F(AbilityRecordMgrTest, GetAbilityItem_0100, TestSize.Level0) EXPECT_EQ(recordMgr->GetAbilityItem(token), nullptr); token = new (std::nothrow) AbilityMgrToken(); - auto abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); recordMgr->AddAbilityRecord(token, abilityRecord); EXPECT_NE(recordMgr->GetAbilityItem(token), nullptr); @@ -219,7 +196,7 @@ HWTEST_F(AbilityRecordMgrTest, GetAllTokens_0100, TestSize.Level0) auto recordMgr = std::make_shared(); sptr token = new (std::nothrow) AbilityMgrToken(); - auto abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); recordMgr->AddAbilityRecord(token, abilityRecord); EXPECT_EQ(recordMgr->GetAllTokens().size(), 1); diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index 9eb6f5b9d2..005a08206b 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -3338,7 +3338,7 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetUriListFromWant_001, TestSize.Level Want want; want.SetUri("file://com.example.test/test.txt"); std::vector uriVec; - abilityRecord->GetUriListFromWant(want, uriVec); + UriUtils::GetInstance().GetUriListFromWant(want, uriVec); EXPECT_EQ(uriVec.size(), 1); } @@ -3357,7 +3357,7 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetUriListFromWant_002, TestSize.Level std::vector oriUriVec = { "file://com.example.test/test.txt" }; want.SetParam(AbilityConfig::PARAMS_STREAM, oriUriVec); std::vector uriVec; - abilityRecord->GetUriListFromWant(want, uriVec); + UriUtils::GetInstance().GetUriListFromWant(want, uriVec); EXPECT_EQ(uriVec.size(), 1); } @@ -3377,7 +3377,7 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetUriListFromWant_003, TestSize.Level std::vector oriUriVec = { "file://com.example.test/test.txt" }; want.SetParam(AbilityConfig::PARAMS_STREAM, oriUriVec); std::vector uriVec; - abilityRecord->GetUriListFromWant(want, uriVec); + UriUtils::GetInstance().GetUriListFromWant(want, uriVec); EXPECT_EQ(uriVec.size(), 2); } @@ -3397,7 +3397,7 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetUriListFromWant_004, TestSize.Level std::vector oriUriVec(500, "file://com.example.test/test.txt"); want.SetParam(AbilityConfig::PARAMS_STREAM, oriUriVec); std::vector uriVec; - abilityRecord->GetUriListFromWant(want, uriVec); + UriUtils::GetInstance().GetUriListFromWant(want, uriVec); EXPECT_EQ(uriVec.size(), 500); } @@ -3416,7 +3416,7 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetUriListFromWant_005, TestSize.Level std::vector oriUriVec(501, "file://com.example.test/test.txt"); want.SetParam(AbilityConfig::PARAMS_STREAM, oriUriVec); std::vector uriVec; - abilityRecord->GetUriListFromWant(want, uriVec); + UriUtils::GetInstance().GetUriListFromWant(want, uriVec); EXPECT_EQ(uriVec.size(), 500); } diff --git a/test/unittest/ability_service_extension_test/BUILD.gn b/test/unittest/ability_service_extension_test/BUILD.gn index a554bbe461..6e1093bfbd 100644 --- a/test/unittest/ability_service_extension_test/BUILD.gn +++ b/test/unittest/ability_service_extension_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("ability_service_extension_test") { deps = [ "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:service_extension", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", diff --git a/test/unittest/ability_service_extension_test/ability_service_extension_test.cpp b/test/unittest/ability_service_extension_test/ability_service_extension_test.cpp index c91cf9661b..976756c164 100644 --- a/test/unittest/ability_service_extension_test/ability_service_extension_test.cpp +++ b/test/unittest/ability_service_extension_test/ability_service_extension_test.cpp @@ -82,7 +82,7 @@ HWTEST_F(AbilityServiceExtensionTest, CreateAndInitContext_0100, TestSize.Level1 applicationContext->AttachContextImpl(contextImpl); application->SetApplicationContext(applicationContext); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); ServiceExtension* serviceExtension = ServiceExtension::Create(nullptr); @@ -115,7 +115,7 @@ HWTEST_F(AbilityServiceExtensionTest, Init_0100, TestSize.Level1) applicationContext->AttachContextImpl(contextImpl); application->SetApplicationContext(applicationContext); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); ServiceExtension* serviceExtension = ServiceExtension::Create(nullptr); diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index 9c2120615a..3cc305c0fc 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -2986,7 +2986,7 @@ HWTEST_F(AmsAppRunningRecordTest, IsAbilitytiesBackground_001, TestSize.Level1) // 1. create AppRunningRecord and verify default status auto record = GetTestAppRunningRecord(); EXPECT_NE(record, nullptr); - EXPECT_TRUE(record->IsAbilitytiesBackground()); + EXPECT_TRUE(record->IsAbilitiesBackground()); // 2. create AbilityInfo and AppInfo, and construct ModuleRunningRecord std::shared_ptr appInfo = std::make_shared(); @@ -3011,7 +3011,7 @@ HWTEST_F(AmsAppRunningRecordTest, IsAbilitytiesBackground_001, TestSize.Level1) record->hapModules_.emplace(bundleName, moduleRecords); // 4. verify function - EXPECT_FALSE(record->IsAbilitytiesBackground()); + EXPECT_FALSE(record->IsAbilitiesBackground()); moduleRecord->abilities_.clear(); abilityRecord->state_ = AbilityState::ABILITY_STATE_BACKGROUND; @@ -3019,7 +3019,7 @@ HWTEST_F(AmsAppRunningRecordTest, IsAbilitytiesBackground_001, TestSize.Level1) moduleRecords.clear(); moduleRecords.push_back(moduleRecord); record->hapModules_.emplace(bundleName, moduleRecords); - EXPECT_TRUE(record->IsAbilitytiesBackground()); + EXPECT_TRUE(record->IsAbilitiesBackground()); GTEST_LOG_(INFO) << "IsAbilitytiesBackground_001 end."; } diff --git a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp index 2f5b73f615..d6a0e8424e 100644 --- a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp +++ b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp @@ -1692,7 +1692,7 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_ClearProcessByToke /** * @tc.name: AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_001 - * @tc.desc: Test IsMemorySizeSufficent + * @tc.desc: Test IsMemorySizeSufficient * @tc.type: FUNC */ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_001, TestSize.Level1) @@ -1713,7 +1713,7 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsMemorySizeSuffic /* * @tc.name: AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_002 - * @tc.desc: Test IsMemorySizeSufficent + * @tc.desc: Test IsMemorySizeSufficient * @tc.type: FUNC */ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_002, TestSize.Level1) @@ -1735,7 +1735,7 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsMemorySizeSuffic /* * @tc.name: AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_003 - * @tc.desc: Test IsMemorySizeSufficent + * @tc.desc: Test IsMemorySizeSufficient * @tc.type: FUNC */ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsMemorySizeSufficent_003, TestSize.Level1) diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index 4db1331bfc..9bf7ee9c4f 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -727,11 +727,11 @@ HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByToken_001, TestSize.Level0) /* * Feature: AmsMgrScheduler - * Function: IsMemorySizeSufficent + * Function: IsMemorySizeSufficient * SubFunction: NA - * FunctionPoints: AmsMgrScheduler IsMemorySizeSufficent + * FunctionPoints: AmsMgrScheduler IsMemorySizeSufficient * EnvConditions: NA - * CaseDescription: Verify IsMemorySizeSufficent + * CaseDescription: Verify IsMemorySizeSufficient */ HWTEST_F(AmsMgrSchedulerTest, IsMemorySizeSufficent_001, TestSize.Level0) { diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index f9834fd36f..2d1c4f87f3 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -1324,8 +1324,8 @@ HWTEST_F(AppMgrClientTest, GetAppRunningUniqueIdByPid_001, TestSize.Level0) HWTEST_F(AppMgrClientTest, NotifyMemorySizeStateChanged_001, TestSize.Level0) { auto appMgrClient = std::make_unique(); - bool isMemorySizeSufficent = false; - int32_t ret = appMgrClient->NotifyMemorySizeStateChanged(isMemorySizeSufficent); + bool isMemorySizeSufficient = false; + int32_t ret = appMgrClient->NotifyMemorySizeStateChanged(isMemorySizeSufficient); EXPECT_EQ(ret, 1); } diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 831a8f7d1b..245e158876 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -2045,14 +2045,14 @@ HWTEST_F(AppMgrServiceInnerTest, CheckGetRunningInfoPermission_001, TestSize.Lev */ HWTEST_F(AppMgrServiceInnerTest, IsMemorySizeSufficent_001, TestSize.Level0) { - TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent start"); + TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficient start"); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); - appMgrServiceInner->IsMemorySizeSufficent(); + appMgrServiceInner->IsMemorySizeSufficient(); appMgrServiceInner->appRunningManager_ = nullptr; - appMgrServiceInner->IsMemorySizeSufficent(); + appMgrServiceInner->IsMemorySizeSufficient(); TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent_001 end"); } @@ -3644,7 +3644,7 @@ HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityDebugResponse_001, TestSize.Leve /** * @tc.name: NotifyAbilitysDebugChange_001 - * @tc.desc: Test the status of NotifyAbilitysDebugChange. + * @tc.desc: Test the status of NotifyAbilitiesDebugChange. * @tc.type: FUNC */ HWTEST_F(AppMgrServiceInnerTest, NotifyAbilitysDebugChange_001, TestSize.Level0) @@ -3655,7 +3655,7 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAbilitysDebugChange_001, TestSize.Level0) bool isAppDebug = true; appMgrServiceInner->appRunningManager_ = std::make_shared(); appMgrServiceInner->appDebugManager_ = std::make_shared(); - auto result = appMgrServiceInner->NotifyAbilitysDebugChange(bundleName, isAppDebug); + auto result = appMgrServiceInner->NotifyAbilitiesDebugChange(bundleName, isAppDebug); EXPECT_EQ(result, ERR_NO_INIT); } diff --git a/test/unittest/app_recovery_test/ability_recovery_test.cpp b/test/unittest/app_recovery_test/ability_recovery_test.cpp index dcf0c54f53..77e12c9be7 100644 --- a/test/unittest/app_recovery_test/ability_recovery_test.cpp +++ b/test/unittest/app_recovery_test/ability_recovery_test.cpp @@ -513,6 +513,19 @@ HWTEST_F(AbilityRecoveryUnitTest, PersistAppState_002, TestSize.Level1) EXPECT_TRUE(abilityRecovery_->PersistState()); } +/** + * @tc.name: PersistAppState_003 + * @tc.desc: add testcase. + * @tc.type: FUNC + * @tc.require: I5Z7LE + */ +HWTEST_F(AbilityRecoveryUnitTest, PersistAppState_003, TestSize.Level1) +{ + abilityRecovery_->abilityInfo_ = abilityInfo_; + abilityRecovery_->missionId_ = -1; + EXPECT_FALSE(abilityRecovery_->PersistState()); +} + /** * @tc.name: IsSameAbility_001 * @tc.desc: Test IsSameAbility when not set SetJsAbility. @@ -551,5 +564,29 @@ HWTEST_F(AbilityRecoveryUnitTest, TestAppRecoveryAllocator_001, TestSize.Level1) EXPECT_EQ(allocator.Alloc(0), nullptr); EXPECT_EQ(allocator.Realloc(nullptr, 0), nullptr); } + +/** + * @tc.name: Test ReadSerializeDataFromFile + * @tc.desc: add testcase + * @tc.type: Bugfix + */ +HWTEST_F(AbilityRecoveryUnitTest, TestReadSerializeDataFromFile_001, TestSize.Level1) +{ + int32_t savedStateId = 0; + AAFwk::WantParams wantParams; + EXPECT_TRUE(!abilityRecovery_->ReadSerializeDataFromFile(savedStateId, wantParams)); +} + +/** + * @tc.name: Test LoadSavedState + * @tc.desc: add testcase + * @tc.type: Bugfix + */ +HWTEST_F(AbilityRecoveryUnitTest, TestLoadSavedState_001, TestSize.Level1) +{ + abilityRecovery_->hasLoaded_ = false; + abilityRecovery_->missionId_ = 10; + EXPECT_TRUE(!abilityRecovery_->LoadSavedState(StateReason::DEVELOPER_REQUEST)); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_recovery_test/app_recovery_test.cpp b/test/unittest/app_recovery_test/app_recovery_test.cpp index b242f2dc5a..0bc0e7f23b 100644 --- a/test/unittest/app_recovery_test/app_recovery_test.cpp +++ b/test/unittest/app_recovery_test/app_recovery_test.cpp @@ -698,5 +698,27 @@ HWTEST_F(AppRecoveryUnitTest, DeleteInValidMissionFiles_001, TestSize.Level1) AppRecovery::GetInstance().DeleteInValidMissionFiles(); EXPECT_NE(AbilityRuntime::Context::GetApplicationContext(), nullptr); } + +/** + * @tc.name: DeleteInValidMissionFileById_001 + * @tc.desc: add testcase. + */ +HWTEST_F(AppRecoveryUnitTest, DeleteInValidMissionFileById_001, TestSize.Level1) +{ + AbilityRuntime::ApplicationContext::GetInstance()->contextImpl_ = std::make_shared(); + AppRecovery::GetInstance().DeleteInValidMissionFileById("/data/local/tmp", 10); + EXPECT_NE(AbilityRuntime::Context::GetApplicationContext(), nullptr); +} + +/** + * @tc.name: ClearPageStack_001 + * @tc.desc: add testcase. + */ +HWTEST_F(AppRecoveryUnitTest, ClearPageStack_001, TestSize.Level1) +{ + AbilityRuntime::ApplicationContext::GetInstance()->contextImpl_ = std::make_shared(); + AppRecovery::GetInstance().ClearPageStack("ClearPageStack_001"); + EXPECT_NE(AbilityRuntime::Context::GetApplicationContext(), nullptr); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp b/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp index deee8b998e..c89d4ca528 100644 --- a/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp +++ b/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp @@ -127,7 +127,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_CheckAppRunningRecordIsE record->SetRestartAppFlag(true); ret = appRunningManager->CheckAppRunningRecordIsExistByUid(USR_ID_100); EXPECT_FALSE(ret); - + /** * @tc.steps: step4. call CheckAppRunningRecordIsExistByUid USR_ID_101 * @tc.expected: step4. expect call CheckAppRunningRecordIsExistByUid false @@ -294,17 +294,17 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_ProcessExitByBundleName_ record1->SetKeepAliveEnableState(true); record1->SetMainProcess(true); record1->GetPriorityObject()->SetPid(10000); // 10000 means valid process id - ExitResidentProcessManager::GetInstance().HandleMemorySizeInSufficent(); // marked mem insufficent + ExitResidentProcessManager::GetInstance().HandleMemorySizeInSufficent(); // marked mem insufficient std::list pids; appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, false); EXPECT_TRUE(pids.empty()); /** * @tc.steps: step2. process resident process and ExitResidentProcessManager Memory Size Insufficent - * @tc.expected: step2. expect pids not empty, memory size sufficent + * @tc.expected: step2. expect pids not empty, memory size sufficient */ pids.clear(); - ExitResidentProcessManager::GetInstance().HandleMemorySizeSufficient(processInfos); // marked mem sufficent + ExitResidentProcessManager::GetInstance().HandleMemorySizeSufficient(processInfos); // marked mem sufficient appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, true); EXPECT_TRUE(pids.empty()); } diff --git a/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp b/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp index 7ef501f016..7ffd2c76ae 100644 --- a/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp +++ b/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp @@ -14,7 +14,7 @@ */ #include - +#include "hilog_tag_wrapper.h" #define private public #include "app_spawn_client.h" #undef private @@ -70,5 +70,881 @@ HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcessImpl_002, TestSize.Level0) int ret = asc->PreStartNWebSpawnProcess(); EXPECT_EQ(ret, ERR_OK); } + +/** + * @tc.name: AppSpawnClient_001 + * @tc.desc: new AppSpawnClient object + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppSpawnClient_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_001 start"); + const char* serviceName = "appspawn"; + auto asc = std::make_shared(serviceName); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_001 end"); +} + +/** + * @tc.name: AppSpawnClient_002 + * @tc.desc: new AppSpawnClient object + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppSpawnClient_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_002 start"); + const char* serviceName = "cjappspawn"; + auto asc = std::make_shared(serviceName); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_002 end"); +} + +/** + * @tc.name: AppSpawnClient_003 + * @tc.desc: new AppSpawnClient object + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppSpawnClient_003, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_003 start"); + const char* serviceName = "nwebRestart"; + auto asc = std::make_shared(serviceName); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_003 end"); +} + +/** + * @tc.name: AppSpawnClient_004 + * @tc.desc: new AppSpawnClient object + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppSpawnClient_004, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_004 start"); + const char* serviceName = "nativespawn"; + auto asc = std::make_shared(serviceName); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_004 end"); +} + +/** + * @tc.name: AppSpawnClient_005 + * @tc.desc: new AppSpawnClient object + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppSpawnClient_005, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_005 start"); + const char* serviceName = "nwebspawn"; + auto asc = std::make_shared(serviceName); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_005 end"); +} + +/** + * @tc.name: OpenConnection_001 + * @tc.desc: appspawn OpenConnection + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, OpenConnection_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start"); + auto asc = std::make_shared(true); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end"); +} + +/** + * @tc.name: OpenConnection_002 + * @tc.desc: appspawn OpenConnection + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, OpenConnection_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start"); + auto asc = std::make_shared(false); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end"); +} + +/** + * @tc.name: CloseConnection_001 + * @tc.desc: appspawn CloseConnection + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, CloseConnection_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start"); + auto asc = std::make_shared(true); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end"); +} + +/** + * @tc.name: CloseConnection_002 + * @tc.desc: appspawn CloseConnection + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, CloseConnection_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start"); + auto asc = std::make_shared(false); + auto ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end"); +} + +/** + * @tc.name: SetDacInfo_001 + * @tc.desc: appspawn SetDacInfo + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetDacInfo_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetDacInfo_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetDacInfo(startMsg, reqHandle); + EXPECT_EQ(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "SetDacInfo_001 end"); +} + +/** + * @tc.name: SetMountPermission_001 + * @tc.desc: appspawn SetMountPermission + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetMountPermission_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetMountPermission_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetMountPermission(startMsg, reqHandle); + EXPECT_NE(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "SetMountPermission_001 end"); +} + +/** + * @tc.name: SetStartFlags_001 + * @tc.desc: appspawn SetStartFlags + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetStartFlags_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetStartFlags_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetStartFlags(startMsg, reqHandle); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetStartFlags_001 end"); +} + + +/** + * @tc.name: AppspawnSetExtMsgMore_001 + * @tc.desc: appspawn AppspawnSetExtMsgMore + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppspawnSetExtMsgMore_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppspawnSetExtMsgMore_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->AppspawnSetExtMsgMore(startMsg, reqHandle); + EXPECT_EQ(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AppspawnSetExtMsgMore_001 end"); +} + + +/** + * @tc.name: AppspawnCreateDefaultMsg_001 + * @tc.desc: appspawn AppspawnCreateDefaultMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, AppspawnCreateDefaultMsg_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppspawnCreateDefaultMsg_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string apl("test_apl"); + startMsg.apl = apl; + std::string ownerId("test_owner_id"); + startMsg.ownerId = ownerId; + std::string bundleName("test_bundle_name"); + startMsg.bundleName = bundleName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->AppspawnCreateDefaultMsg(startMsg, reqHandle); + EXPECT_NE(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AppspawnCreateDefaultMsg_001 end"); +} + + +/** + * @tc.name: VerifyMsg_001 + * @tc.desc: appspawn VerifyMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, VerifyMsg_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + bool result = false; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + + result = asc->VerifyMsg(startMsg); + EXPECT_EQ(result, true); + + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_001 end"); +} + +/** + * @tc.name: VerifyMsg_002 + * @tc.desc: appspawn VerifyMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, VerifyMsg_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_002 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = -1; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + bool result = false; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + + result = asc->VerifyMsg(startMsg); + EXPECT_EQ(result, false); + + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_002 end"); +} + +/** + * @tc.name: VerifyMsg_003 + * @tc.desc: appspawn VerifyMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, VerifyMsg_003, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_003 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = -1; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + bool result = false; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + + result = asc->VerifyMsg(startMsg); + EXPECT_EQ(result, false); + + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_003 end"); +} + +/** + * @tc.name: VerifyMsg_004 + * @tc.desc: appspawn VerifyMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, VerifyMsg_004, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_004 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003, -1}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + bool result = false; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + result = asc->VerifyMsg(startMsg); + EXPECT_EQ(result, false); + + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_004 end"); +} + +/** + * @tc.name: VerifyMsg_005 + * @tc.desc: appspawn VerifyMsg + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, VerifyMsg_005, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_005 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002}; + std::string procName(""); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + auto asc = std::make_shared(false); + int32_t ret = 0; + bool result = false; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + result = asc->VerifyMsg(startMsg); + EXPECT_EQ(result, false); + + TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_005 end"); +} + +/** + * @tc.name: SetChildProcessTypeStartFlag_001 + * @tc.desc: appspawn SetChildProcessTypeStartFlag + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetChildProcessTypeStartFlag_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_001 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + int32_t childProcessType = 1; + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetChildProcessTypeStartFlag(reqHandle, childProcessType); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_001 end"); +} + +/** + * @tc.name: SetChildProcessTypeStartFlag_002 + * @tc.desc: appspawn SetChildProcessTypeStartFlag + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetChildProcessTypeStartFlag_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_002 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + int32_t childProcessType = -1; + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetChildProcessTypeStartFlag(reqHandle, childProcessType); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_002 end"); +} + +/** + * @tc.name: SetExtMsgFds_001 + * @tc.desc: appspawn SetExtMsgFds + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetExtMsgFds_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_001 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + startMsg.fds.emplace("test_fd1", 100); + startMsg.fds.emplace("test_fd2", 101); + startMsg.fds.emplace("test_fd3", 102); + + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetExtMsgFds(reqHandle, startMsg.fds); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_001 end"); +} + +/** + * @tc.name: SetExtMsgFds_002 + * @tc.desc: appspawn SetExtMsgFds + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetExtMsgFds_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_002 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + startMsg.fds.emplace("test_fd1", 100); + startMsg.fds.emplace("test_fd2", 101); + startMsg.fds.emplace("test_fd3", -1); + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetExtMsgFds(reqHandle, startMsg.fds); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_002 end"); +} + +/** + * @tc.name: SetIsolationModeFlag_001 + * @tc.desc: appspawn SetIsolationModeFlag + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetIsolationModeFlag_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_001 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + startMsg.isolationMode = true; + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetIsolationModeFlag(startMsg, reqHandle); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_001 end"); +} + +/** + * @tc.name: SetIsolationModeFlag_002 + * @tc.desc: appspawn SetIsolationModeFlag + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, SetIsolationModeFlag_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_002 start"); + AppSpawnStartMsg startMsg = {0}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + startMsg.isolationMode = false; + auto asc = std::make_shared(false); + int32_t ret = 0; + AppSpawnReqMsgHandle reqHandle = nullptr; + ret = asc->OpenConnection(); + EXPECT_EQ(ret, ERR_OK); + ret = AppSpawnReqMsgCreate(static_cast(startMsg.code), startMsg.procName.c_str(), &reqHandle); + EXPECT_EQ(ret, ERR_OK); + ret = asc->SetIsolationModeFlag(startMsg, reqHandle); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_002 end"); +} + + +/** + * @tc.name: StartProcess_001 + * @tc.desc: appspawn StartProcess + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, StartProcess_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + int32_t ret = 0; + auto asc = std::make_shared(false); + pid_t pid = 0; + ret = asc->StartProcess(startMsg, pid); + EXPECT_NE(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 end"); +} + +/** + * @tc.name: StartProcess_002 + * @tc.desc: appspawn StartProcess + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppSpawnClientTest, StartProcess_002, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "StartProcess_002 start"); + AppSpawnStartMsg startMsg = {0}; + startMsg.uid = 1001; + startMsg.gid = 2001; + startMsg.gids = {1001, 1002, 1003, -1}; + std::string procName("test_proc_name"); + startMsg.procName = procName; + std::string permission1("permission_for_test_1"); + std::string permission2("permission_for_test_2"); + std::string permission3("permission_for_test_3"); + startMsg.permissions.insert(permission1); + startMsg.permissions.insert(permission2); + startMsg.permissions.insert(permission3); + startMsg.flags = 0x1000; + startMsg.atomicServiceFlag = false; + startMsg.strictMode = false; + startMsg.isolatedExtension = false; + startMsg.childProcessType = 1; + startMsg.isolationMode = false; + std::string provisionType("test_provisionType"); + startMsg.provisionType = provisionType; + std::string processType("test_processType"); + startMsg.processType = processType; + startMsg.maxChildProcess = 1; + std::string extensionSandboxPath("test_extensionSandboxPath"); + startMsg.extensionSandboxPath = extensionSandboxPath; + + int32_t ret = 0; + auto asc = std::make_shared(false); + pid_t pid = 0; + ret = asc->StartProcess(startMsg, pid); + EXPECT_NE(ret, ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "StartProcess_002 end"); +} + + } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index 0fe86c7ca0..0d1cd5b548 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -666,7 +666,7 @@ HWTEST_F(MainThreadTest, CheckAbilityItem_0100, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); EXPECT_FALSE(mainThread_->CheckAbilityItem(record)); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } @@ -680,7 +680,7 @@ HWTEST_F(MainThreadTest, CheckAbilityItem_0100, TestSize.Level1) HWTEST_F(MainThreadTest, CheckAbilityItem_0200, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); - std::shared_ptr record = std::make_shared(nullptr, nullptr); + auto record = std::make_shared(nullptr, nullptr, nullptr, 0); EXPECT_FALSE(mainThread_->CheckAbilityItem(record)); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } @@ -991,7 +991,7 @@ HWTEST_F(MainThreadTest, PrepareAbilityDelegator_0400, TestSize.Level1) HWTEST_F(MainThreadTest, HandleLaunchAbility_0100, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); - std::shared_ptr abilityRecord = std::make_shared(nullptr, nullptr); + auto abilityRecord = std::make_shared(nullptr, nullptr, nullptr, 0); ASSERT_NE(abilityRecord, nullptr); mainThread_->HandleLaunchAbility(abilityRecord); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); @@ -1532,10 +1532,10 @@ HWTEST_F(MainThreadTest, LoadNativeLiabrary_0100, TestSize.Level1) std::string nativeLibraryPath = ""; ASSERT_NE(mainThread_, nullptr); BundleInfo bundleInfo; - mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath); + mainThread_->LoadNativeLibrary(bundleInfo, nativeLibraryPath); nativeLibraryPath = "test/"; - mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath); + mainThread_->LoadNativeLibrary(bundleInfo, nativeLibraryPath); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } #endif @@ -1903,11 +1903,11 @@ HWTEST_F(MainThreadTest, HandleLaunchAbility_0200, TestSize.Level1) const std::shared_ptr info1 = nullptr; const sptr token = nullptr; - const std::shared_ptr abilityRecord2 = std::make_shared(info1, token); + const auto abilityRecord2 = std::make_shared(info1, token, nullptr, 0); mainThread_->HandleLaunchAbility(abilityRecord2); const std::shared_ptr info2 = std::make_shared(); - const std::shared_ptr abilityRecord3 = std::make_shared(info2, token); + const auto abilityRecord3 = std::make_shared(info2, token, nullptr, 0); mainThread_->application_ = std::make_shared(); mainThread_->HandleLaunchAbility(abilityRecord3); @@ -1954,7 +1954,7 @@ HWTEST_F(MainThreadTest, HandleCleanAbility_0100, TestSize.Level1) mainThread_->HandleCleanAbility(token); std::shared_ptr info = nullptr; - abilityRecord = std::make_shared(info, token); + abilityRecord = std::make_shared(info, token, nullptr, 0); mainThread_->abilityRecordMgr_->AddAbilityRecord(token, abilityRecord); mainThread_->HandleCleanAbility(token); diff --git a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp index 4d1fb6bca2..57f07e54d8 100644 --- a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp +++ b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp @@ -129,7 +129,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_DumpApplication_010 ohosApplication_->abilityRecordMgr_ = std::make_shared(); sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = nullptr; - std::shared_ptr record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); ohosApplication_->abilityRecordMgr_->abilityRecords_.emplace(token, record); ohosApplication_->DumpApplication(); EXPECT_TRUE(record != nullptr); @@ -147,7 +147,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_DumpApplication_020 ohosApplication_->abilityRecordMgr_ = std::make_shared(); sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = std::make_shared(); - std::shared_ptr record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); info->permissions.push_back(std::string("abc")); ohosApplication_->abilityRecordMgr_->abilityRecords_.emplace(token, record); ohosApplication_->DumpApplication(); @@ -291,7 +291,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnConfigurationUpda ohosApplication_->configuration_ = std::make_shared(); sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = nullptr; - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); ohosApplication_->abilityRecordMgr_->abilityRecords_.emplace(token, abilityRecord); sptr abilityThread = new (std::nothrow) AbilityRuntime::FAAbilityThread(); abilityRecord->SetAbilityThread(abilityThread); @@ -371,7 +371,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnMemoryLevel_0100, ohosApplication_->abilityRecordMgr_ = std::make_shared(); std::shared_ptr info = nullptr; sptr token = new (std::nothrow) Notification::MockIRemoteObject(); - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); EXPECT_TRUE(abilityRecord != nullptr); ohosApplication_->abilityRecordMgr_->abilityRecords_.emplace(token, abilityRecord); sptr abilityThread = new (std::nothrow) AbilityRuntime::FAAbilityThread(); @@ -450,7 +450,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_030 GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddAbilityStage_0300 start."; sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = nullptr; - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); EXPECT_TRUE(ohosApplication_->abilityStages_.empty()); auto callback = [](const std::shared_ptr &) {}; bool isAsyncCallback = false; @@ -469,7 +469,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_040 std::shared_ptr info = std::make_shared(); info->applicationInfo.multiProjects = true; sptr token = new (std::nothrow) Notification::MockIRemoteObject(); - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); auto want = std::make_shared(); abilityRecord->SetWant(want); auto callback = [](const std::shared_ptr &) {}; @@ -490,7 +490,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_050 sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = nullptr; std::string moduleName = "entry"; - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); EXPECT_TRUE(ohosApplication_->abilityStages_.empty()); std::shared_ptr abilityStages = std::make_shared(); ohosApplication_->abilityStages_.emplace(moduleName, abilityStages); @@ -513,7 +513,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_060 sptr token; std::shared_ptr info = std::make_shared(); info->moduleName = "entry"; - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); auto callback = [](const std::shared_ptr &) {}; bool isAsyncCallback = false; ohosApplication_->AddAbilityStage(abilityRecord, callback, isAsyncCallback); @@ -532,7 +532,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_070 GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddAbilityStage_0700 start."; sptr token = new (std::nothrow) Notification::MockIRemoteObject(); std::shared_ptr info = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(info, token); + auto abilityRecord = std::make_shared(info, token, nullptr, 0); abilityRecord->token_ = new (std::nothrow) Notification::MockIRemoteObject(); auto callback = [](const std::shared_ptr &) {}; bool isAsyncCallback = false; diff --git a/test/unittest/cj_ability_stage_object_test/BUILD.gn b/test/unittest/cj_ability_stage_object_test/BUILD.gn index d2b3754015..3bb281c9bf 100644 --- a/test/unittest/cj_ability_stage_object_test/BUILD.gn +++ b/test/unittest/cj_ability_stage_object_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("cj_ability_stage_object_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", diff --git a/test/unittest/cj_ability_stage_test/BUILD.gn b/test/unittest/cj_ability_stage_test/BUILD.gn index b659e389ba..314575185e 100644 --- a/test/unittest/cj_ability_stage_test/BUILD.gn +++ b/test/unittest/cj_ability_stage_test/BUILD.gn @@ -55,6 +55,7 @@ ohos_unittest("cj_ability_stage_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", diff --git a/test/unittest/cj_ui_ability_test/BUILD.gn b/test/unittest/cj_ui_ability_test/BUILD.gn index 2d57d7621a..3707769671 100644 --- a/test/unittest/cj_ui_ability_test/BUILD.gn +++ b/test/unittest/cj_ui_ability_test/BUILD.gn @@ -57,6 +57,7 @@ ohos_unittest("cj_ui_ability_test") { "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:insight_intent_executor", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", diff --git a/test/unittest/cj_ui_ability_test/cj_ui_ability_test.cpp b/test/unittest/cj_ui_ability_test/cj_ui_ability_test.cpp index 8b74d21752..7d6f13be39 100644 --- a/test/unittest/cj_ui_ability_test/cj_ui_ability_test.cpp +++ b/test/unittest/cj_ui_ability_test/cj_ui_ability_test.cpp @@ -139,11 +139,11 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_Init_0100, Function | MediumTest | Level1) sptr token = nullptr; cjAbility_->Init(nullptr, application, handler, token); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); abilityInfo->isModuleJson = true; - abilityLocalRecord = std::make_shared(abilityInfo, token); + abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -186,7 +186,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnNewWant_0100, Function | MediumTest | Leve std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); Want want; @@ -205,7 +205,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnStart_0100, Function | MediumTest | Level1 std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); Want want; @@ -246,7 +246,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnStop_0100, Function | MediumTest | Level1) std::shared_ptr handler = nullptr; std::shared_ptr application = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); cjAbility_->OnStop(); AbilityLifecycleExecutor::LifecycleState state = cjAbility_->GetState(); @@ -273,7 +273,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnBackground_0300, Function | MediumTest | L std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); cjAbility_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = cjAbility_->GetState(); @@ -342,7 +342,7 @@ HWTEST_F(CjUIAbilityTest, CJUIAbility_OnStop_AsyncCallback_0100, TestSize.Level1 std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); bool isAsyncCallback = false; cjAbility_->OnStop(nullptr, isAsyncCallback); @@ -407,7 +407,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnForeground_0100, Function | MediumTest | L std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); Want want; cjAbility_->OnForeground(want); @@ -452,7 +452,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnForeground_0300, Function | MediumTest | L std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); Want want; cjAbility_->OnForeground(want); @@ -479,8 +479,7 @@ HWTEST_F(CjUIAbilityTest, CJUIAbilityVirtualFunc_0100, TestSize.Level1) pageAbilityInfo->isStageBasedModel = true; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - std::shared_ptr abilityLocalRecord = - std::make_shared(pageAbilityInfo, nullptr); + auto abilityLocalRecord = std::make_shared(pageAbilityInfo, nullptr, nullptr, 0); cjAbility_->Init(abilityLocalRecord, nullptr, handler, nullptr); cjAbility_->UpdateContextConfiguration(); EXPECT_NE(abilityLocalRecord, nullptr); @@ -531,8 +530,7 @@ HWTEST_F(CjUIAbilityTest, CJUIAbilityRequestFocus_0100, TestSize.Level1) pageAbilityInfo->isStageBasedModel = true; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - std::shared_ptr abilityLocalRecord = - std::make_shared(pageAbilityInfo, nullptr); + auto abilityLocalRecord = std::make_shared(pageAbilityInfo, nullptr, nullptr, 0); cjAbility_->Init(abilityLocalRecord, nullptr, handler, nullptr); EXPECT_NE(abilityLocalRecord, nullptr); @@ -559,7 +557,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnBackground_0100, Function | MediumTest | L std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); cjAbility_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = cjAbility_->GetState(); @@ -583,7 +581,7 @@ HWTEST_F(CjUIAbilityTest, CJRuntime_OnBackground_0200, Function | MediumTest | L std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); cjAbility_->Init(abilityLocalRecord, application, handler, token); cjAbility_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = cjAbility_->GetState(); @@ -627,7 +625,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0100, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -650,7 +648,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0200, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); Want want; @@ -679,7 +677,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0300, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -706,7 +704,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0400, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -744,7 +742,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0500, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -784,7 +782,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0600, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); EXPECT_NE(abilityLocalRecord, nullptr); @@ -819,7 +817,7 @@ HWTEST_F(CjUIAbilityTest, InitedCJUIAbilityTest_0700, TestSize.Level1) sptr token = nullptr; abilityInfo->isModuleJson = false; PreSetCJAbilityStageFuncs(); - std::shared_ptr abilityLocalRecord = std::make_shared(abilityInfo, token); + auto abilityLocalRecord = std::make_shared(abilityInfo, token, nullptr, 0); initedCJUIAbility_->Init(abilityLocalRecord, application, handler, token); Want want; diff --git a/test/unittest/configuration_test/configuration_test.cpp b/test/unittest/configuration_test/configuration_test.cpp index 2950ce8d26..1d67f63d5e 100644 --- a/test/unittest/configuration_test/configuration_test.cpp +++ b/test/unittest/configuration_test/configuration_test.cpp @@ -583,6 +583,49 @@ HWTEST_F(ConfigurationTest, InitDisplayConfig_0100, TestSize.Level1) EXPECT_EQ(ConvertDirection(originDirection), resConfig->GetDirection()); } +/** + * @tc.name: InitDisplayConfig_0200 + * @tc.desc: Init display config. + * @tc.type: FUNC + */ +HWTEST_F(ConfigurationTest, InitDisplayConfig_0200, TestSize.Level1) +{ + auto configUtils = std::make_shared(); + ASSERT_NE(configUtils, nullptr); + + int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; + float originDensity; + std::string originDirection; + auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); + EXPECT_EQ(ret, true); + + configUtils->InitDisplayConfig(nullptr, nullptr, displayId, originDensity, 0); + + AppExecFwk::Configuration originConfig; + auto configuration = std::make_shared(originConfig); + ASSERT_NE(configuration, nullptr); + configUtils->InitDisplayConfig(configuration, nullptr, displayId, originDensity, 0); + + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + ASSERT_NE(resourceManager, nullptr); + InitResourceManager(resourceManager); + configUtils->InitDisplayConfig(configuration, resourceManager, displayId, originDensity, 0); + + // check configurtion + std::string displayIdStr = configuration->GetItem(ConfigurationInner::APPLICATION_DISPLAYID); + EXPECT_EQ(displayIdStr, std::to_string(displayId)); + std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); + EXPECT_EQ(densityStr, GetDensityStr(originDensity)); + std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); + EXPECT_EQ(directionStr, ConfigurationInner::DIRECTION_VERTICAL); + + // check resourcemanager + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + resourceManager->GetResConfig(*resConfig); + EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); + EXPECT_EQ(ConvertDirection(ConfigurationInner::DIRECTION_VERTICAL), resConfig->GetDirection()); +} + /** * @tc.name: UpdateDisplayConfig_0100 * @tc.desc: Update display config with changed config. @@ -662,5 +705,86 @@ HWTEST_F(ConfigurationTest, UpdateDisplayConfig_0200, TestSize.Level1) configUtils->UpdateDisplayConfig(displayId, configuration, resourceManager, configChanged); EXPECT_EQ(configChanged, false); } + +/** + * @tc.name: UpdateDisplayConfig_0300 + * @tc.desc: Update display config with changed config. + * @tc.type: FUNC + */ +HWTEST_F(ConfigurationTest, UpdateDisplayConfig_0300, TestSize.Level1) +{ + auto configUtils = std::make_shared(); + ASSERT_NE(configUtils, nullptr); + + int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; + float originDensity; + std::string originDirection; + auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); + EXPECT_EQ(ret, true); + + bool configChanged = false; + configChanged = configUtils->UpdateDisplayConfig( + nullptr, nullptr, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); + EXPECT_EQ(configChanged, false); + + AppExecFwk::Configuration originConfig; + auto configuration = std::make_shared(originConfig); + ASSERT_NE(configuration, nullptr); + configChanged = configUtils->UpdateDisplayConfig( + configuration, nullptr, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); + EXPECT_EQ(configChanged, false); + + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + ASSERT_NE(resourceManager, nullptr); + InitResourceManager(resourceManager); + configChanged = configUtils->UpdateDisplayConfig( + configuration, resourceManager, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); + EXPECT_EQ(configChanged, true); + + // check configurtion + std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); + EXPECT_EQ(densityStr, GetDensityStr(originDensity)); + std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); + EXPECT_EQ(directionStr, ConfigurationInner::DIRECTION_VERTICAL); + + // check resourcemanager + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + resourceManager->GetResConfig(*resConfig); + EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); + EXPECT_EQ(ConvertDirection(ConfigurationInner::DIRECTION_VERTICAL), resConfig->GetDirection()); +} + +/** + * @tc.name: UpdateDisplayConfig_0400 + * @tc.desc: Update display config with unchanged config. + * @tc.type: FUNC + */ +HWTEST_F(ConfigurationTest, UpdateDisplayConfig_0400, TestSize.Level1) +{ + auto configUtils = std::make_shared(); + ASSERT_NE(configUtils, nullptr); + + int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; + float originDensity; + std::string originDirection; + auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); + EXPECT_EQ(ret, true); + + AppExecFwk::Configuration originConfig; + auto configuration = std::make_shared(originConfig); + ASSERT_NE(configuration, nullptr); + + // Add configuration. + configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(originDensity)); + configuration->AddItem( + displayId, ConfigurationInner::APPLICATION_DIRECTION, ConfigurationInner::DIRECTION_VERTICAL); + configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId)); + + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + ASSERT_NE(resourceManager, nullptr); + bool configChanged = configUtils->UpdateDisplayConfig( + configuration, resourceManager, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); + EXPECT_EQ(configChanged, false); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn index d4818c5bbd..0a334c59b4 100644 --- a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/appfreeze_inner_test" +module_output_path = "ability_runtime/dfr_test" ############################################################################### config("module_context_config") { diff --git a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn index ca35c2db20..c8c755ed45 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/appfreeze_inner_test" +module_output_path = "ability_runtime/dfr_test" ############################################################################### config("module_context_config") { diff --git a/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp b/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp index ae70eebc19..03f045f72a 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp +++ b/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp @@ -98,6 +98,9 @@ HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_002, TestSize.Level1) EXPECT_EQ(ret, 0); ret = appfreezeManager->AcquireStack(faultData, appInfo, "test"); EXPECT_EQ(ret, 0); + faultData.errorObject.name = AppFreezeType::LIFECYCLE_HALF_TIMEOUT; + ret = appfreezeManager->AppfreezeHandleWithStack(faultData, appInfo); + EXPECT_EQ(ret, 0); } /** @@ -200,5 +203,71 @@ HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_006, TestSize.Level1) result = appfreezeManager->IsNeedIgnoreFreezeEvent(pid); EXPECT_TRUE(result); } + +/** + * @tc.number: AppfreezeManagerTest_007 + * @tc.desc: add testcase codecoverage + * @tc.type: FUNC + */ +HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_007, TestSize.Level1) +{ + int32_t pid = static_cast(getprocpid()); + int state = AppfreezeManager::AppFreezeState::APPFREEZE_STATE_IDLE; + EXPECT_EQ(appfreezeManager->GetFreezeState(pid), state); + appfreezeManager->SetFreezeState(pid, + AppfreezeManager::AppFreezeState::APPFREEZE_STATE_FREEZE); + appfreezeManager->SetFreezeState(pid, state); + EXPECT_EQ(appfreezeManager->GetFreezeState(pid), state); +} + +/** + * @tc.number: AppfreezeManagerTest_AppFreezeFilter_001 + * @tc.desc: add testcase codecoverage + * @tc.type: FUNC + */ +HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_AppFreezeFilter_001, TestSize.Level1) +{ + int32_t pid = static_cast(getprocpid()); + EXPECT_TRUE(!appfreezeManager->CancelAppFreezeDetect(pid, "")); + appfreezeManager->ResetAppfreezeState(pid, ""); + EXPECT_TRUE(appfreezeManager->IsValidFreezeFilter(pid, "")); + appfreezeManager->RemoveDeathProcess(""); +} + +/** + * @tc.number: AppfreezeManagerTest_AppFreezeFilter_002 + * @tc.desc: add testcase codecoverage + * @tc.type: FUNC + */ +HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_AppFreezeFilter_002, TestSize.Level1) +{ + int32_t pid = static_cast(getprocpid()); + std::string bundleName = "AppfreezeManagerTest_AppFreezeFilter_002"; + EXPECT_TRUE(appfreezeManager->CancelAppFreezeDetect(pid, bundleName)); + EXPECT_TRUE(appfreezeManager->IsProcessDebug(pid, bundleName)); + appfreezeManager->ResetAppfreezeState(pid, bundleName); + EXPECT_TRUE(!appfreezeManager->IsProcessDebug(pid, bundleName)); + EXPECT_TRUE(!appfreezeManager->IsValidFreezeFilter(pid, bundleName)); + appfreezeManager->RemoveDeathProcess(bundleName); +} + +/** + * @tc.number: AppfreezeManagerTest_CatchStack_001 + * @tc.desc: add testcase codecoverage + * @tc.type: FUNC + */ +HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_CatchStack_001, TestSize.Level1) +{ + int32_t pid = static_cast(getprocpid()); + std::string ret = ""; + appfreezeManager->FindStackByPid(ret, pid); + EXPECT_TRUE(ret.empty()); + appfreezeManager->catchStackMap_[pid] = "AppfreezeManagerTest_CatchStack_001"; + appfreezeManager->FindStackByPid(ret, pid); + EXPECT_TRUE(!ret.empty()); + EXPECT_TRUE(!appfreezeManager->catchStackMap_.empty()); + appfreezeManager->DeleteStack(pid); + EXPECT_TRUE(appfreezeManager->catchStackMap_.empty()); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn index 422a69dcb9..b28a2ed51d 100644 --- a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/appfreeze_state_test" +module_output_path = "ability_runtime/dfr_test" ############################################################################### config("module_context_config") { diff --git a/test/unittest/dfr_test/watchdog_test/BUILD.gn b/test/unittest/dfr_test/watchdog_test/BUILD.gn index 9f6238bdb1..8faac0b8ba 100644 --- a/test/unittest/dfr_test/watchdog_test/BUILD.gn +++ b/test/unittest/dfr_test/watchdog_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/watchdog_test" +module_output_path = "ability_runtime/dfr_test" ############################################################################### config("module_context_config") { diff --git a/test/unittest/dfr_test/watchdog_test/watchdog_test.cpp b/test/unittest/dfr_test/watchdog_test/watchdog_test.cpp index be58e12cee..c98f9c3be0 100644 --- a/test/unittest/dfr_test/watchdog_test/watchdog_test.cpp +++ b/test/unittest/dfr_test/watchdog_test/watchdog_test.cpp @@ -132,6 +132,39 @@ HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0002, Function | MediumTe EXPECT_TRUE(1); } +/** + * @tc.number: AppExecFwk_watchdog_ReportEvent_0003 + * @tc.name: ReportEvent + * @tc.desc: Test ReportEvent. + * @tc.require: I5UL6H + */ +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0003, Function | MediumTest | Level3) +{ + watchdog_->isBgWorkingThread_.store(true); + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->needReport_); +} + +/** + * @tc.number: AppExecFwk_watchdog_ReportEvent_0004 + * @tc.name: ReportEvent + * @tc.desc: Test ReportEvent. + * @tc.require: I5UL6H + */ +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0004, Function | MediumTest | Level3) +{ + watchdog_->isBgWorkingThread_.store(false); + watchdog_->lastWatchTime_ = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME; + watchdog_->needReport_ = true; + watchdog_->isSixSecondEvent_.store(true); + watchdog_->isInBackground_.store(false); + watchdog_->ReportEvent(); + watchdog_->needReport_ = false; + watchdog_->ReportEvent(); + EXPECT_TRUE(!watchdog_->needReport_); +} + /** * @tc.number: WatchdogTest_Init_001 * @tc.name: Init diff --git a/test/unittest/dialog_session_manager_test/BUILD.gn b/test/unittest/dialog_session_manager_test/BUILD.gn new file mode 100644 index 0000000000..cc4fe5593a --- /dev/null +++ b/test/unittest/dialog_session_manager_test/BUILD.gn @@ -0,0 +1,74 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("dialog_session_manager_test") { + module_out_path = module_output_path + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } + + include_dirs = [ + "${ability_runtime_path}/services/abilitymgr/include/dialog_session", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", + ] + + sources = [ + "${ability_runtime_path}/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp", + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_info.cpp", + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_path}/services/abilitymgr/src/start_ability_utils.cpp", + "dialog_session_manager_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + cflags = [] + + deps = [ + "${ability_base_path}:base", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/googletest:gmock_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "jsoncpp:jsoncpp", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":dialog_session_manager_test" ] +} diff --git a/test/unittest/dialog_session_manager_test/dialog_session_manager_test.cpp b/test/unittest/dialog_session_manager_test/dialog_session_manager_test.cpp new file mode 100644 index 0000000000..2dec4d9e38 --- /dev/null +++ b/test/unittest/dialog_session_manager_test/dialog_session_manager_test.cpp @@ -0,0 +1,275 @@ +/* + * 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 "gtest/gtest.h" + +#define private public +#include "dialog_session_manager.h" +#undef private +#include "hilog_tag_wrapper.h" +#include "mock_ability_token.h" +#include "start_ability_utils.h" + +using OHOS::AppExecFwk::AbilityType; +using namespace testing::ext; + +namespace OHOS { +namespace AAFwk { +namespace { +constexpr int32_t TEST_USER_ID = 10001; +constexpr int32_t TEST_ERMS_ISALLOW_RESULTCODE = 9; +const std::string TEST_BUNDLE_NAME = "com.test.demo"; +const std::string TEST_DIALOG_SESSION_ID = "dialogSessionId"; +} + +class DialogSessionManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + std::shared_ptr MockAbilityRecord(AbilityType); + sptr MockToken(AbilityType); +}; + +void DialogSessionManagerTest::SetUpTestCase(void) +{} + +void DialogSessionManagerTest::TearDownTestCase(void) +{} + +void DialogSessionManagerTest::SetUp() +{} + +void DialogSessionManagerTest::TearDown() +{} + +std::shared_ptr DialogSessionManagerTest::MockAbilityRecord(AbilityType abilityType) +{ + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = TEST_BUNDLE_NAME; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = abilityType; + return AbilityRecord::CreateAbilityRecord(abilityRequest); +} + +sptr DialogSessionManagerTest::MockToken(AbilityType abilityType) +{ + std::shared_ptr abilityRecord = MockAbilityRecord(abilityType); + if (!abilityRecord) { + return nullptr; + } + return abilityRecord->GetToken(); +} + +/** + * @tc.name: GetStartupSessionInfoTest_0100 + * @tc.desc: Test GetStartupSessionInfo + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, GetStartupSessionInfoTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetStartupSessionInfoTest_0100 start"; + DialogSessionManager dialogSessionManager; + std::shared_ptr ret = dialogSessionManager.GetStartupSessionInfo(TEST_DIALOG_SESSION_ID); + EXPECT_EQ(ret, nullptr); + + AbilityRequest abilityRequest; + dialogSessionManager.SetStartupSessionInfo(TEST_DIALOG_SESSION_ID, abilityRequest); + ret = dialogSessionManager.GetStartupSessionInfo(TEST_DIALOG_SESSION_ID); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetStartupSessionInfoTest_0100 end"; +} + +/** + * @tc.name: SendDialogResultTest_0100 + * @tc.desc: Test SendDialogResult + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, SendDialogResultTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SendDialogResultTest_0100 start"; + AbilityRequest abilityRequest; + DialogSessionManager dialogSessionManager; + Want want; + bool isAllowed = false; + int32_t ret = dialogSessionManager.SendDialogResult(want, TEST_DIALOG_SESSION_ID, isAllowed); + EXPECT_EQ(ret, ERR_OK); + + isAllowed = true; + ret = dialogSessionManager.SendDialogResult(want, TEST_DIALOG_SESSION_ID, isAllowed); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + + dialogSessionManager.SetStartupSessionInfo(TEST_DIALOG_SESSION_ID, abilityRequest); + ret = dialogSessionManager.SendDialogResult(want, TEST_DIALOG_SESSION_ID, isAllowed); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "SendDialogResultTest_0100 end"; +} + +/** + * @tc.name: SendDialogResultTest_0200 + * @tc.desc: Test SendDialogResult + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, SendDialogResultTest_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SendDialogResultTest_0200 start"; + AbilityRequest abilityRequest; + DialogSessionManager dialogSessionManager; + Want want; + bool isAllowed = true; + sptr dilogSessionInfo = nullptr; + std::shared_ptr dialogCallerInfo = std::make_shared(); + + dialogSessionManager.SetDialogSessionInfo(TEST_DIALOG_SESSION_ID, dilogSessionInfo, dialogCallerInfo); + int32_t ret = dialogSessionManager.SendDialogResult(want, TEST_DIALOG_SESSION_ID, isAllowed); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + + want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 0); + ret = dialogSessionManager.SendDialogResult(want, TEST_DIALOG_SESSION_ID, isAllowed); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "SendDialogResultTest_0200 end"; +} + +/** + * @tc.name: NotifySCBToRecoveryAfterInterceptionTest_0100 + * @tc.desc: Test NotifySCBToRecoveryAfterInterception + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, NotifySCBToRecoveryAfterInterceptionTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NotifySCBToRecoveryAfterInterceptionTest_0100 start"; + AbilityRequest abilityRequest; + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.NotifySCBToRecoveryAfterInterception(TEST_DIALOG_SESSION_ID, abilityRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "NotifySCBToRecoveryAfterInterceptionTest_0100 end"; +} + +/** + * @tc.name: CreateJumpModalDialogTest_0100 + * @tc.desc: Test CreateJumpModalDialog + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, CreateJumpModalDialogTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateJumpModalDialogTest_0100 start"; + AbilityRequest abilityRequest; + Want replaceWant; + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.CreateJumpModalDialog(abilityRequest, TEST_USER_ID, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + GTEST_LOG_(INFO) << "CreateJumpModalDialogTest_0100 end"; +} + +/** + * @tc.name: CreateCloneSelectorModalDialogTest_0100 + * @tc.desc: Test CreateCloneSelectorModalDialog + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, CreateCloneSelectorModalDialogTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateCloneSelectorModalDialogTest_0100 start"; + AbilityRequest abilityRequest; + std::string replaceWant = "replaceWant"; + Want want; + std::vector dialogAppInfos; + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.CreateCloneSelectorModalDialog(abilityRequest, + want, TEST_USER_ID, dialogAppInfos, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + + replaceWant = ""; + ret = dialogSessionManager.CreateCloneSelectorModalDialog(abilityRequest, + want, TEST_USER_ID, dialogAppInfos, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + GTEST_LOG_(INFO) << "CreateCloneSelectorModalDialogTest_0100 end"; +} + +/** + * @tc.name: CreateModalDialogCommonTest_0100 + * @tc.desc: Test CreateModalDialogCommon + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, CreateModalDialogCommonTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateModalDialogCommonTest_0100 start"; + Want replaceWant; + sptr callerToken = MockToken(AbilityType::PAGE); + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.CreateModalDialogCommon(replaceWant, callerToken, TEST_DIALOG_SESSION_ID); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + GTEST_LOG_(INFO) << "CreateModalDialogCommonTest_0100 end"; +} + +/** + * @tc.name: HandleErmsResultTest_0100 + * @tc.desc: Test HandleErmsResult + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, HandleErmsResultTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HandleErmsResultTest_0100 start"; + AbilityRequest abilityRequest; + Want replaceWant; + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.HandleErmsResult(abilityRequest, TEST_USER_ID, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + + StartAbilityUtils::ermsResultCode = TEST_ERMS_ISALLOW_RESULTCODE; + ret = dialogSessionManager.HandleErmsResult(abilityRequest, TEST_USER_ID, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + GTEST_LOG_(INFO) << "HandleErmsResultTest_0100 end"; +} + +/** + * @tc.name: HandleErmsResultBySCBTest_0100 + * @tc.desc: Test HandleErmsResultBySCB + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, HandleErmsResultBySCBTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HandleErmsResultBySCBTest_0100 start"; + AbilityRequest abilityRequest; + Want replaceWant; + DialogSessionManager dialogSessionManager; + + int32_t ret = dialogSessionManager.HandleErmsResultBySCB(abilityRequest, replaceWant); + EXPECT_EQ(ret, INNER_ERR); + GTEST_LOG_(INFO) << "HandleErmsResultBySCBTest_0100 end"; +} + +/** + * @tc.name: IsCreateCloneSelectorDialogTest_0100 + * @tc.desc: Test IsCreateCloneSelectorDialog + * @tc.type: FUNC + */ +HWTEST_F(DialogSessionManagerTest, IsCreateCloneSelectorDialogTest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IsCreateCloneSelectorDialogTest_0100 start"; + DialogSessionManager dialogSessionManager; + + StartAbilityUtils::isWantWithAppCloneIndex = true; + bool ret = dialogSessionManager.IsCreateCloneSelectorDialog(TEST_BUNDLE_NAME, TEST_USER_ID); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "IsCreateCloneSelectorDialogTest_0100 end"; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/exit_resident_process_manager_test/exit_resident_process_manager_test.cpp b/test/unittest/exit_resident_process_manager_test/exit_resident_process_manager_test.cpp index 3c5b077414..4bdc1b9b9d 100644 --- a/test/unittest/exit_resident_process_manager_test/exit_resident_process_manager_test.cpp +++ b/test/unittest/exit_resident_process_manager_test/exit_resident_process_manager_test.cpp @@ -52,13 +52,13 @@ void ExitResidentProcessManagerTest::TearDown() /** * @tc.name: IsMemorySizeSufficent_001 - * @tc.desc: Verify that the IsMemorySizeSufficent interface calls normally + * @tc.desc: Verify that the IsMemorySizeSufficient interface calls normally * @tc.type: FUNC */ HWTEST_F(ExitResidentProcessManagerTest, IsMemorySizeSufficent_001, TestSize.Level1) { auto exitResidentProcessManager = std::make_shared(); - EXPECT_EQ(exitResidentProcessManager->IsMemorySizeSufficent(), true); + EXPECT_EQ(exitResidentProcessManager->IsMemorySizeSufficient(), true); } /** diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index af64435466..b3f499df50 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -99,6 +99,7 @@ ohos_unittest("ability_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -618,6 +619,7 @@ ohos_unittest("ability_impl_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -675,6 +677,7 @@ ohos_unittest("ui_ability_impl_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -748,6 +751,7 @@ ohos_unittest("ability_thread_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -826,6 +830,7 @@ ohos_unittest("fa_ability_thread_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -936,6 +941,7 @@ ohos_unittest("ui_ability_thread_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -1319,6 +1325,7 @@ ohos_unittest("data_ability_impl_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -1390,6 +1397,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -1450,6 +1458,7 @@ ohos_unittest("data_ability_impl_file_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -1512,6 +1521,7 @@ ohos_unittest("ability_thread_dataability_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -1746,6 +1756,7 @@ ohos_unittest("ui_ability_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -1860,6 +1871,7 @@ ohos_unittest("form_host_client_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -1911,6 +1923,7 @@ ohos_unittest("continuation_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -2136,6 +2149,7 @@ ohos_unittest("ability_window_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -2199,6 +2213,7 @@ ohos_unittest("ability_handler_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -2251,6 +2266,7 @@ ohos_unittest("ability_impl_factory_test") { "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:continuation_ipc", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_impl_active_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_impl_active_test.cpp index c6e3c79e0f..1d6d7193a5 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_impl_active_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_impl_active_test.cpp @@ -125,7 +125,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_Active_001, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); @@ -165,7 +165,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_Active_002, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); @@ -205,7 +205,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_Active_003, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); @@ -244,7 +244,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_InActive_001, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); @@ -284,7 +284,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_InActive_002, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); @@ -324,7 +324,7 @@ HWTEST_F(AbilityImplActiveTest, AaFwk_AbilityImpl_InActive_003, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mockAbility = std::make_shared(); std::shared_ptr ability = std::static_pointer_cast(mockAbility); std::shared_ptr handler = std::make_shared(nullptr); diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp index 477c0032f3..2e532dd6c6 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp @@ -87,7 +87,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ScheduleUpdateConfiguration_001, Tes sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKPageAbility = std::make_shared(); @@ -135,7 +135,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ScheduleUpdateConfiguration_002, Tes sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKPageAbility = std::make_shared(); @@ -192,7 +192,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ScheduleUpdateConfiguration_003, Tes sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKPageAbility = std::make_shared(); @@ -254,7 +254,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -285,7 +285,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -324,7 +324,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -362,7 +362,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Active_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -403,7 +403,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Inactive_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -444,7 +444,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Foreground_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -480,7 +480,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Background_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -523,7 +523,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -567,7 +567,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_002, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -611,7 +611,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Background_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -654,7 +654,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Background_002, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -699,7 +699,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_001, TestS sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -744,7 +744,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_002, TestS sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -790,7 +790,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_003, TestS sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -835,7 +835,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_004, TestS sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -879,7 +879,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchSaveAbilityState_001, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -907,7 +907,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchSaveAbilityState_002, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -935,7 +935,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchRestoreAbilityState_001, Tes sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -966,7 +966,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchRestoreAbilityState_002, Tes sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -996,7 +996,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ConnectAbility_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1034,7 +1034,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CommandAbility_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1142,7 +1142,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SendResult_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1182,7 +1182,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NewWant_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1220,7 +1220,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_GetFileTypes_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1260,7 +1260,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_OpenFile_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1298,7 +1298,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Insert_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1337,7 +1337,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Update_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1377,7 +1377,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Delete_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1416,7 +1416,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Query_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1457,7 +1457,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndSave_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1493,7 +1493,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndRestore_001, TestSize.Level1 sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1522,7 +1522,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0200, TestSize.Level1) std::shared_ptr application; std::shared_ptr abilityInfo = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKPageAbility = std::make_shared(); std::shared_ptr ability = pMocKPageAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -1563,7 +1563,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0400, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr ability; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -1583,7 +1583,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0500, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKPageAbility = std::make_shared(); std::shared_ptr ability = pMocKPageAbility; std::shared_ptr handler; @@ -1603,7 +1603,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0600, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = nullptr; std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKPageAbility = std::make_shared(); std::shared_ptr ability = pMocKPageAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -1624,7 +1624,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0700, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKPageAbility = std::make_shared(); std::shared_ptr ability = pMocKPageAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -1651,7 +1651,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0200, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1689,7 +1689,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0300, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; @@ -1888,7 +1888,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0800, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability; diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_local_record_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_local_record_test.cpp index f084059a0a..507b8dde0a 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_local_record_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_local_record_test.cpp @@ -51,36 +51,6 @@ void AbilityLocalRecordTest::SetUp() void AbilityLocalRecordTest::TearDown() {} -/** - * @tc.number: GetEventHandler_0100 - * @tc.name: GetEventHandler - * @tc.desc: GetEventHandler Test, return is not nullptr. - */ -HWTEST_F(AbilityLocalRecordTest, GetEventHandler_0100, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetEventHandler_0100 start"; - auto record = std::make_shared(nullptr, nullptr); - auto handler = std::make_shared(EventRunner::Create()); - record->SetEventHandler(handler); - EXPECT_TRUE(record->GetEventHandler() != nullptr); - GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetEventHandler_0100 end"; -} - -/** - * @tc.number: GetEventRunner_0100 - * @tc.name: GetEventRunner - * @tc.desc: GetEventRunner Test, return is not nullptr. - */ -HWTEST_F(AbilityLocalRecordTest, GetEventRunner_0100, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "AbilityLocalRecordTest SetEventHandler_0100 start"; - auto record = std::make_shared(nullptr, nullptr); - std::shared_ptr runner = EventRunner::GetMainEventRunner(); - record->SetEventRunner(runner); - EXPECT_TRUE(record->GetEventRunner() != nullptr); - GTEST_LOG_(INFO) << "AbilityLocalRecordTest SetEventHandler_0100 end"; -} - /** * @tc.number: GetAbilityThread_0100 * @tc.name: GetAbilityThread @@ -89,7 +59,7 @@ HWTEST_F(AbilityLocalRecordTest, GetEventRunner_0100, TestSize.Level0) HWTEST_F(AbilityLocalRecordTest, GetAbilityThread_0100, TestSize.Level0) { GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetAbilityThread_0100 start"; - auto record = std::make_shared(nullptr, nullptr); + auto record = std::make_shared(nullptr, nullptr, nullptr, 0); auto abilityThread = sptr(nullptr); record->SetAbilityThread(abilityThread); EXPECT_TRUE(record->GetAbilityThread() == nullptr); @@ -104,9 +74,8 @@ HWTEST_F(AbilityLocalRecordTest, GetAbilityThread_0100, TestSize.Level0) HWTEST_F(AbilityLocalRecordTest, GetWant_0100, TestSize.Level0) { GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetWant_0100 start"; - auto record = std::make_shared(nullptr, nullptr); std::shared_ptr want; - record->SetWant(want); + auto record = std::make_shared(nullptr, nullptr, want, 0); EXPECT_TRUE(record->GetWant() == nullptr); GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetWant_0100 end"; } @@ -121,7 +90,7 @@ HWTEST_F(AbilityLocalRecordTest, GetAbilityInfo_0100, TestSize.Level0) GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetAbilityInfo_0100 start"; auto info = std::make_shared(); sptr token = new (std::nothrow) MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); EXPECT_TRUE(record->GetAbilityInfo() != nullptr); GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetAbilityInfo_0100 end"; } @@ -136,7 +105,7 @@ HWTEST_F(AbilityLocalRecordTest, GetToken_0100, TestSize.Level0) GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetToken_0100 start"; auto info = std::make_shared(); sptr token = new (std::nothrow) MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); EXPECT_TRUE(record->GetToken() != nullptr); GTEST_LOG_(INFO) << "AbilityLocalRecordTest GetToken_0100 end"; } \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_thread_dataability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_thread_dataability_test.cpp index 5693796af4..c6dd3d939b 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_thread_dataability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_thread_dataability_test.cpp @@ -94,8 +94,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Query_0100, Function | MediumTes EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::shared_ptr mockdataability = std::make_shared(); @@ -159,8 +158,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_GetFileTypes_0100, Function | Me EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::shared_ptr mockdataability = std::make_shared(); @@ -223,8 +221,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_OpenFile_0100, Function | Medium EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::shared_ptr mockdataability = std::make_shared(); @@ -283,8 +280,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Insert_0100, Function | MediumTe EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::shared_ptr mockdataability = std::make_shared(); @@ -339,8 +335,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Update_0100, Function | MediumTe EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::shared_ptr mockdataability = std::make_shared(); diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp index f798388c79..8217ba8a76 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp @@ -88,7 +88,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_DumpAbilityInfo_0100, Function | abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -127,8 +127,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleSaveAbilityState_0100, F EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -176,8 +175,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleRestoreAbilityState_0100 EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); PacMap state; @@ -225,8 +223,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_3_Param_0100, Function | EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); sleep(1); @@ -253,8 +250,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_3_Param_0200, Function | EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -282,8 +278,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_2_Param_0100, Function | EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); abilitythread->Attach(application, abilityRecord, nullptr); sleep(1); @@ -310,8 +305,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_2_Param_0200, Function | EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, nullptr); @@ -341,8 +335,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleAbilityTransaction_0100, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -374,8 +367,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleAbilityTransaction_0200, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); abilitythread->Attach(application, abilityRecord, nullptr); Want want; @@ -405,8 +397,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleConnectAbility_0100, Fun EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -436,8 +427,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleConnectAbility_0200, Fun abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -466,8 +456,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleDisconnectAbility_0100, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -497,8 +486,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleDisconnectAbility_0200, abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -528,8 +516,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleCommandAbility_0100, Fun EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -562,8 +549,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleCommandAbility_0200, Fun abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -594,8 +580,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleCommandAbilityWindow_010 EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -628,8 +613,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_SendResult_0100, Function | Medi EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr abilityimpl = std::make_shared(); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -662,8 +646,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_SendResult_0200, Function | Medi abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -693,8 +676,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0100, Function EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner, nullptr); @@ -721,8 +703,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0200, Function EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner, nullptr); @@ -749,8 +730,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0300, Function EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->AbilityThreadMain(application, abilityRecord, nullptr); @@ -777,8 +757,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0400, Function EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->AbilityThreadMain(application, abilityRecord, nullptr); @@ -804,7 +783,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0100, Function | abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); @@ -833,7 +812,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0200, Function | abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); @@ -858,7 +837,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0201, Function | abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, nullptr); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); @@ -1287,7 +1266,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_SendResult_0300, Function | Medi abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); auto application = std::make_shared(); - auto abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); diff --git a/test/unittest/frameworks_kits_ability_native_test/action_extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/action_extension_test.cpp index 9367b3f31c..772994e0c2 100644 --- a/test/unittest/frameworks_kits_ability_native_test/action_extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/action_extension_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(ActionExtensionTest, Action_Extension_0300, Function | MediumTest | Lev GTEST_LOG_(INFO) << "Action_Extension_0300 start"; auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto application = std::make_shared(); auto contextImpl = std::make_shared(); auto applicationContext = ApplicationContext::GetInstance(); diff --git a/test/unittest/frameworks_kits_ability_native_test/auto_fill_extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/auto_fill_extension_test.cpp index c0ea4c7bfe..3130dfc9f8 100644 --- a/test/unittest/frameworks_kits_ability_native_test/auto_fill_extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/auto_fill_extension_test.cpp @@ -98,7 +98,7 @@ HWTEST_F(AutoFillExtensionTest, Init_0100, Function | MediumTest | Level1) auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); EXPECT_NE(token, nullptr); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); EXPECT_NE(record, nullptr); auto application = std::make_shared(); EXPECT_NE(application, nullptr); @@ -108,7 +108,7 @@ HWTEST_F(AutoFillExtensionTest, Init_0100, Function | MediumTest | Level1) application->SetApplicationContext(applicationContext); auto handler = std::make_shared(nullptr); EXPECT_NE(handler, nullptr); - + autoFillExtension->Init(record, application, handler, token); EXPECT_TRUE(autoFillExtension->context_ != nullptr); GTEST_LOG_(INFO) << "Init_0100 end"; @@ -135,7 +135,7 @@ HWTEST_F(AutoFillExtensionTest, CreateAndInitContext_0100, Function | MediumTest abilityInfo->bundleName = BUNDLE_NAME; sptr token = new AppExecFwk::MockAbilityToken(); EXPECT_NE(token, nullptr); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); EXPECT_NE(record, nullptr); auto application = std::make_shared(); EXPECT_NE(application, nullptr); @@ -145,7 +145,7 @@ HWTEST_F(AutoFillExtensionTest, CreateAndInitContext_0100, Function | MediumTest application->SetApplicationContext(applicationContext); auto handler = std::make_shared(nullptr); EXPECT_NE(handler, nullptr); - + auto context = autoFillExtension->CreateAndInitContext(record, application, handler, token); EXPECT_NE(context, nullptr); @@ -157,7 +157,7 @@ HWTEST_F(AutoFillExtensionTest, CreateAndInitContext_0100, Function | MediumTest auto resourceManager = appContext->GetResourceManager(); EXPECT_EQ(context->GetResourceManager(), resourceManager); EXPECT_EQ(context->parentContext_, appContext); - + EXPECT_EQ(context->GetAbilityInfo(), abilityInfo); EXPECT_EQ(context->GetConfiguration(), appContext->GetConfiguration()); @@ -193,7 +193,7 @@ HWTEST_F(AutoFillExtensionTest, CreateAndInitContext_0200, Function | MediumTest auto handler = std::make_shared(nullptr); EXPECT_NE(handler, nullptr); std::shared_ptr record = nullptr; - + auto context = autoFillExtension->CreateAndInitContext(record, application, handler, token); EXPECT_NE(context, nullptr); @@ -205,7 +205,7 @@ HWTEST_F(AutoFillExtensionTest, CreateAndInitContext_0200, Function | MediumTest auto resourceManager = appContext->GetResourceManager(); EXPECT_EQ(context->GetResourceManager(), resourceManager); EXPECT_EQ(context->parentContext_, appContext); - + EXPECT_EQ(context->GetAbilityInfo(), nullptr); EXPECT_EQ(context->GetConfiguration(), nullptr); diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_secondpart_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_secondpart_test.cpp index d2973c6ccf..06cd67ccfa 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_secondpart_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_secondpart_test.cpp @@ -69,7 +69,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_001, Functio abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); std::shared_ptr ability = std::make_shared(); dataabilityimpl->Init(application, record, ability, handler, token); @@ -117,7 +117,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); std::shared_ptr ability = std::make_shared(); dataabilityimpl->Init(application, record, ability, handler, token); @@ -144,7 +144,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); std::shared_ptr ability = std::make_shared(); dataabilityimpl->Init(application, record, ability, handler, token); diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_test.cpp index 33fa440111..e29bf550c4 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_file_test.cpp @@ -69,7 +69,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_001, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -97,7 +97,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_002, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = nullptr; @@ -123,7 +123,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetFileTypes_001, Functi abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -178,7 +178,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_001, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -229,7 +229,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_001, Functio abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -280,7 +280,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Reload_001, Function | M abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp index f1e1d4bebf..4a87cc7f2c 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp @@ -77,7 +77,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Insert_0100, Function | abilityInfo->type = AbilityType::DATA; abilityInfo->isNativeAbility = true; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -129,7 +129,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Insert_0300, Function | abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -163,7 +163,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Update_0100, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -214,7 +214,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Update_0300, Function | abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -247,7 +247,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Delete_0100, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -297,7 +297,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Delete_0300, Function | abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -330,7 +330,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Query_0100, Function | M abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -383,7 +383,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Query_0300, Function | M abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -418,7 +418,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0100, Function abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -466,7 +466,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0300, Function abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -497,7 +497,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_0100, Functi abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -545,7 +545,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_0300, Functi abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -576,7 +576,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Call_0100, Function | Me abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -627,7 +627,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetFileTypes_0100, Funct abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -677,7 +677,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_0100, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -722,7 +722,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Reload_0100, Function | abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -767,7 +767,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_0100, Functi abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -816,7 +816,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_0300, Functi abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -848,7 +848,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_NormalizeUri_0100, Funct abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -895,7 +895,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_NormalizeUri_0300, Funct abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -926,7 +926,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_DenormalizeUri_0100, Fun abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -973,7 +973,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_DenormalizeUri_0300, Fun abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1006,7 +1006,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0100, abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1039,7 +1039,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0200, abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1072,7 +1072,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0300, abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1105,7 +1105,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0400, abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1135,7 +1135,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0500, abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1166,7 +1166,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1202,7 +1202,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1235,7 +1235,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1268,7 +1268,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1304,7 +1304,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1339,7 +1339,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_ abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1374,7 +1374,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_ abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1409,7 +1409,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_ abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1444,7 +1444,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_ abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1479,7 +1479,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_ abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1512,7 +1512,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0100, Funct abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1559,7 +1559,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0300, Funct abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1594,7 +1594,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0400, Funct abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1625,7 +1625,7 @@ HWTEST_F( abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1653,7 +1653,7 @@ HWTEST_F( abilityInfo->name = "MockDataAbility"; abilityInfo->type = AbilityType::DATA; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1685,7 +1685,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1721,7 +1721,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1757,7 +1757,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1793,7 +1793,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); @@ -1829,7 +1829,7 @@ HWTEST_F( abilityInfo->readPermission = "r"; abilityInfo->writePermission = "w"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr ability = std::make_shared(); diff --git a/test/unittest/frameworks_kits_ability_native_test/embedded_ui_extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/embedded_ui_extension_test.cpp index bdaf6854e8..23c1e5763d 100644 --- a/test/unittest/frameworks_kits_ability_native_test/embedded_ui_extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/embedded_ui_extension_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(EmbeddedUIExtensionTest, EmbeddedUI_Extension_0300, Function | MediumTe GTEST_LOG_(INFO) << "EmbeddedUI_Extension_0300 start"; auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto application = std::make_shared(); auto contextImpl = std::make_shared(); auto applicationContext = ApplicationContext::GetInstance(); diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp index 414f6ce837..b7fd594f31 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp @@ -68,7 +68,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_DumpAbilityInfo_0100 abilityInfo->type = AbilityType::EXTENSION; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); std::vector params; @@ -144,8 +144,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_Attach_3_Param_0100, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); sleep(1); @@ -173,8 +172,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_Attach_3_Param_0200, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); sleep(1); @@ -202,8 +200,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_Attach_2_Param_0100, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); extensionabilitythread->Attach(application, abilityRecord, nullptr); sleep(1); } @@ -230,8 +227,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_Attach_2_Param_0200, EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, nullptr); sleep(1); @@ -260,8 +256,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleAbilityTrans EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -293,8 +288,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleAbilityTrans EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); extensionabilitythread->Attach(application, abilityRecord, nullptr); Want want; LifeCycleStateInfo lifeCycleStateInfo; @@ -367,8 +361,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleConnectAbili EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -397,7 +390,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleConnectAbili abilityInfo->type = AbilityType::EXTENSION; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -426,8 +419,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleDisconnectAb EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -456,7 +448,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleDisconnectAb abilityInfo->type = AbilityType::EXTENSION; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -486,8 +478,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleCommandAbili EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -518,7 +509,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleCommandAbili abilityInfo->type = AbilityType::EXTENSION; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -549,8 +540,7 @@ HWTEST_F(ExtensionAbilityThreadTest, ExtensionAbilityThread_ScheduleCommandAbili EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); extensionabilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -1007,7 +997,7 @@ HWTEST_F( abilityInfo->name = "ExtensionAbility"; abilityInfo->type = AbilityType::EXTENSION; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); std::string abilityName = extensionabilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp index 7ed127f350..0b57816a31 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp @@ -111,7 +111,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0300, Function | MediumTest | Le std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); std::shared_ptr extension; std::shared_ptr handler; @@ -199,7 +199,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0700, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -222,7 +222,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0800, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -279,7 +279,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1100, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -304,7 +304,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1200, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -360,7 +360,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1500, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -386,7 +386,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1600, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -439,7 +439,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1900, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -496,7 +496,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2200, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -523,7 +523,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2300, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -560,7 +560,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2600, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -591,7 +591,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2700, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -618,7 +618,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2800, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -645,7 +645,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2900, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -670,7 +670,7 @@ HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_3000, Function | MediumTest | Le auto application = std::make_shared(); std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto extension = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_second_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_second_test.cpp index 24db446fab..8620d25a21 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_second_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_second_test.cpp @@ -54,7 +54,7 @@ void ExtensionTest::SetUp(void) { std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto application = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp index ef0d14c801..70b33d0229 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp @@ -54,7 +54,7 @@ void ExtensionTest::SetUp(void) { std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto application = std::make_shared(); std::shared_ptr runner; auto handler = std::make_shared(runner); @@ -97,7 +97,7 @@ HWTEST_F(ExtensionTest, AaFwk_Extension_0200, Function | MediumTest | Level1) OHOS::AppExecFwk::AbilityInfo abilityInfo; std::shared_ptr info = std::make_shared(); sptr token = nullptr; - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); std::shared_ptr application; std::shared_ptr handler; @@ -162,7 +162,7 @@ HWTEST_F(ExtensionTest, AaFwk_Extension_0500, Function | MediumTest | Level1) GTEST_LOG_(INFO) << "AaFwk_Extension_0500 start"; std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); auto application = std::make_shared(); diff --git a/test/unittest/frameworks_kits_ability_native_test/fa_ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/fa_ability_thread_test.cpp index 7a75a8b023..6199eaf37b 100644 --- a/test/unittest/frameworks_kits_ability_native_test/fa_ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/fa_ability_thread_test.cpp @@ -231,7 +231,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_CreateAbilityName_0100, Functi abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, nullptr); EXPECT_EQ(abilityName, ""); @@ -271,7 +271,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_CreateExtensionAbilityName_010 std::string abilityName = "MockPageAbility"; abilitythread->CreateExtensionAbilityName(application, abilityInfo, abilityName); sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string ret = abilitythread->CreateAbilityName(abilityRecord, application); EXPECT_EQ(abilityName, "MockPageAbility"); GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CreateExtensionAbilityName_0101 end"; @@ -295,7 +295,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_CreateExtensionAbilityName_020 std::string abilityName = ""; abilitythread->CreateExtensionAbilityName(application, abilityInfo, abilityName); sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string ret = abilitythread->CreateAbilityName(abilityRecord, application); EXPECT_EQ(abilityName, "ServiceExtension"); GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CreateExtensionAbilityName_0200 end"; @@ -316,7 +316,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0300, Function abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); @@ -370,7 +370,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0500, Function abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); @@ -398,7 +398,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_CreateAndInitContextDeal_0500, abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); @@ -424,7 +424,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_CreateAndInitContextDeal_0600, abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr abilityObject = std::make_shared(); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, nullptr); @@ -453,7 +453,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_InitExtensionFlag_0200, Functi abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); @@ -485,7 +485,7 @@ HWTEST_F(FaAbilityThreadTest, AaFwk_AbilityThread_InitExtensionFlag_0300, Functi abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); diff --git a/test/unittest/frameworks_kits_ability_native_test/form_extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/form_extension_test.cpp index 31c4b67e9c..660022660d 100644 --- a/test/unittest/frameworks_kits_ability_native_test/form_extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/form_extension_test.cpp @@ -94,7 +94,7 @@ HWTEST_F(FormExtensionTest, AaFwk_Form_Extension_0300, Function | MediumTest | L GTEST_LOG_(INFO) << "AaFwk_Form_Extension_0300 start"; std::shared_ptr abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr contextImpl = std::make_shared(); @@ -141,7 +141,7 @@ HWTEST_F(FormExtensionTest, AaFwk_Form_Extension_0500, Function | MediumTest | L GTEST_LOG_(INFO) << "AaFwk_Form_Extension_0500 start"; std::shared_ptr info = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(info, token); + auto record = std::make_shared(info, token, nullptr, 0); std::shared_ptr application; std::shared_ptr handler; AbilityRuntime::Runtime::Options options; diff --git a/test/unittest/frameworks_kits_ability_native_test/new_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/new_ability_impl_test.cpp index 4ba8752d79..97e5ac539e 100644 --- a/test/unittest/frameworks_kits_ability_native_test/new_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/new_ability_impl_test.cpp @@ -79,7 +79,7 @@ HWTEST_F(NewAbilityImplTest, AaFwk_NewAbilityImpl_HandleAbilityTransaction_0100, std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "newAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -136,7 +136,7 @@ HWTEST_F(NewAbilityImplTest, AaFwk_NewAbilityImpl_HandleAbilityTransaction_0300, std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "newAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); diff --git a/test/unittest/frameworks_kits_ability_native_test/page_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/page_ability_impl_test.cpp index d9b15a7c79..ca42188510 100644 --- a/test/unittest/frameworks_kits_ability_native_test/page_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/page_ability_impl_test.cpp @@ -73,7 +73,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoKeyDown_0100, Function | M std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -106,7 +106,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoKeyDown_0200, Function | M std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -138,7 +138,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoKeyUp_0100, Function | Med std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -171,7 +171,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoKeyUp_0200, Function | Med std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -204,7 +204,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoTouchEvent_0100, Function std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -237,7 +237,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DoTouchEvent_0200, Function std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -269,7 +269,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_010 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -303,7 +303,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_020 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -333,7 +333,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_030 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -363,7 +363,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_040 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -393,7 +393,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_050 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -425,7 +425,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_060 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -458,7 +458,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_070 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -493,7 +493,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_080 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -527,7 +527,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_090 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -563,7 +563,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DispatchSaveAbilityState_010 std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -590,7 +590,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_DispatchRestoreAbilityState_ std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -618,7 +618,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_SendResult_0100, Function | std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -648,7 +648,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_NewWant_0100, Function | Med std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -674,7 +674,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_100 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -705,7 +705,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_110 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -736,7 +736,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_120 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -767,7 +767,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_130 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -798,7 +798,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_140 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -829,7 +829,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_150 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); @@ -861,7 +861,7 @@ HWTEST_F(PageAbilityImplTest, AaFwk_PageAbilityImpl_HandleAbilityTransaction_160 auto abilityInfo = std::make_shared(); abilityInfo->name = "pageAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); diff --git a/test/unittest/frameworks_kits_ability_native_test/service_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/service_ability_impl_test.cpp index e2d3be03be..754ce81650 100644 --- a/test/unittest/frameworks_kits_ability_native_test/service_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/service_ability_impl_test.cpp @@ -72,7 +72,7 @@ HWTEST_F(ServiceAbilityImplTest, AaFwk_ServiceAbilityImpl_HandleAbilityTransacti std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "MockServiceAbility"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); sptr abilityThread = @@ -113,7 +113,7 @@ HWTEST_F(ServiceAbilityImplTest, AaFwk_ServiceAbilityImpl_HandleAbilityTransacti abilityInfo->name = "MockServiceAbility"; abilityInfo->type = AppExecFwk::AbilityType::SERVICE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); sptr abilityThread = @@ -150,7 +150,7 @@ HWTEST_F(ServiceAbilityImplTest, AaFwk_ServiceAbilityImpl_HandleAbilityTransacti std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->name = "MockServiceAbility"; sptr token = nullptr; - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -186,7 +186,7 @@ HWTEST_F(ServiceAbilityImplTest, AaFwk_ServiceAbilityImpl_HandleAbilityTransacti abilityInfo->name = "MockServiceAbility"; abilityInfo->type = AppExecFwk::AbilityType::SERVICE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); diff --git a/test/unittest/frameworks_kits_ability_native_test/share_extension_module_loader_test.cpp b/test/unittest/frameworks_kits_ability_native_test/share_extension_module_loader_test.cpp index 5347bf1668..b899969a58 100644 --- a/test/unittest/frameworks_kits_ability_native_test/share_extension_module_loader_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/share_extension_module_loader_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(ShareExtensionTest, Share_Extension_0300, Function | MediumTest | Level GTEST_LOG_(INFO) << "Share_Extension_0300 start"; auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto application = std::make_shared(); auto contextImpl = std::make_shared(); auto applicationContext = ApplicationContext::GetInstance(); diff --git a/test/unittest/frameworks_kits_ability_native_test/share_extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/share_extension_test.cpp index 24d65287b1..b681e822fd 100644 --- a/test/unittest/frameworks_kits_ability_native_test/share_extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/share_extension_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(ShareExtensionTest, Share_Extension_0300, Function | MediumTest | Level GTEST_LOG_(INFO) << "Share_Extension_0300 start"; auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto application = std::make_shared(); auto contextImpl = std::make_shared(); auto applicationContext = ApplicationContext::GetInstance(); diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp index 2e6267800e..f7cea9c254 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp @@ -80,7 +80,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_001, Test sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKUIAbility = std::make_shared(); @@ -128,7 +128,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_002, Test sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKUIAbility = std::make_shared(); @@ -184,7 +184,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_003, Test sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr pMocKUIAbility = std::make_shared(); @@ -244,7 +244,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = std::make_shared(); @@ -274,7 +274,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -313,7 +313,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -353,7 +353,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -397,7 +397,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_002, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -439,7 +439,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Background_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -482,7 +482,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Background_002, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -527,7 +527,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_001, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -572,7 +572,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -618,7 +618,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_003, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -663,7 +663,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_004, TestSi sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -707,7 +707,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchRestoreAbilityState_001, Test sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = std::make_shared(); @@ -737,7 +737,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchRestoreAbilityState_002, Test sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability = nullptr; @@ -767,7 +767,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_SendResult_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -806,7 +806,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_NewWant_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -843,7 +843,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_CheckAndRestore_001, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -872,7 +872,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0200, TestSize.Level1) std::shared_ptr application; std::shared_ptr abilityInfo = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKUIAbility = std::make_shared(); std::shared_ptr uiability = pMocKUIAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -913,7 +913,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0400, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr uiability; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); @@ -933,7 +933,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0500, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKUIAbility = std::make_shared(); std::shared_ptr uiability = pMocKUIAbility; std::shared_ptr handler; @@ -953,7 +953,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0600, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = nullptr; std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKUIAbility = std::make_shared(); std::shared_ptr uiability = pMocKUIAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -974,7 +974,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0700, TestSize.Level1) std::shared_ptr application = std::make_shared(); sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr pMocKUIAbility = std::make_shared(); std::shared_ptr uiability = pMocKUIAbility; std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); @@ -1002,7 +1002,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_0300, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; @@ -1201,7 +1201,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0800, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); EXPECT_NE(token, nullptr); if (token != nullptr) { - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); std::shared_ptr uiability; diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp index 0ab938e2fd..e7af954413 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp @@ -72,11 +72,11 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_Name_0100, Function | MediumTest | Le std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); EXPECT_STREQ(abilityInfo->name.c_str(), ability_->GetAbilityName().c_str()); - std::shared_ptr abilityRecord2 = std::make_shared(nullptr, abilityToken); + auto abilityRecord2 = std::make_shared(nullptr, abilityToken, nullptr, 0); ability_->Init(abilityRecord2, application, handler, token); EXPECT_EQ("", ability_->GetAbilityName()); @@ -106,7 +106,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetAbilityName_0100, Function | Mediu std::string name = "LOL"; abilityInfo->name = name; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); EXPECT_STREQ(ability_->GetAbilityName().c_str(), name.c_str()); GTEST_LOG_(INFO) << "AbilityRuntime_GetAbilityName_0100 end"; @@ -127,12 +127,11 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetModuleName_0100, Function | Medium std::string name = "LOL"; abilityInfo->moduleName = name; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(nullptr, abilityToken); + auto abilityRecord = std::make_shared(nullptr, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); EXPECT_EQ(ability_->GetModuleName(), ""); - std::shared_ptr abilityRecord2 = std::make_shared(abilityInfo, - abilityToken); + auto abilityRecord2 = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord2, application, handler, token); EXPECT_STREQ(ability_->GetModuleName().c_str(), name.c_str()); } @@ -151,7 +150,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetLifecycle_0100, Function | MediumT std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); std::shared_ptr lifeCycle = ability_->GetLifecycle(); EXPECT_NE(lifeCycle, nullptr); @@ -201,7 +200,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnNewWant_0100, Function | MediumTest std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnNewWant(want); @@ -222,7 +221,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnRestoreAbilityState_0100, Function std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); PacMap inState; ability_->OnRestoreAbilityState(inState); @@ -243,7 +242,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetWindow_001, Function | MediumTest std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); EXPECT_EQ(ability_->GetWindow(), nullptr); GTEST_LOG_(INFO) << "AbilityRuntime_GetWindow_0100 end"; @@ -265,7 +264,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0100, Function | MediumTest | std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnStart(want); @@ -318,7 +317,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0300, TestSize.Level1) auto handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, application, handler, token); Want want; ability->OnStart(want); @@ -364,7 +363,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStop_0100, Function | MediumTest | std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); ability_->OnStop(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -442,7 +441,7 @@ HWTEST_F(UIAbilityBaseTest, DestroyInstance_0100, TestSize.Level1) auto handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, application, handler, token); ability->DestroyInstance(); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); @@ -463,7 +462,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0100, Function | MediumT std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; bool prevSilentForground = ability_->CheckIsSilentForeground(); @@ -513,7 +512,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0300, Function | MediumT std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnForeground(want); @@ -540,7 +539,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0100, Function | MediumT std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -564,7 +563,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0200, Function | MediumT std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -590,7 +589,7 @@ HWTEST_F(UIAbilityBaseTest, AaFwk_Ability_OnBackground_0300, Function | MediumTe std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -627,7 +626,7 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0400, TestSize.Level1) auto handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, application, handler, token); int32_t displayId = 0; sptr option = new Rosen::WindowOption(); @@ -771,8 +770,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0300, TestSize.Level1) auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); Want want; bool success = false; @@ -1090,8 +1088,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionLabel_0100, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); ret = ability->SetMissionLabel(label); EXPECT_EQ(ret, -1); @@ -1124,8 +1121,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionIcon_0100, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); ret = ability->SetMissionIcon(icon); EXPECT_EQ(ret, -1); @@ -1153,8 +1149,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnChange_0100, TestSize.Level1) auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); // application is nullptr @@ -1188,8 +1183,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnDisplayMove_0100, TestSize.Level1) auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); // application is nullptr @@ -1228,8 +1222,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityRequestFocus_0100, TestSize.Level1) auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = - std::make_shared(pageAbilityInfo, abilityToken); + auto abilityRecord = std::make_shared(pageAbilityInfo, abilityToken, nullptr, 0); ability->Init(abilityRecord, nullptr, handler, nullptr); // window is nullptr @@ -1269,7 +1262,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_OnStop_AsyncCallback_0100, TestSize.Level1 std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); bool isAsyncCallback = false; ability_->OnStop(nullptr, isAsyncCallback); @@ -1298,7 +1291,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_OnConfigurationUpdatedNotify_0100, TestSiz std::shared_ptr handler = nullptr; sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); auto abilityContext = std::make_shared(); ability_->AttachAbilityContext(abilityContext); @@ -1325,7 +1318,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_InitWindow_0100, TestSize.Level1) std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); int32_t displayId = 0; sptr option = new Rosen::WindowOption(); @@ -1366,7 +1359,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_GetWindowOption_0100, TestSize.Level1) std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); CustomizeData custData = CustomizeData("ShowOnLockScreen", "0", ""); std::vector vecCustData; @@ -1396,7 +1389,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0100, TestSize.Level1) std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; ability_->DoOnForeground(want); @@ -1422,7 +1415,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0200, TestSize.Level1) std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + auto abilityRecord = std::make_shared(abilityInfo, abilityToken, nullptr, 0); ability_->Init(abilityRecord, application, handler, token); Want want; ability_->DoOnForeground(want); @@ -1455,7 +1448,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_RegisterAbilityLifecycleObserver_0100, Fun // init UIAbility to make sure lifecycle is created. std::shared_ptr abilityInfo = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, nullptr); + auto abilityRecord = std::make_shared(abilityInfo, nullptr, nullptr, 0); std::shared_ptr handler = std::make_shared(nullptr); ability->Init(abilityRecord, nullptr, handler, nullptr); std::shared_ptr lifeCycle = ability->GetLifecycle(); diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp index d4373d913f..7e11ad8836 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp @@ -74,8 +74,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0100, Function | Me EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); @@ -169,8 +168,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleSaveAbilityState_0100, Func EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); abilitythread->ScheduleSaveAbilityState(); @@ -214,8 +212,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleRestoreAbilityState_0100, F EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); PacMap state; @@ -260,8 +257,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0100, Function | Med EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); sleep(1); @@ -288,8 +284,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0200, Function | Med EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); sleep(1); @@ -316,8 +311,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0100, Function | Med EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); abilitythread->Attach(application, abilityRecord, nullptr); sleep(1); } @@ -343,8 +337,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0200, Function | Med EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = nullptr; - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, nullptr); sleep(1); @@ -371,8 +364,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0100, Fu EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); Want want; @@ -402,8 +394,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0200, Fu EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); abilitythread->Attach(application, abilityRecord, nullptr); Want want; LifeCycleStateInfo lifeCycleStateInfo; @@ -491,8 +482,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0100, Function | MediumT EXPECT_NE(token, nullptr); if (token != nullptr) { std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = - std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr abilityimpl = std::make_shared(); @@ -523,7 +513,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0200, Function | MediumT abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr application = std::make_shared(); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); int requestCode = 0; @@ -549,7 +539,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0300, Function | MediumT abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); auto application = std::make_shared(); - auto abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); abilitythread->abilityImpl_ = std::make_shared(); @@ -937,7 +927,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CreateAndInitContextDeal_0100, Func abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); auto ret = abilitythread->CreateAndInitContextDeal(application, abilityRecord, nullptr); EXPECT_EQ(ret, nullptr); GTEST_LOG_(INFO) << "AbilityRuntime_CreateAndInitContextDeal_0100 end"; @@ -959,7 +949,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CreateAndInitContextDeal_0200, Func abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr abilityObject = std::make_shared(); auto ret = abilitythread->CreateAndInitContextDeal(application, abilityRecord, abilityObject); EXPECT_NE(ret, nullptr); @@ -982,7 +972,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CreateAndInitContextDeal_0300, Func abilityInfo->name = "MockPageAbility"; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr abilityObject = std::make_shared(); auto ret = abilitythread->CreateAndInitContextDeal(nullptr, abilityRecord, abilityObject); EXPECT_EQ(ret, nullptr); @@ -1026,7 +1016,7 @@ HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_0100, Function | MediumTest abilityInfo->name = ""; abilityInfo->type = AbilityType::PAGE; sptr token = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); auto ret = abilitythread->CreateAbilityName(abilityRecord); diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index dc59a98949..5cfe2335e5 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -115,6 +115,7 @@ ohos_unittest("application_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -174,6 +175,7 @@ ohos_unittest("context_impl_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", @@ -226,6 +228,7 @@ ohos_unittest("context_container_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -415,6 +418,7 @@ ohos_unittest("context_deal_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -473,6 +477,7 @@ ohos_unittest("application_impl_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", @@ -609,6 +614,7 @@ ohos_unittest("form_extension_context_test") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", "${ability_runtime_native_path}/ability/native:form_extension", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_manager_helper", diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_stage_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_stage_test.cpp index 9d2d792083..72e5cc57d4 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_stage_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_stage_test.cpp @@ -143,7 +143,7 @@ HWTEST_F(AbilityStageTest, AppExecFwk_AbilityStage_AddAbility_002, Function | Me GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_002 start"; sptr token = new (std::nothrow) MockToken(); GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_002 111"; - abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr)); + abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr, nullptr, 0)); GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_002 222"; EXPECT_TRUE(abilityStage_->ContainsAbility()); GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_002 end"; @@ -160,7 +160,7 @@ HWTEST_F(AbilityStageTest, AppExecFwk_AbilityStage_AddAbility_003, Function | Me { GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_003 start"; EXPECT_FALSE(abilityStage_->ContainsAbility()); - abilityStage_->AddAbility(nullptr, std::make_shared(nullptr, nullptr)); + abilityStage_->AddAbility(nullptr, std::make_shared(nullptr, nullptr, nullptr, 0)); EXPECT_FALSE(abilityStage_->ContainsAbility()); GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_AddAbility_003 end"; } @@ -209,7 +209,7 @@ HWTEST_F(AbilityStageTest, AppExecFwk_AbilityStage_RemoveAbility_002, Function | { GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_RemoveAbility_002 start"; sptr token = new MockToken(); - abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr)); + abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr, nullptr, 0)); EXPECT_TRUE(abilityStage_->ContainsAbility()); abilityStage_->RemoveAbility(token); EXPECT_FALSE(abilityStage_->ContainsAbility()); @@ -241,7 +241,7 @@ HWTEST_F(AbilityStageTest, AppExecFwk_AbilityStage_ContainsAbility_002, Function { GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_ContainsAbility_002 start"; sptr token = new MockToken(); - abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr)); + abilityStage_->AddAbility(token, std::make_shared(nullptr, nullptr, nullptr, 0)); EXPECT_TRUE(abilityStage_->ContainsAbility()); GTEST_LOG_(INFO) << "AppExecFwk_AbilityStage_ContainsAbility_002 end"; } diff --git a/test/unittest/js_auto_fill_extension_test/js_auto_fill_extension_test.cpp b/test/unittest/js_auto_fill_extension_test/js_auto_fill_extension_test.cpp index bdcd82d9da..f9ce763e4f 100644 --- a/test/unittest/js_auto_fill_extension_test/js_auto_fill_extension_test.cpp +++ b/test/unittest/js_auto_fill_extension_test/js_auto_fill_extension_test.cpp @@ -89,7 +89,7 @@ void JsAutoFillExtensionTest::CreateJsAutoFillExtension() { std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr contextImpl = std::make_shared(); diff --git a/test/unittest/js_service_extension_test/js_service_extension_test.cpp b/test/unittest/js_service_extension_test/js_service_extension_test.cpp index 943437a609..b9f02ea8cc 100644 --- a/test/unittest/js_service_extension_test/js_service_extension_test.cpp +++ b/test/unittest/js_service_extension_test/js_service_extension_test.cpp @@ -91,7 +91,7 @@ void JsServiceExtensionTest::CreateJsServiceExtension() { std::shared_ptr abilityInfo = std::make_shared(); sptr token(new (std::nothrow) MockAbilityToken()); - std::shared_ptr record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr contextImpl = std::make_shared(); diff --git a/test/unittest/js_ui_service_extension_test/js_ui_service_extension_test.cpp b/test/unittest/js_ui_service_extension_test/js_ui_service_extension_test.cpp index 4a14933d8e..051393d22f 100644 --- a/test/unittest/js_ui_service_extension_test/js_ui_service_extension_test.cpp +++ b/test/unittest/js_ui_service_extension_test/js_ui_service_extension_test.cpp @@ -104,8 +104,7 @@ void JsUIServiceExtensionTest::SetUp() std::shared_ptr info = std::make_shared(); info->name = "JsUIServiceExtensionTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); diff --git a/test/unittest/photo_editor_extension_test/photo_editor_extension_test.cpp b/test/unittest/photo_editor_extension_test/photo_editor_extension_test.cpp index d4cb80b467..b66ddcd3b2 100644 --- a/test/unittest/photo_editor_extension_test/photo_editor_extension_test.cpp +++ b/test/unittest/photo_editor_extension_test/photo_editor_extension_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(PhotoEditorExtensionTest, PhotoEditor_Extension_0300, Function | Medium GTEST_LOG_(INFO) << "PhotoEditor_Extension_0300 start"; auto abilityInfo = std::make_shared(); sptr token = new AppExecFwk::MockAbilityToken(); - auto record = std::make_shared(abilityInfo, token); + auto record = std::make_shared(abilityInfo, token, nullptr, 0); auto application = std::make_shared(); auto contextImpl = std::make_shared(); auto applicationContext = ApplicationContext::GetInstance(); diff --git a/test/unittest/ui_service_extension_test/ui_service_extension_test.cpp b/test/unittest/ui_service_extension_test/ui_service_extension_test.cpp index 693b051b1b..46ba7157f9 100644 --- a/test/unittest/ui_service_extension_test/ui_service_extension_test.cpp +++ b/test/unittest/ui_service_extension_test/ui_service_extension_test.cpp @@ -97,8 +97,7 @@ HWTEST_F(UIServiceExtensionTest, CreateAndInitContext_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "UIServiceExtensionTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); @@ -125,8 +124,7 @@ HWTEST_F(UIServiceExtensionTest, Init_0100, TestSize.Level1) std::shared_ptr info = std::make_shared(); info->name = "UIServiceExtensionTest"; - std::shared_ptr record = - std::make_shared(info, nullptr); + auto record = std::make_shared(info, nullptr, nullptr, 0); std::shared_ptr application = std::make_shared(); std::shared_ptr handler = std::make_shared(nullptr); sptr token = new AppExecFwk::MockAbilityToken(); diff --git a/test/unittest/uri_permission_impl_test/mock/include/mock_accesstoken_kit.h b/test/unittest/uri_permission_impl_test/mock/include/mock_accesstoken_kit.h index 6474da1451..3b87f2f4a7 100644 --- a/test/unittest/uri_permission_impl_test/mock/include/mock_accesstoken_kit.h +++ b/test/unittest/uri_permission_impl_test/mock/include/mock_accesstoken_kit.h @@ -18,6 +18,7 @@ #include "access_token.h" #include "native_token_info.h" +#include "hap_token_info.h" namespace OHOS { namespace Security { @@ -28,6 +29,8 @@ public: static ATokenTypeEnum GetTokenTypeFlag(AccessTokenID tokenID); static int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo& nativeTokenInfoRes); + + static int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& hapInfo); }; } // namespace AccessToken } // namespace Security diff --git a/test/unittest/uri_permission_impl_test/mock/include/mock_bundle_mgr_helper.h b/test/unittest/uri_permission_impl_test/mock/include/mock_bundle_mgr_helper.h index 19d7dfae90..7b7550a9bc 100644 --- a/test/unittest/uri_permission_impl_test/mock/include/mock_bundle_mgr_helper.h +++ b/test/unittest/uri_permission_impl_test/mock/include/mock_bundle_mgr_helper.h @@ -37,6 +37,8 @@ public: ErrCode GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex, BundleInfo &bundleInfo, int32_t userId); + std::string GetAppIdByBundleName(const std::string &bundleName, const int32_t userId); + private: void OnDeath(); diff --git a/test/unittest/uri_permission_impl_test/mock/include/mock_media_permission_manager.h b/test/unittest/uri_permission_impl_test/mock/include/mock_media_permission_manager.h new file mode 100644 index 0000000000..cc79664049 --- /dev/null +++ b/test/unittest/uri_permission_impl_test/mock/include/mock_media_permission_manager.h @@ -0,0 +1,42 @@ +/* +* 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_MEDIA_PERMISSION_MANAGER_H +#define OHOS_ABILITY_RUNTIME_MEDIA_PERMISSION_MANAGER_H + +#include +#include +#include + +namespace OHOS { +namespace AAFwk { +class MediaPermissionManager { +public: + static int32_t GrantPhotoUriPermission(const std::string &bundleName, const std::vector &uris, + uint32_t flag) + { + return 0; + } + + static std::vector CheckPhotoUriPermission(const std::vector &uriVec, + uint32_t tokenId, uint32_t flag) + { + return std::vector(uriVec.size(), 0); + } +}; + +} // OHOS +} // AAFwk +#endif // OHOS_ABILITY_RUNTIME_MEDIA_PERMISSION_MANAGER_H \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/mock_accesstoken_kit.cpp b/test/unittest/uri_permission_impl_test/mock/src/mock_accesstoken_kit.cpp index bfa66bcab8..c24e601ead 100644 --- a/test/unittest/uri_permission_impl_test/mock/src/mock_accesstoken_kit.cpp +++ b/test/unittest/uri_permission_impl_test/mock/src/mock_accesstoken_kit.cpp @@ -37,6 +37,15 @@ int AccessTokenKit::GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo& n } return -1; } + +int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& hapInfo) +{ + if (MyFlag::tokenInfos.find(tokenID) != MyFlag::tokenInfos.end()) { + hapInfo.bundleName = MyFlag::tokenInfos[tokenID].bundleName; + return 0; + } + return -1; +} } // namespace AccessToken } // namespace Security } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/uri_permission_impl_test/mock/src/mock_bundle_mgr_helper.cpp index 5859e7b056..cc31030736 100644 --- a/test/unittest/uri_permission_impl_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/uri_permission_impl_test/mock/src/mock_bundle_mgr_helper.cpp @@ -76,6 +76,12 @@ bool BundleMgrHelper::GetApplicationInfo(const std::string &appName, uint32_t fl return true; } +std::string BundleMgrHelper::GetAppIdByBundleName(const std::string &bundleName, const int32_t userId) +{ + auto appId = bundleName + "_appId"; + return appId; +} + ErrCode BundleMgrHelper::GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex, BundleInfo &bundleInfo, int32_t userId) { diff --git a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp index 9d0acf36c0..3fc634c6f9 100755 --- a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp +++ b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp @@ -15,6 +15,7 @@ #include +#include "mock_media_permission_manager.h" #include "mock_accesstoken_kit.h" #include "mock_bundle_mgr_helper.h" #include "mock_ipc_skeleton.h" @@ -485,53 +486,12 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_001, TestSize.Level1) ASSERT_NE(upms, nullptr); auto mediaPhotoUri = Uri("file://media/Photo/1/IMG_001/test_001.jpg"); uint32_t callerTokenId = 1001; - uint32_t targetTokenId = 1002; uint32_t flagRead = 1; - uint32_t flagWrite = 2; TokenIdPermission tokenIdPermission(callerTokenId); - auto ret = upms->CheckUriPermission(mediaPhotoUri, flagRead, tokenIdPermission); + std::vector mediaPhotoUris = { mediaPhotoUri }; + auto ret = upms->CheckUriPermission(tokenIdPermission, mediaPhotoUris, flagRead)[0]; ASSERT_EQ(ret, false); - - // read - MyFlag::permissionReadImageVideo_ = true; - tokenIdPermission = TokenIdPermission(callerTokenId); - ret = upms->CheckUriPermission(mediaPhotoUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaPhotoUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - MyFlag::permissionReadImageVideo_ = false; - - // write - MyFlag::permissionWriteImageVideo_ = true; - tokenIdPermission = TokenIdPermission(callerTokenId); - ret = upms->CheckUriPermission(mediaPhotoUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaPhotoUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, true); - MyFlag::permissionWriteImageVideo_ = false; - - // proxy uri permision - MyFlag::permissionProxyAuthorization_ = true; - tokenIdPermission = TokenIdPermission(targetTokenId); - // no record - ret = upms->CheckUriPermission(mediaPhotoUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, false); - ret = upms->CheckUriPermission(mediaPhotoUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - - // read - upms->AddTempUriPermission(mediaPhotoUri.ToString(), flagRead, callerTokenId, targetTokenId, false); - ret = upms->CheckUriPermission(mediaPhotoUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaPhotoUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - - // write - upms->AddTempUriPermission(mediaPhotoUri.ToString(), flagWrite, callerTokenId, targetTokenId, false); - ret = upms->CheckUriPermission(mediaPhotoUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, true); - MyFlag::permissionProxyAuthorization_ = false; } /* @@ -546,53 +506,12 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_002, TestSize.Level1) ASSERT_NE(upms, nullptr); auto mediaAudioUri = Uri("file://media/Audio/1/Record_001/test_001.mp3"); uint32_t callerTokenId = 1001; - uint32_t targetTokenId = 1002; uint32_t flagRead = 1; - uint32_t flagWrite = 2; TokenIdPermission tokenIdPermission(callerTokenId); - auto ret = upms->CheckUriPermission(mediaAudioUri, flagRead, tokenIdPermission); + std::vector mediaAudioUris = { mediaAudioUri }; + auto ret = upms->CheckUriPermission(tokenIdPermission, mediaAudioUris, flagRead)[0]; ASSERT_EQ(ret, false); - - // read - MyFlag::permissionReadAudio_ = true; - tokenIdPermission = TokenIdPermission(targetTokenId); - ret = upms->CheckUriPermission(mediaAudioUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaAudioUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - MyFlag::permissionReadAudio_ = false; - - // write - MyFlag::permissionWriteAudio_ = true; - tokenIdPermission = TokenIdPermission(targetTokenId); - ret = upms->CheckUriPermission(mediaAudioUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaAudioUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, true); - MyFlag::permissionWriteAudio_ = false; - - // proxy uri permission - MyFlag::permissionProxyAuthorization_ = true; - tokenIdPermission = TokenIdPermission(targetTokenId); - // no record - ret = upms->CheckUriPermission(mediaAudioUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, false); - ret = upms->CheckUriPermission(mediaAudioUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - - // read - upms->AddTempUriPermission(mediaAudioUri.ToString(), flagRead, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(mediaAudioUri, flagRead, tokenIdPermission); - ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(mediaAudioUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, false); - - // write - upms->AddTempUriPermission(mediaAudioUri.ToString(), flagWrite, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(mediaAudioUri, flagWrite, tokenIdPermission); - ASSERT_EQ(ret, true); - MyFlag::permissionProxyAuthorization_ = false; } /* @@ -605,22 +524,22 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_003, TestSize.Level1) { auto upms = std::make_unique(); ASSERT_NE(upms, nullptr); - auto docsUri = Uri("file://docs/DestTop/Text/test_001.txt"); + std::vector docsUri = { Uri("file://docs/DestTop/Text/test_001.txt") }; uint32_t callerTokenId = 1001; uint32_t targetTokenId = 1002; uint32_t flagRead = 1; uint32_t flagWrite = 2; TokenIdPermission tokenIdPermission(callerTokenId); - auto ret = upms->CheckUriPermission(docsUri, flagRead, tokenIdPermission); + auto ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagRead)[0]; ASSERT_EQ(ret, false); // have FILE_ACCESS_MANAGER permission MyFlag::permissionFileAccessManager_ = true; tokenIdPermission = TokenIdPermission(targetTokenId); - ret = upms->CheckUriPermission(docsUri, flagRead, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagRead)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(docsUri, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0]; ASSERT_EQ(ret, true); MyFlag::permissionFileAccessManager_ = false; @@ -628,21 +547,21 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_003, TestSize.Level1) MyFlag::permissionProxyAuthorization_ = true; tokenIdPermission = TokenIdPermission(targetTokenId); // no record - ret = upms->CheckUriPermission(docsUri, flagRead, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagRead)[0]; ASSERT_EQ(ret, false); - ret = upms->CheckUriPermission(docsUri, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0]; ASSERT_EQ(ret, false); // read - upms->AddTempUriPermission(docsUri.ToString(), flagRead, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(docsUri, flagRead, tokenIdPermission); + upms->AddTempUriPermission(docsUri[0].ToString(), flagRead, callerTokenId, targetTokenId, 0); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagRead)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(docsUri, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0]; ASSERT_EQ(ret, false); // write - upms->AddTempUriPermission(docsUri.ToString(), flagWrite, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(docsUri, flagWrite, tokenIdPermission); + upms->AddTempUriPermission(docsUri[0].ToString(), flagWrite, callerTokenId, targetTokenId, 0); + ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0]; ASSERT_EQ(ret, true); MyFlag::permissionProxyAuthorization_ = false; } @@ -657,45 +576,46 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_004, TestSize.Level1) { auto upms = std::make_unique(); ASSERT_NE(upms, nullptr); - auto uri1 = Uri("file://com.example.app1001/data/storage/el2/base/haps/entry/files/test_001.txt"); - auto uri2 = Uri("file://com.example.app1002/data/storage/el2/base/haps/entry/files/test_002.txt"); + std::vector uri1 = { Uri("file://com.example.app1001/data/storage/el2/base/haps/entry/files/test_001.txt") }; + std::vector uri2 = { Uri("file://com.example.app1002/data/storage/el2/base/haps/entry/files/test_002.txt") }; uint32_t callerTokenId = 1001; uint32_t targetTokenId = 1002; uint32_t flagRead = 1; uint32_t flagWrite = 2; TokenIdPermission tokenIdPermission(callerTokenId); - auto ret = upms->CheckUriPermission(uri1, flagRead, tokenIdPermission); + MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_HAP, "", "com.example.app1001"); + auto ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(uri1, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(uri2, flagRead, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri2, flagRead)[0]; ASSERT_EQ(ret, false); - ret = upms->CheckUriPermission(uri2, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri2, flagWrite)[0]; ASSERT_EQ(ret, false); // proxy uri permision MyFlag::permissionProxyAuthorization_ = true; tokenIdPermission = TokenIdPermission(targetTokenId); // no record - ret = upms->CheckUriPermission(uri1, flagRead, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0]; ASSERT_EQ(ret, false); - ret = upms->CheckUriPermission(uri1, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0]; ASSERT_EQ(ret, false); // read - upms->AddTempUriPermission(uri1.ToString(), flagRead, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(uri1, flagRead, tokenIdPermission); + upms->AddTempUriPermission(uri1[0].ToString(), flagRead, callerTokenId, targetTokenId, 0); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(uri1, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0]; ASSERT_EQ(ret, false); // write - upms->AddTempUriPermission(uri1.ToString(), flagWrite, callerTokenId, targetTokenId, 0); - ret = upms->CheckUriPermission(uri1, flagRead, tokenIdPermission); + upms->AddTempUriPermission(uri1[0].ToString(), flagWrite, callerTokenId, targetTokenId, 0); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0]; ASSERT_EQ(ret, true); - ret = upms->CheckUriPermission(uri1, flagWrite, tokenIdPermission); + ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0]; ASSERT_EQ(ret, true); MyFlag::permissionProxyAuthorization_ = false; } @@ -711,21 +631,21 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_005, TestSize.Level1) auto upms = std::make_unique(); ASSERT_NE(upms, nullptr); MyFlag::flag_ |= MyFlag::IS_SA_CALL; - auto uri = Uri("content://com.example.app1001/data/storage/el2/base/haps/entry/files/test_001.txt"); + std::vector uri = { Uri("content://com.example.app1001/data/storage/el2/base/haps/entry/files/test_1.txt") }; uint32_t flagRead = 1; uint32_t callerTokenId1 = 1001; IPCSkeleton::callerTokenId = callerTokenId1; MyFlag::tokenInfos[callerTokenId1] = TokenInfo(callerTokenId1, MyATokenTypeEnum::TOKEN_NATIVE, "foundation"); TokenIdPermission tokenIdPermission1(callerTokenId1); - auto ret = upms->CheckUriPermission(uri, flagRead, tokenIdPermission1); + auto ret = upms->CheckUriPermission(tokenIdPermission1, uri, flagRead)[0]; ASSERT_EQ(ret, true); uint32_t callerTokenId2 = 1002; IPCSkeleton::callerTokenId = callerTokenId2; MyFlag::tokenInfos[callerTokenId2] = TokenInfo(callerTokenId2, MyATokenTypeEnum::TOKEN_NATIVE, "testProcess"); TokenIdPermission tokenIdPermission2(callerTokenId2); - ret = upms->CheckUriPermission(uri, flagRead, tokenIdPermission2); + ret = upms->CheckUriPermission(tokenIdPermission2, uri, flagRead)[0]; ASSERT_EQ(ret, false); } @@ -1004,6 +924,7 @@ HWTEST_F(UriPermissionImplTest, CheckUriAuthorization_005, TestSize.Level1) const std::vector uris = { uri }; uint32_t flag = 1; uint32_t tokenId = 1001; + MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_HAP, "", "com.example.app1001"); auto res = upms->CheckUriAuthorization(uris, flag, tokenId); std::vector expectRes(1, true); EXPECT_EQ(res, expectRes); diff --git a/tools/aa/BUILD.gn b/tools/aa/BUILD.gn index 7f39b45b16..86df81bbea 100644 --- a/tools/aa/BUILD.gn +++ b/tools/aa/BUILD.gn @@ -66,11 +66,9 @@ ohos_static_library("tools_aa_source_set") { "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", - # "graphic_2d:2d_graphics", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", - # "skia:skia_canvaskit", ] public_external_deps = [ "ability_base:session_info", @@ -102,13 +100,10 @@ ohos_executable("aa") { "ability_base:base", "ability_base:configuration", "ability_base:session_info", - # "ability_base:want", "c_utils:utils", - # "graphic_2d:2d_graphics", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", - # "skia:skia_canvaskit", ] symlink_target_name = [ "ability_tool" ]