Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into master

Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
xinking129
2023-01-16 10:03:44 +00:00
committed by Gitee
77 changed files with 2891 additions and 159 deletions
+18 -1
View File
@@ -243,6 +243,15 @@
},
"name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:data_ability_helper"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/frameworks/js/napi/dialog_request_info/include",
"header_files": [
"request_info.h"
]
},
"name": "//foundation/ability/ability_runtime/frameworks/js/napi/dialog_request_info:dialog_request_info"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/",
@@ -258,8 +267,16 @@
"header_files": [
"quick_fix_manager_client.h"
]
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/quick_fix:quickfix_manager"
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/quick_fix:quickfix_manager"
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/dataobs_manager/",
"header_files": [
]
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/dataobs_manager:dataobs_manager"
}
],
"test": [
+1
View File
@@ -49,6 +49,7 @@ group("napi_packages") {
"${ability_runtime_napi_path}/featureAbility:featureability",
"${ability_runtime_napi_path}/feature_ability:featureability_napi",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_napi_path}/js_dialog_request:dialogrequest_napi",
"${ability_runtime_napi_path}/js_mission_manager:missionmanager",
"${ability_runtime_napi_path}/mission_manager:distributedmissionmanager",
"${ability_runtime_napi_path}/mission_manager:missionmanager_napi",
@@ -41,6 +41,10 @@ class AbilityContext extends Context {
return this.__context_impl__.startAbility(want, options, callback)
}
startRecentAbility(want, options, callback) {
return this.__context_impl__.startRecentAbility(want, options, callback)
}
startAbilityWithAccount(want, accountId, options, callback) {
return this.__context_impl__.startAbilityWithAccount(want, accountId, options, callback)
}
@@ -142,6 +146,10 @@ class AbilityContext extends Context {
setMissionIcon(icon, callback) {
return this.__context_impl__.setMissionIcon(icon, callback)
}
requestDialogService(want, resultCallback) {
return this.__context_impl__.requestDialogService(want, resultCallback)
}
}
export default AbilityContext
@@ -95,6 +95,14 @@ class ApplicationContext {
return this.__context_impl__.unregisterEnvironmentCallback(callbackId, envcallback)
}
on(type, callback) {
return this.__context_impl__.on(type, callback);
}
off(type, callbackId, callback) {
return this.__context_impl__.off(type, callbackId, callback);
}
createBundleContext(bundleName) {
return this.__context_impl__.createBundleContext(bundleName)
}
+43
View File
@@ -0,0 +1,43 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
config("dialog_request_info_external_config") {
include_dirs = [ "include" ]
}
ohos_shared_library("dialog_request_info") {
sources = [ "request_info.cpp" ]
public_configs = [ ":dialog_request_info_external_config" ]
configs = [ "${ability_runtime_services_path}/common:common_config" ]
deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common" ]
external_deps = [
"ability_base:base",
"ability_base:want",
"ability_runtime:abilitykit_native",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"napi:ace_napi",
]
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_REQUEST_INFO_H
#define OHOS_ABILITY_RUNTIME_REQUEST_INFO_H
#include "iremote_object.h"
#include "native_engine/native_engine.h"
namespace OHOS {
namespace AbilityRuntime {
class RequestInfo {
public:
explicit RequestInfo(const sptr<IRemoteObject> &token);
~RequestInfo();
static NativeValue* WrapRequestInfo(NativeEngine &engine, RequestInfo *request);
static std::shared_ptr<RequestInfo> UnwrapRequestInfo(NativeEngine &engine, NativeValue *jsParam);
sptr<IRemoteObject> GetToken();
private:
sptr<IRemoteObject> callerToken_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_REQUEST_INFO_H
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "request_info.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
RequestInfo::RequestInfo(const sptr<IRemoteObject> &token)
{
callerToken_ = token;
}
RequestInfo::~RequestInfo()
{
}
sptr<IRemoteObject> RequestInfo::GetToken()
{
return callerToken_;
}
NativeValue* RequestInfo::WrapRequestInfo(NativeEngine &engine, RequestInfo *request)
{
HILOG_DEBUG("WrapRequestInfo called.");
if (request == nullptr) {
HILOG_ERROR("request is nullptr.");
return nullptr;
}
NativeCallback callback = [](NativeEngine* engine, NativeCallbackInfo* info) -> NativeValue* {
return info->thisVar;
};
NativeValue* requestInfoClass = engine.DefineClass("RequestInfoClass", callback, nullptr, nullptr, 0);
NativeValue* result = engine.CreateInstance(requestInfoClass, nullptr, 0);
if (result == nullptr) {
HILOG_ERROR("create instance failed.");
return nullptr;
}
NativeObject* nativeObject = reinterpret_cast<NativeObject*>(result->GetInterface(NativeObject::INTERFACE_ID));
if (nativeObject == nullptr) {
HILOG_ERROR("get nativeObject failed.");
return nullptr;
}
NativeFinalize nativeFinalize = [](NativeEngine* engine, void* data, void* hint) {
HILOG_INFO("Js RequestInfo finalizer is called");
auto requestInfo = static_cast<RequestInfo*>(data);
if (requestInfo) {
delete requestInfo;
requestInfo = nullptr;
}
};
nativeObject->SetNativePointer(reinterpret_cast<void*>(request), nativeFinalize, nullptr);
return result;
}
std::shared_ptr<RequestInfo> RequestInfo::UnwrapRequestInfo(NativeEngine &engine, NativeValue *jsParam)
{
HILOG_INFO("UnwrapRequestInfo called.");
if (jsParam == nullptr) {
HILOG_ERROR("jsParam is nullptr");
return nullptr;
}
if (jsParam->TypeOf() != NATIVE_OBJECT) {
HILOG_ERROR("UnwrapRequestInfo jsParam type error!");
return nullptr;
}
NativeObject *nativeObject = reinterpret_cast<NativeObject*>(jsParam->GetInterface(NativeObject::INTERFACE_ID));
if (nativeObject == nullptr) {
HILOG_ERROR("UnwrapRequestInfo reinterpret_cast failed!");
return nullptr;
}
HILOG_INFO("UnwrapRequestInfo success.");
RequestInfo *info = static_cast<RequestInfo*>(nativeObject->GetNativePointer());
return std::make_shared<RequestInfo>(*info);
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -45,6 +45,7 @@ ohos_shared_library("napi_common") {
"ability_runtime:napi_base_context",
"ability_runtime:runtime",
"ability_runtime:wantagent_innerkits",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
@@ -16,6 +16,7 @@
#include "napi_common_want.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "napi_common_util.h"
#include "array_wrapper.h"
#include "bool_wrapper.h"
@@ -27,6 +28,7 @@
#include "long_wrapper.h"
#include "short_wrapper.h"
#include "string_wrapper.h"
#include "tokenid_kit.h"
#include "zchar_wrapper.h"
#include "remote_object_wrapper.h"
#include "want_params_wrapper.h"
@@ -910,8 +912,12 @@ void HandleNapiObject(napi_env env, napi_value param, napi_value jsProValue, std
if (IsSpecialObject(env, param, strProName, FD, napi_number)) {
HandleFdObject(env, param, strProName, wantParams);
} else if (IsSpecialObject(env, param, strProName, REMOTE_OBJECT, napi_object)) {
HILOG_WARN("REMOTE_OBJECT is FORIBBED IN WANT.");
// HandleRemoteObject(env, param, strProName, wantParams);
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HandleRemoteObject(env, param, strProName, wantParams);
} else {
HILOG_WARN("not system app, REMOTE_OBJECT is FORIBBED IN WANT.");
}
} else {
bool isArray = false;
if (napi_is_array(env, jsProValue, &isArray) == napi_ok) {
+54
View File
@@ -0,0 +1,54 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
config("dialog_request_external_config") {
include_dirs = [ "include" ]
}
ohos_shared_library("dialogrequest_napi") {
sources = [
"js_dialog_request.cpp",
"js_dialog_request_callback.cpp",
"native_module.cpp",
]
public_configs = [ ":dialog_request_external_config" ]
configs = [ "${ability_runtime_services_path}/common:common_config" ]
deps = [
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:dialog_request_callback",
]
external_deps = [
"ability_base:base",
"ability_base:want",
"ability_runtime:abilitykit_native",
"ability_runtime:dialog_request_info",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
]
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H
#define OHOS_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H
#include "native_engine/native_engine.h"
namespace OHOS {
namespace AbilityRuntime {
NativeValue* JsDialogRequestInit(NativeEngine* engine, NativeValue* exportObj);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_DIALOG_REQUEST_H
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H
#include "idialog_request_callback.h"
#include "native_engine/native_value.h"
namespace OHOS {
namespace AbilityRuntime {
NativeValue* CreateJsDialogRequestCallback(NativeEngine &engine, const sptr<IDialogRequestCallback> &remoteObj);
} // AbilityRuntime
} // OHOS
#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_H
+173
View File
@@ -0,0 +1,173 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "js_dialog_request.h"
#include "hilog_wrapper.h"
#include "js_error_utils.h"
#include "js_dialog_request_callback.h"
#include "js_runtime_utils.h"
#include "napi_common_want.h"
#include "request_constants.h"
#include "request_info.h"
namespace OHOS {
namespace AbilityRuntime {
namespace {
constexpr size_t ARGC_ONE = 1;
constexpr int32_t RESULT_OK = 0;
constexpr int32_t RESULT_CANCEL = 1;
}
NativeValue* ResultCodeInit(NativeEngine* engine)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
if (engine == nullptr) {
HILOG_ERROR("Invalid input parameters");
return nullptr;
}
NativeValue* objValue = engine->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Failed to get object");
return nullptr;
}
object->SetProperty("RESULT_OK", CreateJsValue(*engine, RESULT_OK));
object->SetProperty("RESULT_CANCEL", CreateJsValue(*engine, RESULT_CANCEL));
return objValue;
}
class JsDialogRequest {
public:
JsDialogRequest() = default;
~JsDialogRequest() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
HILOG_INFO("JsDialogRequest::Finalizer is called");
std::unique_ptr<JsDialogRequest>(static_cast<JsDialogRequest*>(data));
}
static NativeValue* GetRequestInfo(NativeEngine* engine, NativeCallbackInfo* info)
{
JsDialogRequest* me = CheckParamsAndGetThis<JsDialogRequest>(engine, info);
return (me != nullptr) ? me->OnGetRequestInfo(*engine, *info) : nullptr;
}
static NativeValue* GetRequestCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsDialogRequest* me = CheckParamsAndGetThis<JsDialogRequest>(engine, info);
return (me != nullptr) ? me->OnGetRequestCallback(*engine, *info) : nullptr;
}
private:
NativeValue* OnGetRequestInfo(NativeEngine &engine, NativeCallbackInfo &info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
if (info.argc < ARGC_ONE) {
HILOG_ERROR("Params not match");
ThrowTooFewParametersError(engine);
return engine.CreateUndefined();
}
OHOS::AAFwk::Want want;
if (!OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
reinterpret_cast<napi_value>(info.argv[0]), want)) {
HILOG_ERROR("The input want is invalid.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
sptr<IRemoteObject> callerToken = want.GetRemoteObject(RequestConstants::REQUEST_TOKEN_KEY);
if (!callerToken) {
HILOG_ERROR("Can not get token from target want.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
auto requestInfo = new RequestInfo(callerToken);
auto jsRequestInfo = RequestInfo::WrapRequestInfo(engine, requestInfo);
if (jsRequestInfo == nullptr) {
HILOG_ERROR("Can not wrap requestinfo from target request.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
return jsRequestInfo;
}
NativeValue* OnGetRequestCallback(NativeEngine &engine, NativeCallbackInfo &info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
if (info.argc < ARGC_ONE) {
HILOG_ERROR("Params is not match");
ThrowTooFewParametersError(engine);
return engine.CreateUndefined();
}
OHOS::AAFwk::Want want;
if (!OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
reinterpret_cast<napi_value>(info.argv[0]), want)) {
HILOG_ERROR("The input want is invalid.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
sptr<IRemoteObject> remoteObj = want.GetRemoteObject(RequestConstants::REQUEST_CALLBACK_KEY);
if (!remoteObj) {
HILOG_ERROR("Can not get callback from target want.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
sptr<IDialogRequestCallback> callback = iface_cast<IDialogRequestCallback>(remoteObj);
if (!callback) {
HILOG_ERROR("Cast to IDialogRequestCallback failed.");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER);
return engine.CreateUndefined();
}
return CreateJsDialogRequestCallback(engine, callback);
}
};
NativeValue* JsDialogRequestInit(NativeEngine* engine, NativeValue* exportObj)
{
HILOG_INFO("JsDialogRequestInit is called");
if (engine == nullptr || exportObj == nullptr) {
HILOG_INFO("Invalid input parameters");
return nullptr;
}
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
HILOG_INFO("object is nullptr");
return nullptr;
}
std::unique_ptr<JsDialogRequest> jsDialogRequest = std::make_unique<JsDialogRequest>();
object->SetNativePointer(jsDialogRequest.release(), JsDialogRequest::Finalizer, nullptr);
object->SetProperty("ResultCode", ResultCodeInit(engine));
const char *moduleName = "JsDialogRequest";
BindNativeFunction(*engine, *object, "getRequestInfo", moduleName, JsDialogRequest::GetRequestInfo);
BindNativeFunction(*engine, *object, "getRequestCallback", moduleName, JsDialogRequest::GetRequestCallback);
return engine->CreateUndefined();
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "js_dialog_request_callback.h"
#include "hilog_wrapper.h"
#include "js_context_utils.h"
#include "js_error_utils.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace AbilityRuntime {
namespace { // nameless
class JsDialogRequestCallback {
public:
explicit JsDialogRequestCallback(const sptr<IDialogRequestCallback> remoteObj) :callback_(remoteObj) {}
virtual ~JsDialogRequestCallback() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
HILOG_DEBUG("JsDialogRequestCallback::Finalizer is called.");
std::unique_ptr<JsDialogRequestCallback>(static_cast<JsDialogRequestCallback*>(data));
}
static NativeValue* SetRequestResult(NativeEngine* engine, NativeCallbackInfo* info)
{
if (engine == nullptr || info == nullptr) {
HILOG_ERROR("input parameters %{public}s is nullptr", ((engine == nullptr) ? "engine" : "info"));
return nullptr;
}
auto object = CheckParamsAndGetThis<JsDialogRequestCallback>(engine, info);
if (object == nullptr) {
HILOG_ERROR("CheckParamsAndGetThis return nullptr");
return nullptr;
}
return object->OnSetRequestResult(*engine, *info);
}
private:
NativeValue* OnSetRequestResult(NativeEngine& engine, NativeCallbackInfo& info)
{
HILOG_INFO("function called");
if (info.argc < 1) {
HILOG_ERROR("Params not match");
ThrowTooFewParametersError(engine);
return engine.CreateUndefined();
}
if (info.argv[0]->TypeOf() != NativeValueType::NATIVE_OBJECT) {
HILOG_ERROR("param type mismatch!");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
NativeObject* paramObject = ConvertNativeValueTo<NativeObject>(info.argv[0]);
NativeValue* resultCode = paramObject->GetProperty("result");
int32_t resultCodeValue = 0;
if (!ConvertFromJsValue(engine, resultCode, resultCodeValue)) {
HILOG_ERROR("Convert result failed!");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
if (callback_ == nullptr) {
HILOG_ERROR("JsDialogRequestCallback::%{public}s, callback_ is nullptr", __func__);
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER);
return engine.CreateUndefined();
}
callback_->SendResult(resultCodeValue);
HILOG_INFO("function called end.");
return engine.CreateUndefined();
}
private:
sptr<IDialogRequestCallback> callback_;
};
} // nameless
NativeValue* CreateJsDialogRequestCallback(NativeEngine &engine, const sptr<IDialogRequestCallback> &remoteObj)
{
HILOG_INFO("CreateJsDialogRequestCallback");
if (!remoteObj) {
HILOG_ERROR("remoteObj is invalid.");
return engine.CreateUndefined();
}
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("object is invalid.");
return engine.CreateUndefined();
}
auto jsDialogRequestCallback = std::make_unique<JsDialogRequestCallback>(remoteObj);
object->SetNativePointer(jsDialogRequestCallback.release(), JsDialogRequestCallback::Finalizer, nullptr);
const char *moduleName = "JsDialogRequestCallback";
BindNativeFunction(engine, *object, "setRequestResult", moduleName, JsDialogRequestCallback::SetRequestResult);
HILOG_INFO("CreateJsDialogRequestCallback end");
return objValue;
}
} // AbilityRuntime
} // OHOS
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "js_dialog_request.h"
#include "native_engine/native_engine.h"
extern "C" __attribute__((constructor))
void NAPI_app_ability_dialogrequest_AutoRegister()
{
auto moduleManager = NativeModuleManager::GetInstance();
NativeModule newModuleInfo = {
.name = "app.ability.dialogRequest",
.fileName = "app/ability/libdialogrequest.so/dialogrequest.js",
.registerCallback = OHOS::AbilityRuntime::JsDialogRequestInit,
};
moduleManager->Register(&newModuleInfo);
}
@@ -35,6 +35,11 @@ class ServiceExtensionContext extends ExtensionContext {
return this.__context_impl__.startAbility(want, options, callback);
}
startRecentAbility(want, options, callback) {
console.log("startRecentAbility");
return this.__context_impl__.startRecentAbility(want, options, callback);
}
connectAbility(want, options) {
console.log("connectAbility");
return this.__context_impl__.connectAbility(want, options);
+2
View File
@@ -41,12 +41,14 @@ ohos_shared_library("ability_context_native") {
"ability_runtime/ability_context_impl.cpp",
"ability_runtime/authorization_result.cpp",
"ability_runtime/connection_manager.cpp",
"ability_runtime/dialog_request_callback_impl.cpp",
"ability_runtime/js_extension_context.cpp",
"ability_runtime/local_call_container.cpp",
"ability_runtime/local_call_record.cpp",
]
deps = [
"${ability_runtime_native_path}/ability/native:dialog_request_callback",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
]
@@ -22,9 +22,11 @@
#include "authorization_result.h"
#include "hitrace_meter.h"
#include "connection_manager.h"
#include "dialog_request_callback_impl.h"
#include "hilog_wrapper.h"
#include "permission_list_state.h"
#include "remote_object_wrapper.h"
#include "request_constants.h"
#include "string_wrapper.h"
#include "want_params_wrapper.h"
@@ -45,6 +47,11 @@ const std::string CALLBACK_KEY = "ohos.ability.params.callback";
std::mutex AbilityContextImpl::mutex_;
std::map<int, PermissionRequestTask> AbilityContextImpl::permissionRequestCallbacks;
struct RequestResult {
int32_t resultCode {0};
RequestDialogResultTask task;
};
Global::Resource::DeviceType AbilityContextImpl::GetDeviceType() const
{
return (stageContext_ != nullptr) ? stageContext_->GetDeviceType() : Global::Resource::DeviceType::DEVICE_PHONE;
@@ -546,6 +553,75 @@ void AbilityContextImpl::RegisterAbilityCallback(std::weak_ptr<AppExecFwk::IAbil
abilityCallback_ = abilityCallback;
}
ErrCode AbilityContextImpl::RequestDialogService(NativeEngine &engine,
AAFwk::Want &want, RequestDialogResultTask &&task)
{
want.SetParam(RequestConstants::REQUEST_TOKEN_KEY, token_);
auto resultTask =
[&engine, outTask = std::move(task)](int32_t resultCode) {
auto retData = new RequestResult();
retData->resultCode = resultCode;
retData->task = std::move(outTask);
auto loop = engine.GetUVLoop();
if (loop == nullptr) {
HILOG_ERROR("RequestDialogService, fail to get uv loop.");
return;
}
auto work = new uv_work_t;
work->data = static_cast<void*>(retData);
int rev = uv_queue_work(
loop,
work,
[](uv_work_t* work) {},
RequestDialogResultJSThreadWorker);
if (rev != 0) {
if (retData != nullptr) {
delete retData;
retData = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
};
sptr<IRemoteObject> remoteObject = new DialogRequestCallbackImpl(std::move(resultTask));
want.SetParam(RequestConstants::REQUEST_CALLBACK_KEY, remoteObject);
auto err = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(
want, token_, -1, AppExecFwk::ExtensionAbilityType::SERVICE);
HILOG_DEBUG("RequestDialogService ret=%{public}d", static_cast<int32_t>(err));
return err;
}
void AbilityContextImpl::RequestDialogResultJSThreadWorker(uv_work_t* work, int status)
{
HILOG_DEBUG("RequestDialogResultJSThreadWorker is called.");
if (work == nullptr) {
HILOG_ERROR("RequestDialogResultJSThreadWorker, uv_queue_work input work is nullptr");
return;
}
RequestResult* retCB = static_cast<RequestResult*>(work->data);
if (retCB == nullptr) {
HILOG_ERROR("RequestDialogResultJSThreadWorker, retCB is nullptr");
delete work;
work = nullptr;
return;
}
if (retCB->task) {
retCB->task(retCB->resultCode);
}
delete retCB;
retCB = nullptr;
delete work;
work = nullptr;
}
#ifdef SUPPORT_GRAPHICS
ErrCode AbilityContextImpl::SetMissionLabel(const std::string& label)
{
@@ -62,10 +62,10 @@ ErrCode ConnectionManager::ConnectAbilityInner(const sptr<IRemoteObject>& connec
connectReceiver.GetBundleName() == obj.first.connectReceiver.GetBundleName() &&
connectReceiver.GetAbilityName() == obj.first.connectReceiver.GetAbilityName();
});
HILOG_DEBUG("abilityConnectionsSize: %{public}zu.", abilityConnections_.size());
if (item != abilityConnections_.end()) {
std::vector<sptr<AbilityConnectCallback>> callbacks = item->second;
std::vector<sptr<AbilityConnectCallback>>& callbacks = item->second;
callbacks.push_back(connectCallback);
abilityConnections_[item->first] = callbacks;
abilityConnection = item->first.abilityConnection;
abilityConnection->AddConnectCallback(connectCallback);
HILOG_INFO("find abilityConnection exist, callbackSize:%{public}zu.", callbacks.size());
@@ -76,9 +76,8 @@ ErrCode ConnectionManager::ConnectAbilityInner(const sptr<IRemoteObject>& connec
} else if (abilityConnection->GetConnectionState() == CONNECTION_STATE_CONNECTING) {
return ERR_OK;
} else {
HILOG_ERROR("AbilityConnection has disconnected");
HILOG_ERROR("AbilityConnection has disconnected, erase it.");
abilityConnections_.erase(item);
HILOG_DEBUG("not find connection, abilityConnectionsSize:%{public}zu.", abilityConnections_.size());
return ERR_INVALID_VALUE;
}
} else {
@@ -90,6 +89,7 @@ ErrCode ConnectionManager::CreateConnection(const sptr<IRemoteObject>& connectCa
const AAFwk::Want& want, int accountId, const sptr<AbilityConnectCallback>& connectCallback,
const AppExecFwk::ElementName& connectReceiver)
{
HILOG_INFO("Can not find connection, CreateConnection");
sptr<AbilityConnection> abilityConnection = new AbilityConnection();
if (abilityConnection == nullptr) {
HILOG_ERROR("create connedction failed.");
@@ -107,7 +107,6 @@ ErrCode ConnectionManager::CreateConnection(const sptr<IRemoteObject>& connectCa
} else {
HILOG_ERROR("Call AbilityManagerService's ConnectAbility error:%{public}d", ret);
}
HILOG_DEBUG("not find connection, abilityConnectionsSize:%{public}zu.", abilityConnections_.size());
return ret;
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dialog_request_callback_impl.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
void DialogRequestCallbackImpl::SendResult(int32_t resultCode)
{
HILOG_INFO("%{public}s called.", __func__);
if (task_) {
HILOG_DEBUG("result code:%{public}d.", resultCode);
task_(resultCode);
}
}
} // namespace AbilityRuntime
} // namespace OHOS
+33
View File
@@ -522,6 +522,39 @@ ohos_shared_library("ability_business_error") {
part_name = "ability_runtime"
}
config("dialog_request_callback_config") {
visibility = [ ":*" ]
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/dialog_request_callback" ]
}
config("dialog_request_callback_public_config") {
visibility = [ ":*" ]
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/dialog_request_callback" ]
}
ohos_shared_library("dialog_request_callback") {
sources = [
"${ability_runtime_native_path}/ability/native/dialog_request_callback/dialog_request_callback_proxy.cpp",
"${ability_runtime_native_path}/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp",
]
configs = [
":dialog_request_callback_config",
"${ability_runtime_services_path}/common:common_config",
]
public_configs = [ ":dialog_request_callback_public_config" ]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_prebuilt_etc("extension_blacklist_config.json") {
source = "etc/extension_blacklist_config.json"
subsystem_name = "ability"
@@ -334,6 +334,7 @@ void Ability::OnActive()
eventInfo.bundleName = abilityInfo_->bundleName;
eventInfo.moduleName = abilityInfo_->moduleName;
eventInfo.abilityName = abilityInfo_->name;
eventInfo.abilityType = static_cast<int32_t>(abilityInfo_->type);
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONACTIVE,
HiSysEventType::BEHAVIOR, eventInfo);
HILOG_DEBUG("%{public}s end.", __func__);
@@ -168,6 +168,12 @@ NativeValue* JsAbilityContext::RestoreWindowStage(NativeEngine* engine, NativeCa
return (me != nullptr) ? me->OnRestoreWindowStage(*engine, *info) : nullptr;
}
NativeValue* JsAbilityContext::RequestDialogService(NativeEngine* engine, NativeCallbackInfo* info)
{
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
return (me != nullptr) ? me->OnRequestDialogService(*engine, *info) : nullptr;
}
NativeValue* JsAbilityContext::IsTerminating(NativeEngine* engine, NativeCallbackInfo* info)
{
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
@@ -757,13 +763,12 @@ NativeValue* JsAbilityContext::OnConnectAbility(NativeEngine& engine, NativeCall
} else {
g_serialNumber = 0;
}
HILOG_INFO("%{public}s not find connection, make new one", __func__);
AsyncTask::CompleteCallback complete =
[weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) {
HILOG_INFO("OnConnectAbility begin");
auto context = weak.lock();
if (!context) {
HILOG_WARN("Connect ability failed, context is released.");
HILOG_ERROR("Connect ability failed, context is released.");
task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
return;
}
@@ -822,14 +827,12 @@ NativeValue* JsAbilityContext::OnConnectAbilityWithAccount(NativeEngine& engine,
} else {
g_serialNumber = 0;
}
HILOG_INFO("%{public}s not find connection, make new one", __func__);
AsyncTask::CompleteCallback complete =
[weak = context_, want, accountId, connection, connectId](
NativeEngine& engine, AsyncTask& task, int32_t status) {
HILOG_INFO("OnConnectAbilityWithAccount begin");
auto context = weak.lock();
if (!context) {
HILOG_WARN("context is released");
HILOG_ERROR("context is released");
task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
return;
}
@@ -1010,6 +1013,51 @@ NativeValue* JsAbilityContext::OnRestoreWindowStage(NativeEngine& engine, Native
return engine.CreateUndefined();
}
NativeValue* JsAbilityContext::OnRequestDialogService(NativeEngine& engine, NativeCallbackInfo& info)
{
HILOG_INFO("OnRequestDialogService is called");
if (info.argc < ARGC_ONE) {
HILOG_ERROR("Not enough params");
ThrowTooFewParametersError(engine);
return engine.CreateUndefined();
}
AAFwk::Want want;
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine), reinterpret_cast<napi_value>(info.argv[0]), want);
HILOG_INFO("requestdialogservice, target:%{public}s.%{public}s.", want.GetBundle().c_str(),
want.GetElement().GetAbilityName().c_str());
NativeValue* lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
NativeValue* result = nullptr;
auto uasyncTask = CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result);
std::shared_ptr<AsyncTask> asyncTask = std::move(uasyncTask);
RequestDialogResultTask task =
[&engine, asyncTask](int32_t resultCode) {
HILOG_INFO("OnRequestDialogService async callback is called");
NativeValue* requestResult = JsAbilityContext::WrapRequestDialogResult(engine, resultCode);
if (requestResult == nullptr) {
HILOG_WARN("wrap requestResult failed");
asyncTask->Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER));
} else {
asyncTask->Resolve(engine, requestResult);
}
HILOG_INFO("OnRequestDialogService async callback is called end");
};
auto context = context_.lock();
if (context == nullptr) {
HILOG_WARN("context is released, can not requestDialogService");
asyncTask->Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
} else {
auto errCode = context->RequestDialogService(engine, want, std::move(task));
if (errCode != ERR_OK) {
asyncTask->Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(errCode)));
}
}
HILOG_INFO("OnRequestDialogService is called end");
return result;
}
NativeValue* JsAbilityContext::OnIsTerminating(NativeEngine& engine, NativeCallbackInfo& info)
{
HILOG_INFO("OnIsTerminating is called");
@@ -1069,6 +1117,19 @@ bool JsAbilityContext::UnWrapAbilityResult(NativeEngine& engine, NativeValue* ar
return JsAbilityContext::UnWrapWant(engine, jWant, want);
}
NativeValue* JsAbilityContext::WrapRequestDialogResult(NativeEngine& engine, int32_t resultCode)
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("result", CreateJsValue(engine, resultCode));
return objValue;
}
NativeValue* JsAbilityContext::WrapAbilityResult(NativeEngine& engine, const int& resultCode, const AAFwk::Want& want)
{
NativeValue* jAbilityResult = engine.CreateObject();
@@ -1189,6 +1250,8 @@ NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptr<Abilit
BindNativeFunction(engine, *object, "isTerminating", moduleName, JsAbilityContext::IsTerminating);
BindNativeFunction(engine, *object, "startRecentAbility", moduleName,
JsAbilityContext::StartRecentAbility);
BindNativeFunction(engine, *object, "requestDialogService", moduleName,
JsAbilityContext::RequestDialogService);
#ifdef SUPPORT_GRAPHICS
BindNativeFunction(engine, *object, "setMissionLabel", moduleName, JsAbilityContext::SetMissionLabel);
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dialog_request_callback_proxy.h"
#include "hilog_wrapper.h"
#include "ipc_types.h"
#include "message_parcel.h"
namespace OHOS {
namespace AbilityRuntime {
void DialogRequestCallbackProxy::SendResult(int32_t resultCode)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
HILOG_INFO("DialogRequestCallbackProxy, send result");
if (!data.WriteInterfaceToken(IDialogRequestCallback::GetDescriptor())) {
HILOG_ERROR("Write interface token failed.");
return;
}
if (!data.WriteInt32(resultCode)) {
HILOG_ERROR("Write resultCode error.");
return;
}
auto remote = Remote();
if (remote) {
auto errCode = remote->SendRequest(IDialogRequestCallback::CODE_SEND_RESULT, data, reply, option);
HILOG_INFO("SendRequest result, error code: %{public}d", errCode);
}
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dialog_request_callback_stub.h"
#include "hilog_wrapper.h"
#include "ipc_types.h"
#include "message_parcel.h"
namespace OHOS {
namespace AbilityRuntime {
DialogRequestCallbackStub::DialogRequestCallbackStub()
{
vecMemberFunc_.resize(IDialogRequestCallback::CODE_MAX);
vecMemberFunc_[CODE_SEND_RESULT] = &DialogRequestCallbackStub::SendResultInner;
}
int DialogRequestCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
std::u16string descriptor = DialogRequestCallbackStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
HILOG_INFO("Local descriptor is not equal to remote");
return ERR_INVALID_STATE;
}
if (code < IDialogRequestCallback::CODE_MAX) {
auto memberFunc = vecMemberFunc_[code];
return (this->*memberFunc)(data, reply);
}
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int DialogRequestCallbackStub::SendResultInner(MessageParcel &data, MessageParcel &reply)
{
auto resultCode = data.ReadInt32();
SendResult(resultCode);
return NO_ERROR;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -461,7 +461,6 @@ private:
NativeValue* OnConnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
{
HILOG_INFO("OnConnectAbility is called");
HILOG_INFO("Connect ability called.");
// Check params count
if (info.argc < ARGC_TWO) {
@@ -480,10 +479,9 @@ private:
int64_t connectId = connection->GetConnectionId();
AsyncTask::CompleteCallback complete =
[weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) {
HILOG_INFO("OnConnectAbility begin");
auto context = weak.lock();
if (!context) {
HILOG_WARN("context is released");
HILOG_ERROR("context is released");
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
return;
}
@@ -524,10 +522,9 @@ private:
AsyncTask::CompleteCallback complete =
[weak = context_, want, accountId, connection, connectId](
NativeEngine& engine, AsyncTask& task, int32_t status) {
HILOG_INFO("OnConnectAbilityWithAccount begin");
auto context = weak.lock();
if (!context) {
HILOG_WARN("context is released");
HILOG_ERROR("context is released");
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
return;
}
@@ -644,7 +644,7 @@ void AbilityDelegator::RemoveAbilityProperty(const std::shared_ptr<ADelegatorAbi
ability->name_.data(), ability->lifecycleState_);
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
abilityProperties_.remove_if([ability](auto &properties) {
abilityProperties_.remove_if([ability](const auto &properties) {
return ability->fullName_ == properties->fullName_;
});
}
@@ -767,7 +767,7 @@ NativeValue *JsApplicationContextUtils::OnOn(NativeEngine &engine, NativeCallbac
return engine.CreateUndefined();
}
if (type == "abilityLifeCycle") {
if (type == "abilityLifecycle") {
return OnOnAbilityLifecycle(engine, info);
}
if (type == "environment") {
@@ -811,7 +811,7 @@ NativeValue *JsApplicationContextUtils::OnOff(NativeEngine &engine, const Native
return engine.CreateUndefined();
}
if (type == "abilityLifeCycle") {
if (type == "abilityLifecycle") {
return OnOffAbilityLifecycle(engine, info, callbackId);
}
if (type == "environment") {
+10 -1
View File
@@ -97,9 +97,18 @@ void IdleTime::RequestVSync()
}
receiver_->Init();
}
std::weak_ptr<IdleTime> weak(shared_from_this());
auto task = [weak](int64_t timestamp, void* data) {
auto idleTime = weak.lock();
if (idleTime == nullptr) {
HILOG_ERROR("idleTime is nullptr.");
return;
}
idleTime->OnVSync(timestamp, data);
};
Rosen::VSyncReceiver::FrameCallback frameCallback = {
.userData_ = this,
.callback_ = [this](int64_t timestamp, void* data) { OnVSync(timestamp, data); },
.callback_ = task,
};
receiver_->RequestNextVSync(frameCallback);
}
+5 -5
View File
@@ -1000,13 +1000,13 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
applicationContext->AttachContextImpl(contextImpl);
applicationContext->InitApplicationContext();
application_->SetApplicationContext(applicationContext);
std::string BundleCodeDir = applicationContext->GetBundleCodeDir();
if (isStageBased) {
// Create runtime
auto hapPath = entryHapModuleInfo.hapPath;
AbilityRuntime::Runtime::Options options;
options.bundleName = appInfo.bundleName;
options.codePath = LOCAL_CODE_PATH;
options.hapPath = entryHapModuleInfo.hapPath;
options.hapPath = hapPath;
options.eventRunner = mainHandler_->GetEventRunner();
options.loadAce = true;
options.isBundle = (entryHapModuleInfo.compileMode != AppExecFwk::CompileMode::ES_MODULE);
@@ -1022,7 +1022,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
auto bundleName = appInfo.bundleName;
auto versionCode = appInfo.versionCode;
wptr<MainThread> weak = this;
auto uncaughtTask = [weak, bundleName, versionCode, BundleCodeDir](NativeValue* v) {
auto uncaughtTask = [weak, bundleName, versionCode, hapPath](NativeValue* v) {
HILOG_INFO("Js uncaught exception callback come.");
auto appThread = weak.promote();
if (appThread == nullptr) {
@@ -1054,7 +1054,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
error = fuc->GetSourceCodeInfo(errorPos);
}
summary += error + "Stacktrace:\n" + OHOS::AbilityRuntime::ModSourceMap::TranslateBySourceMap(errorStack,
bindSourceMaps, BundleCodeDir);
bindSourceMaps, hapPath);
time_t timet;
time(&timet);
HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR",
@@ -1145,7 +1145,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
}
HILOG_DEBUG("MainThread handle launch application, InitResourceManager End.");
contextImpl->SetResourceManager(resourceManager);
AbilityBase::ExtractResourceManager::GetExtractResourceManager().AddGlobalObject(resourceManager);
AbilityBase::ExtractResourceManager::GetExtractResourceManager().SetGlobalObject(resourceManager);
contextDeal->initResourceManager(resourceManager);
contextDeal->SetApplicationContext(application_);
@@ -299,6 +299,7 @@ void MixStackDumper::BuildJsNativeMixStack(int fd, std::vector<JsFrames>& jsFram
nativeIdx++;
}
write(fd, mixStackStr.c_str(), mixStackStr.size());
write(fd, "\n", 1);
}
std::string MixStackDumper::GetThreadStackTraceLabel(pid_t tid)
@@ -321,6 +322,7 @@ void MixStackDumper::PrintNativeFrames(int fd, std::vector<NativeFrame>& nativeF
std::string nativeFrameStr = PrintNativeFrame(frame);
write(fd, nativeFrameStr.c_str(), nativeFrameStr.size());
}
write(fd, "\n", 1);
}
void MixStackDumper::PrintProcessHeader(int fd, pid_t pid, uid_t uid)
+1 -1
View File
@@ -167,7 +167,7 @@ public:
}
}
auto func = [&](std::string modulePath, std::string abcPath) {
auto func = [&](std::string modulePath, const std::string abcPath) {
std::ostringstream outStream;
if (!extractor->GetFileBuffer(modulePath, outStream)) {
HILOG_ERROR("Get abc file failed");
+36 -5
View File
@@ -129,9 +129,13 @@ struct AssetHelper final {
std::string filePath = uri.substr(0, index) + ".abc";
ami = codePath_ + filePath;
HILOG_INFO("Get asset, ami: %{private}s", ami.c_str());
if (!ReadAssetData(filePath, content)) {
HILOG_ERROR("Get asset content failed.");
return;
std::string flag = "el2";
if (ami.find(flag) != std::string::npos) {
if (!ReadAmiData(ami, content)) {
HILOG_ERROR("Get asset content by ami failed.");
}
} else if (!ReadFilePathData(filePath, content)) {
HILOG_ERROR("Get asset content by filepath failed.");
}
}
@@ -154,7 +158,34 @@ struct AssetHelper final {
return iface_cast<BundleMgrProxy>(remoteObject);
}
bool ReadAssetData(const std::string& filePath, std::vector<uint8_t>& content) const
bool ReadAmiData(const std::string& ami, std::vector<uint8_t>& content) const
{
char path[PATH_MAX];
if (realpath(ami.c_str(), path) == nullptr) {
HILOG_ERROR("ReadAmiData realpath(%{private}s) failed, errno = %{public}d", ami.c_str(), errno);
return false;
}
std::ifstream stream(path, std::ios::binary | std::ios::ate);
if (!stream.is_open()) {
HILOG_ERROR("ReadAmiData failed to open file %{private}s", ami.c_str());
return false;
}
auto fileLen = stream.tellg();
if (!isDebugVersion_ && fileLen > ASSET_FILE_MAX_SIZE) {
HILOG_ERROR("ReadAmiData failed, file is too large");
return false;
}
content.resize(fileLen);
stream.seekg(0);
stream.read(reinterpret_cast<char*>(content.data()), content.size());
return true;
}
bool ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content) const
{
bool newCreate = false;
size_t fileLen = 0;
@@ -203,7 +234,7 @@ struct AssetHelper final {
return false;
}
if (!isDebugVersion_ && fileLen > ASSET_FILE_MAX_SIZE) {
HILOG_ERROR("ReadAssetData failed, file is too large");
HILOG_ERROR("ReadFilePathData failed, file is too large");
return false;
}
content.assign(dataPtr.get(), dataPtr.get() + fileLen);
+26 -56
View File
@@ -22,7 +22,12 @@
#include <vector>
#include <unistd.h>
#include "extractor.h"
#include "hilog_wrapper.h"
using namespace OHOS::AbilityBase;
using Extractor = OHOS::AbilityBase::Extractor;
namespace OHOS {
namespace AbilityRuntime {
@@ -37,9 +42,8 @@ constexpr char DELIMITER_SEMICOLON = ';';
constexpr char DOUBLE_SLASH = '\\';
constexpr char WEBPACK[] = "webpack:///";
const std::string REALPATH_FLAG = "/temprary/";
const std::string ABILITYPATH_FLAG = "/entry/ets/";
const std::string MEGER_SOURCE_MAP_PATH = "ets/sourceMaps.map";
const std::string NOT_FOUNDMAP = "Cannot get SourceMap info, dump raw stack:\n";
constexpr int64_t ASSET_FILE_MAX_SIZE = 20 * (1 << 20);
constexpr int32_t INDEX_TWO = 2;
constexpr int32_t INDEX_THREE = 3;
constexpr int32_t INDEX_FOUR = 4;
@@ -48,32 +52,26 @@ constexpr int32_t NUM_TWENTY = 20;
constexpr int32_t NUM_TWENTYSIX = 26;
constexpr int32_t DIGIT_NUM = 64;
bool ModSourceMap::ReadSourceMapData(const std::string& filePath, std::string& content)
bool ModSourceMap::ReadSourceMapData(const std::string& hapPath, std::string& content)
{
char path[PATH_MAX] ;
if (realpath(filePath.c_str(), path) == nullptr) {
HILOG_ERROR("ModSourceMap::ReadSourceMapData realpath(%{public}s) failed, errno = %{public}d",
filePath.c_str(), errno);
if (hapPath.empty()) {
HILOG_ERROR("hapPath is empty");
return false;
}
std::ifstream stream(path, std::ios::binary | std::ios::ate);
if (!stream.is_open()) {
HILOG_ERROR("ModSourceMap::ReadSourceMapData failed to open file %{public}s", path);
bool newCreate = false;
std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(
ExtractorUtil::GetLoadFilePath(hapPath), newCreate);
if (extractor == nullptr) {
HILOG_ERROR("hapPath %{public}s GetExtractor failed", hapPath.c_str());
return false;
}
int64_t fileLen = stream.tellg();
if (fileLen > ASSET_FILE_MAX_SIZE) {
std::unique_ptr<uint8_t[]> dataPtr = nullptr;
size_t len = 0;
if (!extractor->ExtractToBufByName(MEGER_SOURCE_MAP_PATH, dataPtr, len)) {
HILOG_ERROR("get mergeSourceMapData fileBuffer failed");
return false;
}
char buffer[fileLen];
buffer[fileLen - 1] = '\0';
stream.seekg(0);
stream.read(buffer, fileLen);
content = buffer;
content = reinterpret_cast<char *>(dataPtr.get());
return true;
}
@@ -355,36 +353,8 @@ bool ModSourceMap::VlqRevCode(const std::string& vStr, std::vector<int32_t>& ans
return true;
};
bool ModSourceMap::GetSourceMapData(ModSourceMap& bindSourceMaps, const std::string& temp, SourceMapData& curMapData)
{
// get the file path of the .map file
int32_t startPos = static_cast<int32_t>(temp.find(REALPATH_FLAG));
if (startPos == -1) {
HILOG_ERROR("ModSourceMap::TranslateBySourceMap Get /temprary/ pos error.");
return false;
}
int32_t endPos = static_cast<int32_t>(temp.size() - 1);
std::string mapFilePath = bindSourceMaps.bundleCodeDir_ + ABILITYPATH_FLAG +
temp.substr(startPos + REALPATH_FLAG.size(), endPos - startPos) + ".map";
// parse file and cache
auto iter = bindSourceMaps.sourceMaps_.find(mapFilePath);
if (iter == bindSourceMaps.sourceMaps_.end()) {
std::string curSourceMap;
if (!ReadSourceMapData(mapFilePath, curSourceMap)) {
return false;
}
Init(curSourceMap, curMapData);
bindSourceMaps.sourceMaps_.insert(std::pair<std::string, SourceMapData>(mapFilePath, curMapData));
} else {
curMapData = iter->second;
}
return true;
}
std::string ModSourceMap::TranslateBySourceMap(const std::string& stackStr, ModSourceMap& bindSourceMaps,
const std::string& BundleCodeDir)
const std::string& hapPath)
{
const std::string closeBrace = ")";
const std::string openBrace = "(";
@@ -418,11 +388,10 @@ std::string ModSourceMap::TranslateBySourceMap(const std::string& stackStr, ModS
sourceCode = fristLine.substr(codeStartLen, fristLine.length() - codeStartLen - 1);
i = 1; // 1 means Convert from the second line
needGetErrorPos = true;
}
}
}
std::string curSourceMap;
std::string filePath = BundleCodeDir + ABILITYPATH_FLAG + "sourceMaps.map";
if (!ReadSourceMapData(filePath, curSourceMap)) {
if (!ReadSourceMapData(hapPath, curSourceMap)) {
HILOG_ERROR("ReadSourceMapData fail");
return stackStr;
}
@@ -570,11 +539,12 @@ std::string ModSourceMap::GetOriginalNames(std::shared_ptr<SourceMapData> target
ErrorPos ModSourceMap::GetErrorPos(const std::string& rawStack)
{
uint32_t lineEnd = rawStack.find("\n") - 1;
if (lineEnd < 1) {
size_t findLineEnd = rawStack.find("\n");
if (findLineEnd == std::string::npos) {
return std::make_pair(0, 0);
}
if (rawStack[lineEnd - 1] == '?') {
uint32_t lineEnd = findLineEnd - 1;
if (lineEnd < 1 || rawStack[lineEnd - 1] == '?') {
return std::make_pair(0, 0);
}
+3 -2
View File
@@ -139,6 +139,7 @@ ABILITY_ONACTIVE:
BUNDLE_NAME: {type: STRING, desc: bundle name}
MODULE_NAME: {type: STRING, desc: module name}
ABILITY_NAME: {type: STRING, desc: ability name}
ABILITY_TYPE: {type: INT32, desc: ability type}
ABILITY_ONINACTIVE:
__BASE: {type: BEHAVIOR, level: MINOR, desc: ability onInactive}
@@ -154,7 +155,7 @@ START_SERVICE:
BUNDLE_NAME: {type: STRING, desc: bundle name}
MODULE_NAME: {type: STRING, desc: module name}
ABILITY_NAME: {type: STRING, desc: ability name}
EXTENSION_TYPE: {type: STRING, desc: extension type}
EXTENSION_TYPE: {type: INT32, desc: extension type}
STOP_SERVICE:
__BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: stop serviceExtensionAbility}
@@ -162,7 +163,7 @@ STOP_SERVICE:
BUNDLE_NAME: {type: STRING, desc: bundle name}
MODULE_NAME: {type: STRING, desc: module name}
ABILITY_NAME: {type: STRING, desc: ability name}
EXTENSION_TYPE: {type: STRING, desc: extension type}
EXTENSION_TYPE: {type: INT32, desc: extension type}
CONNECT_SERVICE:
__BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: connect serviceAbility}
@@ -79,6 +79,8 @@ public:
virtual void OnAppStateChanged(const AppStateData &appStateData) override;
virtual void OnProcessReused(const ProcessData &processData) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
static inline BrokerDelegator<ApplicationStateObserverProxy> delegator_;
@@ -86,6 +86,8 @@ public:
virtual void OnAppStateChanged(const AppStateData &appStateData) override;
virtual void OnProcessReused(const ProcessData &processData) override;
private:
int32_t HandleOnForegroundApplicationChanged(MessageParcel &data, MessageParcel &reply);
@@ -103,6 +105,8 @@ private:
int32_t HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply);
int32_t HandleOnProcessReused(MessageParcel &data, MessageParcel &reply);
using ApplicationStateObserverFunc = int32_t (ApplicationStateObserverStub::*)(MessageParcel &data,
MessageParcel &reply);
std::map<uint32_t, ApplicationStateObserverFunc> memberFuncMap_;
@@ -79,6 +79,8 @@ public:
virtual void OnAppStateChanged(const AppStateData &appStateData) {}
virtual void OnProcessReused(const ProcessData &processData) {}
enum class Message {
TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED = 0,
TRANSACT_ON_ABILITY_STATE_CHANGED,
@@ -88,6 +90,7 @@ public:
TRANSACT_ON_PROCESS_DIED,
TRANSACT_ON_APPLICATION_STATE_CHANGED,
TRANSACT_ON_APP_STATE_CHANGED,
TRANSACT_ON_PROCESS_REUSED,
};
};
} // namespace AppExecFwk
@@ -122,6 +122,27 @@ void ApplicationStateObserverProxy::OnProcessCreated(const ProcessData &processD
}
}
void ApplicationStateObserverProxy::OnProcessReused(const ProcessData &processData) {
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
return;
}
data.WriteParcelable(&processData);
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HILOG_ERROR("Remote() is NULL");
return;
}
int32_t ret = remote->SendRequest(
static_cast<uint32_t>(IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_REUSED),
data, reply, option);
if (ret != NO_ERROR) {
HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
}
}
void ApplicationStateObserverProxy::OnProcessStateChanged(const ProcessData &processData)
{
MessageParcel data;
@@ -49,6 +49,10 @@ ApplicationStateObserverStub::ApplicationStateObserverStub()
memberFuncMap_[static_cast<uint32_t>(
IApplicationStateObserver::Message::TRANSACT_ON_APP_STATE_CHANGED)] =
&ApplicationStateObserverStub::HandleOnAppStateChanged;
memberFuncMap_[static_cast<uint32_t>(
IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_REUSED)] =
&ApplicationStateObserverStub::HandleOnProcessReused;
}
ApplicationStateObserverStub::~ApplicationStateObserverStub()
@@ -102,6 +106,9 @@ void ApplicationStateObserverStub::OnApplicationStateChanged(const AppStateData
void ApplicationStateObserverStub::OnAppStateChanged(const AppStateData &appStateData)
{}
void ApplicationStateObserverStub::OnProcessReused(const ProcessData &processData)
{}
int32_t ApplicationStateObserverStub::HandleOnForegroundApplicationChanged(MessageParcel &data, MessageParcel &reply)
{
std::unique_ptr<AppStateData> processData(data.ReadParcelable<AppStateData>());
@@ -222,6 +229,18 @@ void ApplicationStateObserverRecipient::OnRemoteDied(const wptr<IRemoteObject> &
}
}
int32_t ApplicationStateObserverStub::HandleOnProcessReused(MessageParcel &data, MessageParcel &reply)
{
std::unique_ptr<ProcessData> processData(data.ReadParcelable<ProcessData>());
if (!processData) {
HILOG_ERROR("ReadParcelable<ProcessData> failed");
return ERR_APPEXECFWK_PARCEL_ERROR;
}
OnProcessReused(*processData);
return NO_ERROR;
}
ApplicationStateObserverRecipient::ApplicationStateObserverRecipient(RemoteDiedHandler handler) : handler_(handler)
{}
@@ -72,7 +72,7 @@ public:
~ModSourceMap() = default;
static std::string TranslateBySourceMap(const std::string& stackStr, ModSourceMap& targetMaps,
const std::string& BundleCodeDir);
const std::string& hapPath);
static std::string GetOriginalNames(std::shared_ptr<SourceMapData> targetMapData,
const std::string& sourceCode, uint32_t& errorPos);
static ErrorPos GetErrorPos(const std::string& rawStack);
@@ -82,7 +82,6 @@ public:
private:
static void Init(const std::string& sourceMap, SourceMapData& curMap);
static bool GetSourceMapData(ModSourceMap& bindSourceMaps, const std::string& temp, SourceMapData& curMapData);
static MappingInfo Find(int32_t row, int32_t col, const SourceMapData& targetMap, const std::string& key);
static void ExtractKeyInfo(const std::string& sourceMap, std::vector<std::string>& sourceKeyInfo);
static void GetPosInfo(const std::string& temp, int32_t start, std::string& line, std::string& column);
@@ -90,7 +89,7 @@ private:
static std::string GetRelativePath(const std::string& sources);
static std::string GetSourceInfo(const std::string& line, const std::string& column,
const SourceMapData& targetMap, const std::string& key);
static bool ReadSourceMapData(const std::string& filePath, std::string& content);
static bool ReadSourceMapData(const std::string& hapPath, std::string& content);
static std::vector<std::string> HandleMappings(const std::string& mapping);
static uint32_t Base64CharToInt(char charCode);
static bool VlqRevCode(const std::string& vStr, std::vector<int32_t>& ans);
@@ -36,6 +36,7 @@ namespace OHOS {
namespace AbilityRuntime {
using RuntimeTask = std::function<void(int, const AAFwk::Want&)>;
using PermissionRequestTask = std::function<void(const std::vector<std::string>&, const std::vector<int>&)>;
using RequestDialogResultTask = std::function<void(int32_t resultCode)>;
class LocalCallContainer;
class AbilityContext : public Context {
public:
@@ -221,6 +222,18 @@ public:
virtual void RegisterAbilityCallback(std::weak_ptr<AppExecFwk::IAbilityCallback> abilityCallback) = 0;
/**
* @brief Requests dialogService from the system.
* This method is called for dialog request. This is an asynchronous method. When it is executed,
* the task will be called back.
*
* @param engine js native engine.
* @param want Indicates the dialog service to be requested.
* @param task The callback or promise fo js interface.
* @return Returns ERR_OK if success.
*/
virtual ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) = 0;
#ifdef SUPPORT_GRAPHICS
/**
* @brief Set mission label of this ability.
@@ -168,6 +168,8 @@ public:
isTerminating_ = state;
}
ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) override;
#ifdef SUPPORT_GRAPHICS
/**
* @brief Set mission label of this ability.
@@ -207,6 +209,7 @@ private:
bool isTerminating_ = false;
static void ResultCallbackJSThreadWorker(uv_work_t* work, int status);
static void RequestDialogResultJSThreadWorker(uv_work_t* work, int status);
void StartGrantExtension(NativeEngine& engine, const std::vector<std::string>& permissions,
const std::vector<int>& permissionsState, int requestCode, PermissionRequestTask &&task);
@@ -57,7 +57,7 @@ struct ConnectionInfo {
if (connectCaller == that.connectCaller &&
connectReceiver.GetBundleName() == that.connectReceiver.GetBundleName() &&
connectReceiver.GetModuleName() == that.connectReceiver.GetModuleName() &&
connectReceiver.GetAbilityName() == that.connectReceiver.GetAbilityName()) {
connectReceiver.GetAbilityName() < that.connectReceiver.GetAbilityName()) {
return true;
}
return false;
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_IMPL_H
#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_IMPL_H
#include "ability_context.h"
#include "dialog_request_callback_stub.h"
namespace OHOS {
namespace AbilityRuntime {
class DialogRequestCallbackImpl : public DialogRequestCallbackStub {
public:
explicit DialogRequestCallbackImpl(RequestDialogResultTask &&task) : task_(task) {}
virtual ~DialogRequestCallbackImpl() = default;
void SendResult(int32_t resultCode) override;
private:
RequestDialogResultTask task_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_AUTHORIZATION_RESULT_H
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_REQUEST_CONSTANTS_H
#define OHOS_ABILITY_RUNTIME_REQUEST_CONSTANTS_H
namespace OHOS {
namespace AbilityRuntime {
namespace RequestConstants {
constexpr const char* REQUEST_TOKEN_KEY = "ohos.ability.params.request.token";
constexpr const char* REQUEST_CALLBACK_KEY = "ohos.ability.params.request.callback";
} // namespace RequestConstants
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_REQUEST_CONSTANTS_H
@@ -55,6 +55,7 @@ public:
static NativeValue* TerminateSelfWithResult(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* RequestPermissionsFromUser(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* RestoreWindowStage(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* RequestDialogService(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* IsTerminating(NativeEngine* engine, NativeCallbackInfo* info);
static void ConfigurationUpdated(NativeEngine* engine, std::shared_ptr<NativeReference> &jsContext,
@@ -92,6 +93,7 @@ private:
NativeValue* OnTerminateSelf(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnRequestPermissionsFromUser(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnRestoreWindowStage(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnRequestDialogService(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnIsTerminating(NativeEngine& engine, NativeCallbackInfo& info);
static bool UnWrapWant(NativeEngine& engine, NativeValue* argv, AAFwk::Want& want);
@@ -101,6 +103,7 @@ private:
static NativeValue* WrapPermissionRequestResult(NativeEngine& engine,
const std::vector<std::string> &permissions, const std::vector<int> &grantResults);
void InheritWindowMode(AAFwk::Want &want);
static NativeValue* WrapRequestDialogResult(NativeEngine& engine, int32_t resultCode);
std::weak_ptr<AbilityContext> context_;
int curRequestCode_ = 0;
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H
#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H
#include <string>
#include "idialog_request_callback.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace AbilityRuntime {
/**
* proxy of dialog request callback.
*/
class DialogRequestCallbackProxy : public IRemoteProxy<IDialogRequestCallback> {
public:
explicit DialogRequestCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDialogRequestCallback>(impl)
{}
/**
* @brief Send dialogRequest result.
*
* @param resultCode result code.
*/
virtual void SendResult(int32_t resultCode) override;
private:
static inline BrokerDelegator<DialogRequestCallbackProxy> delegator_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_PROXY_H
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H
#define OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H
#include <vector>
#include "idialog_request_callback.h"
#include "iremote_object.h"
#include "iremote_stub.h"
#include "nocopyable.h"
namespace OHOS {
namespace AbilityRuntime {
/**
* @class DialogRequestCallbackStub
* DialogRequestCallback Stub.
*/
class DialogRequestCallbackStub : public IRemoteStub<IDialogRequestCallback> {
public:
DialogRequestCallbackStub();
virtual ~DialogRequestCallbackStub() = default;
virtual int OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
DISALLOW_COPY_AND_MOVE(DialogRequestCallbackStub);
int SendResultInner(MessageParcel &data, MessageParcel &reply);
using StubFunc = int (DialogRequestCallbackStub::*)(MessageParcel &data, MessageParcel &reply);
std::vector<StubFunc> vecMemberFunc_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_DIALOG_REQUEST_CALLBACK_STUB_H
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H
#include "iremote_broker.h"
namespace OHOS {
namespace AbilityRuntime {
/**
* @class IMissionListener
* IMissionListener is used to notify caller ability that connect or disconnect is complete.
*/
class IDialogRequestCallback : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ability.dialogrequestcallback");
/**
* @brief Send dialogRequest result.
*
* @param resultCode result code.
*/
virtual void SendResult(int32_t resultCode) = 0;
enum DialogRequestCallbackCmd {
// ipc id for SendResult
CODE_SEND_RESULT = 1,
// maximum of enum
CODE_MAX
};
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_IDIALOG_REQUEST_CALLBACK_H
@@ -40,20 +40,20 @@ public:
/**
* @brief ExtensionConfigMgr initialization
*
*
*/
void Init();
/**
* @brief Update bundle extension information
*
*
* @param engine JS NativeEngine
*/
void UpdateBundleExtensionInfo(NativeEngine &engine, AppExecFwk::BundleInfo &bundleInfo);
/**
* @brief Add extension blacklist item
*
*
* @param name Extension name
* @param type Extension type
*/
@@ -61,7 +61,7 @@ public:
/**
* @brief Update extension blacklist to native engine
*
*
* @param engine JS NativeEngine
*/
void UpdateBlackListToEngine(NativeEngine &engine);
@@ -152,7 +152,8 @@ public:
int32_t requestCode, const int32_t callerUid);
int32_t DeviceIdDetermine(
const Want &want, const sptr<IRemoteObject> &callerToken, int32_t requestCode, const int32_t callerUid);
int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid);
int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid,
int32_t callerTokenId);
void ClearPendingWantRecord(const std::string &bundleName, int32_t uid);
void Dump(std::vector<std::string> &info);
@@ -34,7 +34,7 @@ public:
PendingWantRecord();
PendingWantRecord(const std::shared_ptr<PendingWantManager> &pendingWantManager, int32_t uid,
const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key);
int32_t callerTokenId, const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key);
virtual ~PendingWantRecord();
virtual void Send(SenderInfo &senderInfo);
@@ -55,6 +55,7 @@ private:
std::weak_ptr<PendingWantManager> pendingWantManager_ = {};
int32_t uid_ = 0;
int32_t callerUid_ = 0;
int32_t callerTokenId_ = 0;
sptr<IRemoteObject> callerToken_ = {};
bool canceled_ = false;
std::shared_ptr<PendingWantKey> key_ = {};
@@ -1730,6 +1730,13 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u
AbilityRequest abilityRequest;
ErrCode result = GenerateAbilityRequest(want, DEFAULT_INVAL_VALUE, abilityRequest, callerToken, userId);
Want requestWant = want;
requestWant.SetParam("abilityConnectionObj", connect->AsObject());
if (!IsComponentInterceptionStart(requestWant, callerToken, 0, result, abilityRequest)) {
return ERR_OK;
}
if (result != ERR_OK) {
HILOG_ERROR("Generate ability request error.");
return result;
@@ -295,8 +295,6 @@ bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName,
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto it = std::find_if(missionInfoList_.begin(), missionInfoList_.end(),
[&missionName, &flag, &isFindRecentStandard](const InnerMissionInfo item) {
@@ -109,7 +109,8 @@ sptr<IWantSender> PendingWantManager::GetWantSenderLocked(const int32_t callingU
}
sptr<PendingWantRecord> rec =
new (std::nothrow) PendingWantRecord(shared_from_this(), uid, callerToken, pendingKey);
new (std::nothrow) PendingWantRecord(shared_from_this(), uid, IPCSkeleton::GetCallingTokenID(),
callerToken, pendingKey);
if (rec != nullptr) {
rec->SetCallerUid(callingUid);
pendingKey->SetCode(PendingRecordIdCreate());
@@ -274,7 +275,7 @@ int32_t PendingWantManager::PendingWantStartAbilitys(const std::vector<WantsInfo
}
int32_t PendingWantManager::PendingWantPublishCommonEvent(
const Want &want, const SenderInfo &senderInfo, int32_t callerUid)
const Want &want, const SenderInfo &senderInfo, int32_t callerUid, int32_t callerTokenId)
{
HILOG_INFO("%{public}s:begin.", __func__);
@@ -297,8 +298,8 @@ int32_t PendingWantManager::PendingWantPublishCommonEvent(
WantParams wantParams = {};
pendingWantCommonEvent->SetWantParams(wantParams);
}
bool result = DelayedSingleton<EventFwk::CommonEvent>::GetInstance()->PublishCommonEvent(
eventData, eventPublishData, pendingWantCommonEvent, callerUid);
bool result = IN_PROCESS_CALL(DelayedSingleton<EventFwk::CommonEvent>::GetInstance()->PublishCommonEvent(
eventData, eventPublishData, pendingWantCommonEvent, callerUid, callerTokenId));
return ((result == true) ? ERR_OK : (-1));
}
@@ -25,8 +25,9 @@ PendingWantRecord::PendingWantRecord()
{}
PendingWantRecord::PendingWantRecord(const std::shared_ptr<PendingWantManager> &pendingWantManager, int32_t uid,
const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key)
: pendingWantManager_(pendingWantManager), uid_(uid), callerToken_(callerToken), key_(key)
int32_t callerTokenId, const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key)
: pendingWantManager_(pendingWantManager), uid_(uid), callerTokenId_(callerTokenId),
callerToken_(callerToken), key_(key)
{}
PendingWantRecord::~PendingWantRecord()
@@ -103,7 +104,7 @@ int32_t PendingWantRecord::SenderInner(SenderInfo &senderInfo)
res = pendingWantManager->PendingWantStartAbility(want, callerToken_, -1, callerUid_);
break;
case static_cast<int32_t>(OperationType::SEND_COMMON_EVENT):
res = pendingWantManager->PendingWantPublishCommonEvent(want, senderInfo, callerUid_);
res = pendingWantManager->PendingWantPublishCommonEvent(want, senderInfo, callerUid_, callerTokenId_);
(res == ERR_OK) ? (sendFinish = false) : (sendFinish = (senderInfo.finishedReceiver != nullptr));
break;
default:
@@ -540,6 +540,8 @@ public:
void ClearAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord, bool containsApp);
void TerminateApplication(const std::shared_ptr<AppRunningRecord> &appRecord);
int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug);
/**
* Notify application status.
+1 -1
View File
@@ -545,7 +545,7 @@ public:
int64_t GetAppStartTime() const;
void SetRestartTimeMillis(const int64_t restartTimeMills);
void SetRestartTimeMillis(const int64_t restartTimeMillis);
void SetRequestProcCode(int32_t requestProcCode);
int32_t GetRequestProcCode() const;
@@ -47,6 +47,7 @@ public:
void OnRenderProcessCreated(const std::shared_ptr<RenderRecord> &RenderRecord);
void OnProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord);
void OnRenderProcessDied(const std::shared_ptr<RenderRecord> &renderRecord);
void OnProcessReused(const std::shared_ptr<AppRunningRecord> &appRecord);
private:
void HandleAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state,
bool needNotifyApp);
@@ -66,6 +67,7 @@ private:
void HandleOnProcessCreated(const ProcessData &data);
void HandleOnProcessStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord);
void HandleOnProcessDied(const ProcessData &data);
void HandleOnProcessResued(const std::shared_ptr<AppRunningRecord> &appRecord);
private:
std::shared_ptr<AppExecFwk::EventHandler> handler_;
@@ -136,7 +136,8 @@ public:
*
* @return
*/
void TerminateAbility(const sptr<IRemoteObject> &token, const bool isForce);
void TerminateAbility(const std::shared_ptr<AppRunningRecord> &appRecord,
const sptr<IRemoteObject> &token, const bool isForce);
/**
* AbilityTerminated, terminate the ability.
@@ -173,8 +174,6 @@ public:
void SetApplicationClient(std::shared_ptr<AppLifeCycleDeal> &appLifeCycleDeal);
void SetAppRunningRecord(const std::shared_ptr<AppRunningRecord> &appRunningRecord);
const std::shared_ptr<ApplicationInfo> GetAppInfo();
bool RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const;
@@ -30,7 +30,7 @@ public:
: callback_(callback)
{}
virtual ~QuickFixCallbackWithRecord();
~QuickFixCallbackWithRecord() override;
void OnLoadPatchDone(int32_t resultCode, int32_t recordId) override;
void OnUnloadPatchDone(int32_t resultCode, int32_t recordId) override;
+14 -1
View File
@@ -181,7 +181,11 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord,
appInfo->uid, appInfo->bundleName, bundleIndex);
} else {
appRecord->SetRequestProcCode((want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0));
int32_t requestProcCode = (want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0);
if (requestProcCode != 0 && appRecord->GetRequestProcCode() == 0) {
appRecord->SetRequestProcCode(requestProcCode);
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessReused(appRecord);
}
StartAbility(token, preToken, abilityInfo, appRecord, hapModuleInfo, want);
}
PerfProfile::GetInstance().SetAbilityLoadEndTime(GetTickCount());
@@ -742,6 +746,10 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf
}
auto callerPid = IPCSkeleton::GetCallingPid();
auto appRecord = GetAppRunningRecordByPid(callerPid);
if (!appRecord) {
HILOG_ERROR("no such appRecord, callerPid:%{public}d", callerPid);
return ERR_INVALID_VALUE;
}
GetRunningProcess(appRecord, info);
return ERR_OK;
}
@@ -1687,6 +1695,11 @@ void AppMgrServiceInner::HandleTerminateApplicationTimeOut(const int64_t eventId
return;
}
auto appRecord = appRunningManager_->GetAppRunningRecord(eventId);
TerminateApplication(appRecord);
}
void AppMgrServiceInner::TerminateApplication(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (!appRecord) {
HILOG_ERROR("appRecord is nullptr");
return;
+1 -1
View File
@@ -903,7 +903,7 @@ void AppRunningRecord::TerminateAbility(const sptr<IRemoteObject> &token, const
auto abilityRecord = GetAbilityRunningRecordByToken(token);
StateChangedNotifyObserver(abilityRecord, static_cast<int32_t>(AbilityState::ABILITY_STATE_TERMINATED), true);
moduleRecord->TerminateAbility(token, isForce);
moduleRecord->TerminateAbility(shared_from_this(), token, isForce);
}
void AppRunningRecord::AbilityTerminated(const sptr<IRemoteObject> &token)
@@ -188,6 +188,25 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptr<AppRunningR
handler_->PostTask(task);
}
void AppStateObserverManager::OnProcessReused(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnProcessReused failed.");
return;
}
auto task = [weak = weak_from_this(), appRecord]() {
auto self = weak.lock();
if (self == nullptr) {
HILOG_ERROR("self is nullptr, OnProcessReused failed.");
return;
}
HILOG_INFO("OnProcessReused come.");
self->HandleOnProcessResued(appRecord);
};
handler_->PostTask(task);
}
void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr<RenderRecord> &renderRecord)
{
if (handler_ == nullptr) {
@@ -299,6 +318,26 @@ void AppStateObserverManager::HandleOnAppProcessCreated(const std::shared_ptr<Ap
HandleOnProcessCreated(data);
}
void AppStateObserverManager::HandleOnProcessResued(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (!appRecord) {
HILOG_ERROR("app record is null");
return;
}
ProcessData data = WrapProcessData(appRecord);
HILOG_DEBUG("Process Resued, bundle:%{public}s, pid:%{public}d, uid:%{public}d",
data.bundleName.c_str(), data.pid, data.uid);
std::lock_guard<std::recursive_mutex> lockNotify(observerLock_);
for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) {
std::vector<std::string>::iterator iter = std::find(it->second.begin(),
it->second.end(), data.bundleName);
if ((it->second.empty() || iter != it->second.end()) && it->first != nullptr) {
it->first->OnProcessReused(data);
}
}
}
void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr<RenderRecord> &renderRecord)
{
if (!renderRecord) {
@@ -236,7 +236,8 @@ void ModuleRunningRecord::LaunchPendingAbilities()
}
}
void ModuleRunningRecord::TerminateAbility(const sptr<IRemoteObject> &token, const bool isForce)
void ModuleRunningRecord::TerminateAbility(const std::shared_ptr<AppRunningRecord> &appRecord,
const sptr<IRemoteObject> &token, const bool isForce)
{
HILOG_INFO("Terminate ability.");
auto abilityRecord = GetAbilityRunningRecordByToken(token);
@@ -265,9 +266,8 @@ void ModuleRunningRecord::TerminateAbility(const sptr<IRemoteObject> &token, con
} else {
HILOG_WARN("appLifeCycleDeal_ is null");
auto serviceInner = appMgrServiceInner_.lock();
auto appRunningRecord = appRunningRecord_.lock();
if (serviceInner) {
serviceInner->ClearAppRunningData(appRunningRecord, true);
serviceInner->TerminateApplication(appRecord);
}
}
@@ -345,10 +345,5 @@ ModuleRecordState ModuleRunningRecord::GetState() const
{
return owenState_;
}
void ModuleRunningRecord::SetAppRunningRecord(const std::shared_ptr<AppRunningRecord> &appRunningRecord)
{
appRunningRecord_ = appRunningRecord;
}
} // namespace AppExecFwk
} // namespace OHOS
+1
View File
@@ -38,6 +38,7 @@ struct EventInfo {
std::string moduleName;
std::string abilityName;
std::string processName;
int32_t abilityType = -1;
};
enum class EventName {
+11 -1
View File
@@ -30,6 +30,7 @@ const std::string EVENT_KEY_ERROR_CODE = "ERROR_CODE";
const std::string EVENT_KEY_BUNDLE_NAME = "BUNDLE_NAME";
const std::string EVENT_KEY_MODULE_NAME = "MODULE_NAME";
const std::string EVENT_KEY_ABILITY_NAME = "ABILITY_NAME";
const std::string EVENT_KEY_ABILITY_TYPE = "ABILITY_TYPE";
const std::string EVENT_KEY_VERSION_NAME = "VERSION_NAME";
const std::string EVENT_KEY_VERSION_CODE = "VERSION_CODE";
const std::string EVENT_KEY_PROCESS_NAME = "PROCESS_NAME";
@@ -132,7 +133,6 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty
break;
case EventName::ABILITY_ONFOREGROUND:
case EventName::ABILITY_ONBACKGROUND:
case EventName::ABILITY_ONACTIVE:
case EventName::ABILITY_ONINACTIVE:
HiSysEventWrite(
HiSysEvent::Domain::AAFWK,
@@ -142,6 +142,16 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName);
break;
case EventName::ABILITY_ONACTIVE:
HiSysEventWrite(
HiSysEvent::Domain::AAFWK,
name,
type,
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName,
EVENT_KEY_ABILITY_TYPE, eventInfo.abilityType);
break;
default:
break;
}
@@ -70,8 +70,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
moduleRecord.SetModuleRecordState(moduleState);
std::shared_ptr<AppLifeCycleDeal> appLifeCycleDeal;
moduleRecord.SetApplicationClient(appLifeCycleDeal);
std::shared_ptr<AppRunningRecord> appRunningRecord;
moduleRecord.SetAppRunningRecord(appRunningRecord);
sptr<IRemoteObject> token = GetFuzzAbilityToken();
moduleRecord.GetAbilityRunningRecordByToken(token);
std::shared_ptr<AbilityInfo> abilityInfo;
@@ -89,7 +87,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY;
moduleRecord.OnAbilityStateChanged(record, state);
bool isForce = *data % ENABLE;
moduleRecord.TerminateAbility(token, isForce);
std::shared_ptr<AppRunningRecord> appRunningRecord;
moduleRecord.TerminateAbility(appRunningRecord, token, isForce);
moduleRecord.AbilityTerminated(token);
moduleRecord.GetAbilityByTerminateLists(token);
uint32_t msg = GetU32Data(data);
@@ -129,7 +129,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
pendingWantManager->DeviceIdDetermine(*want, token, int32Param, int32Param);
pendingWantManager->PendingWantStartAbility(*want, token, int32Param, int32Param);
pendingWantManager->PendingWantStartAbilitys(allWantsInfos, token, int32Param, int32Param);
pendingWantManager->PendingWantPublishCommonEvent(*want, senderInfo, int32Param);
pendingWantManager->PendingWantPublishCommonEvent(*want, senderInfo, int32Param, int32Param);
pendingWantManager->PendingRecordIdCreate();
pendingWantManager->GetPendingWantRecordByCode(int32Param);
pendingWantManager->GetPendingWantUid(wantSenderPtr);
@@ -315,10 +315,11 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_KillApplicationSelf_001, TestSize.Level0
*/
HWTEST_F(AppMgrClientTest, AppMgrClient_AbilityAttachTimeOut_001, TestSize.Level0)
{
sptr<IRemoteObject> token = nullptr;
auto appMgrClient = std::make_unique<AppMgrClient>();
auto result = appMgrClient->ConnectAppMgrService();
EXPECT_EQ(result, AppMgrResultCode::ERROR_SERVICE_NOT_READY);
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
sptr<IRemoteObject> token = nullptr;
appMgrClient->AbilityAttachTimeOut(token);
}
@@ -208,6 +208,7 @@ HWTEST_F(AbilityProcessTest, AaFwk_AbilityProcess_0800, Function | MediumTest |
HWTEST_F(AbilityProcessTest, AaFwk_AbilityProcess_0900, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_AbilityProcess_0900 start";
process_->abilityResultMap_.clear();
Ability *ability = new (std::nothrow) MockNewAbility();
CallAbilityParam param;
param.forResultOption = true;
@@ -199,7 +199,7 @@ HWTEST_F(SourceMapTest, AaFwk_SourceMap_0700, Function | MediumTest | Level1)
/**
* @tc.number: AaFwk_SourceMap_0800
* @tc.name: ReadSourceMapData
* @tc.desc: Verifying ReadSourceMapData succeeded.
* @tc.desc: Verifying ReadSourceMapData Failed.
*/
HWTEST_F(SourceMapTest, AaFwk_SourceMap_0800, Function | MediumTest | Level1)
{
@@ -207,8 +207,7 @@ HWTEST_F(SourceMapTest, AaFwk_SourceMap_0800, Function | MediumTest | Level1)
auto modSourceMap = std::make_shared<AbilityRuntime::ModSourceMap>();
std::string filePath = "./source_map_test";
std::string context;
modSourceMap->ReadSourceMapData(filePath, context);
EXPECT_TRUE(!context.empty());
EXPECT_FALSE(modSourceMap->ReadSourceMapData(filePath, context));
GTEST_LOG_(INFO) << "AaFwk_SourceMap_0800 end";
}
@@ -68,7 +68,7 @@ HWTEST_F(PendingWantManagerDumpTest, PendingWantManagerDump_DumpByRecordId_0100,
EXPECT_NE(pendingKey, nullptr);
pendingKey->SetCode(CODE);
auto pendingWantRecord = std::make_shared<PendingWantRecord>(pendingManager, UID, nullptr, pendingKey);
auto pendingWantRecord = std::make_shared<PendingWantRecord>(pendingManager, UID, 0, nullptr, pendingKey);
EXPECT_NE(pendingWantRecord, nullptr);
pendingManager->wantRecords_ = { {pendingKey, pendingWantRecord.get()} };
@@ -510,7 +510,7 @@ HWTEST_F(PendingWantManagerTest, PendingWantManagerTest_1400, TestSize.Level1)
pendingManager_ = std::make_shared<PendingWantManager>();
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
sptr<PendingWantRecord> pendingWantRecord = new PendingWantRecord(pendingManager_, 1, nullptr, key);
sptr<PendingWantRecord> pendingWantRecord = new PendingWantRecord(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
info.finishedReceiver = new CancelReceiver();
@@ -164,7 +164,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0100, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
EXPECT_EQ(pendingWantRecord->uid_, 1);
EXPECT_EQ(pendingWantRecord->callerToken_, nullptr);
@@ -186,7 +186,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0200, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(cance);
EXPECT_EQ(static_cast<int>(pendingWantRecord->mCancelCallbacks_.size()), 1);
@@ -208,7 +208,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0300, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(nullptr);
EXPECT_EQ(static_cast<int>(pendingWantRecord->mCancelCallbacks_.size()), 0);
@@ -231,7 +231,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0400, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(cance);
pendingWantRecord->RegisterCancelListener(cance1);
@@ -255,7 +255,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0500, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(cance);
pendingWantRecord->RegisterCancelListener(cance1);
@@ -280,7 +280,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0600, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(cance);
pendingWantRecord->RegisterCancelListener(cance1);
@@ -303,7 +303,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0700, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
pendingWantRecord->canceled_ = true;
@@ -326,7 +326,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0800, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
EXPECT_NE(pendingWantRecord->SenderInner(info), 0); // Assert SenderInner failed.
@@ -346,7 +346,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_0900, TestSize.Level1)
WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::CONSTANT_FLAG, 0);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(nullptr, 1, nullptr, key);
std::make_shared<PendingWantRecord>(nullptr, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
EXPECT_EQ(pendingWantRecord->SenderInner(info), ERR_INVALID_VALUE);
@@ -366,7 +366,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1000, TestSize.Level1)
WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::ONE_TIME_FLAG, 0);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(nullptr, 1, nullptr, key);
std::make_shared<PendingWantRecord>(nullptr, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
info.finishedReceiver = new CancelReceiver();
@@ -390,7 +390,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1100, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR);
@@ -413,7 +413,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1200, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR);
@@ -437,7 +437,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1300, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
EXPECT_NE(pendingWantRecord->SenderInner(info), NO_ERROR);
@@ -461,7 +461,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1400, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
pendingWantRecord->SenderInner(info);
@@ -485,7 +485,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1500, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
info.finishedReceiver = new CancelReceiver();
@@ -511,7 +511,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1600, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
EXPECT_EQ(pendingWantRecord->GetKey(), key);
}
@@ -532,7 +532,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1700, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
EXPECT_EQ(pendingWantRecord->GetUid(), 1);
}
@@ -553,7 +553,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1800, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
EXPECT_EQ(pendingWantRecord->GetCanceled(), false);
pendingWantRecord->SetCanceled();
@@ -577,7 +577,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_1900, TestSize.Level1)
EXPECT_NE(pendingManager_, nullptr);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
pendingWantRecord->RegisterCancelListener(cance);
pendingWantRecord->RegisterCancelListener(cance1);
@@ -599,7 +599,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_2000, TestSize.Level1)
WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::CONSTANT_FLAG, 0);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
pendingWantRecord->SenderInner(info);
@@ -621,7 +621,7 @@ HWTEST_F(PendingWantRecordTest, PendingWantRecordTest_2100, TestSize.Level1)
WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, (int32_t)Flags::ONE_TIME_FLAG, 0);
std::shared_ptr<PendingWantKey> key = MakeWantKey(wantSenderInfo);
std::shared_ptr<PendingWantRecord> pendingWantRecord =
std::make_shared<PendingWantRecord>(pendingManager_, 1, nullptr, key);
std::make_shared<PendingWantRecord>(pendingManager_, 1, 0, nullptr, key);
EXPECT_NE(pendingWantRecord, nullptr);
SenderInfo info;
info.finishedReceiver = new CancelReceiver();
File diff suppressed because it is too large Load Diff