mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
@@ -175,57 +175,13 @@ void Ability::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
HILOG_INFO("AbilityName is %{public}s.", abilityInfo_->name.c_str());
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
int32_t defualtDisplayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
int32_t displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId);
|
||||
int32_t defualtDisplayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
int32_t displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId);
|
||||
HILOG_DEBUG("abilityName:%{public}s, displayId:%{public}d", abilityInfo_->name.c_str(), displayId);
|
||||
if (!abilityInfo_->isStageBasedModel) {
|
||||
auto option = GetWindowOption(want);
|
||||
InitWindow(displayId, option);
|
||||
}
|
||||
InitFAWindow(want, displayId);
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
HILOG_DEBUG("Get window from abilityWindow.");
|
||||
auto window = abilityWindow_->GetWindow();
|
||||
if (window) {
|
||||
HILOG_DEBUG("Call RegisterDisplayMoveListener, windowId: %{public}d", window->GetWindowId());
|
||||
abilityDisplayMoveListener_ = new AbilityDisplayMoveListener(weak_from_this());
|
||||
window->RegisterDisplayMoveListener(abilityDisplayMoveListener_);
|
||||
}
|
||||
}
|
||||
|
||||
// Update resMgr, Configuration
|
||||
HILOG_DEBUG("Get display by displayId %{public}d.", displayId);
|
||||
auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId);
|
||||
if (display) {
|
||||
float density = display->GetVirtualPixelRatio();
|
||||
int32_t width = display->GetWidth();
|
||||
int32_t height = display->GetHeight();
|
||||
std::shared_ptr<Configuration> configuration = nullptr;
|
||||
if (application_) {
|
||||
configuration = application_->GetConfiguration();
|
||||
}
|
||||
if (configuration) {
|
||||
std::string direction = GetDirectionStr(height, width);
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, direction);
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId));
|
||||
UpdateContextConfiguration();
|
||||
}
|
||||
|
||||
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
|
||||
if (resConfig == nullptr) {
|
||||
HILOG_ERROR("Create resource config failed.");
|
||||
return;
|
||||
}
|
||||
auto resourceManager = GetResourceManager();
|
||||
if (resourceManager != nullptr) {
|
||||
resourceManager->GetResConfig(*resConfig);
|
||||
resConfig->SetScreenDensity(density);
|
||||
resConfig->SetDirection(ConvertDirection(height, width));
|
||||
resourceManager->UpdateResConfig(*resConfig);
|
||||
HILOG_DEBUG("Notify ResourceManager, Density: %{public}f, Direction: %{public}d.",
|
||||
resConfig->GetScreenDensity(), resConfig->GetDirection());
|
||||
}
|
||||
if (!UpdateResMgrAndConfiguration(displayId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1123,8 +1079,7 @@ void Ability::ExecuteOperation(std::shared_ptr<DataAbilityOperation> &operation,
|
||||
return;
|
||||
}
|
||||
if (index < 0) {
|
||||
HILOG_ERROR(
|
||||
"exec operation result index should not below zero, current index: %{public}d", index);
|
||||
HILOG_ERROR("exec operation result index should not below zero, current index: %{public}d", index);
|
||||
return;
|
||||
}
|
||||
if (operation == nullptr) {
|
||||
@@ -1135,8 +1090,7 @@ void Ability::ExecuteOperation(std::shared_ptr<DataAbilityOperation> &operation,
|
||||
|
||||
int numRows = 0;
|
||||
std::shared_ptr<NativeRdb::ValuesBucket> valuesBucket = ParseValuesBucketReference(results, operation, index);
|
||||
std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates =
|
||||
ParsePredictionArgsReference(results, operation, index);
|
||||
auto predicates = ParsePredictionArgsReference(results, operation, index);
|
||||
if (operation->IsInsertOperation()) {
|
||||
HILOG_DEBUG("exec IsInsertOperation");
|
||||
numRows = Insert(*(operation->GetUri().get()), *valuesBucket);
|
||||
@@ -1149,34 +1103,18 @@ void Ability::ExecuteOperation(std::shared_ptr<DataAbilityOperation> &operation,
|
||||
} else if (operation->IsAssertOperation() && predicates) {
|
||||
HILOG_DEBUG("exec IsAssertOperation");
|
||||
std::vector<std::string> columns;
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> queryResult =
|
||||
Query(*(operation->GetUri().get()), columns, *predicates);
|
||||
auto queryResult = Query(*(operation->GetUri().get()), columns, *predicates);
|
||||
if (queryResult == nullptr) {
|
||||
HILOG_ERROR("exec Query retval is nullptr");
|
||||
results.push_back(std::make_shared<DataAbilityResult>(0));
|
||||
return;
|
||||
}
|
||||
if (queryResult->GetRowCount(numRows) != 0) {
|
||||
HILOG_ERROR("exec queryResult->GetRowCount(numRows) != E_OK");
|
||||
}
|
||||
if (!CheckAssertQueryResult(queryResult, operation->GetValuesBucket())) {
|
||||
if (queryResult != nullptr) {
|
||||
queryResult->Close();
|
||||
}
|
||||
HILOG_ERROR("Query Result is not equal to expected value.");
|
||||
}
|
||||
|
||||
if (queryResult != nullptr) {
|
||||
queryResult->Close();
|
||||
}
|
||||
(void)CheckAssertQueryResult(queryResult, operation->GetValuesBucket());
|
||||
queryResult->Close();
|
||||
} else {
|
||||
HILOG_ERROR("exec Expected bad type %{public}d", operation->GetType());
|
||||
}
|
||||
if (operation->GetExpectedCount() != numRows) {
|
||||
HILOG_ERROR("exec Expected %{public}d rows but actual %{public}d",
|
||||
operation->GetExpectedCount(),
|
||||
numRows);
|
||||
} else {
|
||||
if (operation->GetExpectedCount() == numRows) {
|
||||
if (operation->GetUri() != nullptr) {
|
||||
results.push_back(std::make_shared<DataAbilityResult>(*operation->GetUri(), numRows));
|
||||
} else {
|
||||
@@ -1238,21 +1176,17 @@ std::shared_ptr<NativeRdb::ValuesBucket> Ability::ParseValuesBucketReference(
|
||||
std::vector<std::shared_ptr<DataAbilityResult>> &results, std::shared_ptr<DataAbilityOperation> &operation,
|
||||
int numRefs)
|
||||
{
|
||||
NativeRdb::ValuesBucket retValueBucket;
|
||||
if (operation == nullptr) {
|
||||
HILOG_ERROR("intput is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (operation->GetValuesBucketReferences() == nullptr) {
|
||||
return operation->GetValuesBucket();
|
||||
}
|
||||
|
||||
NativeRdb::ValuesBucket retValueBucket;
|
||||
retValueBucket.Clear();
|
||||
if (operation->GetValuesBucket() == nullptr) {
|
||||
HILOG_DEBUG("operation->GetValuesBucket is nullptr");
|
||||
} else {
|
||||
HILOG_DEBUG("operation->GetValuesBucket is nullptr");
|
||||
if (operation->GetValuesBucket() != nullptr) {
|
||||
retValueBucket = *operation->GetValuesBucket();
|
||||
}
|
||||
|
||||
@@ -1261,80 +1195,99 @@ std::shared_ptr<NativeRdb::ValuesBucket> Ability::ParseValuesBucketReference(
|
||||
|
||||
for (auto itermap : valuesMapReferences) {
|
||||
std::string key = itermap.first;
|
||||
HILOG_DEBUG("key is %{public}s", key.c_str());
|
||||
NativeRdb::ValueObject obj;
|
||||
if (!operation->GetValuesBucketReferences()->GetObject(key, obj)) {
|
||||
HILOG_ERROR("operation->GetValuesBucketReferences()->GetObject error");
|
||||
continue;
|
||||
}
|
||||
switch (obj.GetType()) {
|
||||
case NativeRdb::ValueObjectType::TYPE_INT: {
|
||||
int val = 0;
|
||||
if (obj.GetInt(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetInt() error");
|
||||
break;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutInt(%{public}s, %{public}d)",
|
||||
key.c_str(),
|
||||
val);
|
||||
retValueBucket.PutInt(key, val);
|
||||
} break;
|
||||
case NativeRdb::ValueObjectType::TYPE_DOUBLE: {
|
||||
double val = 0.0;
|
||||
if (obj.GetDouble(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetDouble() error");
|
||||
break;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutDouble(%{public}s, %{public}f)",
|
||||
key.c_str(),
|
||||
val);
|
||||
retValueBucket.PutDouble(key, val);
|
||||
} break;
|
||||
case NativeRdb::ValueObjectType::TYPE_STRING: {
|
||||
std::string val = "";
|
||||
if (obj.GetString(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetString() error");
|
||||
break;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutString(%{public}s, %{public}s)",
|
||||
key.c_str(),
|
||||
val.c_str());
|
||||
retValueBucket.PutString(key, val);
|
||||
} break;
|
||||
case NativeRdb::ValueObjectType::TYPE_BLOB: {
|
||||
std::vector<uint8_t> val;
|
||||
if (obj.GetBlob(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetBlob() error");
|
||||
break;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutBlob(%{public}s, %{public}zu)",
|
||||
key.c_str(),
|
||||
val.size());
|
||||
retValueBucket.PutBlob(key, val);
|
||||
} break;
|
||||
case NativeRdb::ValueObjectType::TYPE_BOOL: {
|
||||
bool val = false;
|
||||
if (obj.GetBool(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetBool() error");
|
||||
break;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutBool(%{public}s, %{public}s)",
|
||||
key.c_str(),
|
||||
val ? "true" : "false");
|
||||
retValueBucket.PutBool(key, val);
|
||||
} break;
|
||||
default: {
|
||||
HILOG_DEBUG("retValueBucket->PutNull(%{public}s)", key.c_str());
|
||||
case NativeRdb::ValueObjectType::TYPE_INT:
|
||||
ParseIntValue(obj, key, retValueBucket);
|
||||
break;
|
||||
case NativeRdb::ValueObjectType::TYPE_DOUBLE:
|
||||
ParseDoubleValue(obj, key, retValueBucket);
|
||||
break;
|
||||
case NativeRdb::ValueObjectType::TYPE_STRING:
|
||||
ParseStringValue(obj, key, retValueBucket);
|
||||
break;
|
||||
case NativeRdb::ValueObjectType::TYPE_BLOB:
|
||||
ParseBlobValue(obj, key, retValueBucket);
|
||||
break;
|
||||
case NativeRdb::ValueObjectType::TYPE_BOOL:
|
||||
ParseBoolValue(obj, key, retValueBucket);
|
||||
break;
|
||||
default:
|
||||
retValueBucket.PutNull(key);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, NativeRdb::ValueObject> valuesMap;
|
||||
retValueBucket.GetAll(valuesMap);
|
||||
|
||||
return std::make_shared<NativeRdb::ValuesBucket>(valuesMap);
|
||||
}
|
||||
|
||||
void Ability::ParseIntValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const
|
||||
{
|
||||
int val = 0;
|
||||
if (obj.GetInt(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetInt() error");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutInt(%{public}s, %{public}d)", key.c_str(), val);
|
||||
retValueBucket.PutInt(key, val);
|
||||
}
|
||||
|
||||
void Ability::ParseDoubleValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const
|
||||
{
|
||||
double val = 0.0;
|
||||
if (obj.GetDouble(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetDouble() error");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutDouble(%{public}s, %{public}f)", key.c_str(), val);
|
||||
retValueBucket.PutDouble(key, val);
|
||||
}
|
||||
|
||||
void Ability::ParseStringValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const
|
||||
{
|
||||
std::string val = "";
|
||||
if (obj.GetString(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetString() error");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutString(%{public}s, %{public}s)", key.c_str(), val.c_str());
|
||||
retValueBucket.PutString(key, val);
|
||||
}
|
||||
|
||||
void Ability::ParseBlobValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const
|
||||
{
|
||||
std::vector<uint8_t> val;
|
||||
if (obj.GetBlob(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetBlob() error");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutBlob(%{public}s, %{public}zu)", key.c_str(), val.size());
|
||||
retValueBucket.PutBlob(key, val);
|
||||
}
|
||||
|
||||
void Ability::ParseBoolValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const
|
||||
{
|
||||
bool val = false;
|
||||
if (obj.GetBool(val) != 0) {
|
||||
HILOG_ERROR("ValueObject->GetBool() error");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("retValueBucket->PutBool(%{public}s, %{public}s)", key.c_str(), val ? "true" : "false");
|
||||
retValueBucket.PutBool(key, val);
|
||||
}
|
||||
|
||||
int Ability::ChangeRef2Value(std::vector<std::shared_ptr<DataAbilityResult>> &results, int numRefs, int index)
|
||||
{
|
||||
int retval = -1;
|
||||
@@ -2132,7 +2085,64 @@ void Ability::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
|
||||
HILOG_ERROR("Ability window is nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityWindow_->SetSessionToken(sessionToken_);
|
||||
abilityWindow_->SetSessionToken(sessionToken);
|
||||
}
|
||||
|
||||
void Ability::InitFAWindow(const Want &want, int32_t displayId)
|
||||
{
|
||||
if (!abilityInfo_->isStageBasedModel) {
|
||||
auto option = GetWindowOption(want);
|
||||
InitWindow(displayId, option);
|
||||
}
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
HILOG_DEBUG("Get window from abilityWindow.");
|
||||
auto window = abilityWindow_->GetWindow();
|
||||
if (window) {
|
||||
HILOG_DEBUG("Call RegisterDisplayMoveListener, windowId: %{public}d", window->GetWindowId());
|
||||
abilityDisplayMoveListener_ = new AbilityDisplayMoveListener(weak_from_this());
|
||||
window->RegisterDisplayMoveListener(abilityDisplayMoveListener_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Ability::UpdateResMgrAndConfiguration(int32_t displayId)
|
||||
{
|
||||
auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId);
|
||||
if (!display) {
|
||||
HILOG_INFO("The display is invliad.");
|
||||
return true;
|
||||
}
|
||||
float density = display->GetVirtualPixelRatio();
|
||||
int32_t width = display->GetWidth();
|
||||
int32_t height = display->GetHeight();
|
||||
std::shared_ptr<Configuration> configuration = nullptr;
|
||||
if (application_) {
|
||||
configuration = application_->GetConfiguration();
|
||||
}
|
||||
if (configuration) {
|
||||
std::string direction = GetDirectionStr(height, width);
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, direction);
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId));
|
||||
UpdateContextConfiguration();
|
||||
}
|
||||
|
||||
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
|
||||
if (resConfig == nullptr) {
|
||||
HILOG_ERROR("Create resource config failed.");
|
||||
return false;
|
||||
}
|
||||
auto resourceManager = GetResourceManager();
|
||||
if (resourceManager != nullptr) {
|
||||
resourceManager->GetResConfig(*resConfig);
|
||||
resConfig->SetScreenDensity(density);
|
||||
resConfig->SetDirection(ConvertDirection(height, width));
|
||||
resourceManager->UpdateResConfig(*resConfig);
|
||||
HILOG_DEBUG("Notify ResourceManager, Density: %{public}f, Direction: %{public}d.",
|
||||
resConfig->GetScreenDensity(), resConfig->GetDirection());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -122,6 +122,33 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
HILOG_ERROR("abilityInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
auto srcPath = GenerateSrcPath(abilityInfo);
|
||||
if (srcPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string moduleName(abilityInfo->moduleName);
|
||||
moduleName.append("::").append(abilityInfo->name);
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
|
||||
jsAbilityObj_ = jsRuntime_.LoadModule(
|
||||
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
if (jsAbilityObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get AbilityStage object");
|
||||
return;
|
||||
}
|
||||
|
||||
BindContext();
|
||||
}
|
||||
|
||||
std::string JsAbility::GenerateSrcPath(std::shared_ptr<AbilityInfo> abilityInfo) const
|
||||
{
|
||||
if (abilityInfo == nullptr) {
|
||||
HILOG_ERROR("abilityInfo is nullptr");
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string srcPath(abilityInfo->package);
|
||||
if (!abilityInfo->isModuleJson) {
|
||||
/* temporary compatibility api8 + config.json */
|
||||
@@ -133,7 +160,7 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
} else {
|
||||
if (abilityInfo->srcEntrance.empty()) {
|
||||
HILOG_ERROR("abilityInfo srcEntrance is empty");
|
||||
return;
|
||||
return "";
|
||||
}
|
||||
srcPath.append("/");
|
||||
srcPath.append(abilityInfo->srcEntrance);
|
||||
@@ -141,20 +168,12 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
srcPath.append(".abc");
|
||||
HILOG_INFO("JsAbility srcPath is %{public}s", srcPath.c_str());
|
||||
}
|
||||
return srcPath;
|
||||
}
|
||||
|
||||
std::string moduleName(abilityInfo->moduleName);
|
||||
moduleName.append("::").append(abilityInfo->name);
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
void JsAbility::BindContext()
|
||||
{
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
|
||||
jsAbilityObj_ = jsRuntime_.LoadModule(
|
||||
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
if (jsAbilityObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get AbilityStage object");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value obj = jsAbilityObj_->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, obj, napi_object)) {
|
||||
HILOG_ERROR("Failed to check type");
|
||||
@@ -612,40 +631,9 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (scene_ == nullptr) {
|
||||
if ((abilityContext_ == nullptr) || (sceneListener_ == nullptr)) {
|
||||
HILOG_ERROR("Ability::OnForeground error. abilityContext_ or sceneListener_ is nullptr!");
|
||||
if (!InitWindowScene(want)) {
|
||||
return;
|
||||
}
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
int32_t displayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
if (setting_ != nullptr) {
|
||||
std::string strDisplayId =
|
||||
setting_->GetProperty(OHOS::AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY);
|
||||
std::regex formatRegex("[0-9]{0,9}$");
|
||||
std::smatch sm;
|
||||
bool flag = std::regex_match(strDisplayId, sm, formatRegex);
|
||||
if (flag && !strDisplayId.empty()) {
|
||||
int base = 10; // Numerical base (radix) that determines the valid characters and their interpretation.
|
||||
displayId = strtol(strDisplayId.c_str(), nullptr, base);
|
||||
HILOG_DEBUG("%{public}s success. displayId is %{public}d", __func__, displayId);
|
||||
} else {
|
||||
HILOG_WARN("%{public}s failed to formatRegex:[%{public}s]", __func__, strDisplayId.c_str());
|
||||
}
|
||||
}
|
||||
auto option = GetWindowOption(want);
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) {
|
||||
abilityContext_->SetWeakSessionToken(sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken);
|
||||
} else {
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
}
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("%{public}s error. failed to init window scene!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityContinuationOrRecover(want);
|
||||
auto window = scene_->GetMainWindow();
|
||||
if (window) {
|
||||
@@ -674,6 +662,48 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
HILOG_DEBUG("%{public}s end scene_->GoForeground.", __func__);
|
||||
}
|
||||
|
||||
bool JsAbility::InitWindowScene(const Want &want)
|
||||
{
|
||||
if ((abilityContext_ == nullptr) || (sceneListener_ == nullptr)) {
|
||||
HILOG_ERROR("abilityContext_ or sceneListener_ is nullptr!");
|
||||
return false;
|
||||
}
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
int32_t displayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
if (setting_ != nullptr) {
|
||||
std::string strDisplayId =
|
||||
setting_->GetProperty(OHOS::AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY);
|
||||
std::regex formatRegex("[0-9]{0,9}$");
|
||||
std::smatch sm;
|
||||
bool flag = std::regex_match(strDisplayId, sm, formatRegex);
|
||||
if (flag && !strDisplayId.empty()) {
|
||||
int base = 10; // Numerical base (radix) that determines the valid characters and their interpretation.
|
||||
displayId = strtol(strDisplayId.c_str(), nullptr, base);
|
||||
HILOG_DEBUG("The displayId is %{public}d", displayId);
|
||||
} else {
|
||||
HILOG_WARN("Failed to formatRegex:[%{public}s]", strDisplayId.c_str());
|
||||
}
|
||||
}
|
||||
auto option = GetWindowOption(want);
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (sessionToken == nullptr) {
|
||||
HILOG_ERROR("The sessionToken is nullptr!");
|
||||
return false;
|
||||
}
|
||||
abilityContext_->SetWeakSessionToken(sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken);
|
||||
} else {
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
}
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("Failed to init window scene!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsAbility::RequestFocus(const Want &want)
|
||||
{
|
||||
HILOG_INFO("Lifecycle: begin.");
|
||||
@@ -1054,37 +1084,44 @@ void JsAbility::Dump(const std::vector<std::string> ¶ms, std::vector<std::st
|
||||
Ability::Dump(params, info);
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
// create js array object of params
|
||||
napi_value argv[] = { CreateNativeArray(env, params) };
|
||||
|
||||
if (!jsAbilityObj_) {
|
||||
HILOG_WARN("Not found .js");
|
||||
return;
|
||||
}
|
||||
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
napi_value obj = jsAbilityObj_->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, obj, napi_object)) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AddDumpInfo(env, obj, params, info, "dump")) {
|
||||
return;
|
||||
}
|
||||
if (!AddDumpInfo(env, obj, params, info, "onDump")) {
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("Dump info size: %{public}zu", info.size());
|
||||
}
|
||||
|
||||
bool JsAbility::AddDumpInfo(napi_env env, napi_value obj, const std::vector<std::string> ¶ms,
|
||||
std::vector<std::string> &info, const std::string &methodName) const
|
||||
{
|
||||
// create js array object of params
|
||||
napi_value argv[] = { CreateNativeArray(env, params) };
|
||||
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env, obj, "dump", &method);
|
||||
napi_value onDumpMethod = nullptr;
|
||||
napi_get_named_property(env, obj, "onDump", &onDumpMethod);
|
||||
napi_get_named_property(env, obj, methodName.c_str(), &method);
|
||||
|
||||
napi_value dumpInfo = nullptr;
|
||||
if (method != nullptr) {
|
||||
napi_call_function(env, obj, method, 1, argv, &dumpInfo);
|
||||
}
|
||||
|
||||
napi_value onDumpInfo = nullptr;
|
||||
if (onDumpMethod != nullptr) {
|
||||
napi_call_function(env, obj, onDumpMethod, 1, argv, &onDumpInfo);
|
||||
}
|
||||
|
||||
if (dumpInfo != nullptr) {
|
||||
if (dumpInfo == nullptr) {
|
||||
uint32_t len = 0;
|
||||
napi_get_array_length(env, dumpInfo, &len);
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
@@ -1093,28 +1130,12 @@ void JsAbility::Dump(const std::vector<std::string> ¶ms, std::vector<std::st
|
||||
napi_get_element(env, dumpInfo, i, &element);
|
||||
if (!ConvertFromJsValue(env, element, dumpInfoStr)) {
|
||||
HILOG_ERROR("Parse dumpInfoStr failed");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
info.push_back(dumpInfoStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (onDumpInfo != nullptr) {
|
||||
uint32_t len = 0;
|
||||
napi_get_array_length(env, onDumpInfo, &len);
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
std::string dumpInfoStr;
|
||||
napi_value element = nullptr;
|
||||
napi_get_element(env, onDumpInfo, i, &element);
|
||||
if (!ConvertFromJsValue(env, element, dumpInfoStr)) {
|
||||
HILOG_ERROR("Parse dumpInfoStr from onDumpInfoNative failed");
|
||||
return;
|
||||
}
|
||||
info.push_back(dumpInfoStr);
|
||||
}
|
||||
}
|
||||
|
||||
HILOG_DEBUG("Dump info size: %{public}zu", info.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> JsAbility::GetJsAbility()
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
class AbsSharedResultSet;
|
||||
class DataAbilityPredicates;
|
||||
class ValueObject;
|
||||
class ValuesBucket;
|
||||
} // namespace NativeRdb
|
||||
namespace AbilityRuntime {
|
||||
@@ -1318,6 +1319,17 @@ private:
|
||||
void InitConfigurationProperties(const Configuration& changeConfiguration, std::string& language,
|
||||
std::string& colormode, std::string& hasPointerDevice);
|
||||
|
||||
void ParseIntValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const;
|
||||
void ParseDoubleValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const;
|
||||
void ParseStringValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const;
|
||||
void ParseBlobValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const;
|
||||
void ParseBoolValue(const NativeRdb::ValueObject &obj, const std::string &key,
|
||||
NativeRdb::ValuesBucket &retValueBucket) const;
|
||||
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler_ = nullptr;
|
||||
std::shared_ptr<ContinuationManager> continuationManager_ = nullptr;
|
||||
std::shared_ptr<ContinuationRegisterManager> continuationRegisterManager_ = nullptr;
|
||||
@@ -1349,6 +1361,9 @@ private:
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
private:
|
||||
void InitFAWindow(const Want &want, int32_t displayId);
|
||||
bool UpdateResMgrAndConfiguration(int32_t displayId);
|
||||
|
||||
std::shared_ptr<AbilityWindow> abilityWindow_ = nullptr;
|
||||
bool bWindowFocus_ = false;
|
||||
bool showOnLockScreen_ = false;
|
||||
|
||||
@@ -107,6 +107,11 @@ private:
|
||||
sptr<IRemoteObject> SetNewRuleFlagToCallee(napi_env env, napi_value remoteJsObj);
|
||||
void AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
void AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
std::string GenerateSrcPath(std::shared_ptr<AbilityInfo> abilityInfo) const;
|
||||
void BindContext();
|
||||
bool InitWindowScene(const Want &want);
|
||||
bool AddDumpInfo(napi_env env, napi_value obj, const std::vector<std::string> ¶ms,
|
||||
std::vector<std::string> &info, const std::string &methodName) const;
|
||||
|
||||
JsRuntime &jsRuntime_;
|
||||
std::shared_ptr<NativeReference> shellContextRef_;
|
||||
|
||||
@@ -409,7 +409,7 @@ void AbilityManagerStub::FourthStepInit()
|
||||
|
||||
int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
HILOG_INFO("Received code : %{public}d", code);
|
||||
HILOG_DEBUG("Received code : %{public}d", code);
|
||||
std::u16string abilityDescriptor = AbilityManagerStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (abilityDescriptor != remoteDescriptor && extensionDescriptor != remoteDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user