mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-12-11 20:03:42 +00:00
commit
2330c183dc
@ -179,37 +179,32 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[appManager = appManager_, observer = observer_, observerId, errCode](
|
||||
napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (observer == nullptr || appManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr"));
|
||||
return;
|
||||
}
|
||||
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
|
||||
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task.Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed"));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [appManager = appManager_, observer = observer_, observerId, errCode,
|
||||
env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
if (observer == nullptr || appManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr"));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
|
||||
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
|
||||
task->Resolve(env, CreateJsUndefined(env));
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task->Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed"));
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::Schedule("JSAppManager::OnUnregisterApplicationStateObserver",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -223,38 +218,32 @@ private:
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (appManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
|
||||
return;
|
||||
}
|
||||
std::vector<AppExecFwk::AppStateData> list;
|
||||
int32_t ret = appManager->GetForegroundApplications(list);
|
||||
if (ret == 0) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "success.");
|
||||
task.Resolve(env, CreateJsAppStateDataArray(env, list));
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task.Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed"));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
if (appManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
std::vector<AppExecFwk::AppStateData> list;
|
||||
int32_t ret = appManager->GetForegroundApplications(list);
|
||||
if (ret == 0) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "success.");
|
||||
task->Resolve(env, CreateJsAppStateDataArray(env, list));
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task->Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed"));
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::Schedule("JSAppManager::OnGetForegroundApplications",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -268,30 +257,25 @@ private:
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[appManager = appManager_, errCode](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
std::vector<AppExecFwk::RunningProcessInfo> infos;
|
||||
auto ret = appManager->GetAllRunningProcesses(infos);
|
||||
if (ret == 0) {
|
||||
task.Resolve(env, CreateJsProcessRunningInfoArray(env, infos));
|
||||
} else {
|
||||
task.Reject(env, CreateJsError(env, ret, "Get mission infos failed."));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
std::vector<AppExecFwk::RunningProcessInfo> infos;
|
||||
auto ret = appManager->GetAllRunningProcesses(infos);
|
||||
if (ret == 0) {
|
||||
task->Resolve(env, CreateJsProcessRunningInfoArray(env, infos));
|
||||
} else {
|
||||
task->Reject(env, CreateJsError(env, ret, "Get mission infos failed."));
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::Schedule("JSAppManager::OnGetProcessRunningInfos",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -305,51 +289,29 @@ private:
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
return;
|
||||
}
|
||||
bool ret = abilityManager->IsRunningInStabilityTest();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
|
||||
task.Resolve(env, CreateJsValue(env, ret));
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
bool ret = abilityManager->IsRunningInStabilityTest();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
|
||||
task->Resolve(env, CreateJsValue(env, ret));
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::Schedule("JSAppManager::OnIsRunningInStabilityTest",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
static void OnKillProcessByBundleNameInner(std::string bundleName, bool clearPageStack,
|
||||
sptr<OHOS::AAFwk::IAbilityManager> abilityManager, napi_env env, NapiAsyncTask *task)
|
||||
{
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
return;
|
||||
}
|
||||
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
|
||||
if (ret == 0) {
|
||||
task->Resolve(env, CreateJsValue(env, ret));
|
||||
} else {
|
||||
task->Reject(env, CreateJsError(env, ret, "kill process failed."));
|
||||
}
|
||||
}
|
||||
|
||||
napi_value OnKillProcessByBundleName(napi_env env, size_t argc, napi_value* argv)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called");
|
||||
@ -378,23 +340,29 @@ private:
|
||||
TAG_LOGI(AAFwkTag::APPMGR,
|
||||
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
|
||||
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[bundleName, clearPageStack, abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task,
|
||||
int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
return;
|
||||
}
|
||||
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
|
||||
if (ret == 0) {
|
||||
task.Resolve(env, CreateJsValue(env, ret));
|
||||
} else {
|
||||
task.Reject(env, CreateJsError(env, ret, "kill process failed."));
|
||||
}
|
||||
};
|
||||
napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, errCode,
|
||||
env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
} else {
|
||||
OnKillProcessByBundleNameInner(bundleName, clearPageStack, abilityManager, env, task);
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessByBundleName",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -417,35 +385,30 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [bundleName, appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[bundleName, appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task,
|
||||
int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (appManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
|
||||
delete task;
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
|
||||
return;
|
||||
}
|
||||
auto ret = appManager->ClearUpApplicationData(bundleName, 0);
|
||||
if (ret == 0) {
|
||||
task->Resolve(env, CreateJsValue(env, ret));
|
||||
task.Resolve(env, CreateJsValue(env, ret));
|
||||
} else {
|
||||
task->Reject(env, CreateJsError(env, AAFwk::CLEAR_APPLICATION_DATA_FAIL,
|
||||
"clear up application failed."));
|
||||
task.Reject(env, CreateJsError(env, ret, "clear up application failed."));
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
|
||||
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JSAppManager::OnClearUpApplicationData",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -482,31 +445,25 @@ private:
|
||||
TAG_LOGI(AAFwkTag::APPMGR,
|
||||
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
|
||||
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[appManager = appManager_, bundleName, accountId, clearPageStack, errCode](
|
||||
napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
|
||||
if (ret == 0) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task.Reject(env, CreateJsError(env, ret, "Kill processes failed."));
|
||||
}
|
||||
};
|
||||
napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack, errCode,
|
||||
env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
|
||||
if (ret == 0) {
|
||||
task->Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
|
||||
task->Reject(env, CreateJsError(env, ret, "Kill processes failed."));
|
||||
}
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "end");
|
||||
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -520,31 +477,26 @@ private:
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
return;
|
||||
}
|
||||
int32_t memorySize = abilityManager->GetAppMemorySize();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
|
||||
task.Resolve(env, CreateJsValue(env, memorySize));
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
int32_t memorySize = abilityManager->GetAppMemorySize();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
|
||||
task->Resolve(env, CreateJsValue(env, memorySize));
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetAppMemorySize",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -558,31 +510,26 @@ private:
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
return;
|
||||
}
|
||||
bool ret = abilityManager->IsRamConstrainedDevice();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
|
||||
task.Resolve(env, CreateJsValue(env, ret));
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
|
||||
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
|
||||
if (errCode != 0) {
|
||||
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
if (abilityManager == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
|
||||
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
bool ret = abilityManager->IsRamConstrainedDevice();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
|
||||
task->Resolve(env, CreateJsValue(env, ret));
|
||||
delete task;
|
||||
};
|
||||
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
|
||||
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsRamConstrainedDevice",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user