IssueNo:api7 context interface
Description:commit applicationFramework api7 interface about context
Sig:SIG_ApplicationFramework
Feature or Bugfix: Feature
Binary Source: No

Signed-off-by: dy_study <dingyao5@huawei.com>
Change-Id: If783773dfa58139046a075827ea96522d96769f6
This commit is contained in:
dy_study
2022-03-01 12:50:34 +00:00
committed by dy
parent 6c86608ed7
commit 718888bbf5
37 changed files with 2858 additions and 7 deletions
@@ -33,6 +33,8 @@ public:
std::string GetCacheDir() override;
std::string GetTempDir() override;
std::string GetFilesDir() override;
bool IsUpdatingConfigurations() override;
bool PrintDrawnCompleted() override;
std::string GetDatabaseDir() override;
std::string GetStorageDir() override;
std::string GetDistributedFilesDir() override;
@@ -64,6 +64,16 @@ std::string AbilityContextImpl::GetDistributedFilesDir()
return stageContext_ ? stageContext_->GetDistributedFilesDir() : "";
}
bool AbilityContextImpl::IsUpdatingConfigurations()
{
return stageContext_ ? stageContext_->IsUpdatingConfigurations() : false;
}
bool AbilityContextImpl::PrintDrawnCompleted()
{
return stageContext_ ? stageContext_->PrintDrawnCompleted() : false;
}
void AbilityContextImpl::SwitchArea(int mode)
{
HILOG_DEBUG("AbilityContextImpl::SwitchArea.");
@@ -160,6 +160,20 @@ public:
*/
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
bool IsUpdatingConfigurations() override;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
bool PrintDrawnCompleted() override;
/**
* @brief Inflates UI controls by using ComponentContainer.
* You can create a ComponentContainer instance that contains multiple components.
@@ -65,6 +65,19 @@ public:
*/
std::string GetFilesDir() override;
/**
* @brief IsUpdatingConfigurations
*
* @return true or false
*/
bool IsUpdatingConfigurations() override;
/**
* @brief PrintDrawnCompleted
*
* @return true or false
*/
bool PrintDrawnCompleted() override;
/**
* @brief Obtains the absolute path which app created and will be excluded from automatic backup to remote storage.
* The returned path maybe changed if the application is moved to an adopted storage device.
@@ -169,6 +169,26 @@ std::shared_ptr<Global::Resource::ResourceManager> Ability::GetResourceManager()
return AbilityContext::GetResourceManager();
}
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
bool Ability::IsUpdatingConfigurations()
{
return AbilityContext::IsUpdatingConfigurations();
}
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
bool Ability::PrintDrawnCompleted()
{
return AbilityContext::PrintDrawnCompleted();
}
/**
* Will be called when ability start. You should override this function
*
@@ -756,5 +756,15 @@ void AbilityContext::SetShowOnLockScreen(bool isAllow)
{
ContextContainer::SetShowOnLockScreen(isAllow);
}
bool AbilityContext::IsUpdatingConfigurations()
{
return ContextContainer::IsUpdatingConfigurations();
}
bool AbilityContext::PrintDrawnCompleted()
{
return ContextContainer::PrintDrawnCompleted();
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -119,6 +119,20 @@ public:
*/
virtual std::string GetFilesDir() = 0;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
virtual bool IsUpdatingConfigurations() = 0;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
virtual bool PrintDrawnCompleted() = 0;
/**
* @brief Obtains the local database path.
* If the local database path does not exist, the system creates one and returns the created path.
@@ -85,6 +85,16 @@ std::string ContextImpl::GetCacheDir()
return dir;
}
bool ContextImpl::IsUpdatingConfigurations()
{
return false;
}
bool ContextImpl::PrintDrawnCompleted()
{
return false;
}
std::string ContextImpl::GetDatabaseDir()
{
std::string dir;
@@ -52,6 +52,20 @@ public:
*/
std::string GetCacheDir() override;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
bool IsUpdatingConfigurations() override;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
bool PrintDrawnCompleted() override;
/**
* @brief Obtains the temporary directory.
*
@@ -718,6 +718,20 @@ public:
*/
virtual void SetShowOnLockScreen(bool isAllow) = 0;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
virtual bool IsUpdatingConfigurations() = 0;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
virtual bool PrintDrawnCompleted() = 0;
friend DataAbilityHelper;
friend DataShareHelper;
friend ContinuationConnector;
@@ -72,6 +72,20 @@ public:
*/
virtual const std::shared_ptr<AbilityInfo> GetAbilityInfo() override;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
virtual bool IsUpdatingConfigurations() override;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
virtual bool PrintDrawnCompleted() override;
/**
* @brief Obtains the Context object of the application.
*
@@ -174,6 +174,20 @@ public:
*/
std::string GetCacheDir() override;
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
bool IsUpdatingConfigurations() override;
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @return Returns the notification is successful or fail
*/
bool PrintDrawnCompleted() override;
/**
* @brief Obtains the application-specific code-cache directory on the device's internal storage.
* The system will delete any files stored in this location both when your specific application is upgraded,
@@ -732,17 +746,30 @@ public:
*/
AAFwk::LifeCycleStateInfo GetLifeCycleStateInfo() const;
public:
static const int64_t CONTEXT_CREATE_BY_SYSTEM_APP;
static const std::string CONTEXT_DEAL_FILE_SEPARATOR;
static const std::string CONTEXT_DEAL_CODE_CACHE;
static const std::string CONTEXT_DEAL_Files;
static const std::string CONTEXT_DEAL_NO_BACKUP_Files;
static const std::string CONTEXT_DEAL_DIRNAME;
static const std::string CONTEXT_FILE_SEPARATOR;
static const std::string CONTEXT_DISTRIBUTED_BASE_BEFORE;
static const std::string CONTEXT_DISTRIBUTED_BASE_MIDDLE;
static const std::string CONTEXT_DISTRIBUTED;
static const std::string CONTEXT_DATA_STORAGE;
static const std::string CONTEXT_ELS[];
static const int EL_DEFAULT = 1;
int flags_ = 0x00000000;
protected:
sptr<IRemoteObject> GetToken() override;
bool HapModuleInfoRequestInit();
private:
bool IsCreateBySystemApp() const;
int GetCurrentAccountId() const;
void CreateDirIfNotExist(const std::string& dirPath) const;
std::shared_ptr<ProcessInfo> processInfo_ = nullptr;
std::shared_ptr<ApplicationInfo> applicationInfo_ = nullptr;
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
@@ -760,6 +787,7 @@ private:
std::shared_ptr<EventRunner> mainEventRunner_;
std::shared_ptr<HapModuleInfo> hapModuleInfoLocal_ = nullptr;
bool isCreateBySystemApp_ = false;
std::string currArea_ = CONTEXT_ELS[EL_DEFAULT];
};
} // namespace AppExecFwk
} // namespace OHOS
@@ -1130,5 +1130,21 @@ void ContextContainer::SetShowOnLockScreen(bool isAllow)
baseContext_->SetShowOnLockScreen(isAllow);
APP_LOGI("ContextContainer::SetShowOnLockScreen called end.");
}
bool ContextContainer::IsUpdatingConfigurations()
{
if (baseContext_ != nullptr) {
return baseContext_->IsUpdatingConfigurations();
}
return false;
}
bool ContextContainer::PrintDrawnCompleted()
{
if (baseContext_ != nullptr) {
return baseContext_->PrintDrawnCompleted();
}
return false;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -25,6 +25,7 @@
#include "directory_ex.h"
#include "file_ex.h"
#include "iservice_registry.h"
#include "os_account_manager.h"
#include "spec_task_dispatcher.h"
#include "sys_mgr_client.h"
#include "system_ability_definition.h"
@@ -40,6 +41,13 @@ const std::string ContextDeal::CONTEXT_DEAL_CODE_CACHE("code_cache");
const std::string ContextDeal::CONTEXT_DEAL_Files("files");
const std::string ContextDeal::CONTEXT_DEAL_NO_BACKUP_Files("no_backup");
const std::string ContextDeal::CONTEXT_DEAL_DIRNAME("preferences");
const int64_t ContextDeal::CONTEXT_CREATE_BY_SYSTEM_APP(0x00000001);
const std::string ContextDeal::CONTEXT_FILE_SEPARATOR("/");
const std::string ContextDeal::CONTEXT_DISTRIBUTED_BASE_BEFORE("/mnt/hmdfs/");
const std::string ContextDeal::CONTEXT_DISTRIBUTED_BASE_MIDDLE("/device_view/local/data/");
const std::string ContextDeal::CONTEXT_DISTRIBUTED("distributedfiles");
const std::string ContextDeal::CONTEXT_DATA_STORAGE("/data/storage/");
const std::string ContextDeal::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"};
ContextDeal::ContextDeal(bool isCreateBySystemApp) : isCreateBySystemApp_(isCreateBySystemApp)
{}
@@ -309,6 +317,16 @@ std::string ContextDeal::GetCacheDir()
return (applicationInfo_ != nullptr) ? applicationInfo_->cacheDir : "";
}
bool ContextDeal::IsUpdatingConfigurations()
{
return false;
}
bool ContextDeal::PrintDrawnCompleted()
{
return false;
}
/**
* @brief Obtains the application-specific code-cache directory on the device's internal storage.
* The system will delete any files stored in this location both when your specific application is upgraded,
@@ -621,6 +639,31 @@ int ContextDeal::VerifyPermission(const std::string &permission, int pid, int ui
return 0;
}
bool ContextDeal::IsCreateBySystemApp() const
{
return (static_cast<uint64_t>(flags_) & CONTEXT_CREATE_BY_SYSTEM_APP) == 1;
}
int ContextDeal::GetCurrentAccountId() const
{
int userId = 0;
AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId);
return userId;
}
void ContextDeal::CreateDirIfNotExist(const std::string &dirPath) const
{
APP_LOGI("CreateDirIfNotExist: create directory if not exists.");
if (!OHOS::FileExists(dirPath)) {
APP_LOGI("ContextDeal::CreateDirIfNotExist File is not exits");
bool createDir = OHOS::ForceCreateDirectory(dirPath);
if (!createDir) {
APP_LOGI("CreateDirIfNotExist: create dir %{public}s failed.", dirPath.c_str());
return;
}
}
}
/**
* @brief Obtains the distributed file path.
* If the distributed file path does not exist, the system creates one and returns the created path. This method is
@@ -630,7 +673,18 @@ int ContextDeal::VerifyPermission(const std::string &permission, int pid, int ui
*/
std::string ContextDeal::GetDistributedDir()
{
return "";
APP_LOGI("ContextImpl::GetDistributedDir");
std::string dir;
if (IsCreateBySystemApp()) {
dir = CONTEXT_DISTRIBUTED_BASE_BEFORE + std::to_string(GetCurrentAccountId()) +
CONTEXT_DISTRIBUTED_BASE_MIDDLE + GetBundleName();
} else {
dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTED + CONTEXT_FILE_SEPARATOR +
((GetHapModuleInfo() == nullptr) ? "" : GetHapModuleInfo()->moduleName);
}
CreateDirIfNotExist(dir);
APP_LOGI("ContextImpl::GetDistributedDir:%{public}s", dir.c_str());
return dir;
}
/**
* @brief Sets the pattern of this Context based on the specified pattern ID.
@@ -677,7 +731,22 @@ std::shared_ptr<HapModuleInfo> ContextDeal::GetHapModuleInfo()
if (hapModuleInfoLocal_ == nullptr) {
HapModuleInfoRequestInit();
}
sptr<IBundleMgr> ptr = GetBundleManager();
if (ptr == nullptr) {
APP_LOGE("GetAppType failed to get bundle manager service");
return hapModuleInfoLocal_;
}
Want want;
ElementName name;
name.SetBundleName(GetBundleName());
want.SetElement(name);
std::vector<AbilityInfo> abilityInfos;
bool isSuc = ptr->QueryAbilityInfos(want, abilityInfos);
if (isSuc) {
hapModuleInfoLocal_->abilityInfos = abilityInfos;
}
APP_LOGI("ContextDeal::GetHapModuleInfo end");
return hapModuleInfoLocal_;
}
@@ -122,6 +122,16 @@ public:
int32_t userId = DEFAULT_INVAL_VALUE,
int requestCode = DEFAULT_INVAL_VALUE) = 0;
virtual int GetAppMemorySize()
{
return 0;
}
virtual bool IsRamConstrainedDevice()
{
return false;
}
/**
* TerminateAbility, terminate the special ability.
*
@@ -938,6 +948,10 @@ public:
GET_SYSTEM_MEMORY_ATTR,
GET_APP_MEMORY_SIZE,
IS_RAM_CONSTRAINED_DEVICE,
GET_ABILITY_RUNNING_INFO,
GET_EXTENSION_RUNNING_INFO,
@@ -2239,5 +2239,269 @@ napi_value NAPI_GetSystemMemoryAttr(napi_env env, napi_callback_info info)
HILOG_INFO("%{public}s end", __func__);
return ret;
}
static void GetAppMemorySizeExecute(napi_env env, void *data)
{
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
cb->result = GetAbilityManagerInstance()->GetAppMemorySize();
HILOG_INFO("%{public}s, result = %{public}d", __func__, cb->result);
}
static void GetAppMemorySizePromiseComplete(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s, main event thread complete.", __func__);
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
if (cb == nullptr) {
HILOG_ERROR("%{public}s, main event thread complete end.", __func__);
return;
}
napi_value result = nullptr;
napi_create_int32(env, cb->result, &result);
NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, cb->deferred, result));
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, cb->asyncWork));
if (cb != nullptr) {
delete cb;
cb = nullptr;
}
HILOG_INFO("%{public}s, main event thread complete end.", __func__);
}
static void GetAppMemorySizeAsyncComplete(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s, main event thread complete.", __func__);
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
if (cb == nullptr) {
HILOG_ERROR("%{public}s, main event thread complete end.", __func__);
return;
}
const int errorCodeFailed = -1;
const int errorCodeSuccess = 0;
const unsigned int argsCount = 2;
const unsigned int paramFirst = 0;
const unsigned int paramSecond = 1;
napi_value result[argsCount] = {nullptr};
if (cb->result == errorCodeFailed) {
napi_create_int32(env, 1, &result[paramFirst]);
napi_create_int32(env, cb->result, &result[paramSecond]);
} else {
napi_create_int32(env, errorCodeSuccess, &result[paramFirst]);
napi_create_int32(env, cb->result, &result[paramSecond]);
}
napi_value undefined = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined));
napi_value callback = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, cb->callback, &callback));
napi_value callResult = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, argsCount, result, &callResult));
if (cb->callback != nullptr) {
NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, cb->callback));
}
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, cb->asyncWork));
if (cb != nullptr) {
delete cb;
cb = nullptr;
}
HILOG_INFO("%{public}s, main event thread complete end.", __func__);
}
static napi_value GetAppMemorySizePromise(napi_env env)
{
napi_value resourceName = nullptr;
napi_value retPromise = nullptr;
CallbackInfo *cb = new (std::nothrow) CallbackInfo;
if (cb == nullptr) {
HILOG_INFO("%{public}s, promise cb new failed", __func__);
NAPI_CALL(env, napi_get_null(env, &retPromise));
return retPromise;
}
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_create_promise(env, &cb->deferred, &retPromise));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetAppMemorySizeExecute,
GetAppMemorySizePromiseComplete, (void *)cb, &cb->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, cb->asyncWork));
HILOG_INFO("%{public}s, promise end", __func__);
return retPromise;
}
static napi_value GetAppMemorySizeAsync(napi_env env, napi_value args)
{
napi_value resourceName = nullptr;
napi_value retAsync = nullptr;
napi_valuetype valuetype = napi_undefined;
CallbackInfo *cb = new (std::nothrow) CallbackInfo;
if (cb == nullptr) {
HILOG_ERROR("%{public}s, async cb new failed", __func__);
NAPI_CALL(env, napi_get_null(env, &retAsync));
return retAsync;
}
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_typeof(env, args, &valuetype));
if (valuetype != napi_function) {
return retAsync;
}
NAPI_CALL(env, napi_create_reference(env, args, 1, &cb->callback));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetAppMemorySizeExecute,
GetAppMemorySizeAsyncComplete, (void *)cb, &cb->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, cb->asyncWork));
HILOG_INFO("%{public}s, async end", __func__);
NAPI_CALL(env, napi_create_int32(env, 0, &retAsync));
return retAsync;
}
napi_value NAPI_GetAppMemorySize(napi_env env, napi_callback_info info)
{
size_t argc = 1;
napi_value argv[1] = {nullptr};
napi_value ret = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
HILOG_INFO("%{public}s argc = [%{public}zu]", __func__, argc);
if (argc == 0) {
// promiss
ret = GetAppMemorySizePromise(env);
} else if (argc == 1) {
// async
ret = GetAppMemorySizeAsync(env, argv[0]);
} else {
HILOG_ERROR("%{public}s js input param error", __func__);
NAPI_CALL(env, napi_get_null(env, &ret));
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
static void IsRamConstrainedDeviceExecute(napi_env env, void *data)
{
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
cb->isRamConstrainedDevice = GetAbilityManagerInstance()->IsRamConstrainedDevice();
if (cb->isRamConstrainedDevice) {
HILOG_ERROR("%{public}s, true", __func__);
} else {
HILOG_ERROR("%{public}s, false", __func__);
}
}
static void IsRamConstrainedDevicePromiseComplete(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s, main event thread complete.", __func__);
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
if (cb == nullptr) {
HILOG_ERROR("%{public}s, main event thread complete end.", __func__);
return;
}
napi_value result = nullptr;
napi_get_boolean(env, cb->isRamConstrainedDevice, &result);
NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, cb->deferred, result));
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, cb->asyncWork));
if (cb != nullptr) {
delete cb;
cb = nullptr;
}
HILOG_INFO("%{public}s, main event thread complete end.", __func__);
}
static napi_value IsRamConstrainedDevicePromise(napi_env env)
{
napi_value resourceName = nullptr;
napi_value retPromise = nullptr;
CallbackInfo *cb = new (std::nothrow) CallbackInfo;
if (cb == nullptr) {
HILOG_INFO("%{public}s, promise cb new failed", __func__);
NAPI_CALL(env, napi_get_null(env, &retPromise));
return retPromise;
}
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_create_promise(env, &cb->deferred, &retPromise));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, IsRamConstrainedDeviceExecute,
IsRamConstrainedDevicePromiseComplete, (void *)cb, &cb->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, cb->asyncWork));
HILOG_INFO("%{public}s, promise end", __func__);
return retPromise;
}
static void IsRamConstrainedDeviceAsyncComplete(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s, main event thread complete.", __func__);
CallbackInfo *cb = static_cast<CallbackInfo *>(data);
if (cb == nullptr) {
HILOG_ERROR("%{public}s, main event thread complete end.", __func__);
return;
}
const int errorCodeFailed = 1;
const int errorCodeSuccess = 0;
const unsigned int argsCount = 2;
const unsigned int paramFirst = 0;
const unsigned int paramSecond = 1;
napi_value result[argsCount] = {nullptr};
if (cb->isRamConstrainedDevice) {
napi_create_int32(env, errorCodeSuccess, &result[paramFirst]);
napi_get_boolean(env, cb->isRamConstrainedDevice, &result[paramSecond]);
} else {
napi_create_int32(env, errorCodeFailed, &result[paramFirst]);
napi_get_boolean(env, cb->isRamConstrainedDevice, &result[paramSecond]);
}
napi_value undefined = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined));
napi_value callback = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, cb->callback, &callback));
napi_value callResult = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, argsCount, result, &callResult));
if (cb->callback != nullptr) {
NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, cb->callback));
}
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, cb->asyncWork));
if (cb != nullptr) {
delete cb;
cb = nullptr;
}
HILOG_INFO("%{public}s, main event thread complete end.", __func__);
}
static napi_value IsRamConstrainedDeviceAsync(napi_env env, napi_value args)
{
napi_value resourceName = nullptr;
napi_value retAsync = nullptr;
napi_valuetype valuetype = napi_undefined;
CallbackInfo *cb = new (std::nothrow) CallbackInfo;
if (cb == nullptr) {
HILOG_ERROR("%{public}s, async cb new failed", __func__);
NAPI_CALL(env, napi_get_null(env, &retAsync));
return retAsync;
}
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_typeof(env, args, &valuetype));
if (valuetype != napi_function) {
return retAsync;
}
NAPI_CALL(env, napi_create_reference(env, args, 1, &cb->callback));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, IsRamConstrainedDeviceExecute,
IsRamConstrainedDeviceAsyncComplete, (void *)cb, &cb->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, cb->asyncWork));
HILOG_INFO("%{public}s, async end", __func__);
NAPI_CALL(env, napi_create_int32(env, 0, &retAsync));
return retAsync;
}
napi_value NAPI_IsRamConstrainedDevice(napi_env env, napi_callback_info info)
{
size_t argc = 1;
napi_value argv[1] = {nullptr};
napi_value ret = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
HILOG_INFO("%{public}s argc = [%{public}zu]", __func__, argc);
if (argc == 0) {
// promiss
ret = IsRamConstrainedDevicePromise(env);
} else if (argc == 1) {
// async
ret = IsRamConstrainedDeviceAsync(env, argv[0]);
} else {
HILOG_ERROR("%{public}s js input param error", __func__);
NAPI_CALL(env, napi_get_null(env, &ret));
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -143,6 +143,14 @@ struct SystemMemroyInfoCB {
napi_ref callback = nullptr;
};
struct CallbackInfo {
napi_async_work asyncWork = nullptr;
napi_deferred deferred = nullptr;
napi_ref callback = nullptr;
int result = -1;
bool isRamConstrainedDevice = false;
};
napi_value NAPI_GetAllRunningProcesses(napi_env env, napi_callback_info info);
napi_value NAPI_GetActiveProcessInfos(napi_env env, napi_callback_info info);
napi_value NAPI_QueryRunningAbilityMissionInfos(napi_env env, napi_callback_info info);
@@ -160,6 +168,8 @@ void CreateWeightReasonCodeObject(napi_env env, napi_value value);
napi_value GetCallbackErrorValue(napi_env env, int errCode);
napi_value NapiGetNull(napi_env env);
napi_value NAPI_GetSystemMemoryAttr(napi_env env, napi_callback_info);
napi_value NAPI_GetAppMemorySize(napi_env env, napi_callback_info info);
napi_value NAPI_IsRamConstrainedDevice(napi_env env, napi_callback_info info);
} // namespace AppExecFwk
} // namespace OHOS
#endif // NAPI_ABILITY_MANAGER_H
@@ -56,6 +56,8 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getAbilityMissionSnapshot", NAPI_GetAbilityMissionSnapshot),
DECLARE_NAPI_PROPERTY("WeightReasonCode", nWeightReasonCode),
DECLARE_NAPI_FUNCTION("getSystemMemoryAttr", NAPI_GetSystemMemoryAttr),
DECLARE_NAPI_FUNCTION("getAppMemorySize", NAPI_GetAppMemorySize),
DECLARE_NAPI_FUNCTION("isRamConstrainedDevice", NAPI_IsRamConstrainedDevice),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
@@ -25,6 +25,8 @@ ohos_shared_library("featureability") {
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include",
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include",
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/include",
"//third_party/jsoncpp",
"//third_party/jsoncpp/include/json",
]
sources = [
@@ -49,6 +51,7 @@ ohos_shared_library("featureability") {
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
"//foundation/ace/napi:ace_napi",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//third_party/jsoncpp:jsoncpp",
"//third_party/libuv:uv_static",
"//utils/native/base:utils",
]
@@ -498,7 +498,7 @@ void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector<s
EXTERN_C_END
/**
* @brief Get Diles Dir.
* @brief Get Files Dir.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
@@ -511,6 +511,118 @@ napi_value NAPI_GetFilesDir(napi_env env, napi_callback_info info)
return NAPI_GetFilesDirCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Get OrCreateDistributed Dir.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetOrCreateDistributedDir(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called", __func__);
return NAPI_GetOrCreateDistributedDirCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Get Cache Dir.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCacheDir(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called", __func__);
return NAPI_GetCacheDirCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Get ExternalCache Dir.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetExternalCacheDir(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called", __func__);
return NAPI_GetExternalCacheDirCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Obtains the type of this application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxAppType(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
return NAPI_GetAppTypeCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Obtains the HapModuleInfo object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxHapModuleInfo(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
return NAPI_GetHapModuleInfoCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Obtains the AppVersionInfo object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetAppVersionInfo(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
return NAPI_GetAppVersionInfoCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Obtains the Application Context object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetApplicationContext(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
return NAPI_GetContextCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Obtains information about the current ability.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxAbilityInfo(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
return NAPI_GetAbilityInfoCommon(env, info, AbilityType::PAGE);
}
void CanRequestPermissionExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called.", __func__);
@@ -2927,6 +3039,34 @@ napi_value NAPI_GetPreferencesDirSync(napi_env env, napi_callback_info info)
return ret;
}
/**
* @brief Checks whether the configuration of this ability is changing.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return Returns true if the configuration of this ability is changing and false otherwise.
*/
napi_value NAPI_IsUpdatingConfigurations(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called", __func__);
return NAPI_IsUpdatingConfigurationsCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Informs the system of the time required for drawing this Page ability.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_PrintDrawnCompleted(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called", __func__);
return NAPI_PrintDrawnCompletedCommon(env, info, AbilityType::PAGE);
}
/**
* @brief Context NAPI module registration.
*
@@ -2954,8 +3094,18 @@ napi_value ContextPermissionInit(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getCallingBundle", NAPI_GetCallingBundle),
DECLARE_NAPI_FUNCTION("getOrCreateLocalDir", NAPI_GetOrCreateLocalDir),
DECLARE_NAPI_FUNCTION("getFilesDir", NAPI_GetFilesDir),
DECLARE_NAPI_FUNCTION("isUpdatingConfigurations", NAPI_IsUpdatingConfigurations),
DECLARE_NAPI_FUNCTION("printDrawnCompleted", NAPI_PrintDrawnCompleted),
DECLARE_NAPI_FUNCTION("getDatabaseDirSync", NAPI_GetDatabaseDirSync),
DECLARE_NAPI_FUNCTION("getPreferencesDirSync", NAPI_GetPreferencesDirSync),
DECLARE_NAPI_FUNCTION("getCacheDir", NAPI_GetCacheDir),
DECLARE_NAPI_FUNCTION("getExternalCacheDir", NAPI_GetExternalCacheDir),
DECLARE_NAPI_FUNCTION("getAppType", NAPI_GetCtxAppType),
DECLARE_NAPI_FUNCTION("getHapModuleInfo", NAPI_GetCtxHapModuleInfo),
DECLARE_NAPI_FUNCTION("getAppVersionInfo", NAPI_GetAppVersionInfo),
DECLARE_NAPI_FUNCTION("getApplicationContext", NAPI_GetApplicationContext),
DECLARE_NAPI_FUNCTION("getAbilityInfo", NAPI_GetCtxAbilityInfo),
DECLARE_NAPI_FUNCTION("getOrCreateDistributedDir", NAPI_GetOrCreateDistributedDir),
};
NAPI_CALL(env,
@@ -112,6 +112,48 @@ napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info);
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info);
napi_value NAPI_GetOrCreateDistributedDir(napi_env env, napi_callback_info info);
napi_value NAPI_GetFilesDir(napi_env env, napi_callback_info info);
napi_value NAPI_GetCacheDir(napi_env env, napi_callback_info info);
napi_value NAPI_GetExternalCacheDir(napi_env env, napi_callback_info info);
/**
* @brief Obtains the type of this application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxAppType(napi_env env, napi_callback_info info);
/**
* @brief Obtains the HapModuleInfo object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxHapModuleInfo(napi_env env, napi_callback_info info);
napi_value NAPI_GetAppVersionInfo(napi_env env, napi_callback_info info);
napi_value NAPI_GetApplicationContext(napi_env env, napi_callback_info info);
/**
* @brief Obtains information about the current ability.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetCtxAbilityInfo(napi_env env, napi_callback_info info);
} // namespace AppExecFwk
} // namespace OHOS
#endif /* OHOS_APPEXECFWK_NAPI_CONTEXT_H */
File diff suppressed because it is too large Load Diff
@@ -369,6 +369,8 @@ void UpdateAsyncCompleteCB(napi_env env, napi_status status, void *data);
void UpdatePromiseCompleteCB(napi_env env, napi_status status, void *data);
napi_value NAPI_Call(napi_env env, napi_callback_info info);
napi_value NAPI_OpenFile(napi_env env, napi_callback_info info);
napi_value OpenFileWrap(napi_env env, napi_callback_info info, DAHelperOpenFileCB *openFileCB);
@@ -23,6 +23,7 @@
#include "napi/native_node_api.h"
#include "napi_common.h"
#include "napi_common_util.h"
#include "pac_map.h"
#include "values_bucket.h"
#include "want.h"
@@ -209,6 +210,17 @@ struct HapModuleInfoCB {
HapModuleInfo_ hapModuleInfo;
};
struct AppVersionInfo {
std::string appName;
std::string versionName;
int32_t versionCode = 0;
};
struct AppVersionInfoCB {
CBBase cbBase;
AppVersionInfo appVersionInfo;
};
struct DataAbilityHelperCB {
CBBase cbBase;
napi_ref uri = nullptr;
@@ -313,6 +325,7 @@ struct DAHelperDeleteCB {
DataAbilityHelper *dataAbilityHelper = nullptr;
std::string uri;
NativeRdb::DataAbilityPredicates predicates;
AppExecFwk::PacMap pacMap;
int result = 0;
int execResult;
};
@@ -323,6 +336,7 @@ struct DAHelperQueryCB {
std::string uri;
std::vector<std::string> columns;
NativeRdb::DataAbilityPredicates predicates;
AppExecFwk::PacMap pacMap;
std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
int execResult;
};
@@ -333,6 +347,7 @@ struct DAHelperUpdateCB {
std::string uri;
NativeRdb::ValuesBucket valueBucket;
NativeRdb::DataAbilityPredicates predicates;
AppExecFwk::PacMap pacMap;
int result = 0;
int execResult;
};
@@ -336,14 +336,71 @@ void GetFilesDirExecuteCallback(napi_env env, void *data)
asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetFilesDir();
HILOG_INFO("%{public}s end. filesDir=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str());
}
void IsUpdatingConfigurationsExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = static_cast<AsyncJSCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__);
return;
}
asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR;
asyncCallbackInfo->native_data.data_type = NVT_NONE;
if (asyncCallbackInfo->ability == nullptr) {
HILOG_ERROR("%{public}s ability == nullptr", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(asyncCallbackInfo)) {
HILOG_ERROR("%{public}s wrong ability type", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID;
asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED;
return;
}
asyncCallbackInfo->native_data.data_type = NVT_BOOL;
asyncCallbackInfo->native_data.bool_value = asyncCallbackInfo->ability->IsUpdatingConfigurations();
HILOG_INFO("%{public}s end", __func__);
}
/**
* @brief GetFilesDir processing function.
* @brief PrintDrawnCompleted asynchronous processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param asyncCallbackInfo Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
* @param data Point to asynchronous processing of data.
*/
void PrintDrawnCompletedExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = static_cast<AsyncJSCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__);
return;
}
asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR;
asyncCallbackInfo->native_data.data_type = NVT_NONE;
if (asyncCallbackInfo->ability == nullptr) {
HILOG_ERROR("%{public}s ability == nullptr", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(asyncCallbackInfo)) {
HILOG_ERROR("%{public}s wrong ability type", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID;
asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED;
return;
}
asyncCallbackInfo->native_data.data_type = NVT_NONE;
asyncCallbackInfo->native_data.bool_value = asyncCallbackInfo->ability->PrintDrawnCompleted();
HILOG_INFO("%{public}s end", __func__);
}
napi_value NAPI_GetFilesDirWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
@@ -403,6 +460,432 @@ napi_value NAPI_GetFilesDirCommon(napi_env env, napi_callback_info info, Ability
return ret;
}
void GetOrCreateDistributedDirExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = static_cast<AsyncJSCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__);
return;
}
asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR;
asyncCallbackInfo->native_data.data_type = NVT_NONE;
if (asyncCallbackInfo->ability == nullptr) {
HILOG_ERROR("%{public}s ability == nullptr", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(asyncCallbackInfo)) {
HILOG_ERROR("%{public}s wrong ability type", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID;
asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED;
return;
}
asyncCallbackInfo->native_data.data_type = NVT_STRING;
asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetDistributedDir();
HILOG_INFO("%{public}s end. filesDir=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str());
}
/**
* @brief GetFilesDir processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param asyncCallbackInfo Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value NAPI_GetOrCreateDistributedDirWrap(
napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
size_t argc = ARGS_MAX_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value jsthis = 0;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data));
if (argc > ARGS_ONE) {
HILOG_ERROR("%{public}s called, parameters is invalid.", __func__);
return nullptr;
}
if (argc == ARGS_ONE) {
if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) {
HILOG_ERROR("%{public}s called, the first parameter is invalid.", __func__);
return nullptr;
}
}
AsyncParamEx asyncParamEx;
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
HILOG_INFO("%{public}s called. asyncCallback.", __func__);
asyncParamEx.resource = "NAPI_GetFilesDirCallback";
asyncParamEx.execute = GetOrCreateDistributedDirExecuteCallback;
asyncParamEx.complete = CompleteAsyncCallbackWork;
return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
} else {
HILOG_INFO("%{public}s called. promise.", __func__);
asyncParamEx.resource = "NAPI_GetFilesDirPromise";
asyncParamEx.execute = GetOrCreateDistributedDirExecuteCallback;
asyncParamEx.complete = CompletePromiseCallbackWork;
return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
}
}
napi_value NAPI_GetOrCreateDistributedDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->abilityType = abilityType;
napi_value ret = NAPI_GetOrCreateDistributedDirWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
FreeAsyncJSCallbackInfo(&asyncCallbackInfo);
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
/**
* @brief GetCacheDir asynchronous processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param data Point to asynchronous processing of data.
*/
void GetCacheDirExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = static_cast<AsyncJSCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__);
return;
}
asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR;
asyncCallbackInfo->native_data.data_type = NVT_NONE;
if (asyncCallbackInfo->ability == nullptr) {
HILOG_ERROR("%{public}s ability == nullptr", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(asyncCallbackInfo)) {
HILOG_ERROR("%{public}s wrong ability type", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID;
asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED;
return;
}
asyncCallbackInfo->native_data.data_type = NVT_STRING;
asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetCacheDir();
HILOG_INFO("%{public}s end. CacheDir=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str());
}
/**
* @brief NAPI_GetCacheDirWrap processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param asyncCallbackInfo Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value NAPI_GetCacheDirWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
size_t argc = ARGS_MAX_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value jsthis = 0;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data));
if (argc > ARGS_ONE) {
HILOG_ERROR("%{public}s called, parameters is invalid.", __func__);
return nullptr;
}
if (argc == ARGS_ONE) {
if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) {
HILOG_ERROR("%{public}s called, the first parameter is invalid.", __func__);
return nullptr;
}
}
AsyncParamEx asyncParamEx;
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
HILOG_INFO("%{public}s called. asyncCallback.", __func__);
asyncParamEx.resource = "NAPI_GetCacheDirCallback";
asyncParamEx.execute = GetCacheDirExecuteCallback;
asyncParamEx.complete = CompleteAsyncCallbackWork;
return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
} else {
HILOG_INFO("%{public}s called. promise.", __func__);
asyncParamEx.resource = "NAPI_GetCacheDirPromise";
asyncParamEx.execute = GetCacheDirExecuteCallback;
asyncParamEx.complete = CompletePromiseCallbackWork;
return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
}
}
napi_value NAPI_GetCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->abilityType = abilityType;
napi_value ret = NAPI_GetCacheDirWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
FreeAsyncJSCallbackInfo(&asyncCallbackInfo);
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
/**
* @brief GetExternalCacheDir asynchronous processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param data Point to asynchronous processing of data.
*/
void GetExternalCacheDirExecuteCallback(napi_env env, void *data)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = static_cast<AsyncJSCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s. asyncCallbackInfo is null", __func__);
return;
}
asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR;
asyncCallbackInfo->native_data.data_type = NVT_NONE;
if (asyncCallbackInfo->ability == nullptr) {
HILOG_ERROR("%{public}s ability == nullptr", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(asyncCallbackInfo)) {
HILOG_ERROR("%{public}s wrong ability type", __func__);
asyncCallbackInfo->error_code = NAPI_ERR_ABILITY_TYPE_INVALID;
asyncCallbackInfo->native_data.data_type = NVT_UNDEFINED;
return;
}
asyncCallbackInfo->native_data.data_type = NVT_STRING;
asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetExternalCacheDir();
HILOG_INFO(
"%{public}s end. ExternalCacheDir=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str());
}
/**
* @brief NAPI_GetExternalCacheDirWrap processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param asyncCallbackInfo Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value NAPI_GetExternalCacheDirWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
size_t argc = ARGS_MAX_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value jsthis = 0;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data));
if (argc > ARGS_ONE) {
HILOG_INFO("%{public}s called, parameters is invalid.", __func__);
return nullptr;
}
if (argc == ARGS_ONE) {
if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) {
HILOG_INFO("%{public}s called, the first parameter is invalid.", __func__);
return nullptr;
}
}
AsyncParamEx asyncParamEx;
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
HILOG_INFO("%{public}s called. asyncCallback.", __func__);
asyncParamEx.resource = "NAPI_GetExternalCacheDirCallback";
asyncParamEx.execute = GetExternalCacheDirExecuteCallback;
asyncParamEx.complete = CompleteAsyncCallbackWork;
return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
} else {
HILOG_INFO("%{public}s called. promise.", __func__);
asyncParamEx.resource = "NAPI_GetExternalCacheDirPromise";
asyncParamEx.execute = GetExternalCacheDirExecuteCallback;
asyncParamEx.complete = CompletePromiseCallbackWork;
return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
}
}
napi_value NAPI_GetExternalCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->abilityType = abilityType;
napi_value ret = NAPI_GetExternalCacheDirWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
FreeAsyncJSCallbackInfo(&asyncCallbackInfo);
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
napi_value NAPI_IsUpdatingConfigurationsWrap(
napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
size_t argc = ARGS_MAX_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value jsthis = 0;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data));
if (argc > ARGS_ONE) {
HILOG_INFO("%{public}s called, parameters is invalid.", __func__);
return nullptr;
}
if (argc == ARGS_ONE) {
if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) {
HILOG_INFO("%{public}s called, the first parameter is invalid.", __func__);
return nullptr;
}
}
AsyncParamEx asyncParamEx;
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
HILOG_INFO("%{public}s called. asyncCallback.", __func__);
asyncParamEx.resource = "NAPI_IsUpdatingConfigurationsCallback";
asyncParamEx.execute = IsUpdatingConfigurationsExecuteCallback;
asyncParamEx.complete = CompleteAsyncCallbackWork;
return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
} else {
HILOG_INFO("%{public}s called. promise.", __func__);
asyncParamEx.resource = "NAPI_IsUpdatingConfigurationsPromise";
asyncParamEx.execute = IsUpdatingConfigurationsExecuteCallback;
asyncParamEx.complete = CompletePromiseCallbackWork;
return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
}
}
napi_value NAPI_PrintDrawnCompletedWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo)
{
HILOG_INFO("%{public}s called", __func__);
size_t argc = ARGS_MAX_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value jsthis = 0;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data));
if (argc > ARGS_ONE) {
HILOG_INFO("%{public}s called, parameters is invalid.", __func__);
return nullptr;
}
if (argc == ARGS_ONE) {
if (!CreateAsyncCallback(env, args[PARAM0], asyncCallbackInfo)) {
HILOG_INFO("%{public}s called, the first parameter is invalid.", __func__);
return nullptr;
}
}
AsyncParamEx asyncParamEx;
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
HILOG_INFO("%{public}s called. asyncCallback.", __func__);
asyncParamEx.resource = "NAPI_PrintDrawnCompletedCallback";
asyncParamEx.execute = PrintDrawnCompletedExecuteCallback;
asyncParamEx.complete = CompleteAsyncVoidCallbackWork;
return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
} else {
HILOG_INFO("%{public}s called. promise.", __func__);
asyncParamEx.resource = "NAPI_PrintDrawnCompletedPromise";
asyncParamEx.execute = PrintDrawnCompletedExecuteCallback;
asyncParamEx.complete = CompletePromiseVoidCallbackWork;
return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx);
}
}
napi_value NAPI_IsUpdatingConfigurationsCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->abilityType = abilityType;
napi_value ret = NAPI_IsUpdatingConfigurationsWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
FreeAsyncJSCallbackInfo(&asyncCallbackInfo);
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
napi_value NAPI_PrintDrawnCompletedCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->abilityType = abilityType;
napi_value ret = NAPI_PrintDrawnCompletedWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
FreeAsyncJSCallbackInfo(&asyncCallbackInfo);
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end", __func__);
return ret;
}
/**
* @brief Create asynchronous data.
*
@@ -1480,6 +1963,281 @@ napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, Ab
return ret;
}
/**
* @brief Create asynchronous data.
*
* @param env The environment that the Node-API call is invoked under.
*
* @return Return a pointer to AppVersionInfoCB on success, nullptr on failure.
*/
AppVersionInfoCB *CreateAppVersionInfoCBInfo(napi_env env)
{
HILOG_INFO("%{public}s called.", __func__);
napi_value global = nullptr;
NAPI_CALL(env, napi_get_global(env, &global));
napi_value abilityObj = nullptr;
NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj));
Ability *ability = nullptr;
NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability));
AppVersionInfoCB *appVersionInfoCB = new (std::nothrow) AppVersionInfoCB;
if (appVersionInfoCB == nullptr) {
HILOG_ERROR("%{public}s, appVersionInfoCB == nullptr.", __func__);
return nullptr;
}
appVersionInfoCB->cbBase.cbInfo.env = env;
appVersionInfoCB->cbBase.asyncWork = nullptr;
appVersionInfoCB->cbBase.deferred = nullptr;
appVersionInfoCB->cbBase.ability = ability;
HILOG_INFO("%{public}s end.", __func__);
return appVersionInfoCB;
}
void SaveAppVersionInfo(AppVersionInfo &appVersionInfo, const std::string appName, const std::string versionName,
const int32_t versionCode)
{
HILOG_INFO("%{public}s called.", __func__);
appVersionInfo.appName = appName;
appVersionInfo.versionName = versionName;
appVersionInfo.versionCode = versionCode;
HILOG_INFO("%{public}s end.", __func__);
}
napi_value WrapAppVersionInfo(napi_env env, const AppVersionInfoCB &appVersionInfoCB)
{
HILOG_INFO("%{public}s called.", __func__);
napi_value result = nullptr;
napi_value proValue = nullptr;
NAPI_CALL(env, napi_create_object(env, &result));
NAPI_CALL(env,
napi_create_string_utf8(env, appVersionInfoCB.appVersionInfo.appName.c_str(), NAPI_AUTO_LENGTH, &proValue));
NAPI_CALL(env, napi_set_named_property(env, result, "appName", proValue));
NAPI_CALL(env,
napi_create_string_utf8(env, appVersionInfoCB.appVersionInfo.versionName.c_str(), NAPI_AUTO_LENGTH, &proValue));
NAPI_CALL(env, napi_set_named_property(env, result, "versionName", proValue));
NAPI_CALL(env, napi_create_int32(env, appVersionInfoCB.appVersionInfo.versionCode, &proValue));
NAPI_CALL(env, napi_set_named_property(env, result, "versionCode", proValue));
HILOG_INFO("%{public}s end.", __func__);
return result;
}
void GetAppVersionInfoExecuteCB(napi_env env, void *data)
{
HILOG_INFO("NAPI_GetAppVersionInfo, worker pool thread execute.");
AppVersionInfoCB *appVersionInfoCB = static_cast<AppVersionInfoCB *>(data);
if (appVersionInfoCB == nullptr) {
HILOG_ERROR("NAPI_GetAppVersionInfo, appVersionInfoCB == nullptr");
return;
}
appVersionInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR;
if (appVersionInfoCB->cbBase.ability == nullptr) {
HILOG_ERROR("NAPI_GetAppVersionInfo, ability == nullptr");
appVersionInfoCB->cbBase.errCode = NAPI_ERR_ACE_ABILITY;
return;
}
if (!CheckAbilityType(&appVersionInfoCB->cbBase)) {
HILOG_ERROR("NAPI_GetAppVersionInfo,wrong ability type");
appVersionInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_TYPE_INVALID;
return;
}
std::shared_ptr<AbilityInfo> abilityInfoPtr = appVersionInfoCB->cbBase.ability->GetAbilityInfo();
std::shared_ptr<ApplicationInfo> appInfoPtr = appVersionInfoCB->cbBase.ability->GetApplicationInfo();
if (abilityInfoPtr != nullptr && appInfoPtr != nullptr) {
HILOG_ERROR("NAPI_GetAppVersionInfo, bundleName = %{public}s", abilityInfoPtr->bundleName.c_str());
HILOG_ERROR("NAPI_GetAppVersionInfo, appName = %{public}s", abilityInfoPtr->appName.c_str());
HILOG_ERROR("NAPI_GetAppVersionInfo, versionName1 = %{public}s", abilityInfoPtr->versionName.c_str());
HILOG_ERROR("NAPI_GetAppVersionInfo, name = %{public}s", appInfoPtr->name.c_str());
HILOG_ERROR("NAPI_GetAppVersionInfo, versionCode = %{public}d", appInfoPtr->versionCode);
HILOG_ERROR("NAPI_GetAppVersionInfo, versionName2 = %{public}s", appInfoPtr->versionName.c_str());
SaveAppVersionInfo(appVersionInfoCB->appVersionInfo, abilityInfoPtr->appName, appInfoPtr->versionName,
appInfoPtr->versionCode);
} else {
appVersionInfoCB->cbBase.errCode = NAPI_ERR_ABILITY_CALL_INVALID;
}
HILOG_INFO("NAPI_GetAppVersionInfo, worker pool thread execute end.");
}
void GetAppVersionInfoAsyncCompleteCB(napi_env env, napi_status status, void *data)
{
HILOG_INFO("NAPI_GetAppVersionInfo, main event thread complete.");
AppVersionInfoCB *appVersionInfoCB = static_cast<AppVersionInfoCB *>(data);
napi_value callback = nullptr;
napi_value undefined = nullptr;
napi_value result[ARGS_TWO] = {nullptr};
napi_value callResult = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined));
result[PARAM0] = GetCallbackErrorValue(env, appVersionInfoCB->cbBase.errCode);
if (appVersionInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) {
result[PARAM1] = WrapAppVersionInfo(env, *appVersionInfoCB);
} else {
result[PARAM1] = WrapUndefinedToJS(env);
}
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, appVersionInfoCB->cbBase.cbInfo.callback, &callback));
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult));
if (appVersionInfoCB->cbBase.cbInfo.callback != nullptr) {
NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, appVersionInfoCB->cbBase.cbInfo.callback));
}
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, appVersionInfoCB->cbBase.asyncWork));
delete appVersionInfoCB;
appVersionInfoCB = nullptr;
HILOG_INFO("NAPI_GetAppVersionInfo, main event thread complete end.");
}
void GetAppVersionInfoPromiseCompleteCB(napi_env env, napi_status status, void *data)
{
HILOG_INFO("NAPI_GetAppVersionInfo, main event thread complete.");
AppVersionInfoCB *appVersionInfoCB = static_cast<AppVersionInfoCB *>(data);
napi_value result = nullptr;
if (appVersionInfoCB->cbBase.errCode == NAPI_ERR_NO_ERROR) {
result = WrapAppVersionInfo(env, *appVersionInfoCB);
napi_resolve_deferred(env, appVersionInfoCB->cbBase.deferred, result);
} else {
result = GetCallbackErrorValue(env, appVersionInfoCB->cbBase.errCode);
napi_reject_deferred(env, appVersionInfoCB->cbBase.deferred, result);
}
napi_delete_async_work(env, appVersionInfoCB->cbBase.asyncWork);
delete appVersionInfoCB;
appVersionInfoCB = nullptr;
HILOG_INFO("NAPI_GetAppVersionInfo, main event thread complete end.");
}
/**
* @brief GetAppVersionInfo Async.
*
* @param env The environment that the Node-API call is invoked under.
* @param args Indicates the arguments passed into the callback.
* @param argcPromise Asynchronous data processing.
* @param AppVersionInfoCB Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value GetAppVersionInfoAsync(
napi_env env, napi_value *args, const size_t argCallback, AppVersionInfoCB *appVersionInfoCB)
{
HILOG_INFO("%{public}s, asyncCallback.", __func__);
if (args == nullptr || appVersionInfoCB == nullptr) {
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
return nullptr;
}
napi_value resourceName = nullptr;
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
napi_valuetype valuetype = napi_undefined;
NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype));
if (valuetype == napi_function) {
NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &appVersionInfoCB->cbBase.cbInfo.callback));
}
NAPI_CALL(
env, napi_create_async_work(env, nullptr, resourceName, GetAppVersionInfoExecuteCB,
GetAppVersionInfoAsyncCompleteCB, (void *)appVersionInfoCB, &appVersionInfoCB->cbBase.asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, appVersionInfoCB->cbBase.asyncWork));
napi_value result = nullptr;
NAPI_CALL(env, napi_get_null(env, &result));
HILOG_INFO("%{public}s, asyncCallback end.", __func__);
return result;
}
/**
* @brief GetAppVersionInfo Promise.
*
* @param env The environment that the Node-API call is invoked under.
* @param AppVersionInfoCB Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value GetAppVersionInfoPromise(napi_env env, AppVersionInfoCB *appVersionInfoCB)
{
HILOG_INFO("%{public}s, promise.", __func__);
if (appVersionInfoCB == nullptr) {
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
return nullptr;
}
napi_value resourceName = nullptr;
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
napi_deferred deferred;
napi_value promise = nullptr;
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
appVersionInfoCB->cbBase.deferred = deferred;
NAPI_CALL(
env, napi_create_async_work(env, nullptr, resourceName, GetAppVersionInfoExecuteCB,
GetAppVersionInfoPromiseCompleteCB, (void *)appVersionInfoCB, &appVersionInfoCB->cbBase.asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, appVersionInfoCB->cbBase.asyncWork));
HILOG_INFO("%{public}s, promise end.", __func__);
return promise;
}
napi_value GetAppVersionInfoWrap(napi_env env, napi_callback_info info, AppVersionInfoCB *appVersionInfoCB)
{
HILOG_INFO("%{public}s, asyncCallback.", __func__);
if (appVersionInfoCB == nullptr) {
HILOG_ERROR("%{public}s, appVersionInfoCB == nullptr.", __func__);
return nullptr;
}
size_t argcAsync = 1;
const size_t argcPromise = 0;
const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
napi_value args[ARGS_MAX_COUNT] = {nullptr};
napi_value ret = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr));
if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
return nullptr;
}
if (argcAsync > argcPromise) {
ret = GetAppVersionInfoAsync(env, args, 0, appVersionInfoCB);
} else {
ret = GetAppVersionInfoPromise(env, appVersionInfoCB);
}
HILOG_INFO("%{public}s, asyncCallback end.", __func__);
return ret;
}
/**
* @brief Obtains the AppVersionInfo object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetAppVersionInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
HILOG_INFO("%{public}s called.", __func__);
AppVersionInfoCB *appVersionInfoCB = CreateAppVersionInfoCBInfo(env);
if (appVersionInfoCB == nullptr) {
return WrapVoidToJS(env);
}
appVersionInfoCB->cbBase.errCode = NAPI_ERR_NO_ERROR;
appVersionInfoCB->cbBase.abilityType = abilityType;
napi_value ret = GetAppVersionInfoWrap(env, info, appVersionInfoCB);
if (ret == nullptr) {
HILOG_ERROR("%{public}s ret == nullptr", __func__);
if (appVersionInfoCB != nullptr) {
delete appVersionInfoCB;
appVersionInfoCB = nullptr;
}
ret = WrapVoidToJS(env);
}
HILOG_INFO("%{public}s end.", __func__);
return ret;
}
/**
* @brief Create asynchronous data.
*
@@ -43,6 +43,24 @@ napi_value WrapAppInfo(napi_env env, const AppInfo_ &appInfo);
*/
napi_value NAPI_GetFilesDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
/**
* @brief Get OrCreateDistribute Dir.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetOrCreateDistributedDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
napi_value NAPI_GetCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
napi_value NAPI_GetExternalCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
napi_value NAPI_IsUpdatingConfigurationsCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
napi_value NAPI_PrintDrawnCompletedCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
/**
* @brief Obtains the type of this application.
*
@@ -73,6 +91,16 @@ napi_value NAPI_GetAbilityInfoCommon(napi_env env, napi_callback_info info, Abil
*/
napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
/**
* @brief Obtains the AppVersionInfo object of the application.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_GetAppVersionInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
/**
* @brief Create asynchronous data.
*
@@ -1064,6 +1064,36 @@ void CompleteAsyncCallbackWork(napi_env env, napi_status status, void *data)
asyncCallbackInfo = nullptr;
}
void CompleteAsyncVoidCallbackWork(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s called.", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data;
if (asyncCallbackInfo == nullptr) {
HILOG_INFO("%{public}s called, asyncCallbackInfo is null", __func__);
return;
}
napi_value callback = 0;
napi_value undefined = 0;
napi_get_undefined(env, &undefined);
napi_value callResult = 0;
napi_value result[ARGS_TWO] = {nullptr};
result[PARAM0] = GetCallbackErrorValue(env, asyncCallbackInfo->error_code);
if (asyncCallbackInfo->error_code == NAPI_ERR_NO_ERROR) {
result[PARAM1] = WrapVoidToJS(env);
} else {
result[PARAM1] = WrapUndefinedToJS(env);
}
if (asyncCallbackInfo->cbInfo.callback != nullptr) {
napi_get_reference_value(env, asyncCallbackInfo->cbInfo.callback, &callback);
napi_call_function(env, undefined, callback, ARGS_TWO, result, &callResult);
napi_delete_reference(env, asyncCallbackInfo->cbInfo.callback);
}
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
}
/**
* @brief The callback at the end of the Promise callback.
*
@@ -1093,6 +1123,28 @@ void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data)
asyncCallbackInfo = nullptr;
}
void CompletePromiseVoidCallbackWork(napi_env env, napi_status status, void *data)
{
HILOG_INFO("%{public}s called.", __func__);
AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data;
if (asyncCallbackInfo == nullptr) {
HILOG_INFO("%{public}s called, asyncCallbackInfo is null", __func__);
return;
}
napi_value result = 0;
if (asyncCallbackInfo->error_code == NAPI_ERR_NO_ERROR) {
result = WrapVoidToJS(env);
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
} else {
result = GetCallbackErrorValue(env, asyncCallbackInfo->error_code);
napi_reject_deferred(env, asyncCallbackInfo->deferred, result);
}
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
}
std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue)
{
bool isTypedArray = false;
@@ -1117,5 +1169,31 @@ std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue)
return result;
}
std::vector<std::string> ConvertStringVector(napi_env env, napi_value jsValue)
{
bool isTypedArray = false;
napi_status status = napi_is_typedarray(env, jsValue, &isTypedArray);
if (status != napi_ok || !isTypedArray) {
HILOG_INFO("%{public}s called, napi_is_typedarray error", __func__);
return {};
}
napi_typedarray_type type;
size_t length = 0;
napi_value buffer = nullptr;
size_t offset = 0;
NAPI_CALL_BASE(env, napi_get_typedarray_info(env, jsValue, &type, &length, nullptr, &buffer, &offset), {});
if (type != napi_uint8_array) {
HILOG_ERROR("%{public}s called, napi_uint8_array is null", __func__);
return {};
}
std::string *data = nullptr;
size_t total = 0;
NAPI_CALL_BASE(env, napi_get_arraybuffer_info(env, buffer, reinterpret_cast<void **>(&data), &total), {});
length = std::min<size_t>(length, total - offset);
std::vector<std::string> result(sizeof(std::string) + length);
memcpy_s(result.data(), result.size(), &data[offset], length);
return result;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -228,6 +228,14 @@ napi_value ExecutePromiseCallbackWork(napi_env env, AsyncJSCallbackInfo *asyncCa
*/
void CompleteAsyncCallbackWork(napi_env env, napi_status status, void *data);
/**
* @brief The callback at the end of the asynchronous callback.
*
* @param env The environment that the Node-API call is invoked under.
* @param data Point to asynchronous processing of data.
*/
void CompleteAsyncVoidCallbackWork(napi_env env, napi_status status, void *data);
/**
* @brief The callback at the end of the Promise callback.
*
@@ -236,8 +244,18 @@ void CompleteAsyncCallbackWork(napi_env env, napi_status status, void *data);
*/
void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data);
/**
* @brief The callback at the end of the Promise callback.
*
* @param env The environment that the Node-API call is invoked under.
* @param data Point to asynchronous processing of data.
*/
void CompletePromiseVoidCallbackWork(napi_env env, napi_status status, void *data);
std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue);
std::vector<std::string> ConvertStringVector(napi_env env, napi_value jsValue);
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_APPEXECFWK_NAPI_COMMON_UTIL_H
@@ -27,6 +27,8 @@ ohos_shared_library("particleability") {
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include",
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include",
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/include",
"//third_party/jsoncpp",
"//third_party/jsoncpp/include/json",
]
sources = [
@@ -48,6 +50,7 @@ ohos_shared_library("particleability") {
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
"//foundation/ace/napi:ace_napi",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//third_party/jsoncpp:jsoncpp",
"//third_party/libuv:uv_static",
"//utils/native/base:utils",
]
+2
View File
@@ -64,6 +64,7 @@ config("abilityms_config") {
"//base/account/os_account/frameworks/common/log/include",
"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
"//base/hiviewdfx/hicollie/interfaces/native/innerkits/include",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
]
cflags = []
if (target_cpu == "arm") {
@@ -84,6 +85,7 @@ ohos_shared_library("abilityms") {
"//base/account/os_account/frameworks/osaccount/native:os_account_innerkits",
"//base/global/i18n_standard/frameworks/intl:intl_util",
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
@@ -529,7 +529,9 @@ public:
* @param SystemMemoryAttr, memory information.
*/
virtual void GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo) override;
virtual int GetAppMemorySize() override;
virtual bool IsRamConstrainedDevice() override;
virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override;
@@ -686,7 +686,9 @@ public:
* @param SystemMemoryAttr, memory information.
*/
virtual void GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo) override;
virtual int GetAppMemorySize() override;
virtual bool IsRamConstrainedDevice() override;
/**
* Start Ability, connect session with common ability.
*
@@ -123,6 +123,8 @@ private:
int SetShowOnLockScreenInner(MessageParcel &data, MessageParcel &reply);
int GetSystemMemoryAttrInner(MessageParcel &data, MessageParcel &reply);
int GetAppMemorySizeInner(MessageParcel &data, MessageParcel &reply);
int IsRamConstrainedDeviceInner(MessageParcel &data, MessageParcel &reply);
int ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply);
int ContinueMissionInner(MessageParcel &data, MessageParcel &reply);
@@ -1638,6 +1638,40 @@ void AbilityManagerProxy::GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memo
memoryInfo = *remoteRetsult;
}
int AbilityManagerProxy::GetAppMemorySize()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("WriteInterfaceToken faild");
return INNER_ERR;
}
auto error = Remote()->SendRequest(IAbilityManager::GET_APP_MEMORY_SIZE, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
bool AbilityManagerProxy::IsRamConstrainedDevice()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("WriteInterfaceToken faild");
return false;
}
auto error = Remote()->SendRequest(IAbilityManager::IS_RAM_CONSTRAINED_DEVICE, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return false;
}
return reply.ReadBool();
}
int AbilityManagerProxy::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams)
{
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <csignal>
#include <cstdlib>
#include "ability_info.h"
#include "ability_manager_errors.h"
@@ -52,6 +53,7 @@
#include "ui_service_mgr_client.h"
#include "uri_permission_manager_client.h"
#include "xcollie/watchdog.h"
#include "parameter.h"
using OHOS::AppExecFwk::ElementName;
using OHOS::Security::AccessToken::AccessTokenKit;
@@ -70,6 +72,13 @@ constexpr uint32_t SCENE_FLAG_NORMAL = 0;
const int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20;
const int32_t MAX_NUMBER_OF_CONNECT_BMS = 15;
const std::string EMPTY_DEVICE_ID = "";
const int32_t APP_MEMORY_SIZE = 512;
const int32_t GET_PARAMETER_INCORRECT = -9;
const int32_t GET_PARAMETER_OTHER = -1;
const int32_t SIZE_10 = -1;
const bool isRamConstrainedDevice = false;
const std::string APP_MEMORY_MAX_SIZE_PARAMETER = "const.product.dalvikheaplimit";
const std::string RAM_CONSTRAINED_DEVICE_SIGN = "const.product.islowram";
const std::string PKG_NAME = "ohos.distributedhardware.devicemanager";
const std::string ACTION_CHOOSE = "ohos.want.action.select";
const std::string PERMISSION_SET_ABILITY_CONTROLLER = "ohos.permission.SET_ABILITY_CONTROLLER";
@@ -3409,6 +3418,53 @@ void AbilityManagerService::GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &me
appScheduler->GetSystemMemoryAttr(memoryInfo, memConfig);
}
int AbilityManagerService::GetAppMemorySize()
{
HILOG_INFO("service GetAppMemorySize start");
const char *key = "const.product.dalvikheaplimit";
const char *def = "512m";
char *valueGet = nullptr;
unsigned int len = 128;
int ret = GetParameter(key, def, valueGet, len);
if ((ret != GET_PARAMETER_OTHER) && (ret != GET_PARAMETER_INCORRECT)) {
int *size = 0;
int len = strlen(valueGet);
int index = 0;
for (int i = 0; i < len; i++) {
while (!(valueGet[i] > '0' && valueGet[i] < '9')) {
i++;
}
while (valueGet[i] >= '0' && valueGet[i] < '9') {
int t = valueGet[i] - '0';
size[index] = size[index] * SIZE_10 + t;
i++;
}
index++;
}
return *size;
}
return APP_MEMORY_SIZE;
}
bool AbilityManagerService::IsRamConstrainedDevice()
{
HILOG_INFO("service IsRamConstrainedDevice start");
const char *key = "const.product.islowram";
const char *def = "0";
char *valueGet = nullptr;
unsigned int len = 128;
int ret = GetParameter(key, def, valueGet, len);
if ((ret != GET_PARAMETER_OTHER) && (ret != GET_PARAMETER_INCORRECT)) {
int value = atoi(valueGet);
if (value) {
return true;
} else {
return isRamConstrainedDevice;
}
}
return isRamConstrainedDevice;
}
int AbilityManagerService::GetMissionSaveTime() const
{
if (!amsConfigResolver_) {
@@ -116,6 +116,8 @@ void AbilityManagerStub::SecondStepInit()
requestFuncMap_[UPDATE_CONFIGURATION] = &AbilityManagerStub::UpdateConfigurationInner;
requestFuncMap_[SET_SHOW_ON_LOCK_SCREEN] = &AbilityManagerStub::SetShowOnLockScreenInner;
requestFuncMap_[GET_SYSTEM_MEMORY_ATTR] = &AbilityManagerStub::GetSystemMemoryAttrInner;
requestFuncMap_[GET_APP_MEMORY_SIZE] = &AbilityManagerStub::GetAppMemorySizeInner;
requestFuncMap_[IS_RAM_CONSTRAINED_DEVICE] = &AbilityManagerStub::IsRamConstrainedDeviceInner;
requestFuncMap_[CLEAR_UP_APPLICATION_DATA] = &AbilityManagerStub::ClearUpApplicationDataInner;
requestFuncMap_[LOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::LockMissionForCleanupInner;
requestFuncMap_[UNLOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::UnlockMissionForCleanupInner;
@@ -970,6 +972,27 @@ int AbilityManagerStub::GetSystemMemoryAttrInner(MessageParcel &data, MessagePar
return NO_ERROR;
}
int AbilityManagerStub::GetAppMemorySizeInner(MessageParcel &data, MessageParcel &reply)
{
int32_t result = GetAppMemorySize();
HILOG_INFO("GetAppMemorySizeInner result %{public}d", result);
if (!reply.WriteInt32(result)) {
HILOG_ERROR("GetAppMemorySize error");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
int AbilityManagerStub::IsRamConstrainedDeviceInner(MessageParcel &data, MessageParcel &reply)
{
auto result = IsRamConstrainedDevice();
if (!reply.WriteBool(result)) {
HILOG_ERROR("reply write failed.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel &reply)
{
std::string srcDeviceId = data.ReadString();
@@ -27,6 +27,7 @@ ohos_moduletest("AbilityRecordModuleTest") {
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/distributed_ability_runtime",
"//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager/include",
"//base/hiviewdfx/hicollie/interfaces/native/innerkits/include/xcollie",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
]
sources = [
@@ -94,6 +95,7 @@ ohos_moduletest("AbilityRecordModuleTest") {
"${services_path}/common:perm_verification",
"//base/account/os_account/frameworks/osaccount/native:os_account_innerkits",
"//base/global/i18n_standard/frameworks/intl:intl_util",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
"//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager",