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

Signed-off-by: ql <qianli16@huawei.com>
This commit is contained in:
ql
2022-08-15 01:09:18 +00:00
committed by Gitee
15 changed files with 201 additions and 304 deletions
+31 -103
View File
@@ -46,58 +46,34 @@
## 目录
```
foundation/ability/ability_runtime #ability_runtime元能力运行时部件
├── frameworks
   ├── js
   │ └── napi # ability_runtime的napi代码实现
   └── native # ability_runtime的核心代码实现
├── interfaces
   ├── inner_api # ability_runtime的系统内部件间接口
│   ── kits
     └── native # ability_runtime的对外接口  
├── services
│ ├── abilitymgr # Ability管理服务框架代码
│ ├── appmgr # Ability管理服务框架代码
│ ├── common # 日志组件目录
│ ├── dataobsmgr # DataAbilityObserver管理服务框架代码
  └── uripermmge # UriPermission管理服务框架代码
├── test # 测试目录
└── tools # aa命令工具代码目录
foundation/ability/ability_base # ability_base元能力基础部件
├── frameworks
   └── js
│   └── napi # ability_base的napi代码实现
   └── native # ability_base的核心代码实现
├── interfaces
   └── inner_api # ability_base的系统内部件间接口 
── test # 测试目录
foundation/ability/dmsfwk # dmsfwk分布式组件管理部件
├── interfaces
│ ├── inner_api # dmsfwk的系统内部件间接口
│ └── kits # dmsfwk的对外接口
├── services # dmsfwk分布式组件管理代码
└── util # 公共方法代码
foundation/ability/form_fwk # form_fwk卡片运行时部件
├── frameworks
│   └── js
│   └── napi # form_fwk的napi代码实现
├── interfaces
│   ├── inner_api # form_fwk的系统内部件间接口 
│   └── kits
│     └── native # form_fwk的对外接口  
├── services # form管理服务框架代码
└── test # 测试目录
foundation/ability/idl_tool # idl工具部件
├── ast # idl语法解析定义代码
├── codegen # 跨进程通信模板生成模块代码
├── metadata # matedata自定义数据解析模块代码
├── parser # idl解析模块代码
├── test # 测试目录
└── util # 公共方法代码
foundation/ability #元能力子系统
├── ability_runtime #ability_runtime元能力运行时部件
├── frameworks
│   ├── js
│   │ └── napi # ability_runtime的napi代码实现
│ │   └── native # ability_runtime的核心代码实现
├── interfaces
│   ── inner_api # ability_runtime的系统内部件间接口
   └── kits
│ │     └── native # ability_runtime的对外接口  
│ ├── services
│ ├── abilitymgr # Ability管理服务框架代码
│ ├── appmgr # App管理服务框架代码
│ ├── common # 服务公共组件目录
│ ├── dataobsmgr # DataAbilityObserver管理服务框架代码
│ │  └── uripermmgr # UriPermission管理服务框架代码
│ ├── test # 测试目录
│ └── tools # aa命令工具代码目录
├── ability_base # ability_base元能力基础部件
├── ability_lite # ability_lite轻量化元能力部件
├── dmsfwk # dmsfwk分布式组件管理部件
── form_fwk # form_fwk卡片运行时部件
├── idl_tool # idl工具部件
```
@@ -140,57 +116,7 @@ foundation/ability/idl_tool # idl工具部件
* 示例
```javascript
import featureAbility from '@ohos.ability.featureAbility'
function addSlotsCallBack(err) {
console.info("==========================>startAbility=======================>");
}
featureAbility.startAbility(
{
want:
{
action: "",
entities: [""],
type: "",
options: {
// indicates the grant to perform read operations on the URI
authReadUriPermission: true,
// indicates the grant to perform write operations on the URI
authWriteUriPermission: true,
// support forward want result to origin ability
abilityForwardResult: true,
// used for marking the ability start-up is triggered by continuation
abilityContinuation: true,
// specifies whether a component does not belong to ohos
notOhosComponent: true,
// specifies whether an ability is started
abilityFormEnabled: true,
// indicates the grant for possible persisting on the URI.
authPersistableUriPermission: true,
// indicates the grant for possible persisting on the URI.
authPrefixUriPermission: true,
// support distributed scheduling system start up multiple devices
abilitySliceMultiDevice: true,
// indicates that an ability using the service template is started regardless of whether the
// host application has been started.
startForegroundAbility: true,
// install the specified ability if it's not installed.
installOnDemand: true,
// return result to origin ability slice
abilitySliceForwardResult: true,
// install the specified ability with background mode if it's not installed.
installWithBackgroundMode: true
},
deviceId: "",
bundleName: "com.example.startability",
abilityName: "com.example.startability.MainAbility",
uri: ""
},
},
);
)
```
其他功能开发指导可参考[**示例文档**](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ability/Readme-CN.md)
更多开发指导可参考[**示例文档**](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ability/Readme-CN.md)
## **aa命令**
@@ -234,6 +160,8 @@ aa force-stop com.ohos.app
[ability_base](https://gitee.com/openharmony/ability_ability_base)
[ability_lite](https://gitee.com/openharmony/ability_ability_lite)
[**ability_runtime**](https://gitee.com/openharmony/ability_ability_runtime)
[dmsfwk](https://gitee.com/openharmony/ability_dmsfwk)
@@ -47,11 +47,11 @@ constexpr size_t INDEX_TWO = 2;
constexpr int ERROR = -1;
using namespace OHOS::AbilityRuntime;
std::map<std::shared_ptr<NativeReference>, std::shared_ptr<AbilityMonitor>> monitorRecord_;
std::map<std::shared_ptr<NativeReference>, std::shared_ptr<AbilityStageMonitor>> stageMonitorRecord_;
std::map<std::weak_ptr<NativeReference>, sptr<IRemoteObject>, std::owner_less<>> ablityRecord_;
std::mutex mutexAblityRecord_;
std::mutex mtxStageMonitorRecord_;
std::map<std::shared_ptr<NativeReference>, std::shared_ptr<AbilityMonitor>> g_monitorRecord;
std::map<std::shared_ptr<NativeReference>, std::shared_ptr<AbilityStageMonitor>> g_stageMonitorRecord;
std::map<std::weak_ptr<NativeReference>, sptr<IRemoteObject>, std::owner_less<>> g_ablityRecord;
std::mutex g_mutexAblityRecord;
std::mutex g_mtxStageMonitorRecord;
NativeValue *AttachAppContext(NativeEngine *engine, void *value, void *)
{
@@ -91,10 +91,10 @@ JSAbilityDelegator::JSAbilityDelegator()
return;
}
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
for (auto it = ablityRecord_.begin(); it != ablityRecord_.end();) {
std::unique_lock<std::mutex> lck(g_mutexAblityRecord);
for (auto it = g_ablityRecord.begin(); it != g_ablityRecord.end();) {
if (it->second == property->token_) {
it = ablityRecord_.erase(it);
it = g_ablityRecord.erase(it);
continue;
}
++it;
@@ -297,10 +297,10 @@ NativeValue *JSAbilityDelegator::OnRemoveAbilityMonitor(NativeEngine &engine, Na
lastParam, nullptr, std::move(complete), &result));
if (AbilityDelegatorRegistry::GetAbilityDelegator()) {
for (auto iter = monitorRecord_.begin(); iter != monitorRecord_.end(); ++iter) {
for (auto iter = g_monitorRecord.begin(); iter != g_monitorRecord.end(); ++iter) {
std::shared_ptr<NativeReference> jsMonitor = iter->first;
if ((info.argv[INDEX_ZERO])->StrictEquals(jsMonitor->Get())) {
monitorRecord_.erase(iter);
g_monitorRecord.erase(iter);
break;
}
}
@@ -383,8 +383,8 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati
abilityObjectBox->object_ = property->object_;
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_.emplace(property->object_, property->token_);
std::unique_lock<std::mutex> lck(g_mutexAblityRecord);
g_ablityRecord.emplace(property->object_, property->token_);
};
AsyncTask::CompleteCallback complete = [abilityObjectBox](NativeEngine &engine, AsyncTask &task, int32_t status) {
@@ -647,8 +647,8 @@ NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, Na
task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed."));
} else {
{
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_.emplace(property->object_, property->token_);
std::unique_lock<std::mutex> lck(g_mutexAblityRecord);
g_ablityRecord.emplace(property->object_, property->token_);
}
task.Resolve(engine, property->object_.lock()->Get());
}
@@ -780,9 +780,9 @@ NativeValue *JSAbilityDelegator::OnFinishTest(NativeEngine &engine, NativeCallba
NativeValue *JSAbilityDelegator::ParseMonitorPara(
NativeEngine &engine, NativeValue *value, std::shared_ptr<AbilityMonitor> &monitor)
{
HILOG_INFO("enter, monitorRecord size = %{public}zu", monitorRecord_.size());
HILOG_INFO("enter, monitorRecord size = %{public}zu", g_monitorRecord.size());
for (auto iter = monitorRecord_.begin(); iter != monitorRecord_.end(); ++iter) {
for (auto iter = g_monitorRecord.begin(); iter != g_monitorRecord.end(); ++iter) {
std::shared_ptr<NativeReference> jsMonitor = iter->first;
if (value->StrictEquals(jsMonitor->Get())) {
HILOG_ERROR("monitor existed");
@@ -818,7 +818,7 @@ NativeValue *JSAbilityDelegator::ParseMonitorPara(
std::shared_ptr<NativeReference> reference = nullptr;
reference.reset(engine.CreateReference(value, 1));
monitorRecord_.emplace(reference, monitor);
g_monitorRecord.emplace(reference, monitor);
return engine.CreateNull();
}
@@ -826,10 +826,10 @@ NativeValue *JSAbilityDelegator::ParseMonitorPara(
NativeValue *JSAbilityDelegator::ParseStageMonitorPara(
NativeEngine &engine, NativeValue *value, std::shared_ptr<AbilityStageMonitor> &monitor, bool &isExisted)
{
HILOG_INFO("enter, stageMonitorRecord size = %{public}zu", stageMonitorRecord_.size());
HILOG_INFO("enter, stageMonitorRecord size = %{public}zu", g_stageMonitorRecord.size());
isExisted = false;
for (auto iter = stageMonitorRecord_.begin(); iter != stageMonitorRecord_.end(); ++iter) {
for (auto iter = g_stageMonitorRecord.begin(); iter != g_stageMonitorRecord.end(); ++iter) {
std::shared_ptr<NativeReference> jsMonitor = iter->first;
if (value->StrictEquals(jsMonitor->Get())) {
HILOG_WARN("AbilityStage monitor existed");
@@ -877,10 +877,10 @@ NativeValue *JSAbilityDelegator::ParseAbilityPara(
{
HILOG_INFO("enter");
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end();) {
std::unique_lock<std::mutex> lck(g_mutexAblityRecord);
for (auto iter = g_ablityRecord.begin(); iter != g_ablityRecord.end();) {
if (iter->first.expired()) {
iter = ablityRecord_.erase(iter);
iter = g_ablityRecord.erase(iter);
continue;
}
@@ -916,8 +916,8 @@ NativeValue *JSAbilityDelegator::CreateAbilityObject(NativeEngine &engine, const
std::shared_ptr<NativeReference> refence = nullptr;
refence.reset(engine.CreateReference(objValue, 1));
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_[refence] = remoteObject;
std::unique_lock<std::mutex> lck(g_mutexAblityRecord);
g_ablityRecord[refence] = remoteObject;
return objValue;
}
@@ -1196,10 +1196,10 @@ void JSAbilityDelegator::AddStageMonitorRecord(
std::shared_ptr<NativeReference> reference = nullptr;
reference.reset(engine.CreateReference(value, 1));
{
std::unique_lock<std::mutex> lck(mtxStageMonitorRecord_);
stageMonitorRecord_.emplace(reference, monitor);
std::unique_lock<std::mutex> lck(g_mtxStageMonitorRecord);
g_stageMonitorRecord.emplace(reference, monitor);
}
HILOG_INFO("stageMonitorRecord_ added, size = %{public}zu", stageMonitorRecord_.size());
HILOG_INFO("g_stageMonitorRecord added, size = %{public}zu", g_stageMonitorRecord.size());
}
void JSAbilityDelegator::RemoveStageMonitorRecord(NativeValue *value)
@@ -1212,12 +1212,12 @@ void JSAbilityDelegator::RemoveStageMonitorRecord(NativeValue *value)
HILOG_ERROR("AbilityDelegator is null");
return;
}
std::unique_lock<std::mutex> lck(mtxStageMonitorRecord_);
for (auto iter = stageMonitorRecord_.begin(); iter != stageMonitorRecord_.end(); ++iter) {
std::unique_lock<std::mutex> lck(g_mtxStageMonitorRecord);
for (auto iter = g_stageMonitorRecord.begin(); iter != g_stageMonitorRecord.end(); ++iter) {
std::shared_ptr<NativeReference> jsMonitor = iter->first;
if (value->StrictEquals(jsMonitor->Get())) {
stageMonitorRecord_.erase(iter);
HILOG_INFO("stageMonitorRecord_ removed, size = %{public}zu", stageMonitorRecord_.size());
g_stageMonitorRecord.erase(iter);
HILOG_INFO("g_stageMonitorRecord removed, size = %{public}zu", g_stageMonitorRecord.size());
break;
}
}
@@ -29,7 +29,7 @@ JsErrorObserver::JsErrorObserver(NativeEngine& engine) : engine_(engine) {}
JsErrorObserver::~JsErrorObserver() = default;
void JsErrorObserver::OnUnhandledException(std::string errMsg)
void JsErrorObserver::OnUnhandledException(const std::string errMsg)
{
HILOG_DEBUG("OnUnhandledException come.");
std::weak_ptr<JsErrorObserver> thisWeakPtr(shared_from_this());
@@ -74,13 +74,13 @@ void JsErrorObserver::CallJsFunction(NativeValue* value, const char* methodName,
engine_.CallFunction(value, method, argv, argc);
}
void JsErrorObserver::AddJsObserverObject(int32_t observerId, NativeValue* jsObserverObject)
void JsErrorObserver::AddJsObserverObject(const int32_t observerId, NativeValue* jsObserverObject)
{
jsObserverObjectMap_.emplace(
observerId, std::shared_ptr<NativeReference>(engine_.CreateReference(jsObserverObject, 1)));
}
bool JsErrorObserver::RemoveJsObserverObject(int32_t observerId, bool &isEmpty)
bool JsErrorObserver::RemoveJsObserverObject(const int32_t observerId, bool &isEmpty)
{
bool result = (jsObserverObjectMap_.erase(observerId) == 1);
isEmpty = jsObserverObjectMap_.empty();
@@ -27,9 +27,9 @@ class JsErrorObserver : public AppExecFwk::IErrorObserver,
public:
explicit JsErrorObserver(NativeEngine& engine);
~JsErrorObserver();
void OnUnhandledException(std::string errMsg) override;
void AddJsObserverObject(int32_t observerId, NativeValue* jsObserverObject);
bool RemoveJsObserverObject(int32_t observerId, bool &isEmpty);
void OnUnhandledException(const std::string errMsg) override;
void AddJsObserverObject(const int32_t observerId, NativeValue* jsObserverObject);
bool RemoveJsObserverObject(const int32_t observerId, bool &isEmpty);
private:
void CallJsFunction(NativeValue* value, const char* methodName, NativeValue* const* argv, size_t argc);
@@ -417,10 +417,7 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
asyncCallbackInfo->deferred = deferred;
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_SetResult, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
@@ -589,10 +586,7 @@ napi_value TerminateAbilityPromise(napi_env env, AsyncCallbackInfo *asyncCallbac
asyncCallbackInfo->deferred = deferred;
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_TerminateAbility, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
@@ -781,10 +775,7 @@ napi_value HasWindowFocusPromise(napi_env env, AsyncCallbackInfo *asyncCallbackI
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
asyncCallbackInfo->deferred = deferred;
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_HasWindowFocus, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
@@ -1054,30 +1045,29 @@ napi_value GetWindowWrapAsync(
NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &asyncCallbackInfo->cbInfo.callback));
}
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("GetWindowWrapAsync, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
if (asyncCallbackInfo->ability != nullptr) {
asyncCallbackInfo->window = asyncCallbackInfo->ability->GetWindow();
auto engine = reinterpret_cast<NativeEngine*>(env);
OHOS::Rosen::CreateJsWindowObject(*engine, asyncCallbackInfo->window);
} else {
HILOG_ERROR("GetWindowWrapAsync, ability == nullptr");
}
HILOG_INFO("GetWindowWrapAsync, worker pool thread execute end.");
},
[](napi_env env, void *data) {},
[](napi_env env, napi_status status, void *data) {
HILOG_INFO("GetWindowWrapAsync, main event thread complete.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
napi_value callback = 0;
napi_value undefined = 0;
napi_value result[ARGS_TWO] = {0};
napi_value callResult = 0;
napi_get_undefined(env, &undefined);
result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR);
napi_get_null(env, &result[PARAM1]);
napi_get_reference_value(env, asyncCallbackInfo->cbInfo.callback, &callback);
napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
AsyncCallbackInfo* asyncCallbackInfo = static_cast<AsyncCallbackInfo*>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("GetWindowWrapAsync, asyncCallbackInfo is nullptr");
return;
}
if (asyncCallbackInfo->ability != nullptr) {
HILOG_DEBUG("GetWindowWrapAsync, ability is valid.");
auto engine = reinterpret_cast<NativeEngine*>(env);
asyncCallbackInfo->window = asyncCallbackInfo->ability->GetWindow();
auto jsWindow = OHOS::Rosen::CreateJsWindowObject(*engine, asyncCallbackInfo->window);
napi_value result[ARGS_TWO] = {0};
result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR);
result[PARAM1] = reinterpret_cast<napi_value>(jsWindow);
napi_value callback = 0;
napi_get_reference_value(env, asyncCallbackInfo->cbInfo.callback, &callback);
napi_value callResult = 0;
napi_value undefined = 0;
napi_get_undefined(env, &undefined);
napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
}
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
napi_delete_reference(env, asyncCallbackInfo->cbInfo.callback);
@@ -1110,28 +1100,27 @@ napi_value GetWindowWrapPromise(napi_env env, AsyncCallbackInfo *asyncCallbackIn
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
asyncCallbackInfo->deferred = deferred;
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
[](napi_env env, void *data) {
HILOG_INFO("GetWindowWrapPromise, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
if (asyncCallbackInfo->ability != nullptr) {
asyncCallbackInfo->window = asyncCallbackInfo->ability->GetWindow();
auto engine = reinterpret_cast<NativeEngine*>(env);
OHOS::Rosen::CreateJsWindowObject(*engine, asyncCallbackInfo->window);
} else {
HILOG_INFO("GetWindowWrapPromise, ability == nullptr");
}
HILOG_INFO("GetWindowWrapPromise, worker pool thread execute end.");
},
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {},
[](napi_env env, napi_status status, void *data) {
HILOG_INFO("GetWindowWrapPromise, main event thread complete.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("GetWindowWrapPromise, asyncCallbackInfo is nullptr");
return;
}
napi_value result = 0;
napi_get_null(env, &result);
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
if (asyncCallbackInfo->ability != nullptr) {
auto engine = reinterpret_cast<NativeEngine*>(env);
asyncCallbackInfo->window = asyncCallbackInfo->ability->GetWindow();
auto jsWindow = OHOS::Rosen::CreateJsWindowObject(*engine, asyncCallbackInfo->window);
result = reinterpret_cast<napi_value>(jsWindow);
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
} else {
HILOG_WARN("GetWindowWrapPromise, ability is nullptr.");
napi_get_null(env, &result);
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
}
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
@@ -1481,10 +1470,7 @@ napi_value GetDataAbilityHelperAsync(
}
NAPI_CALL(env,
napi_create_async_work(
env,
nullptr,
resourceName,
napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) { HILOG_INFO("NAPI_GetDataAbilityHelper, worker pool thread execute."); },
GetDataAbilityHelperAsyncCompleteCB,
(void *)dataAbilityHelperCB,
@@ -1511,10 +1497,7 @@ napi_value GetDataAbilityHelperPromise(napi_env env, DataAbilityHelperCB *dataAb
dataAbilityHelperCB->cbBase.deferred = deferred;
NAPI_CALL(env,
napi_create_async_work(
env,
nullptr,
resourceName,
napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) { HILOG_INFO("NAPI_GetDataAbilityHelper, worker pool thread execute."); },
GetDataAbilityHelperPromiseCompleteCB,
(void *)dataAbilityHelperCB,
@@ -1737,10 +1720,7 @@ napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInf
}
}
napi_create_async_work(
env,
nullptr,
resourceName,
napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_ContinueAbility, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
@@ -1809,8 +1789,7 @@ napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackI
asyncCallbackInfo->deferred = deferred;
napi_create_async_work(
env, nullptr, resourceName,
napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_ContinueAbility, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
@@ -482,66 +482,53 @@ void AbilityImpl::NotifyMemoryLevel(int32_t level)
#ifdef SUPPORT_GRAPHICS
void AbilityImpl::AfterUnFocused()
{
if (!ability_ || !ability_->GetAbilityInfo() || !contextDeal_ || !handler_) {
HILOG_ERROR("AbilityImpl::AfterUnFocused failed");
return;
}
HILOG_INFO("isStageBasedModel: %{public}d", ability_->GetAbilityInfo()->isStageBasedModel);
if (ability_->GetAbilityInfo()->isStageBasedModel) {
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = ability_->GetAbilityContext();
if (abilityContext != nullptr) {
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
abilityContext->GetApplicationContext();
if (applicationContext != nullptr && !applicationContext->isAbilityLifecycleCallbackEmpty()) {
AbilityRuntime::JsAbility& jsAbility = static_cast<AbilityRuntime::JsAbility&>(*ability_);
applicationContext->DispatchWindowStageUnfocus(jsAbility.GetJsAbility(), jsAbility.GetJsWindowStage());
}
}
return;
}
if (ability_->GetWant() == nullptr) {
HILOG_ERROR("want is nullptr.");
return;
}
auto task = [abilityImpl = shared_from_this(), want = *(ability_->GetWant()), contextDeal = contextDeal_]() {
auto info = contextDeal->GetLifeCycleStateInfo();
info.state = AbilityLifeCycleState::ABILITY_STATE_INACTIVE;
info.isNewWant = false;
abilityImpl->HandleAbilityTransaction(want, info);
};
handler_->PostTask(task);
HILOG_DEBUG("%{public}s end.", __func__);
AfterFocusedCommon(false);
}
void AbilityImpl::AfterFocused()
{
AfterFocusedCommon(true);
}
void AbilityImpl::AfterFocusedCommon(bool isFocused)
{
if (!ability_ || !ability_->GetAbilityInfo() || !contextDeal_ || !handler_) {
HILOG_ERROR("AbilityImpl::AfterFocused failed");
HILOG_WARN("AbilityImpl::%{public}s failed", isFocused ? "AfterFocused" : "AfterUnFocused");
return;
}
HILOG_INFO("isStageBasedModel: %{public}d", ability_->GetAbilityInfo()->isStageBasedModel);
if (ability_->GetAbilityInfo()->isStageBasedModel) {
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = ability_->GetAbilityContext();
if (abilityContext != nullptr) {
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
abilityContext->GetApplicationContext();
if (applicationContext != nullptr && !applicationContext->isAbilityLifecycleCallbackEmpty()) {
AbilityRuntime::JsAbility& jsAbility = static_cast<AbilityRuntime::JsAbility&>(*ability_);
applicationContext->DispatchWindowStageFocus(jsAbility.GetJsAbility(), jsAbility.GetJsWindowStage());
if (abilityContext == nullptr) {
return;
}
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
abilityContext->GetApplicationContext();
if (applicationContext != nullptr && !applicationContext->isAbilityLifecycleCallbackEmpty()) {
AbilityRuntime::JsAbility& jsAbility = static_cast<AbilityRuntime::JsAbility&>(*ability_);
if (isFocused) {
applicationContext->DispatchWindowStageFocus(jsAbility.GetJsAbility(),
jsAbility.GetJsWindowStage());
} else {
applicationContext->DispatchWindowStageUnfocus(jsAbility.GetJsAbility(),
jsAbility.GetJsWindowStage());
}
}
return;
}
if (ability_->GetWant() == nullptr) {
HILOG_INFO("want is nullptr.");
HILOG_WARN("want is nullptr.");
return;
}
auto task = [abilityImpl = shared_from_this(), want = *(ability_->GetWant()), contextDeal = contextDeal_]() {
auto task = [abilityImpl = shared_from_this(), want = *(ability_->GetWant()), contextDeal = contextDeal_,
focuseMode = isFocused]() {
auto info = contextDeal->GetLifeCycleStateInfo();
info.state = AbilityLifeCycleState::ABILITY_STATE_ACTIVE;
if (focuseMode) {
info.state = AbilityLifeCycleState::ABILITY_STATE_ACTIVE;
} else {
info.state = AbilityLifeCycleState::ABILITY_STATE_INACTIVE;
}
info.isNewWant = false;
abilityImpl->HandleAbilityTransaction(want, info);
};
@@ -455,6 +455,9 @@ private:
bool needSaveDate_ = false;
PacMap restoreData_;
private:
void AfterFocusedCommon(bool isFocused);
#ifdef SUPPORT_GRAPHICS
private:
class WindowLifeCycleImpl : public Rosen::IWindowLifeCycle {
+1 -1
View File
@@ -781,7 +781,7 @@ public:
// new version
ResolveResultType Resolve(const AbilityRequest &abilityRequest);
bool ReleaseCall(const sptr<IAbilityConnection> & connect);
bool ReleaseCall(const sptr<IAbilityConnection>& connect);
bool IsNeedToCallRequest() const;
bool IsStartedByCall() const;
void SetStartedByCall(const bool isFlag);
@@ -145,6 +145,10 @@ public:
*/
void HandleAppDied(int32_t pid);
private:
bool CheckDataAbilityConnectionParams(const DataAbilityCaller &caller,
const std::shared_ptr<DataAbilityRecord> &record) const;
private:
class InnerAppStateObserver : public AppExecFwk::ApplicationStateObserverStub {
public:
+1 -1
View File
@@ -1816,7 +1816,7 @@ ResolveResultType AbilityRecord::Resolve(const AbilityRequest &abilityRequest)
return ResolveResultType::OK_NO_REMOTE_OBJ;
}
bool AbilityRecord::ReleaseCall(const sptr<IAbilityConnection> & connect)
bool AbilityRecord::ReleaseCall(const sptr<IAbilityConnection>& connect)
{
HILOG_DEBUG("ability release call record by callback.");
CHECK_POINTER_RETURN_BOOL(callContainer_);
@@ -134,18 +134,7 @@ void ConnectionStateManager::RemoveConnection(const std::shared_ptr<ConnectionRe
void ConnectionStateManager::AddDataAbilityConnection(const DataAbilityCaller &caller,
const std::shared_ptr<DataAbilityRecord> &record)
{
std::shared_ptr<ConnectionObserverController> controller = observerController_;
if (!controller) {
return;
}
if (!record) {
HILOG_ERROR("data ability record is invalid");
return;
}
if (caller.callerPid == 0) {
HILOG_ERROR("data ability, invalid callerInfo");
if (!CheckDataAbilityConnectionParams(caller, record)) {
return;
}
@@ -154,24 +143,13 @@ void ConnectionStateManager::AddDataAbilityConnection(const DataAbilityCaller &c
HILOG_WARN("add data ability onnection, no need to notify observers");
return;
}
controller->NotifyExtensionConnected(connectionData);
observerController_->NotifyExtensionConnected(connectionData);
}
void ConnectionStateManager::RemoveDataAbilityConnection(const DataAbilityCaller &caller,
const std::shared_ptr<DataAbilityRecord> &record)
{
std::shared_ptr<ConnectionObserverController> controller = observerController_;
if (!controller) {
return;
}
if (!record) {
HILOG_ERROR("data ability record is invalid");
return;
}
if (caller.callerPid == 0) {
HILOG_ERROR("data ability, invalid caller pid");
if (!CheckDataAbilityConnectionParams(caller, record)) {
return;
}
@@ -180,7 +158,27 @@ void ConnectionStateManager::RemoveDataAbilityConnection(const DataAbilityCaller
HILOG_WARN("remove data ability, no need to notify observers");
return;
}
controller->NotifyExtensionDisconnected(connectionData);
observerController_->NotifyExtensionDisconnected(connectionData);
}
bool ConnectionStateManager::CheckDataAbilityConnectionParams(const DataAbilityCaller &caller,
const std::shared_ptr<DataAbilityRecord> &record) const
{
if (!observerController_) {
return false;
}
if (!record) {
HILOG_ERROR("data ability record is invalid");
return false;
}
if (caller.callerPid == 0) {
HILOG_ERROR("data ability, invalid caller pid");
return false;
}
return true;
}
void ConnectionStateManager::HandleDataAbilityDied(const std::shared_ptr<DataAbilityRecord> &record)
@@ -48,9 +48,9 @@ public:
private:
void HandleAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state);
void HandleStateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility);
void HandleOnProcessCreated(const std::shared_ptr<AppRunningRecord> &appRecord);
void HandleOnAppProcessCreated(const std::shared_ptr<AppRunningRecord> &appRecord);
void HandleOnRenderProcessCreated(const std::shared_ptr<RenderRecord> &RenderRecord);
void HandleOnProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord);
void HandleOnAppProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord);
void HandleOnRenderProcessDied(const std::shared_ptr<RenderRecord> &RenderRecord);
bool ObserverExist(const sptr<IApplicationStateObserver> &observer);
void AddObserverDeathRecipient(const sptr<IApplicationStateObserver> &observer);
@@ -60,6 +60,8 @@ private:
void OnObserverDied(const wptr<IRemoteObject> &remote);
AppStateData WrapAppStateData(const std::shared_ptr<AppRunningRecord> &appRecord,
const ApplicationState state);
void HandleOnProcessCreated(const ProcessData &data);
void HandleOnProcessDied(const ProcessData &data);
private:
std::shared_ptr<AppExecFwk::EventHandler> handler_;
@@ -115,7 +115,7 @@ void AppStateObserverManager::OnProcessDied(const std::shared_ptr<AppRunningReco
return;
}
HILOG_INFO("OnProcessDied come.");
self->HandleOnProcessDied(appRecord);
self->HandleOnAppProcessDied(appRecord);
};
handler_->PostTask(task);
}
@@ -143,7 +143,7 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptr<AppRunningR
return;
}
HILOG_INFO("OnProcessCreated come.");
self->HandleOnProcessCreated(appRecord);
self->HandleOnAppProcessCreated(appRecord);
};
handler_->PostTask(task);
}
@@ -229,7 +229,7 @@ void AppStateObserverManager::HandleStateChangedNotifyObserver(const AbilityStat
}
}
void AppStateObserverManager::HandleOnProcessCreated(const std::shared_ptr<AppRunningRecord> &appRecord)
void AppStateObserverManager::HandleOnAppProcessCreated(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (!appRecord) {
HILOG_ERROR("app record is null");
@@ -238,14 +238,7 @@ void AppStateObserverManager::HandleOnProcessCreated(const std::shared_ptr<AppRu
ProcessData data = WrapProcessData(appRecord);
HILOG_DEBUG("Process Create, bundle:%{public}s, pid:%{public}d, uid:%{public}d, size:%{public}d",
data.bundleName.c_str(), data.pid, data.uid, (int32_t)appStateObserverMap_.size());
std::lock_guard<std::recursive_mutex> lockNotify(observerLock_);
for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) {
std::vector<std::string>::iterator iter = std::find(it->second.begin(),
it->second.end(), data.bundleName);
if ((it->second.empty() || iter != it->second.end()) && it->first != nullptr) {
it->first->OnProcessCreated(data);
}
}
HandleOnProcessCreated(data);
}
void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr<RenderRecord> &renderRecord)
@@ -257,6 +250,11 @@ void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr
ProcessData data = WrapRenderProcessData(renderRecord);
HILOG_DEBUG("RenderProcess Create, bundle:%{public}s, pid:%{public}d, uid:%{public}d, size:%{public}d",
data.bundleName.c_str(), data.pid, data.uid, (int32_t)appStateObserverMap_.size());
HandleOnProcessCreated(data);
}
void AppStateObserverManager::HandleOnProcessCreated(const ProcessData &data)
{
std::lock_guard<std::recursive_mutex> lockNotify(observerLock_);
for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) {
std::vector<std::string>::iterator iter = std::find(it->second.begin(),
@@ -267,7 +265,7 @@ void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr
}
}
void AppStateObserverManager::HandleOnProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord)
void AppStateObserverManager::HandleOnAppProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (!appRecord) {
HILOG_ERROR("app record is null");
@@ -276,14 +274,7 @@ void AppStateObserverManager::HandleOnProcessDied(const std::shared_ptr<AppRunni
ProcessData data = WrapProcessData(appRecord);
HILOG_DEBUG("Process died, bundle:%{public}s, pid:%{public}d, uid:%{public}d, size:%{public}d.",
data.bundleName.c_str(), data.pid, data.uid, (int32_t)appStateObserverMap_.size());
std::lock_guard<std::recursive_mutex> lockNotify(observerLock_);
for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) {
std::vector<std::string>::iterator iter = std::find(it->second.begin(),
it->second.end(), data.bundleName);
if ((it->second.empty() || iter != it->second.end()) && it->first != nullptr) {
it->first->OnProcessDied(data);
}
}
HandleOnProcessDied(data);
}
void AppStateObserverManager::HandleOnRenderProcessDied(const std::shared_ptr<RenderRecord> &renderRecord)
@@ -295,6 +286,11 @@ void AppStateObserverManager::HandleOnRenderProcessDied(const std::shared_ptr<Re
ProcessData data = WrapRenderProcessData(renderRecord);
HILOG_DEBUG("Render Process died, bundle:%{public}s, pid:%{public}d, uid:%{public}d, size:%{public}d.",
data.bundleName.c_str(), data.pid, data.uid, (int32_t)appStateObserverMap_.size());
HandleOnProcessDied(data);
}
void AppStateObserverManager::HandleOnProcessDied(const ProcessData &data)
{
std::lock_guard<std::recursive_mutex> lockNotify(observerLock_);
for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) {
std::vector<std::string>::iterator iter = std::find(it->second.begin(),
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#include "ability_info.h"
#include "application_info.h"
#include "process_info.h"
@@ -85,4 +85,4 @@ public:
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#include "want.h"
namespace OHOS {
@@ -27,4 +27,4 @@ public:
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H