1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "JsAppImpl.h"
17
18 #include "CommandParser.h"
19 #include "FileSystem.h"
20 #include "JsonReader.h"
21 #include "PreviewerEngineLog.h"
22 #include "SharedData.h"
23 #include "TraceTool.h"
24 #include "VirtualScreenImpl.h"
25 #include "KeyInputImpl.h"
26
27 using namespace std;
28 using namespace OHOS::Ace;
29
JsAppImpl()30 JsAppImpl::JsAppImpl() : ability(nullptr), isStop(false) {}
31
GetInstance()32 JsAppImpl& JsAppImpl::GetInstance()
33 {
34 static JsAppImpl instance;
35 return instance;
36 }
37
Start()38 void JsAppImpl::Start()
39 {
40 VirtualScreenImpl::GetInstance().InitVirtualScreen();
41 VirtualScreenImpl::GetInstance().InitAll(pipeName, pipePort);
42 isFinished = false;
43 while (!isStop) {
44 ILOG("Start run js app");
45 RunJsApp();
46 ILOG("Js app run finished");
47 }
48 isFinished = true;
49 }
50
Restart()51 void JsAppImpl::Restart()
52 {
53 Platform::AceAbility::Stop();
54 }
55
GetJSONTree()56 std::string JsAppImpl::GetJSONTree()
57 {
58 std::string jsongTree = ability->GetJSONTree();
59 Json::Value jsonData = JsonReader::ParseJsonData(jsongTree);
60 Json::StreamWriterBuilder builder;
61 builder["indentation"] = "";
62 builder["emitUTF8"] = true;
63 return Json::writeString(builder, jsonData);
64 }
65
GetDefaultJSONTree()66 std::string JsAppImpl::GetDefaultJSONTree()
67 {
68 ILOG("Start getDefaultJsontree.");
69 std::string jsongTree = ability->GetDefaultJSONTree();
70 Json::Value jsonData = JsonReader::ParseJsonData(jsongTree);
71 ILOG("GetDefaultJsontree finished.");
72 Json::StreamWriterBuilder builder;
73 builder["indentation"] = "";
74 builder["emitUTF8"] = true;
75 return Json::writeString(builder, jsonData);
76 }
77
OrientationChanged(std::string commandOrientation)78 void JsAppImpl::OrientationChanged(std::string commandOrientation)
79 {
80 aceRunArgs.deviceWidth = height;
81 aceRunArgs.deviceHeight = width;
82 VirtualScreenImpl::GetInstance().WidthAndHeightReverse();
83 AdaptDeviceType(aceRunArgs, CommandParser::GetInstance().GetDeviceType(),
84 VirtualScreenImpl::GetInstance().GetOrignalWidth());
85 AssignValueForWidthAndHeight(VirtualScreenImpl::GetInstance().GetOrignalWidth(),
86 VirtualScreenImpl::GetInstance().GetOrignalHeight(),
87 VirtualScreenImpl::GetInstance().GetCompressionWidth(),
88 VirtualScreenImpl::GetInstance().GetCompressionHeight());
89 if (commandOrientation == "portrait") {
90 aceRunArgs.deviceConfig.orientation = DeviceOrientation::PORTRAIT;
91 } else {
92 aceRunArgs.deviceConfig.orientation = DeviceOrientation::LANDSCAPE;
93 }
94
95 orientation = commandOrientation;
96 ILOG("OrientationChanged: %s %d %d %f", orientation.c_str(), aceRunArgs.deviceWidth,
97 aceRunArgs.deviceHeight, aceRunArgs.deviceConfig.density);
98 if (ability != nullptr) {
99 ability->SurfaceChanged(aceRunArgs.deviceConfig.orientation, aceRunArgs.deviceConfig.density,
100 aceRunArgs.deviceWidth, aceRunArgs.deviceHeight);
101 }
102 }
103
ColorModeChanged(const std::string commandColorMode)104 void JsAppImpl::ColorModeChanged(const std::string commandColorMode)
105 {
106 if (commandColorMode == "light") {
107 aceRunArgs.deviceConfig.colorMode = ColorMode::LIGHT;
108 } else {
109 aceRunArgs.deviceConfig.colorMode = ColorMode::DARK;
110 }
111
112 if (ability != nullptr) {
113 ability->OnConfigurationChanged(aceRunArgs.deviceConfig);
114 }
115 }
116
Interrupt()117 void JsAppImpl::Interrupt()
118 {
119 isStop = true;
120 Platform::AceAbility::Stop();
121 }
122
SetJsAppArgs(OHOS::Ace::Platform::AceRunArgs & args)123 void JsAppImpl::SetJsAppArgs(OHOS::Ace::Platform::AceRunArgs& args)
124 {
125 SetAssetPath(args, jsAppPath);
126 SetProjectModel(args);
127 SetPageProfile(args, CommandParser::GetInstance().GetPages());
128 SetDeviceWidth(args, width);
129 SetDeviceHeight(args, height);
130 SetWindowTitle(args, "Ace");
131 SetUrl(args, urlPath);
132 SetConfigChanges(args, configChanges);
133 SetColorMode(args, colorMode);
134 SetOrientation(args, orientation);
135 SetAceVersionArgs(args, aceVersion);
136 SetDeviceScreenDensity(atoi(screenDensity.c_str()),
137 CommandParser::GetInstance().GetDeviceType());
138 SetLanguage(args, SharedData<string>::GetData(SharedDataType::LAN));
139 SetRegion(args, SharedData<string>::GetData(SharedDataType::REGION));
140 SetScript(args, "");
141 SetSystemResourcesPath(args);
142 SetAppResourcesPath(args, CommandParser::GetInstance().GetAppResourcePath());
143 SetFormsEnabled(args, CommandParser::GetInstance().IsCardDisplay());
144 SetContainerSdkPath(args, CommandParser::GetInstance().GetContainerSdkPath());
145 AdaptDeviceType(args, CommandParser::GetInstance().GetDeviceType(),
146 VirtualScreenImpl::GetInstance().GetOrignalWidth());
147 SetOnRender(args);
148 SetOnRouterChange(args);
149 SetOnError(args);
150 SetComponentModeEnabled(args, CommandParser::GetInstance().IsComponentMode());
151 ILOG("start abilit: %d %d %f", args.deviceWidth, args.deviceHeight, args.deviceConfig.density);
152 }
153
RunJsApp()154 void JsAppImpl::RunJsApp()
155 {
156 KeyInputImpl::GetInstance().SetDelegate();
157 AssignValueForWidthAndHeight(VirtualScreenImpl::GetInstance().GetOrignalWidth(),
158 VirtualScreenImpl::GetInstance().GetOrignalHeight(),
159 VirtualScreenImpl::GetInstance().GetCompressionWidth(),
160 VirtualScreenImpl::GetInstance().GetCompressionHeight());
161 SetJsAppArgs(aceRunArgs);
162 if (ability != nullptr) {
163 ability.reset();
164 }
165 ILOG("Launch Js App");
166 TraceTool::GetInstance().HandleTrace("Launch Js App");
167 ability = Platform::AceAbility::CreateInstance(aceRunArgs);
168 if (ability == nullptr) {
169 ELOG("JsApp::Run ability create failed.");
170 return;
171 }
172 ability->InitEnv();
173 ability->Start();
174 }
175
AdaptDeviceType(Platform::AceRunArgs & args,const std::string type,const int32_t realDeviceWidth,double screenDendity) const176 void JsAppImpl::AdaptDeviceType(Platform::AceRunArgs& args, const std::string type,
177 const int32_t realDeviceWidth, double screenDendity) const
178 {
179 if (type == "wearable") {
180 args.deviceConfig.deviceType = DeviceType::WATCH;
181 double density = screenDendity > 0 ? screenDendity : watchScreenDensity;
182 double adaptWidthWatch = realDeviceWidth * BASE_SCREEN_DENSITY / density;
183 args.deviceConfig.density = args.deviceWidth / adaptWidthWatch;
184 return;
185 }
186 if (type == "tv") {
187 args.deviceConfig.deviceType = DeviceType::TV;
188 double density = screenDendity > 0 ? screenDendity : tvScreenDensity;
189 double adaptWidthTv = realDeviceWidth * BASE_SCREEN_DENSITY / density;
190 args.deviceConfig.density = args.deviceWidth / adaptWidthTv;
191 return;
192 }
193 if (type == "phone") {
194 args.deviceConfig.deviceType = DeviceType::PHONE;
195 double density = screenDendity > 0 ? screenDendity : phoneScreenDensity;
196 double adaptWidthPhone = realDeviceWidth * BASE_SCREEN_DENSITY / density;
197 args.deviceConfig.density = args.deviceWidth / adaptWidthPhone;
198 return;
199 }
200 if (type == "tablet") {
201 args.deviceConfig.deviceType = DeviceType::TABLET;
202 double density = screenDendity > 0 ? screenDendity : tabletScreenDensity;
203 double adaptWidthTablet = realDeviceWidth * BASE_SCREEN_DENSITY / density;
204 args.deviceConfig.density = args.deviceWidth / adaptWidthTablet;
205 return;
206 }
207 if (type == "car") {
208 args.deviceConfig.deviceType = DeviceType::CAR;
209 double density = screenDendity > 0 ? screenDendity : carScreenDensity;
210 double adaptWidthCar = realDeviceWidth * BASE_SCREEN_DENSITY / density;
211 args.deviceConfig.density = args.deviceWidth / adaptWidthCar;
212 return;
213 }
214 ELOG("DeviceType not supported : %s", type.c_str());
215 return;
216 }
217
SetAssetPath(Platform::AceRunArgs & args,const std::string assetPath) const218 void JsAppImpl::SetAssetPath(Platform::AceRunArgs& args, const std::string assetPath) const
219 {
220 args.assetPath = assetPath;
221 }
222
SetProjectModel(Platform::AceRunArgs & args) const223 void JsAppImpl::SetProjectModel(Platform::AceRunArgs& args) const
224 {
225 int idxVal = CommandParser::GetInstance().GetProjectModelEnumValue();
226 ILOG("ProjectModel: %s", CommandParser::GetInstance().GetProjectModelEnumName(idxVal).c_str());
227 args.projectModel = Platform::ProjectModel(idxVal);
228 }
229
SetPageProfile(Platform::AceRunArgs & args,const std::string pageProfile) const230 void JsAppImpl::SetPageProfile(Platform::AceRunArgs& args, const std::string pageProfile) const
231 {
232 args.pageProfile = pageProfile;
233 }
234
SetDeviceWidth(Platform::AceRunArgs & args,const int32_t deviceWidth) const235 void JsAppImpl::SetDeviceWidth(Platform::AceRunArgs& args, const int32_t deviceWidth) const
236 {
237 args.deviceWidth = deviceWidth;
238 }
239
SetDeviceHeight(Platform::AceRunArgs & args,const int32_t deviceHeight) const240 void JsAppImpl::SetDeviceHeight(Platform::AceRunArgs& args, const int32_t deviceHeight) const
241 {
242 args.deviceHeight = deviceHeight;
243 }
244
SetWindowTitle(Platform::AceRunArgs & args,const std::string windowTitle) const245 void JsAppImpl::SetWindowTitle(Platform::AceRunArgs& args, const std::string windowTitle) const
246 {
247 args.windowTitle = windowTitle;
248 }
249
SetUrl(Platform::AceRunArgs & args,const std::string urlPath) const250 void JsAppImpl::SetUrl(Platform::AceRunArgs& args, const std::string urlPath) const
251 {
252 args.url = urlPath;
253 }
254
SetConfigChanges(Platform::AceRunArgs & args,const std::string configChanges) const255 void JsAppImpl::SetConfigChanges(Platform::AceRunArgs& args, const std::string configChanges) const
256 {
257 args.configChanges = configChanges;
258 }
259
SetColorMode(Platform::AceRunArgs & args,const std::string colorMode) const260 void JsAppImpl::SetColorMode(Platform::AceRunArgs& args, const std::string colorMode) const
261 {
262 ILOG("JsAppImpl::RunJsApp SetColorMode: %s", colorMode.c_str());
263 if (colorMode == "dark") {
264 args.deviceConfig.colorMode = ColorMode::DARK;
265 } else {
266 args.deviceConfig.colorMode = ColorMode::LIGHT;
267 }
268 }
269
SetOrientation(Platform::AceRunArgs & args,const std::string orientation) const270 void JsAppImpl::SetOrientation(Platform::AceRunArgs& args, const std::string orientation) const
271 {
272 ILOG("JsAppImpl::RunJsApp SetOrientation: %s", orientation.c_str());
273 if (orientation == "landscape") {
274 args.deviceConfig.orientation = DeviceOrientation::LANDSCAPE;
275 } else {
276 args.deviceConfig.orientation = DeviceOrientation::PORTRAIT;
277 }
278 }
279
SetAceVersionArgs(Platform::AceRunArgs & args,const std::string aceVersion) const280 void JsAppImpl::SetAceVersionArgs(Platform::AceRunArgs& args, const std::string aceVersion) const
281 {
282 ILOG("JsAppImpl::RunJsApp SetAceVersionArgs: %s", aceVersion.c_str());
283 if (aceVersion == "ACE_2_0") {
284 args.aceVersion = Platform::AceVersion::ACE_2_0;
285 } else {
286 args.aceVersion = Platform::AceVersion::ACE_1_0;
287 }
288 }
289
SetLanguage(Platform::AceRunArgs & args,const std::string language) const290 void JsAppImpl::SetLanguage(Platform::AceRunArgs& args, const std::string language) const
291 {
292 args.language = language;
293 }
294
SetRegion(Platform::AceRunArgs & args,const std::string region) const295 void JsAppImpl::SetRegion(Platform::AceRunArgs& args, const std::string region) const
296 {
297 args.region = region;
298 }
299
SetScript(Platform::AceRunArgs & args,const std::string script) const300 void JsAppImpl::SetScript(Platform::AceRunArgs& args, const std::string script) const
301 {
302 args.script = script;
303 }
304
SetSystemResourcesPath(Platform::AceRunArgs & args) const305 void JsAppImpl::SetSystemResourcesPath(Platform::AceRunArgs& args) const
306 {
307 string sep = FileSystem::GetSeparator();
308 string rPath = FileSystem::GetApplicationPath();
309 int idx = rPath.find_last_of(sep);
310 rPath = rPath.substr(0, idx + 1) + "resources";
311 args.systemResourcesPath = rPath;
312 }
313
SetAppResourcesPath(Platform::AceRunArgs & args,const std::string appResourcesPath) const314 void JsAppImpl::SetAppResourcesPath(Platform::AceRunArgs& args, const std::string appResourcesPath) const
315 {
316 args.appResourcesPath = appResourcesPath;
317 }
318
SetFormsEnabled(Platform::AceRunArgs & args,bool formsEnabled) const319 void JsAppImpl::SetFormsEnabled(Platform::AceRunArgs& args, bool formsEnabled) const
320 {
321 args.formsEnabled = formsEnabled;
322 }
323
SetContainerSdkPath(Platform::AceRunArgs & args,const std::string containerSdkPath) const324 void JsAppImpl::SetContainerSdkPath(Platform::AceRunArgs& args, const std::string containerSdkPath) const
325 {
326 args.containerSdkPath = containerSdkPath;
327 }
328
SetOnRender(Platform::AceRunArgs & args) const329 void JsAppImpl::SetOnRender(Platform::AceRunArgs& args) const
330 {
331 args.onRender = std::move(VirtualScreenImpl::CallBack);
332 }
333
SetOnRouterChange(Platform::AceRunArgs & args) const334 void JsAppImpl::SetOnRouterChange(Platform::AceRunArgs& args) const
335 {
336 args.onRouterChange = std::move(VirtualScreenImpl::PageCallBack);
337 }
338
SetOnError(Platform::AceRunArgs & args) const339 void JsAppImpl::SetOnError(Platform::AceRunArgs& args) const
340 {
341 args.onError = std::move(VirtualScreenImpl::FastPreviewCallBack);
342 }
343
SetComponentModeEnabled(Platform::AceRunArgs & args,bool isComponentMode) const344 void JsAppImpl::SetComponentModeEnabled(Platform::AceRunArgs& args, bool isComponentMode) const
345 {
346 args.isComponentMode = isComponentMode;
347 }
348
AssignValueForWidthAndHeight(const int32_t origWidth,const int32_t origHeight,const int32_t compWidth,const int32_t compHeight)349 void JsAppImpl::AssignValueForWidthAndHeight(const int32_t origWidth,
350 const int32_t origHeight,
351 const int32_t compWidth,
352 const int32_t compHeight)
353 {
354 orignalWidth = origWidth;
355 orignalHeight = origHeight;
356 width = compWidth;
357 height = compHeight;
358 ILOG("AssignValueForWidthAndHeight: %d %d %d %d", orignalWidth, orignalHeight, width, height);
359 }
360
ResolutionChanged(int32_t changedOriginWidth,int32_t changedOriginHeight,int32_t changedWidth,int32_t changedHeight,int32_t screenDensity)361 void JsAppImpl::ResolutionChanged(int32_t changedOriginWidth,
362 int32_t changedOriginHeight,
363 int32_t changedWidth,
364 int32_t changedHeight,
365 int32_t screenDensity)
366 {
367 SetDeviceWidth(aceRunArgs, changedWidth);
368 SetDeviceHeight(aceRunArgs, changedHeight);
369 orignalWidth = changedOriginWidth;
370 orignalHeight = changedOriginHeight;
371 VirtualScreenImpl::GetInstance().SetVirtualScreenWidthAndHeight(changedOriginWidth, changedOriginHeight,
372 changedWidth, changedHeight);
373 SetDeviceScreenDensity(screenDensity,
374 CommandParser::GetInstance().GetDeviceType());
375 AdaptDeviceType(aceRunArgs, CommandParser::GetInstance().GetDeviceType(),
376 VirtualScreenImpl::GetInstance().GetOrignalWidth());
377 AssignValueForWidthAndHeight(VirtualScreenImpl::GetInstance().GetOrignalWidth(),
378 VirtualScreenImpl::GetInstance().GetOrignalHeight(),
379 VirtualScreenImpl::GetInstance().GetCompressionWidth(),
380 VirtualScreenImpl::GetInstance().GetCompressionHeight());
381 // Runtime change device orientation
382 if (changedWidth <= changedHeight) {
383 JsAppImpl::GetInstance().SetDeviceOrentation("portrait");
384 } else {
385 JsAppImpl::GetInstance().SetDeviceOrentation("landscape");
386 }
387 SetOrientation(aceRunArgs, orientation);
388
389 ILOG("ResolutionChanged: %s %d %d %f", orientation.c_str(), aceRunArgs.deviceWidth,
390 aceRunArgs.deviceHeight, aceRunArgs.deviceConfig.density);
391 if (ability != nullptr) {
392 ability->SurfaceChanged(aceRunArgs.deviceConfig.orientation, aceRunArgs.deviceConfig.density,
393 aceRunArgs.deviceWidth, aceRunArgs.deviceHeight);
394 }
395 }
396
SetArgsColorMode(const string & value)397 void JsAppImpl::SetArgsColorMode(const string& value)
398 {
399 colorMode = value;
400 }
401
SetArgsAceVersion(const string & value)402 void JsAppImpl::SetArgsAceVersion(const string& value)
403 {
404 aceVersion = value;
405 }
406
SetDeviceOrentation(const string & value)407 void JsAppImpl::SetDeviceOrentation(const string& value)
408 {
409 orientation = value;
410 }
411
GetOrientation() const412 std::string JsAppImpl::GetOrientation() const
413 {
414 return orientation;
415 }
416
GetColorMode() const417 std::string JsAppImpl::GetColorMode() const
418 {
419 return colorMode;
420 }
421
SetDeviceScreenDensity(const int32_t screenDensity,const std::string type)422 void JsAppImpl::SetDeviceScreenDensity(const int32_t screenDensity, const std::string type)
423 {
424 if (type == "wearable" && screenDensity != 0) {
425 watchScreenDensity = screenDensity;
426 return;
427 }
428 if (type == "tv" && screenDensity != 0) {
429 tvScreenDensity = screenDensity;
430 return;
431 }
432 if (type == "phone" && screenDensity != 0) {
433 phoneScreenDensity = screenDensity;
434 return;
435 }
436 if (type == "tablet" && screenDensity != 0) {
437 tabletScreenDensity = screenDensity;
438 return;
439 }
440 if (type == "car" && screenDensity != 0) {
441 carScreenDensity = screenDensity;
442 return;
443 }
444 ILOG("DeviceType not supported to SetDeviceScreenDensity: %s", type.c_str());
445 return;
446 }
447
ReloadRuntimePage(const std::string currentPage)448 void JsAppImpl::ReloadRuntimePage(const std::string currentPage)
449 {
450 std::string params = "";
451 if (ability != nullptr) {
452 ability->ReplacePage(currentPage, params);
453 }
454 }
455
SetScreenDensity(const std::string value)456 void JsAppImpl::SetScreenDensity(const std::string value)
457 {
458 screenDensity = value;
459 }
460
SetConfigChanges(const std::string value)461 void JsAppImpl::SetConfigChanges(const std::string value)
462 {
463 configChanges = value;
464 }
465
MemoryRefresh(const std::string memoryRefreshArgs) const466 bool JsAppImpl::MemoryRefresh(const std::string memoryRefreshArgs) const
467 {
468 ILOG("MemoryRefresh.");
469 if (ability != nullptr) {
470 return ability->OperateComponent(memoryRefreshArgs);
471 }
472 return false;
473 }
474
ParseSystemParams(OHOS::Ace::Platform::AceRunArgs & args,Json::Value paramObj)475 void JsAppImpl::ParseSystemParams(OHOS::Ace::Platform::AceRunArgs& args, Json::Value paramObj)
476 {
477 if (paramObj == Json::nullValue) {
478 SetDeviceWidth(args, VirtualScreenImpl::GetInstance().GetCompressionWidth());
479 SetDeviceHeight(args, VirtualScreenImpl::GetInstance().GetCompressionHeight());
480 AssignValueForWidthAndHeight(args.deviceWidth, args.deviceHeight,
481 args.deviceWidth, args.deviceHeight);
482 SetColorMode(args, colorMode);
483 SetOrientation(args, orientation);
484 SetDeviceScreenDensity(atoi(screenDensity.c_str()),
485 CommandParser::GetInstance().GetDeviceType());
486 AdaptDeviceType(args, CommandParser::GetInstance().GetDeviceType(),
487 VirtualScreenImpl::GetInstance().GetOrignalWidth());
488 SetLanguage(args, SharedData<string>::GetData(SharedDataType::LAN));
489 SetRegion(args, SharedData<string>::GetData(SharedDataType::REGION));
490 } else {
491 SetDeviceWidth(args, paramObj["width"].asInt());
492 SetDeviceHeight(args, paramObj["height"].asInt());
493 AssignValueForWidthAndHeight(args.deviceWidth, args.deviceHeight,
494 args.deviceWidth, args.deviceHeight);
495 SetColorMode(args, paramObj["colorMode"].asString());
496 SetOrientation(args, paramObj["orientation"].asString());
497 string deviceType = paramObj["deviceType"].asString();
498 SetDeviceScreenDensity(atoi(screenDensity.c_str()), deviceType);
499 AdaptDeviceType(args, deviceType, args.deviceWidth, paramObj["dpi"].asDouble());
500 string lanInfo = paramObj["locale"].asString();
501 SetLanguage(args, lanInfo.substr(0, lanInfo.find("_")));
502 SetRegion(args, lanInfo.substr(lanInfo.find("_") + 1, lanInfo.length() - 1));
503 }
504 }
505
SetSystemParams(OHOS::Ace::Platform::SystemParams & params,Json::Value paramObj)506 void JsAppImpl::SetSystemParams(OHOS::Ace::Platform::SystemParams& params, Json::Value paramObj)
507 {
508 ParseSystemParams(aceRunArgs, paramObj);
509 params.deviceWidth = aceRunArgs.deviceWidth;
510 params.deviceHeight = aceRunArgs.deviceHeight;
511 params.language = aceRunArgs.language;
512 params.region = aceRunArgs.region;
513 params.colorMode = aceRunArgs.deviceConfig.colorMode;
514 params.orientation = aceRunArgs.deviceConfig.orientation;
515 params.deviceType = aceRunArgs.deviceConfig.deviceType;
516 params.density = aceRunArgs.deviceConfig.density;
517 params.isRound = (paramObj == Json::nullValue) ?
518 (CommandParser::GetInstance().GetScreenShape() == "circle") :
519 paramObj["roundScreen"].asBool();
520 }
521
LoadDocument(const std::string filePath,const std::string componentName,Json::Value previewContext)522 void JsAppImpl::LoadDocument(const std::string filePath,
523 const std::string componentName,
524 Json::Value previewContext)
525 {
526 ILOG("LoadDocument.");
527 if (ability != nullptr) {
528 OHOS::Ace::Platform::SystemParams params;
529 SetSystemParams(params, previewContext);
530 ILOG("LoadDocument params is density: %f region: %s language: %s deviceWidth: %d\
531 deviceHeight: %d isRound:%d colorMode:%s orientation: %s deviceType: %s",
532 params.density,
533 params.region.c_str(),
534 params.language.c_str(),
535 params.deviceWidth,
536 params.deviceHeight,
537 (params.isRound ? "true" : "false"),
538 ((params.colorMode == ColorMode::DARK) ? "dark" : "light"),
539 ((params.orientation == DeviceOrientation::LANDSCAPE) ? "landscape" : "portrait"),
540 GetDeviceTypeName(params.deviceType).c_str());
541 ability->LoadDocument(filePath, componentName, params);
542 }
543 }
544
GetDeviceTypeName(const OHOS::Ace::DeviceType type) const545 string JsAppImpl::GetDeviceTypeName(const OHOS::Ace::DeviceType type) const
546 {
547 switch (type) {
548 case DeviceType::WATCH:
549 return "watch";
550 case DeviceType::TV:
551 return "tv";
552 case DeviceType::PHONE:
553 return "phone";
554 case DeviceType::TABLET:
555 return "tablet";
556 case DeviceType::CAR:
557 return "car";
558 default:
559 return "";
560 }
561 }