mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-12-21 16:45:47 +00:00
commit
803193029a
@ -30,7 +30,20 @@ napi_ref thread_local g_dataAbilityHelper = nullptr;
|
||||
bool thread_local g_dataAbilityHelperStatus = false;
|
||||
const int32_t ERR_ABILITY_START_SUCCESS = 0;
|
||||
const int32_t ERR_ABILITY_QUERY_FAILED = 1;
|
||||
const int32_t ERR_NETWORK_UNAVAILABLE = 2;
|
||||
const int32_t ERR_SYSTEM_ERROR = 3;
|
||||
const int32_t ERR_LOADING_ERROR = 4;
|
||||
const int32_t ERR_CONCURRENT_TASKS_WAITING_FOR_RETRY = 5;
|
||||
const int32_t ERR_FREE_INSTALL_NOT_SUPPORTED = 6;
|
||||
const int32_t ERR_SERVICE_ERROR = 7;
|
||||
const int32_t ERR_PERMISSION_VERIFY_FAILED = 8;
|
||||
const int32_t ERR_PARAMETER_INVALID = 9;
|
||||
const int32_t ERR_REMOTE_INCOMPATIBLE = 10;
|
||||
const int32_t ERR_DEVICE_OFFLINE = 11;
|
||||
const int32_t ERR_FREE_INSTALL_TIMEOUT = 12;
|
||||
const int32_t ERR_NOT_TOP_ABILITY = 13;
|
||||
const int32_t ERR_TARGET_BUNDLE_NOT_EXIST = 14;
|
||||
const int32_t ERR_CONTINUE_FREE_INSTALL_FAILED = 15;
|
||||
const int32_t ERR_PARAM_INVALID = 202;
|
||||
const std::map<int32_t, int32_t> START_ABILITY_ERROR_CODE_MAP = {
|
||||
{ NAPI_ERR_NO_ERROR, ERR_ABILITY_START_SUCCESS },
|
||||
@ -43,6 +56,34 @@ const std::map<int32_t, int32_t> START_ABILITY_ERROR_CODE_MAP = {
|
||||
{ RESOLVE_ABILITY_ERR, ERR_ABILITY_QUERY_FAILED },
|
||||
{ CHECK_PERMISSION_FAILED, ERR_PERMISSION_VERIFY_FAILED },
|
||||
{ RESOLVE_CALL_NO_PERMISSIONS, ERR_PERMISSION_VERIFY_FAILED },
|
||||
{ FA_FREE_INSTALL_QUERY_ERROR, ERR_ABILITY_QUERY_FAILED },
|
||||
{ HAG_QUERY_TIMEOUT, ERR_ABILITY_QUERY_FAILED },
|
||||
{ FA_NETWORK_UNAVAILABLE, ERR_NETWORK_UNAVAILABLE },
|
||||
{ FA_FREE_INSTALL_SERVICE_ERROR, ERR_SYSTEM_ERROR },
|
||||
{ FA_CRASH, ERR_SYSTEM_ERROR },
|
||||
{ FA_TIMEOUT, ERR_SYSTEM_ERROR },
|
||||
{ UNKNOWN_EXCEPTION, ERR_SYSTEM_ERROR },
|
||||
{ NOT_SUPPORT_PA_ON_SAME_DEVICE, ERR_SYSTEM_ERROR },
|
||||
{ FA_INTERNET_ERROR, ERR_SYSTEM_ERROR },
|
||||
{ JUMP_TO_THE_APPLICATION_MARKET_UPGRADE, ERR_SYSTEM_ERROR },
|
||||
{ USER_GIVES_UP, ERR_LOADING_ERROR },
|
||||
{ INSTALLATION_ERROR_IN_FREE_INSTALL, ERR_LOADING_ERROR },
|
||||
{ HAP_PACKAGE_DOWNLOAD_TIMED_OUT, ERR_LOADING_ERROR },
|
||||
{ CONCURRENT_TASKS_WAITING_FOR_RETRY, ERR_CONCURRENT_TASKS_WAITING_FOR_RETRY },
|
||||
{ FA_PACKAGE_DOES_NOT_SUPPORT_FREE_INSTALL, ERR_FREE_INSTALL_NOT_SUPPORTED },
|
||||
{ NOT_ALLOWED_TO_PULL_THIS_FA, ERR_SERVICE_ERROR },
|
||||
{ NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL_PA, ERR_SERVICE_ERROR },
|
||||
{ DMS_PERMISSION_DENIED, ERR_PERMISSION_VERIFY_FAILED },
|
||||
{ DMS_COMPONENT_ACCESS_PERMISSION_DENIED, ERR_PERMISSION_VERIFY_FAILED },
|
||||
{ DMS_ACCOUNT_ACCESS_PERMISSION_DENIED, ERR_PERMISSION_VERIFY_FAILED },
|
||||
{ INVALID_PARAMETERS_ERR, ERR_PARAMETER_INVALID },
|
||||
{ INVALID_REMOTE_PARAMETERS_ERR, ERR_PARAMETER_INVALID },
|
||||
{ REMOTE_DEVICE_NOT_COMPATIBLE, ERR_REMOTE_INCOMPATIBLE },
|
||||
{ DEVICE_OFFLINE_ERR, ERR_DEVICE_OFFLINE },
|
||||
{ FREE_INSTALL_TIMEOUT, ERR_FREE_INSTALL_TIMEOUT },
|
||||
{ NOT_TOP_ABILITY, ERR_NOT_TOP_ABILITY },
|
||||
{ TARGET_BUNDLE_NOT_EXIST, ERR_TARGET_BUNDLE_NOT_EXIST },
|
||||
{ CONTINUE_FREE_INSTALL_FAILED, ERR_CONTINUE_FREE_INSTALL_FAILED }
|
||||
};
|
||||
|
||||
using NAPICreateJsRemoteObject = napi_value (*)(napi_env env, const sptr<IRemoteObject> target);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "ability_runtime/js_caller_complex.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_start_options.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_common_want.h"
|
||||
@ -195,8 +196,9 @@ NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallba
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
auto errcode = (unwrapArgc == 1) ?
|
||||
auto innerErrorCode = (unwrapArgc == 1) ?
|
||||
context->StartAbility(want, -1) : context->StartAbility(want, startOptions, -1);
|
||||
ErrCode errcode = AppExecFwk::GetStartAbilityErrorCode(innerErrorCode);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
@ -247,9 +249,10 @@ NativeValue* JsAbilityContext::OnStartAbilityWithAccount(NativeEngine& engine, N
|
||||
return;
|
||||
}
|
||||
|
||||
auto errcode = (unwrapArgc == INDEX_TWO) ?
|
||||
auto innerErrorCode = (unwrapArgc == INDEX_TWO) ?
|
||||
context->StartAbilityWithAccount(want, accountId, -1) : context->StartAbilityWithAccount(
|
||||
want, accountId, startOptions, -1);
|
||||
ErrCode errcode = AppExecFwk::GetStartAbilityErrorCode(innerErrorCode);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_start_options.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
@ -150,9 +151,9 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
// entry to the core functionality.
|
||||
errcode = context->StartAbility(want);
|
||||
ErrCode innerErrorCode = context->StartAbility(want);
|
||||
ErrCode errcode = AppExecFwk::GetStartAbilityErrorCode(innerErrorCode);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_remote_object.h"
|
||||
@ -171,9 +172,10 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
(unwrapArgc == 1) ? errcode = context->StartAbility(want) :
|
||||
errcode = context->StartAbility(want, startOptions);
|
||||
ErrCode innerErrorCode = ERR_OK;
|
||||
(unwrapArgc == 1) ? innerErrorCode = context->StartAbility(want) :
|
||||
innerErrorCode = context->StartAbility(want, startOptions);
|
||||
ErrCode errcode = AppExecFwk::GetStartAbilityErrorCode(innerErrorCode);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
@ -362,9 +364,10 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
(unwrapArgc == ARGC_TWO) ? errcode = context->StartAbilityWithAccount(want, accountId) :
|
||||
errcode = context->StartAbilityWithAccount(want, accountId, startOptions);
|
||||
ErrCode innerErrorCode = ERR_OK;
|
||||
(unwrapArgc == ARGC_TWO) ? innerErrorCode = context->StartAbilityWithAccount(want, accountId) :
|
||||
innerErrorCode = context->StartAbilityWithAccount(want, accountId, startOptions);
|
||||
ErrCode errcode = AppExecFwk::GetStartAbilityErrorCode(innerErrorCode);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
|
@ -416,38 +416,6 @@ enum NativeFreeInstallError {
|
||||
UNDEFINE_ERROR_CODE = 3,
|
||||
};
|
||||
|
||||
static const std::map<NativeFreeInstallError, int> FIErrorToAppMaps = {
|
||||
{FREE_INSTALL_OK, 0},
|
||||
{FA_FREE_INSTALL_QUERY_ERROR, 1},
|
||||
{HAG_QUERY_TIMEOUT, 1},
|
||||
{FA_NETWORK_UNAVAILABLE, 2},
|
||||
{FA_FREE_INSTALL_SERVICE_ERROR, 3},
|
||||
{FA_CRASH, 3},
|
||||
{FA_TIMEOUT, 3},
|
||||
{UNKNOWN_EXCEPTION, 3},
|
||||
{NOT_SUPPORT_PA_ON_SAME_DEVICE, 3},
|
||||
{FA_INTERNET_ERROR, 3},
|
||||
{JUMP_TO_THE_APPLICATION_MARKET_UPGRADE, 3},
|
||||
{USER_GIVES_UP, 4},
|
||||
{INSTALLATION_ERROR_IN_FREE_INSTALL, 4},
|
||||
{HAP_PACKAGE_DOWNLOAD_TIMED_OUT, 4},
|
||||
{CONCURRENT_TASKS_WAITING_FOR_RETRY, 5},
|
||||
{FA_PACKAGE_DOES_NOT_SUPPORT_FREE_INSTALL, 6},
|
||||
{NOT_ALLOWED_TO_PULL_THIS_FA, 7},
|
||||
{NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL_PA, 7},
|
||||
{DMS_PERMISSION_DENIED, 8},
|
||||
{DMS_COMPONENT_ACCESS_PERMISSION_DENIED, 8},
|
||||
{DMS_ACCOUNT_ACCESS_PERMISSION_DENIED, 8},
|
||||
{INVALID_PARAMETERS_ERR, 9},
|
||||
{INVALID_REMOTE_PARAMETERS_ERR, 9},
|
||||
{REMOTE_DEVICE_NOT_COMPATIBLE, 10},
|
||||
{DEVICE_OFFLINE_ERR, 11},
|
||||
{FREE_INSTALL_TIMEOUT, 12},
|
||||
{NOT_TOP_ABILITY, 13},
|
||||
{TARGET_BUNDLE_NOT_EXIST, 14},
|
||||
{CONTINUE_FREE_INSTALL_FAILED, 15},
|
||||
};
|
||||
|
||||
static const std::map<NativeFreeInstallError, std::string> FIErrorStrs = {
|
||||
{
|
||||
FREE_INSTALL_OK,
|
||||
|
@ -128,7 +128,6 @@ private:
|
||||
*/
|
||||
int RemoteFreeInstall(const Want &want, int32_t userId, int requestCode, const sptr<IRemoteObject> &callerToken);
|
||||
|
||||
int HandleFreeInstallErrorCode(int resultCode);
|
||||
int NotifyDmsCallback(const Want &want, int resultCode);
|
||||
bool IsTopAbility(const sptr<IRemoteObject> &callerToken);
|
||||
void NotifyFreeInstallResult(const Want &want, int resultCode);
|
||||
|
@ -80,7 +80,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
|
||||
HILOG_INFO("StartFreeInstall called");
|
||||
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
|
||||
if (!isSaCall && !IsTopAbility(callerToken)) {
|
||||
return HandleFreeInstallErrorCode(NOT_TOP_ABILITY);
|
||||
return NOT_TOP_ABILITY;
|
||||
}
|
||||
FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken);
|
||||
freeInstallList_.push_back(info);
|
||||
@ -104,9 +104,9 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
|
||||
std::future_status status = future.wait_for(std::chrono::milliseconds(DELAY_LOCAL_FREE_INSTALL_TIMEOUT));
|
||||
if (status == std::future_status::timeout) {
|
||||
info.isInstalled = true;
|
||||
return HandleFreeInstallErrorCode(FREE_INSTALL_TIMEOUT);
|
||||
return FREE_INSTALL_TIMEOUT;
|
||||
}
|
||||
return HandleFreeInstallErrorCode(future.get());
|
||||
return future.get();
|
||||
}
|
||||
|
||||
int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int requestCode,
|
||||
@ -116,7 +116,7 @@ int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int
|
||||
bool isFromRemote = want.GetBoolParam(FROM_REMOTE_KEY, false);
|
||||
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
|
||||
if (!isSaCall && !isFromRemote && !IsTopAbility(callerToken)) {
|
||||
return HandleFreeInstallErrorCode(NOT_TOP_ABILITY);
|
||||
return NOT_TOP_ABILITY;
|
||||
}
|
||||
FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken);
|
||||
freeInstallList_.push_back(info);
|
||||
@ -126,15 +126,15 @@ int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int
|
||||
DistributedClient dmsClient;
|
||||
auto result = dmsClient.StartRemoteFreeInstall(info.want, callerUid, info.requestCode, accessToken, callback);
|
||||
if (result != ERR_NONE) {
|
||||
return HandleFreeInstallErrorCode(result);
|
||||
return result;
|
||||
}
|
||||
auto remoteFuture = info.promise->get_future();
|
||||
std::future_status remoteStatus = remoteFuture.wait_for(std::chrono::milliseconds(
|
||||
DELAY_REMOTE_FREE_INSTALL_TIMEOUT));
|
||||
if (remoteStatus == std::future_status::timeout) {
|
||||
return HandleFreeInstallErrorCode(FREE_INSTALL_TIMEOUT);
|
||||
return FREE_INSTALL_TIMEOUT;
|
||||
}
|
||||
return HandleFreeInstallErrorCode(remoteFuture.get());
|
||||
return remoteFuture.get();
|
||||
}
|
||||
|
||||
FreeInstallInfo FreeInstallManager::BuildFreeInstallInfo(const Want &want, int32_t userId, int requestCode,
|
||||
@ -278,21 +278,6 @@ int FreeInstallManager::FreeInstallAbilityFromRemote(const Want &want, const spt
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int FreeInstallManager::HandleFreeInstallErrorCode(int resultCode)
|
||||
{
|
||||
auto it = FIErrorStrs.find(static_cast<enum NativeFreeInstallError>(resultCode));
|
||||
if (it != FIErrorStrs.end()) {
|
||||
HILOG_ERROR("Error code : %{public}d, info: %{public}s", resultCode, it->second.c_str());
|
||||
}
|
||||
|
||||
auto itToApp = FIErrorToAppMaps.find(static_cast<enum NativeFreeInstallError>(resultCode));
|
||||
if (itToApp == FIErrorToAppMaps.end()) {
|
||||
HILOG_ERROR("Undefind error code.");
|
||||
return NativeFreeInstallError::UNDEFINE_ERROR_CODE;
|
||||
}
|
||||
return itToApp->second;
|
||||
}
|
||||
|
||||
int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId,
|
||||
const sptr<IRemoteObject> &callerToken, const std::string& localDeviceId)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user