mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
IssueNo: SR000GP4TG SR000GP4TE SR000GP4TG SR000GP4TI
Description: 1. Notify total configuration, even one config didn't change. 2. direction and densitydpi distinguish by displayId. 3. because serviceextension use ServiceExtAbilityContext(inherit from ExtAbilityContext), not ExtensionContext, need modify ext_ability_context.js. 4. delete unnecessary interpretation. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com> Change-Id: I1a29270f2aabad6396fa361d3a3058a46e1755e9
This commit is contained in:
@@ -241,8 +241,9 @@ void Ability::OnStart(const Want &want)
|
||||
int32_t width = display->GetWidth();
|
||||
int32_t height = display->GetHeight();
|
||||
auto configuration = application_->GetConfiguration();
|
||||
configuration->AddItem(ConfigurationInner::APPLICATION_DIRECTION, GetDirectionStr(height, width));
|
||||
configuration->AddItem(ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION,
|
||||
GetDirectionStr(height, width));
|
||||
configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId));
|
||||
UpdateContextConfiguration();
|
||||
|
||||
@@ -3465,8 +3466,8 @@ void Ability::OnChange(Rosen::DisplayId displayId, Rosen::DisplayChangeEvent cha
|
||||
|
||||
// Notify ability
|
||||
Configuration newConfig;
|
||||
newConfig.AddItem(ConfigurationInner::APPLICATION_DIRECTION, GetDirectionStr(height, width));
|
||||
newConfig.AddItem(ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
newConfig.AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, GetDirectionStr(height, width));
|
||||
newConfig.AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density));
|
||||
|
||||
std::vector<std::string> changeKeyV;
|
||||
auto configuration = application_->GetConfiguration();
|
||||
|
||||
@@ -305,9 +305,10 @@ void JsAbility::OnConfigurationUpdated(const Configuration &configuration)
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
JsAbilityContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, GetAbilityContext()->GetConfiguration());
|
||||
auto fullConfig = GetAbilityContext()->GetConfiguration();
|
||||
JsAbilityContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, fullConfig);
|
||||
napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(
|
||||
reinterpret_cast<napi_env>(&nativeEngine), configuration);
|
||||
reinterpret_cast<napi_env>(&nativeEngine), *fullConfig);
|
||||
NativeValue* jsConfiguration = reinterpret_cast<NativeValue*>(napiConfiguration);
|
||||
CallObjectMethod("onConfigurationUpdated", &jsConfiguration, 1);
|
||||
}
|
||||
|
||||
@@ -672,11 +672,6 @@ void AbilityThread::ScheduleRestoreAbilityState(const PacMap &state)
|
||||
void AbilityThread::ScheduleUpdateConfiguration(const Configuration &config)
|
||||
{
|
||||
APP_LOGI("AbilityThread::ScheduleUpdateConfiguration begin");
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ScheduleUpdateConfiguration abilityImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
wptr<AbilityThread> weak = this;
|
||||
auto task = [weak, config]() {
|
||||
auto abilityThread = weak.promote();
|
||||
|
||||
@@ -308,10 +308,11 @@ void JsFormExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& co
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
// Notify extension context
|
||||
JsExtensionContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, GetContext()->GetConfiguration());
|
||||
auto fullConfig = GetContext()->GetConfiguration();
|
||||
JsExtensionContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, fullConfig);
|
||||
|
||||
napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(
|
||||
reinterpret_cast<napi_env>(&nativeEngine), configuration);
|
||||
reinterpret_cast<napi_env>(&nativeEngine), *fullConfig);
|
||||
NativeValue* jsConfiguration = reinterpret_cast<NativeValue*>(napiConfiguration);
|
||||
CallObjectMethod("onConfigurationUpdated", &jsConfiguration, 1);
|
||||
}
|
||||
|
||||
@@ -281,10 +281,11 @@ void JsServiceExtension::OnConfigurationUpdated(const AppExecFwk::Configuration&
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
// Notify extension context
|
||||
JsExtensionContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, GetContext()->GetConfiguration());
|
||||
auto fullConfig = GetContext()->GetConfiguration();
|
||||
JsExtensionContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, fullConfig);
|
||||
|
||||
napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(
|
||||
reinterpret_cast<napi_env>(&nativeEngine), configuration);
|
||||
reinterpret_cast<napi_env>(&nativeEngine), *fullConfig);
|
||||
NativeValue* jsConfiguration = reinterpret_cast<NativeValue*>(napiConfiguration);
|
||||
CallObjectMethod("onConfigurationUpdated", &jsConfiguration, 1);
|
||||
}
|
||||
|
||||
@@ -185,10 +185,11 @@ void JsAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration& con
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
// Notify Ability stage context
|
||||
JsAbilityStageContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, GetContext()->GetConfiguration());
|
||||
auto fullConfig = GetContext()->GetConfiguration();
|
||||
JsAbilityStageContext::ConfigurationUpdated(&nativeEngine, shellContextRef_, fullConfig);
|
||||
|
||||
napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(
|
||||
reinterpret_cast<napi_env>(&nativeEngine), configuration);
|
||||
reinterpret_cast<napi_env>(&nativeEngine), *fullConfig);
|
||||
NativeValue* jsConfiguration = reinterpret_cast<NativeValue*>(napiConfiguration);
|
||||
CallObjectMethod("onConfigurationUpdated", &jsConfiguration, 1);
|
||||
}
|
||||
|
||||
@@ -898,6 +898,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
application_->AttachBaseContext(contextDeal);
|
||||
application_->SetAbilityRecordMgr(abilityRecordMgr_);
|
||||
application_->SetConfiguration(config);
|
||||
contextImpl->SetConfiguration(application_->GetConfiguration());
|
||||
|
||||
applicationImpl_->SetRecordId(appLaunchData.GetRecordId());
|
||||
applicationImpl_->SetApplication(application_);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
NativeValue* CreateJsWantObject(NativeEngine& engine, const AAFwk::Want& want)
|
||||
{
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
@@ -172,15 +173,19 @@ NativeValue* CreateJsConfiguration(NativeEngine& engine, const AppExecFwk::Confi
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
object->SetProperty("language", CreateJsValue(engine,
|
||||
configuration.GetItem(AppExecFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)));
|
||||
configuration.GetItem(GlobalConfigurationKey::SYSTEM_LANGUAGE)));
|
||||
object->SetProperty("colorMode", CreateJsValue(engine,
|
||||
AppExecFwk::ConvertColorMode(configuration.GetItem(AppExecFwk::GlobalConfigurationKey::SYSTEM_COLORMODE))));
|
||||
object->SetProperty("direction", CreateJsValue(engine,
|
||||
AppExecFwk::ConvertDirection(configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION))));
|
||||
object->SetProperty("screenDensity", CreateJsValue(engine,
|
||||
AppExecFwk::ConvertDensity(configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI))));
|
||||
object->SetProperty("displayId", CreateJsValue(engine,
|
||||
AppExecFwk::ConvertDisplayId(configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID))));
|
||||
ConvertColorMode(configuration.GetItem(GlobalConfigurationKey::SYSTEM_COLORMODE))));
|
||||
|
||||
int32_t displayId = ConvertDisplayId(configuration.GetItem(ConfigurationInner::APPLICATION_DISPLAYID));
|
||||
|
||||
std::string direction = configuration.GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION);
|
||||
object->SetProperty("direction", CreateJsValue(engine, ConvertDirection(direction)));
|
||||
|
||||
std::string density = configuration.GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI);
|
||||
object->SetProperty("screenDensity", CreateJsValue(engine, ConvertDensity(density)));
|
||||
|
||||
object->SetProperty("displayId", CreateJsValue(engine, displayId));
|
||||
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ class ExtAbilityContext extends Context {
|
||||
constructor(obj) {
|
||||
super(obj);
|
||||
this.currentHapModuleInfo = obj.currentHapModuleInfo
|
||||
this.config = obj.config
|
||||
}
|
||||
|
||||
onUpdateConfiguration(config) {
|
||||
this.config = config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,13 +50,17 @@ napi_value WrapConfiguration(napi_env env, const AppExecFwk::Configuration &conf
|
||||
jsValue = WrapInt32ToJS(env, ConvertColorMode(configuration.GetItem(GlobalConfigurationKey::SYSTEM_COLORMODE)));
|
||||
SetPropertyValueByPropertyName(env, jsObject, "colorMode", jsValue);
|
||||
|
||||
jsValue = WrapInt32ToJS(env, ConvertDirection(configuration.GetItem(ConfigurationInner::APPLICATION_DIRECTION)));
|
||||
int32_t displayId = ConvertDisplayId(configuration.GetItem(ConfigurationInner::APPLICATION_DISPLAYID));
|
||||
|
||||
std::string direction = configuration.GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION);
|
||||
jsValue = WrapInt32ToJS(env, ConvertDirection(direction));
|
||||
SetPropertyValueByPropertyName(env, jsObject, "direction", jsValue);
|
||||
|
||||
jsValue = WrapInt32ToJS(env, ConvertDensity(configuration.GetItem(ConfigurationInner::APPLICATION_DENSITYDPI)));
|
||||
std::string density = configuration.GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI);
|
||||
jsValue = WrapInt32ToJS(env, ConvertDensity(density));
|
||||
SetPropertyValueByPropertyName(env, jsObject, "screenDensity", jsValue);
|
||||
|
||||
jsValue = WrapInt32ToJS(env, ConvertDisplayId(configuration.GetItem(ConfigurationInner::APPLICATION_DISPLAYID)));
|
||||
jsValue = WrapInt32ToJS(env, displayId);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "displayId", jsValue);
|
||||
|
||||
return jsObject;
|
||||
|
||||
Reference in New Issue
Block a user