• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     ILOG("start abilit: %d %d %f", args.deviceWidth, args.deviceHeight, args.deviceConfig.density);
151 }
152 
RunJsApp()153 void JsAppImpl::RunJsApp()
154 {
155     KeyInputImpl::GetInstance().SetDelegate();
156     AssignValueForWidthAndHeight(VirtualScreenImpl::GetInstance().GetOrignalWidth(),
157                                  VirtualScreenImpl::GetInstance().GetOrignalHeight(),
158                                  VirtualScreenImpl::GetInstance().GetCompressionWidth(),
159                                  VirtualScreenImpl::GetInstance().GetCompressionHeight());
160     SetJsAppArgs(aceRunArgs);
161     if (ability != nullptr) {
162         ability.reset();
163     }
164     ILOG("Launch Js App");
165     TraceTool::GetInstance().HandleTrace("Launch Js App");
166     ability = Platform::AceAbility::CreateInstance(aceRunArgs);
167     if (ability == nullptr) {
168         ELOG("JsApp::Run ability create failed.");
169         return;
170     }
171     ability->InitEnv();
172     ability->Start();
173 }
174 
AdaptDeviceType(Platform::AceRunArgs & args,const std::string type,const int32_t realDeviceWidth,double screenDendity) const175 void JsAppImpl::AdaptDeviceType(Platform::AceRunArgs& args, const std::string type,
176                                 const int32_t realDeviceWidth, double screenDendity) const
177 {
178     if (type == "wearable") {
179         args.deviceConfig.deviceType = DeviceType::WATCH;
180         double density = screenDendity > 0 ? screenDendity : watchScreenDensity;
181         double adaptWidthWatch = realDeviceWidth * BASE_SCREEN_DENSITY / density;
182         args.deviceConfig.density = args.deviceWidth / adaptWidthWatch;
183         return;
184     }
185     if (type == "tv") {
186         args.deviceConfig.deviceType = DeviceType::TV;
187         double density = screenDendity > 0 ? screenDendity : tvScreenDensity;
188         double adaptWidthTv = realDeviceWidth * BASE_SCREEN_DENSITY / density;
189         args.deviceConfig.density = args.deviceWidth / adaptWidthTv;
190         return;
191     }
192     if (type == "phone") {
193         args.deviceConfig.deviceType = DeviceType::PHONE;
194         double density = screenDendity > 0 ? screenDendity : phoneScreenDensity;
195         double adaptWidthPhone = realDeviceWidth * BASE_SCREEN_DENSITY / density;
196         args.deviceConfig.density = args.deviceWidth / adaptWidthPhone;
197         return;
198     }
199     if (type == "tablet") {
200         args.deviceConfig.deviceType = DeviceType::TABLET;
201         double density = screenDendity > 0 ? screenDendity : tabletScreenDensity;
202         double adaptWidthTablet = realDeviceWidth * BASE_SCREEN_DENSITY / density;
203         args.deviceConfig.density = args.deviceWidth / adaptWidthTablet;
204         return;
205     }
206     if (type == "car") {
207         args.deviceConfig.deviceType = DeviceType::CAR;
208         double density = screenDendity > 0 ? screenDendity : carScreenDensity;
209         double adaptWidthCar = realDeviceWidth * BASE_SCREEN_DENSITY / density;
210         args.deviceConfig.density = args.deviceWidth / adaptWidthCar;
211         return;
212     }
213     ELOG("DeviceType not supported : %s", type.c_str());
214     return;
215 }
216 
SetAssetPath(Platform::AceRunArgs & args,const std::string assetPath) const217 void JsAppImpl::SetAssetPath(Platform::AceRunArgs& args, const std::string assetPath) const
218 {
219     args.assetPath = assetPath;
220 }
221 
SetProjectModel(Platform::AceRunArgs & args) const222 void JsAppImpl::SetProjectModel(Platform::AceRunArgs& args) const
223 {
224     int idxVal = CommandParser::GetInstance().GetProjectModelEnumValue();
225     ILOG("ProjectModel: %s", CommandParser::GetInstance().GetProjectModelEnumName(idxVal).c_str());
226     args.projectModel = Platform::ProjectModel(idxVal);
227 }
228 
SetPageProfile(Platform::AceRunArgs & args,const std::string pageProfile) const229 void JsAppImpl::SetPageProfile(Platform::AceRunArgs& args, const std::string pageProfile) const
230 {
231     args.pageProfile = pageProfile;
232 }
233 
SetDeviceWidth(Platform::AceRunArgs & args,const int32_t deviceWidth) const234 void JsAppImpl::SetDeviceWidth(Platform::AceRunArgs& args, const int32_t deviceWidth) const
235 {
236     args.deviceWidth = deviceWidth;
237 }
238 
SetDeviceHeight(Platform::AceRunArgs & args,const int32_t deviceHeight) const239 void JsAppImpl::SetDeviceHeight(Platform::AceRunArgs& args, const int32_t deviceHeight) const
240 {
241     args.deviceHeight = deviceHeight;
242 }
243 
SetWindowTitle(Platform::AceRunArgs & args,const std::string windowTitle) const244 void JsAppImpl::SetWindowTitle(Platform::AceRunArgs& args, const std::string windowTitle) const
245 {
246     args.windowTitle = windowTitle;
247 }
248 
SetUrl(Platform::AceRunArgs & args,const std::string urlPath) const249 void JsAppImpl::SetUrl(Platform::AceRunArgs& args, const std::string urlPath) const
250 {
251     args.url = urlPath;
252 }
253 
SetConfigChanges(Platform::AceRunArgs & args,const std::string configChanges) const254 void JsAppImpl::SetConfigChanges(Platform::AceRunArgs& args, const std::string configChanges) const
255 {
256     args.configChanges = configChanges;
257 }
258 
SetColorMode(Platform::AceRunArgs & args,const std::string colorMode) const259 void JsAppImpl::SetColorMode(Platform::AceRunArgs& args, const std::string colorMode) const
260 {
261     ILOG("JsAppImpl::RunJsApp SetColorMode: %s", colorMode.c_str());
262     if (colorMode == "dark") {
263         args.deviceConfig.colorMode = ColorMode::DARK;
264     } else {
265         args.deviceConfig.colorMode = ColorMode::LIGHT;
266     }
267 }
268 
SetOrientation(Platform::AceRunArgs & args,const std::string orientation) const269 void JsAppImpl::SetOrientation(Platform::AceRunArgs& args, const std::string orientation) const
270 {
271     ILOG("JsAppImpl::RunJsApp SetOrientation: %s", orientation.c_str());
272     if (orientation == "landscape") {
273         args.deviceConfig.orientation = DeviceOrientation::LANDSCAPE;
274     } else {
275         args.deviceConfig.orientation = DeviceOrientation::PORTRAIT;
276     }
277 }
278 
SetAceVersionArgs(Platform::AceRunArgs & args,const std::string aceVersion) const279 void JsAppImpl::SetAceVersionArgs(Platform::AceRunArgs& args, const std::string aceVersion) const
280 {
281     ILOG("JsAppImpl::RunJsApp SetAceVersionArgs: %s", aceVersion.c_str());
282     if (aceVersion == "ACE_2_0") {
283         args.aceVersion = Platform::AceVersion::ACE_2_0;
284     } else {
285         args.aceVersion = Platform::AceVersion::ACE_1_0;
286     }
287 }
288 
SetLanguage(Platform::AceRunArgs & args,const std::string language) const289 void JsAppImpl::SetLanguage(Platform::AceRunArgs& args, const std::string language) const
290 {
291     args.language = language;
292 }
293 
SetRegion(Platform::AceRunArgs & args,const std::string region) const294 void JsAppImpl::SetRegion(Platform::AceRunArgs& args, const std::string region) const
295 {
296     args.region = region;
297 }
298 
SetScript(Platform::AceRunArgs & args,const std::string script) const299 void JsAppImpl::SetScript(Platform::AceRunArgs& args, const std::string script) const
300 {
301     args.script = script;
302 }
303 
SetSystemResourcesPath(Platform::AceRunArgs & args) const304 void JsAppImpl::SetSystemResourcesPath(Platform::AceRunArgs& args) const
305 {
306     string sep = FileSystem::GetSeparator();
307     string rPath = FileSystem::GetApplicationPath();
308     int idx = rPath.find_last_of(sep);
309     rPath = rPath.substr(0, idx + 1) + "resources";
310     args.systemResourcesPath = rPath;
311 }
312 
SetAppResourcesPath(Platform::AceRunArgs & args,const std::string appResourcesPath) const313 void JsAppImpl::SetAppResourcesPath(Platform::AceRunArgs& args, const std::string appResourcesPath) const
314 {
315     args.appResourcesPath = appResourcesPath;
316 }
317 
SetFormsEnabled(Platform::AceRunArgs & args,bool formsEnabled) const318 void JsAppImpl::SetFormsEnabled(Platform::AceRunArgs& args, bool formsEnabled) const
319 {
320     args.formsEnabled = formsEnabled;
321 }
322 
SetContainerSdkPath(Platform::AceRunArgs & args,const std::string containerSdkPath) const323 void JsAppImpl::SetContainerSdkPath(Platform::AceRunArgs& args, const std::string containerSdkPath) const
324 {
325     args.containerSdkPath = containerSdkPath;
326 }
327 
SetOnRender(Platform::AceRunArgs & args) const328 void JsAppImpl::SetOnRender(Platform::AceRunArgs& args) const
329 {
330     args.onRender = std::move(VirtualScreenImpl::CallBack);
331 }
332 
SetOnRouterChange(Platform::AceRunArgs & args) const333 void JsAppImpl::SetOnRouterChange(Platform::AceRunArgs& args) const
334 {
335     args.onRouterChange = std::move(VirtualScreenImpl::PageCallBack);
336 }
337 
SetOnError(Platform::AceRunArgs & args) const338 void JsAppImpl::SetOnError(Platform::AceRunArgs& args) const
339 {
340     args.onError = std::move(VirtualScreenImpl::FastPreviewCallBack);
341 }
342 
AssignValueForWidthAndHeight(const int32_t origWidth,const int32_t origHeight,const int32_t compWidth,const int32_t compHeight)343 void JsAppImpl::AssignValueForWidthAndHeight(const int32_t origWidth,
344                                              const int32_t origHeight,
345                                              const int32_t compWidth,
346                                              const int32_t compHeight)
347 {
348     orignalWidth = origWidth;
349     orignalHeight = origHeight;
350     width = compWidth;
351     height = compHeight;
352     ILOG("AssignValueForWidthAndHeight: %d %d %d %d", orignalWidth, orignalHeight, width, height);
353 }
354 
ResolutionChanged(int32_t changedOriginWidth,int32_t changedOriginHeight,int32_t changedWidth,int32_t changedHeight,int32_t screenDensity)355 void JsAppImpl::ResolutionChanged(int32_t changedOriginWidth,
356                                   int32_t changedOriginHeight,
357                                   int32_t changedWidth,
358                                   int32_t changedHeight,
359                                   int32_t screenDensity)
360 {
361     SetDeviceWidth(aceRunArgs, changedWidth);
362     SetDeviceHeight(aceRunArgs, changedHeight);
363     orignalWidth = changedOriginWidth;
364     orignalHeight = changedOriginHeight;
365     VirtualScreenImpl::GetInstance().SetVirtualScreenWidthAndHeight(changedOriginWidth, changedOriginHeight,
366                                                                     changedWidth, changedHeight);
367     SetDeviceScreenDensity(screenDensity,
368                            CommandParser::GetInstance().GetDeviceType());
369     AdaptDeviceType(aceRunArgs, CommandParser::GetInstance().GetDeviceType(),
370                     VirtualScreenImpl::GetInstance().GetOrignalWidth());
371     AssignValueForWidthAndHeight(VirtualScreenImpl::GetInstance().GetOrignalWidth(),
372                                  VirtualScreenImpl::GetInstance().GetOrignalHeight(),
373                                  VirtualScreenImpl::GetInstance().GetCompressionWidth(),
374                                  VirtualScreenImpl::GetInstance().GetCompressionHeight());
375     // Runtime change device orientation
376     if (changedWidth <= changedHeight) {
377         JsAppImpl::GetInstance().SetDeviceOrentation("portrait");
378     } else {
379         JsAppImpl::GetInstance().SetDeviceOrentation("landscape");
380     }
381     SetOrientation(aceRunArgs, orientation);
382 
383     ILOG("ResolutionChanged: %s %d %d %f", orientation.c_str(), aceRunArgs.deviceWidth,
384          aceRunArgs.deviceHeight, aceRunArgs.deviceConfig.density);
385     if (ability != nullptr) {
386         ability->SurfaceChanged(aceRunArgs.deviceConfig.orientation, aceRunArgs.deviceConfig.density,
387                                 aceRunArgs.deviceWidth, aceRunArgs.deviceHeight);
388     }
389 }
390 
SetArgsColorMode(const string & value)391 void JsAppImpl::SetArgsColorMode(const string& value)
392 {
393     colorMode = value;
394 }
395 
SetArgsAceVersion(const string & value)396 void JsAppImpl::SetArgsAceVersion(const string& value)
397 {
398     aceVersion = value;
399 }
400 
SetDeviceOrentation(const string & value)401 void JsAppImpl::SetDeviceOrentation(const string& value)
402 {
403     orientation = value;
404 }
405 
GetOrientation() const406 std::string JsAppImpl::GetOrientation() const
407 {
408     return orientation;
409 }
410 
GetColorMode() const411 std::string JsAppImpl::GetColorMode() const
412 {
413     return colorMode;
414 }
415 
SetDeviceScreenDensity(const int32_t screenDensity,const std::string type)416 void JsAppImpl::SetDeviceScreenDensity(const int32_t screenDensity, const std::string type)
417 {
418     if (type == "wearable" && screenDensity != 0) {
419         watchScreenDensity = screenDensity;
420         return;
421     }
422     if (type == "tv" && screenDensity != 0) {
423         tvScreenDensity = screenDensity;
424         return;
425     }
426     if (type == "phone" && screenDensity != 0) {
427         phoneScreenDensity = screenDensity;
428         return;
429     }
430     if (type == "tablet" && screenDensity != 0) {
431         tabletScreenDensity = screenDensity;
432         return;
433     }
434     if (type == "car" && screenDensity != 0) {
435         carScreenDensity = screenDensity;
436         return;
437     }
438     ILOG("DeviceType not supported to SetDeviceScreenDensity: %s", type.c_str());
439     return;
440 }
441 
ReloadRuntimePage(const std::string currentPage)442 void JsAppImpl::ReloadRuntimePage(const std::string currentPage)
443 {
444     std::string params = "";
445     if (ability != nullptr) {
446         ability->ReplacePage(currentPage, params);
447     }
448 }
449 
SetScreenDensity(const std::string value)450 void JsAppImpl::SetScreenDensity(const std::string value)
451 {
452     screenDensity = value;
453 }
454 
SetConfigChanges(const std::string value)455 void JsAppImpl::SetConfigChanges(const std::string value)
456 {
457     configChanges = value;
458 }
459 
MemoryRefresh(const std::string memoryRefreshArgs) const460 bool JsAppImpl::MemoryRefresh(const std::string memoryRefreshArgs) const
461 {
462     ILOG("MemoryRefresh.");
463     if (ability != nullptr) {
464         return ability->OperateComponent(memoryRefreshArgs);
465     }
466     return false;
467 }
468 
ParseSystemParams(OHOS::Ace::Platform::AceRunArgs & args,Json::Value paramObj)469 void JsAppImpl::ParseSystemParams(OHOS::Ace::Platform::AceRunArgs& args, Json::Value paramObj)
470 {
471     if (paramObj == Json::nullValue) {
472         SetDeviceWidth(args, VirtualScreenImpl::GetInstance().GetCompressionWidth());
473         SetDeviceHeight(args, VirtualScreenImpl::GetInstance().GetCompressionHeight());
474         AssignValueForWidthAndHeight(args.deviceWidth, args.deviceHeight,
475                                      args.deviceWidth, args.deviceHeight);
476         SetColorMode(args, colorMode);
477         SetOrientation(args, orientation);
478         SetDeviceScreenDensity(atoi(screenDensity.c_str()),
479                                CommandParser::GetInstance().GetDeviceType());
480         AdaptDeviceType(args, CommandParser::GetInstance().GetDeviceType(),
481                         VirtualScreenImpl::GetInstance().GetOrignalWidth());
482         SetLanguage(args, SharedData<string>::GetData(SharedDataType::LAN));
483         SetRegion(args, SharedData<string>::GetData(SharedDataType::REGION));
484     } else {
485         SetDeviceWidth(args, paramObj["width"].asInt());
486         SetDeviceHeight(args, paramObj["height"].asInt());
487         AssignValueForWidthAndHeight(args.deviceWidth, args.deviceHeight,
488                                      args.deviceWidth, args.deviceHeight);
489         SetColorMode(args, paramObj["colorMode"].asString());
490         SetOrientation(args, paramObj["orientation"].asString());
491         string deviceType = paramObj["deviceType"].asString();
492         SetDeviceScreenDensity(atoi(screenDensity.c_str()), deviceType);
493         AdaptDeviceType(args, deviceType, args.deviceWidth, paramObj["dpi"].asDouble());
494         string lanInfo = paramObj["locale"].asString();
495         SetLanguage(args, lanInfo.substr(0, lanInfo.find("_")));
496         SetRegion(args, lanInfo.substr(lanInfo.find("_") + 1, lanInfo.length() - 1));
497     }
498 }
499 
SetSystemParams(OHOS::Ace::Platform::SystemParams & params,Json::Value paramObj)500 void JsAppImpl::SetSystemParams(OHOS::Ace::Platform::SystemParams& params, Json::Value paramObj)
501 {
502     ParseSystemParams(aceRunArgs, paramObj);
503     params.deviceWidth = aceRunArgs.deviceWidth;
504     params.deviceHeight = aceRunArgs.deviceHeight;
505     params.language = aceRunArgs.language;
506     params.region = aceRunArgs.region;
507     params.colorMode = aceRunArgs.deviceConfig.colorMode;
508     params.orientation = aceRunArgs.deviceConfig.orientation;
509     params.deviceType = aceRunArgs.deviceConfig.deviceType;
510     params.density = aceRunArgs.deviceConfig.density;
511     params.isRound = (paramObj == Json::nullValue) ?
512                      (CommandParser::GetInstance().GetScreenShape() == "circle") :
513                      paramObj["roundScreen"].asBool();
514 }
515 
LoadDocument(const std::string filePath,const std::string componentName,Json::Value previewContext)516 void JsAppImpl::LoadDocument(const std::string filePath,
517                              const std::string componentName,
518                              Json::Value previewContext)
519 {
520     ILOG("LoadDocument.");
521     if (ability != nullptr) {
522         OHOS::Ace::Platform::SystemParams params;
523         SetSystemParams(params, previewContext);
524         ILOG("LoadDocument params is density: %f region: %s language: %s deviceWidth: %d\
525              deviceHeight: %d isRound:%d colorMode:%s orientation: %s deviceType: %s",
526              params.density,
527              params.region.c_str(),
528              params.language.c_str(),
529              params.deviceWidth,
530              params.deviceHeight,
531              (params.isRound ? "true" : "false"),
532              ((params.colorMode == ColorMode::DARK) ? "dark" : "light"),
533              ((params.orientation == DeviceOrientation::LANDSCAPE) ? "landscape" : "portrait"),
534              GetDeviceTypeName(params.deviceType).c_str());
535         ability->LoadDocument(filePath, componentName, params);
536     }
537 }
538 
GetDeviceTypeName(const OHOS::Ace::DeviceType type) const539 string JsAppImpl::GetDeviceTypeName(const OHOS::Ace::DeviceType type) const
540 {
541     switch (type) {
542         case DeviceType::WATCH:
543             return "watch";
544         case DeviceType::TV:
545             return "tv";
546         case DeviceType::PHONE:
547             return "phone";
548         case DeviceType::TABLET:
549             return "tablet";
550         case DeviceType::CAR:
551             return "car";
552         default:
553             return "";
554     }
555 }