• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "adapter/preview/entrance/ace_ability.h"
17 
18 #ifdef INIT_ICU_DATA_PATH
19 #include "unicode/putil.h"
20 #endif
21 
22 #include <ui/rs_surface_node.h>
23 #include <ui/rs_ui_director.h>
24 
25 #include "include/core/SkFontMgr.h"
26 #include "previewer/include/window.h"
27 
28 #include "adapter/ohos/entrance/ace_new_pipe_judgement.h"
29 #include "adapter/preview/entrance/ace_application_info.h"
30 #include "adapter/preview/entrance/ace_container.h"
31 #include "adapter/preview/entrance/event_dispatcher.h"
32 #include "adapter/preview/entrance/rs_dir_asset_provider.h"
33 #include "adapter/preview/inspector/inspector_client.h"
34 #include "frameworks/base/utils/utils.h"
35 #include "frameworks/bridge/common/utils/utils.h"
36 #include "frameworks/bridge/js_frontend/js_frontend.h"
37 
38 namespace OHOS::Ace::Platform {
39 namespace {
40 
41 // JS frontend maintain the page ID self, so it's useless to pass page ID from platform
42 // layer, neither Android/OpenHarmony or Windows, we should delete here usage when Java delete it.
43 constexpr int32_t UNUSED_PAGE_ID = 1;
44 
45 constexpr char ASSET_PATH_SHARE[] = "share";
46 #ifdef WINDOWS_PLATFORM
47 constexpr char DELIMITER[] = "\\";
48 constexpr char ASSET_PATH_SHARE_STAGE[] = "resources\\base\\profile";
49 #else
50 constexpr char DELIMITER[] = "/";
51 constexpr char ASSET_PATH_SHARE_STAGE[] = "resources/base/profile";
52 #endif
53 
SetFontMgrConfig(const std::string & containerSdkPath)54 void SetFontMgrConfig(const std::string& containerSdkPath)
55 {
56     // To check if use ohos or container fonts.
57     std::string runtimeOS = "OHOS_Container";
58     std::string containerFontBasePath = containerSdkPath + DELIMITER + "resources" + DELIMITER + "fonts" + DELIMITER;
59     RSDirAssetProvider dirAsset(containerFontBasePath);
60     std::vector<std::string> fileList;
61     dirAsset.GetAssetList("", fileList);
62     if (containerSdkPath.empty() || fileList.empty()) {
63         runtimeOS = "OHOS";
64         containerFontBasePath = "";
65     }
66     LOGI("Runtime OS is %{public}s, and the container fontBasePath is %{public}s", runtimeOS.c_str(),
67         containerFontBasePath.c_str());
68     SkFontMgr::SetFontMgrConfig(runtimeOS, containerFontBasePath);
69 }
70 
GetCustomAssetPath(std::string assetPath)71 std::string GetCustomAssetPath(std::string assetPath)
72 {
73     if (assetPath.empty()) {
74         LOGE("AssetPath is null.");
75         return std::string();
76     }
77     std::string customAssetPath;
78     if (OHOS::Ace::Framework::EndWith(assetPath, DELIMITER)) {
79         assetPath = assetPath.substr(0, assetPath.size() - 1);
80     }
81     customAssetPath = assetPath.substr(0, assetPath.find_last_of(DELIMITER) + 1);
82     return customAssetPath;
83 }
84 
DumpAceRunArgs(const AceRunArgs & runArgs)85 inline void DumpAceRunArgs(const AceRunArgs& runArgs)
86 {
87 #ifdef ACE_DEBUG
88     LOGI("runArgs.pageProfile: %{private}s", runArgs.pageProfile.c_str());
89     LOGI("runArgs.asset: %{private}s", runArgs.assetPath.c_str());
90     LOGI("runArgs.systemResources: %{private}s", runArgs.systemResourcesPath.c_str());
91     LOGI("runArgs.appResources: %{private}s", runArgs.appResourcesPath.c_str());
92     LOGI("runArgs.themeId: %{private}u", runArgs.themeId);
93     LOGI("runArgs.deviceConfig.orientation: %{private}d", static_cast<int>(runArgs.deviceConfig.orientation));
94     LOGI("runArgs.deviceConfig.density: %{private}lf", runArgs.deviceConfig.density);
95     LOGI("runArgs.deviceConfig.deviceType: %{private}d", static_cast<int>(runArgs.deviceConfig.deviceType));
96     LOGI("runArgs.deviceConfig.fontRatio: %{private}lf", runArgs.deviceConfig.fontRatio);
97     LOGI("runArgs.deviceConfig.colorMode: %{private}d", static_cast<int>(runArgs.deviceConfig.colorMode));
98     LOGI("runArgs.url: %{private}s", runArgs.url.c_str());
99     LOGI("runArgs.windowTitle: %{private}s", runArgs.windowTitle.c_str());
100     LOGI("runArgs.isRound: %{private}s", runArgs.isRound ? "true" : "false");
101     LOGI("runArgs.viewWidth: %{private}d", runArgs.viewWidth);
102     LOGI("runArgs.viewHeight: %{private}d", runArgs.viewHeight);
103     LOGI("runArgs.deviceWidth: %{private}d", runArgs.deviceWidth);
104     LOGI("runArgs.deviceHeight: %{private}d", runArgs.deviceHeight);
105 #endif
106 }
107 
108 } // namespace
109 
AceAbility(const AceRunArgs & runArgs)110 AceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs)
111 {
112     static std::once_flag onceFlag;
113     std::call_once(onceFlag, []() {
114         LOGI("Initialize for current process.");
115         Container::UpdateCurrent(INSTANCE_ID_PLATFORM);
116     });
117     SystemProperties::SetExtSurfaceEnabled(!runArgs.containerSdkPath.empty());
118     SystemProperties::InitDeviceInfo(runArgs.deviceWidth, runArgs.deviceHeight,
119         runArgs.deviceConfig.orientation == DeviceOrientation::PORTRAIT ? 0 : 1, runArgs.deviceConfig.density,
120         runArgs.isRound);
121     SystemProperties::InitDeviceType(runArgs.deviceConfig.deviceType);
122     SystemProperties::SetColorMode(runArgs.deviceConfig.colorMode);
123     InitializeAppInfo();
124     if (runArgs_.aceVersion == AceVersion::ACE_1_0) {
125         if (runArgs_.formsEnabled) {
126             LOGI("CreateContainer with JS_CARD frontend");
127             AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS_CARD, false);
128         } else {
129             LOGI("CreateContainer with JS frontend");
130             AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS, false);
131         }
132     } else if (runArgs_.aceVersion == AceVersion::ACE_2_0) {
133         if (runArgs_.formsEnabled) {
134             LOGI("CreateContainer with ETS_CARD frontend");
135             AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::ETS_CARD, useNewPipeline_);
136         } else {
137             LOGI("CreateContainer with JSDECLARATIVE frontend");
138             AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::DECLARATIVE_JS, useNewPipeline_);
139         }
140     } else {
141         LOGE("UnKnown frontend type");
142     }
143     AceContainer::SetComponentModeFlag(runArgs.isComponentMode);
144     SetConfigChanges(runArgs.configChanges);
145     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
146     CHECK_NULL_VOID(container);
147     container->SetContainerSdkPath(runArgs.containerSdkPath);
148     container->SetInstallationFree(installationFree_);
149     container->SetLabelId(labelId_);
150     auto config = container->GetResourceConfiguration();
151     config.SetDeviceType(SystemProperties::GetDeviceType());
152     config.SetOrientation(SystemProperties::GetDeviceOrientation());
153     config.SetDensity(SystemProperties::GetResolution());
154     config.SetColorMode(SystemProperties::GetColorMode());
155     config.SetFontRatio(runArgs.deviceConfig.fontRatio);
156     container->SetResourceConfiguration(config);
157     InitializeClipboard();
158 }
159 
~AceAbility()160 AceAbility::~AceAbility()
161 {
162     AceContainer::DestroyContainer(ACE_INSTANCE_ID);
163 }
164 
CreateInstance(AceRunArgs & runArgs)165 std::unique_ptr<AceAbility> AceAbility::CreateInstance(AceRunArgs& runArgs)
166 {
167     DumpAceRunArgs(runArgs);
168     LOGI("Start create AceAbility instance");
169     AceApplicationInfo::GetInstance().SetLocale(runArgs.language, runArgs.region, runArgs.script, "");
170     SetFontMgrConfig(runArgs.containerSdkPath);
171     EventDispatcher::GetInstance().Initialize();
172     auto aceAbility = std::make_unique<AceAbility>(runArgs);
173     return aceAbility;
174 }
175 
InitEnv()176 void AceAbility::InitEnv()
177 {
178 #ifdef INIT_ICU_DATA_PATH
179     std::string icuPath = ".";
180     u_setDataDirectory(icuPath.c_str());
181 #endif
182     std::vector<std::string> paths;
183     paths.push_back(runArgs_.assetPath);
184     std::string appResourcesPath(runArgs_.appResourcesPath);
185     if (!OHOS::Ace::Framework::EndWith(appResourcesPath, DELIMITER)) {
186         appResourcesPath.append(DELIMITER);
187     }
188     if (runArgs_.projectModel == ProjectModel::STAGE) {
189         // eTS Card
190         if (runArgs_.aceVersion == AceVersion::ACE_2_0 && runArgs_.formsEnabled) {
191             paths.push_back(runArgs_.assetPath + DELIMITER + "ets");
192         }
193         paths.push_back(appResourcesPath);
194         paths.push_back(appResourcesPath + ASSET_PATH_SHARE_STAGE);
195     } else {
196         paths.push_back(GetCustomAssetPath(runArgs_.assetPath) + ASSET_PATH_SHARE);
197     }
198     if (!runArgs_.containerSdkPath.empty()) {
199         paths.push_back(runArgs_.containerSdkPath);
200     }
201     AceContainer::AddAssetPath(ACE_INSTANCE_ID, "", paths);
202     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
203     CHECK_NULL_VOID(container);
204     if (runArgs_.projectModel == ProjectModel::STAGE) {
205         if (runArgs_.formsEnabled) {
206             container->SetStageCardConfig(runArgs_.pageProfile, runArgs_.url);
207         } else {
208             container->SetPageProfile((runArgs_.pageProfile.empty() ? "" : runArgs_.pageProfile + ".json"));
209         }
210     }
211     AceContainer::SetResourcesPathAndThemeStyle(ACE_INSTANCE_ID, runArgs_.systemResourcesPath + "/entry",
212         runArgs_.appResourcesPath, runArgs_.themeId, runArgs_.deviceConfig.colorMode);
213 
214     auto view = AceViewPreview::CreateView(ACE_INSTANCE_ID);
215     auto window = GetWindow();
216     UIEnvCallback callback = [window, id = ACE_INSTANCE_ID](const OHOS::Ace::RefPtr<PipelineContext>& context) mutable {
217         CHECK_NULL_VOID(context);
218         CHECK_NULL_VOID(window);
219         auto director = OHOS::Rosen::RSUIDirector::Create();
220         CHECK_NULL_VOID(director);
221         director->SetRSSurfaceNode(window->GetSurfaceNode());
222         auto container = AceContainer::GetContainerInstance(id);
223         CHECK_NULL_VOID(container);
224         auto func = [taskExecutor = container->GetTaskExecutor(), id](const std::function<void()>& task) {
225             CHECK_NULL_VOID(taskExecutor);
226             ContainerScope scope(id);
227             taskExecutor->PostTask(task, TaskExecutor::TaskType::UI);
228         };
229         director->SetUITaskRunner(func);
230         director->Init();
231         context->SetRSUIDirector(director);
232     };
233 
234     if (runArgs_.aceVersion == AceVersion::ACE_2_0) {
235         AceContainer::SetView(
236             view, window, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight, callback);
237         AceContainer::RunPage(ACE_INSTANCE_ID, UNUSED_PAGE_ID, runArgs_.url, "");
238     } else {
239         AceContainer::RunPage(ACE_INSTANCE_ID, UNUSED_PAGE_ID, runArgs_.url, "");
240         AceContainer::SetView(
241             view, window, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight, callback);
242     }
243     // Drive the native engine with the platform thread.
244     container->RunNativeEngineLoop();
245     auto pipelineContext = container->GetPipelineContext();
246     if (pipelineContext) {
247         LOGI("Set MinPlatformVersion to %{public}d", compatibleVersion_);
248         pipelineContext->SetMinPlatformVersion(compatibleVersion_);
249     }
250     container->InitializeStageAppConfig(
251         runArgs_.assetPath, bundleName_, moduleName_, compileMode_);
252     AceContainer::AddRouterChangeCallback(ACE_INSTANCE_ID, runArgs_.onRouterChange);
253     OHOS::Ace::Framework::InspectorClient::GetInstance().RegisterFastPreviewErrorCallback(runArgs_.onError);
254     // Should make it possible to update surface changes by using viewWidth and viewHeight.
255     view->NotifySurfaceChanged(runArgs_.deviceWidth, runArgs_.deviceHeight);
256     view->NotifyDensityChanged(runArgs_.deviceConfig.density);
257 }
258 
InitializeClipboard() const259 void AceAbility::InitializeClipboard() const
260 {
261     ClipboardProxy::GetInstance()->SetDelegate(std::make_unique<Platform::ClipboardProxyImpl>());
262 }
263 
OnBackPressed() const264 void AceAbility::OnBackPressed() const
265 {
266     LOGI("Process Back Pressed Event");
267     EventDispatcher::GetInstance().DispatchBackPressedEvent();
268 }
269 
OnInputEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent) const270 bool AceAbility::OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const
271 {
272     LOGI("Process MMI::PointerEvent");
273     return EventDispatcher::GetInstance().DispatchTouchEvent(pointerEvent);
274 }
275 
OnInputEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent) const276 bool AceAbility::OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const
277 {
278     LOGI("Process MMI::KeyEvent");
279     return EventDispatcher::GetInstance().DispatchKeyEvent(keyEvent);
280 }
281 
OnInputEvent(const std::shared_ptr<MMI::AxisEvent> & axisEvent) const282 bool AceAbility::OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const
283 {
284     LOGI("Process MMI::AxisEvent");
285     return false;
286 }
287 
OnInputMethodEvent(const unsigned int codePoint) const288 bool AceAbility::OnInputMethodEvent(const unsigned int codePoint) const
289 {
290     LOGI("Process Input Method Event");
291     return EventDispatcher::GetInstance().DispatchInputMethodEvent(codePoint);
292 }
293 
InitializeAppInfo()294 void AceAbility::InitializeAppInfo()
295 {
296     RefPtr<Context> context =
297         Context::CreateContext(runArgs_.projectModel == ProjectModel::STAGE, runArgs_.appResourcesPath);
298     if (runArgs_.projectModel == ProjectModel::STAGE) {
299         auto stageContext = AceType::DynamicCast<StageContext>(context);
300         CHECK_NULL_VOID(stageContext);
301         auto appInfo = stageContext->GetAppInfo();
302         CHECK_NULL_VOID(appInfo);
303         auto hapModuleInfo = stageContext->GetHapModuleInfo();
304         CHECK_NULL_VOID(hapModuleInfo);
305         bundleName_ = appInfo->GetBundleName();
306         moduleName_ = hapModuleInfo->GetModuleName();
307         compileMode_ = hapModuleInfo->GetCompileMode();
308         compatibleVersion_ = appInfo->GetMinAPIVersion();
309         auto targetVersion = appInfo->GetTargetAPIVersion();
310         AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(targetVersion));
311         auto releaseType = appInfo->GetApiReleaseType();
312         bool enablePartialUpdate = hapModuleInfo->GetPartialUpdateFlag();
313         // only app should have menubar, card don't need
314         if (!runArgs_.formsEnabled) {
315             installationFree_ = appInfo->IsInstallationFree();
316             labelId_ = hapModuleInfo->GetLabelId();
317         }
318         useNewPipeline_ = AceNewPipeJudgement::QueryAceNewPipeEnabledStage(
319             "", compatibleVersion_, targetVersion, releaseType, !enablePartialUpdate);
320     } else {
321         auto faContext = AceType::DynamicCast<FaContext>(context);
322         CHECK_NULL_VOID(faContext);
323         auto appInfo = faContext->GetAppInfo();
324         CHECK_NULL_VOID(appInfo);
325         compatibleVersion_ = appInfo->GetMinAPIVersion();
326         auto targetVersion = appInfo->GetTargetAPIVersion();
327         auto releaseType = appInfo->GetApiReleaseType();
328         useNewPipeline_ =
329             AceNewPipeJudgement::QueryAceNewPipeEnabledFA("", compatibleVersion_, targetVersion, releaseType);
330     }
331 }
332 
SetConfigChanges(const std::string & configChanges)333 void AceAbility::SetConfigChanges(const std::string& configChanges)
334 {
335     if (configChanges == "") {
336         return;
337     }
338     std::vector<std::string> configChangesSplitter;
339     OHOS::Ace::StringUtils::StringSplitter(configChanges, ',', configChangesSplitter);
340     for (const auto& singleConfig : configChangesSplitter) {
341         if (singleConfig == "locale") {
342             configChanges_.watchLocale = true;
343             continue;
344         } else if (singleConfig == "layout") {
345             configChanges_.watchLayout = true;
346             continue;
347         } else if (singleConfig == "fontSize") {
348             configChanges_.watchFontSize = true;
349             continue;
350         } else if (singleConfig == "orientation") {
351             configChanges_.watchOrientation = true;
352             continue;
353         } else if (singleConfig == "density") {
354             configChanges_.watchDensity = true;
355             continue;
356         } else {
357             LOGW("unsupported config %{public}s", singleConfig.c_str());
358         }
359     }
360 }
361 
OnConfigurationChanged(const DeviceConfig & newConfig)362 void AceAbility::OnConfigurationChanged(const DeviceConfig& newConfig)
363 {
364     if (newConfig.colorMode == runArgs_.deviceConfig.colorMode) {
365         return;
366     }
367     int32_t width = runArgs_.deviceWidth;
368     int32_t height = runArgs_.deviceHeight;
369     SurfaceChanged(runArgs_.deviceConfig.orientation, runArgs_.deviceConfig.density, width, height);
370     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
371     if (!container) {
372         LOGE("container is null, change configuration failed.");
373         return;
374     }
375     container->UpdateDeviceConfig(newConfig);
376     runArgs_.deviceConfig.colorMode = newConfig.colorMode;
377     if (container->GetType() == FrontendType::DECLARATIVE_JS) {
378         container->NativeOnConfigurationUpdated(ACE_INSTANCE_ID);
379     }
380 }
381 
SurfaceChanged(const DeviceOrientation & orientation,const double & resolution,int32_t & width,int32_t & height)382 void AceAbility::SurfaceChanged(
383     const DeviceOrientation& orientation, const double& resolution, int32_t& width, int32_t& height)
384 {
385     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
386     CHECK_NULL_VOID(container);
387     auto viewPtr = container->GetAceView();
388     CHECK_NULL_VOID(viewPtr);
389     // Need to change the window resolution and then change the rendering resolution. Otherwise, the image may not adapt
390     // to the new window after the window is modified.
391     auto context = container->GetPipelineContext();
392     CHECK_NULL_VOID(context);
393     SystemProperties::InitDeviceInfo(
394         width, height, orientation == DeviceOrientation::PORTRAIT ? 0 : 1, resolution, runArgs_.isRound);
395     DeviceConfig deviceConfig = runArgs_.deviceConfig;
396     deviceConfig.orientation = orientation;
397     deviceConfig.density = resolution;
398     container->UpdateDeviceConfig(deviceConfig);
399     viewPtr->NotifyDensityChanged(resolution);
400     viewPtr->NotifySurfaceChanged(width, height);
401     if ((orientation != runArgs_.deviceConfig.orientation && configChanges_.watchOrientation) ||
402         (resolution != runArgs_.deviceConfig.density && configChanges_.watchDensity) ||
403         ((width != runArgs_.deviceWidth || height != runArgs_.deviceHeight) && configChanges_.watchLayout)) {
404         container->NativeOnConfigurationUpdated(ACE_INSTANCE_ID);
405     }
406     runArgs_.deviceConfig.orientation = orientation;
407     runArgs_.deviceConfig.density = resolution;
408     runArgs_.deviceWidth = width;
409     runArgs_.deviceHeight = height;
410 }
411 
ReplacePage(const std::string & url,const std::string & params)412 void AceAbility::ReplacePage(const std::string& url, const std::string& params)
413 {
414     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
415     CHECK_NULL_VOID(container);
416     container->GetFrontend()->ReplacePage(url, params);
417 }
418 
LoadDocument(const std::string & url,const std::string & componentName,SystemParams & systemParams)419 void AceAbility::LoadDocument(const std::string& url, const std::string& componentName, SystemParams& systemParams)
420 {
421     AceApplicationInfo::GetInstance().ChangeLocale(systemParams.language, systemParams.region);
422     runArgs_.isRound = systemParams.isRound;
423     SurfaceChanged(systemParams.orientation, systemParams.density, systemParams.deviceWidth, systemParams.deviceHeight);
424     DeviceConfig deviceConfig = {
425         .orientation = systemParams.orientation,
426         .density = systemParams.density,
427         .deviceType = systemParams.deviceType,
428         .colorMode = systemParams.colorMode,
429     };
430     OnConfigurationChanged(deviceConfig);
431     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
432     CHECK_NULL_VOID(container);
433     container->LoadDocument(url, componentName);
434 }
435 
GetJSONTree()436 std::string AceAbility::GetJSONTree()
437 {
438     std::string jsonTreeStr;
439     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
440     CHECK_NULL_RETURN(container, "");
441     auto taskExecutor = container->GetTaskExecutor();
442     CHECK_NULL_RETURN(taskExecutor, "");
443     taskExecutor->PostSyncTask(
444         [&jsonTreeStr] { OHOS::Ace::Framework::InspectorClient::GetInstance().AssembleJSONTreeStr(jsonTreeStr); },
445         TaskExecutor::TaskType::UI);
446     return jsonTreeStr;
447 }
448 
GetDefaultJSONTree()449 std::string AceAbility::GetDefaultJSONTree()
450 {
451     std::string defaultJsonTreeStr;
452     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
453     CHECK_NULL_RETURN(container, "");
454     auto taskExecutor = container->GetTaskExecutor();
455     CHECK_NULL_RETURN(taskExecutor, "");
456     taskExecutor->PostSyncTask(
457         [&defaultJsonTreeStr] {
458             OHOS::Ace::Framework::InspectorClient::GetInstance().AssembleDefaultJSONTreeStr(defaultJsonTreeStr);
459         },
460         TaskExecutor::TaskType::UI);
461     return defaultJsonTreeStr;
462 }
463 
OperateComponent(const std::string & attrsJson)464 bool AceAbility::OperateComponent(const std::string& attrsJson)
465 {
466     LOGD("OperateComponent attrsJson %{public}s", attrsJson.c_str());
467     auto root = JsonUtil::ParseJsonString(attrsJson);
468     if (!root || !root->IsValid()) {
469         LOGE("the attrsJson is illegal json format");
470         return false;
471     }
472 
473     auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
474     if (!container) {
475         return false;
476     }
477     auto taskExecutor = container->GetTaskExecutor();
478     if (!taskExecutor) {
479         return false;
480     }
481     taskExecutor->PostTask(
482         [attrsJson, instanceId = ACE_INSTANCE_ID] {
483             ContainerScope scope(instanceId);
484             bool result = OHOS::Ace::Framework::InspectorClient::GetInstance().OperateComponent(attrsJson);
485             if (!result) {
486                 OHOS::Ace::Framework::InspectorClient::GetInstance().CallFastPreviewErrorCallback(attrsJson);
487             }
488         },
489         TaskExecutor::TaskType::UI);
490     return true;
491 }
492 
SetWindow(sptr<OHOS::Rosen::Window> rsWindow)493 void AceAbility::SetWindow(sptr<OHOS::Rosen::Window> rsWindow)
494 {
495     rsWindow_ = rsWindow;
496 }
497 
GetWindow()498 sptr<OHOS::Rosen::Window> AceAbility::GetWindow()
499 {
500     return rsWindow_;
501 }
502 
503 } // namespace OHOS::Ace::Platform
504