mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
This commit is contained in:
+153
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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_ability_auto_startup_callback.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_ability_auto_startup_manager_utils.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
const std::string METHOD_ON = "onAutoStartupOn";
|
||||
const std::string METHOD_OFF = "onAutoStartupOff";
|
||||
} // namespace
|
||||
JsAbilityAutoStartupCallBack::JsAbilityAutoStartupCallBack(napi_env env) : env_(env) {}
|
||||
|
||||
JsAbilityAutoStartupCallBack::~JsAbilityAutoStartupCallBack() {}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::OnAutoStartupOn(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
JSCallFunction(info, METHOD_ON);
|
||||
}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::OnAutoStartupOff(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
JSCallFunction(info, METHOD_OFF);
|
||||
}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::Register(napi_value value)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
for (auto callback : callbacks_) {
|
||||
if (IsJsCallbackEquals(callback, value)) {
|
||||
HILOG_ERROR("The current callback already exists.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env_, value, 1, &ref);
|
||||
callbacks_.emplace_back(std::unique_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref)));
|
||||
}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::UnRegister(napi_value value)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_valuetype type = napi_undefined;
|
||||
napi_typeof(env_, value, &type);
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
if (type == napi_undefined || type == napi_null) {
|
||||
HILOG_DEBUG("jsCallback is nullptr, delete all callback.");
|
||||
callbacks_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto item = callbacks_.begin(); item != callbacks_.end();) {
|
||||
if (IsJsCallbackEquals(*item, value)) {
|
||||
item = callbacks_.erase(item);
|
||||
} else {
|
||||
item++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool JsAbilityAutoStartupCallBack::IsCallbacksEmpty()
|
||||
{
|
||||
return callbacks_.empty();
|
||||
}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::JSCallFunction(const AutoStartupInfo &info, const std::string &methodName)
|
||||
{
|
||||
wptr<JsAbilityAutoStartupCallBack> stub = iface_cast<JsAbilityAutoStartupCallBack>(AsObject());
|
||||
NapiAsyncTask::CompleteCallback complete = [stub, info, methodName](
|
||||
napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
sptr<JsAbilityAutoStartupCallBack> obj = stub.promote();
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Callback object is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
obj->JSCallFunctionWorker(info, methodName);
|
||||
};
|
||||
|
||||
NapiAsyncTask::Schedule("JsAbilityAutoStartupCallBack::JSCallFunction:" + methodName, env_,
|
||||
CreateAsyncTaskWithLastParam(env_, nullptr, nullptr, std::move(complete), nullptr));
|
||||
}
|
||||
|
||||
void JsAbilityAutoStartupCallBack::JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto obj = callback->GetNapiValue();
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get value.");
|
||||
continue;
|
||||
}
|
||||
|
||||
napi_value funcObject;
|
||||
if (napi_get_named_property(env_, obj, methodName.c_str(), &funcObject) != napi_ok) {
|
||||
HILOG_ERROR("Get function by name failed.");
|
||||
continue;
|
||||
}
|
||||
|
||||
napi_value argv[] = { CreateJsAutoStartupInfo(env_, info) };
|
||||
napi_call_function(env_, obj, funcObject, ArraySize(argv), argv, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool JsAbilityAutoStartupCallBack::IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("Invalid jsCallback.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto object = callback->GetNapiValue();
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Failed to get object.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (napi_strict_equals(env_, object, value, &result) != napi_ok) {
|
||||
HILOG_ERROR("Object does not match value.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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_ABILITY_AUTO_STARTUP_CALLBACK_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_CALLBACK_H
|
||||
|
||||
#include <chrono>
|
||||
#include <iremote_object.h>
|
||||
|
||||
#include "auto_startup_callback_stub.h"
|
||||
#include "auto_startup_info.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
#include "parcel.h"
|
||||
|
||||
class NativeReference;
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
/**
|
||||
*
|
||||
* @class JsAbilityAutoStartupCallBack
|
||||
*/
|
||||
class JsAbilityAutoStartupCallBack : public AutoStartupCallBackStub {
|
||||
public:
|
||||
explicit JsAbilityAutoStartupCallBack(napi_env env);
|
||||
virtual ~JsAbilityAutoStartupCallBack();
|
||||
void Register(napi_value value);
|
||||
void UnRegister(napi_value value);
|
||||
void OnAutoStartupOn(const AutoStartupInfo &info) override;
|
||||
void OnAutoStartupOff(const AutoStartupInfo &info) override;
|
||||
bool IsCallbacksEmpty();
|
||||
|
||||
private:
|
||||
void JSCallFunction(const AutoStartupInfo &info, const std::string &methodName);
|
||||
void JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName);
|
||||
bool IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value);
|
||||
|
||||
napi_env env_;
|
||||
std::vector<std::shared_ptr<NativeReference>> callbacks_;
|
||||
std::mutex mutexlock;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_CALLBACK_H
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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_ability_auto_startup_manager_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
bool UnwrapAutoStartupInfo(napi_env env, napi_value param, AutoStartupInfo &info)
|
||||
{
|
||||
if (!IsNormalObject(env, param)) {
|
||||
HILOG_ERROR("param is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AppExecFwk::UnwrapStringByPropertyName(env, param, "bundleName", info.bundleName)) {
|
||||
HILOG_ERROR("Convert bundle name failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AppExecFwk::UnwrapStringByPropertyName(env, param, "abilityName", info.abilityName)) {
|
||||
HILOG_ERROR("Convert ability name failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
AppExecFwk::UnwrapStringByPropertyName(env, param, "moduleName", info.moduleName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsNormalObject(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("value is nullptr.");
|
||||
return false;
|
||||
}
|
||||
napi_valuetype type;
|
||||
napi_typeof(env, value, &type);
|
||||
if (type == napi_undefined || type == napi_null) {
|
||||
HILOG_ERROR("value is invalid type.");
|
||||
return false;
|
||||
}
|
||||
if (type != napi_object) {
|
||||
HILOG_ERROR("Invalid type.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStartupInfo> &infoList)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value arrayObj = nullptr;
|
||||
napi_create_array(env, &arrayObj);
|
||||
for (size_t i = 0; i < infoList.size(); ++i) {
|
||||
auto object = CreateJsAutoStartupInfo(env, infoList.at(i));
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Convert object failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_set_element(env, arrayObj, i, object) != napi_ok) {
|
||||
HILOG_ERROR("Inster object to array failed.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return arrayObj;
|
||||
}
|
||||
|
||||
napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value object = AppExecFwk::CreateJSObject(env);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("object is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value bundleName = AppExecFwk::WrapStringToJS(env, info.bundleName);
|
||||
if (bundleName == nullptr) {
|
||||
HILOG_ERROR("Convert bundle name failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value abilityName = AppExecFwk::WrapStringToJS(env, info.abilityName);
|
||||
if (abilityName == nullptr) {
|
||||
HILOG_ERROR("Convert ability name failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value moduleName = AppExecFwk::WrapStringToJS(env, info.moduleName);
|
||||
if (moduleName == nullptr) {
|
||||
HILOG_ERROR("Convert module name failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value abilityTypeName = AppExecFwk::WrapStringToJS(env, info.abilityTypeName);
|
||||
if (abilityTypeName == nullptr) {
|
||||
HILOG_ERROR("Convert ability type name failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!(AppExecFwk::SetPropertyValueByPropertyName(env, object, "bundleName", bundleName) &&
|
||||
AppExecFwk::SetPropertyValueByPropertyName(env, object, "abilityName", abilityName) &&
|
||||
AppExecFwk::SetPropertyValueByPropertyName(env, object, "moduleName", moduleName) &&
|
||||
AppExecFwk::SetPropertyValueByPropertyName(env, object, "abilityTypeName", abilityTypeName))) {
|
||||
HILOG_ERROR("Create js AutoStartupInfo failed.");
|
||||
return nullptr;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H
|
||||
|
||||
#include "auto_startup_info.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
bool UnwrapAutoStartupInfo(napi_env env, napi_value param, AutoStartupInfo &info);
|
||||
bool IsNormalObject(napi_env env, napi_value value);
|
||||
napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStartupInfo> &infoList);
|
||||
napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* 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_ability_auto_startup_manager.h"
|
||||
|
||||
#include "ability_business_error.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "ability_manager_interface.h"
|
||||
#include "auto_startup_info.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "js_ability_auto_startup_manager_utils.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "permission_constants.h"
|
||||
#include "tokenid_kit.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AAFwk;
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr const char *ON_OFF_TYPE_SYSTEM = "systemAutoStartup";
|
||||
} // namespace
|
||||
|
||||
void JsAbilityAutoStartupManager::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::unique_ptr<JsAbilityAutoStartupManager>(static_cast<JsAbilityAutoStartupManager *>(data));
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::RegisterAutoStartupCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityAutoStartupManager, OnRegisterAutoStartupCallback);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::UnregisterAutoStartupCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityAutoStartupManager, OnUnregisterAutoStartupCallback);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::SetApplicationAutoStartup(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityAutoStartupManager, OnSetApplicationAutoStartup);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::CancelApplicationAutoStartup(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityAutoStartupManager, OnCancelApplicationAutoStartup);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::QueryAllAutoStartupApplications(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityAutoStartupManager, OnQueryAllAutoStartupApplications);
|
||||
}
|
||||
|
||||
bool JsAbilityAutoStartupManager::CheckCallerIsSystemApp()
|
||||
{
|
||||
auto selfToken = IPCSkeleton::GetSelfTokenID();
|
||||
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
|
||||
HILOG_ERROR("Current app is not system app, not allow.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_TWO) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string type;
|
||||
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (!CheckCallerIsSystemApp()) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (jsAutoStartupCallback_ == nullptr) {
|
||||
jsAutoStartupCallback_ = new (std::nothrow) JsAbilityAutoStartupCallBack(env);
|
||||
if (jsAutoStartupCallback_ == nullptr) {
|
||||
HILOG_ERROR("JsAutoStartupCallback_ is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto ret =
|
||||
AbilityManagerClient::GetInstance()->RegisterAutoStartupSystemCallback(jsAutoStartupCallback_->AsObject());
|
||||
if (ret != ERR_OK) {
|
||||
jsAutoStartupCallback_ = nullptr;
|
||||
HILOG_ERROR("Register auto start up listener error[%{public}d].", ret);
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
|
||||
jsAutoStartupCallback_->Register(info.argv[INDEX_ONE]);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string type;
|
||||
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
|
||||
HILOG_ERROR("Failed to parse type.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (!CheckCallerIsSystemApp()) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (jsAutoStartupCallback_ == nullptr) {
|
||||
HILOG_ERROR("JsAutoStartupCallback_ is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto callback = info.argc > ARGC_ONE ? info.argv[INDEX_ONE] : CreateJsUndefined(env);
|
||||
jsAutoStartupCallback_->UnRegister(callback);
|
||||
if (jsAutoStartupCallback_->IsCallbacksEmpty()) {
|
||||
auto ret = AbilityManagerClient::GetInstance()->UnregisterAutoStartupSystemCallback(
|
||||
jsAutoStartupCallback_->AsObject());
|
||||
if (ret != ERR_OK) {
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
}
|
||||
jsAutoStartupCallback_ = nullptr;
|
||||
}
|
||||
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (!CheckCallerIsSystemApp()) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
AutoStartupInfo autoStartupInfo;
|
||||
if (!UnwrapAutoStartupInfo(env, info.argv[INDEX_ZERO], autoStartupInfo)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto retVal = std::make_shared<int32_t>(0);
|
||||
NapiAsyncTask::ExecuteCallback execute = [autoStartupInfo, ret = retVal] () {
|
||||
if (ret == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
return;
|
||||
}
|
||||
*ret = AbilityManagerClient::GetInstance()->SetApplicationAutoStartup(autoStartupInfo);
|
||||
};
|
||||
NapiAsyncTask::CompleteCallback complete = [ret = retVal](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (ret == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
|
||||
return;
|
||||
}
|
||||
if (*ret != ERR_OK) {
|
||||
HILOG_ERROR("Failed error:%{public}d.", *ret);
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
|
||||
return;
|
||||
}
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityAutoStartupManager::OnSetApplicationAutoStartup", env,
|
||||
CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (!CheckCallerIsSystemApp()) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
AutoStartupInfo autoStartupInfo;
|
||||
if (!UnwrapAutoStartupInfo(env, info.argv[INDEX_ZERO], autoStartupInfo)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto retVal = std::make_shared<int32_t>(0);
|
||||
NapiAsyncTask::ExecuteCallback execute = [autoStartupInfo, ret = retVal] () {
|
||||
if (ret == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
return;
|
||||
}
|
||||
*ret = AbilityManagerClient::GetInstance()->CancelApplicationAutoStartup(autoStartupInfo);
|
||||
};
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete = [ret = retVal](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (ret == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
|
||||
return;
|
||||
}
|
||||
if (*ret != ERR_OK) {
|
||||
HILOG_ERROR("Failed error:%{public}d.", *ret);
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
|
||||
return;
|
||||
}
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup", env,
|
||||
CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_env env, const NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!CheckCallerIsSystemApp()) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto retVal = std::make_shared<int32_t>(0);
|
||||
auto infoList = std::make_shared<std::vector<AutoStartupInfo>>();
|
||||
NapiAsyncTask::ExecuteCallback execute = [infos = infoList, ret = retVal] () {
|
||||
if (ret == nullptr || infos == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
return;
|
||||
}
|
||||
*ret = AbilityManagerClient::GetInstance()->QueryAllAutoStartupApplications(*infos);
|
||||
};
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete = [infos = infoList, ret = retVal] (napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (ret == nullptr || infos == nullptr) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
|
||||
return;
|
||||
}
|
||||
if (*ret != ERR_OK) {
|
||||
HILOG_ERROR("Failed error:%{public}d.", *ret);
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
|
||||
return;
|
||||
}
|
||||
task.ResolveWithNoError(env, CreateJsAutoStartupInfoArray(env, *infos));
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup", env,
|
||||
CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsAbilityAutoStartupManagerInit(napi_env env, napi_value exportObj)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (env == nullptr || exportObj == nullptr) {
|
||||
HILOG_ERROR("Env or exportObj nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto jsAbilityAutoStartupManager = std::make_unique<JsAbilityAutoStartupManager>();
|
||||
napi_wrap(env, exportObj, jsAbilityAutoStartupManager.release(),
|
||||
JsAbilityAutoStartupManager::Finalizer, nullptr, nullptr);
|
||||
|
||||
const char *moduleName = "JsAbilityAutoStartupManager";
|
||||
BindNativeFunction(env, exportObj, "on", moduleName, JsAbilityAutoStartupManager::RegisterAutoStartupCallback);
|
||||
BindNativeFunction(env, exportObj, "off", moduleName, JsAbilityAutoStartupManager::UnregisterAutoStartupCallback);
|
||||
BindNativeFunction(env, exportObj, "setApplicationAutoStartup", moduleName,
|
||||
JsAbilityAutoStartupManager::SetApplicationAutoStartup);
|
||||
BindNativeFunction(env, exportObj, "cancelApplicationAutoStartup", moduleName,
|
||||
JsAbilityAutoStartupManager::CancelApplicationAutoStartup);
|
||||
BindNativeFunction(env, exportObj, "queryAllAutoStartupApplications", moduleName,
|
||||
JsAbilityAutoStartupManager::QueryAllAutoStartupApplications);
|
||||
HILOG_DEBUG("End.");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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_ABILITY_AUTO_STARTUP_MANAGER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_H
|
||||
|
||||
#include "js_ability_auto_startup_callback.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsAbilityAutoStartupManager {
|
||||
public:
|
||||
JsAbilityAutoStartupManager() = default;
|
||||
~JsAbilityAutoStartupManager() = default;
|
||||
static void Finalizer(napi_env env, void *data, void *hint);
|
||||
static napi_value RegisterAutoStartupCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value UnregisterAutoStartupCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value SetApplicationAutoStartup(napi_env env, napi_callback_info info);
|
||||
static napi_value CancelApplicationAutoStartup(napi_env env, napi_callback_info info);
|
||||
static napi_value QueryAllAutoStartupApplications(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
napi_value OnRegisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnUnregisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnSetApplicationAutoStartup(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnCancelApplicationAutoStartup(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnQueryAllAutoStartupApplications(napi_env env, const NapiCallbackInfo &info);
|
||||
bool CheckCallerIsSystemApp();
|
||||
|
||||
sptr<JsAbilityAutoStartupCallBack> jsAutoStartupCallback_;
|
||||
};
|
||||
napi_value JsAbilityAutoStartupManagerInit(napi_env env, napi_value exportObj);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_H
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
|
||||
AbilityErrorCode preCheck()
|
||||
{
|
||||
auto mgr = ChildProcessManager::GetInstance();
|
||||
auto &mgr = ChildProcessManager::GetInstance();
|
||||
if (!mgr.MultiProcessModelEnabled()) {
|
||||
HILOG_ERROR("Starting child process is not supported");
|
||||
return AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED;
|
||||
|
||||
@@ -1691,6 +1691,15 @@ void Ability::SetShowOnLockScreen(bool showOnLockScreen)
|
||||
HILOG_DEBUG("SetShowOnLockScreen come, addWindowFlag, showOnLockScreen is %{public}d", showOnLockScreen);
|
||||
if (showOnLockScreen) {
|
||||
window->AddWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
|
||||
if (abilityInfo_ == nullptr) {
|
||||
HILOG_ERROR("Ability::SetShowOnLockScreen abilityInfo_ == nullptr");
|
||||
return;
|
||||
}
|
||||
AAFwk::EventInfo eventInfo;
|
||||
eventInfo.bundleName = abilityInfo_->bundleName;
|
||||
eventInfo.moduleName = abilityInfo_->moduleName;
|
||||
eventInfo.abilityName = abilityInfo_->name;
|
||||
AAFwk::EventReport::SendKeyEvent(AAFwk::EventName::FA_SHOW_ON_LOCK, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
} else {
|
||||
window->RemoveWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 "auto_startup_callback_proxy.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AAFwk;
|
||||
void AutoStartupCallBackProxy::OnAutoStartupOn(const AutoStartupInfo &info)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(AutoStartupCallBackProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&info)) {
|
||||
HILOG_ERROR("Write AutoStartupInfo failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto ret = SendRequest(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_ON, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Send request error: %{public}d.", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoStartupCallBackProxy::OnAutoStartupOff(const AutoStartupInfo &info)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(AutoStartupCallBackProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&info)) {
|
||||
HILOG_ERROR("Write AutoStartupInfo failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto ret = SendRequest(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_OFF, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Send request error: %{public}d.", ret);
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode AutoStartupCallBackProxy::SendRequest(
|
||||
AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("Remote is nullptr.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 "auto_startup_callback_stub.h"
|
||||
|
||||
#include "ability_manager_ipc_interface_code.h"
|
||||
#include "auto_startup_info.h"
|
||||
#include "event_handler.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AAFwk;
|
||||
AutoStartupCallBackStub::AutoStartupCallBackStub()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
AutoStartupCallBackStub::~AutoStartupCallBackStub()
|
||||
{
|
||||
requestFuncMap_.clear();
|
||||
}
|
||||
|
||||
void AutoStartupCallBackStub::Init()
|
||||
{
|
||||
requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_ON)] =
|
||||
&AutoStartupCallBackStub::OnAutoStartupOnInner;
|
||||
requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_OFF)] =
|
||||
&AutoStartupCallBackStub::OnAutoStartupOffInner;
|
||||
}
|
||||
|
||||
int AutoStartupCallBackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::u16string autoStartUpCallBackDescriptor = AutoStartupCallBackStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (autoStartUpCallBackDescriptor != remoteDescriptor) {
|
||||
HILOG_ERROR("Local descriptor is not equal to remote.");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = requestFuncMap_.find(code);
|
||||
if (itFunc != requestFuncMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return (this->*requestFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
HILOG_WARN("Default case, need check.");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t AutoStartupCallBackStub::OnAutoStartupOnInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<AutoStartupInfo> info = data.ReadParcelable<AutoStartupInfo>();
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("Failed to read parcelable.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler =
|
||||
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
|
||||
wptr<AutoStartupCallBackStub> weak = this;
|
||||
if (handler) {
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOn(*info);
|
||||
});
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t AutoStartupCallBackStub::OnAutoStartupOffInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<AutoStartupInfo> info = data.ReadParcelable<AutoStartupInfo>();
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("Failed to read parcelable.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler =
|
||||
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
|
||||
wptr<AutoStartupCallBackStub> weak = this;
|
||||
if (handler) {
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOff(*info);
|
||||
});
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "application_info.h"
|
||||
@@ -41,13 +42,33 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr pid_t INVALID_PID = -1;
|
||||
const std::string SYS_PARAM_MULTI_PROCESS_MODEL = "persist.sys.multi_process_model";
|
||||
constexpr pid_t INVALID_PID = -1;
|
||||
const std::string SYS_PARAM_MULTI_PROCESS_MODEL = "persist.sys.multi_process_model";
|
||||
}
|
||||
|
||||
bool ChildProcessManager::signalRegistered_ = false;
|
||||
|
||||
ChildProcessManager::ChildProcessManager()
|
||||
{
|
||||
HILOG_DEBUG("ChildProcessManager constructor called");
|
||||
multiProcessModelEnabled_ = OHOS::system::GetBoolParameter(SYS_PARAM_MULTI_PROCESS_MODEL, false);
|
||||
if (!signalRegistered_) {
|
||||
signalRegistered_ = true;
|
||||
HILOG_DEBUG("Register signal");
|
||||
signal(SIGCHLD, ChildProcessManager::HandleSigChild);
|
||||
}
|
||||
}
|
||||
|
||||
ChildProcessManager::~ChildProcessManager()
|
||||
{
|
||||
HILOG_DEBUG("ChildProcessManager deconstructor called");
|
||||
}
|
||||
|
||||
void ChildProcessManager::HandleSigChild(int32_t signo)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
pid_t ChildProcessManager::StartChildProcessBySelfFork(const std::string &srcEntry)
|
||||
@@ -73,7 +94,7 @@ pid_t ChildProcessManager::StartChildProcessBySelfFork(const std::string &srcEnt
|
||||
isChildProcess_ = true;
|
||||
HandleChildProcess(srcEntry, hapModuleInfo);
|
||||
HILOG_DEBUG("Child process end");
|
||||
kill(getpid(), SIGQUIT);
|
||||
exit(0);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <native_engine/native_value.h>
|
||||
#include "ability_context.h"
|
||||
#include "configuration.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
class NativeObject;
|
||||
class NativeReference;
|
||||
@@ -33,40 +34,40 @@ public:
|
||||
explicit JsAbilityContext(const std::shared_ptr<AbilityContext> &context) : context_(context) {}
|
||||
~JsAbilityContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine *engine, void *data, void *hint);
|
||||
static void Finalizer(napi_env env, void *data, void *hint);
|
||||
|
||||
static NativeValue *StartAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartAbilityAsCaller(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartRecentAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartAbilityByCall(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartAbilityForResult(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartAbilityForResultWithAccount(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartServiceExtensionAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StartServiceExtensionAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StopServiceExtensionAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *StopServiceExtensionAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *ConnectAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *ConnectAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *DisconnectAbility(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *TerminateSelf(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *TerminateSelfWithResult(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 napi_value StartAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityAsCaller(napi_env env, napi_callback_info info);
|
||||
static napi_value StartRecentAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityByCall(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityForResult(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityForResultWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StartServiceExtensionAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StopServiceExtensionAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value ConnectAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value ConnectAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value DisconnectAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value TerminateSelf(napi_env env, napi_callback_info info);
|
||||
static napi_value TerminateSelfWithResult(napi_env env, napi_callback_info info);
|
||||
static napi_value RestoreWindowStage(napi_env env, napi_callback_info info);
|
||||
static napi_value RequestDialogService(napi_env env, napi_callback_info info);
|
||||
static napi_value IsTerminating(napi_env env, napi_callback_info info);
|
||||
|
||||
static void ConfigurationUpdated(NativeEngine *engine, std::shared_ptr<NativeReference> &jsContext,
|
||||
static void ConfigurationUpdated(napi_env env, std::shared_ptr<NativeReference> &jsContext,
|
||||
const std::shared_ptr<AppExecFwk::Configuration> &config);
|
||||
|
||||
private:
|
||||
NativeValue *OnTerminateSelf(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnIsTerminating(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnTerminateSelfWithResult(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
napi_value OnTerminateSelf(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnIsTerminating(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo &info);
|
||||
|
||||
std::weak_ptr<AbilityContext> context_;
|
||||
};
|
||||
NativeValue *CreateJsAbilityContext(NativeEngine &engine, const std::shared_ptr<AbilityContext> &context);
|
||||
NativeValue *CreateJsErrorByNativeErr(NativeEngine &engine, int32_t err, const std::string &permission = "");
|
||||
napi_value CreateJsAbilityContext(napi_env env, const std::shared_ptr<AbilityContext> &context);
|
||||
napi_value CreateJsErrorByNativeErr(napi_env env, int32_t err, const std::string &permission = "");
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_SIMULATOR_JS_ABILITY_CONTEXT_H
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
explicit JsAbilityStageContext(const std::shared_ptr<Context> &context) : context_(context) {}
|
||||
~JsAbilityStageContext() = default;
|
||||
|
||||
static void ConfigurationUpdated(NativeEngine *engine, std::shared_ptr<NativeReference> &jsContext,
|
||||
static void ConfigurationUpdated(napi_env env, std::shared_ptr<NativeReference> &jsContext,
|
||||
const std::shared_ptr<AppExecFwk::Configuration> &config);
|
||||
|
||||
std::shared_ptr<Context> GetContext()
|
||||
@@ -39,7 +39,7 @@ private:
|
||||
std::weak_ptr<Context> context_;
|
||||
};
|
||||
|
||||
NativeValue *CreateJsAbilityStageContext(NativeEngine &engine, const std::shared_ptr<Context> &context);
|
||||
napi_value CreateJsAbilityStageContext(napi_env env, const std::shared_ptr<Context> &context);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_SIMULATOR_JS_ABILITY_STAGE_CONTEXT_H
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "context.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@@ -27,42 +28,42 @@ class JsApplicationContextUtils {
|
||||
public:
|
||||
JsApplicationContextUtils(std::weak_ptr<Context> &&context) : context_(std::move(context)) {}
|
||||
virtual ~JsApplicationContextUtils() = default;
|
||||
static void Finalizer(NativeEngine *engine, void *data, void *hint);
|
||||
static NativeValue *RegisterAbilityLifecycleCallback(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *UnregisterAbilityLifecycleCallback(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *RegisterEnvironmentCallback(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *UnregisterEnvironmentCallback(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *On(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *Off(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *CreateBundleContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *SwitchArea(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetArea(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *CreateModuleContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetTempDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetFilesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetDistributedFilesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetDatabaseDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetPreferencesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetRunningProcessInformation(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *CreateJsApplicationContext(NativeEngine &engine, const std::shared_ptr<Context> &context);
|
||||
static void Finalizer(napi_env env, void *data, void *hint);
|
||||
static napi_value RegisterAbilityLifecycleCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value UnregisterAbilityLifecycleCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value RegisterEnvironmentCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value UnregisterEnvironmentCallback(napi_env env, napi_callback_info info);
|
||||
static napi_value On(napi_env env, napi_callback_info info);
|
||||
static napi_value Off(napi_env env, napi_callback_info info);
|
||||
static napi_value CreateBundleContext(napi_env env, napi_callback_info info);
|
||||
static napi_value SwitchArea(napi_env env, napi_callback_info info);
|
||||
static napi_value GetArea(napi_env env, napi_callback_info info);
|
||||
static napi_value CreateModuleContext(napi_env env, napi_callback_info info);
|
||||
static napi_value GetCacheDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetTempDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetFilesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDistributedFilesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDatabaseDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetPreferencesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetBundleCodeDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetApplicationContext(napi_env env, napi_callback_info info);
|
||||
static napi_value KillProcessBySelf(napi_env env, napi_callback_info info);
|
||||
static napi_value GetRunningProcessInformation(napi_env env, napi_callback_info info);
|
||||
static napi_value CreateJsApplicationContext(napi_env env, const std::shared_ptr<Context> &context);
|
||||
|
||||
NativeValue *OnGetCacheDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetTempDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetFilesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetDistributedFilesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetDatabaseDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetArea(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetTempDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetFilesDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetDatabaseDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetPreferencesDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetBundleCodeDir(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetArea(napi_env env, NapiCallbackInfo& info);
|
||||
|
||||
private:
|
||||
NativeValue *OnSwitchArea(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetApplicationContext(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
static void BindNativeApplicationContext(NativeEngine &engine, NativeObject *object);
|
||||
napi_value OnSwitchArea(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo& info);
|
||||
static void BindNativeApplicationContext(napi_env env, napi_value object);
|
||||
|
||||
private:
|
||||
std::weak_ptr<Context> context_;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void InitConsoleLogModule(NativeEngine &engine, NativeObject &globalObject);
|
||||
void InitConsoleLogModule(napi_env env, napi_value globalObject);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue *CreateJsBaseContext(NativeEngine &engine, std::shared_ptr<Context> context, bool keepContext = false);
|
||||
napi_value CreateJsBaseContext(napi_env env, std::shared_ptr<Context> context, bool keepContext = false);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_SIMULATOR_JS_CONTEXT_UTILS_H
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "application_info.h"
|
||||
#include "hap_module_info.h"
|
||||
#include "configuration.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "res_common.h"
|
||||
|
||||
class NativeEngine;
|
||||
@@ -31,10 +32,10 @@ Global::Resource::Direction ConvertDirection(const std::string &direction);
|
||||
Global::Resource::ScreenDensity ConvertDensity(const std::string &density);
|
||||
int32_t ConvertDisplayId(const std::string &displayId);
|
||||
std::string GetDensityStr(float density);
|
||||
NativeValue *CreateJsConfiguration(NativeEngine &engine, const AppExecFwk::Configuration &configuration);
|
||||
NativeValue *CreateJsApplicationInfo(NativeEngine &engine, const AppExecFwk::ApplicationInfo &applicationInfo);
|
||||
NativeValue *CreateJsHapModuleInfo(NativeEngine &engine, const AppExecFwk::HapModuleInfo &hapModuleInfo);
|
||||
NativeValue *CreateJsAbilityInfo(NativeEngine &engine, const AppExecFwk::AbilityInfo &abilityInfo);
|
||||
napi_value CreateJsConfiguration(napi_env env, const AppExecFwk::Configuration &configuration);
|
||||
napi_value CreateJsApplicationInfo(napi_env env, const AppExecFwk::ApplicationInfo &applicationInfo);
|
||||
napi_value CreateJsHapModuleInfo(napi_env env, const AppExecFwk::HapModuleInfo &hapModuleInfo);
|
||||
napi_value CreateJsAbilityInfo(napi_env env, const AppExecFwk::AbilityInfo &abilityInfo);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_SIMULATOR_JS_DATA_CONVERTER_H
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define OHOS_ABILITY_RUNTIME_JS_RESOURCE_MANAGER_UTILS_H
|
||||
|
||||
#include "context.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "resource_manager.h"
|
||||
|
||||
class NativeEngine;
|
||||
@@ -24,7 +25,7 @@ class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue *CreateJsResourceManager(NativeEngine &engine,
|
||||
napi_value CreateJsResourceManager(napi_env env,
|
||||
std::shared_ptr<Global::Resource::ResourceManager> resourceManager, std::shared_ptr<Context> context);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void InitTimer(NativeEngine &engine, NativeObject &globalObject);
|
||||
void InitTimer(napi_env env, napi_value globalObject);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
@@ -28,89 +28,88 @@ namespace {
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
}
|
||||
void JsAbilityContext::Finalizer(NativeEngine *engine, void *data, void *hint)
|
||||
void JsAbilityContext::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
std::unique_ptr<JsAbilityContext>(static_cast<JsAbilityContext*>(data));
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbilityAsCaller(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbilityAsCaller(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartRecentAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartRecentAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbilityByCall(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbilityByCall(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbilityForResult(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbilityForResult(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartAbilityForResultWithAccount(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartAbilityForResultWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartServiceExtensionAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartServiceExtensionAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StartServiceExtensionAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StopServiceExtensionAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StopServiceExtensionAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::StopServiceExtensionAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::ConnectAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::ConnectAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::ConnectAbilityWithAccount(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::ConnectAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::DisconnectAbility(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::DisconnectAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::TerminateSelf(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::TerminateSelf(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsAbilityContext *me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateSelf(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityContext, OnTerminateSelf);
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::OnTerminateSelf(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("TerminateSelf");
|
||||
auto abilityContext = context_.lock();
|
||||
@@ -119,30 +118,29 @@ NativeValue *JsAbilityContext::OnTerminateSelf(NativeEngine &engine, NativeCallb
|
||||
}
|
||||
abilityContext->SetTerminating(true);
|
||||
|
||||
NativeValue *lastParam = (info.argc > ARGC_ZERO) ? info.argv[ARGC_ZERO] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
auto task = CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result);
|
||||
napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[ARGC_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
auto task = CreateAsyncTaskWithLastParam(env, lastParam, nullptr, nullptr, &result);
|
||||
if (task == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto errcode = abilityContext->TerminateSelf();
|
||||
if (errcode == 0) {
|
||||
task->Resolve(engine, engine.CreateUndefined());
|
||||
task->Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
task->Reject(engine, CreateJsErrorByNativeErr(engine, errcode));
|
||||
task->Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::TerminateSelfWithResult(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::TerminateSelfWithResult(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsAbilityContext *me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateSelfWithResult(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityContext, OnTerminateSelfWithResult);
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::OnTerminateSelfWithResult(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
auto abilityContext = context_.lock();
|
||||
@@ -151,59 +149,58 @@ NativeValue *JsAbilityContext::OnTerminateSelfWithResult(NativeEngine &engine, N
|
||||
}
|
||||
abilityContext->SetTerminating(true);
|
||||
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
auto task = CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result);
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
auto task = CreateAsyncTaskWithLastParam(env, lastParam, nullptr, nullptr, &result);
|
||||
if (task == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto errcode = abilityContext->TerminateSelf();
|
||||
if (errcode == 0) {
|
||||
task->Resolve(engine, engine.CreateUndefined());
|
||||
task->Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
task->Reject(engine, CreateJsErrorByNativeErr(engine, errcode));
|
||||
task->Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::RestoreWindowStage(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::RestoreWindowStage(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::RequestDialogService(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::RequestDialogService(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::IsTerminating(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsAbilityContext::IsTerminating(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsAbilityContext *me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnIsTerminating(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityContext, OnIsTerminating);
|
||||
}
|
||||
|
||||
NativeValue *JsAbilityContext::OnIsTerminating(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsAbilityContext::OnIsTerminating(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("IsTerminating");
|
||||
auto context = context_.lock();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("OnIsTerminating context is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
return engine.CreateBoolean(context->IsTerminating());
|
||||
return CreateJsValue(env, context->IsTerminating());
|
||||
}
|
||||
|
||||
NativeValue *CreateJsErrorByNativeErr(NativeEngine &engine, int32_t err, const std::string &permission)
|
||||
napi_value CreateJsErrorByNativeErr(napi_env env, int32_t err, const std::string &permission)
|
||||
{
|
||||
auto errCode = GetJsErrorCodeByNativeError(err);
|
||||
auto errMsg = (errCode == AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED && !permission.empty()) ?
|
||||
GetNoPermissionErrorMsg(permission) : GetErrorMsg(errCode);
|
||||
return CreateJsError(engine, static_cast<int32_t>(errCode), errMsg);
|
||||
return CreateJsError(env, static_cast<int32_t>(errCode), errMsg);
|
||||
}
|
||||
|
||||
void JsAbilityContext::ConfigurationUpdated(NativeEngine *engine, std::shared_ptr<NativeReference> &jsContext,
|
||||
void JsAbilityContext::ConfigurationUpdated(napi_env env, std::shared_ptr<NativeReference> &jsContext,
|
||||
const std::shared_ptr<AppExecFwk::Configuration> &config)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
@@ -212,83 +209,86 @@ void JsAbilityContext::ConfigurationUpdated(NativeEngine *engine, std::shared_pt
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *value = jsContext->Get();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("object is nullptr.");
|
||||
napi_value value = jsContext->GetNapiValue();
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("value is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *method = object->GetProperty("onUpdateConfiguration");
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env, value, "onUpdateConfiguration", &method);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onUpdateConfiguration from object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *argv[] = { CreateJsConfiguration(*engine, *config) };
|
||||
engine->CallFunction(value, method, argv, 1);
|
||||
napi_value argv[] = { CreateJsConfiguration(env, *config) };
|
||||
napi_value callResult = nullptr;
|
||||
napi_call_function(env, nullptr, method, 1, argv, &callResult);
|
||||
}
|
||||
|
||||
NativeValue *CreateJsAbilityContext(NativeEngine &engine, const std::shared_ptr<AbilityContext> &context)
|
||||
napi_value CreateJsAbilityContext(napi_env env, const std::shared_ptr<AbilityContext> &context)
|
||||
{
|
||||
NativeValue *objValue = CreateJsBaseContext(engine, context);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
napi_value object = CreateJsBaseContext(env, context);
|
||||
|
||||
std::unique_ptr<JsAbilityContext> jsContext = std::make_unique<JsAbilityContext>(context);
|
||||
object->SetNativePointer(jsContext.release(), JsAbilityContext::Finalizer, nullptr);
|
||||
napi_wrap(env, object, jsContext.release(), JsAbilityContext::Finalizer, nullptr, nullptr);
|
||||
|
||||
auto resourceManager = context->GetResourceManager();
|
||||
if (resourceManager != nullptr) {
|
||||
object->SetProperty("resourceManager", CreateJsResourceManager(engine, resourceManager, context));
|
||||
napi_set_named_property(env, object, "resourceManager",
|
||||
CreateJsResourceManager(env, resourceManager, context));
|
||||
}
|
||||
|
||||
auto abilityInfo = context->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr) {
|
||||
object->SetProperty("abilityInfo", CreateJsAbilityInfo(engine, *abilityInfo));
|
||||
napi_set_named_property(
|
||||
env, object, "abilityInfo", CreateJsAbilityInfo(env, *abilityInfo));
|
||||
}
|
||||
|
||||
auto configuration = context->GetConfiguration();
|
||||
if (configuration != nullptr) {
|
||||
object->SetProperty("config", CreateJsConfiguration(engine, *configuration));
|
||||
napi_set_named_property(
|
||||
env, object, "config", CreateJsConfiguration(env, *configuration));
|
||||
}
|
||||
|
||||
const char *moduleName = "JsAbilityContext";
|
||||
BindNativeFunction(engine, *object, "startAbility", moduleName, JsAbilityContext::StartAbility);
|
||||
BindNativeFunction(engine, *object, "startAbilityAsCaller", moduleName, JsAbilityContext::StartAbilityAsCaller);
|
||||
BindNativeFunction(engine, *object, "startAbilityWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "startAbility", moduleName, JsAbilityContext::StartAbility);
|
||||
BindNativeFunction(env, object, "startAbilityAsCaller", moduleName, JsAbilityContext::StartAbilityAsCaller);
|
||||
BindNativeFunction(env, object, "startAbilityWithAccount", moduleName,
|
||||
JsAbilityContext::StartAbilityWithAccount);
|
||||
BindNativeFunction(engine, *object, "startAbilityByCall", moduleName, JsAbilityContext::StartAbilityByCall);
|
||||
BindNativeFunction(engine, *object, "startAbilityForResult", moduleName, JsAbilityContext::StartAbilityForResult);
|
||||
BindNativeFunction(engine, *object, "startAbilityForResultWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "startAbilityByCall", moduleName, JsAbilityContext::StartAbilityByCall);
|
||||
BindNativeFunction(env, object, "startAbilityForResult", moduleName, JsAbilityContext::StartAbilityForResult);
|
||||
BindNativeFunction(env, object, "startAbilityForResultWithAccount", moduleName,
|
||||
JsAbilityContext::StartAbilityForResultWithAccount);
|
||||
BindNativeFunction(engine, *object, "startServiceExtensionAbility", moduleName,
|
||||
BindNativeFunction(env, object, "startServiceExtensionAbility", moduleName,
|
||||
JsAbilityContext::StartServiceExtensionAbility);
|
||||
BindNativeFunction(engine, *object, "startServiceExtensionAbilityWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "startServiceExtensionAbilityWithAccount", moduleName,
|
||||
JsAbilityContext::StartServiceExtensionAbilityWithAccount);
|
||||
BindNativeFunction(engine, *object, "stopServiceExtensionAbility", moduleName,
|
||||
BindNativeFunction(env, object, "stopServiceExtensionAbility", moduleName,
|
||||
JsAbilityContext::StopServiceExtensionAbility);
|
||||
BindNativeFunction(engine, *object, "stopServiceExtensionAbilityWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "stopServiceExtensionAbilityWithAccount", moduleName,
|
||||
JsAbilityContext::StopServiceExtensionAbilityWithAccount);
|
||||
BindNativeFunction(engine, *object, "connectAbility", moduleName, JsAbilityContext::ConnectAbility);
|
||||
BindNativeFunction(engine, *object, "connectServiceExtensionAbility", moduleName, JsAbilityContext::ConnectAbility);
|
||||
BindNativeFunction(engine, *object, "connectAbilityWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "connectAbility", moduleName, JsAbilityContext::ConnectAbility);
|
||||
BindNativeFunction(env, object, "connectServiceExtensionAbility", moduleName, JsAbilityContext::ConnectAbility);
|
||||
BindNativeFunction(env, object, "connectAbilityWithAccount", moduleName,
|
||||
JsAbilityContext::ConnectAbilityWithAccount);
|
||||
BindNativeFunction(engine, *object, "connectServiceExtensionAbilityWithAccount", moduleName,
|
||||
BindNativeFunction(env, object, "connectServiceExtensionAbilityWithAccount", moduleName,
|
||||
JsAbilityContext::ConnectAbilityWithAccount);
|
||||
BindNativeFunction(engine, *object, "disconnectAbility", moduleName, JsAbilityContext::DisconnectAbility);
|
||||
BindNativeFunction(env, object, "disconnectAbility", moduleName, JsAbilityContext::DisconnectAbility);
|
||||
BindNativeFunction(
|
||||
engine, *object, "disconnectServiceExtensionAbility", moduleName, JsAbilityContext::DisconnectAbility);
|
||||
BindNativeFunction(engine, *object, "terminateSelf", moduleName, JsAbilityContext::TerminateSelf);
|
||||
BindNativeFunction(engine, *object, "terminateSelfWithResult", moduleName,
|
||||
env, object, "disconnectServiceExtensionAbility", moduleName, JsAbilityContext::DisconnectAbility);
|
||||
BindNativeFunction(env, object, "terminateSelf", moduleName, JsAbilityContext::TerminateSelf);
|
||||
BindNativeFunction(env, object, "terminateSelfWithResult", moduleName,
|
||||
JsAbilityContext::TerminateSelfWithResult);
|
||||
BindNativeFunction(engine, *object, "restoreWindowStage", moduleName, JsAbilityContext::RestoreWindowStage);
|
||||
BindNativeFunction(engine, *object, "isTerminating", moduleName, JsAbilityContext::IsTerminating);
|
||||
BindNativeFunction(engine, *object, "startRecentAbility", moduleName,
|
||||
BindNativeFunction(env, object, "restoreWindowStage", moduleName, JsAbilityContext::RestoreWindowStage);
|
||||
BindNativeFunction(env, object, "isTerminating", moduleName, JsAbilityContext::IsTerminating);
|
||||
BindNativeFunction(env, object, "startRecentAbility", moduleName,
|
||||
JsAbilityContext::StartRecentAbility);
|
||||
BindNativeFunction(engine, *object, "requestDialogService", moduleName,
|
||||
BindNativeFunction(env, object, "requestDialogService", moduleName,
|
||||
JsAbilityContext::RequestDialogService);
|
||||
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -22,23 +22,22 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue *CreateJsAbilityStageContext(NativeEngine &engine, const std::shared_ptr<AbilityRuntime::Context> &context)
|
||||
napi_value CreateJsAbilityStageContext(napi_env env, const std::shared_ptr<AbilityRuntime::Context> &context)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
NativeValue *objValue = CreateJsBaseContext(engine, context);
|
||||
napi_value objValue = CreateJsBaseContext(env, context);
|
||||
if (context == nullptr) {
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
auto configuration = context->GetConfiguration();
|
||||
if (configuration != nullptr && object != nullptr) {
|
||||
object->SetProperty("config", CreateJsConfiguration(engine, *configuration));
|
||||
if (configuration != nullptr && objValue != nullptr) {
|
||||
napi_set_named_property(env, objValue, "config",
|
||||
CreateJsConfiguration(env, *configuration));
|
||||
}
|
||||
return objValue;
|
||||
}
|
||||
|
||||
void JsAbilityStageContext::ConfigurationUpdated(NativeEngine *engine, std::shared_ptr<NativeReference> &jsContext,
|
||||
void JsAbilityStageContext::ConfigurationUpdated(napi_env env, std::shared_ptr<NativeReference> &jsContext,
|
||||
const std::shared_ptr<AppExecFwk::Configuration> &config)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
@@ -47,22 +46,23 @@ void JsAbilityStageContext::ConfigurationUpdated(NativeEngine *engine, std::shar
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *value = jsContext->Get();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (!object) {
|
||||
HILOG_ERROR("object is nullptr.");
|
||||
napi_value value = jsContext->GetNapiValue();
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("value is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *method = object->GetProperty("onUpdateConfiguration");
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env, value, "onUpdateConfiguration", &method);
|
||||
if (!method) {
|
||||
HILOG_ERROR("Failed to get onUpdateConfiguration from object");
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("JsAbilityStageContext call onUpdateConfiguration.");
|
||||
NativeValue *argv[] = { CreateJsConfiguration(*engine, *config) };
|
||||
engine->CallFunction(value, method, argv, 1);
|
||||
napi_value argv[] = { CreateJsConfiguration(env, *config) };
|
||||
napi_value callResult = nullptr;
|
||||
napi_call_function(env, value, method, 1, argv, &callResult);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -29,312 +29,287 @@ constexpr char APPLICATION_CONTEXT_NAME[] = "__application_context_ptr__";
|
||||
const char *MD_NAME = "JsApplicationContextUtils";
|
||||
} // namespace
|
||||
|
||||
NativeValue *JsApplicationContextUtils::CreateBundleContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::CreateBundleContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::SwitchArea(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::SwitchArea(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnSwitchArea(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnSwitchArea, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnSwitchArea(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnSwitchArea(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
NativeValue *thisVar = info.thisVar;
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(thisVar);
|
||||
napi_value object = info.thisVar;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("object is null");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
BindNativeProperty(*object, "cacheDir", GetCacheDir);
|
||||
BindNativeProperty(*object, "tempDir", GetTempDir);
|
||||
BindNativeProperty(*object, "filesDir", GetFilesDir);
|
||||
BindNativeProperty(*object, "distributedFilesDir", GetDistributedFilesDir);
|
||||
BindNativeProperty(*object, "databaseDir", GetDatabaseDir);
|
||||
BindNativeProperty(*object, "preferencesDir", GetPreferencesDir);
|
||||
BindNativeProperty(*object, "bundleCodeDir", GetBundleCodeDir);
|
||||
return engine.CreateUndefined();
|
||||
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
|
||||
BindNativeProperty(env, object, "tempDir", GetTempDir);
|
||||
BindNativeProperty(env, object, "filesDir", GetFilesDir);
|
||||
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
|
||||
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
|
||||
BindNativeProperty(env, object, "preferencesDir", GetPreferencesDir);
|
||||
BindNativeProperty(env, object, "bundleCodeDir", GetBundleCodeDir);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
|
||||
NativeValue *JsApplicationContextUtils::CreateModuleContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::CreateModuleContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetTempDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetTempDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetTempDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetTempDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetTempDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetTempDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetTempDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetArea(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetArea(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetArea(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetArea, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetArea(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetArea(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
int area = context->GetArea();
|
||||
return engine.CreateNumber(area);
|
||||
return CreateJsValue(env, area);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetCacheDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetCacheDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetCacheDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetCacheDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetCacheDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetCacheDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetFilesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetFilesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetFilesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetFilesDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetFilesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetFilesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetFilesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetDistributedFilesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetDistributedFilesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetDistributedFilesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils,
|
||||
OnGetDistributedFilesDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetDistributedFilesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetDistributedFilesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetDatabaseDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetDatabaseDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetDatabaseDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetDatabaseDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetDatabaseDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetDatabaseDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetDatabaseDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetPreferencesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetPreferencesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetPreferencesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env,
|
||||
info, JsApplicationContextUtils, OnGetPreferencesDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetPreferencesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetPreferencesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetBundleCodeDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetBundleCodeDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env,
|
||||
info, JsApplicationContextUtils, OnGetBundleCodeDir, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetBundleCodeDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetBundleCodeDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::KillProcessBySelf(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetRunningProcessInformation(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetRunningProcessInformation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JsApplicationContextUtils::Finalizer(NativeEngine *engine, void *data, void *hint)
|
||||
void JsApplicationContextUtils::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
std::unique_ptr<JsApplicationContextUtils>(static_cast<JsApplicationContextUtils *>(data));
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::RegisterAbilityLifecycleCallback(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::RegisterAbilityLifecycleCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::UnregisterAbilityLifecycleCallback(
|
||||
NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::UnregisterAbilityLifecycleCallback(
|
||||
napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::RegisterEnvironmentCallback(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::RegisterEnvironmentCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::UnregisterEnvironmentCallback(
|
||||
NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::UnregisterEnvironmentCallback(
|
||||
napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::On(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::Off(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsApplicationContextUtils::GetApplicationContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsApplicationContextUtils *me =
|
||||
CheckParamsAndGetThis<JsApplicationContextUtils>(engine, info, APPLICATION_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetApplicationContext(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils,
|
||||
OnGetApplicationContext, APPLICATION_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::OnGetApplicationContext(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsApplicationContextUtils::OnGetApplicationContext(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
NativeValue *value = CreateJsApplicationContext(engine, context_.lock());
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(&engine, "application.ApplicationContext", &value, 1);
|
||||
napi_value value = CreateJsApplicationContext(env, context_.lock());
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.ApplicationContext", &value, 1);
|
||||
if (systemModule == nullptr) {
|
||||
HILOG_WARN("OnGetApplicationContext, invalid systemModule.");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
return systemModule->Get();
|
||||
return systemModule->GetNapiValue();
|
||||
}
|
||||
|
||||
NativeValue *JsApplicationContextUtils::CreateJsApplicationContext(
|
||||
NativeEngine &engine, const std::shared_ptr<Context> &context)
|
||||
napi_value JsApplicationContextUtils::CreateJsApplicationContext(
|
||||
napi_env env, const std::shared_ptr<Context> &context)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
|
||||
auto jsApplicationContextUtils = std::make_unique<JsApplicationContextUtils>(context);
|
||||
SetNamedNativePointer(engine, *object, APPLICATION_CONTEXT_NAME, jsApplicationContextUtils.release(),
|
||||
SetNamedNativePointer(env, object, APPLICATION_CONTEXT_NAME, jsApplicationContextUtils.release(),
|
||||
JsApplicationContextUtils::Finalizer);
|
||||
|
||||
auto appInfo = context->GetApplicationInfo();
|
||||
if (appInfo != nullptr) {
|
||||
object->SetProperty("applicationInfo", CreateJsApplicationInfo(engine, *appInfo));
|
||||
napi_set_named_property(env, object, "applicationInfo", CreateJsApplicationInfo(env, *appInfo));
|
||||
}
|
||||
|
||||
BindNativeApplicationContext(engine, object);
|
||||
BindNativeApplicationContext(env, object);
|
||||
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
|
||||
void JsApplicationContextUtils::BindNativeApplicationContext(NativeEngine &engine, NativeObject *object)
|
||||
void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_value object)
|
||||
{
|
||||
BindNativeProperty(*object, "cacheDir", JsApplicationContextUtils::GetCacheDir);
|
||||
BindNativeProperty(*object, "tempDir", JsApplicationContextUtils::GetTempDir);
|
||||
BindNativeProperty(*object, "filesDir", JsApplicationContextUtils::GetFilesDir);
|
||||
BindNativeProperty(*object, "distributedFilesDir", JsApplicationContextUtils::GetDistributedFilesDir);
|
||||
BindNativeProperty(*object, "databaseDir", JsApplicationContextUtils::GetDatabaseDir);
|
||||
BindNativeProperty(*object, "preferencesDir", JsApplicationContextUtils::GetPreferencesDir);
|
||||
BindNativeProperty(*object, "bundleCodeDir", JsApplicationContextUtils::GetBundleCodeDir);
|
||||
BindNativeFunction(engine, *object, "registerAbilityLifecycleCallback", MD_NAME,
|
||||
BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir);
|
||||
BindNativeProperty(env, object, "tempDir", JsApplicationContextUtils::GetTempDir);
|
||||
BindNativeProperty(env, object, "filesDir", JsApplicationContextUtils::GetFilesDir);
|
||||
BindNativeProperty(env, object, "distributedFilesDir", JsApplicationContextUtils::GetDistributedFilesDir);
|
||||
BindNativeProperty(env, object, "databaseDir", JsApplicationContextUtils::GetDatabaseDir);
|
||||
BindNativeProperty(env, object, "preferencesDir", JsApplicationContextUtils::GetPreferencesDir);
|
||||
BindNativeProperty(env, object, "bundleCodeDir", JsApplicationContextUtils::GetBundleCodeDir);
|
||||
BindNativeFunction(env, object, "registerAbilityLifecycleCallback", MD_NAME,
|
||||
JsApplicationContextUtils::RegisterAbilityLifecycleCallback);
|
||||
BindNativeFunction(engine, *object, "unregisterAbilityLifecycleCallback", MD_NAME,
|
||||
BindNativeFunction(env, object, "unregisterAbilityLifecycleCallback", MD_NAME,
|
||||
JsApplicationContextUtils::UnregisterAbilityLifecycleCallback);
|
||||
BindNativeFunction(engine, *object, "registerEnvironmentCallback", MD_NAME,
|
||||
BindNativeFunction(env, object, "registerEnvironmentCallback", MD_NAME,
|
||||
JsApplicationContextUtils::RegisterEnvironmentCallback);
|
||||
BindNativeFunction(engine, *object, "unregisterEnvironmentCallback", MD_NAME,
|
||||
BindNativeFunction(env, object, "unregisterEnvironmentCallback", MD_NAME,
|
||||
JsApplicationContextUtils::UnregisterEnvironmentCallback);
|
||||
BindNativeFunction(engine, *object, "createBundleContext", MD_NAME, JsApplicationContextUtils::CreateBundleContext);
|
||||
BindNativeFunction(engine, *object, "switchArea", MD_NAME, JsApplicationContextUtils::SwitchArea);
|
||||
BindNativeFunction(engine, *object, "getArea", MD_NAME, JsApplicationContextUtils::GetArea);
|
||||
BindNativeFunction(engine, *object, "createModuleContext", MD_NAME, JsApplicationContextUtils::CreateModuleContext);
|
||||
BindNativeFunction(engine, *object, "on", MD_NAME, JsApplicationContextUtils::On);
|
||||
BindNativeFunction(engine, *object, "off", MD_NAME, JsApplicationContextUtils::Off);
|
||||
BindNativeFunction(engine, *object, "getApplicationContext", MD_NAME,
|
||||
BindNativeFunction(env, object, "createBundleContext", MD_NAME, JsApplicationContextUtils::CreateBundleContext);
|
||||
BindNativeFunction(env, object, "switchArea", MD_NAME, JsApplicationContextUtils::SwitchArea);
|
||||
BindNativeFunction(env, object, "getArea", MD_NAME, JsApplicationContextUtils::GetArea);
|
||||
BindNativeFunction(env, object, "createModuleContext", MD_NAME, JsApplicationContextUtils::CreateModuleContext);
|
||||
BindNativeFunction(env, object, "on", MD_NAME, JsApplicationContextUtils::On);
|
||||
BindNativeFunction(env, object, "off", MD_NAME, JsApplicationContextUtils::Off);
|
||||
BindNativeFunction(env, object, "getApplicationContext", MD_NAME,
|
||||
JsApplicationContextUtils::GetApplicationContext);
|
||||
BindNativeFunction(engine, *object, "killAllProcesses", MD_NAME, JsApplicationContextUtils::KillProcessBySelf);
|
||||
BindNativeFunction(engine, *object, "getProcessRunningInformation", MD_NAME,
|
||||
BindNativeFunction(env, object, "killAllProcesses", MD_NAME, JsApplicationContextUtils::KillProcessBySelf);
|
||||
BindNativeFunction(env, object, "getProcessRunningInformation", MD_NAME,
|
||||
JsApplicationContextUtils::GetRunningProcessInformation);
|
||||
BindNativeFunction(engine, *object, "getRunningProcessInformation", MD_NAME,
|
||||
BindNativeFunction(env, object, "getRunningProcessInformation", MD_NAME,
|
||||
JsApplicationContextUtils::GetRunningProcessInformation);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
||||
@@ -27,24 +27,29 @@ constexpr uint32_t JS_CONSOLE_LOG_MAX_LOG_LEN = 1024;
|
||||
constexpr uint32_t JS_CONSOLE_LOG_DOMAIN = 0xFEFE;
|
||||
constexpr char JS_CONSOLE_LOG_TAG[] = "JsApp";
|
||||
|
||||
std::string MakeLogContent(NativeCallbackInfo &info)
|
||||
std::string MakeLogContent(napi_env env, napi_callback_info info)
|
||||
{
|
||||
std::string content;
|
||||
|
||||
for (size_t i = 0; i < info.argc; i++) {
|
||||
NativeValue *value = info.argv[i];
|
||||
if (value->TypeOf() != NATIVE_STRING) {
|
||||
value = value->ToString();
|
||||
size_t argc = ARGC_MAX_COUNT;
|
||||
napi_value argv[ARGC_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
napi_value value = argv[i];
|
||||
if (!CheckTypeForNapiValue(env, value, napi_string)) {
|
||||
napi_value resultStr = nullptr;
|
||||
napi_coerce_to_string(env, value, &resultStr);
|
||||
value = resultStr;
|
||||
}
|
||||
|
||||
NativeString *str = ConvertNativeValueTo<NativeString>(value);
|
||||
if (str == nullptr) {
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Failed to convert to string object");
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t bufferLen = str->GetLength();
|
||||
if (bufferLen >= JS_CONSOLE_LOG_MAX_LOG_LEN) {
|
||||
size_t bufferLen = 0;
|
||||
napi_status status = napi_get_value_string_utf8(env, value, nullptr, 0, &bufferLen);
|
||||
if (status != napi_ok || bufferLen == 0 || bufferLen >= JS_CONSOLE_LOG_MAX_LOG_LEN) {
|
||||
HILOG_DEBUG("Log length exceeds maximum");
|
||||
return content;
|
||||
}
|
||||
@@ -56,7 +61,7 @@ std::string MakeLogContent(NativeCallbackInfo &info)
|
||||
}
|
||||
|
||||
size_t strLen = 0;
|
||||
str->GetCString(buff, bufferLen + 1, &strLen);
|
||||
napi_get_value_string_utf8(env, value, buff, bufferLen + 1, &strLen);
|
||||
if (!content.empty()) {
|
||||
content.append(" ");
|
||||
}
|
||||
@@ -68,37 +73,37 @@ std::string MakeLogContent(NativeCallbackInfo &info)
|
||||
}
|
||||
|
||||
template<LogLevel LEVEL>
|
||||
NativeValue *ConsoleLog(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value ConsoleLog(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (engine == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("engine or callback info is nullptr");
|
||||
if (env == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("env or callback info is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string content = MakeLogContent(*info);
|
||||
std::string content = MakeLogContent(env, info);
|
||||
HiLogPrint(LOG_APP, LEVEL, JS_CONSOLE_LOG_DOMAIN, JS_CONSOLE_LOG_TAG, "%{public}s", content.c_str());
|
||||
|
||||
return engine->CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
|
||||
void InitConsoleLogModule(NativeEngine &engine, NativeObject &globalObject)
|
||||
void InitConsoleLogModule(napi_env env, napi_value globalObject)
|
||||
{
|
||||
NativeValue *consoleValue = engine.CreateObject();
|
||||
NativeObject *consoleObj = ConvertNativeValueTo<NativeObject>(consoleValue);
|
||||
napi_value consoleObj = nullptr;
|
||||
napi_create_object(env, &consoleObj);
|
||||
if (consoleObj == nullptr) {
|
||||
HILOG_ERROR("Failed to create console object");
|
||||
return;
|
||||
}
|
||||
const char *moduleName = "console";
|
||||
BindNativeFunction(engine, *consoleObj, "log", moduleName, ConsoleLog<LOG_INFO>);
|
||||
BindNativeFunction(engine, *consoleObj, "debug", moduleName, ConsoleLog<LOG_DEBUG>);
|
||||
BindNativeFunction(engine, *consoleObj, "info", moduleName, ConsoleLog<LOG_INFO>);
|
||||
BindNativeFunction(engine, *consoleObj, "warn", moduleName, ConsoleLog<LOG_WARN>);
|
||||
BindNativeFunction(engine, *consoleObj, "error", moduleName, ConsoleLog<LOG_ERROR>);
|
||||
BindNativeFunction(engine, *consoleObj, "fatal", moduleName, ConsoleLog<LOG_FATAL>);
|
||||
BindNativeFunction(env, consoleObj, "log", moduleName, ConsoleLog<LOG_INFO>);
|
||||
BindNativeFunction(env, consoleObj, "debug", moduleName, ConsoleLog<LOG_DEBUG>);
|
||||
BindNativeFunction(env, consoleObj, "info", moduleName, ConsoleLog<LOG_INFO>);
|
||||
BindNativeFunction(env, consoleObj, "warn", moduleName, ConsoleLog<LOG_WARN>);
|
||||
BindNativeFunction(env, consoleObj, "error", moduleName, ConsoleLog<LOG_ERROR>);
|
||||
BindNativeFunction(env, consoleObj, "fatal", moduleName, ConsoleLog<LOG_FATAL>);
|
||||
|
||||
globalObject.SetProperty("console", consoleValue);
|
||||
napi_set_named_property(env, globalObject, "console", consoleObj);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -31,296 +31,276 @@ public:
|
||||
explicit JsBaseContext(std::weak_ptr<Context> &&context) : context_(std::move(context)) {}
|
||||
virtual ~JsBaseContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine *engine, void *data, void *hint);
|
||||
static NativeValue *CreateBundleContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *SwitchArea(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetArea(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *CreateModuleContext(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static void Finalizer(napi_env env, void *data, void *hint);
|
||||
static napi_value CreateBundleContext(napi_env env, napi_callback_info info);
|
||||
static napi_value GetApplicationContext(napi_env env, napi_callback_info info);
|
||||
static napi_value SwitchArea(napi_env env, napi_callback_info info);
|
||||
static napi_value GetArea(napi_env env, napi_callback_info info);
|
||||
static napi_value CreateModuleContext(napi_env env, napi_callback_info info);
|
||||
|
||||
static NativeValue *GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetTempDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetFilesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetDistributedFilesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetDatabaseDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetPreferencesDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static NativeValue *GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info);
|
||||
static napi_value GetCacheDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetTempDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetFilesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDistributedFilesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDatabaseDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetPreferencesDir(napi_env env, napi_callback_info info);
|
||||
static napi_value GetBundleCodeDir(napi_env env, napi_callback_info info);
|
||||
|
||||
NativeValue *OnGetCacheDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetTempDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetFilesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetDistributedFilesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetDatabaseDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnSwitchArea(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetArea(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *OnGetApplicationContext(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetTempDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetFilesDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetDatabaseDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetPreferencesDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetBundleCodeDir(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnSwitchArea(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetArea(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo &info);
|
||||
|
||||
protected:
|
||||
std::weak_ptr<Context> context_;
|
||||
};
|
||||
|
||||
void JsBaseContext::Finalizer(NativeEngine *engine, void *data, void *hint)
|
||||
void JsBaseContext::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
std::unique_ptr<JsBaseContext>(static_cast<JsBaseContext*>(data));
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::CreateBundleContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::CreateBundleContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetApplicationContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetApplicationContext(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetApplicationContext, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::SwitchArea(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::SwitchArea(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnSwitchArea(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnSwitchArea, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnSwitchArea(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnSwitchArea(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
if (info.argc == 0) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
int mode = 0;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], mode)) {
|
||||
if (!ConvertFromJsValue(env, info.argv[0], mode)) {
|
||||
HILOG_ERROR("Parse mode failed");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
context->SwitchArea(mode);
|
||||
|
||||
NativeValue *thisVar = info.thisVar;
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(thisVar);
|
||||
napi_value object = info.thisVar;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("object is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
BindNativeProperty(*object, "cacheDir", GetCacheDir);
|
||||
BindNativeProperty(*object, "tempDir", GetTempDir);
|
||||
BindNativeProperty(*object, "filesDir", GetFilesDir);
|
||||
BindNativeProperty(*object, "distributedFilesDir", GetDistributedFilesDir);
|
||||
BindNativeProperty(*object, "databaseDir", GetDatabaseDir);
|
||||
BindNativeProperty(*object, "preferencesDir", GetPreferencesDir);
|
||||
BindNativeProperty(*object, "bundleCodeDir", GetBundleCodeDir);
|
||||
return engine.CreateUndefined();
|
||||
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
|
||||
BindNativeProperty(env, object, "tempDir", GetTempDir);
|
||||
BindNativeProperty(env, object, "filesDir", GetFilesDir);
|
||||
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
|
||||
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
|
||||
BindNativeProperty(env, object, "preferencesDir", GetPreferencesDir);
|
||||
BindNativeProperty(env, object, "bundleCodeDir", GetBundleCodeDir);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::CreateModuleContext(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::CreateModuleContext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetArea(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetArea(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetArea(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetArea, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetArea(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetArea(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
int area = context->GetArea();
|
||||
return engine.CreateNumber(area);
|
||||
return CreateJsValue(env, area);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetCacheDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetCacheDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetCacheDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetCacheDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetCacheDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetCacheDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetTempDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetTempDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetTempDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetTempDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetTempDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetTempDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetTempDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetFilesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetFilesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetFilesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetFilesDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetFilesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetFilesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetFilesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetDistributedFilesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetDistributedFilesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetDistributedFilesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetDistributedFilesDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetDistributedFilesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetDistributedFilesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetDatabaseDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetDatabaseDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetDatabaseDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetDatabaseDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetDatabaseDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetDatabaseDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetDatabaseDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetPreferencesDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetPreferencesDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetPreferencesDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetPreferencesDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetPreferencesDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetPreferencesDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value JsBaseContext::GetBundleCodeDir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
JsBaseContext *me = CheckParamsAndGetThis<JsBaseContext>(engine, info, BASE_CONTEXT_NAME);
|
||||
return me != nullptr ? me->OnGetBundleCodeDir(*engine, *info) : nullptr;
|
||||
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetBundleCodeDir, BASE_CONTEXT_NAME);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetBundleCodeDir(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetBundleCodeDir();
|
||||
return engine.CreateString(path.c_str(), path.length());
|
||||
return CreateJsValue(env, path);
|
||||
}
|
||||
|
||||
NativeValue *JsBaseContext::OnGetApplicationContext(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
napi_value JsBaseContext::OnGetApplicationContext(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
NativeValue *value = JsApplicationContextUtils::CreateJsApplicationContext(engine, context_.lock());
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(&engine, "application.ApplicationContext", &value, 1);
|
||||
napi_value value = JsApplicationContextUtils::CreateJsApplicationContext(env, context_.lock());
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.ApplicationContext", &value, 1);
|
||||
if (systemModule == nullptr) {
|
||||
return engine.CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
auto contextObj = systemModule->Get();
|
||||
auto contextObj = systemModule->GetNapiValue();
|
||||
return contextObj;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
NativeValue *CreateJsBaseContext(NativeEngine &engine, std::shared_ptr<Context> context, bool keepContext)
|
||||
napi_value CreateJsBaseContext(napi_env env, std::shared_ptr<Context> context, bool keepContext)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_WARN("invalid object.");
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
|
||||
auto appInfo = context->GetApplicationInfo();
|
||||
if (appInfo != nullptr) {
|
||||
object->SetProperty("applicationInfo", CreateJsApplicationInfo(engine, *appInfo));
|
||||
napi_set_named_property(env, object, "applicationInfo", CreateJsApplicationInfo(env, *appInfo));
|
||||
}
|
||||
auto hapModuleInfo = context->GetHapModuleInfo();
|
||||
if (hapModuleInfo != nullptr) {
|
||||
object->SetProperty("currentHapModuleInfo", CreateJsHapModuleInfo(engine, *hapModuleInfo));
|
||||
napi_set_named_property(env, object, "currentHapModuleInfo", CreateJsHapModuleInfo(env, *hapModuleInfo));
|
||||
}
|
||||
|
||||
auto jsContext = std::make_unique<JsBaseContext>(context);
|
||||
SetNamedNativePointer(engine, *object, BASE_CONTEXT_NAME, jsContext.release(), JsBaseContext::Finalizer);
|
||||
SetNamedNativePointer(env, object, BASE_CONTEXT_NAME, jsContext.release(), JsBaseContext::Finalizer);
|
||||
|
||||
BindNativeProperty(*object, "cacheDir", JsBaseContext::GetCacheDir);
|
||||
BindNativeProperty(*object, "tempDir", JsBaseContext::GetTempDir);
|
||||
BindNativeProperty(*object, "filesDir", JsBaseContext::GetFilesDir);
|
||||
BindNativeProperty(*object, "distributedFilesDir", JsBaseContext::GetDistributedFilesDir);
|
||||
BindNativeProperty(*object, "databaseDir", JsBaseContext::GetDatabaseDir);
|
||||
BindNativeProperty(*object, "preferencesDir", JsBaseContext::GetPreferencesDir);
|
||||
BindNativeProperty(*object, "bundleCodeDir", JsBaseContext::GetBundleCodeDir);
|
||||
BindNativeProperty(*object, "area", JsBaseContext::GetArea);
|
||||
BindNativeProperty(env, object, "cacheDir", JsBaseContext::GetCacheDir);
|
||||
BindNativeProperty(env, object, "tempDir", JsBaseContext::GetTempDir);
|
||||
BindNativeProperty(env, object, "filesDir", JsBaseContext::GetFilesDir);
|
||||
BindNativeProperty(env, object, "distributedFilesDir", JsBaseContext::GetDistributedFilesDir);
|
||||
BindNativeProperty(env, object, "databaseDir", JsBaseContext::GetDatabaseDir);
|
||||
BindNativeProperty(env, object, "preferencesDir", JsBaseContext::GetPreferencesDir);
|
||||
BindNativeProperty(env, object, "bundleCodeDir", JsBaseContext::GetBundleCodeDir);
|
||||
BindNativeProperty(env, object, "area", JsBaseContext::GetArea);
|
||||
const char *moduleName = "JsBaseContext";
|
||||
BindNativeFunction(engine, *object, "createBundleContext", moduleName, JsBaseContext::CreateBundleContext);
|
||||
BindNativeFunction(engine, *object, "getApplicationContext", moduleName, JsBaseContext::GetApplicationContext);
|
||||
BindNativeFunction(engine, *object, "switchArea", moduleName, JsBaseContext::SwitchArea);
|
||||
BindNativeFunction(engine, *object, "getArea", moduleName, JsBaseContext::GetArea);
|
||||
BindNativeFunction(engine, *object, "createModuleContext", moduleName, JsBaseContext::CreateModuleContext);
|
||||
BindNativeFunction(env, object, "createBundleContext", moduleName, JsBaseContext::CreateBundleContext);
|
||||
BindNativeFunction(env, object, "getApplicationContext", moduleName, JsBaseContext::GetApplicationContext);
|
||||
BindNativeFunction(env, object, "switchArea", moduleName, JsBaseContext::SwitchArea);
|
||||
BindNativeFunction(env, object, "getArea", moduleName, JsBaseContext::GetArea);
|
||||
BindNativeFunction(env, object, "createModuleContext", moduleName, JsBaseContext::CreateModuleContext);
|
||||
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -92,73 +92,74 @@ Global::Resource::Direction ConvertDirection(const std::string &direction)
|
||||
return resolution;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsConfiguration(NativeEngine &engine, const AppExecFwk::Configuration &configuration)
|
||||
napi_value CreateJsConfiguration(napi_env env, const AppExecFwk::Configuration &configuration)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Native object is nullptr.");
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
|
||||
object->SetProperty("language", CreateJsValue(engine,
|
||||
napi_set_named_property(env, object, "language", CreateJsValue(env,
|
||||
configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)));
|
||||
|
||||
object->SetProperty("colorMode", CreateJsValue(engine,
|
||||
|
||||
napi_set_named_property(env, object, "colorMode", CreateJsValue(env,
|
||||
ConvertColorMode(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE))));
|
||||
|
||||
std::string direction = configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION);
|
||||
object->SetProperty("direction", CreateJsValue(engine, ConvertDirection(direction)));
|
||||
napi_set_named_property(env, object, "direction", CreateJsValue(env, ConvertDirection(direction)));
|
||||
|
||||
std::string density = configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI);
|
||||
object->SetProperty("screenDensity", CreateJsValue(engine, ConvertDensity(density)));
|
||||
napi_set_named_property(env, object, "screenDensity", CreateJsValue(env, ConvertDensity(density)));
|
||||
|
||||
int32_t displayId = ConvertDisplayId(configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID));
|
||||
object->SetProperty("displayId", CreateJsValue(engine, displayId));
|
||||
napi_set_named_property(env, object, "displayId", CreateJsValue(env, displayId));
|
||||
|
||||
std::string hasPointerDevice = configuration.GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
|
||||
object->SetProperty("hasPointerDevice", CreateJsValue(engine, hasPointerDevice == "true" ? true : false));
|
||||
napi_set_named_property(
|
||||
env, object, "hasPointerDevice", CreateJsValue(env, hasPointerDevice == "true" ? true : false));
|
||||
|
||||
return objValue;
|
||||
return object;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsApplicationInfo(NativeEngine &engine, const AppExecFwk::ApplicationInfo &applicationInfo)
|
||||
napi_value CreateJsApplicationInfo(napi_env env, const AppExecFwk::ApplicationInfo &applicationInfo)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
if (objValue == nullptr) {
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Create object failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AppExecFwk::CommonFunc::ConvertApplicationInfo(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(objValue), applicationInfo);
|
||||
return objValue;
|
||||
AppExecFwk::CommonFunc::ConvertApplicationInfo(env, object, applicationInfo);
|
||||
return object;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsHapModuleInfo(NativeEngine &engine, const AppExecFwk::HapModuleInfo &hapModuleInfo)
|
||||
napi_value CreateJsHapModuleInfo(napi_env env, const AppExecFwk::HapModuleInfo &hapModuleInfo)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
if (objValue == nullptr) {
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Create object failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AppExecFwk::CommonFunc::ConvertHapModuleInfo(reinterpret_cast<napi_env>(&engine), hapModuleInfo,
|
||||
reinterpret_cast<napi_value>(objValue));
|
||||
return objValue;
|
||||
AppExecFwk::CommonFunc::ConvertHapModuleInfo(env, hapModuleInfo, object);
|
||||
return object;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsAbilityInfo(NativeEngine &engine, const AppExecFwk::AbilityInfo &abilityInfo)
|
||||
napi_value CreateJsAbilityInfo(napi_env env, const AppExecFwk::AbilityInfo &abilityInfo)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
if (objValue == nullptr) {
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Create object failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AppExecFwk::CommonFunc::ConvertAbilityInfo(reinterpret_cast<napi_env>(&engine), abilityInfo,
|
||||
reinterpret_cast<napi_value>(objValue));
|
||||
return objValue;
|
||||
AppExecFwk::CommonFunc::ConvertAbilityInfo(env, abilityInfo, object);
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue *CreateJsResourceManager(NativeEngine &engine,
|
||||
napi_value CreateJsResourceManager(napi_env env,
|
||||
std::shared_ptr<Global::Resource::ResourceManager> resourceManager, std::shared_ptr<Context> context)
|
||||
{
|
||||
napi_env env = reinterpret_cast<napi_env>(&engine);
|
||||
napi_value result = Global::Resource::ResourceManagerAddon::Create(env, "", resourceManager, context);
|
||||
return reinterpret_cast<NativeValue*>(result);
|
||||
return result;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -37,10 +37,16 @@ std::unordered_map<uint32_t, std::shared_ptr<JsTimer>> g_timerTable;
|
||||
|
||||
class JsTimer final {
|
||||
public:
|
||||
JsTimer(NativeEngine &nativeEngine, const std::shared_ptr<NativeReference> &jsFunction, uint32_t id)
|
||||
: nativeEngine_(nativeEngine), jsFunction_(jsFunction), id_(id)
|
||||
JsTimer(napi_env env, const std::shared_ptr<NativeReference> &jsFunction, uint32_t id)
|
||||
: env_(env), jsFunction_(jsFunction), id_(id)
|
||||
{
|
||||
uv_timer_init(nativeEngine.GetUVLoop(), &timerReq_);
|
||||
uv_loop_s* loop = nullptr;
|
||||
napi_get_uv_event_loop(env_, &loop);
|
||||
if (loop == nullptr) {
|
||||
HILOG_ERROR("loop == nullptr.");
|
||||
return;
|
||||
}
|
||||
uv_timer_init(loop, &timerReq_);
|
||||
timerReq_.data = this;
|
||||
}
|
||||
|
||||
@@ -59,12 +65,14 @@ public:
|
||||
|
||||
void OnTimeout()
|
||||
{
|
||||
std::vector<NativeValue*> args;
|
||||
std::vector<napi_value> args;
|
||||
args.reserve(jsArgs_.size());
|
||||
for (auto arg : jsArgs_) {
|
||||
args.emplace_back(arg->Get());
|
||||
args.emplace_back(arg->GetNapiValue());
|
||||
}
|
||||
nativeEngine_.CallFunction(nativeEngine_.CreateUndefined(), jsFunction_->Get(), args.data(), args.size());
|
||||
napi_value res = nullptr;
|
||||
napi_call_function(env_, CreateJsUndefined(env_),
|
||||
jsFunction_->GetNapiValue(), args.size(), args.data(), &res);
|
||||
|
||||
if (uv_timer_get_repeat(&timerReq_) == 0) {
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
@@ -78,34 +86,44 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
NativeEngine& nativeEngine_;
|
||||
napi_env env_;
|
||||
std::shared_ptr<NativeReference> jsFunction_;
|
||||
std::vector<std::shared_ptr<NativeReference>> jsArgs_;
|
||||
uv_timer_t timerReq_;
|
||||
uint32_t id_ = 0;
|
||||
};
|
||||
|
||||
NativeValue *StartTimeoutOrInterval(NativeEngine *engine, NativeCallbackInfo *info, bool isInterval)
|
||||
napi_value StartTimeoutOrInterval(napi_env env, napi_callback_info info, bool isInterval)
|
||||
{
|
||||
if (engine == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("Start timeout or interval failed with engine or callback info is nullptr.");
|
||||
if (env == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("Start timeout or interval failed with env or callback info is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
size_t argc = ARGC_MAX_COUNT;
|
||||
napi_value argv[ARGC_MAX_COUNT] = {nullptr};
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
|
||||
|
||||
// parameter check, must have at least 2 params
|
||||
if (info->argc < 2 || info->argv[0]->TypeOf() != NATIVE_FUNCTION || info->argv[1]->TypeOf() != NATIVE_NUMBER) {
|
||||
if (argc < 2 ||!CheckTypeForNapiValue(env, argv[0], napi_function)
|
||||
|| !CheckTypeForNapiValue(env, argv[1], napi_number)) {
|
||||
HILOG_ERROR("Set callback timer failed with invalid parameter.");
|
||||
return engine->CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
// parse parameter
|
||||
std::shared_ptr<NativeReference> jsFunction(engine->CreateReference(info->argv[0], 1));
|
||||
int64_t delayTime = *ConvertNativeValueTo<NativeNumber>(info->argv[1]);
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env, argv[0], 1, &ref);
|
||||
std::shared_ptr<NativeReference> jsFunction(reinterpret_cast<NativeReference*>(ref));
|
||||
int64_t delayTime = 0;
|
||||
napi_get_value_int64(env, argv[1], &delayTime);
|
||||
uint32_t callbackId = g_callbackId.fetch_add(1, std::memory_order_relaxed);
|
||||
|
||||
auto task = std::make_shared<JsTimer>(*engine, jsFunction, callbackId);
|
||||
for (size_t index = 2; index < info->argc; ++index) {
|
||||
task->PushArgs(std::shared_ptr<NativeReference>(engine->CreateReference(info->argv[index], 1)));
|
||||
auto task = std::make_shared<JsTimer>(env, jsFunction, callbackId);
|
||||
for (size_t index = 2; index < argc; ++index) {
|
||||
napi_ref taskRef = nullptr;
|
||||
napi_create_reference(env, argv[index], 1, &taskRef);
|
||||
task->PushArgs(std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(taskRef)));
|
||||
}
|
||||
|
||||
// if setInterval is called, interval must not be zero for repeat, so set to 1ms
|
||||
@@ -120,48 +138,52 @@ NativeValue *StartTimeoutOrInterval(NativeEngine *engine, NativeCallbackInfo *in
|
||||
g_timerTable.emplace(callbackId, task);
|
||||
}
|
||||
|
||||
return engine->CreateNumber(callbackId);
|
||||
return CreateJsValue(env, callbackId);
|
||||
}
|
||||
|
||||
NativeValue *StartTimeout(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value StartTimeout(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return StartTimeoutOrInterval(engine, info, false);
|
||||
return StartTimeoutOrInterval(env, info, false);
|
||||
}
|
||||
|
||||
NativeValue *StartInterval(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value StartInterval(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return StartTimeoutOrInterval(engine, info, true);
|
||||
return StartTimeoutOrInterval(env, info, true);
|
||||
}
|
||||
|
||||
NativeValue *StopTimeoutOrInterval(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
napi_value StopTimeoutOrInterval(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (engine == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("Stop timeout or interval failed with engine or callback info is nullptr.");
|
||||
if (env == nullptr || info == nullptr) {
|
||||
HILOG_ERROR("Stop timeout or interval failed with env or callback info is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
size_t argc = ARGC_MAX_COUNT;
|
||||
napi_value argv[ARGC_MAX_COUNT] = {nullptr};
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
|
||||
|
||||
// parameter check, must have at least 1 param
|
||||
if (info->argc < 1 || info->argv[0]->TypeOf() != NATIVE_NUMBER) {
|
||||
if (argc < 1 || !CheckTypeForNapiValue(env, argv[0], napi_number)) {
|
||||
HILOG_ERROR("Clear callback timer failed with invalid parameter.");
|
||||
return engine->CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
uint32_t callbackId = *ConvertNativeValueTo<NativeNumber>(info->argv[0]);
|
||||
uint32_t callbackId = 0;
|
||||
napi_get_value_uint32(env, argv[0], &callbackId);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
g_timerTable.erase(callbackId);
|
||||
}
|
||||
return engine->CreateUndefined();
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
|
||||
void InitTimer(NativeEngine &engine, NativeObject &globalObject)
|
||||
void InitTimer(napi_env env, napi_value globalObject)
|
||||
{
|
||||
const char *moduleName = "AsJsTimer";
|
||||
BindNativeFunction(engine, globalObject, "setTimeout", moduleName, StartTimeout);
|
||||
BindNativeFunction(engine, globalObject, "setInterval", moduleName, StartInterval);
|
||||
BindNativeFunction(engine, globalObject, "clearTimeout", moduleName, StopTimeoutOrInterval);
|
||||
BindNativeFunction(engine, globalObject, "clearInterval", moduleName, StopTimeoutOrInterval);
|
||||
BindNativeFunction(env, globalObject, "setTimeout", moduleName, StartTimeout);
|
||||
BindNativeFunction(env, globalObject, "setInterval", moduleName, StartInterval);
|
||||
BindNativeFunction(env, globalObject, "clearTimeout", moduleName, StopTimeoutOrInterval);
|
||||
BindNativeFunction(env, globalObject, "clearInterval", moduleName, StopTimeoutOrInterval);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -101,25 +101,26 @@ public:
|
||||
private:
|
||||
bool OnInit();
|
||||
void Run();
|
||||
NativeValue *LoadScript(const std::string &srcPath);
|
||||
napi_value LoadScript(const std::string &srcPath);
|
||||
void InitResourceMgr();
|
||||
void InitJsAbilityContext(NativeValue *instanceValue);
|
||||
void DispatchStartLifecycle(NativeValue *instanceValue);
|
||||
void InitJsAbilityContext(napi_env env, napi_value instanceValue);
|
||||
void DispatchStartLifecycle(napi_value instanceValue);
|
||||
std::unique_ptr<NativeReference> CreateJsWindowStage(const std::shared_ptr<Rosen::WindowScene> &windowScene);
|
||||
NativeValue *CreateJsWant(NativeEngine &engine);
|
||||
napi_value CreateJsWant(napi_env env);
|
||||
bool LoadAbilityStage(uint8_t *buffer, size_t len);
|
||||
void InitJsAbilityStageContext(NativeValue *instanceValue);
|
||||
NativeValue *CreateJsLaunchParam(NativeEngine &engine);
|
||||
void InitJsAbilityStageContext(napi_value instanceValue);
|
||||
napi_value CreateJsLaunchParam(napi_env env);
|
||||
bool ParseBundleAndModuleInfo();
|
||||
bool ParseAbilityInfo(const std::string &abilitySrcPath);
|
||||
bool LoadRuntimeEnv(NativeEngine &nativeEngine, NativeObject &globalObject);
|
||||
bool LoadRuntimeEnv(napi_env env, napi_value globalObject);
|
||||
static napi_value RequireNapi(napi_env env, napi_callback_info info);
|
||||
|
||||
panda::ecmascript::EcmaVM *CreateJSVM();
|
||||
Options options_;
|
||||
std::string abilityPath_;
|
||||
panda::ecmascript::EcmaVM *vm_ = nullptr;
|
||||
DebuggerTask debuggerTask_;
|
||||
std::unique_ptr<NativeEngine> nativeEngine_;
|
||||
napi_env nativeEngine_ = nullptr;
|
||||
|
||||
int64_t currentId_ = 0;
|
||||
std::unordered_map<int64_t, std::shared_ptr<NativeReference>> abilities_;
|
||||
@@ -159,11 +160,12 @@ SimulatorImpl::~SimulatorImpl()
|
||||
{
|
||||
if (nativeEngine_) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&debuggerTask_.onPostTaskSignal), nullptr);
|
||||
uv_loop_t *uvLoop = nativeEngine_->GetUVLoop();
|
||||
uv_loop_t* uvLoop = nullptr;
|
||||
napi_get_uv_event_loop(nativeEngine_, &uvLoop);
|
||||
if (uvLoop != nullptr) {
|
||||
uv_work_t work;
|
||||
uv_queue_work(uvLoop, &work, [](uv_work_t*) {}, [](uv_work_t *work, int32_t status) {
|
||||
HILOG_DEBUG("Simulator stop uv loop");
|
||||
HILOG_ERROR("Simulator stop uv loop");
|
||||
uv_stop(work->loop);
|
||||
});
|
||||
}
|
||||
@@ -172,7 +174,7 @@ SimulatorImpl::~SimulatorImpl()
|
||||
panda::JSNApi::StopDebugger(vm_);
|
||||
|
||||
abilities_.clear();
|
||||
nativeEngine_.reset();
|
||||
nativeEngine_ = nullptr;
|
||||
panda::JSNApi::DestroyJSVM(vm_);
|
||||
vm_ = nullptr;
|
||||
}
|
||||
@@ -180,7 +182,7 @@ SimulatorImpl::~SimulatorImpl()
|
||||
bool SimulatorImpl::Initialize(const Options &options)
|
||||
{
|
||||
if (nativeEngine_) {
|
||||
HILOG_DEBUG("Simulator is already initialized");
|
||||
HILOG_ERROR("Simulator is already initialized");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,7 +191,8 @@ bool SimulatorImpl::Initialize(const Options &options)
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_loop_t *uvLoop = nativeEngine_->GetUVLoop();
|
||||
uv_loop_t* uvLoop = nullptr;
|
||||
napi_get_uv_event_loop(nativeEngine_, &uvLoop);
|
||||
if (uvLoop == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -201,23 +204,25 @@ bool SimulatorImpl::Initialize(const Options &options)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CallObjectMethod(NativeEngine &engine, NativeValue *value, const char *name, NativeValue *const *argv, size_t argc)
|
||||
void CallObjectMethod(napi_env env, napi_value obj, const char *name, napi_value const *argv, size_t argc)
|
||||
{
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("%{public}s, Failed to get Ability object", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *methodOnCreate = obj->GetProperty(name);
|
||||
napi_value methodOnCreate = nullptr;
|
||||
napi_get_named_property(env, obj, name, &methodOnCreate);
|
||||
if (methodOnCreate == nullptr) {
|
||||
HILOG_ERROR("Failed to get '%{public}s' from Ability object", name);
|
||||
return;
|
||||
}
|
||||
engine.CallFunction(value, methodOnCreate, argv, argc);
|
||||
napi_status status = napi_call_function(env, obj, methodOnCreate, argc, argv, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("Failed to napi call function");
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue *SimulatorImpl::LoadScript(const std::string &srcPath)
|
||||
napi_value SimulatorImpl::LoadScript(const std::string &srcPath)
|
||||
{
|
||||
panda::Local<panda::ObjectRef> objRef = panda::JSNApi::GetExportObject(vm_, srcPath, "default");
|
||||
if (objRef->IsNull()) {
|
||||
@@ -225,8 +230,10 @@ NativeValue *SimulatorImpl::LoadScript(const std::string &srcPath)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto obj = ArkNativeEngine::ArkValueToNativeValue(static_cast<ArkNativeEngine*>(nativeEngine_.get()), objRef);
|
||||
return nativeEngine_->CreateInstance(obj, nullptr, 0);
|
||||
auto obj = ArkNativeEngine::ArkValueToNapiValue(nativeEngine_, objRef);
|
||||
napi_value instanceValue = nullptr;
|
||||
napi_new_instance(nativeEngine_, obj, 0, nullptr, &instanceValue);
|
||||
return instanceValue;
|
||||
}
|
||||
|
||||
bool SimulatorImpl::ParseBundleAndModuleInfo()
|
||||
@@ -326,12 +333,12 @@ int64_t SimulatorImpl::StartAbility(const std::string &abilitySrcPath, Terminate
|
||||
}
|
||||
|
||||
abilityPath_ = BUNDLE_INSTALL_PATH + options_.moduleName + "/" + abilitySrcPath;
|
||||
if (!nativeEngine_->RunScriptBuffer(abilityPath_, buf, len, false)) {
|
||||
if (!reinterpret_cast<NativeEngine*>(nativeEngine_)->RunScriptBuffer(abilityPath_, buf, len, false)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", abilityPath_.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
NativeValue *instanceValue = LoadScript(abilityPath_);
|
||||
napi_value instanceValue = LoadScript(abilityPath_);
|
||||
if (instanceValue == nullptr) {
|
||||
HILOG_ERROR("Failed to create object instance");
|
||||
return -1;
|
||||
@@ -339,9 +346,11 @@ int64_t SimulatorImpl::StartAbility(const std::string &abilitySrcPath, Terminate
|
||||
|
||||
++currentId_;
|
||||
InitResourceMgr();
|
||||
InitJsAbilityContext(instanceValue);
|
||||
InitJsAbilityContext(nativeEngine_, instanceValue);
|
||||
DispatchStartLifecycle(instanceValue);
|
||||
abilities_.emplace(currentId_, nativeEngine_->CreateReference(instanceValue, 1));
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(nativeEngine_, instanceValue, 1, &ref);
|
||||
abilities_.emplace(currentId_, std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref)));
|
||||
return currentId_;
|
||||
}
|
||||
|
||||
@@ -368,56 +377,56 @@ bool SimulatorImpl::LoadAbilityStage(uint8_t *buffer, size_t len)
|
||||
|
||||
auto moduleSrcPath = BUNDLE_INSTALL_PATH + options_.moduleName + "/" + srcEntrance;
|
||||
HILOG_DEBUG("moduleSrcPath is %{public}s", moduleSrcPath.c_str());
|
||||
if (!nativeEngine_->RunScriptBuffer(moduleSrcPath, buffer, len, false)) {
|
||||
if (!reinterpret_cast<NativeEngine*>(nativeEngine_)->RunScriptBuffer(moduleSrcPath, buffer, len, false)) {
|
||||
HILOG_ERROR("Failed to run ability stage script: %{public}s", moduleSrcPath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
NativeValue *instanceValue = LoadScript(moduleSrcPath);
|
||||
napi_value instanceValue = LoadScript(moduleSrcPath);
|
||||
if (instanceValue == nullptr) {
|
||||
HILOG_ERROR("Failed to create ability stage instance");
|
||||
return false;
|
||||
}
|
||||
|
||||
InitJsAbilityStageContext(instanceValue);
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onCreate", nullptr, 0);
|
||||
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onCreate", nullptr, 0);
|
||||
NativeValue *wantArgv[] = {
|
||||
CreateJsWant(*nativeEngine_)
|
||||
napi_value wantArgv[] = {
|
||||
CreateJsWant(nativeEngine_)
|
||||
};
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onAcceptWant", wantArgv, ArraySize(wantArgv));
|
||||
|
||||
abilityStage_ = std::shared_ptr<NativeReference>(nativeEngine_->CreateReference(instanceValue, 1));
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onAcceptWant", wantArgv, ArraySize(wantArgv));
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(nativeEngine_, instanceValue, 1, &ref);
|
||||
abilityStage_ = std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref));
|
||||
return true;
|
||||
}
|
||||
|
||||
void SimulatorImpl::InitJsAbilityStageContext(NativeValue *instanceValue)
|
||||
void SimulatorImpl::InitJsAbilityStageContext(napi_value obj)
|
||||
{
|
||||
NativeValue *contextObj = CreateJsAbilityStageContext(*nativeEngine_, stageContext_);
|
||||
napi_value contextObj = CreateJsAbilityStageContext(nativeEngine_, stageContext_);
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("contextObj is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
jsStageContext_ = std::shared_ptr<NativeReference>(
|
||||
JsRuntime::LoadSystemModuleByEngine(nativeEngine_.get(), "application.AbilityStageContext", &contextObj, 1));
|
||||
JsRuntime::LoadSystemModuleByEngine(nativeEngine_, "application.AbilityStageContext", &contextObj, 1));
|
||||
if (jsStageContext_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get LoadSystemModuleByEngine");
|
||||
return;
|
||||
}
|
||||
|
||||
contextObj = jsStageContext_->Get();
|
||||
contextObj = jsStageContext_->GetNapiValue();
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("contextObj is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(instanceValue);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("obj is nullptr");
|
||||
return;
|
||||
}
|
||||
obj->SetProperty("context", contextObj);
|
||||
napi_set_named_property(nativeEngine_, obj, "context", contextObj);
|
||||
}
|
||||
|
||||
void SimulatorImpl::TerminateAbility(int64_t abilityId)
|
||||
@@ -435,14 +444,14 @@ void SimulatorImpl::TerminateAbility(int64_t abilityId)
|
||||
std::shared_ptr<NativeReference> ref = it->second;
|
||||
abilities_.erase(it);
|
||||
|
||||
auto instanceValue = ref->Get();
|
||||
auto instanceValue = ref->GetNapiValue();
|
||||
if (instanceValue == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onBackground", nullptr, 0);
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onWindowStageDestroy", nullptr, 0);
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onDestroy", nullptr, 0);
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onBackground", nullptr, 0);
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onWindowStageDestroy", nullptr, 0);
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onDestroy", nullptr, 0);
|
||||
|
||||
auto windowSceneIter = windowScenes_.find(abilityId);
|
||||
if (windowSceneIter != windowScenes_.end()) {
|
||||
@@ -477,29 +486,29 @@ void SimulatorImpl::UpdateConfiguration(const AppExecFwk::Configuration &config)
|
||||
stageContext_->SetConfiguration(configuration);
|
||||
}
|
||||
|
||||
NativeValue *configArgv[] = {
|
||||
CreateJsConfiguration(*nativeEngine_, config)
|
||||
napi_value configArgv[] = {
|
||||
CreateJsConfiguration(nativeEngine_, config)
|
||||
};
|
||||
|
||||
auto abilityStage = abilityStage_->Get();
|
||||
auto abilityStage = abilityStage_->GetNapiValue();
|
||||
if (abilityStage == nullptr) {
|
||||
HILOG_ERROR("abilityStage is nullptr");
|
||||
return;
|
||||
}
|
||||
CallObjectMethod(*nativeEngine_, abilityStage, "onConfigurationUpdated", configArgv, ArraySize(configArgv));
|
||||
CallObjectMethod(*nativeEngine_, abilityStage, "onConfigurationUpdate", configArgv, ArraySize(configArgv));
|
||||
JsAbilityStageContext::ConfigurationUpdated(nativeEngine_.get(), jsStageContext_, configuration);
|
||||
CallObjectMethod(nativeEngine_, abilityStage, "onConfigurationUpdated", configArgv, ArraySize(configArgv));
|
||||
CallObjectMethod(nativeEngine_, abilityStage, "onConfigurationUpdate", configArgv, ArraySize(configArgv));
|
||||
JsAbilityStageContext::ConfigurationUpdated(nativeEngine_, jsStageContext_, configuration);
|
||||
|
||||
for (auto iter = abilities_.begin(); iter != abilities_.end(); iter++) {
|
||||
auto ability = iter->second->Get();
|
||||
auto ability = iter->second->GetNapiValue();
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("ability is nullptr");
|
||||
continue;
|
||||
}
|
||||
|
||||
CallObjectMethod(*nativeEngine_, ability, "onConfigurationUpdated", configArgv, ArraySize(configArgv));
|
||||
CallObjectMethod(*nativeEngine_, ability, "onConfigurationUpdate", configArgv, ArraySize(configArgv));
|
||||
JsAbilityContext::ConfigurationUpdated(nativeEngine_.get(), iter->second, configuration);
|
||||
CallObjectMethod(nativeEngine_, ability, "onConfigurationUpdated", configArgv, ArraySize(configArgv));
|
||||
CallObjectMethod(nativeEngine_, ability, "onConfigurationUpdate", configArgv, ArraySize(configArgv));
|
||||
JsAbilityContext::ConfigurationUpdated(nativeEngine_, iter->second, configuration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +533,7 @@ void SimulatorImpl::InitResourceMgr()
|
||||
HILOG_DEBUG("Add resource success.");
|
||||
}
|
||||
|
||||
void SimulatorImpl::InitJsAbilityContext(NativeValue *instanceValue)
|
||||
void SimulatorImpl::InitJsAbilityContext(napi_env env, napi_value obj)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
context_ = std::make_shared<AbilityContext>();
|
||||
@@ -534,66 +543,67 @@ void SimulatorImpl::InitJsAbilityContext(NativeValue *instanceValue)
|
||||
context_->SetResourceManager(resourceMgr_);
|
||||
context_->SetAbilityInfo(abilityInfo_);
|
||||
}
|
||||
NativeValue *contextObj = CreateJsAbilityContext(*nativeEngine_, context_);
|
||||
napi_value contextObj = CreateJsAbilityContext(nativeEngine_, context_);
|
||||
auto systemModule = std::shared_ptr<NativeReference>(
|
||||
JsRuntime::LoadSystemModuleByEngine(nativeEngine_.get(), "application.AbilityContext", &contextObj, 1));
|
||||
JsRuntime::LoadSystemModuleByEngine(nativeEngine_, "application.AbilityContext", &contextObj, 1));
|
||||
if (systemModule == nullptr) {
|
||||
HILOG_ERROR("systemModule is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
contextObj = systemModule->Get();
|
||||
contextObj = systemModule->GetNapiValue();
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("contextObj is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(instanceValue);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("obj is nullptr");
|
||||
return;
|
||||
}
|
||||
obj->SetProperty("context", contextObj);
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
jsContexts_.emplace(currentId_, systemModule);
|
||||
}
|
||||
|
||||
NativeValue *SimulatorImpl::CreateJsWant(NativeEngine &engine)
|
||||
napi_value SimulatorImpl::CreateJsWant(napi_env env)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
object->SetProperty("deviceId", CreateJsValue(engine, ""));
|
||||
object->SetProperty("bundleName", CreateJsValue(engine, options_.bundleName));
|
||||
napi_value objValue = nullptr;
|
||||
napi_create_object(env, &objValue);
|
||||
napi_set_named_property(env, objValue, "deviceId", CreateJsValue(env, std::string("")));
|
||||
napi_set_named_property(env, objValue, "bundleName", CreateJsValue(env, options_.bundleName));
|
||||
if (abilityInfo_) {
|
||||
object->SetProperty("abilityName", CreateJsValue(engine, abilityInfo_->name));
|
||||
napi_set_named_property(env, objValue, "abilityName", CreateJsValue(env, abilityInfo_->name));
|
||||
}
|
||||
object->SetProperty("moduleName", CreateJsValue(engine, options_.moduleName));
|
||||
object->SetProperty("uri", CreateJsValue(engine, ""));
|
||||
object->SetProperty("type", CreateJsValue(engine, ""));
|
||||
object->SetProperty("flags", CreateJsValue(engine, 0));
|
||||
object->SetProperty("action", CreateJsValue(engine, ""));
|
||||
object->SetProperty("parameters", engine.CreateObject());
|
||||
object->SetProperty("entities", engine.CreateArray(0));
|
||||
napi_set_named_property(env, objValue, "moduleName", CreateJsValue(env, options_.moduleName));
|
||||
|
||||
napi_set_named_property(env, objValue, "uri", CreateJsValue(env, std::string("")));
|
||||
napi_set_named_property(env, objValue, "type", CreateJsValue(env, std::string("")));
|
||||
napi_set_named_property(env, objValue, "flags", CreateJsValue(env, 0));
|
||||
napi_set_named_property(env, objValue, "type", CreateJsValue(env, std::string("")));
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
napi_set_named_property(env, objValue, "parameters", object);
|
||||
napi_value array = nullptr;
|
||||
napi_create_array_with_length(env, 0, &array);
|
||||
napi_set_named_property(env, objValue, "entities", array);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue *SimulatorImpl::CreateJsLaunchParam(NativeEngine &engine)
|
||||
napi_value SimulatorImpl::CreateJsLaunchParam(napi_env env)
|
||||
{
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
object->SetProperty("launchReason", CreateJsValue(engine, AAFwk::LAUNCHREASON_UNKNOWN));
|
||||
object->SetProperty("lastExitReason", CreateJsValue(engine, AAFwk::LASTEXITREASON_UNKNOWN));
|
||||
napi_value objValue = nullptr;
|
||||
napi_create_object(env, &objValue);
|
||||
napi_set_named_property(env, objValue, "launchReason", CreateJsValue(env, AAFwk::LAUNCHREASON_UNKNOWN));
|
||||
napi_set_named_property(env, objValue, "lastExitReason", CreateJsValue(env, AAFwk::LASTEXITREASON_UNKNOWN));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
void SimulatorImpl::DispatchStartLifecycle(NativeValue *instanceValue)
|
||||
void SimulatorImpl::DispatchStartLifecycle(napi_value instanceValue)
|
||||
{
|
||||
NativeValue *wantArgv[] = {
|
||||
CreateJsWant(*nativeEngine_),
|
||||
CreateJsLaunchParam(*nativeEngine_)
|
||||
napi_value wantArgv[] = {
|
||||
CreateJsWant(nativeEngine_),
|
||||
CreateJsLaunchParam(nativeEngine_)
|
||||
};
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onCreate", wantArgv, ArraySize(wantArgv));
|
||||
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onCreate", wantArgv, ArraySize(wantArgv));
|
||||
auto windowScene = std::make_shared<Rosen::WindowScene>();
|
||||
if (windowScene == nullptr) {
|
||||
return;
|
||||
@@ -604,10 +614,10 @@ void SimulatorImpl::DispatchStartLifecycle(NativeValue *instanceValue)
|
||||
if (jsWindowStage == nullptr) {
|
||||
return;
|
||||
}
|
||||
NativeValue *argv[] = { jsWindowStage->Get() };
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onWindowStageCreate", argv, ArraySize(argv));
|
||||
napi_value argv[] = { jsWindowStage->GetNapiValue() };
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onWindowStageCreate", argv, ArraySize(argv));
|
||||
|
||||
CallObjectMethod(*nativeEngine_, instanceValue, "onForeground", nullptr, 0);
|
||||
CallObjectMethod(nativeEngine_, instanceValue, "onForeground", nullptr, 0);
|
||||
|
||||
windowScenes_.emplace(currentId_, windowScene);
|
||||
jsWindowStages_.emplace(currentId_, std::shared_ptr<NativeReference>(jsWindowStage.release()));
|
||||
@@ -616,12 +626,13 @@ void SimulatorImpl::DispatchStartLifecycle(NativeValue *instanceValue)
|
||||
std::unique_ptr<NativeReference> SimulatorImpl::CreateJsWindowStage(
|
||||
const std::shared_ptr<Rosen::WindowScene> &windowScene)
|
||||
{
|
||||
NativeValue *jsWindowStage = Rosen::CreateJsWindowStage(*nativeEngine_, windowScene);
|
||||
auto engine = reinterpret_cast<NativeEngine*>(nativeEngine_);
|
||||
napi_value jsWindowStage = reinterpret_cast<napi_value>(Rosen::CreateJsWindowStage(*engine, windowScene));
|
||||
if (jsWindowStage == nullptr) {
|
||||
HILOG_ERROR("Failed to create jsWindowSatge object");
|
||||
return nullptr;
|
||||
}
|
||||
return JsRuntime::LoadSystemModuleByEngine(nativeEngine_.get(), "application.WindowStage", &jsWindowStage, 1);
|
||||
return JsRuntime::LoadSystemModuleByEngine(nativeEngine_, "application.WindowStage", &jsWindowStage, 1);
|
||||
}
|
||||
|
||||
panda::ecmascript::EcmaVM *SimulatorImpl::CreateJSVM()
|
||||
@@ -673,18 +684,23 @@ bool SimulatorImpl::OnInit()
|
||||
panda::JSNApi::StartDebugger(vm_, debugOption, 0,
|
||||
std::bind(&DebuggerTask::OnPostTask, &debuggerTask_, std::placeholders::_1));
|
||||
|
||||
auto nativeEngine = std::make_unique<ArkNativeEngine>(vm_, nullptr);
|
||||
auto nativeEngine = new (std::nothrow) ArkNativeEngine(vm_, nullptr);
|
||||
if (nativeEngine == nullptr) {
|
||||
HILOG_ERROR("nativeEngine is nullptr");
|
||||
return false;
|
||||
}
|
||||
NativeObject *globalObj = ConvertNativeValueTo<NativeObject>(nativeEngine->GetGlobal());
|
||||
napi_env env = reinterpret_cast<napi_env>(nativeEngine);
|
||||
|
||||
napi_value globalObj;
|
||||
napi_get_global(env, &globalObj);
|
||||
if (globalObj == nullptr) {
|
||||
delete nativeEngine;
|
||||
HILOG_ERROR("Failed to get global object");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!LoadRuntimeEnv(*nativeEngine, *globalObj)) {
|
||||
if (!LoadRuntimeEnv(env, globalObj)) {
|
||||
delete nativeEngine;
|
||||
HILOG_ERROR("Load runtime env failed.");
|
||||
return false;
|
||||
}
|
||||
@@ -694,18 +710,40 @@ bool SimulatorImpl::OnInit()
|
||||
panda::JSNApi::SetModuleName(vm_, options_.moduleName);
|
||||
panda::JSNApi::SetAssetPath(vm_, options_.modulePath);
|
||||
|
||||
nativeEngine_ = std::move(nativeEngine);
|
||||
nativeEngine_ = env;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimulatorImpl::LoadRuntimeEnv(NativeEngine &nativeEngine, NativeObject &globalObj)
|
||||
napi_value SimulatorImpl::RequireNapi(napi_env env, napi_callback_info info)
|
||||
{
|
||||
JsSysModule::Console::InitConsoleModule(reinterpret_cast<napi_env>(&nativeEngine));
|
||||
auto ret = JsSysModule::Timer::RegisterTime(reinterpret_cast<napi_env>(&nativeEngine));
|
||||
napi_value globalObj;
|
||||
napi_get_global(env, &globalObj);
|
||||
napi_value requireNapi = nullptr;
|
||||
napi_get_named_property(env, globalObj, "requireNapiPreview", &requireNapi);
|
||||
size_t argc = ARGC_MAX_COUNT;
|
||||
napi_value argv[ARGC_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
napi_value result = nullptr;
|
||||
napi_call_function(env, CreateJsUndefined(env), requireNapi, argc, argv, &result);
|
||||
if (!CheckTypeForNapiValue(env, result, napi_undefined)) {
|
||||
return result;
|
||||
}
|
||||
napi_value mockRequireNapi = nullptr;
|
||||
napi_get_named_property(env, globalObj, "mockRequireNapi", &mockRequireNapi);
|
||||
napi_call_function(env, CreateJsUndefined(env), mockRequireNapi, argc, argv, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SimulatorImpl::LoadRuntimeEnv(napi_env env, napi_value globalObj)
|
||||
{
|
||||
JsSysModule::Console::InitConsoleModule(env);
|
||||
auto ret = JsSysModule::Timer::RegisterTime(env);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Register timer failed");
|
||||
}
|
||||
globalObj.SetProperty("group", nativeEngine.CreateObject());
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
napi_set_named_property(env, globalObj, "group", object);
|
||||
|
||||
uintptr_t bufferStart = reinterpret_cast<uintptr_t>(_binary_jsMockSystemPlugin_abc_start);
|
||||
uintptr_t bufferEnd = reinterpret_cast<uintptr_t>(_binary_jsMockSystemPlugin_abc_end);
|
||||
@@ -713,12 +751,12 @@ bool SimulatorImpl::LoadRuntimeEnv(NativeEngine &nativeEngine, NativeObject &glo
|
||||
size_t size = bufferEnd - bufferStart;
|
||||
panda::JSNApi::Execute(vm_, buffer, size, "_GLOBAL::func_main_0");
|
||||
|
||||
NativeValue *mockRequireNapi = globalObj.GetProperty("requireNapi");
|
||||
globalObj.SetProperty("mockRequireNapi", mockRequireNapi);
|
||||
|
||||
auto* moduleManager = nativeEngine.GetModuleManager();
|
||||
napi_value mockRequireNapi = nullptr;
|
||||
napi_get_named_property(env, globalObj, "requireNapi", &mockRequireNapi);
|
||||
napi_set_named_property(env, globalObj, "mockRequireNapi", mockRequireNapi);
|
||||
auto* moduleManager = reinterpret_cast<NativeEngine*>(env)->GetModuleManager();
|
||||
if (moduleManager != nullptr) {
|
||||
HILOG_DEBUG("moduleManager SetPreviewSearchPath: %{public}s", options_.containerSdkPath.c_str());
|
||||
HILOG_ERROR("moduleManager SetPreviewSearchPath: %{public}s", options_.containerSdkPath.c_str());
|
||||
moduleManager->SetPreviewSearchPath(options_.containerSdkPath);
|
||||
}
|
||||
|
||||
@@ -735,25 +773,14 @@ bool SimulatorImpl::LoadRuntimeEnv(NativeEngine &nativeEngine, NativeObject &glo
|
||||
}
|
||||
|
||||
const char *moduleName = "SimulatorImpl";
|
||||
BindNativeFunction(nativeEngine, globalObj, "requireNapi", moduleName,
|
||||
[](NativeEngine *engine, NativeCallbackInfo *info) {
|
||||
NativeObject *globalObj = ConvertNativeValueTo<NativeObject>(engine->GetGlobal());
|
||||
NativeValue *requireNapi = globalObj->GetProperty("requireNapiPreview");
|
||||
|
||||
NativeValue *result = engine->CallFunction(engine->CreateUndefined(), requireNapi, info->argv, info->argc);
|
||||
if (result->TypeOf() != NATIVE_UNDEFINED) {
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *mockRequireNapi = globalObj->GetProperty("mockRequireNapi");
|
||||
return engine->CallFunction(engine->CreateUndefined(), mockRequireNapi, info->argv, info->argc);
|
||||
});
|
||||
BindNativeFunction(env, globalObj, "requireNapi", moduleName, SimulatorImpl::RequireNapi);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SimulatorImpl::Run()
|
||||
{
|
||||
uv_loop_t *uvLoop = nativeEngine_->GetUVLoop();
|
||||
uv_loop_t* uvLoop = nullptr;
|
||||
napi_get_uv_event_loop(nativeEngine_, &uvLoop);
|
||||
if (uvLoop != nullptr) {
|
||||
uv_run(uvLoop, UV_RUN_NOWAIT);
|
||||
}
|
||||
|
||||
+32
-2
@@ -218,7 +218,11 @@ APP_LAUNCH:
|
||||
VERSION_NAME: {type: STRING, desc: version name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
CALLER_BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name}
|
||||
CALLER_VERSION_NAME: {type: STRING, desc: caller version name}
|
||||
CALLER_VERSION_CODE: {type: UINT32, desc: caller version code}
|
||||
CALLER_UID: {type: INT32, desc: caller app uid}
|
||||
CALLER_STATE: {type: INT32, desc: caller app state}
|
||||
|
||||
APP_FOREGROUND:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: foreground app}
|
||||
@@ -287,4 +291,30 @@ DRAWN_COMPLETED:
|
||||
APP_PID: {type: INT32, desc: app pid}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
|
||||
FA_SHOW_ON_LOCK:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: fa show on lock}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
|
||||
GRANT_URI_PERMISSION:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: grant uri permission form SA to third-party app}
|
||||
BUNDLE_NAME: {type: STRING, desc: callee bundle name}
|
||||
CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name}
|
||||
URI: {type: STRING, desc: uri information}
|
||||
|
||||
START_PRIVATE_ABILITY:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: start private ability}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
|
||||
RESTART_PROCESS_BY_SAME_APP:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: reStart process by different processes from the same app}
|
||||
RESTART_TIME: {type: STRING, desc: process reStart time}
|
||||
APP_UID: {type: INT32, desc: app uid}
|
||||
CALLER_PROCESS_NAME: {type: STRING, desc: caller process name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
|
||||
@@ -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_AUTO_STARTUP_INFO_H
|
||||
#define OHOS_ABILITY_RUNTIME_AUTO_STARTUP_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
/**
|
||||
* @struct AutoStartupInfo
|
||||
* Defines auto startup info.
|
||||
*/
|
||||
struct AutoStartupInfo : public Parcelable {
|
||||
public:
|
||||
std::string bundleName;
|
||||
std::string abilityName;
|
||||
std::string moduleName;
|
||||
std::string abilityTypeName;
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static AutoStartupInfo *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
|
||||
struct AutoStartupStatus {
|
||||
int32_t code;
|
||||
bool isAutoStartup;
|
||||
bool isEdmForce;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_AUTO_STARTUP_INFO_H
|
||||
@@ -31,8 +31,9 @@ public:
|
||||
static ChildProcessManager instance;
|
||||
return instance;
|
||||
}
|
||||
~ChildProcessManager() = default;
|
||||
|
||||
~ChildProcessManager();
|
||||
|
||||
static void HandleSigChild(int32_t signo);
|
||||
pid_t StartChildProcessBySelfFork(const std::string &srcEntry);
|
||||
bool MultiProcessModelEnabled();
|
||||
bool IsChildProcess();
|
||||
@@ -46,8 +47,11 @@ private:
|
||||
const std::string &moduleName, AppExecFwk::HapModuleInfo &hapModuleInfo);
|
||||
std::unique_ptr<AbilityRuntime::Runtime> CreateRuntime(AppExecFwk::HapModuleInfo &hapModuleInfo);
|
||||
|
||||
static bool signalRegistered_;
|
||||
bool multiProcessModelEnabled_ = false;
|
||||
bool isChildProcess_ = false;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(ChildProcessManager);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_SERVICE_H
|
||||
#define OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_SERVICE_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "auto_startup_info.h"
|
||||
#include "bundle_mgr_client.h"
|
||||
#include "iremote_object.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class AbilityAutoStartupService : public std::enable_shared_from_this<AbilityAutoStartupService> {
|
||||
public:
|
||||
explicit AbilityAutoStartupService();
|
||||
|
||||
virtual ~AbilityAutoStartupService();
|
||||
|
||||
/**
|
||||
* @brief Register auto start up callback for system api.
|
||||
* @param callback The point of JsAbilityAutoStartupCallBack.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback);
|
||||
|
||||
/**
|
||||
* @brief Unregister auto start up callback for system api.
|
||||
* @param callback The point of JsAbilityAutoStartupCallBack.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback);
|
||||
|
||||
/**
|
||||
* @brief Set every application auto start up state.
|
||||
* @param info The auto startup info,include bundle name, module name, ability name.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t SetApplicationAutoStartup(const AutoStartupInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Cancel every application auto start up .
|
||||
* @param info The auto startup info,include bundle name, module name, ability name.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t CancelApplicationAutoStartup(const AutoStartupInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Query auto startup state all application.
|
||||
* @param infoList Output parameters, return auto startup info list.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList);
|
||||
|
||||
/**
|
||||
* @brief Query auto startup state all application without permission.
|
||||
* @param infoList Output parameters, return auto startup info list.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t QueryAllAutoStartupApplicationsWithoutPermission(std::vector<AutoStartupInfo> &infoList);
|
||||
|
||||
/**
|
||||
* @brief Register auto start up callback.
|
||||
* @param callback The point of JsAbilityAutoStartupCallBack.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t RegisterAutoStartupCallback(const sptr<IRemoteObject> &callback);
|
||||
|
||||
/**
|
||||
* @brief Unregister auto start up callback.
|
||||
* @param callback The point of JsAbilityAutoStartupCallBack.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t UnregisterAutoStartupCallback(const sptr<IRemoteObject> &callback);
|
||||
|
||||
/**
|
||||
* @brief Set current application auto start up state.
|
||||
* @param info The auto startup info,include bundle name, module name, ability name.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t SetAutoStartup(const AutoStartupInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Cancel current application auto start up state.
|
||||
* @param info The auto startup info, include bundle name, module name, ability name.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t CancelAutoStartup(const AutoStartupInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Check current application auto start up state.
|
||||
* @param info The auto startup info, include bundle name, module name, ability name.
|
||||
* @param isAutoStartup Output parameters, return auto start up state.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t IsAutoStartup(const AutoStartupInfo &info, bool &isAutoStartup);
|
||||
|
||||
/**
|
||||
* @brief Delete current bundleName auto start up data.
|
||||
* @param bundleName The current bundleName.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t DeleteAutoStartupData(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief Check current bundleName auto start up data.
|
||||
* @param bundleName The current bundleName.
|
||||
* @param uid The uid.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t CheckAutoStartupData(const std::string &bundleName, int32_t uid);
|
||||
|
||||
/**
|
||||
* @class ClientDeathRecipient
|
||||
* notices IRemoteBroker died.
|
||||
*/
|
||||
class ClientDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
explicit ClientDeathRecipient(const std::weak_ptr<AbilityAutoStartupService> &weakPtr);
|
||||
virtual ~ClientDeathRecipient() = default;
|
||||
/**
|
||||
* @brief handle remote object died event.
|
||||
* @param remote remote object.
|
||||
*/
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<AbilityAutoStartupService> weakPtr_;
|
||||
};
|
||||
|
||||
private:
|
||||
int32_t InnerSetApplicationAutoStartup(const AutoStartupInfo &info);
|
||||
int32_t InnerCancelApplicationAutoStartup(const AutoStartupInfo &info);
|
||||
int32_t InnerSetAutoStartup(const AutoStartupInfo &info);
|
||||
int32_t InnerCancelAutoStartup(const AutoStartupInfo &info);
|
||||
void ExecuteCallbacks(bool isCallOn, const AutoStartupInfo &info);
|
||||
void SetDeathRecipient(
|
||||
const sptr<IRemoteObject> &callback, const sptr<IRemoteObject::DeathRecipient> &deathRecipient);
|
||||
void CleanResource(const wptr<IRemoteObject> &remote);
|
||||
std::string GetSelfApplicationBundleName();
|
||||
bool CheckSelfApplication(const std::string &bundleName);
|
||||
bool GetBundleInfo(const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo, int32_t uid = -1);
|
||||
bool GetAbilityData(const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName);
|
||||
std::string GetAbilityTypeName(AppExecFwk::AbilityInfo abilityInfo);
|
||||
std::string GetExtensionTypeName(AppExecFwk::ExtensionAbilityInfo extensionInfo);
|
||||
std::shared_ptr<AppExecFwk::BundleMgrClient> GetBundleMgrClient();
|
||||
int32_t CheckPermissionForSystem();
|
||||
int32_t CheckPermissionForSelf(const std::string &bundleName);
|
||||
|
||||
mutable std::mutex autoStartUpMutex_;
|
||||
mutable std::mutex deathRecipientsMutex_;
|
||||
std::vector<sptr<IRemoteObject>> callbackVector_;
|
||||
std::map<std::string, sptr<IRemoteObject>> callbackMaps_;
|
||||
std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> deathRecipients_;
|
||||
std::shared_ptr<AppExecFwk::BundleMgrClient> bundleMgrClient_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_SERVICE_H
|
||||
@@ -519,6 +519,8 @@ private:
|
||||
const std::shared_ptr<Mission> &targetMission, InnerMissionInfo &info);
|
||||
bool GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const;
|
||||
|
||||
void SendKeyEvent(const AbilityRequest &abilityRequest);
|
||||
|
||||
int userId_;
|
||||
mutable ffrt::mutex managerLock_;
|
||||
// launcher list is also in currentMissionLists_
|
||||
|
||||
@@ -0,0 +1,714 @@
|
||||
/*
|
||||
* 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 "ability_auto_startup_service.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
|
||||
#include "ability_auto_startup_data_manager.h"
|
||||
#include "ability_manager_errors.h"
|
||||
#include "auto_startup_info.h"
|
||||
#include "auto_startup_interface.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "parameters.h"
|
||||
#include "permission_constants.h"
|
||||
#include "permission_verification.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AAFwk;
|
||||
namespace {
|
||||
constexpr char PRODUCT_APPBOOT_SETTING_ENABLED[] = "const.product.appboot.setting.enabled";
|
||||
} // namespace
|
||||
|
||||
AbilityAutoStartupService::AbilityAutoStartupService() {}
|
||||
|
||||
AbilityAutoStartupService::~AbilityAutoStartupService() {}
|
||||
|
||||
int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
int32_t code = CheckPermissionForSystem();
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
bool isFound = false;
|
||||
auto item = callbackVector_.begin();
|
||||
while (item != callbackVector_.end()) {
|
||||
if (*item == callback) {
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
item++;
|
||||
}
|
||||
if (!isFound) {
|
||||
callbackVector_.emplace_back(callback);
|
||||
SetDeathRecipient(
|
||||
callback, new (std::nothrow) AbilityAutoStartupService::ClientDeathRecipient(weak_from_this()));
|
||||
} else {
|
||||
HILOG_DEBUG("Callback is already exist.");
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
int32_t code = CheckPermissionForSystem();
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
bool isFound = false;
|
||||
auto item = callbackVector_.begin();
|
||||
while (item != callbackVector_.end()) {
|
||||
if (*item == callback) {
|
||||
item = callbackVector_.erase(item);
|
||||
isFound = true;
|
||||
} else {
|
||||
item++;
|
||||
}
|
||||
}
|
||||
if (!isFound) {
|
||||
HILOG_DEBUG("Callback is not exist.");
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
int32_t code = CheckPermissionForSystem();
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
bool isVisible;
|
||||
std::string abilityTypeName;
|
||||
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
|
||||
HILOG_ERROR("Failed to get ability data.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
if (!isVisible) {
|
||||
HILOG_ERROR("Current ability is not visible.");
|
||||
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
|
||||
}
|
||||
|
||||
AutoStartupInfo fullInfo(info);
|
||||
fullInfo.abilityTypeName = abilityTypeName;
|
||||
|
||||
return InnerSetApplicationAutoStartup(fullInfo);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
AutoStartupStatus status =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
|
||||
if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) {
|
||||
HILOG_ERROR("Query auto startup data failed.");
|
||||
return status.code;
|
||||
}
|
||||
|
||||
int32_t result;
|
||||
if (status.code == ERR_NAME_NOT_FOUND) {
|
||||
HILOG_INFO("Query data is not exist.");
|
||||
result =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->InsertAutoStartupData(info, true, false);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(true, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (status.isEdmForce) {
|
||||
HILOG_ERROR("Edm application abnormal.");
|
||||
return ERR_EDM_APP_CONTROLLED;
|
||||
}
|
||||
if (!status.isAutoStartup) {
|
||||
result =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->UpdateAutoStartupData(info, true, false);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(true, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ERR_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
int32_t code = CheckPermissionForSystem();
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
bool isVisible;
|
||||
std::string abilityTypeName;
|
||||
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
|
||||
HILOG_ERROR("Failed to get ability data.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
if (!isVisible) {
|
||||
HILOG_ERROR("Current ability is not visible.");
|
||||
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
|
||||
}
|
||||
|
||||
AutoStartupInfo fullInfo(info);
|
||||
fullInfo.abilityTypeName = abilityTypeName;
|
||||
|
||||
return InnerCancelApplicationAutoStartup(fullInfo);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::InnerCancelApplicationAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
AutoStartupStatus status =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
|
||||
if (status.code != ERR_OK) {
|
||||
HILOG_ERROR("Query auto startup data failed.");
|
||||
return status.code;
|
||||
}
|
||||
|
||||
if (status.isEdmForce) {
|
||||
HILOG_ERROR("Edm application abnormal.");
|
||||
return ERR_EDM_APP_CONTROLLED;
|
||||
}
|
||||
|
||||
if (status.isAutoStartup) {
|
||||
int32_t result = DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(info);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(false, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
int32_t code = CheckPermissionForSystem();
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAllAutoStartupApplications(infoList);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::QueryAllAutoStartupApplicationsWithoutPermission(
|
||||
std::vector<AutoStartupInfo> &infoList)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
|
||||
HILOG_ERROR("Product configuration item is disable.");
|
||||
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
|
||||
}
|
||||
|
||||
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAllAutoStartupApplications(infoList);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::RegisterAutoStartupCallback(const sptr<IRemoteObject> &callback)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
|
||||
HILOG_ERROR("Product configuration item is disable.");
|
||||
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
|
||||
}
|
||||
|
||||
std::string bundleName = GetSelfApplicationBundleName();
|
||||
if (bundleName.empty()) {
|
||||
HILOG_ERROR("Get self application bundleName failed.");
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
auto item = callbackMaps_.find(bundleName);
|
||||
if (item != callbackMaps_.end()) {
|
||||
HILOG_DEBUG("Callback is already exist.");
|
||||
return ERR_OK;
|
||||
}
|
||||
callbackMaps_.emplace(bundleName, callback);
|
||||
SetDeathRecipient(
|
||||
callback, new (std::nothrow) AbilityAutoStartupService::ClientDeathRecipient(weak_from_this()));
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::UnregisterAutoStartupCallback(const sptr<IRemoteObject> &callback)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
|
||||
HILOG_ERROR("Product configuration item is disable.");
|
||||
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
|
||||
}
|
||||
|
||||
std::string bundleName = GetSelfApplicationBundleName();
|
||||
if (bundleName.empty()) {
|
||||
HILOG_ERROR("Get self application bundleName failed.");
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
auto item = callbackMaps_.find(bundleName);
|
||||
if (item == callbackMaps_.end()) {
|
||||
HILOG_DEBUG("BundleName is not exist.");
|
||||
return ERR_NAME_NOT_FOUND;
|
||||
}
|
||||
if (item->second != callback) {
|
||||
HILOG_DEBUG("Callback is not exist.");
|
||||
return ERR_NAME_NOT_FOUND;
|
||||
}
|
||||
callbackMaps_.erase(item);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::SetAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
int32_t code = CheckPermissionForSelf(info.bundleName);
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
bool isVisible;
|
||||
std::string abilityTypeName;
|
||||
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
|
||||
HILOG_ERROR("Failed to get ability data.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
if (!isVisible) {
|
||||
HILOG_ERROR("Current ability is not visible.");
|
||||
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
|
||||
}
|
||||
|
||||
AutoStartupInfo fullInfo(info);
|
||||
fullInfo.abilityTypeName = abilityTypeName;
|
||||
|
||||
return InnerSetAutoStartup(fullInfo);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::InnerSetAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
AutoStartupStatus status =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
|
||||
if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) {
|
||||
HILOG_ERROR("Query auto startup data failed.");
|
||||
return status.code;
|
||||
}
|
||||
|
||||
int32_t result;
|
||||
if (status.code == ERR_NAME_NOT_FOUND) {
|
||||
HILOG_INFO("Query data is not exist.");
|
||||
result =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->InsertAutoStartupData(info, true, false);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(true, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (status.isEdmForce) {
|
||||
HILOG_ERROR("Edm application abnormal.");
|
||||
return ERR_EDM_APP_CONTROLLED;
|
||||
}
|
||||
|
||||
if (!status.isAutoStartup) {
|
||||
result =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->UpdateAutoStartupData(info, true, false);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(true, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ERR_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::CancelAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
int32_t code = CheckPermissionForSelf(info.bundleName);
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
bool isVisible;
|
||||
std::string abilityTypeName;
|
||||
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
|
||||
HILOG_ERROR("Failed to get ability data.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
if (!isVisible) {
|
||||
HILOG_ERROR("Current ability is not visible.");
|
||||
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
|
||||
}
|
||||
|
||||
AutoStartupInfo fullInfo(info);
|
||||
fullInfo.abilityTypeName = abilityTypeName;
|
||||
|
||||
return InnerCancelAutoStartup(fullInfo);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::InnerCancelAutoStartup(const AutoStartupInfo &info)
|
||||
{
|
||||
AutoStartupStatus status =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
|
||||
if (status.code != ERR_OK) {
|
||||
HILOG_ERROR("Query auto startup data failed.");
|
||||
return status.code;
|
||||
}
|
||||
|
||||
if (status.isEdmForce) {
|
||||
HILOG_ERROR("Edm application abnormal.");
|
||||
return ERR_EDM_APP_CONTROLLED;
|
||||
}
|
||||
|
||||
if (status.isAutoStartup) {
|
||||
int32_t result = DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(info);
|
||||
if (result == ERR_OK) {
|
||||
ExecuteCallbacks(false, info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::IsAutoStartup(const AutoStartupInfo &info, bool &isAutoStartup)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
int32_t code = CheckPermissionForSelf(info.bundleName);
|
||||
if (code != ERR_OK) {
|
||||
return code;
|
||||
}
|
||||
|
||||
AutoStartupStatus status =
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
|
||||
if (status.code != ERR_OK) {
|
||||
HILOG_DEBUG("Query auto startup data failed.");
|
||||
isAutoStartup = false;
|
||||
} else {
|
||||
isAutoStartup = status.isAutoStartup;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(bundleName);
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundleName, int32_t uid)
|
||||
{
|
||||
std::vector<AutoStartupInfo> infoList;
|
||||
int32_t result = DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->GetCurrentAppAutoStartupData(
|
||||
bundleName, infoList);
|
||||
if (result != ERR_OK) {
|
||||
HILOG_ERROR("Failed to get auto startup data.");
|
||||
return result;
|
||||
}
|
||||
if (infoList.size() == 0) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
if (!GetBundleInfo(bundleName, bundleInfo, uid)) {
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
bool isFound = false;
|
||||
for (auto info : infoList) {
|
||||
for (auto abilityInfo : bundleInfo.abilityInfos) {
|
||||
if ((abilityInfo.bundleName == info.bundleName) && (abilityInfo.name == info.abilityName) &&
|
||||
(info.moduleName.empty() || (abilityInfo.moduleName == info.moduleName))) {
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isFound) {
|
||||
HILOG_DEBUG("Current bundleName not found in Datebase.");
|
||||
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(bundleName);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartupInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
|
||||
info.moduleName.c_str(), info.abilityName.c_str());
|
||||
for (auto item : callbackVector_) {
|
||||
auto remoteSystemCallback = iface_cast<IAutoStartupCallBack>(item);
|
||||
if (remoteSystemCallback != nullptr) {
|
||||
if (isCallOn) {
|
||||
remoteSystemCallback->OnAutoStartupOn(info);
|
||||
} else {
|
||||
remoteSystemCallback->OnAutoStartupOff(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto it = callbackMaps_.find(info.bundleName);
|
||||
if (it != callbackMaps_.end()) {
|
||||
auto remoteCallback = iface_cast<IAutoStartupCallBack>(it->second);
|
||||
if (remoteCallback != nullptr) {
|
||||
if (isCallOn) {
|
||||
remoteCallback->OnAutoStartupOn(info);
|
||||
} else {
|
||||
remoteCallback->OnAutoStartupOff(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityAutoStartupService::SetDeathRecipient(
|
||||
const sptr<IRemoteObject> &callback, const sptr<IRemoteObject::DeathRecipient> &deathRecipient)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (callback == nullptr || deathRecipient == nullptr) {
|
||||
HILOG_ERROR("The callerToken or the deathRecipient is empty.");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(deathRecipientsMutex_);
|
||||
auto iter = deathRecipients_.find(callback);
|
||||
if (iter == deathRecipients_.end()) {
|
||||
deathRecipients_.emplace(callback, deathRecipient);
|
||||
callback->AddDeathRecipient(deathRecipient);
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("The deathRecipient has been added.");
|
||||
}
|
||||
|
||||
void AbilityAutoStartupService::CleanResource(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto object = remote.promote();
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Remote object is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean the callbackVector_ and callbackMaps_.
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
for (auto item = callbackVector_.begin(); item != callbackVector_.end();) {
|
||||
if (*item == object) {
|
||||
item = callbackVector_.erase(item);
|
||||
} else {
|
||||
item++;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = callbackMaps_.begin(); it != callbackMaps_.end();) {
|
||||
auto &callback = it->second;
|
||||
if (callback == object) {
|
||||
it = callbackMaps_.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> deathLock(deathRecipientsMutex_);
|
||||
auto iter = deathRecipients_.find(object);
|
||||
if (iter != deathRecipients_.end()) {
|
||||
auto deathRecipient = iter->second;
|
||||
deathRecipients_.erase(iter);
|
||||
object->RemoveDeathRecipient(deathRecipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AbilityAutoStartupService::ClientDeathRecipient::ClientDeathRecipient(
|
||||
const std::weak_ptr<AbilityAutoStartupService> &weakPtr)
|
||||
{
|
||||
weakPtr_ = weakPtr;
|
||||
}
|
||||
|
||||
void AbilityAutoStartupService::ClientDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto abilityAutoStartupService = weakPtr_.lock();
|
||||
if (abilityAutoStartupService == nullptr) {
|
||||
HILOG_ERROR("abilityAutoStartupService is nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityAutoStartupService->CleanResource(remote);
|
||||
}
|
||||
|
||||
std::string AbilityAutoStartupService::GetSelfApplicationBundleName()
|
||||
{
|
||||
auto bundleMgrClient = GetBundleMgrClient();
|
||||
if (bundleMgrClient == nullptr) {
|
||||
HILOG_ERROR("Failed to get BundleMgrClient.");
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string bundleName;
|
||||
int32_t callerUid = IPCSkeleton::GetCallingUid();
|
||||
if (IN_PROCESS_CALL(bundleMgrClient->GetNameForUid(callerUid, bundleName)) != ERR_OK) {
|
||||
HILOG_ERROR("Get Bundle Name failed.");
|
||||
return "";
|
||||
}
|
||||
HILOG_DEBUG("Get bundle name: %{public}s.", bundleName.c_str());
|
||||
return bundleName;
|
||||
}
|
||||
|
||||
bool AbilityAutoStartupService::CheckSelfApplication(const std::string &bundleName)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s.", bundleName.c_str());
|
||||
return GetSelfApplicationBundleName() == bundleName ? true : false;
|
||||
}
|
||||
|
||||
bool AbilityAutoStartupService::GetBundleInfo(
|
||||
const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo, int32_t uid)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto bundleMgrClient = GetBundleMgrClient();
|
||||
if (bundleMgrClient == nullptr) {
|
||||
HILOG_ERROR("Failed to get BundleMgrClient.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t userId;
|
||||
if (uid == -1) {
|
||||
userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE;
|
||||
} else {
|
||||
userId = uid / AppExecFwk::Constants::BASE_USER_RANGE;
|
||||
}
|
||||
HILOG_DEBUG("Current userId: %{public}d.", userId);
|
||||
auto flags =
|
||||
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES | AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO;
|
||||
if (!IN_PROCESS_CALL(bundleMgrClient->GetBundleInfo(
|
||||
bundleName, static_cast<AppExecFwk::BundleFlag>(flags), bundleInfo, userId))) {
|
||||
HILOG_ERROR("Failed to get bundle info.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbilityAutoStartupService::GetAbilityData(
|
||||
const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName)
|
||||
{
|
||||
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
|
||||
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
if (!GetBundleInfo(info.bundleName, bundleInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto abilityInfo : bundleInfo.abilityInfos) {
|
||||
if ((abilityInfo.bundleName == info.bundleName) && (abilityInfo.name == info.abilityName)) {
|
||||
if (info.moduleName.empty() || (abilityInfo.moduleName == info.moduleName)) {
|
||||
isVisible = abilityInfo.visible;
|
||||
abilityTypeName = GetAbilityTypeName(abilityInfo);
|
||||
HILOG_DEBUG("Get ability info success.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto extensionInfo : bundleInfo.extensionInfos) {
|
||||
if ((extensionInfo.bundleName == info.bundleName) && (extensionInfo.name == info.abilityName)) {
|
||||
if (info.moduleName.empty() || (extensionInfo.moduleName == info.moduleName)) {
|
||||
isVisible = extensionInfo.visible;
|
||||
abilityTypeName = GetExtensionTypeName(extensionInfo);
|
||||
HILOG_DEBUG("Get extension info success.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string AbilityAutoStartupService::GetAbilityTypeName(AppExecFwk::AbilityInfo abilityInfo)
|
||||
{
|
||||
std::string abilityTypeName;
|
||||
if (abilityInfo.type == AppExecFwk::AbilityType::PAGE) {
|
||||
abilityTypeName = "UIAbility";
|
||||
}
|
||||
return abilityTypeName;
|
||||
}
|
||||
|
||||
std::string AbilityAutoStartupService::GetExtensionTypeName(AppExecFwk::ExtensionAbilityInfo extensionInfo)
|
||||
{
|
||||
std::string abilityTypeName;
|
||||
if (extensionInfo.type == AppExecFwk::ExtensionAbilityType::SERVICE) {
|
||||
abilityTypeName = "ServiceExtension";
|
||||
}
|
||||
return abilityTypeName;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::BundleMgrClient> AbilityAutoStartupService::GetBundleMgrClient()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (bundleMgrClient_ == nullptr) {
|
||||
bundleMgrClient_ = DelayedSingleton<AppExecFwk::BundleMgrClient>::GetInstance();
|
||||
}
|
||||
return bundleMgrClient_;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::CheckPermissionForSystem()
|
||||
{
|
||||
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
|
||||
HILOG_ERROR("Product configuration item is disable.");
|
||||
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
|
||||
}
|
||||
|
||||
if (!PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
|
||||
HILOG_ERROR("The caller is not system-app, can not use system-api.");
|
||||
return ERR_NOT_SYSTEM_APP;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::CheckPermissionForSelf(const std::string &bundleName)
|
||||
{
|
||||
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
|
||||
HILOG_ERROR("Product configuration item is disable.");
|
||||
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
|
||||
}
|
||||
|
||||
if (!CheckSelfApplication(bundleName)) {
|
||||
HILOG_ERROR("Not self application.");
|
||||
return ERR_NOT_SELF_APPLICATION;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -108,6 +108,7 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque
|
||||
}
|
||||
|
||||
if (!isLoadedAbility) {
|
||||
HILOG_INFO("Target service has not been loaded.");
|
||||
LoadAbility(targetService);
|
||||
} else if (targetService->IsAbilityState(AbilityState::ACTIVE)) {
|
||||
// It may have been started through connect
|
||||
|
||||
@@ -831,7 +831,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
|
||||
HILOG_ERROR("connectManager is nullptr. userId=%{public}d", validUserId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
HILOG_DEBUG("Start service or extension, name is %{public}s.", abilityInfo.name.c_str());
|
||||
HILOG_INFO("Start service or extension, name is %{public}s.", abilityInfo.name.c_str());
|
||||
ReportEventToSuspendManager(abilityInfo);
|
||||
return connectManager->StartAbility(abilityRequest);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ int AppScheduler::LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemo
|
||||
const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Send load ability to AppMgrService.");
|
||||
HILOG_INFO("Send load ability to AppMgrService.");
|
||||
CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
|
||||
/* because the errcode type of AppMgr Client API will be changed to int,
|
||||
* so must to covert the return result */
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "auto_startup_info.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
bool AutoStartupInfo::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
bundleName = Str16ToStr8(parcel.ReadString16());
|
||||
abilityName = Str16ToStr8(parcel.ReadString16());
|
||||
moduleName = Str16ToStr8(parcel.ReadString16());
|
||||
abilityTypeName = Str16ToStr8(parcel.ReadString16());
|
||||
return true;
|
||||
}
|
||||
|
||||
AutoStartupInfo *AutoStartupInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
AutoStartupInfo *info = new (std::nothrow) AutoStartupInfo();
|
||||
if (info == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!info->ReadFromParcel(parcel)) {
|
||||
delete info;
|
||||
info = nullptr;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
bool AutoStartupInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16(Str8ToStr16(abilityTypeName))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -172,6 +172,9 @@ int MissionListManager::StartAbility(AbilityRequest &abilityRequest)
|
||||
|
||||
abilityRequest.callerAccessTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
int ret = StartAbility(currentTopAbility, callerAbility, abilityRequest);
|
||||
if (ret == 0 && !abilityRequest.abilityInfo.visible) {
|
||||
SendKeyEvent(abilityRequest);
|
||||
}
|
||||
NotifyStartAbilityResult(abilityRequest, ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -326,7 +329,9 @@ void MissionListManager::StartWaitingAbility()
|
||||
HILOG_INFO("name:%{public}s", abilityRequest.abilityInfo.name.c_str());
|
||||
waitingAbilityQueue_.pop();
|
||||
auto callerAbility = GetAbilityRecordByTokenInner(abilityRequest.callerToken);
|
||||
StartAbility(topAbility, callerAbility, abilityRequest);
|
||||
if (StartAbility(topAbility, callerAbility, abilityRequest) == 0 && !abilityRequest.abilityInfo.visible) {
|
||||
SendKeyEvent(abilityRequest);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -3402,7 +3407,9 @@ void MissionListManager::OnStartSpecifiedAbilityTimeoutResponse(const AAFwk::Wan
|
||||
|
||||
auto currentTopAbility = GetCurrentTopAbilityLocked();
|
||||
auto callerAbility = GetAbilityRecordByTokenInner(abilityRequest.callerToken);
|
||||
StartAbility(currentTopAbility, callerAbility, abilityRequest);
|
||||
if (StartAbility(currentTopAbility, callerAbility, abilityRequest) == 0 && !abilityRequest.abilityInfo.visible) {
|
||||
SendKeyEvent(abilityRequest);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Mission> MissionListManager::GetMissionBySpecifiedFlag(
|
||||
@@ -4128,5 +4135,15 @@ int32_t MissionListManager::TerminateMission(int32_t missionId)
|
||||
std::lock_guard guard(managerLock_);
|
||||
return TerminateAbilityInner(abilityRecord, DEFAULT_INVAL_VALUE, nullptr, true);
|
||||
}
|
||||
|
||||
void MissionListManager::SendKeyEvent(const AbilityRequest &abilityRequest)
|
||||
{
|
||||
auto abilityInfo = abilityRequest.abilityInfo;
|
||||
EventInfo eventInfo;
|
||||
eventInfo.abilityName = abilityInfo.name;
|
||||
eventInfo.bundleName = abilityInfo.bundleName;
|
||||
eventInfo.moduleName = abilityInfo.moduleName;
|
||||
EventReport::SendKeyEvent(EventName::START_PRIVATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -136,6 +136,14 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp
|
||||
uiAbilityRecord->SetSpecifiedFlag(specifiedInfo.flag);
|
||||
specifiedAbilityMap_.emplace(specifiedInfo, uiAbilityRecord);
|
||||
}
|
||||
auto abilityInfo = abilityRequest.abilityInfo;
|
||||
if (abilityInfo.visible == false) {
|
||||
EventInfo eventInfo;
|
||||
eventInfo.abilityName = abilityInfo.name;
|
||||
eventInfo.bundleName = abilityInfo.bundleName;
|
||||
eventInfo.moduleName = abilityInfo.moduleName;
|
||||
EventReport::SendKeyEvent(EventName::START_PRIVATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ ohos_shared_library("libappms") {
|
||||
"src/quick_fix_callback_with_record.cpp",
|
||||
"src/remote_client_manager.cpp",
|
||||
"src/window_focus_changed_listener.cpp",
|
||||
"src/window_visibility_changed_listener.cpp",
|
||||
]
|
||||
|
||||
defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ]
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_info.h"
|
||||
#include "cpp/mutex.h"
|
||||
#include "event_report.h"
|
||||
#include "fault_data.h"
|
||||
#include "hisysevent.h"
|
||||
#include "iapp_state_callback.h"
|
||||
#include "iapplication_state_observer.h"
|
||||
#include "iconfiguration_observer.h"
|
||||
@@ -55,6 +57,7 @@
|
||||
#include "task_handler_wrap.h"
|
||||
#include "want.h"
|
||||
#include "window_focus_changed_listener.h"
|
||||
#include "window_visibility_changed_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@@ -647,6 +650,12 @@ public:
|
||||
void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
|
||||
void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
|
||||
|
||||
/**
|
||||
* Handle window visibility changed.
|
||||
*/
|
||||
void HandleWindowVisibilityChanged(
|
||||
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
|
||||
|
||||
/**
|
||||
* Set the current userId, only used by abilityMgr.
|
||||
*
|
||||
@@ -721,6 +730,16 @@ public:
|
||||
void FreeFocusListener();
|
||||
|
||||
/**
|
||||
* Init window visibility changed listener.
|
||||
*/
|
||||
void InitWindowVisibilityChangedListener();
|
||||
|
||||
/**
|
||||
* Free window visibility changed listener.
|
||||
*/
|
||||
void FreeWindowVisibilityChangedListener();
|
||||
|
||||
/*
|
||||
* @brief Notify NativeEngine GC of status change.
|
||||
*
|
||||
* @param state GC state
|
||||
@@ -1045,6 +1064,9 @@ private:
|
||||
int32_t NotifyAbilitysDebugChange(const std::string &bundleName, const bool &isAppDebug);
|
||||
|
||||
bool JudgeSelfCalledByToken(const sptr<IRemoteObject> &token, const PageStateData &pageStateData);
|
||||
|
||||
void SendReStartProcessEvent(const AAFwk::EventInfo &eventInfo,
|
||||
const std::shared_ptr<AppRunningRecord> &appRecord);
|
||||
private:
|
||||
/**
|
||||
* Notify application status.
|
||||
@@ -1077,6 +1099,7 @@ private:
|
||||
ffrt::mutex configurationObserverLock_;
|
||||
std::vector<sptr<IConfigurationObserver>> configurationObservers_;
|
||||
sptr<WindowFocusChangedListener> focusListener_;
|
||||
sptr<WindowVisibilityChangedListener> windowVisibilityChangedListener_;
|
||||
std::vector<std::shared_ptr<AppRunningRecord>> restartResedentTaskList_;
|
||||
std::map<std::string, std::vector<BaseSharedBundleInfo>> runningSharedBundleList_;
|
||||
std::unordered_set<int32_t> renderUidSet_;
|
||||
@@ -1086,6 +1109,8 @@ private:
|
||||
int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS;
|
||||
sptr<IAbilityDebugResponse> abilityDebugResponse_;
|
||||
std::shared_ptr<AppDebugManager> appDebugManager_;
|
||||
ffrt::mutex killpedProcessMapLock_;
|
||||
mutable std::map<int64_t, std::string> killedPorcessMap_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -209,6 +209,7 @@ public:
|
||||
bool IsApplicationBackground(const std::string &bundleName);
|
||||
bool IsApplicationFirstFocused(const AppRunningRecord &foregroundingRecord);
|
||||
bool IsApplicationUnfocused(const std::string &bundleName);
|
||||
void OnWindowVisibilityChanged(const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
|
||||
|
||||
/**
|
||||
* @brief Set attach app debug mode.
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "module_running_record.h"
|
||||
#include "app_spawn_msg_wrapper.h"
|
||||
#include "app_malloc_info.h"
|
||||
#include "window_visibility_changed_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@@ -627,6 +628,10 @@ public:
|
||||
|
||||
int32_t NotifyAppFault(const FaultData &faultData);
|
||||
|
||||
void OnWindowVisibilityChanged(const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
|
||||
|
||||
bool IsAbilitytiesBackground();
|
||||
|
||||
inline void SetAbilityForegroundingFlag()
|
||||
{
|
||||
isAbilityForegrounding_.store(true);
|
||||
@@ -788,6 +793,8 @@ private:
|
||||
int32_t callerTokenId_ = -1;
|
||||
ProcessType processType_ = ProcessType::NORMAL;
|
||||
ExtensionAbilityType extensionType_ = ExtensionAbilityType::UNSPECIFIED;
|
||||
|
||||
std::set<uint32_t> windowIds_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -157,6 +157,8 @@ public:
|
||||
const std::shared_ptr<ApplicationInfo> GetAppInfo();
|
||||
|
||||
bool RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const;
|
||||
|
||||
bool IsAbilitiesBackgrounded();
|
||||
|
||||
private:
|
||||
void SendEvent(uint32_t msg, int64_t timeOut, const std::shared_ptr<AbilityRunningRecord> &abilityRecord);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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_APP_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H
|
||||
#define OHOS_APP_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H
|
||||
|
||||
#include "task_handler_wrap.h"
|
||||
#include "window_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AppMgrServiceInner;
|
||||
class WindowVisibilityChangedListener : public OHOS::Rosen::IVisibilityChangedListener {
|
||||
public:
|
||||
WindowVisibilityChangedListener(
|
||||
const std::weak_ptr<AppMgrServiceInner> &appInner, const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler);
|
||||
virtual ~WindowVisibilityChangedListener() {}
|
||||
|
||||
void OnWindowVisibilityChanged(
|
||||
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<AppMgrServiceInner> appServiceInner_;
|
||||
std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APP_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H
|
||||
@@ -71,6 +71,7 @@ void AmsMgrScheduler::LoadAbility(const sptr<IRemoteObject> &token, const sptr<I
|
||||
return;
|
||||
}
|
||||
PerfProfile::GetInstance().SetAbilityLoadStartTime(GetTickCount());
|
||||
HILOG_INFO("SubmitLoadTask: %{public}s-%{public}s", abilityInfo->bundleName.c_str(), abilityInfo->name.c_str());
|
||||
std::function<void()> loadAbilityFunc =
|
||||
std::bind(&AppMgrServiceInner::LoadAbility, amsMgrServiceInner_, token, preToken, abilityInfo, appInfo, want);
|
||||
|
||||
@@ -174,13 +175,13 @@ void AmsMgrScheduler::KillProcessesByUserId(int32_t userId)
|
||||
HILOG_ERROR("The caller is not system-app, can not use system-api");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto permission = AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES;
|
||||
if (amsMgrServiceInner_->VerifyAccountPermission(permission, userId) == ERR_PERMISSION_DENIED) {
|
||||
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::function<void()> killProcessesByUserIdFunc =
|
||||
std::bind(&AppMgrServiceInner::KillProcessesByUserId, amsMgrServiceInner_, userId);
|
||||
amsHandler_->SubmitTask(killProcessesByUserIdFunc, TASK_KILL_PROCESSES_BY_USERID);
|
||||
|
||||
@@ -63,16 +63,22 @@ void AppLifeCycleDeal::AddAbilityStage(const HapModuleInfo &abilityStage)
|
||||
void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability)
|
||||
{
|
||||
if (appThread_ && ability) {
|
||||
auto &abilityInfo = ability->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr && abilityInfo->type == AbilityType::PAGE) {
|
||||
auto abilityInfo = ability->GetAbilityInfo();
|
||||
if (abilityInfo == nullptr) {
|
||||
HILOG_WARN("LoadLifecycle: abilityInfo null.");
|
||||
return;
|
||||
}
|
||||
if (abilityInfo->type == AbilityType::PAGE) {
|
||||
FreezeUtil::LifecycleFlow flow = {ability->GetToken(), FreezeUtil::TimeoutState::LOAD};
|
||||
auto entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AppLifeCycleDeal::LaunchAbility; the LoadAbility lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
HILOG_INFO("LoadLifecycle: Launch ability.");
|
||||
appThread_->ScheduleLaunchAbility(*(ability->GetAbilityInfo()), ability->GetToken(),
|
||||
appThread_->ScheduleLaunchAbility(*abilityInfo, ability->GetToken(),
|
||||
ability->GetWant());
|
||||
} else {
|
||||
HILOG_WARN("LoadLifecycle.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -807,6 +807,7 @@ void AppMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::strin
|
||||
}
|
||||
|
||||
appMgrServiceInner_->InitFocusListener();
|
||||
appMgrServiceInner_->InitWindowVisibilityChangedListener();
|
||||
}
|
||||
|
||||
void AppMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
|
||||
@@ -822,6 +823,7 @@ void AppMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::st
|
||||
}
|
||||
|
||||
appMgrServiceInner_->FreeFocusListener();
|
||||
appMgrServiceInner_->FreeWindowVisibilityChangedListener();
|
||||
}
|
||||
|
||||
int32_t AppMgrService::ChangeAppGcState(pid_t pid, int32_t state)
|
||||
|
||||
@@ -37,10 +37,8 @@
|
||||
#include "common_event_support.h"
|
||||
#include "datetime_ex.h"
|
||||
#include "distributed_data_mgr.h"
|
||||
#include "event_report.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hisysevent.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
@@ -88,6 +86,7 @@ constexpr int KILL_PROCESS_TIMEOUT_MICRO_SECONDS = 1000;
|
||||
constexpr int KILL_PROCESS_DELAYTIME_MICRO_SECONDS = 200;
|
||||
// delay register focus listener to wms
|
||||
constexpr int REGISTER_FOCUS_DELAY = 5000;
|
||||
constexpr int REGISTER_VISIBILITY_DELAY = 5000;
|
||||
const std::string CLASS_NAME = "ohos.app.MainThread";
|
||||
const std::string FUNC_NAME = "main";
|
||||
const std::string RENDER_PARAM = "invalidparam";
|
||||
@@ -210,6 +209,7 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
|
||||
auto appRecord =
|
||||
appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo);
|
||||
if (!appRecord) {
|
||||
HILOG_INFO("appRecord null");
|
||||
bool appExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByBundleName(bundleInfo.name);
|
||||
appRecord = CreateAppRunningRecord(token, preToken, appInfo, abilityInfo,
|
||||
processName, bundleInfo, hapModuleInfo, want);
|
||||
@@ -219,7 +219,7 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
|
||||
}
|
||||
if (hapModuleInfo.isStageBasedModel && !IsMainProcess(appInfo, hapModuleInfo)) {
|
||||
appRecord->SetKeepAliveAppState(false, false);
|
||||
HILOG_DEBUG("The process %{public}s will not keepalive", hapModuleInfo.process.c_str());
|
||||
HILOG_INFO("The process %{public}s will not keepalive", hapModuleInfo.process.c_str());
|
||||
}
|
||||
SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::COLD);
|
||||
auto callRecord = GetAppRunningRecordByAbilityToken(preToken);
|
||||
@@ -277,6 +277,7 @@ void AppMgrServiceInner::MakeProcessName(const std::shared_ptr<AbilityInfo> &abi
|
||||
return;
|
||||
}
|
||||
if (!abilityInfo->process.empty()) {
|
||||
HILOG_INFO("Process not null");
|
||||
processName = abilityInfo->process;
|
||||
return;
|
||||
}
|
||||
@@ -290,13 +291,14 @@ void AppMgrServiceInner::MakeProcessName(
|
||||
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName) const
|
||||
{
|
||||
if (!appInfo) {
|
||||
HILOG_ERROR("appInfo nill");
|
||||
return;
|
||||
}
|
||||
// check after abilityInfo, because abilityInfo contains extension process.
|
||||
if (hapModuleInfo.isStageBasedModel && !hapModuleInfo.process.empty()
|
||||
&& hapModuleInfo.process != appInfo->bundleName) {
|
||||
processName = hapModuleInfo.process;
|
||||
HILOG_DEBUG("Stage mode, Make processName:%{public}s", processName.c_str());
|
||||
HILOG_INFO("Stage mode, Make processName:%{public}s", processName.c_str());
|
||||
return;
|
||||
}
|
||||
bool isRunInIsolationMode = CheckIsolationMode(hapModuleInfo);
|
||||
@@ -481,6 +483,13 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptr<AppRunningRecor
|
||||
auto callerRecord = GetAppRunningRecordByPid(callerPid);
|
||||
if (callerRecord != nullptr) {
|
||||
eventInfo.callerBundleName = callerRecord->GetBundleName();
|
||||
eventInfo.callerUid = callerRecord->GetUid();
|
||||
eventInfo.callerState = static_cast<int32_t>(callerRecord->GetState());
|
||||
auto applicationInfo = callerRecord->GetApplicationInfo();
|
||||
if (applicationInfo != nullptr) {
|
||||
eventInfo.callerVersionName = applicationInfo->versionName;
|
||||
eventInfo.callerVersionCode = applicationInfo->versionCode;
|
||||
}
|
||||
} else {
|
||||
HILOG_ERROR("callerRecord is nullptr, can not get callerBundleName.");
|
||||
}
|
||||
@@ -1135,6 +1144,11 @@ int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid) const
|
||||
eventInfo.versionName = applicationInfo->versionName;
|
||||
eventInfo.versionCode = applicationInfo->versionCode;
|
||||
}
|
||||
if (ret >= 0) {
|
||||
int64_t killTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
|
||||
system_clock::now().time_since_epoch()).count();
|
||||
killedPorcessMap_.emplace(killTime, appRecord->GetProcessName());
|
||||
}
|
||||
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
|
||||
eventInfo.processName = appRecord->GetProcessName();
|
||||
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_TERMINATE, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
@@ -1851,6 +1865,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
|
||||
const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("StartProcess: %{public}s", bundleName.c_str());
|
||||
if (!appRecord) {
|
||||
HILOG_ERROR("appRecord is null");
|
||||
return;
|
||||
@@ -1891,7 +1906,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
|
||||
HspList hspList;
|
||||
ErrCode ret = bundleMgr_->GetBaseSharedBundleInfos(bundleName, hspList);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("GetBaseSharedBundleInfos failed: %d", ret);
|
||||
HILOG_ERROR("GetBaseSharedBundleInfos failed: %{public}d", ret);
|
||||
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
|
||||
return;
|
||||
}
|
||||
@@ -1933,7 +1948,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
|
||||
|
||||
SetOverlayInfo(bundleName, userId, startMsg);
|
||||
|
||||
HILOG_DEBUG("Start process, apl is %{public}s, bundleName is %{public}s, startFlags is %{public}d.",
|
||||
HILOG_INFO("Start process, apl is %{public}s, bundleName is %{public}s, startFlags is %{public}d.",
|
||||
startMsg.apl.c_str(), bundleName.c_str(), startFlags);
|
||||
|
||||
bundleMgrResult = IN_PROCESS_CALL(bundleMgr_->GetBundleGidsByUid(bundleName, uid, startMsg.gids));
|
||||
@@ -2084,6 +2099,7 @@ bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr<AppRunningR
|
||||
uid : %{public}d, process : %{public}s",
|
||||
__func__, eventInfo.time, eventInfo.abilityType, eventInfo.callerBundleName.c_str(), eventInfo.callerUid,
|
||||
eventInfo.callerProcessName.c_str());
|
||||
SendReStartProcessEvent(eventInfo, appRecord);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -3778,6 +3794,61 @@ void AppMgrServiceInner::HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo
|
||||
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessStateChanged(appRecord);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::InitWindowVisibilityChangedListener()
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
if (windowVisibilityChangedListener_ != nullptr) {
|
||||
HILOG_WARN("Visibility listener has been initiated.");
|
||||
return;
|
||||
}
|
||||
windowVisibilityChangedListener_ =
|
||||
new (std::nothrow) WindowVisibilityChangedListener(weak_from_this(), taskHandler_);
|
||||
auto registerTask = [innerService = weak_from_this()] () {
|
||||
auto inner = innerService.lock();
|
||||
if (inner == nullptr) {
|
||||
HILOG_ERROR("Service inner is nullptr.");
|
||||
return;
|
||||
}
|
||||
if (inner->windowVisibilityChangedListener_ == nullptr) {
|
||||
HILOG_ERROR("Window visibility changed listener is nullptr.");
|
||||
return;
|
||||
}
|
||||
WindowManager::GetInstance().RegisterVisibilityChangedListener(inner->windowVisibilityChangedListener_);
|
||||
};
|
||||
|
||||
if (taskHandler_ == nullptr) {
|
||||
HILOG_ERROR("Task handler is nullptr.");
|
||||
return;
|
||||
}
|
||||
taskHandler_->SubmitTask(registerTask, "RegisterVisibilityListener.", REGISTER_VISIBILITY_DELAY);
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::FreeWindowVisibilityChangedListener()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (windowVisibilityChangedListener_ == nullptr) {
|
||||
HILOG_WARN("Visibility listener has been freed.");
|
||||
return;
|
||||
}
|
||||
WindowManager::GetInstance().UnregisterVisibilityChangedListener(windowVisibilityChangedListener_);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::HandleWindowVisibilityChanged(
|
||||
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (windowVisibilityInfos.empty()) {
|
||||
HILOG_WARN("Window visibility info is empty.");
|
||||
return;
|
||||
}
|
||||
if (appRunningManager_ == nullptr) {
|
||||
HILOG_ERROR("App running manager is nullptr.");
|
||||
return;
|
||||
}
|
||||
appRunningManager_->OnWindowVisibilityChanged(windowVisibilityInfos);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::PointerDeviceEventCallback(const char *key, const char *value, void *context)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
@@ -4506,5 +4577,39 @@ bool AppMgrServiceInner::JudgeSelfCalledByToken(const sptr<IRemoteObject> &token
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::SendReStartProcessEvent(const AAFwk::EventInfo &eventInfo,
|
||||
const std::shared_ptr<AppRunningRecord> &appRecord)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!appRecord) {
|
||||
HILOG_ERROR("appRecord is nullptr");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<ffrt::mutex> lock(killpedProcessMapLock_);
|
||||
int64_t restartTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
|
||||
system_clock::now().time_since_epoch()).count();
|
||||
for (auto iter = killedPorcessMap_.begin(); iter != killedPorcessMap_.end();) {
|
||||
int64_t killTime = iter->first;
|
||||
if (restartTime - killTime > 2000) {
|
||||
killedPorcessMap_.erase(iter++);
|
||||
continue;
|
||||
}
|
||||
AAFwk::EventInfo currentEventInfo;
|
||||
currentEventInfo = eventInfo;
|
||||
currentEventInfo.time = restartTime;
|
||||
std::string processName = appRecord->GetProcessName();
|
||||
currentEventInfo.appUid = appRecord->GetUid();
|
||||
if (currentEventInfo.bundleName == currentEventInfo.callerBundleName &&
|
||||
processName != currentEventInfo.callerProcessName) {
|
||||
currentEventInfo.processName = processName;
|
||||
AAFwk::EventReport::SendKeyEvent(AAFwk::EventName::RESTART_PROCESS_BY_SAME_APP,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
killedPorcessMap_.erase(iter++);
|
||||
continue;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -854,6 +854,24 @@ bool AppRunningManager::IsApplicationBackground(const std::string &bundleName)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppRunningManager::OnWindowVisibilityChanged(
|
||||
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
for (const auto &info : windowVisibilityInfos) {
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("Window visibility info is nullptr.");
|
||||
continue;
|
||||
}
|
||||
auto appRecord = GetAppRunningRecordByPidInner(info->pid_);
|
||||
if (appRecord == nullptr) {
|
||||
HILOG_ERROR("App running record is nullptr.");
|
||||
return;
|
||||
}
|
||||
appRecord->OnWindowVisibilityChanged(windowVisibilityInfos);
|
||||
}
|
||||
}
|
||||
|
||||
bool AppRunningManager::IsApplicationFirstFocused(const AppRunningRecord &focusedRecord)
|
||||
{
|
||||
HILOG_DEBUG("check focus function called.");
|
||||
|
||||
@@ -886,7 +886,7 @@ void AppRunningRecord::AbilityBackground(const std::shared_ptr<AbilityRunningRec
|
||||
|
||||
|
||||
// Then schedule application background when all ability is not foreground.
|
||||
if (foregroundSize == 0 && mainBundleName_ != LAUNCHER_NAME) {
|
||||
if (foregroundSize == 0 && mainBundleName_ != LAUNCHER_NAME && windowIds_.empty()) {
|
||||
ScheduleBackgroundRunning();
|
||||
}
|
||||
} else {
|
||||
@@ -1581,6 +1581,62 @@ int32_t AppRunningRecord::NotifyAppFault(const FaultData &faultData)
|
||||
return appLifeCycleDeal_->NotifyAppFault(faultData);
|
||||
}
|
||||
|
||||
bool AppRunningRecord::IsAbilitytiesBackground()
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
|
||||
for (const auto &iter : hapModules_) {
|
||||
for (const auto &moduleRecord : iter.second) {
|
||||
if (moduleRecord == nullptr) {
|
||||
HILOG_ERROR("Module record is nullptr.");
|
||||
continue;
|
||||
}
|
||||
if (!moduleRecord->IsAbilitiesBackgrounded()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppRunningRecord::OnWindowVisibilityChanged(
|
||||
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (windowVisibilityInfos.empty()) {
|
||||
HILOG_WARN("Window visibility info is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &info : windowVisibilityInfos) {
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("Window visibility info is nullptr.");
|
||||
continue;
|
||||
}
|
||||
if (info->pid_ != GetPriorityObject()->GetPid()) {
|
||||
continue;
|
||||
}
|
||||
auto iter = windowIds_.find(info->windowId_);
|
||||
if (iter != windowIds_.end() && !info->isVisible_) {
|
||||
windowIds_.erase(iter);
|
||||
continue;
|
||||
}
|
||||
if (iter == windowIds_.end() && info->isVisible_) {
|
||||
windowIds_.emplace(info->windowId_);
|
||||
}
|
||||
}
|
||||
|
||||
if (!windowIds_.empty() && curState_ != ApplicationState::APP_STATE_FOREGROUND) {
|
||||
SetUpdateStateFromService(true);
|
||||
ScheduleForegroundRunning();
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowIds_.empty() && IsAbilitytiesBackground() && curState_ == ApplicationState::APP_STATE_FOREGROUND) {
|
||||
SetUpdateStateFromService(true);
|
||||
ScheduleBackgroundRunning();
|
||||
}
|
||||
}
|
||||
|
||||
bool AppRunningRecord::IsContinuousTask()
|
||||
{
|
||||
return isContinuousTask_;
|
||||
|
||||
@@ -300,6 +300,31 @@ bool ModuleRunningRecord::RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteOb
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModuleRunningRecord::IsAbilitiesBackgrounded()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<ffrt::mutex> lock(abilitiesMutex_);
|
||||
for (const auto &iter : abilities_) {
|
||||
const auto &ability = iter.second;
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("Ability is nullptr.");
|
||||
continue;
|
||||
}
|
||||
const auto &abilityInfo = ability->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr && abilityInfo->type != AbilityType::PAGE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &state = ability->GetState();
|
||||
if (state != AbilityState::ABILITY_STATE_BACKGROUND &&
|
||||
state != AbilityState::ABILITY_STATE_TERMINATED &&
|
||||
state != AbilityState::ABILITY_STATE_END) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModuleRunningRecord::SetAppMgrServiceInner(const std::weak_ptr<AppMgrServiceInner> &inner)
|
||||
{
|
||||
appMgrServiceInner_ = inner;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 "window_visibility_changed_listener.h"
|
||||
|
||||
#include "app_mgr_service_inner.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using namespace OHOS::Rosen;
|
||||
WindowVisibilityChangedListener::WindowVisibilityChangedListener(
|
||||
const std::weak_ptr<AppMgrServiceInner> &appInner, const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler)
|
||||
: appServiceInner_(appInner), taskHandler_(handler)
|
||||
{}
|
||||
|
||||
void WindowVisibilityChangedListener::OnWindowVisibilityChanged(
|
||||
const std::vector<sptr<WindowVisibilityInfo>> &windowVisibilityInfos)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (windowVisibilityInfos.empty()) {
|
||||
HILOG_WARN("Window visibility info is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (taskHandler_ == nullptr) {
|
||||
HILOG_ERROR("Task handler is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto task = [inner = appServiceInner_, windowVisibilityInfos] {
|
||||
auto serviceInner = inner.lock();
|
||||
if (serviceInner == nullptr) {
|
||||
HILOG_ERROR("Failed to get app mgr service inner.");
|
||||
return;
|
||||
}
|
||||
serviceInner->HandleWindowVisibilityChanged(windowVisibilityInfos);
|
||||
};
|
||||
taskHandler_->SubmitTask(task);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -44,6 +44,11 @@ struct EventInfo {
|
||||
int32_t exitResult = -1;
|
||||
int32_t bundleType = -1;
|
||||
int32_t startType = 0;
|
||||
int32_t appUid = -1;
|
||||
int32_t callerState = -1;
|
||||
uint32_t callerVersionCode = -1;
|
||||
std::string callerVersionName;
|
||||
std::string uri;
|
||||
};
|
||||
|
||||
enum class EventName {
|
||||
@@ -82,6 +87,12 @@ enum class EventName {
|
||||
PROCESS_EXIT,
|
||||
DRAWN_COMPLETED,
|
||||
APP_STARTUP_TYPE,
|
||||
|
||||
// key behavior event
|
||||
GRANT_URI_PERMISSION,
|
||||
FA_SHOW_ON_LOCK,
|
||||
START_PRIVATE_ABILITY,
|
||||
RESTART_PROCESS_BY_SAME_APP,
|
||||
};
|
||||
|
||||
class EventReport {
|
||||
@@ -89,6 +100,7 @@ public:
|
||||
static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
|
||||
static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
|
||||
static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
|
||||
static void SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
|
||||
|
||||
private:
|
||||
static std::string ConvertEventName(const EventName &eventName);
|
||||
|
||||
@@ -44,6 +44,12 @@ constexpr const char *EVENT_KEY_EXIT_RESULT = "EXIT_RESULT";
|
||||
constexpr const char *EVENT_KEY_EXIT_PID = "EXIT_PID";
|
||||
constexpr const char *EVENT_KEY_BUNDLE_TYPE = "BUNDLE_TYPE";
|
||||
constexpr const char *EVENT_KEY_START_TYPE = "START_TYPE";
|
||||
constexpr const char *EVENT_KEY_CALLER_STATE = "CALLER_STATE";
|
||||
constexpr const char *EVENT_KEY_CALLER_VERSION_NAME = "CALLER_VERSION_NAME";
|
||||
constexpr const char *EVENT_KEY_CALLER_VERSION_CODE = "CALLER_VERSION_CODE";
|
||||
constexpr const char *EVENT_KEY_URI = "URI";
|
||||
constexpr const char *EVENT_KEY_RESTART_TIME = "RESTART_TIME";
|
||||
constexpr const char *EVENT_KEY_APP_UID = "APP_UID";
|
||||
const std::map<EventName, std::string> eventNameToStrMap_ = {
|
||||
std::map<EventName, std::string>::value_type(EventName::START_ABILITY_ERROR, "START_ABILITY_ERROR"),
|
||||
std::map<EventName, std::string>::value_type(EventName::TERMINATE_ABILITY_ERROR, "TERMINATE_ABILITY_ERROR"),
|
||||
@@ -71,6 +77,11 @@ const std::map<EventName, std::string> eventNameToStrMap_ = {
|
||||
std::map<EventName, std::string>::value_type(EventName::PROCESS_EXIT, "PROCESS_EXIT"),
|
||||
std::map<EventName, std::string>::value_type(EventName::DRAWN_COMPLETED, "DRAWN_COMPLETED"),
|
||||
std::map<EventName, std::string>::value_type(EventName::APP_STARTUP_TYPE, "APP_STARTUP_TYPE"),
|
||||
std::map<EventName, std::string>::value_type(EventName::GRANT_URI_PERMISSION, "GRANT_URI_PERMISSION"),
|
||||
std::map<EventName, std::string>::value_type(EventName::FA_SHOW_ON_LOCK, "FA_SHOW_ON_LOCK"),
|
||||
std::map<EventName, std::string>::value_type(EventName::START_PRIVATE_ABILITY, "START_PRIVATE_ABILITY"),
|
||||
std::map<EventName, std::string>::value_type(EventName::RESTART_PROCESS_BY_SAME_APP,
|
||||
"RESTART_PROCESS_BY_SAME_APP"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -176,7 +187,11 @@ void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type,
|
||||
EVENT_KEY_VERSION_NAME, eventInfo.versionName,
|
||||
EVENT_KEY_VERSION_CODE, eventInfo.versionCode,
|
||||
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName);
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
|
||||
EVENT_KEY_CALLER_VERSION_NAME, eventInfo.callerVersionName,
|
||||
EVENT_KEY_CALLER_VERSION_CODE, eventInfo.callerVersionCode,
|
||||
EVENT_KEY_CALLER_UID, eventInfo.callerUid,
|
||||
EVENT_KEY_CALLER_STATE, eventInfo.callerState);
|
||||
break;
|
||||
default:
|
||||
HiSysEventWrite(
|
||||
@@ -324,6 +339,50 @@ void EventReport::SendExtensionEvent(const EventName &eventName, HiSysEventType
|
||||
}
|
||||
}
|
||||
|
||||
void EventReport::SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo)
|
||||
{
|
||||
std::string name = ConvertEventName(eventName);
|
||||
if (name == "INVALIDEVENTNAME") {
|
||||
HILOG_ERROR("invalid eventName");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("name is %{public}s", name.c_str());
|
||||
switch (eventName) {
|
||||
case EventName::GRANT_URI_PERMISSION:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
|
||||
EVENT_KEY_URI, eventInfo.uri);
|
||||
break;
|
||||
case EventName::FA_SHOW_ON_LOCK:
|
||||
case EventName::START_PRIVATE_ABILITY:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName);
|
||||
break;
|
||||
case EventName::RESTART_PROCESS_BY_SAME_APP:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_RESTART_TIME, eventInfo.time,
|
||||
EVENT_KEY_APP_UID, eventInfo.appUid,
|
||||
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.callerProcessName,
|
||||
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string EventReport::ConvertEventName(const EventName &eventName)
|
||||
{
|
||||
auto it = eventNameToStrMap_.find(eventName);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"ondemand" : true,
|
||||
"uid" : "quickfixserver",
|
||||
"gid" : ["system"],
|
||||
"secon" : "u:r:quick_fix:s0"
|
||||
"secon" : "u:r:quick_fix:s0",
|
||||
"apl" : "system_basic",
|
||||
"permission" : ["ohos.permission.RUNNING_STATE_OBSERVER"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "event_report.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
@@ -147,6 +148,18 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const std::vector<Uri> &uri
|
||||
targetTokenId, autoremove);
|
||||
if (tempRet == ERR_OK) {
|
||||
ret = ERR_OK;
|
||||
auto isSaCall = PermissionVerification::GetInstance()->IsSACall();
|
||||
auto calleeTokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(targetTokenId);
|
||||
if (isSaCall && calleeTokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
|
||||
EventInfo eventInfo;
|
||||
Uri uri_inner = uriVec[0];
|
||||
eventInfo.bundleName = targetBundleName;
|
||||
eventInfo.callerBundleName = uri_inner.GetAuthority();
|
||||
eventInfo.uri = uri_inner.ToString();
|
||||
EventReport::SendKeyEvent(EventName::GRANT_URI_PERMISSION, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
} else {
|
||||
HILOG_INFO("caller is not SA or callee is SA");
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -197,13 +197,13 @@ public:
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
ErrCode GetRunningFormInfos(std::vector<RunningFormInfo> &runningFormInfos)
|
||||
ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode GetRunningFormInfosByBundleName(const std::string &bundleName,
|
||||
std::vector<RunningFormInfo> &runningFormInfos)
|
||||
ErrCode GetRunningFormInfosByBundleName(
|
||||
const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
+9
-3
@@ -23,6 +23,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const int32_t UNSPECIFIED_USER_ID = -2;
|
||||
}
|
||||
class AppControlProxy : public IRemoteProxy<IAppControlMgr> {
|
||||
public:
|
||||
using Want = OHOS::AAFwk::Want;
|
||||
@@ -59,9 +62,12 @@ public:
|
||||
virtual ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName,
|
||||
int32_t userId, AppJumpControlRule &controlRule) override;
|
||||
|
||||
virtual ErrCode SetDisposedStatus(const std::string& appId, const Want& want) override;
|
||||
virtual ErrCode DeleteDisposedStatus(const std::string& appId) override;
|
||||
virtual ErrCode GetDisposedStatus(const std::string& appId, Want& want) override;
|
||||
virtual ErrCode SetDisposedStatus(
|
||||
const std::string& appId, const Want& want, int32_t userId = UNSPECIFIED_USER_ID) override;
|
||||
virtual ErrCode DeleteDisposedStatus(
|
||||
const std::string& appId, int32_t userId = UNSPECIFIED_USER_ID) override;
|
||||
virtual ErrCode GetDisposedStatus(
|
||||
const std::string& appId, Want& want, int32_t userId = UNSPECIFIED_USER_ID) override;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
+3
-3
@@ -122,17 +122,17 @@ ErrCode AppControlProxy::GetAppJumpControlRule(const std::string &callerBundleNa
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AppControlProxy::SetDisposedStatus(const std::string& appId, const Want& want)
|
||||
ErrCode AppControlProxy::SetDisposedStatus(const std::string& appId, const Want& want, int32_t userId)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AppControlProxy::DeleteDisposedStatus(const std::string& appId)
|
||||
ErrCode AppControlProxy::DeleteDisposedStatus(const std::string& appId, int32_t userId)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AppControlProxy::GetDisposedStatus(const std::string& appId, Want& want)
|
||||
ErrCode AppControlProxy::GetDisposedStatus(const std::string& appId, Want& want, int32_t userId)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") {
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
]
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
|
||||
@@ -41,6 +41,7 @@ ohos_unittest("AmsWorkFlowTest") {
|
||||
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp",
|
||||
]
|
||||
|
||||
sources += [ "ams_workflow_test.cpp" ]
|
||||
|
||||
@@ -39,6 +39,7 @@ ohos_unittest("AmsRecentAppListTest") {
|
||||
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_bundle_manager.cpp",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_overlay_manager.cpp",
|
||||
]
|
||||
|
||||
@@ -38,6 +38,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") {
|
||||
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_bundle_manager.cpp",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_overlay_manager.cpp",
|
||||
]
|
||||
|
||||
@@ -38,6 +38,7 @@ ohos_unittest("AMSEventHandlerTest") {
|
||||
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp",
|
||||
]
|
||||
|
||||
sources += [ "app_mgr_service_event_handler_test.cpp" ]
|
||||
|
||||
@@ -23,7 +23,8 @@ ohos_unittest("app_running_manager_test") {
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
|
||||
|
||||
sources = [ "app_running_manager_test.cpp" ]
|
||||
sources = [ "${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp" ]
|
||||
sources += [ "app_running_manager_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
@@ -58,6 +59,7 @@ ohos_unittest("app_running_manager_test") {
|
||||
"memory_utils:libmeminfo",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -214,12 +214,12 @@ public:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ErrCode GetRunningFormInfos(std::vector<RunningFormInfo> &runningFormInfos) override
|
||||
ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
ErrCode GetRunningFormInfosByBundleName(const std::string &bundleName,
|
||||
std::vector<RunningFormInfo> &runningFormInfos) override
|
||||
ErrCode GetRunningFormInfosByBundleName(
|
||||
const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "wants_info.h"
|
||||
#include "want_params.h"
|
||||
#include "want_receiver_stub.h"
|
||||
#include "want_agent_client.h"
|
||||
#include "want_agent_helper.h"
|
||||
#include "want_sender_info.h"
|
||||
#include "want_sender_stub.h"
|
||||
@@ -1243,7 +1244,8 @@ HWTEST_F(PendingWantTest, PendingWant_6700, Function | MediumTest | Level1)
|
||||
sptr<AAFwk::IWantSender> target = nullptr;
|
||||
std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>();
|
||||
ErrCode err = pendingWant->Cancel(target);
|
||||
EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT);
|
||||
ErrCode err1 = WantAgentClient::GetInstance().CancelWantSender(target);
|
||||
EXPECT_EQ(err, err1);
|
||||
HILOG_INFO("PendingWant_6700 end.");
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,9 @@ ohos_unittest("quick_fix_manager_apply_task_test") {
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:quickfix_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
|
||||
+25
@@ -20,12 +20,14 @@
|
||||
#include "iservice_registry.h"
|
||||
#include "mock_bundle_manager.h"
|
||||
#include "mock_quick_fix_util.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "quick_fix_error_utils.h"
|
||||
#define private public
|
||||
#include "quick_fix_manager_service.h"
|
||||
#undef private
|
||||
#include "quick_fix_result_info.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@@ -58,6 +60,27 @@ static void WaitUntilTaskDone(const std::shared_ptr<AppExecFwk::EventHandler>& h
|
||||
auto f = [&taskCalled]() { taskCalled.store(true); };
|
||||
WaitUntilTaskCalled(f, handler, taskCalled);
|
||||
}
|
||||
|
||||
static void SetPermission()
|
||||
{
|
||||
uint64_t tokenId;
|
||||
const char **perms = new const char *[1];
|
||||
perms[0] = "ohos.permission.RUNNING_STATE_OBSERVER";
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 1,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.aplStr = "system_basic",
|
||||
};
|
||||
|
||||
infoInstance.processName = "SetUpTestCase";
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
delete[] perms;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class QuickFixManagerApplyTaskTest : public testing::Test {
|
||||
@@ -453,6 +476,7 @@ HWTEST_F(QuickFixManagerApplyTaskTest, PostNotifyHotReloadPageTask_0200, TestSiz
|
||||
HWTEST_F(QuickFixManagerApplyTaskTest, RegAppStateObserver_0100, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("%{public}s start.", __func__);
|
||||
SetPermission();
|
||||
auto applyTask = std::make_shared<QuickFixManagerApplyTask>(bundleQfMgr_, appMgr_,
|
||||
quickFixMs_->eventHandler_, quickFixMs_);
|
||||
ASSERT_NE(applyTask, nullptr);
|
||||
@@ -469,6 +493,7 @@ HWTEST_F(QuickFixManagerApplyTaskTest, RegAppStateObserver_0100, TestSize.Level1
|
||||
HWTEST_F(QuickFixManagerApplyTaskTest, RegAppStateObserver_0200, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("%{public}s start.", __func__);
|
||||
SetPermission();
|
||||
auto applyTask = std::make_shared<QuickFixManagerApplyTask>(bundleQfMgr_, nullptr,
|
||||
quickFixMs_->eventHandler_, quickFixMs_);
|
||||
ASSERT_NE(applyTask, nullptr);
|
||||
|
||||
@@ -37,6 +37,7 @@ ohos_unittest("uri_permission_impl_test") {
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/uripermmgr:libupms_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "event_report.h"
|
||||
#include "mock_native_token.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "system_ability_manager_client.h"
|
||||
|
||||
@@ -39,6 +39,7 @@ ohos_unittest("uri_permission_persistable_test") {
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/uripermmgr:libupms_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability_manager_errors.h"
|
||||
#include "event_report.h"
|
||||
#include "mock_permission_verification.h"
|
||||
#include "mock_native_token.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
@@ -29,6 +29,7 @@ ohos_unittest("uri_permission_test") {
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/uripermmgr:libupms_static",
|
||||
]
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "event_report.h"
|
||||
#include "istorage_manager.h"
|
||||
#include "storage_manager_proxy.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
Reference in New Issue
Block a user