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 "js_scene_session_manager.h"
17
18 #include <context.h>
19 #include <js_runtime_utils.h>
20 #include "interfaces/include/ws_common.h"
21 #include "napi_common_want.h"
22 #include "native_value.h"
23 #include "pixel_map_napi.h"
24 #include "session/host/include/scene_persistence.h"
25 #include "session/host/include/scene_persistent_storage.h"
26 #include "session/host/include/session.h"
27 #include "session_manager/include/scene_session_manager.h"
28 #include <ui_content.h>
29 #include "want.h"
30 #include "window_manager_hilog.h"
31
32 #include "js_root_scene_session.h"
33 #include "js_scene_session.h"
34 #include "js_scene_utils.h"
35 #include "js_rss_session.h"
36 #include "js_window_scene_config.h"
37 #ifdef SOC_PERF_ENABLE
38 #include "socperf_client.h"
39 #endif
40 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
41 #include "res_sched_client.h"
42 #endif
43
44 namespace OHOS::Rosen {
45 using namespace AbilityRuntime;
46 namespace {
47 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "JsSceneSessionManager" };
48 constexpr int MIN_ARG_COUNT = 3;
49 constexpr int DEFAULT_ARG_COUNT = 4;
50 constexpr int ARG_INDEX_ZERO = 0;
51 constexpr int ARG_INDEX_ONE = 1;
52 constexpr int ARG_INDEX_TWO = 2;
53 constexpr int ARG_INDEX_THREE = 3;
54 constexpr int32_t RESTYPE_RECLAIM = 100001;
55 const std::string RES_PARAM_RECLAIM_TAG = "reclaimTag";
56 const std::string CREATE_SYSTEM_SESSION_CB = "createSpecificSession";
57 const std::string CREATE_KEYBOARD_SESSION_CB = "createKeyboardSession";
58 const std::string RECOVER_SCENE_SESSION_CB = "recoverSceneSession";
59 const std::string STATUS_BAR_ENABLED_CHANGE_CB = "statusBarEnabledChange";
60 const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange";
61 const std::string OUTSIDE_DOWN_EVENT_CB = "outsideDownEvent";
62 const std::string START_UI_ABILITY_ERROR = "startUIAbilityError";
63 const std::string ARG_DUMP_HELP = "-h";
64 const std::string SHIFT_FOCUS_CB = "shiftFocus";
65 const std::string CALLING_WINDOW_ID_CHANGE_CB = "callingWindowIdChange";
66 const std::string ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB = "abilityManagerCollaboratorRegistered";
67 const std::string CLOSE_TARGET_FLOAT_WINDOW_CB = "closeTargetFloatWindow";
68 const std::string START_PIP_FAILED_CB = "startPiPFailed";
69 const std::string NOTIFY_APP_USE_CONTROL_LIST_CB = "updateAppUseControl";
70
71 const std::map<std::string, ListenerFunctionType> ListenerFunctionTypeMap {
72 {CREATE_SYSTEM_SESSION_CB, ListenerFunctionType::CREATE_SYSTEM_SESSION_CB},
73 {CREATE_KEYBOARD_SESSION_CB, ListenerFunctionType::CREATE_KEYBOARD_SESSION_CB},
74 {RECOVER_SCENE_SESSION_CB, ListenerFunctionType::RECOVER_SCENE_SESSION_CB},
75 {STATUS_BAR_ENABLED_CHANGE_CB, ListenerFunctionType::STATUS_BAR_ENABLED_CHANGE_CB},
76 {OUTSIDE_DOWN_EVENT_CB, ListenerFunctionType::OUTSIDE_DOWN_EVENT_CB},
77 {SHIFT_FOCUS_CB, ListenerFunctionType::SHIFT_FOCUS_CB},
78 {CALLING_WINDOW_ID_CHANGE_CB, ListenerFunctionType::CALLING_WINDOW_ID_CHANGE_CB},
79 {START_UI_ABILITY_ERROR, ListenerFunctionType::START_UI_ABILITY_ERROR},
80 {GESTURE_NAVIGATION_ENABLED_CHANGE_CB,
81 ListenerFunctionType::GESTURE_NAVIGATION_ENABLED_CHANGE_CB},
82 {ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB, ListenerFunctionType::ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB},
83 {CLOSE_TARGET_FLOAT_WINDOW_CB, ListenerFunctionType::CLOSE_TARGET_FLOAT_WINDOW_CB},
84 {START_PIP_FAILED_CB, ListenerFunctionType::START_PIP_FAILED_CB},
85 {NOTIFY_APP_USE_CONTROL_LIST_CB, ListenerFunctionType::NOTIFY_APP_USE_CONTROL_LIST_CB},
86 };
87 } // namespace
88
Init(napi_env env,napi_value exportObj)89 napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj)
90 {
91 WLOGFI("[NAPI]");
92 if (env == nullptr || exportObj == nullptr) {
93 WLOGFE("env or exportObj is null!");
94 return nullptr;
95 }
96
97 std::unique_ptr<JsSceneSessionManager> jsSceneSessionManager = std::make_unique<JsSceneSessionManager>(env);
98 napi_wrap(env, exportObj, jsSceneSessionManager.release(), JsSceneSessionManager::Finalizer, nullptr, nullptr);
99
100 napi_set_named_property(env, exportObj, "SessionState", CreateJsSessionState(env));
101 napi_set_named_property(env, exportObj, "SessionType", SessionTypeInit(env));
102 napi_set_named_property(env, exportObj, "SubWindowModalType", SubWindowModalTypeInit(env));
103 napi_set_named_property(env, exportObj, "SceneType", SceneTypeInit(env));
104 napi_set_named_property(env, exportObj, "KeyboardGravity", KeyboardGravityInit(env));
105 napi_set_named_property(env, exportObj, "SessionSizeChangeReason", CreateJsSessionSizeChangeReason(env));
106 napi_set_named_property(env, exportObj, "StartupVisibility", CreateJsSessionStartupVisibility(env));
107 napi_set_named_property(env, exportObj, "WindowVisibility", CreateJsWindowVisibility(env));
108 napi_set_named_property(env, exportObj, "ProcessMode", CreateJsSessionProcessMode(env));
109 napi_set_named_property(env, exportObj, "PiPControlType", CreateJsSessionPiPControlType(env));
110 napi_set_named_property(env, exportObj, "PiPControlStatus", CreateJsSessionPiPControlStatus(env));
111 napi_set_named_property(env, exportObj, "Gravity", CreateJsSessionGravity(env));
112 napi_set_named_property(env, exportObj, "DragResizeType", CreateJsSessionDragResizeType(env));
113
114 const char* moduleName = "JsSceneSessionManager";
115 BindNativeFunction(env, exportObj, "getRootSceneSession", moduleName, JsSceneSessionManager::GetRootSceneSession);
116 BindNativeFunction(env, exportObj, "requestSceneSession", moduleName, JsSceneSessionManager::RequestSceneSession);
117 BindNativeFunction(env, exportObj, "updateSceneSessionWant",
118 moduleName, JsSceneSessionManager::UpdateSceneSessionWant);
119 BindNativeFunction(env, exportObj, "requestSceneSessionActivation", moduleName,
120 JsSceneSessionManager::RequestSceneSessionActivation);
121 BindNativeFunction(env, exportObj, "requestSceneSessionBackground", moduleName,
122 JsSceneSessionManager::RequestSceneSessionBackground);
123 BindNativeFunction(env, exportObj, "requestSceneSessionDestruction", moduleName,
124 JsSceneSessionManager::RequestSceneSessionDestruction);
125 BindNativeFunction(env, exportObj, "notifyForegroundInteractiveStatus", moduleName,
126 JsSceneSessionManager::NotifyForegroundInteractiveStatus);
127 BindNativeFunction(env, exportObj, "isSceneSessionValid", moduleName,
128 JsSceneSessionManager::IsSceneSessionValid);
129 BindNativeFunction(env, exportObj, "on", moduleName, JsSceneSessionManager::RegisterCallback);
130 BindNativeFunction(env, exportObj, "getWindowSceneConfig", moduleName,
131 JsSceneSessionManager::GetWindowSceneConfig);
132 BindNativeFunction(env, exportObj, "getSystemConfig", moduleName,
133 JsSceneSessionManager::GetSystemConfig);
134 BindNativeFunction(env, exportObj, "updateRotateAnimationConfig", moduleName,
135 JsSceneSessionManager::UpdateRotateAnimationConfig);
136 BindNativeFunction(env, exportObj, "processBackEvent", moduleName, JsSceneSessionManager::ProcessBackEvent);
137 BindNativeFunction(env, exportObj, "checkSceneZOrder", moduleName, JsSceneSessionManager::CheckSceneZOrder);
138 BindNativeFunction(env, exportObj, "updateFocus", moduleName, JsSceneSessionManager::UpdateFocus);
139 BindNativeFunction(env, exportObj, "initUserInfo", moduleName, JsSceneSessionManager::InitUserInfo);
140 BindNativeFunction(env, exportObj, "requestSceneSessionByCall", moduleName,
141 JsSceneSessionManager::RequestSceneSessionByCall);
142 BindNativeFunction(env, exportObj, "startAbilityBySpecified", moduleName,
143 JsSceneSessionManager::StartAbilityBySpecified);
144 BindNativeFunction(env, exportObj, "startUIAbilityBySCB", moduleName,
145 JsSceneSessionManager::StartUIAbilityBySCB);
146 BindNativeFunction(env, exportObj, "changeUIAbilityVisibilityBySCB", moduleName,
147 JsSceneSessionManager::ChangeUIAbilityVisibilityBySCB);
148 BindNativeFunction(env, exportObj, "getSessionSnapshot", moduleName,
149 JsSceneSessionManager::GetSessionSnapshotFilePath);
150 BindNativeFunction(env, exportObj, "setVmaCacheStatus", moduleName,
151 JsSceneSessionManager::SetVmaCacheStatus);
152 BindNativeFunction(env, exportObj, "InitWithRenderServiceAdded", moduleName,
153 JsSceneSessionManager::InitWithRenderServiceAdded);
154 BindNativeFunction(env, exportObj, "getAllAbilityInfo", moduleName, JsSceneSessionManager::GetAllAbilityInfos);
155 BindNativeFunction(env, exportObj, "getBatchAbilityInfos", moduleName, JsSceneSessionManager::GetBatchAbilityInfos);
156 BindNativeFunction(env, exportObj, "getAbilityInfo", moduleName, JsSceneSessionManager::GetAbilityInfo);
157 BindNativeFunction(env, exportObj, "getAllWindowVisibilityInfos", moduleName,
158 JsSceneSessionManager::GetAllWindowVisibilityInfos);
159 BindNativeFunction(env, exportObj, "prepareTerminate", moduleName, JsSceneSessionManager::PrepareTerminate);
160 BindNativeFunction(env, exportObj, "perfRequestEx", moduleName, JsSceneSessionManager::PerfRequestEx);
161 BindNativeFunction(env, exportObj, "updateWindowMode", moduleName, JsSceneSessionManager::UpdateWindowMode);
162 BindNativeFunction(env, exportObj, "getRootSceneUIContext", moduleName,
163 JsSceneSessionManager::GetRootSceneUIContext);
164 BindNativeFunction(env, exportObj, "sendTouchEvent", moduleName, JsSceneSessionManager::SendTouchEvent);
165 BindNativeFunction(env, exportObj, "addWindowDragHotArea", moduleName, JsSceneSessionManager::AddWindowDragHotArea);
166 BindNativeFunction(env, exportObj, "preloadInLakeApp", moduleName, JsSceneSessionManager::PreloadInLakeApp);
167 BindNativeFunction(env, exportObj, "requestFocusStatus", moduleName, JsSceneSessionManager::RequestFocusStatus);
168 BindNativeFunction(env, exportObj, "requestAllAppSessionUnfocus", moduleName,
169 JsSceneSessionManager::RequestAllAppSessionUnfocus);
170 BindNativeFunction(env, exportObj, "setScreenLocked", moduleName, JsSceneSessionManager::SetScreenLocked);
171 BindNativeFunction(env, exportObj, "setUserAuthPassed", moduleName, JsSceneSessionManager::SetUserAuthPassed);
172 BindNativeFunction(env, exportObj, "updateMaximizeMode", moduleName, JsSceneSessionManager::UpdateMaximizeMode);
173 BindNativeFunction(env, exportObj, "reportData", moduleName, JsSceneSessionManager::ReportData);
174 BindNativeFunction(env, exportObj, "getRssData", moduleName, JsSceneSessionManager::GetRssData);
175 BindNativeFunction(env, exportObj, "registerRssData", moduleName, JsSceneSessionManager::RegisterRssData);
176 BindNativeFunction(env, exportObj, "unregisterRssData", moduleName, JsSceneSessionManager::UnregisterRssData);
177 BindNativeFunction(env, exportObj, "updateSessionDisplayId", moduleName,
178 JsSceneSessionManager::UpdateSessionDisplayId);
179 BindNativeFunction(env, exportObj, "notifyStackEmpty", moduleName, JsSceneSessionManager::NotifyStackEmpty);
180 BindNativeFunction(env, exportObj, "notifySwitchingUser", moduleName, JsSceneSessionManager::NotifySwitchingUser);
181 BindNativeFunction(env, exportObj, "notifySessionRecoverStatus", moduleName,
182 JsSceneSessionManager::NotifySessionRecoverStatus);
183 BindNativeFunction(env, exportObj, "setStatusBarDefaultVisibilityPerDisplay", moduleName,
184 JsSceneSessionManager::SetStatusBarDefaultVisibilityPerDisplay);
185 BindNativeFunction(env, exportObj, "notifyStatusBarShowStatus", moduleName,
186 JsSceneSessionManager::NotifyStatusBarShowStatus);
187 BindNativeFunction(env, exportObj, "notifyAINavigationBarShowStatus", moduleName,
188 JsSceneSessionManager::NotifyAINavigationBarShowStatus);
189 BindNativeFunction(env, exportObj, "updateTitleInTargetPos", moduleName, JsSceneSessionManager::UpdateTitleInTargetPos);
190 BindNativeFunction(env, exportObj, "setSystemAnimatedScenes", moduleName,
191 JsSceneSessionManager::SetSystemAnimatedScenes);
192 BindNativeFunction(env, exportObj, "getSessionSnapshotPixelMap", moduleName,
193 JsSceneSessionManager::GetSessionSnapshotPixelMap);
194 BindNativeFunction(env, exportObj, "getSessionSnapshotPixelMapSync", moduleName,
195 JsSceneSessionManager::GetSessionSnapshotPixelMapSync);
196 BindNativeFunction(env, exportObj, "setAppDragResizeType", moduleName,
197 JsSceneSessionManager::SetAppDragResizeType);
198 BindNativeFunction(env, exportObj, "getCustomDecorHeight", moduleName, JsSceneSessionManager::GetCustomDecorHeight);
199 BindNativeFunction(env, exportObj, "switchFreeMultiWindow", moduleName,
200 JsSceneSessionManager::SwitchFreeMultiWindow);
201 BindNativeFunction(env, exportObj, "getFreeMultiWindowConfig", moduleName,
202 JsSceneSessionManager::GetFreeMultiWindowConfig);
203 BindNativeFunction(env, exportObj, "getIsLayoutFullScreen", moduleName,
204 JsSceneSessionManager::GetIsLayoutFullScreen);
205 BindNativeFunction(env, exportObj, "notifyEnterRecentTask", moduleName,
206 JsSceneSessionManager::NotifyEnterRecentTask);
207 BindNativeFunction(env, exportObj, "updateDisplayHookInfo", moduleName,
208 JsSceneSessionManager::UpdateDisplayHookInfo);
209 BindNativeFunction(env, exportObj, "initScheduleUtils", moduleName,
210 JsSceneSessionManager::InitScheduleUtils);
211 BindNativeFunction(env, exportObj, "setAppForceLandscapeConfig", moduleName,
212 JsSceneSessionManager::SetAppForceLandscapeConfig);
213 BindNativeFunction(env, exportObj, "updateAppHookDisplayInfo", moduleName,
214 JsSceneSessionManager::UpdateAppHookDisplayInfo);
215 BindNativeFunction(env, exportObj, "isScbCoreEnabled", moduleName,
216 JsSceneSessionManager::IsScbCoreEnabled);
217 BindNativeFunction(env, exportObj, "removeAppInfo", moduleName,
218 JsSceneSessionManager::RemoveAppInfo);
219 BindNativeFunction(env, exportObj, "getWindowPid", moduleName,
220 JsSceneSessionManager::GetWindowPid);
221 BindNativeFunction(env, exportObj, "setIsWindowRectAutoSave", moduleName,
222 JsSceneSessionManager::SetIsWindowRectAutoSave);
223 BindNativeFunction(env, exportObj, "notifyAboveLockScreen", moduleName,
224 JsSceneSessionManager::NotifyAboveLockScreen);
225 return NapiGetUndefined(env);
226 }
227
JsSceneSessionManager(napi_env env)228 JsSceneSessionManager::JsSceneSessionManager(napi_env env) : env_(env)
229 {
230 taskScheduler_ = std::make_shared<MainThreadScheduler>(env);
231 }
232
OnCreateSystemSession(const sptr<SceneSession> & sceneSession)233 void JsSceneSessionManager::OnCreateSystemSession(const sptr<SceneSession>& sceneSession)
234 {
235 if (sceneSession == nullptr) {
236 TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]sceneSession is nullptr");
237 return;
238 }
239 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]found callback, id: %{public}d", sceneSession->GetPersistentId());
240 wptr<SceneSession> weakSession(sceneSession);
241 auto task = [this, weakSession, jsCallBack = GetJSCallback(CREATE_SYSTEM_SESSION_CB), env = env_]() {
242 if (jsCallBack == nullptr) {
243 WLOGFE("[NAPI]jsCallBack is nullptr");
244 return;
245 }
246 auto specificSession = weakSession.promote();
247 if (specificSession == nullptr) {
248 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]specific session is nullptr");
249 return;
250 }
251 napi_value jsSceneSessionObj = JsSceneSession::Create(env, specificSession);
252 if (jsSceneSessionObj == nullptr) {
253 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]jsSceneSessionObj is nullptr");
254 return;
255 }
256 napi_value argv[] = {jsSceneSessionObj};
257 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
258 };
259 taskScheduler_->PostMainThreadTask(task, "OnCreateSystemSession");
260 }
261
OnCreateKeyboardSession(const sptr<SceneSession> & keyboardSession,const sptr<SceneSession> & panelSession)262 void JsSceneSessionManager::OnCreateKeyboardSession(const sptr<SceneSession>& keyboardSession,
263 const sptr<SceneSession>& panelSession)
264 {
265 if (keyboardSession == nullptr || panelSession == nullptr) {
266 TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboard or panel session is nullptr");
267 return;
268 }
269
270 TLOGI(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboardId: %{public}d, panelId: %{public}d",
271 keyboardSession->GetPersistentId(), panelSession->GetPersistentId());
272 wptr<SceneSession> weakKeyboardSession(keyboardSession);
273 wptr<SceneSession> weakPanelSession(panelSession);
274 auto task = [this, weakKeyboardSession, weakPanelSession,
275 jsCallBack = GetJSCallback(CREATE_KEYBOARD_SESSION_CB), env = env_]() {
276 if (!jsCallBack) {
277 TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]jsCallBack is nullptr");
278 return;
279 }
280 auto keyboardSession = weakKeyboardSession.promote();
281 auto panelSession = weakPanelSession.promote();
282 if (keyboardSession == nullptr || panelSession == nullptr) {
283 TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboard or panel session is nullptr");
284 return;
285 }
286 napi_value keyboardSessionObj = JsSceneSession::Create(env, keyboardSession);
287 if (keyboardSessionObj == nullptr) {
288 TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboardSessionObj is nullptr");
289 return;
290 }
291 napi_value panelSessionObj = JsSceneSession::Create(env, panelSession);
292 if (panelSessionObj == nullptr) {
293 TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]panelSessionObj is nullptr");
294 return;
295 }
296 napi_value argv[] = { keyboardSessionObj, panelSessionObj };
297 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
298 };
299 taskScheduler_->PostMainThreadTask(task, "OnCreateKeyboardSession");
300 }
301
OnRecoverSceneSession(const sptr<SceneSession> & sceneSession,const SessionInfo & info)302 void JsSceneSessionManager::OnRecoverSceneSession(const sptr<SceneSession>& sceneSession, const SessionInfo& info)
303 {
304 if (sceneSession == nullptr) {
305 WLOGFI("[NAPI]sceneSession is nullptr");
306 return;
307 }
308
309 WLOGFI("[NAPI]OnRecoverSceneSession");
310 wptr<SceneSession> weakSession(sceneSession);
311 std::shared_ptr<SessionInfo> sessionInfo = std::make_shared<SessionInfo>(info);
312 auto task = [this, weakSession, sessionInfo, jsCallBack = GetJSCallback(RECOVER_SCENE_SESSION_CB), env = env_]() {
313 if (jsCallBack == nullptr) {
314 WLOGFE("[NAPI]jsCallBack is nullptr");
315 return;
316 }
317 auto sceneSession = weakSession.promote();
318 if (sceneSession == nullptr) {
319 WLOGFE("[NAPI]sceneSession is nullptr");
320 return;
321 }
322 napi_value jsSceneSessionObj = JsSceneSession::Create(env, sceneSession);
323 if (jsSceneSessionObj == nullptr) {
324 WLOGFE("[NAPI]jsSceneSessionObj is nullptr");
325 return;
326 }
327 if (sessionInfo == nullptr) {
328 WLOGFE("[NAPI]sessionInfo is nullptr");
329 return;
330 }
331 napi_value jsSessionRecoverInfo =
332 CreateJsSessionRecoverInfo(env, *sessionInfo, sceneSession->GetSessionProperty());
333 if (jsSessionRecoverInfo == nullptr) {
334 WLOGFE("[NAPI]this target session info is nullptr");
335 return;
336 }
337 napi_value argv[] = { jsSceneSessionObj, jsSessionRecoverInfo };
338 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
339 };
340 WLOGFI("[NAPI]OnRecoverSceneSession post task");
341 taskScheduler_->PostMainThreadTask(task, "OnRecoverSceneSession");
342 }
343
OnRootSceneBackEvent()344 void JsSceneSessionManager::OnRootSceneBackEvent()
345 {
346 auto task = [rootScene = RootScene::staticRootScene_]() {
347 if (rootScene == nullptr || rootScene->GetUIContent() == nullptr) {
348 TLOGE(WmsLogTag::WMS_EVENT, "rootScene or UIContent is null");
349 return;
350 }
351 TLOGD(WmsLogTag::WMS_EVENT, "rootScene ProcessBackPressed");
352 rootScene->GetUIContent()->ProcessBackPressed();
353 };
354 taskScheduler_->PostMainThreadTask(task, "OnRootSceneBackEvent");
355 }
356
OnStatusBarEnabledUpdate(bool enable,const std::string & bundleName)357 void JsSceneSessionManager::OnStatusBarEnabledUpdate(bool enable, const std::string& bundleName)
358 {
359 TLOGI(WmsLogTag::WMS_MAIN, "enable:%{public}d bundleName:%{public}s", enable, bundleName.c_str());
360 auto task = [enable, bundleName, jsCallBack = GetJSCallback(STATUS_BAR_ENABLED_CHANGE_CB), env = env_] {
361 if (jsCallBack == nullptr) {
362 WLOGFE("[NAPI]jsCallBack is nullptr");
363 return;
364 }
365 napi_value argv[] = {CreateJsValue(env, enable), CreateJsValue(env, bundleName)};
366 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
367 };
368 taskScheduler_->PostMainThreadTask(task, "OnStatusBarEnabledUpdate, Enable" + std::to_string(enable));
369 }
370
OnGestureNavigationEnabledUpdate(bool enable,const std::string & bundleName,GestureBackType type)371 void JsSceneSessionManager::OnGestureNavigationEnabledUpdate(bool enable, const std::string& bundleName,
372 GestureBackType type)
373 {
374 TLOGI(WmsLogTag::WMS_MAIN, "enable: %{public}d bundleName: %{public}s", enable, bundleName.c_str());
375 auto task =
376 [enable, bundleName, type, jsCallBack = GetJSCallback(GESTURE_NAVIGATION_ENABLED_CHANGE_CB), env = env_] {
377 if (jsCallBack == nullptr) {
378 TLOGNE(WmsLogTag::WMS_MAIN, "jsCallBack is nullptr");
379 return;
380 }
381 napi_value argv[] = {CreateJsValue(env, enable), CreateJsValue(env, bundleName), CreateJsValue(env, type)};
382 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
383 };
384 taskScheduler_->PostMainThreadTask(task, "OnGestureNavigationEnabledUpdate" + std::to_string(enable));
385 }
386
OnStartUIAbilityError(const uint32_t errorCode)387 void JsSceneSessionManager::OnStartUIAbilityError(const uint32_t errorCode)
388 {
389 WLOGFI("[NAPI]OnStartUIAbilityError");
390
391 auto task = [this, errorCode, jsCallBack = GetJSCallback(START_UI_ABILITY_ERROR), env = env_]() {
392 if (jsCallBack == nullptr) {
393 WLOGFE("[NAPI]jsCallBack is nullptr");
394 return;
395 }
396 napi_value argv[] = {CreateJsValue(env, errorCode)};
397 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
398 };
399 taskScheduler_->PostMainThreadTask(task, "OnStartUIAbilityError, errorCode: " + std::to_string(errorCode));
400 }
401
OnOutsideDownEvent(int32_t x,int32_t y)402 void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y)
403 {
404 WLOGFD("[NAPI]OnOutsideDownEvent");
405
406 auto task = [this, x, y, jsCallBack = GetJSCallback(OUTSIDE_DOWN_EVENT_CB), env = env_]() {
407 if (jsCallBack == nullptr) {
408 WLOGFE("[NAPI]jsCallBack is nullptr");
409 return;
410 }
411 napi_value objValue = nullptr;
412 napi_create_object(env, &objValue);
413 if (objValue == nullptr) {
414 WLOGFE("[NAPI]Object is null!");
415 return;
416 }
417
418 napi_set_named_property(env, objValue, "x", CreateJsValue(env_, x));
419 napi_set_named_property(env, objValue, "y", CreateJsValue(env_, y));
420 napi_value argv[] = {objValue};
421 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
422 };
423 std::string info = "OnOutsideDownEvent:[" + std::to_string(x) + ", " + std::to_string(y) + "]";
424 taskScheduler_->PostMainThreadTask(task, info);
425 }
426
OnShiftFocus(int32_t persistentId)427 void JsSceneSessionManager::OnShiftFocus(int32_t persistentId)
428 {
429 TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]OnShiftFocus");
430
431 auto task = [this, persistentId, jsCallBack = GetJSCallback(SHIFT_FOCUS_CB), env = env_]() {
432 if (jsCallBack == nullptr) {
433 WLOGFE("[NAPI]jsCallBack is nullptr");
434 return;
435 }
436 napi_value argv[] = {CreateJsValue(env, persistentId)};
437 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
438 };
439 taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId));
440 }
441
OnCallingSessionIdChange(uint32_t sessionId)442 void JsSceneSessionManager::OnCallingSessionIdChange(uint32_t sessionId)
443 {
444 TLOGD(WmsLogTag::WMS_KEYBOARD, "[NAPI]OnCallingSessionIdChange");
445 auto task = [this, sessionId, jsCallBack = GetJSCallback(CALLING_WINDOW_ID_CHANGE_CB), env = env_]() {
446 if (jsCallBack == nullptr) {
447 WLOGFE("[NAPI]jsCallBack is nullptr");
448 return;
449 }
450 napi_value argv[] = { CreateJsValue(env, sessionId) };
451 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
452 };
453 taskScheduler_->PostMainThreadTask(task, "OnCallingSessionIdChange, sessionId:" + std::to_string(sessionId));
454 }
455
OnAbilityManagerCollaboratorRegistered()456 void JsSceneSessionManager::OnAbilityManagerCollaboratorRegistered()
457 {
458 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
459 const char* const where = __func__;
460 auto task = [jsCallBack = GetJSCallback(ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB), env = env_, where] {
461 if (jsCallBack == nullptr) {
462 TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s: jsCallBack is nullptr", where);
463 return;
464 }
465 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), 0, {}, nullptr);
466 };
467 taskScheduler_->PostMainThreadTask(task, where);
468 }
469
OnStartPiPFailed()470 void JsSceneSessionManager::OnStartPiPFailed()
471 {
472 TLOGD(WmsLogTag::WMS_PIP, "[NAPI]");
473 auto task = [jsCallBack = GetJSCallback(START_PIP_FAILED_CB), env = env_] {
474 if (jsCallBack == nullptr) {
475 TLOGNE(WmsLogTag::WMS_PIP, "jsCallBack is nullptr");
476 return;
477 }
478 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), 0, {}, nullptr);
479 };
480 taskScheduler_->PostMainThreadTask(task, __func__);
481 }
482
ProcessCreateSystemSessionRegister()483 void JsSceneSessionManager::ProcessCreateSystemSessionRegister()
484 {
485 NotifyCreateSystemSessionFunc func = [this](const sptr<SceneSession>& session) {
486 TLOGI(WmsLogTag::WMS_SYSTEM, "NotifyCreateSystemSessionFunc");
487 this->OnCreateSystemSession(session);
488 };
489 SceneSessionManager::GetInstance().SetCreateSystemSessionListener(func);
490 }
491
ProcessCreateKeyboardSessionRegister()492 void JsSceneSessionManager::ProcessCreateKeyboardSessionRegister()
493 {
494 NotifyCreateKeyboardSessionFunc func = [this](const sptr<SceneSession>& keyboardSession,
495 const sptr<SceneSession>& panelSession) {
496 this->OnCreateKeyboardSession(keyboardSession, panelSession);
497 };
498 SceneSessionManager::GetInstance().SetCreateKeyboardSessionListener(func);
499 }
500
ProcessStartUIAbilityErrorRegister()501 void JsSceneSessionManager::ProcessStartUIAbilityErrorRegister()
502 {
503 ProcessStartUIAbilityErrorFunc func = [this](uint32_t startUIAbilityError) {
504 WLOGFD("ProcessStartUIAbilityErrorFunc called, startUIAbilityError: %{public}d", startUIAbilityError);
505 this->OnStartUIAbilityError(startUIAbilityError);
506 };
507 SceneSessionManager::GetInstance().SetStartUIAbilityErrorListener(func);
508 }
509
ProcessRecoverSceneSessionRegister()510 void JsSceneSessionManager::ProcessRecoverSceneSessionRegister()
511 {
512 NotifyRecoverSceneSessionFunc func = [this](const sptr<SceneSession>& session, const SessionInfo& sessionInfo) {
513 TLOGD(WmsLogTag::WMS_RECOVER, "RecoverSceneSession");
514 this->OnRecoverSceneSession(session, sessionInfo);
515 };
516 SceneSessionManager::GetInstance().SetRecoverSceneSessionListener(func);
517 }
518
ProcessStatusBarEnabledChangeListener()519 void JsSceneSessionManager::ProcessStatusBarEnabledChangeListener()
520 {
521 ProcessStatusBarEnabledChangeFunc func = [this](bool enable, const std::string& bundleName) {
522 WLOGFD("StatusBarEnabledUpdate");
523 this->OnStatusBarEnabledUpdate(enable, bundleName);
524 };
525 SceneSessionManager::GetInstance().SetStatusBarEnabledChangeListener(func);
526 }
527
ProcessGestureNavigationEnabledChangeListener()528 void JsSceneSessionManager::ProcessGestureNavigationEnabledChangeListener()
529 {
530 auto func = [this](bool enable, const std::string& bundleName, GestureBackType type) {
531 this->OnGestureNavigationEnabledUpdate(enable, bundleName, type);
532 };
533 SceneSessionManager::GetInstance().SetGestureNavigationEnabledChangeListener(func);
534 }
535
ProcessOutsideDownEvent()536 void JsSceneSessionManager::ProcessOutsideDownEvent()
537 {
538 ProcessOutsideDownEventFunc func = [this](int32_t x, int32_t y) {
539 WLOGFD("ProcessOutsideDownEvent called");
540 this->OnOutsideDownEvent(x, y);
541 };
542 SceneSessionManager::GetInstance().SetOutsideDownEventListener(func);
543 }
544
ProcessShiftFocus()545 void JsSceneSessionManager::ProcessShiftFocus()
546 {
547 ProcessShiftFocusFunc func = [this](int32_t persistentId) {
548 TLOGD(WmsLogTag::WMS_FOCUS, "ProcessShiftFocus called");
549 this->OnShiftFocus(persistentId);
550 };
551 NotifySCBAfterUpdateFocusFunc focusedCallback = [this]() {
552 TLOGD(WmsLogTag::WMS_FOCUS, "scb uicontent focus");
553 const auto& uiContent = RootScene::staticRootScene_->GetUIContent();
554 if (uiContent == nullptr) {
555 WLOGFE("[WMSComm]uiContent is nullptr");
556 return;
557 }
558 uiContent->Focus();
559 };
560 NotifySCBAfterUpdateFocusFunc unfocusedCallback = [this]() {
561 TLOGD(WmsLogTag::WMS_FOCUS, "scb uicontent unfocus");
562 const auto& uiContent = RootScene::staticRootScene_->GetUIContent();
563 if (uiContent == nullptr) {
564 WLOGFE("[WMSComm]uiContent is nullptr");
565 return;
566 }
567 uiContent->UnFocus();
568 };
569 SceneSessionManager::GetInstance().SetShiftFocusListener(func);
570 SceneSessionManager::GetInstance().SetSCBFocusedListener(focusedCallback);
571 SceneSessionManager::GetInstance().SetSCBUnfocusedListener(unfocusedCallback);
572 }
573
ProcessCallingSessionIdChangeRegister()574 void JsSceneSessionManager::ProcessCallingSessionIdChangeRegister()
575 {
576 ProcessCallingSessionIdChangeFunc func = [this](uint32_t callingSessionId) {
577 WLOGFD("ProcessCallingSessionIdChangeRegister called, callingSessionId: %{public}d", callingSessionId);
578 this->OnCallingSessionIdChange(callingSessionId);
579 };
580 SceneSessionManager::GetInstance().SetCallingSessionIdSessionListenser(func);
581 }
582
ProcessAbilityManagerCollaboratorRegistered()583 void JsSceneSessionManager::ProcessAbilityManagerCollaboratorRegistered()
584 {
585 auto func = [this] {
586 this->OnAbilityManagerCollaboratorRegistered();
587 };
588 SceneSessionManager::GetInstance().SetAbilityManagerCollaboratorRegisteredFunc(func);
589 }
590
RegisterRootSceneCallbacksOnSSManager()591 void JsSceneSessionManager::RegisterRootSceneCallbacksOnSSManager()
592 {
593 RegisterDumpRootSceneElementInfoListener();
594 RegisterVirtualPixelRatioChangeListener();
595 SceneSessionManager::GetInstance().SetRootSceneProcessBackEventFunc([this] {
596 TLOGND(WmsLogTag::WMS_EVENT, "rootScene BackEvent");
597 this->OnRootSceneBackEvent();
598 });
599 SceneSessionManager::GetInstance().SetOnFlushUIParamsFunc([] {
600 RootScene::staticRootScene_->OnFlushUIParams();
601 });
602 SceneSessionManager::GetInstance().SetIsRootSceneLastFrameLayoutFinishedFunc([] {
603 return RootScene::staticRootScene_->IsLastFrameLayoutFinished();
604 });
605 }
606
RegisterSSManagerCallbacksOnRootScene()607 void JsSceneSessionManager::RegisterSSManagerCallbacksOnRootScene()
608 {
609 rootScene_->SetGetSessionRectCallback([](AvoidAreaType type) {
610 return SceneSessionManager::GetInstance().GetRootSessionAvoidSessionRect(type);
611 });
612 if (!Session::IsScbCoreEnabled()) {
613 rootScene_->SetFrameLayoutFinishCallback([] {
614 SceneSessionManager::GetInstance().NotifyUpdateRectAfterLayout();
615 SceneSessionManager::GetInstance().FlushWindowInfoToMMI();
616 });
617 }
618 RootScene::SetOnConfigurationUpdatedCallback([](const std::shared_ptr<AppExecFwk::Configuration>& configuration) {
619 SceneSessionManager::GetInstance().OnConfigurationUpdated(configuration);
620 });
621 }
622
ProcessStartPiPFailedRegister()623 void JsSceneSessionManager::ProcessStartPiPFailedRegister()
624 {
625 SceneSessionManager::GetInstance().SetStartPiPFailedListener([this] {
626 TLOGNI(WmsLogTag::WMS_PIP, "NotifyStartPiPFailedFunc");
627 this->OnStartPiPFailed();
628 });
629 }
630
RegisterCallback(napi_env env,napi_callback_info info)631 napi_value JsSceneSessionManager::RegisterCallback(napi_env env, napi_callback_info info)
632 {
633 WLOGFD("[NAPI]");
634 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
635 return (me != nullptr) ? me->OnRegisterCallback(env, info) : nullptr;
636 }
637
UpdateFocus(napi_env env,napi_callback_info info)638 napi_value JsSceneSessionManager::UpdateFocus(napi_env env, napi_callback_info info)
639 {
640 TLOGD(WmsLogTag::WMS_FOCUS, "UpdateFocus");
641 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
642 return (me != nullptr) ? me->OnUpdateFocus(env, info) : nullptr;
643 }
644
ProcessBackEvent(napi_env env,napi_callback_info info)645 napi_value JsSceneSessionManager::ProcessBackEvent(napi_env env, napi_callback_info info)
646 {
647 WLOGFI("[NAPI]");
648 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
649 return (me != nullptr) ? me->OnProcessBackEvent(env, info) : nullptr;
650 }
651
652 /** @note @window.hierarchy */
CheckSceneZOrder(napi_env env,napi_callback_info info)653 napi_value JsSceneSessionManager::CheckSceneZOrder(napi_env env, napi_callback_info info)
654 {
655 WLOGFD("[NAPI]");
656 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
657 return (me != nullptr) ? me->OnCheckSceneZOrder(env, info) : nullptr;
658 }
659
InitUserInfo(napi_env env,napi_callback_info info)660 napi_value JsSceneSessionManager::InitUserInfo(napi_env env, napi_callback_info info)
661 {
662 TLOGI(WmsLogTag::WMS_MAIN, "[NAPI]Init user info");
663 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
664 return (me != nullptr) ? me->OnInitUserInfo(env, info) : nullptr;
665 }
666
InitScheduleUtils(napi_env env,napi_callback_info info)667 napi_value JsSceneSessionManager::InitScheduleUtils(napi_env env, napi_callback_info info)
668 {
669 TLOGI(WmsLogTag::WMS_MAIN, "[NAPI]");
670 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
671 return (me != nullptr) ? me->OnInitScheduleUtils(env, info) : nullptr;
672 }
673
OnInitScheduleUtils(napi_env env,napi_callback_info info)674 napi_value JsSceneSessionManager::OnInitScheduleUtils(napi_env env, napi_callback_info info)
675 {
676 TLOGD(WmsLogTag::WMS_MAIN, "[NAPI]");
677 SceneSessionManager::GetInstance().InitScheduleUtils();
678 return NapiGetUndefined(env);
679 }
680
Finalizer(napi_env env,void * data,void * hint)681 void JsSceneSessionManager::Finalizer(napi_env env, void* data, void* hint)
682 {
683 WLOGFI("[NAPI]");
684 std::unique_ptr<JsSceneSessionManager>(static_cast<JsSceneSessionManager*>(data));
685 }
686
GetRootSceneSession(napi_env env,napi_callback_info info)687 napi_value JsSceneSessionManager::GetRootSceneSession(napi_env env, napi_callback_info info)
688 {
689 WLOGFI("[NAPI]");
690 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
691 return (me != nullptr) ? me->OnGetRootSceneSession(env, info) : nullptr;
692 }
693
RequestSceneSession(napi_env env,napi_callback_info info)694 napi_value JsSceneSessionManager::RequestSceneSession(napi_env env, napi_callback_info info)
695 {
696 WLOGFD("[NAPI]");
697 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
698 if (me == nullptr) {
699 TLOGW(WmsLogTag::WMS_LIFE, "me is null");
700 return nullptr;
701 }
702 return me->OnRequestSceneSession(env, info);
703 }
704
UpdateSceneSessionWant(napi_env env,napi_callback_info info)705 napi_value JsSceneSessionManager::UpdateSceneSessionWant(napi_env env, napi_callback_info info)
706 {
707 WLOGFD("[NAPI]");
708 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
709 return (me != nullptr) ? me->OnUpdateSceneSessionWant(env, info) : nullptr;
710 }
711
RequestSceneSessionActivation(napi_env env,napi_callback_info info)712 napi_value JsSceneSessionManager::RequestSceneSessionActivation(napi_env env, napi_callback_info info)
713 {
714 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
715 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
716 if (me == nullptr) {
717 TLOGW(WmsLogTag::WMS_LIFE, "me is null");
718 return nullptr;
719 }
720 return me->OnRequestSceneSessionActivation(env, info);
721 }
722
RequestSceneSessionBackground(napi_env env,napi_callback_info info)723 napi_value JsSceneSessionManager::RequestSceneSessionBackground(napi_env env, napi_callback_info info)
724 {
725 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
726 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
727 if (me == nullptr) {
728 TLOGW(WmsLogTag::WMS_LIFE, "me is null");
729 return nullptr;
730 }
731 return me->OnRequestSceneSessionBackground(env, info);
732 }
733
RequestSceneSessionDestruction(napi_env env,napi_callback_info info)734 napi_value JsSceneSessionManager::RequestSceneSessionDestruction(napi_env env, napi_callback_info info)
735 {
736 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
737 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
738 if (me == nullptr) {
739 TLOGW(WmsLogTag::WMS_LIFE, "me is null");
740 return nullptr;
741 }
742 return me->OnRequestSceneSessionDestruction(env, info);
743 }
744
NotifyForegroundInteractiveStatus(napi_env env,napi_callback_info info)745 napi_value JsSceneSessionManager::NotifyForegroundInteractiveStatus(napi_env env, napi_callback_info info)
746 {
747 if (Session::IsScbCoreEnabled()) {
748 return nullptr;
749 }
750 WLOGFD("[NAPI]");
751 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
752 return (me != nullptr) ? me->OnNotifyForegroundInteractiveStatus(env, info) : nullptr;
753 }
754
IsSceneSessionValid(napi_env env,napi_callback_info info)755 napi_value JsSceneSessionManager::IsSceneSessionValid(napi_env env, napi_callback_info info)
756 {
757 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
758 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
759 return (me != nullptr) ? me->OnIsSceneSessionValid(env, info) : nullptr;
760 }
761
RequestSceneSessionByCall(napi_env env,napi_callback_info info)762 napi_value JsSceneSessionManager::RequestSceneSessionByCall(napi_env env, napi_callback_info info)
763 {
764 WLOGFD("[NAPI]");
765 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
766 return (me != nullptr) ? me->OnRequestSceneSessionByCall(env, info) : nullptr;
767 }
768
StartAbilityBySpecified(napi_env env,napi_callback_info info)769 napi_value JsSceneSessionManager::StartAbilityBySpecified(napi_env env, napi_callback_info info)
770 {
771 WLOGFD("[NAPI]");
772 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
773 return (me != nullptr) ? me->OnStartAbilityBySpecified(env, info) : nullptr;
774 }
775
StartUIAbilityBySCB(napi_env env,napi_callback_info info)776 napi_value JsSceneSessionManager::StartUIAbilityBySCB(napi_env env, napi_callback_info info)
777 {
778 WLOGFI("[NAPI]");
779 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
780 return (me != nullptr) ? me->OnStartUIAbilityBySCB(env, info) : nullptr;
781 }
782
ChangeUIAbilityVisibilityBySCB(napi_env env,napi_callback_info info)783 napi_value JsSceneSessionManager::ChangeUIAbilityVisibilityBySCB(napi_env env, napi_callback_info info)
784 {
785 WLOGFI("[NAPI]");
786 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
787 return (me != nullptr) ? me->OnChangeUIAbilityVisibilityBySCB(env, info) : nullptr;
788 }
789
GetWindowSceneConfig(napi_env env,napi_callback_info info)790 napi_value JsSceneSessionManager::GetWindowSceneConfig(napi_env env, napi_callback_info info)
791 {
792 WLOGFD("[NAPI]");
793 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
794 return (me != nullptr) ? me->OnGetWindowSceneConfig(env, info) : nullptr;
795 }
796
GetSystemConfig(napi_env env,napi_callback_info info)797 napi_value JsSceneSessionManager::GetSystemConfig(napi_env env, napi_callback_info info)
798 {
799 TLOGD(WmsLogTag::DEFAULT, "in");
800 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
801 return (me != nullptr) ? me->OnGetSystemConfig(env, info) : nullptr;
802 }
803
UpdateRotateAnimationConfig(napi_env env,napi_callback_info info)804 napi_value JsSceneSessionManager::UpdateRotateAnimationConfig(napi_env env, napi_callback_info info)
805 {
806 TLOGI(WmsLogTag::WMS_SCB, "[NAPI]");
807 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
808 return (me != nullptr) ? me->OnUpdateRotateAnimationConfig(env, info) : nullptr;
809 }
810
GetSessionSnapshotFilePath(napi_env env,napi_callback_info info)811 napi_value JsSceneSessionManager::GetSessionSnapshotFilePath(napi_env env, napi_callback_info info)
812 {
813 WLOGFI("[NAPI]");
814 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
815 return (me != nullptr) ? me->OnGetSessionSnapshotFilePath(env, info) : nullptr;
816 }
817
SetVmaCacheStatus(napi_env env,napi_callback_info info)818 napi_value JsSceneSessionManager::SetVmaCacheStatus(napi_env env, napi_callback_info info)
819 {
820 WLOGFI("[NAPI]");
821 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
822 return (me != nullptr) ? me->OnSetVmaCacheStatus(env, info) : nullptr;
823 }
824
InitWithRenderServiceAdded(napi_env env,napi_callback_info info)825 napi_value JsSceneSessionManager::InitWithRenderServiceAdded(napi_env env, napi_callback_info info)
826 {
827 WLOGFI("[NAPI]");
828 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
829 return (me != nullptr) ? me->OnInitWithRenderServiceAdded(env, info) : nullptr;
830 }
831
GetAllWindowVisibilityInfos(napi_env env,napi_callback_info info)832 napi_value JsSceneSessionManager::GetAllWindowVisibilityInfos(napi_env env, napi_callback_info info)
833 {
834 TLOGI(WmsLogTag::WMS_SCB, "[NAPI]");
835 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
836 return (me != nullptr) ? me->OnGetAllWindowVisibilityInfos(env, info) : nullptr;
837 }
838
SetSystemAnimatedScenes(napi_env env,napi_callback_info info)839 napi_value JsSceneSessionManager::SetSystemAnimatedScenes(napi_env env, napi_callback_info info)
840 {
841 WLOGFI("[NAPI]");
842 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
843 return (me != nullptr) ? me->OnSetSystemAnimatedScenes(env, info) : nullptr;
844 }
845
GetAllAbilityInfos(napi_env env,napi_callback_info info)846 napi_value JsSceneSessionManager::GetAllAbilityInfos(napi_env env, napi_callback_info info)
847 {
848 WLOGFD("[NAPI]");
849 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
850 return (me != nullptr) ? me->OnGetAllAbilityInfos(env, info) : nullptr;
851 }
852
GetBatchAbilityInfos(napi_env env,napi_callback_info info)853 napi_value JsSceneSessionManager::GetBatchAbilityInfos(napi_env env, napi_callback_info info)
854 {
855 TLOGI(WmsLogTag::WMS_SCB, "[NAPI]");
856 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
857 return (me != nullptr) ? me->OnGetBatchAbilityInfos(env, info) : nullptr;
858 }
859
GetAbilityInfo(napi_env env,napi_callback_info info)860 napi_value JsSceneSessionManager::GetAbilityInfo(napi_env env, napi_callback_info info)
861 {
862 TLOGD(WmsLogTag::WMS_SCB, "[NAPI]");
863 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
864 return (me != nullptr) ? me->OnGetAbilityInfo(env, info) : nullptr;
865 }
866
PrepareTerminate(napi_env env,napi_callback_info info)867 napi_value JsSceneSessionManager::PrepareTerminate(napi_env env, napi_callback_info info)
868 {
869 WLOGFD("[NAPI]");
870 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
871 return (me != nullptr) ? me->OnPrepareTerminate(env, info) : nullptr;
872 }
873
PerfRequestEx(napi_env env,napi_callback_info info)874 napi_value JsSceneSessionManager::PerfRequestEx(napi_env env, napi_callback_info info)
875 {
876 WLOGFD("[NAPI]");
877 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
878 return (me != nullptr) ? me->OnPerfRequestEx(env, info) : nullptr;
879 }
880
UpdateWindowMode(napi_env env,napi_callback_info info)881 napi_value JsSceneSessionManager::UpdateWindowMode(napi_env env, napi_callback_info info)
882 {
883 WLOGFI("[NAPI]");
884 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
885 return (me != nullptr) ? me->OnUpdateWindowMode(env, info) : nullptr;
886 }
887
AddWindowDragHotArea(napi_env env,napi_callback_info info)888 napi_value JsSceneSessionManager::AddWindowDragHotArea(napi_env env, napi_callback_info info)
889 {
890 WLOGFI("[NAPI]");
891 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
892 return (me != nullptr) ? me->OnAddWindowDragHotArea(env, info) : nullptr;
893 }
894
GetRootSceneUIContext(napi_env env,napi_callback_info info)895 napi_value JsSceneSessionManager::GetRootSceneUIContext(napi_env env, napi_callback_info info)
896 {
897 WLOGFD("[NAPI]");
898 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
899 return (me != nullptr) ? me->OnGetRootSceneUIContext(env, info) : nullptr;
900 }
901
SendTouchEvent(napi_env env,napi_callback_info info)902 napi_value JsSceneSessionManager::SendTouchEvent(napi_env env, napi_callback_info info)
903 {
904 WLOGFI("[NAPI]");
905 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
906 return (me != nullptr) ? me->OnSendTouchEvent(env, info) : nullptr;
907 }
908
PreloadInLakeApp(napi_env env,napi_callback_info info)909 napi_value JsSceneSessionManager::PreloadInLakeApp(napi_env env, napi_callback_info info)
910 {
911 WLOGFD("[NAPI]");
912 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
913 return (me != nullptr) ? me->OnPreloadInLakeApp(env, info) : nullptr;
914 }
915
RequestFocusStatus(napi_env env,napi_callback_info info)916 napi_value JsSceneSessionManager::RequestFocusStatus(napi_env env, napi_callback_info info)
917 {
918 TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]");
919 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
920 return (me != nullptr) ? me->OnRequestFocusStatus(env, info) : nullptr;
921 }
922
RequestAllAppSessionUnfocus(napi_env env,napi_callback_info info)923 napi_value JsSceneSessionManager::RequestAllAppSessionUnfocus(napi_env env, napi_callback_info info)
924 {
925 TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]");
926 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
927 return (me != nullptr) ? me->OnRequestAllAppSessionUnfocus(env, info) : nullptr;
928 }
929
SetScreenLocked(napi_env env,napi_callback_info info)930 napi_value JsSceneSessionManager::SetScreenLocked(napi_env env, napi_callback_info info)
931 {
932 WLOGFI("[NAPI]");
933 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
934 return (me != nullptr) ? me->OnSetScreenLocked(env, info) : nullptr;
935 }
936
SetUserAuthPassed(napi_env env,napi_callback_info info)937 napi_value JsSceneSessionManager::SetUserAuthPassed(napi_env env, napi_callback_info info)
938 {
939 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
940 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
941 return (me != nullptr) ? me->OnSetUserAuthPassed(env, info) : nullptr;
942 }
943
UpdateMaximizeMode(napi_env env,napi_callback_info info)944 napi_value JsSceneSessionManager::UpdateMaximizeMode(napi_env env, napi_callback_info info)
945 {
946 WLOGFI("[NAPI]");
947 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
948 return (me != nullptr) ? me->OnUpdateMaximizeMode(env, info) : nullptr;
949 }
950
ReportData(napi_env env,napi_callback_info info)951 napi_value JsSceneSessionManager::ReportData(napi_env env, napi_callback_info info)
952 {
953 WLOGFD("[NAPI]");
954 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
955 return (me != nullptr) ? me->OnReportData(env, info) : nullptr;
956 }
957
GetRssData(napi_env env,napi_callback_info info)958 napi_value JsSceneSessionManager::GetRssData(napi_env env, napi_callback_info info)
959 {
960 WLOGFD("[NAPI]");
961 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
962 return (me != nullptr) ? me->OnGetRssData(env, info) : nullptr;
963 }
964
RegisterRssData(napi_env env,napi_callback_info info)965 napi_value JsSceneSessionManager::RegisterRssData(napi_env env, napi_callback_info info)
966 {
967 WLOGFD("[NAPI]");
968 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
969 return (me != nullptr) ? me->OnRegisterRssData(env, info) : nullptr;
970 }
971
UnregisterRssData(napi_env env,napi_callback_info info)972 napi_value JsSceneSessionManager::UnregisterRssData(napi_env env, napi_callback_info info)
973 {
974 WLOGFD("[NAPI]");
975 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
976 return (me != nullptr) ? me->OnUnregisterRssData(env, info) : nullptr;
977 }
978
UpdateSessionDisplayId(napi_env env,napi_callback_info info)979 napi_value JsSceneSessionManager::UpdateSessionDisplayId(napi_env env, napi_callback_info info)
980 {
981 WLOGFI("[NAPI]");
982 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
983 return (me != nullptr) ? me->OnUpdateSessionDisplayId(env, info) : nullptr;
984 }
985
NotifyStackEmpty(napi_env env,napi_callback_info info)986 napi_value JsSceneSessionManager::NotifyStackEmpty(napi_env env, napi_callback_info info)
987 {
988 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]");
989 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
990 return (me != nullptr) ? me->OnNotifyStackEmpty(env, info) : nullptr;
991 }
992
NotifySwitchingUser(napi_env env,napi_callback_info info)993 napi_value JsSceneSessionManager::NotifySwitchingUser(napi_env env, napi_callback_info info)
994 {
995 TLOGI(WmsLogTag::WMS_MULTI_USER, "[NAPI]");
996 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
997 return (me != nullptr) ? me->OnNotifySwitchingUser(env, info) : nullptr;
998 }
999
SetStatusBarDefaultVisibilityPerDisplay(napi_env env,napi_callback_info info)1000 napi_value JsSceneSessionManager::SetStatusBarDefaultVisibilityPerDisplay(napi_env env, napi_callback_info info)
1001 {
1002 TLOGD(WmsLogTag::WMS_IMMS, "[NAPI]");
1003 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1004 return (me != nullptr) ? me->OnSetStatusBarDefaultVisibilityPerDisplay(env, info) : nullptr;
1005 }
1006
NotifyStatusBarShowStatus(napi_env env,napi_callback_info info)1007 napi_value JsSceneSessionManager::NotifyStatusBarShowStatus(napi_env env, napi_callback_info info)
1008 {
1009 TLOGD(WmsLogTag::WMS_IMMS, "[NAPI]");
1010 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1011 return (me != nullptr) ? me->OnNotifyStatusBarShowStatus(env, info) : nullptr;
1012 }
1013
NotifyAINavigationBarShowStatus(napi_env env,napi_callback_info info)1014 napi_value JsSceneSessionManager::NotifyAINavigationBarShowStatus(napi_env env, napi_callback_info info)
1015 {
1016 TLOGD(WmsLogTag::WMS_IMMS, "[NAPI]");
1017 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1018 return (me != nullptr) ? me->OnNotifyAINavigationBarShowStatus(env, info) : nullptr;
1019 }
1020
NotifySessionRecoverStatus(napi_env env,napi_callback_info info)1021 napi_value JsSceneSessionManager::NotifySessionRecoverStatus(napi_env env, napi_callback_info info)
1022 {
1023 WLOGFI("[NAPI]");
1024 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1025 return (me != nullptr) ? me->OnNotifySessionRecoverStatus(env, info) : nullptr;
1026 }
1027
UpdateTitleInTargetPos(napi_env env,napi_callback_info info)1028 napi_value JsSceneSessionManager::UpdateTitleInTargetPos(napi_env env, napi_callback_info info)
1029 {
1030 WLOGFI("[NAPI]");
1031 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1032 return (me != nullptr) ? me->OnUpdateTitleInTargetPos(env, info) : nullptr;
1033 }
1034
GetSessionSnapshotPixelMap(napi_env env,napi_callback_info info)1035 napi_value JsSceneSessionManager::GetSessionSnapshotPixelMap(napi_env env, napi_callback_info info)
1036 {
1037 WLOGFI("[NAPI]");
1038 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1039 return (me != nullptr) ? me->OnGetSessionSnapshotPixelMap(env, info) : nullptr;
1040 }
1041
GetSessionSnapshotPixelMapSync(napi_env env,napi_callback_info info)1042 napi_value JsSceneSessionManager::GetSessionSnapshotPixelMapSync(napi_env env, napi_callback_info info)
1043 {
1044 TLOGD(WmsLogTag::WMS_MAIN, "[NAPI]");
1045 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1046 return (me != nullptr) ? me->OnGetSessionSnapshotPixelMapSync(env, info) : nullptr;
1047 }
1048
SetAppDragResizeType(napi_env env,napi_callback_info info)1049 napi_value JsSceneSessionManager::SetAppDragResizeType(napi_env env, napi_callback_info info)
1050 {
1051 TLOGD(WmsLogTag::WMS_LAYOUT, "[NAPI]");
1052 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1053 return (me != nullptr) ? me->OnSetAppDragResizeType(env, info) : nullptr;
1054 }
1055
SwitchFreeMultiWindow(napi_env env,napi_callback_info info)1056 napi_value JsSceneSessionManager::SwitchFreeMultiWindow(napi_env env, napi_callback_info info)
1057 {
1058 TLOGI(WmsLogTag::WMS_LAYOUT, "[NAPI]");
1059 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1060 return (me != nullptr) ? me->OnSwitchFreeMultiWindow(env, info) : nullptr;
1061 }
1062
GetIsLayoutFullScreen(napi_env env,napi_callback_info info)1063 napi_value JsSceneSessionManager::GetIsLayoutFullScreen(napi_env env, napi_callback_info info)
1064 {
1065 WLOGFI("[NAPI]");
1066 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1067 return (me != nullptr) ? me->OnGetIsLayoutFullScreen(env, info) : nullptr;
1068 }
1069
GetFreeMultiWindowConfig(napi_env env,napi_callback_info info)1070 napi_value JsSceneSessionManager::GetFreeMultiWindowConfig(napi_env env, napi_callback_info info)
1071 {
1072 TLOGD(WmsLogTag::DEFAULT, "[NAPI]");
1073 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1074 return (me != nullptr) ? me->OnGetFreeMultiWindowConfig(env, info) : nullptr;
1075 }
1076
NotifyEnterRecentTask(napi_env env,napi_callback_info info)1077 napi_value JsSceneSessionManager::NotifyEnterRecentTask(napi_env env, napi_callback_info info)
1078 {
1079 TLOGI(WmsLogTag::WMS_LAYOUT, "[NAPI]");
1080 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1081 return (me != nullptr) ? me->OnNotifyEnterRecentTask(env, info) : nullptr;
1082 }
1083
UpdateDisplayHookInfo(napi_env env,napi_callback_info info)1084 napi_value JsSceneSessionManager::UpdateDisplayHookInfo(napi_env env, napi_callback_info info)
1085 {
1086 TLOGI(WmsLogTag::WMS_LAYOUT, "[NAPI]");
1087 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1088 return (me != nullptr) ? me->OnUpdateDisplayHookInfo(env, info) : nullptr;
1089 }
1090
UpdateAppHookDisplayInfo(napi_env env,napi_callback_info info)1091 napi_value JsSceneSessionManager::UpdateAppHookDisplayInfo(napi_env env, napi_callback_info info)
1092 {
1093 TLOGI(WmsLogTag::WMS_LAYOUT, "[NAPI]");
1094 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1095 return (me != nullptr) ? me->OnUpdateAppHookDisplayInfo(env, info) : nullptr;
1096 }
1097
IsScbCoreEnabled(napi_env env,napi_callback_info info)1098 napi_value JsSceneSessionManager::IsScbCoreEnabled(napi_env env, napi_callback_info info)
1099 {
1100 TLOGD(WmsLogTag::WMS_PIPELINE, "[NAPI]");
1101 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1102 return (me != nullptr) ? me->OnIsScbCoreEnabled(env, info) : nullptr;
1103 }
1104
RemoveAppInfo(napi_env env,napi_callback_info info)1105 napi_value JsSceneSessionManager::RemoveAppInfo(napi_env env, napi_callback_info info)
1106 {
1107 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1108 if (me == nullptr) {
1109 TLOGW(WmsLogTag::WMS_LIFE, "me is null");
1110 return nullptr;
1111 }
1112 return me->OnRemoveAppInfo(env, info);
1113 }
1114
GetWindowPid(napi_env env,napi_callback_info info)1115 napi_value JsSceneSessionManager::GetWindowPid(napi_env env, napi_callback_info info)
1116 {
1117 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1118 if (me == nullptr) {
1119 TLOGW(WmsLogTag::WMS_SCB, "me is null");
1120 return nullptr;
1121 }
1122 return me->OnGetWindowPid(env, info);
1123 }
1124
SetIsWindowRectAutoSave(napi_env env,napi_callback_info info)1125 napi_value JsSceneSessionManager::SetIsWindowRectAutoSave(napi_env env, napi_callback_info info)
1126 {
1127 TLOGD(WmsLogTag::WMS_MAIN, "[NAPI]");
1128 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1129 return (me != nullptr) ? me->OnSetIsWindowRectAutoSave(env, info) : nullptr;
1130 }
1131
NotifyAboveLockScreen(napi_env env,napi_callback_info info)1132 napi_value JsSceneSessionManager::NotifyAboveLockScreen(napi_env env, napi_callback_info info)
1133 {
1134 TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]");
1135 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
1136 return (me != nullptr) ? me->OnNotifyAboveLockScreen(env, info) : nullptr;
1137 }
1138
IsCallbackRegistered(napi_env env,const std::string & type,napi_value jsListenerObject)1139 bool JsSceneSessionManager::IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject)
1140 {
1141 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsSceneSessionManager::IsCallbackRegistered[%s]", type.c_str());
1142 std::shared_lock<std::shared_mutex> lock(jsCbMapMutex_);
1143 if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
1144 return false;
1145 }
1146
1147 for (auto iter = jsCbMap_.begin(); iter != jsCbMap_.end(); ++iter) {
1148 bool isEquals = false;
1149 napi_strict_equals(env, jsListenerObject, iter->second->GetNapiValue(), &isEquals);
1150 if (isEquals) {
1151 WLOGFE("[NAPI]Method %{public}s has already been registered", type.c_str());
1152 return true;
1153 }
1154 }
1155 return false;
1156 }
1157
OnRegisterCallback(napi_env env,napi_callback_info info)1158 napi_value JsSceneSessionManager::OnRegisterCallback(napi_env env, napi_callback_info info)
1159 {
1160 size_t argc = 4;
1161 napi_value argv[4] = {nullptr};
1162 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1163 if (argc < ARGC_TWO) {
1164 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1165 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1166 "Input parameter is missing or invalid"));
1167 return NapiGetUndefined(env);
1168 }
1169 std::string cbType;
1170 if (!ConvertFromJsValue(env, argv[0], cbType)) {
1171 WLOGFE("[NAPI]Failed to convert parameter to callbackType");
1172 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1173 "Input parameter is missing or invalid"));
1174 return NapiGetUndefined(env);
1175 }
1176 napi_value value = argv[1];
1177 if (value == nullptr || !NapiIsCallable(env, value)) {
1178 WLOGFE("[NAPI]Callback is nullptr or not callable");
1179 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1180 "Input parameter is missing or invalid"));
1181 return NapiGetUndefined(env);
1182 }
1183 if (IsCallbackRegistered(env, cbType, value)) {
1184 return NapiGetUndefined(env);
1185 }
1186 auto iterFuncType = ListenerFunctionTypeMap.find(cbType);
1187 if (iterFuncType == ListenerFunctionTypeMap.end()) {
1188 WLOGFE("Failed to find function handler! type = %{public}s", cbType.c_str());
1189 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1190 "Input parameter is missing or invalid"));
1191 return NapiGetUndefined(env);
1192 }
1193 ListenerFunctionType listenerFunctionType = iterFuncType->second;
1194 ProcessRegisterCallback(listenerFunctionType);
1195 std::shared_ptr<NativeReference> callbackRef;
1196 napi_ref result = nullptr;
1197 napi_create_reference(env, value, 1, &result);
1198 callbackRef.reset(reinterpret_cast<NativeReference*>(result));
1199 {
1200 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsSceneSessionManager set jsCbMap[%s]", cbType.c_str());
1201 std::unique_lock<std::shared_mutex> lock(jsCbMapMutex_);
1202 jsCbMap_[cbType] = callbackRef;
1203 }
1204 WLOGFD("[NAPI]end, type = %{public}s", cbType.c_str());
1205 return NapiGetUndefined(env);
1206 }
1207
ProcessRegisterCallback(ListenerFunctionType listenerFunctionType)1208 void JsSceneSessionManager::ProcessRegisterCallback(ListenerFunctionType listenerFunctionType)
1209 {
1210 switch (listenerFunctionType) {
1211 case ListenerFunctionType::CREATE_SYSTEM_SESSION_CB:
1212 ProcessCreateSystemSessionRegister();
1213 break;
1214 case ListenerFunctionType::CREATE_KEYBOARD_SESSION_CB:
1215 ProcessCreateKeyboardSessionRegister();
1216 break;
1217 case ListenerFunctionType::RECOVER_SCENE_SESSION_CB:
1218 ProcessRecoverSceneSessionRegister();
1219 break;
1220 case ListenerFunctionType::STATUS_BAR_ENABLED_CHANGE_CB:
1221 ProcessStatusBarEnabledChangeListener();
1222 break;
1223 case ListenerFunctionType::OUTSIDE_DOWN_EVENT_CB:
1224 ProcessOutsideDownEvent();
1225 break;
1226 case ListenerFunctionType::SHIFT_FOCUS_CB:
1227 ProcessShiftFocus();
1228 break;
1229 case ListenerFunctionType::CALLING_WINDOW_ID_CHANGE_CB:
1230 ProcessCallingSessionIdChangeRegister();
1231 break;
1232 case ListenerFunctionType::START_UI_ABILITY_ERROR:
1233 ProcessStartUIAbilityErrorRegister();
1234 break;
1235 case ListenerFunctionType::GESTURE_NAVIGATION_ENABLED_CHANGE_CB:
1236 ProcessGestureNavigationEnabledChangeListener();
1237 break;
1238 case ListenerFunctionType::ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB:
1239 ProcessAbilityManagerCollaboratorRegistered();
1240 break;
1241 case ListenerFunctionType::CLOSE_TARGET_FLOAT_WINDOW_CB:
1242 ProcessCloseTargetFloatWindow();
1243 break;
1244 case ListenerFunctionType::START_PIP_FAILED_CB:
1245 ProcessStartPiPFailedRegister();
1246 break;
1247 case ListenerFunctionType::NOTIFY_APP_USE_CONTROL_LIST_CB:
1248 RegisterNotifyAppUseControlListCallback();
1249 break;
1250 default:
1251 break;
1252 }
1253 }
1254
OnUpdateFocus(napi_env env,napi_callback_info info)1255 napi_value JsSceneSessionManager::OnUpdateFocus(napi_env env, napi_callback_info info)
1256 {
1257 size_t argc = 4;
1258 napi_value argv[4] = {nullptr};
1259 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1260 if (argc < ARGC_TWO) {
1261 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1262 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1263 "Input parameter is missing or invalid"));
1264 return NapiGetUndefined(env);
1265 }
1266 int32_t persistentId;
1267 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
1268 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
1269 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1270 "Input parameter is missing or invalid"));
1271 return NapiGetUndefined(env);
1272 }
1273 bool isFocused;
1274 if (!ConvertFromJsValue(env, argv[1], isFocused)) {
1275 WLOGFE("[NAPI]Failed to convert parameter to bool");
1276 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1277 "Input parameter is missing or invalid"));
1278 return NapiGetUndefined(env);
1279 }
1280 SceneSessionManager::GetInstance().UpdateFocus(persistentId, isFocused);
1281 return NapiGetUndefined(env);
1282 }
1283
OnProcessBackEvent(napi_env env,napi_callback_info info)1284 napi_value JsSceneSessionManager::OnProcessBackEvent(napi_env env, napi_callback_info info)
1285 {
1286 SceneSessionManager::GetInstance().ProcessBackEvent();
1287 return NapiGetUndefined(env);
1288 }
1289
OnCheckSceneZOrder(napi_env env,napi_callback_info info)1290 napi_value JsSceneSessionManager::OnCheckSceneZOrder(napi_env env, napi_callback_info info)
1291 {
1292 SceneSessionManager::GetInstance().CheckSceneZOrder();
1293 return NapiGetUndefined(env);
1294 }
1295
CreateWindowModes(napi_env env,const std::vector<AppExecFwk::SupportWindowMode> & windowModes)1296 static napi_value CreateWindowModes(napi_env env,
1297 const std::vector<AppExecFwk::SupportWindowMode>& windowModes)
1298 {
1299 napi_value arrayValue = nullptr;
1300 napi_create_array_with_length(env, windowModes.size(), &arrayValue);
1301 auto index = 0;
1302 for (const auto& windowMode : windowModes) {
1303 napi_set_element(env, arrayValue, index++, CreateJsValue(env, static_cast<int32_t>(windowMode)));
1304 }
1305 return arrayValue;
1306 }
1307
CreateWindowSize(napi_env env,const AppExecFwk::AbilityInfo & abilityInfo)1308 static napi_value CreateWindowSize(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo)
1309 {
1310 napi_value objValue = nullptr;
1311 napi_create_object(env, &objValue);
1312 if (objValue == nullptr) {
1313 WLOGFE("CreateObject failed");
1314 return NapiGetUndefined(env);
1315 }
1316 napi_set_named_property(env, objValue, "maxWindowRatio", CreateJsValue(env, abilityInfo.maxWindowRatio));
1317 napi_set_named_property(env, objValue, "minWindowRatio", CreateJsValue(env, abilityInfo.minWindowRatio));
1318 napi_set_named_property(env, objValue, "maxWindowWidth", CreateJsValue(env, abilityInfo.maxWindowWidth));
1319 napi_set_named_property(env, objValue, "minWindowWidth", CreateJsValue(env, abilityInfo.minWindowWidth));
1320 napi_set_named_property(env, objValue, "maxWindowHeight", CreateJsValue(env, abilityInfo.maxWindowHeight));
1321 napi_set_named_property(env, objValue, "minWindowHeight", CreateJsValue(env, abilityInfo.minWindowHeight));
1322 return objValue;
1323 }
1324
CreateAbilityItemInfo(napi_env env,const AppExecFwk::AbilityInfo & abilityInfo)1325 static napi_value CreateAbilityItemInfo(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo)
1326 {
1327 napi_value objValue = nullptr;
1328 napi_create_object(env, &objValue);
1329 if (objValue == nullptr) {
1330 WLOGFE("CreateObject failed");
1331 return NapiGetUndefined(env);
1332 }
1333 napi_set_named_property(env, objValue, "appIconId", CreateJsValue(env, abilityInfo.iconId));
1334 napi_set_named_property(env, objValue, "appLabelId", CreateJsValue(env, abilityInfo.labelId));
1335 napi_set_named_property(env, objValue, "bundleName", CreateJsValue(env, abilityInfo.bundleName));
1336 napi_set_named_property(env, objValue, "moduleName", CreateJsValue(env, abilityInfo.moduleName));
1337 napi_set_named_property(env, objValue, "name", CreateJsValue(env, abilityInfo.name));
1338 napi_set_named_property(env, objValue, "launchType",
1339 CreateJsValue(env, static_cast<int32_t>(abilityInfo.launchMode)));
1340 napi_set_named_property(env, objValue, "supportWindowModes", CreateWindowModes(env, abilityInfo.windowModes));
1341 napi_set_named_property(env, objValue, "windowSize", CreateWindowSize(env, abilityInfo));
1342 napi_set_named_property(env, objValue, "orientation",
1343 CreateJsValue(env, static_cast<int32_t>(abilityInfo.orientation)));
1344 napi_set_named_property(env, objValue, "excludeFromSession", CreateJsValue(env, abilityInfo.excludeFromMissions));
1345 napi_set_named_property(env, objValue, "unclearableSession", CreateJsValue(env, abilityInfo.unclearableMission));
1346 napi_set_named_property(env, objValue, "continuable", CreateJsValue(env, abilityInfo.continuable));
1347 napi_set_named_property(env, objValue, "removeSessionAfterTerminate",
1348 CreateJsValue(env, abilityInfo.removeMissionAfterTerminate));
1349 napi_set_named_property(env, objValue, "preferMultiWindowOrientation",
1350 CreateJsValue(env, abilityInfo.preferMultiWindowOrientation));
1351 return objValue;
1352 }
1353
CreateSCBAbilityInfo(napi_env env,const SCBAbilityInfo & scbAbilityInfo)1354 static napi_value CreateSCBAbilityInfo(napi_env env, const SCBAbilityInfo& scbAbilityInfo)
1355 {
1356 napi_value objValue = nullptr;
1357 napi_create_object(env, &objValue);
1358 if (objValue == nullptr) {
1359 WLOGFE("CreateObject failed");
1360 return NapiGetUndefined(env);
1361 }
1362 napi_set_named_property(env, objValue, "abilityItemInfo", CreateAbilityItemInfo(env, scbAbilityInfo.abilityInfo_));
1363 napi_set_named_property(env, objValue, "sdkVersion", CreateJsValue(env, scbAbilityInfo.sdkVersion_));
1364 napi_set_named_property(env, objValue, "codePath", CreateJsValue(env, scbAbilityInfo.codePath_));
1365 return objValue;
1366 }
1367
CreateAbilityInfos(napi_env env,const std::vector<SCBAbilityInfo> & scbAbilityInfos)1368 static napi_value CreateAbilityInfos(napi_env env, const std::vector<SCBAbilityInfo>& scbAbilityInfos)
1369 {
1370 napi_value arrayValue = nullptr;
1371 napi_create_array_with_length(env, scbAbilityInfos.size(), &arrayValue);
1372 auto index = 0;
1373 for (const auto& scbAbilityInfo : scbAbilityInfos) {
1374 napi_set_element(env, arrayValue, index++, CreateSCBAbilityInfo(env, scbAbilityInfo));
1375 }
1376 return arrayValue;
1377 }
1378
OnGetAllAbilityInfos(napi_env env,napi_callback_info info)1379 napi_value JsSceneSessionManager::OnGetAllAbilityInfos(napi_env env, napi_callback_info info)
1380 {
1381 size_t argc = 4;
1382 napi_value argv[4] = {nullptr};
1383 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1384 if (argc < ARGC_TWO || argc > ARGC_THREE) {
1385 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1386 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1387 "Input parameter is missing or invalid"));
1388 return NapiGetUndefined(env);
1389 }
1390 AAFwk::Want want;
1391 bool ret = OHOS::AppExecFwk::UnwrapWant(env, argv[0], want);
1392 if (!ret) {
1393 WLOGFE("[NAPI]Failed to convert parameter to want");
1394 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1395 "Input parameter is missing or invalid"));
1396 return NapiGetUndefined(env);
1397 }
1398 int32_t userId;
1399 if (!ConvertFromJsValue(env, argv[1], userId)) {
1400 WLOGFE("[NAPI]Failed to convert parameter to userId");
1401 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1402 "Input parameter is missing or invalid"));
1403 return NapiGetUndefined(env);
1404 }
1405 auto errCode = std::make_shared<int32_t>(static_cast<int32_t>(WSErrorCode::WS_OK));
1406 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1407 auto execute = [want, userId, infos = scbAbilityInfos, errCode] () {
1408 auto code = WS_JS_TO_ERROR_CODE_MAP.at(
1409 SceneSessionManager::GetInstance().GetAllAbilityInfos(want, userId, *infos));
1410 *errCode = static_cast<int32_t>(code);
1411 };
1412 auto complete = [errCode, infos = scbAbilityInfos]
1413 (napi_env env, NapiAsyncTask &task, int32_t status) {
1414 if (*errCode != static_cast<int32_t>(WSErrorCode::WS_OK)) {
1415 std::string errMsg = "invalid params can not get All AbilityInfos!";
1416 task.RejectWithCustomize(env, CreateJsValue(env, *errCode), CreateJsValue(env, errMsg));
1417 return;
1418 }
1419 task.ResolveWithCustomize(env, CreateJsValue(env, static_cast<int32_t>(WSErrorCode::WS_OK)),
1420 CreateAbilityInfos(env, *infos));
1421 };
1422 napi_value result = nullptr;
1423 napi_value callback = (argc == 2) ? nullptr : argv[2];
1424 NapiAsyncTask::Schedule("JsSceneSessionManager::OnGetAllAbilityInfos",
1425 env, CreateAsyncTaskWithLastParam(env, callback, std::move(execute), std::move(complete), &result));
1426 return result;
1427 }
1428
OnGetBatchAbilityInfos(napi_env env,napi_callback_info info)1429 napi_value JsSceneSessionManager::OnGetBatchAbilityInfos(napi_env env, napi_callback_info info)
1430 {
1431 size_t argc = 4;
1432 napi_value argv[4] = { nullptr };
1433 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1434 if (argc != ARGC_TWO) {
1435 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Argc is invalid: %{public}zu", argc);
1436 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1437 "Input parameter is missing or invalid"));
1438 return NapiGetUndefined(env);
1439 }
1440 int32_t userId;
1441 if (!ConvertFromJsValue(env, argv[0], userId)) {
1442 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to userId");
1443 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1444 "Input parameter is missing or invalid"));
1445 return NapiGetUndefined(env);
1446 }
1447 std::vector<std::string> bundleNames;
1448 if (!ParseArrayStringValue(env, argv[1], bundleNames)) {
1449 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to bundleNames");
1450 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1451 "Input parameter is missing or invalid"));
1452 return NapiGetUndefined(env);
1453 }
1454 auto errCode = std::make_shared<WSErrorCode>(WSErrorCode::WS_OK);
1455 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1456 auto execute = [bundleNames, userId, infos = scbAbilityInfos, errCode] {
1457 *errCode = WS_JS_TO_ERROR_CODE_MAP.at(
1458 SceneSessionManager::GetInstance().GetBatchAbilityInfos(bundleNames, userId, *infos));
1459 };
1460 auto complete = [errCode, infos = scbAbilityInfos](napi_env env, NapiAsyncTask& task, int32_t status) {
1461 if (*errCode != WSErrorCode::WS_OK) {
1462 std::string errMsg = "invalid params can not get batch AbilityInfos!";
1463 task.RejectWithCustomize(env, CreateJsValue(env, *errCode), CreateJsValue(env, errMsg));
1464 return;
1465 }
1466 task.ResolveWithCustomize(env, CreateJsValue(env, static_cast<int32_t>(WSErrorCode::WS_OK)),
1467 CreateAbilityInfos(env, *infos));
1468 };
1469 napi_value result = nullptr;
1470 napi_value callback = nullptr;
1471 NapiAsyncTask::Schedule("JsSceneSessionManager::OnGetBatchAbilityInfos",
1472 env, CreateAsyncTaskWithLastParam(env, callback, std::move(execute), std::move(complete), &result));
1473 return result;
1474 }
1475
OnGetAbilityInfo(napi_env env,napi_callback_info info)1476 napi_value JsSceneSessionManager::OnGetAbilityInfo(napi_env env, napi_callback_info info)
1477 {
1478 size_t argc = DEFAULT_ARG_COUNT;
1479 napi_value argv[DEFAULT_ARG_COUNT] = { nullptr };
1480 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1481 if (argc != ARGC_FOUR) {
1482 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Argc is invalid: %{public}zu", argc);
1483 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1484 "Input parameter is missing or invalid"));
1485 return NapiGetUndefined(env);
1486 }
1487 std::string bundleName;
1488 if (!ConvertFromJsValue(env, argv[0], bundleName)) {
1489 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to bundleName");
1490 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1491 "Input parameter is missing or invalid"));
1492 return NapiGetUndefined(env);
1493 }
1494 std::string moduleName;
1495 if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], moduleName)) {
1496 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to moduleName");
1497 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1498 "Input parameter is missing or invalid"));
1499 return NapiGetUndefined(env);
1500 }
1501 std::string abilityName;
1502 if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], abilityName)) {
1503 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to abilityName");
1504 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1505 "Input parameter is missing or invalid"));
1506 return NapiGetUndefined(env);
1507 }
1508 int32_t userId = 0;
1509 if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], userId)) {
1510 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to userId");
1511 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1512 "Input parameter is missing or invalid"));
1513 return NapiGetUndefined(env);
1514 }
1515 SCBAbilityInfo scbAbilityInfo;
1516 WSErrorCode ret = WS_JS_TO_ERROR_CODE_MAP.at(SceneSessionManager::GetInstance().GetAbilityInfo(
1517 bundleName, moduleName, abilityName, userId, scbAbilityInfo));
1518 if (ret != WSErrorCode::WS_OK) {
1519 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
1520 "System is abnormal"));
1521 return NapiGetUndefined(env);
1522 }
1523 return CreateSCBAbilityInfo(env, scbAbilityInfo);
1524 }
1525
OnInitUserInfo(napi_env env,napi_callback_info info)1526 napi_value JsSceneSessionManager::OnInitUserInfo(napi_env env, napi_callback_info info)
1527 {
1528 size_t argc = 4;
1529 napi_value argv[4] = {nullptr};
1530 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1531 if (argc < ARGC_TWO) {
1532 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Argc is invalid: %{public}zu", argc);
1533 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1534 "Input parameter is missing or invalid"));
1535 return NapiGetUndefined(env);
1536 }
1537 int32_t userId;
1538 if (!ConvertFromJsValue(env, argv[0], userId)) { // 1: params num
1539 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert parameter to userId");
1540 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1541 "Input parameter is missing or invalid"));
1542 return NapiGetUndefined(env);
1543 }
1544 std::string fileDir;
1545 if (!ConvertFromJsValue(env, argv[1], fileDir)) { // 2: params num
1546 TLOGE(WmsLogTag::WMS_MAIN, "NAPI]Failed to convert parameter to fileDir");
1547 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1548 "Input parameter is missing or invalid"));
1549 return NapiGetUndefined(env);
1550 }
1551 WSErrorCode ret =
1552 WS_JS_TO_ERROR_CODE_MAP.at(SceneSessionManager::GetInstance().InitUserInfo(userId, fileDir));
1553 if (ret != WSErrorCode::WS_OK) {
1554 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
1555 "System is abnormal"));
1556 }
1557 return NapiGetUndefined(env);
1558 }
1559
RegisterDumpRootSceneElementInfoListener()1560 void JsSceneSessionManager::RegisterDumpRootSceneElementInfoListener()
1561 {
1562 DumpRootSceneElementInfoFunc func = [this](const std::vector<std::string>& params,
1563 std::vector<std::string>& infos) {
1564 if (params.size() == 1 && params[0] == ARG_DUMP_HELP) { // 1: params num
1565 Ace::UIContent::ShowDumpHelp(infos);
1566 WLOGFD("Dump ArkUI help info");
1567 } else if (const auto uiContent = RootScene::staticRootScene_->GetUIContent()) {
1568 uiContent->DumpInfo(params, infos);
1569 WLOGFD("Dump ArkUI element info");
1570 }
1571 };
1572 SceneSessionManager::GetInstance().SetDumpRootSceneElementInfoListener(func);
1573 }
1574
RegisterVirtualPixelRatioChangeListener()1575 void JsSceneSessionManager::RegisterVirtualPixelRatioChangeListener()
1576 {
1577 ProcessVirtualPixelRatioChangeFunc func = [this](float density, const Rect& rect) {
1578 WLOGFI("VirtualPixelRatioChangeListener %{public}d,%{public}d,%{public}d,%{public}d; %{public}f",
1579 rect.posX_, rect.posY_, rect.width_, rect.height_, density);
1580 RootScene::staticRootScene_->SetDisplayDensity(density);
1581 RootScene::staticRootScene_->UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
1582 };
1583 SceneSessionManager::GetInstance().SetVirtualPixelRatioChangeListener(func);
1584 }
1585
OnGetRootSceneSession(napi_env env,napi_callback_info info)1586 napi_value JsSceneSessionManager::OnGetRootSceneSession(napi_env env, napi_callback_info info)
1587 {
1588 WLOGFI("in");
1589 sptr<RootSceneSession> rootSceneSession = SceneSessionManager::GetInstance().GetRootSceneSession();
1590 if (rootSceneSession == nullptr) {
1591 napi_throw(env,
1592 CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
1593 return NapiGetUndefined(env);
1594 }
1595 if (rootScene_ == nullptr) {
1596 rootScene_ = new RootScene();
1597 }
1598 RootScene::staticRootScene_ = rootScene_;
1599 rootSceneSession->SetLoadContentFunc([rootScene = rootScene_]
1600 (const std::string& contentUrl, napi_env env, napi_value storage, AbilityRuntime::Context* context) {
1601 rootScene->LoadContent(contentUrl, env, storage, context);
1602 ScenePersistentStorage::InitDir(context->GetPreferencesDir());
1603 SceneSessionManager::GetInstance().InitPersistentStorage();
1604 });
1605 RegisterRootSceneCallbacksOnSSManager();
1606 RegisterSSManagerCallbacksOnRootScene();
1607 napi_value jsRootSceneSessionObj = JsRootSceneSession::Create(env, rootSceneSession);
1608 if (jsRootSceneSessionObj == nullptr) {
1609 WLOGFE("[NAPI]jsRootSceneSessionObj is nullptr");
1610 napi_throw(env,
1611 CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
1612 return NapiGetUndefined(env);
1613 }
1614 return jsRootSceneSessionObj;
1615 }
1616
OnRequestSceneSession(napi_env env,napi_callback_info info)1617 napi_value JsSceneSessionManager::OnRequestSceneSession(napi_env env, napi_callback_info info)
1618 {
1619 TLOGD(WmsLogTag::WMS_LIFE, "in");
1620 WSErrorCode errCode = WSErrorCode::WS_OK;
1621 size_t argc = 4;
1622 napi_value argv[4] = { nullptr };
1623 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1624 if (argc < ARGC_ONE) {
1625 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1626 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1627 }
1628
1629 SessionInfo sessionInfo;
1630 AAFwk::Want want;
1631 if (errCode == WSErrorCode::WS_OK) {
1632 napi_value nativeObj = argv[0];
1633 if (nativeObj == nullptr) {
1634 WLOGFE("[NAPI]Failed to convert object to session info");
1635 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1636 } else if (!ConvertSessionInfoFromJs(env, nativeObj, sessionInfo)) {
1637 WLOGFE("[NAPI]Failed to get session info from js object");
1638 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1639 }
1640 }
1641 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
1642 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1643 "Input parameter is missing or invalid"));
1644 return NapiGetUndefined(env);
1645 }
1646 if (argc == ARGC_TWO && GetType(env, argv[1]) != napi_undefined) {
1647 OHOS::AppExecFwk::UnwrapWant(env, argv[1], want);
1648 sessionInfo.want = std::make_shared<AAFwk::Want>(want);
1649 }
1650
1651 TLOGI(WmsLogTag::WMS_MAIN, "[NAPI][%{public}s, %{public}s, %{public}s], sceneType: %{public}d, errCode=%{public}d",
1652 sessionInfo.bundleName_.c_str(), sessionInfo.moduleName_.c_str(), sessionInfo.abilityName_.c_str(),
1653 static_cast<uint32_t>(sessionInfo.sceneType_), errCode);
1654 sptr<SceneSession> sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(sessionInfo);
1655 if (sceneSession == nullptr) {
1656 napi_throw(env,
1657 CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
1658 return NapiGetUndefined(env);
1659 } else {
1660 napi_value jsSceneSessionObj = JsSceneSession::Create(env, sceneSession);
1661 if (jsSceneSessionObj == nullptr) {
1662 WLOGFE("jsSceneSessionObj is nullptr");
1663 napi_throw(env, CreateJsError(
1664 env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
1665 }
1666 return jsSceneSessionObj;
1667 }
1668 }
1669
OnUpdateSceneSessionWant(napi_env env,napi_callback_info info)1670 napi_value JsSceneSessionManager::OnUpdateSceneSessionWant(napi_env env, napi_callback_info info)
1671 {
1672 TLOGD(WmsLogTag::WMS_MAIN, "in");
1673 WSErrorCode errCode = WSErrorCode::WS_OK;
1674 size_t argc = 4;
1675 napi_value argv[4] = {nullptr};
1676 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1677 if (argc < ARGC_TWO) {
1678 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1679 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1680 }
1681
1682 SessionInfo sessionInfo;
1683 AAFwk::Want want;
1684 if (errCode == WSErrorCode::WS_OK) {
1685 napi_value nativeObj = argv[0];
1686 if (nativeObj == nullptr) {
1687 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert to session info");
1688 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1689 } else if (!ConvertSessionInfoFromJs(env, nativeObj, sessionInfo)) {
1690 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to get session info from js object");
1691 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1692 } else if (!OHOS::AppExecFwk::UnwrapWant(env, argv[1], want)) {
1693 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to get want from js object");
1694 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1695 }
1696 }
1697 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
1698 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1699 "Input parameter is missing or invalid"));
1700 return NapiGetUndefined(env);
1701 }
1702 sessionInfo.want = std::make_shared<AAFwk::Want>(want);
1703
1704 TLOGI(WmsLogTag::WMS_MAIN, "[NAPI][%{public}s, %{public}s, %{public}s, %{public}d]",
1705 sessionInfo.bundleName_.c_str(), sessionInfo.moduleName_.c_str(), sessionInfo.abilityName_.c_str(),
1706 sessionInfo.persistentId_);
1707 SceneSessionManager::GetInstance().UpdateSceneSessionWant(sessionInfo);
1708 return NapiGetUndefined(env);
1709 }
1710
OnRequestSceneSessionActivation(napi_env env,napi_callback_info info)1711 napi_value JsSceneSessionManager::OnRequestSceneSessionActivation(napi_env env, napi_callback_info info)
1712 {
1713 TLOGI(WmsLogTag::WMS_LIFE, "in");
1714 size_t argc = 4;
1715 napi_value argv[4] = {nullptr};
1716 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1717 if (argc < ARGC_TWO) {
1718 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
1719 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1720 return NapiGetUndefined(env);
1721 }
1722 napi_value jsSceneSessionObj = argv[0];
1723 if (jsSceneSessionObj == nullptr) {
1724 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get js session object");
1725 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1726 return NapiGetUndefined(env);
1727 }
1728 void* pointerResult = nullptr;
1729 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
1730 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
1731 if (jsSceneSession == nullptr) {
1732 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get session from js object");
1733 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1734 return NapiGetUndefined(env);
1735 }
1736 sptr<SceneSession> sceneSession = jsSceneSession->GetNativeSession();
1737 if (sceneSession == nullptr) {
1738 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]sceneSession is nullptr");
1739 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
1740 "sceneSession is nullptr"));
1741 return NapiGetUndefined(env);
1742 }
1743
1744 bool isNewActive = true;
1745 ConvertFromJsValue(env, argv[1], isNewActive);
1746 SceneSessionManager::GetInstance().RequestSceneSessionActivation(sceneSession, isNewActive);
1747 return NapiGetUndefined(env);
1748 }
1749
OnRequestSceneSessionBackground(napi_env env,napi_callback_info info)1750 napi_value JsSceneSessionManager::OnRequestSceneSessionBackground(napi_env env, napi_callback_info info)
1751 {
1752 TLOGI(WmsLogTag::WMS_LIFE, "in");
1753 WSErrorCode errCode = WSErrorCode::WS_OK;
1754 size_t argc = 4;
1755 napi_value argv[4] = {nullptr};
1756 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1757 if (argc < ARGC_ONE) {
1758 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
1759 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1760 }
1761
1762 sptr<SceneSession> sceneSession = nullptr;
1763 if (errCode == WSErrorCode::WS_OK) {
1764 napi_value jsSceneSessionObj = argv[0];
1765 if (jsSceneSessionObj == nullptr) {
1766 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get js scene session object");
1767 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1768 } else {
1769 void* pointerResult = nullptr;
1770 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
1771 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
1772 if (jsSceneSession == nullptr) {
1773 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get scene session from js object");
1774 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1775 } else {
1776 sceneSession = jsSceneSession->GetNativeSession();
1777 }
1778 }
1779 }
1780 if (sceneSession == nullptr) {
1781 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]sceneSession is nullptr");
1782 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
1783 "sceneSession is nullptr"));
1784 return NapiGetUndefined(env);
1785 }
1786
1787 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
1788 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1789 "Input parameter is missing or invalid"));
1790 return NapiGetUndefined(env);
1791 }
1792
1793 bool isDelegator = false;
1794 if (argc >= ARGC_TWO && GetType(env, argv[ARGC_ONE]) == napi_boolean) {
1795 ConvertFromJsValue(env, argv[ARGC_ONE], isDelegator);
1796 TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]isDelegator: %{public}u", isDelegator);
1797 }
1798
1799 bool isToDesktop = false;
1800 if (argc >= ARGC_THREE && GetType(env, argv[ARGC_TWO]) == napi_boolean) {
1801 ConvertFromJsValue(env, argv[ARGC_TWO], isToDesktop);
1802 TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]isToDesktop: %{public}u", isToDesktop);
1803 }
1804
1805 bool isSaveSnapshot = true;
1806 if (argc >= ARGC_FOUR && GetType(env, argv[ARGC_THREE]) == napi_boolean) {
1807 ConvertFromJsValue(env, argv[ARGC_THREE], isSaveSnapshot);
1808 TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]isSaveSnapshot: %{public}u", isSaveSnapshot);
1809 }
1810
1811 SceneSessionManager::GetInstance().RequestSceneSessionBackground(sceneSession, isDelegator, isToDesktop,
1812 isSaveSnapshot);
1813 return NapiGetUndefined(env);
1814 }
1815
OnRequestSceneSessionDestruction(napi_env env,napi_callback_info info)1816 napi_value JsSceneSessionManager::OnRequestSceneSessionDestruction(napi_env env,
1817 napi_callback_info info)
1818 {
1819 TLOGI(WmsLogTag::WMS_LIFE, "in");
1820 WSErrorCode errCode = WSErrorCode::WS_OK;
1821 size_t argc = 4;
1822 napi_value argv[4] = {nullptr};
1823 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1824 if (argc < ARGC_ONE) {
1825 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
1826 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1827 }
1828
1829 sptr<SceneSession> sceneSession = nullptr;
1830 JsSceneSession* jsSceneSession;
1831 if (errCode == WSErrorCode::WS_OK) {
1832 napi_value jsSceneSessionObj = argv[0];
1833 if (jsSceneSessionObj == nullptr) {
1834 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get js scene session object");
1835 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1836 } else {
1837 void* pointerResult = nullptr;
1838 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
1839 jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
1840 if (jsSceneSession == nullptr) {
1841 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get session from js object");
1842 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
1843 } else {
1844 sceneSession = jsSceneSession->GetNativeSession();
1845 SetIsClearSession(env, jsSceneSessionObj, sceneSession);
1846 }
1847 }
1848 }
1849 if (sceneSession == nullptr) {
1850 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]sceneSession is nullptr");
1851 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
1852 "sceneSession is nullptr"));
1853 return NapiGetUndefined(env);
1854 }
1855
1856 bool needRemoveSession = false;
1857 if (argc >= ARGC_TWO && GetType(env, argv[ARGC_ONE]) == napi_boolean) {
1858 if (!ConvertFromJsValue(env, argv[ARGC_ONE], needRemoveSession)) {
1859 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to needRemoveSession");
1860 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1861 "Input parameter is missing or invalid"));
1862 return NapiGetUndefined(env);
1863 }
1864 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]needRemoveSession: %{public}u", needRemoveSession);
1865 }
1866
1867 bool isSaveSnapshot = true;
1868 if (argc >= ARGC_THREE && GetType(env, argv[ARGC_TWO]) == napi_boolean) {
1869 if (!ConvertFromJsValue(env, argv[ARGC_TWO], isSaveSnapshot)) {
1870 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to isSaveSnapshot");
1871 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1872 "Input parameter is missing or invalid"));
1873 return NapiGetUndefined(env);
1874 }
1875 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]isSaveSnapshot: %{public}u", isSaveSnapshot);
1876 }
1877
1878 bool isForceClean = false;
1879 if (argc >= ARGC_FOUR && GetType(env, argv[ARGC_THREE]) == napi_boolean) {
1880 if (!ConvertFromJsValue(env, argv[ARGC_THREE], isForceClean)) {
1881 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to isForceClean");
1882 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1883 "Input parameter is missing or invalid"));
1884 return NapiGetUndefined(env);
1885 }
1886 TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]isForceClean: %{public}u", isForceClean);
1887 }
1888
1889 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
1890 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
1891 "Input parameter is missing or invalid"));
1892 return NapiGetUndefined(env);
1893 }
1894
1895 SceneSessionManager::GetInstance().RequestSceneSessionDestruction(sceneSession,
1896 needRemoveSession, isSaveSnapshot, isForceClean);
1897 auto localScheduler = SceneSessionManager::GetInstance().GetTaskScheduler();
1898 auto clearTask = [jsSceneSession, needRemoveSession, persistentId = sceneSession->GetPersistentId()]() {
1899 if (jsSceneSession != nullptr) {
1900 jsSceneSession->ClearCbMap(needRemoveSession, persistentId);
1901 }
1902 };
1903 localScheduler->PostAsyncTask(clearTask, "Clear callback Map");
1904 return NapiGetUndefined(env);
1905 }
1906
OnNotifyForegroundInteractiveStatus(napi_env env,napi_callback_info info)1907 napi_value JsSceneSessionManager::OnNotifyForegroundInteractiveStatus(napi_env env, napi_callback_info info)
1908 {
1909 TLOGI(WmsLogTag::WMS_LIFE, "in");
1910 size_t argc = 4;
1911 napi_value argv[4] = {nullptr};
1912 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1913 if (argc < ARGC_TWO) {
1914 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
1915 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1916 return NapiGetUndefined(env);
1917 }
1918
1919 napi_value jsSceneSessionObj = argv[0];
1920 if (jsSceneSessionObj == nullptr) {
1921 WLOGFE("[NAPI]Failed to get js scene session object");
1922 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1923 return NapiGetUndefined(env);
1924 }
1925 void* pointerResult = nullptr;
1926 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
1927 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
1928 if (jsSceneSession == nullptr) {
1929 WLOGFE("[NAPI]Failed to get scene session from js object");
1930 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1931 return NapiGetUndefined(env);
1932 }
1933 sptr<SceneSession> sceneSession = jsSceneSession->GetNativeSession();
1934 if (sceneSession == nullptr) {
1935 WLOGFE("[NAPI]sceneSession is nullptr");
1936 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
1937 "sceneSession is nullptr"));
1938 return NapiGetUndefined(env);
1939 }
1940
1941 bool interactive = true;
1942 ConvertFromJsValue(env, argv[1], interactive);
1943 SceneSessionManager::GetInstance().NotifyForegroundInteractiveStatus(sceneSession, interactive);
1944 return NapiGetUndefined(env);
1945 }
1946
OnIsSceneSessionValid(napi_env env,napi_callback_info info)1947 napi_value JsSceneSessionManager::OnIsSceneSessionValid(napi_env env, napi_callback_info info)
1948 {
1949 TLOGI(WmsLogTag::WMS_LIFE, "in");
1950 size_t argc = 4;
1951 napi_value argv[4] = {nullptr};
1952 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
1953 if (argc < ARGC_ONE) {
1954 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
1955 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1956 return NapiGetUndefined(env);
1957 }
1958 napi_value jsSceneSessionObj = argv[0];
1959 if (jsSceneSessionObj == nullptr) {
1960 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get js scene session object");
1961 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1962 return NapiGetUndefined(env);
1963 }
1964 void* pointerResult = nullptr;
1965 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
1966 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
1967 if (jsSceneSession == nullptr) {
1968 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to get session from js object");
1969 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM), "InputInvalid"));
1970 return NapiGetUndefined(env);
1971 }
1972 napi_value result = nullptr;
1973 sptr<SceneSession> sceneSession = jsSceneSession->GetNativeSession();
1974 napi_get_boolean(env, sceneSession != nullptr, &result);
1975 return result;
1976 }
1977
SetIsClearSession(napi_env env,napi_value jsSceneSessionObj,sptr<SceneSession> & sceneSession)1978 void JsSceneSessionManager::SetIsClearSession(napi_env env, napi_value jsSceneSessionObj,
1979 sptr<SceneSession>& sceneSession)
1980 {
1981 if (sceneSession == nullptr) {
1982 WLOGFE("[NAPI]sceneSession is null");
1983 return;
1984 }
1985 napi_value jsOperatorType = nullptr;
1986 napi_get_named_property(env, jsSceneSessionObj, "operatorType", &jsOperatorType);
1987 if (GetType(env, jsOperatorType) != napi_undefined) {
1988 int32_t operatorType = -1;
1989 if (ConvertFromJsValue(env, jsOperatorType, operatorType)) {
1990 WLOGFI("[NAPI]operatorType: %{public}d", operatorType);
1991 if (operatorType == SessionOperationType::TYPE_CLEAR) {
1992 sceneSession->SetSessionInfoIsClearSession(true);
1993 }
1994 }
1995 }
1996 }
1997
OnRequestSceneSessionByCall(napi_env env,napi_callback_info info)1998 napi_value JsSceneSessionManager::OnRequestSceneSessionByCall(napi_env env, napi_callback_info info)
1999 {
2000 TLOGI(WmsLogTag::WMS_LIFE, "in");
2001 WSErrorCode errCode = WSErrorCode::WS_OK;
2002 size_t argc = 4;
2003 napi_value argv[4] = {nullptr};
2004 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2005 if (argc < ARGC_ONE) {
2006 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2007 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2008 }
2009
2010 sptr<SceneSession> sceneSession = nullptr;
2011 if (errCode == WSErrorCode::WS_OK) {
2012 napi_value jsSceneSessionObj = argv[0];
2013 if (jsSceneSessionObj == nullptr) {
2014 WLOGFE("[NAPI]Failed to get js scene session object");
2015 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2016 } else {
2017 void* pointerResult = nullptr;
2018 napi_unwrap(env, jsSceneSessionObj, &pointerResult);
2019 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
2020 if (jsSceneSession == nullptr) {
2021 WLOGFE("[NAPI]Failed to get scene session from js object");
2022 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2023 } else {
2024 sceneSession = jsSceneSession->GetNativeSession();
2025 }
2026 }
2027 }
2028 if (sceneSession == nullptr) {
2029 WLOGFE("[NAPI]sceneSession is nullptr");
2030 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
2031 "sceneSession is nullptr"));
2032 return NapiGetUndefined(env);
2033 }
2034
2035 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
2036 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2037 "Input parameter is missing or invalid"));
2038 return NapiGetUndefined(env);
2039 }
2040
2041 SceneSessionManager::GetInstance().RequestSceneSessionByCall(sceneSession);
2042 return NapiGetUndefined(env);
2043 }
2044
OnStartAbilityBySpecified(napi_env env,napi_callback_info info)2045 napi_value JsSceneSessionManager::OnStartAbilityBySpecified(napi_env env, napi_callback_info info)
2046 {
2047 TLOGD(WmsLogTag::WMS_LIFE, "in");
2048 WSErrorCode errCode = WSErrorCode::WS_OK;
2049 size_t argc = 4;
2050 napi_value argv[4] = {nullptr};
2051 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2052 if (argc < 1) {
2053 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2054 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2055 }
2056
2057 SessionInfo sessionInfo;
2058 if (errCode == WSErrorCode::WS_OK) {
2059 napi_value nativeObj = argv[0];
2060 if (nativeObj == nullptr) {
2061 WLOGFE("[NAPI]Failed to convert object to session info");
2062 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2063 } else if (!ConvertSessionInfoFromJs(env, nativeObj, sessionInfo)) {
2064 WLOGFE("[NAPI]Failed to get session info from js object");
2065 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2066 }
2067 }
2068
2069 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
2070 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2071 "Input parameter is missing or invalid"));
2072 return NapiGetUndefined(env);
2073 }
2074
2075 AAFwk::Want want;
2076 if (OHOS::AppExecFwk::UnwrapWant(env, argv[1], want)) {
2077 sessionInfo.want = std::make_shared<AAFwk::Want>(want);
2078 }
2079
2080 WLOGFI("[NAPI][%{public}s, %{public}s, %{public}s], errCode = %{public}d",
2081 sessionInfo.bundleName_.c_str(), sessionInfo.moduleName_.c_str(), sessionInfo.abilityName_.c_str(), errCode);
2082 SceneSessionManager::GetInstance().StartAbilityBySpecified(sessionInfo);
2083 return NapiGetUndefined(env);
2084 }
2085
OnStartUIAbilityBySCB(napi_env env,napi_callback_info info)2086 napi_value JsSceneSessionManager::OnStartUIAbilityBySCB(napi_env env, napi_callback_info info)
2087 {
2088 TLOGI(WmsLogTag::WMS_LIFE, "in");
2089 WSErrorCode errCode = WSErrorCode::WS_OK;
2090 size_t argc = 4;
2091 napi_value argv[4] = {nullptr};
2092 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2093 if (argc < 1) {
2094 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2095 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2096 }
2097
2098 sptr<SceneSession> sceneSession = nullptr;
2099 if (errCode == WSErrorCode::WS_OK) {
2100 napi_value nativeObj = argv[0];
2101 if (nativeObj == nullptr) {
2102 WLOGFE("[NAPI]Failed to convert object to session info");
2103 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2104 } else {
2105 void* pointerResult = nullptr;
2106 napi_unwrap(env, nativeObj, &pointerResult);
2107 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
2108 if (jsSceneSession == nullptr) {
2109 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2110 } else {
2111 sceneSession = jsSceneSession->GetNativeSession();
2112 }
2113 }
2114 }
2115 if (sceneSession == nullptr) {
2116 WLOGFE("[NAPI]sceneSession is nullptr");
2117 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
2118 "sceneSession is nullptr"));
2119 return NapiGetUndefined(env);
2120 }
2121
2122 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
2123 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2124 "Input parameter is missing or invalid"));
2125 return NapiGetUndefined(env);
2126 }
2127
2128 SceneSessionManager::GetInstance().StartUIAbilityBySCB(sceneSession);
2129 return NapiGetUndefined(env);
2130 }
2131
OnChangeUIAbilityVisibilityBySCB(napi_env env,napi_callback_info info)2132 napi_value JsSceneSessionManager::OnChangeUIAbilityVisibilityBySCB(napi_env env, napi_callback_info info)
2133 {
2134 WLOGFI("in");
2135 WSErrorCode errCode = WSErrorCode::WS_OK;
2136 size_t argc = 4;
2137 napi_value argv[4] = {nullptr};
2138 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2139 if (argc < 1) {
2140 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2141 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2142 }
2143
2144 sptr<SceneSession> sceneSession = nullptr;
2145 if (errCode == WSErrorCode::WS_OK) {
2146 napi_value nativeObj = argv[0];
2147 if (nativeObj == nullptr) {
2148 WLOGFE("[NAPI]Failed to convert object to session info");
2149 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2150 } else {
2151 void* pointerResult = nullptr;
2152 napi_unwrap(env, nativeObj, &pointerResult);
2153 auto jsSceneSession = static_cast<JsSceneSession*>(pointerResult);
2154 if (jsSceneSession == nullptr) {
2155 errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
2156 } else {
2157 sceneSession = jsSceneSession->GetNativeSession();
2158 }
2159 }
2160 }
2161 if (sceneSession == nullptr) {
2162 WLOGFE("[NAPI]sceneSession is nullptr");
2163 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY),
2164 "sceneSession is nullptr"));
2165 return NapiGetUndefined(env);
2166 }
2167
2168 if (errCode == WSErrorCode::WS_ERROR_INVALID_PARAM) {
2169 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2170 "Input parameter is missing or invalid"));
2171 return NapiGetUndefined(env);
2172 }
2173
2174 bool visibility = true;
2175 ConvertFromJsValue(env, argv[1], visibility);
2176
2177 SceneSessionManager::GetInstance().ChangeUIAbilityVisibilityBySCB(sceneSession, visibility);
2178 return NapiGetUndefined(env);
2179 }
2180
OnGetWindowSceneConfig(napi_env env,napi_callback_info info)2181 napi_value JsSceneSessionManager::OnGetWindowSceneConfig(napi_env env, napi_callback_info info)
2182 {
2183 WLOGFD("in");
2184 const AppWindowSceneConfig& windowSceneConfig = SceneSessionManager::GetInstance().GetWindowSceneConfig();
2185 napi_value jsWindowSceneConfigObj = JsWindowSceneConfig::CreateWindowSceneConfig(env, windowSceneConfig);
2186 if (jsWindowSceneConfigObj == nullptr) {
2187 WLOGFE("[NAPI]jsWindowSceneConfigObj is nullptr");
2188 napi_throw(env, CreateJsError(env,
2189 static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
2190 }
2191 return jsWindowSceneConfigObj;
2192 }
2193
OnGetSystemConfig(napi_env env,napi_callback_info info)2194 napi_value JsSceneSessionManager::OnGetSystemConfig(napi_env env, napi_callback_info info)
2195 {
2196 TLOGD(WmsLogTag::DEFAULT, "in");
2197 const SystemSessionConfig& systemConfig = SceneSessionManager::GetInstance().GetSystemSessionConfig();
2198 napi_value jsSystemConfigObj = JsWindowSceneConfig::CreateSystemConfig(env, systemConfig);
2199 if (jsSystemConfigObj == nullptr) {
2200 TLOGE(WmsLogTag::DEFAULT, "jsSystemConfigObj is nullptr");
2201 napi_throw(env, CreateJsError(env,
2202 static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal"));
2203 }
2204 return jsSystemConfigObj;
2205 }
2206
OnUpdateRotateAnimationConfig(napi_env env,napi_callback_info info)2207 napi_value JsSceneSessionManager::OnUpdateRotateAnimationConfig(napi_env env, napi_callback_info info)
2208 {
2209 size_t argc = ARGC_FOUR;
2210 napi_value argv[ARGC_FOUR] = { nullptr };
2211 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2212 if (argc != ARGC_ONE) {
2213 TLOGE(WmsLogTag::WMS_SCB, "[NAPI]Argc is invalid: %{public}zu", argc);
2214 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2215 "Input parameter is missing or invalid"));
2216 return NapiGetUndefined(env);
2217 }
2218 RotateAnimationConfig rotateAnimationConfig;
2219 if (!ConvertRotateAnimationConfigFromJs(env, argv[0], rotateAnimationConfig)) {
2220 TLOGE(WmsLogTag::WMS_SCB, "[NAPI]Failed to convert parameter to rotateAnimationConfig.");
2221 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2222 "Input parameter is invalid."));
2223 return NapiGetUndefined(env);
2224 }
2225 SceneSessionManager::GetInstance().UpdateRotateAnimationConfig(rotateAnimationConfig);
2226 return NapiGetUndefined(env);
2227 }
2228
OnGetSessionSnapshotFilePath(napi_env env,napi_callback_info info)2229 napi_value JsSceneSessionManager::OnGetSessionSnapshotFilePath(napi_env env, napi_callback_info info)
2230 {
2231 size_t argc = 4;
2232 napi_value argv[4] = {nullptr};
2233 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2234 if (argc < 1) {
2235 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2236 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2237 "Input parameter is missing or invalid"));
2238 return NapiGetUndefined(env);
2239 }
2240 int32_t persistentId;
2241 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2242 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2243 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2244 "Input parameter is missing or invalid"));
2245 return NapiGetUndefined(env);
2246 }
2247 std::string path = SceneSessionManager::GetInstance().GetSessionSnapshotFilePath(persistentId);
2248 napi_value result = nullptr;
2249 napi_create_string_utf8(env, path.c_str(), path.length(), &result);
2250 return result;
2251 }
2252
OnSetVmaCacheStatus(napi_env env,napi_callback_info info)2253 napi_value JsSceneSessionManager::OnSetVmaCacheStatus(napi_env env, napi_callback_info info)
2254 {
2255 size_t argc = ARGC_FOUR;
2256 napi_value argv[ARGC_FOUR] = {nullptr};
2257 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2258 if (argc != ARGC_ONE) {
2259 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2260 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2261 "Input parameter is missing or invalid"));
2262 return NapiGetUndefined(env);
2263 }
2264 bool flag = false;
2265 if (!ConvertFromJsValue(env, argv[0], flag)) {
2266 WLOGFE("[NAPI]Faile to convert parameter to flag.");
2267 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2268 "Input parameter is invalid."));
2269 return NapiGetUndefined(env);
2270 }
2271 SceneSessionManager::GetInstance().SetVmaCacheStatus(flag);
2272 return NapiGetUndefined(env);
2273 }
2274
OnInitWithRenderServiceAdded(napi_env env,napi_callback_info info)2275 napi_value JsSceneSessionManager::OnInitWithRenderServiceAdded(napi_env env, napi_callback_info info)
2276 {
2277 WLOGFI("in");
2278 SceneSessionManager::GetInstance().InitWithRenderServiceAdded();
2279 return NapiGetUndefined(env);
2280 }
2281
CreateJsWindowVisibilityInfo(napi_env env,const std::pair<int32_t,uint32_t> & visibilityInfo)2282 static napi_value CreateJsWindowVisibilityInfo(napi_env env,
2283 const std::pair<int32_t, uint32_t>& visibilityInfo)
2284 {
2285 napi_value objValue = nullptr;
2286 napi_create_object(env, &objValue);
2287 if (objValue == nullptr) {
2288 TLOGE(WmsLogTag::WMS_SCB, "failed to create napi object");
2289 return NapiGetUndefined(env);
2290 }
2291 napi_set_named_property(env, objValue, "windowId",
2292 CreateJsValue(env, static_cast<int32_t>(visibilityInfo.first)));
2293 napi_set_named_property(env, objValue, "visibility",
2294 CreateJsValue(env, static_cast<int32_t>(visibilityInfo.second)));
2295 return objValue;
2296 }
2297
CreateJsWindowVisibilityInfoArray(napi_env env,const std::vector<std::pair<int32_t,uint32_t>> & visibilityInfos)2298 static napi_value CreateJsWindowVisibilityInfoArray(napi_env env,
2299 const std::vector<std::pair<int32_t, uint32_t>>& visibilityInfos)
2300 {
2301 napi_value arrayValue = nullptr;
2302 napi_create_array_with_length(env, visibilityInfos.size(), &arrayValue);
2303 if (arrayValue == nullptr) {
2304 TLOGE(WmsLogTag::WMS_SCB, "failed to create napi array");
2305 return NapiGetUndefined(env);
2306 }
2307 auto index = 0;
2308 for (const auto& visibilityInfo : visibilityInfos) {
2309 napi_set_element(env, arrayValue, index++, CreateJsWindowVisibilityInfo(env, visibilityInfo));
2310 }
2311 return arrayValue;
2312 }
2313
OnGetAllWindowVisibilityInfos(napi_env env,napi_callback_info info)2314 napi_value JsSceneSessionManager::OnGetAllWindowVisibilityInfos(napi_env env, napi_callback_info info)
2315 {
2316 auto windowVisibilityInfos = std::make_shared<std::vector<std::pair<int32_t, uint32_t>>>();
2317 if (windowVisibilityInfos == nullptr) {
2318 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
2319 "failed to create window visiblity infos"));
2320 return NapiGetUndefined(env);
2321 }
2322
2323 auto execute = [infos = windowVisibilityInfos]() {
2324 SceneSessionManager::GetInstance().GetAllWindowVisibilityInfos(*infos);
2325 };
2326 auto complete = [infos = windowVisibilityInfos]
2327 (napi_env env, NapiAsyncTask& task, int32_t status) {
2328 task.ResolveWithCustomize(env, CreateJsValue(env, static_cast<int32_t>(WSErrorCode::WS_OK)),
2329 CreateJsWindowVisibilityInfoArray(env, *infos));
2330 };
2331
2332 napi_value result = nullptr;
2333 napi_value callback = nullptr;
2334 NapiAsyncTask::Schedule("JsSceneSessionManager::OnGetAllWindowVisibilityInfos",
2335 env, CreateAsyncTaskWithLastParam(env, callback, std::move(execute), std::move(complete), &result));
2336 return result;
2337 }
2338
OnSetSystemAnimatedScenes(napi_env env,napi_callback_info info)2339 napi_value JsSceneSessionManager::OnSetSystemAnimatedScenes(napi_env env, napi_callback_info info)
2340 {
2341 size_t argc = 4;
2342 napi_value argv[4] = { nullptr };
2343 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2344 if (argc < 1) {
2345 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2346 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2347 "Input parameter is missing."));
2348 return NapiGetUndefined(env);
2349 }
2350 uint32_t sceneCode;
2351 if (!ConvertFromJsValue(env, argv[0], sceneCode)) {
2352 WLOGFE("[NAPI]Faile to convert parameter to sceneCode.");
2353 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2354 "Input parameter is invalid."));
2355 return NapiGetUndefined(env);
2356 }
2357
2358 SystemAnimatedSceneType sceneType = static_cast<SystemAnimatedSceneType>(sceneCode);
2359 WMError ret = SceneSessionManager::GetInstance().SetSystemAnimatedScenes(sceneType);
2360 if (ret != WMError::WM_OK) {
2361 WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret);
2362 WLOGFE("[NAPI]Set system animated scene failed, return %{public}d", wmErrorCode);
2363 napi_throw(env, CreateJsError(env, static_cast<int32_t>(wmErrorCode),
2364 "Set system animated scene failed."));
2365 return NapiGetUndefined(env);
2366 }
2367 WLOGFE("[NAPI]Set system animated scene succeed, return WmErrorCode::WM_OK");
2368 return NapiGetUndefined(env);
2369 }
2370
OnPrepareTerminate(napi_env env,napi_callback_info info)2371 napi_value JsSceneSessionManager::OnPrepareTerminate(napi_env env, napi_callback_info info)
2372 {
2373 TLOGI(WmsLogTag::WMS_LIFE, "in");
2374 size_t argc = 4;
2375 napi_value argv[4] = {nullptr};
2376 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2377 if (argc < 1) {
2378 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2379 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2380 "Input parameter is missing or invalid"));
2381 return NapiGetUndefined(env);
2382 }
2383 int32_t persistentId;
2384 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2385 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2386 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2387 "Input parameter is missing or invalid"));
2388 return NapiGetUndefined(env);
2389 }
2390 bool isPrepareTerminate = false;
2391 SceneSessionManager::GetInstance().PrepareTerminate(persistentId, isPrepareTerminate);
2392 napi_value result = nullptr;
2393 napi_get_boolean(env, isPrepareTerminate, &result);
2394 return result;
2395 }
2396
OnPerfRequestEx(napi_env env,napi_callback_info info)2397 napi_value JsSceneSessionManager::OnPerfRequestEx(napi_env env, napi_callback_info info)
2398 {
2399 WLOGFD("in");
2400 #ifdef SOC_PERF_ENABLE
2401 size_t argc = 4;
2402 napi_value argv[4] = {nullptr};
2403 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2404 if (argc < ARGC_TWO) {
2405 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2406 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2407 "Input parameter is missing or invalid"));
2408 return NapiGetUndefined(env);
2409 }
2410 int32_t cmdId;
2411 bool onOffTag = false;
2412 if (!ConvertFromJsValue(env, argv[0], cmdId) || !ConvertFromJsValue(env, argv[1], onOffTag)) {
2413 WLOGFE("[NAPI]Failed to convert parameter to cmdId or onOffTag");
2414 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2415 "Input parameter is missing or invalid"));
2416 return NapiGetUndefined(env);
2417 }
2418 std::string msg = "";
2419 if (argc == ARGC_THREE) {
2420 if (!ConvertFromJsValue(env, argv[ARGC_TWO], msg)) {
2421 WLOGFE("[NAPI]Failed to convert parameter to cmd msg");
2422 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2423 "Input parameter is missing or invalid"));
2424 return NapiGetUndefined(env);
2425 }
2426 }
2427 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(cmdId, onOffTag, msg);
2428 WLOGFD("[NAPI]PerfRequestEx success cmdId: %{public}d onOffTag: %{public}u msg:%{public}s",
2429 cmdId, static_cast<uint32_t>(onOffTag), msg.c_str());
2430 #endif
2431 return NapiGetUndefined(env);
2432 }
2433
OnUpdateWindowMode(napi_env env,napi_callback_info info)2434 napi_value JsSceneSessionManager::OnUpdateWindowMode(napi_env env, napi_callback_info info)
2435 {
2436 size_t argc = 4;
2437 napi_value argv[4] = {nullptr};
2438 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2439 if (argc < ARGC_TWO) {
2440 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2441 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2442 "Input parameter is missing or invalid"));
2443 return NapiGetUndefined(env);
2444 }
2445 int32_t persistentId;
2446 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2447 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2448 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2449 "Input parameter is missing or invalid"));
2450 return NapiGetUndefined(env);
2451 }
2452 int32_t windowMode;
2453 if (!ConvertFromJsValue(env, argv[1], windowMode)) {
2454 WLOGFE("[NAPI]Failed to convert parameter to windowMode");
2455 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2456 "Input parameter is missing or invalid"));
2457 return NapiGetUndefined(env);
2458 }
2459 SceneSessionManager::GetInstance().UpdateWindowMode(persistentId, windowMode);
2460 return NapiGetUndefined(env);
2461 }
2462
OnAddWindowDragHotArea(napi_env env,napi_callback_info info)2463 napi_value JsSceneSessionManager::OnAddWindowDragHotArea(napi_env env, napi_callback_info info)
2464 {
2465 size_t argc = 4;
2466 napi_value argv[4] = {nullptr};
2467 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2468 if (argc < ARGC_TWO) {
2469 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2470 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2471 "Input parameter is missing or invalid"));
2472 return NapiGetUndefined(env);
2473 }
2474 uint32_t type;
2475 if (!ConvertFromJsValue(env, argv[0], type)) {
2476 WLOGFE("[NAPI]Failed to convert parameter to type");
2477 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2478 "Input parameter is missing or invalid"));
2479 return NapiGetUndefined(env);
2480 }
2481 WSRect area;
2482 napi_value nativeObj = argv[1];
2483 if (nativeObj == nullptr || !ConvertRectInfoFromJs(env, nativeObj, area)) {
2484 WLOGFE("[NAPI]Failed to convert parameter to area");
2485 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2486 "Input parameter is missing or invalid"));
2487 return NapiGetUndefined(env);
2488 }
2489
2490 SceneSessionManager::GetInstance().AddWindowDragHotArea(type, area);
2491 return NapiGetUndefined(env);
2492 }
2493
OnGetRootSceneUIContext(napi_env env,napi_callback_info info)2494 napi_value JsSceneSessionManager::OnGetRootSceneUIContext(napi_env env, napi_callback_info info)
2495 {
2496 size_t argc = 4;
2497 napi_value argv[4] = {nullptr};
2498 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2499 if (argc >= 1) {
2500 WLOGFE("Argc is invalid: %{public}zu, expect zero params", argc);
2501 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2502 return NapiGetUndefined(env);
2503 }
2504
2505 if (RootScene::staticRootScene_ == nullptr) {
2506 WLOGFE("Root scene is nullptr");
2507 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2508 return NapiGetUndefined(env);
2509 }
2510
2511 const auto& uiContent = RootScene::staticRootScene_->GetUIContent();
2512 if (uiContent == nullptr) {
2513 WLOGFE("uiContent is nullptr");
2514 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2515 return NapiGetUndefined(env);
2516 }
2517 napi_value uiContext = uiContent->GetUINapiContext();
2518 if (uiContext == nullptr) {
2519 WLOGFE("uiContext obtained from jsEngine is nullptr");
2520 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2521 return NapiGetUndefined(env);
2522 }
2523 WLOGFD("OnGetRootSceneUIContext success");
2524 return uiContext;
2525 }
2526
OnSendTouchEvent(napi_env env,napi_callback_info info)2527 napi_value JsSceneSessionManager::OnSendTouchEvent(napi_env env, napi_callback_info info)
2528 {
2529 size_t argc = 4;
2530 napi_value argv[4] = {nullptr};
2531 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2532 if (argc != ARGC_TWO) {
2533 TLOGE(WmsLogTag::WMS_EVENT, "[NAPI]Argc is invalid: %{public}zu", argc);
2534 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2535 "Input parameter is missing or invalid"));
2536 return NapiGetUndefined(env);
2537 }
2538 napi_value nativeObj = argv[0];
2539 if (nativeObj == nullptr) {
2540 TLOGE(WmsLogTag::WMS_EVENT, "[NAPI]Failed to convert object");
2541 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2542 "Input parameter is missing or invalid"));
2543 return NapiGetUndefined(env);
2544 }
2545 auto pointerEvent = MMI::PointerEvent::Create();
2546 if (pointerEvent == nullptr) {
2547 TLOGE(WmsLogTag::WMS_EVENT, "[NAPI]Failed to create pointer event");
2548 return NapiGetUndefined(env);
2549 }
2550 if (!ConvertPointerEventFromJs(env, nativeObj, *pointerEvent)) {
2551 TLOGE(WmsLogTag::WMS_EVENT, "[NAPI]Failed to convert pointer event");
2552 return NapiGetUndefined(env);
2553 }
2554 uint32_t zIndex;
2555 if (!ConvertFromJsValue(env, argv[1], zIndex)) {
2556 TLOGE(WmsLogTag::WMS_EVENT, "[NAPI]Failed to convert parameter to zIndex");
2557 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2558 "Input parameter is missing or invalid"));
2559 return NapiGetUndefined(env);
2560 }
2561 SceneSessionManager::GetInstance().SendTouchEvent(pointerEvent, zIndex);
2562 return NapiGetUndefined(env);
2563 }
2564
OnPreloadInLakeApp(napi_env env,napi_callback_info info)2565 napi_value JsSceneSessionManager::OnPreloadInLakeApp(napi_env env, napi_callback_info info)
2566 {
2567 size_t argc = 4;
2568 napi_value argv[4] = {nullptr};
2569 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2570 if (argc != ARGC_ONE) {
2571 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2572 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2573 "Input parameter is missing or invalid"));
2574 return NapiGetUndefined(env);
2575 }
2576 std::string bundleName = "";
2577 if (!ConvertFromJsValue(env, argv[0], bundleName)) {
2578 WLOGFE("[NAPI]Failed to convert parameter to bundleName");
2579 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2580 "Input parameter is missing or invalid"));
2581 return NapiGetUndefined(env);
2582 }
2583 auto localScheduler = SceneSessionManager::GetInstance().GetTaskScheduler();
2584 auto preloadTask = [bundleName]() {
2585 SceneSessionManager::GetInstance().PreloadInLakeApp(bundleName);
2586 };
2587 localScheduler->PostAsyncTask(preloadTask);
2588 return NapiGetUndefined(env);
2589 }
2590
OnRequestFocusStatus(napi_env env,napi_callback_info info)2591 napi_value JsSceneSessionManager::OnRequestFocusStatus(napi_env env, napi_callback_info info)
2592 {
2593 size_t argc = 4;
2594 napi_value argv[4] = {nullptr};
2595 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2596 if (argc < MIN_ARG_COUNT) {
2597 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2598 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2599 "Input parameter is missing or invalid"));
2600 return NapiGetUndefined(env);
2601 }
2602 int32_t persistentId;
2603 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2604 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2605 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2606 "Input parameter is missing or invalid"));
2607 return NapiGetUndefined(env);
2608 }
2609 bool isFocused = false;
2610 if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], isFocused)) {
2611 WLOGFE("[NAPI]Failed to convert parameter to isFocused");
2612 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2613 "Input parameter is missing or invalid"));
2614 return NapiGetUndefined(env);
2615 }
2616 bool byForeground = false;
2617 if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], byForeground)) {
2618 WLOGFE("[NAPI]Failed to convert parameter to byForeground");
2619 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2620 "Input parameter is missing or invalid"));
2621 return NapiGetUndefined(env);
2622 }
2623 FocusChangeReason reason = FocusChangeReason::DEFAULT;
2624 if (argc > MIN_ARG_COUNT) {
2625 if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], reason)) {
2626 TLOGI(WmsLogTag::WMS_FOCUS, "[NAPI]Failed to convert parameter to reason");
2627 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2628 "Input parameter is missing or invalid"));
2629 return NapiGetUndefined(env);
2630 }
2631 }
2632 TLOGI(WmsLogTag::WMS_FOCUS, "[NAPI]persistentId: %{public}d, isFocused: %{public}d, byForeground: %{public}d, "
2633 "reason: %{public}d", persistentId, isFocused, byForeground, reason);
2634 if (Session::IsScbCoreEnabled()) {
2635 SceneSessionManager::GetInstance().RequestFocusStatusBySCB(persistentId, isFocused, byForeground, reason);
2636 } else {
2637 SceneSessionManager::GetInstance().RequestFocusStatus(persistentId, isFocused, byForeground, reason);
2638 }
2639 return NapiGetUndefined(env);
2640 }
2641
OnRequestAllAppSessionUnfocus(napi_env env,napi_callback_info info)2642 napi_value JsSceneSessionManager::OnRequestAllAppSessionUnfocus(napi_env env, napi_callback_info info)
2643 {
2644 size_t argc = 4;
2645 napi_value argv[4] = {nullptr};
2646 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2647 if (argc >= ARGC_ONE) {
2648 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2649 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2650 "Input parameter is missing or invalid"));
2651 return NapiGetUndefined(env);
2652 }
2653 SceneSessionManager::GetInstance().RequestAllAppSessionUnfocus();
2654 return NapiGetUndefined(env);
2655 }
2656
OnSetScreenLocked(napi_env env,napi_callback_info info)2657 napi_value JsSceneSessionManager::OnSetScreenLocked(napi_env env, napi_callback_info info)
2658 {
2659 size_t argc = 4;
2660 napi_value argv[4] = {nullptr};
2661 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2662 if (argc != ARGC_ONE) {
2663 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2664 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2665 "Input parameter is missing or invalid"));
2666 return NapiGetUndefined(env);
2667 }
2668 bool isScreenLocked = false;
2669 if (!ConvertFromJsValue(env, argv[0], isScreenLocked)) {
2670 WLOGFE("[NAPI]Failed to convert parameter to isScreenLocked");
2671 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2672 "Input parameter is missing or invalid"));
2673 return NapiGetUndefined(env);
2674 }
2675 SceneSessionManager::GetInstance().SetScreenLocked(isScreenLocked);
2676 return NapiGetUndefined(env);
2677 }
2678
OnSetUserAuthPassed(napi_env env,napi_callback_info info)2679 napi_value JsSceneSessionManager::OnSetUserAuthPassed(napi_env env, napi_callback_info info)
2680 {
2681 size_t argc = ARGC_FOUR;
2682 napi_value argv[ARGC_FOUR] = { nullptr };
2683 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2684 if (argc != ARGC_ONE) {
2685 TLOGE(WmsLogTag::WMS_LIFE, "Argc is invalid: %{public}zu", argc);
2686 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2687 "Input parameter is missing or invalid"));
2688 return NapiGetUndefined(env);
2689 }
2690 bool isUserAuthPassed = false;
2691 if (!ConvertFromJsValue(env, argv[0], isUserAuthPassed)) {
2692 TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to isUserAuthPassed");
2693 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2694 "Input parameter is missing or invalid"));
2695 return NapiGetUndefined(env);
2696 }
2697 SceneSessionManager::GetInstance().SetUserAuthPassed(isUserAuthPassed);
2698 return NapiGetUndefined(env);
2699 }
2700
OnUpdateMaximizeMode(napi_env env,napi_callback_info info)2701 napi_value JsSceneSessionManager::OnUpdateMaximizeMode(napi_env env, napi_callback_info info)
2702 {
2703 size_t argc = 4;
2704 napi_value argv[4] = {nullptr};
2705 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2706 if (argc < ARGC_TWO) {
2707 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2708 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2709 "Input parameter is missing or invalid"));
2710 return NapiGetUndefined(env);
2711 }
2712 int32_t persistentId;
2713 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2714 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2715 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2716 "Input parameter is missing or invalid"));
2717 return NapiGetUndefined(env);
2718 }
2719 bool isMaximize = false;
2720 if (!ConvertFromJsValue(env, argv[1], isMaximize)) {
2721 WLOGFE("[NAPI]Failed to convert parameter to isMaximize");
2722 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2723 "Input parameter is missing or invalid"));
2724 return NapiGetUndefined(env);
2725 }
2726 SceneSessionManager::GetInstance().UpdateMaximizeMode(persistentId, isMaximize);
2727 return NapiGetUndefined(env);
2728 }
2729
OnUpdateSessionDisplayId(napi_env env,napi_callback_info info)2730 napi_value JsSceneSessionManager::OnUpdateSessionDisplayId(napi_env env, napi_callback_info info)
2731 {
2732 size_t argc = 4;
2733 napi_value argv[4] = {nullptr};
2734 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2735 if (argc < ARGC_TWO) {
2736 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2737 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2738 "Input parameter is missing or invalid"));
2739 return NapiGetUndefined(env);
2740 }
2741 int32_t persistentId;
2742 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2743 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2744 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2745 "Input parameter is missing or invalid"));
2746 return NapiGetUndefined(env);
2747 }
2748 int32_t screenId;
2749 if (!ConvertFromJsValue(env, argv[1], screenId)) {
2750 WLOGFE("[NAPI]Failed to convert parameter to screenId");
2751 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2752 "Input parameter is missing or invalid"));
2753 return NapiGetUndefined(env);
2754 }
2755 SceneSessionManager::GetInstance().UpdateSessionDisplayId(persistentId, screenId);
2756 return NapiGetUndefined(env);
2757 }
2758
OnNotifyStackEmpty(napi_env env,napi_callback_info info)2759 napi_value JsSceneSessionManager::OnNotifyStackEmpty(napi_env env, napi_callback_info info)
2760 {
2761 size_t argc = ARGC_FOUR;
2762 napi_value argv[ARGC_FOUR] = {nullptr};
2763 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2764 if (argc != ARGC_ONE) {
2765 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
2766 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2767 "Input parameter is missing or invalid"));
2768 return NapiGetUndefined(env);
2769 }
2770 int32_t persistentId ;
2771 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2772 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to displayId");
2773 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2774 "Input parameter is missing or invalid"));
2775 return NapiGetUndefined(env);
2776 }
2777 WSErrorCode ret =
2778 WS_JS_TO_ERROR_CODE_MAP.at(SceneSessionManager::GetInstance().NotifyStackEmpty(persistentId));
2779 if (ret != WSErrorCode::WS_OK) {
2780 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Notify stack empty failed");
2781 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
2782 "System is abnormal"));
2783 }
2784 return NapiGetUndefined(env);
2785 }
2786
OnNotifySwitchingUser(napi_env env,napi_callback_info info)2787 napi_value JsSceneSessionManager::OnNotifySwitchingUser(napi_env env, napi_callback_info info)
2788 {
2789 size_t argc = 4;
2790 napi_value argv[4] = {nullptr};
2791 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2792 if (argc < ARGC_ONE) {
2793 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2794 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2795 "Input parameter is missing or invalid"));
2796 return NapiGetUndefined(env);
2797 }
2798 bool isUserActive = true;
2799 if (!ConvertFromJsValue(env, argv[0], isUserActive)) {
2800 WLOGFE("[NAPI]Failed to convert parameter to isUserActive");
2801 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2802 "Input parameter is missing or invalid"));
2803 return NapiGetUndefined(env);
2804 }
2805
2806 SceneSessionManager::GetInstance().NotifySwitchingUser(isUserActive);
2807 return NapiGetUndefined(env);
2808 }
2809
OnSetStatusBarDefaultVisibilityPerDisplay(napi_env env,napi_callback_info info)2810 napi_value JsSceneSessionManager::OnSetStatusBarDefaultVisibilityPerDisplay(napi_env env, napi_callback_info info)
2811 {
2812 size_t argc = ARGC_FOUR;
2813 napi_value argv[ARGC_FOUR] = { nullptr };
2814 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2815 if (argc < ARGC_TWO) {
2816 TLOGE(WmsLogTag::WMS_IMMS, "Argc is invalid: %{public}zu", argc);
2817 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2818 "Input parameter is missing or invalid"));
2819 return NapiGetUndefined(env);
2820 }
2821 int64_t displayId = -1;
2822 if (!ConvertFromJsValue(env, argv[0], displayId)) {
2823 TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to displayId");
2824 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2825 "Input parameter is missing or invalid"));
2826 return NapiGetUndefined(env);
2827 }
2828 if (displayId < 0) {
2829 TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to displayId");
2830 return NapiGetUndefined(env);
2831 }
2832 bool visible = false;
2833 if (!ConvertFromJsValue(env, argv[1], visible)) {
2834 TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to visible");
2835 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2836 "Input parameter is missing or invalid"));
2837 return NapiGetUndefined(env);
2838 }
2839 SceneSessionManager::GetInstance().SetStatusBarDefaultVisibilityPerDisplay(
2840 static_cast<DisplayId>(displayId), visible);
2841 return NapiGetUndefined(env);
2842 }
2843
OnNotifyStatusBarShowStatus(napi_env env,napi_callback_info info)2844 napi_value JsSceneSessionManager::OnNotifyStatusBarShowStatus(napi_env env, napi_callback_info info)
2845 {
2846 size_t argc = ARGC_FOUR;
2847 napi_value argv[ARGC_FOUR] = {nullptr};
2848 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2849 if (argc < ARGC_TWO) {
2850 TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]Argc is invalid: %{public}zu", argc);
2851 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2852 "Input parameter is missing or invalid"));
2853 return NapiGetUndefined(env);
2854 }
2855 int32_t persistentId = 0;
2856 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2857 TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]Failed to convert parameter to persistentId");
2858 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2859 "Input parameter is missing or invalid"));
2860 return NapiGetUndefined(env);
2861 }
2862 if (persistentId <= 0) {
2863 TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]Failed to convert parameter to persistentId");
2864 return NapiGetUndefined(env);
2865 }
2866 bool isVisible = false;
2867 if (!ConvertFromJsValue(env, argv[1], isVisible)) {
2868 TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]Failed to convert parameter to isVisible");
2869 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2870 "Input parameter is missing or invalid"));
2871 return NapiGetUndefined(env);
2872 }
2873 SceneSessionManager::GetInstance().NotifyStatusBarShowStatus(persistentId, isVisible);
2874 return NapiGetUndefined(env);
2875 }
2876
OnNotifyAINavigationBarShowStatus(napi_env env,napi_callback_info info)2877 napi_value JsSceneSessionManager::OnNotifyAINavigationBarShowStatus(napi_env env, napi_callback_info info)
2878 {
2879 size_t argc = 4;
2880 napi_value argv[4] = {nullptr};
2881 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2882 if (argc < ARGC_THREE) {
2883 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2884 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2885 "Input parameter is missing or invalid"));
2886 return NapiGetUndefined(env);
2887 }
2888 bool isVisible = false;
2889 if (!ConvertFromJsValue(env, argv[0], isVisible)) {
2890 WLOGFE("[NAPI]Failed to convert parameter to isVisible");
2891 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2892 "Input parameter is missing or invalid"));
2893 return NapiGetUndefined(env);
2894 }
2895 WSRect barArea;
2896 if (argv[1] == nullptr || !ConvertRectInfoFromJs(env, argv[1], barArea)) {
2897 WLOGFE("[NAPI]Failed to convert parameter to barArea");
2898 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2899 "Input parameter is missing or invalid"));
2900 return NapiGetUndefined(env);
2901 }
2902 int64_t displayId = -1;
2903 if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], displayId)) {
2904 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to displayId");
2905 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2906 "Input parameter is missing or invalid"));
2907 return NapiGetUndefined(env);
2908 }
2909 SceneSessionManager::GetInstance().NotifyAINavigationBarShowStatus(
2910 isVisible, barArea, static_cast<uint64_t>(displayId));
2911 return NapiGetUndefined(env);
2912 }
2913
OnNotifySessionRecoverStatus(napi_env env,napi_callback_info info)2914 napi_value JsSceneSessionManager::OnNotifySessionRecoverStatus(napi_env env, napi_callback_info info)
2915 {
2916 size_t argc = 4;
2917 napi_value argv[4] = { nullptr };
2918 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2919 if (argc != ARGC_TWO) {
2920 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2921 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2922 "Input parameter is missing or invalid"));
2923 return NapiGetUndefined(env);
2924 }
2925 bool isRecovering = false;
2926 if (!ConvertFromJsValue(env, argv[0], isRecovering)) {
2927 WLOGFE("[NAPI]Failed to convert parameter to isRecovering");
2928 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2929 "Input parameter is missing or invalid"));
2930 return NapiGetUndefined(env);
2931 }
2932 WLOGFD("[NAPI]IsRecovering: %{public}u", isRecovering);
2933 // Recovered sessions persistentId list as second argument
2934 std::vector<int32_t> recoveredPersistentIds;
2935 if (!ConvertInt32ArrayFromJs(env, argv[1], recoveredPersistentIds)) {
2936 WLOGFE("[NAPI]Failed to convert recovered persistentId array");
2937 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2938 "Input parameter is missing or invalid"));
2939 return NapiGetUndefined(env);
2940 }
2941 if (!isRecovering) {
2942 // Sceneboard recover finished
2943 SceneSessionManager::GetInstance().NotifyRecoveringFinished();
2944 SceneSessionManager::GetInstance().UpdateRecoveredSessionInfo(recoveredPersistentIds);
2945 } else {
2946 SceneSessionManager::GetInstance().SetAlivePersistentIds(recoveredPersistentIds);
2947 }
2948 SceneSessionManager::GetInstance().SetEnableInputEvent(!isRecovering);
2949
2950 return NapiGetUndefined(env);
2951 }
2952
OnUpdateTitleInTargetPos(napi_env env,napi_callback_info info)2953 napi_value JsSceneSessionManager::OnUpdateTitleInTargetPos(napi_env env, napi_callback_info info)
2954 {
2955 size_t argc = 4;
2956 napi_value argv[4] = {nullptr};
2957 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2958 if (argc < 3) {
2959 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2960 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2961 "Input parameter is missing or invalid"));
2962 return NapiGetUndefined(env);
2963 }
2964 int32_t persistentId;
2965 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
2966 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
2967 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2968 "Input parameter is missing or invalid"));
2969 return NapiGetUndefined(env);
2970 }
2971 bool isShow = false;
2972 if (!ConvertFromJsValue(env, argv[1], isShow)) {
2973 WLOGFE("[NAPI]Failed to convert parameter to isShow");
2974 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2975 "Input parameter is missing or invalid"));
2976 return NapiGetUndefined(env);
2977 }
2978 int32_t height;
2979 if (!ConvertFromJsValue(env, argv[2], height)) {
2980 WLOGFE("[NAPI]Failed to convert parameter to height");
2981 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2982 "Input parameter is missing or invalid"));
2983 return NapiGetUndefined(env);
2984 }
2985 SceneSessionManager::GetInstance().UpdateTitleInTargetPos(persistentId, isShow, height);
2986 return NapiGetUndefined(env);
2987 }
2988
OnReportData(napi_env env,napi_callback_info info)2989 napi_value JsSceneSessionManager::OnReportData(napi_env env, napi_callback_info info)
2990 {
2991 size_t argc = 4;
2992 napi_value argv[4] = {nullptr};
2993 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
2994 if (argc < ARG_INDEX_THREE) { // ReportData args must be greater than three
2995 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
2996 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
2997 "Input parameter is missing or invalid"));
2998 return NapiGetUndefined(env);
2999 }
3000 int32_t resType;
3001 if (!ConvertFromJsValue(env, argv[0], resType)) {
3002 WLOGFE("[NAPI]Failed to convert parameter to resType");
3003 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3004 "Input parameter is missing or invalid"));
3005 return NapiGetUndefined(env);
3006 }
3007 int32_t value;
3008 if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], value)) { // second args is int value
3009 WLOGFE("[NAPI]Failed to convert parameter to value");
3010 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3011 "Input parameter is missing or invalid"));
3012 return NapiGetUndefined(env);
3013 }
3014
3015 std::unordered_map<std::string, std::string> mapPayload;
3016 if (!ConvertStringMapFromJs(env, argv[ARG_INDEX_TWO], mapPayload)) {
3017 WLOGFE("[NAPI]Failed to convert parameter to pauloadPid");
3018 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3019 "Input parameter is missing or invalid"));
3020 return NapiGetUndefined(env);
3021 }
3022 mapPayload["srcPid"] = std::to_string(getprocpid());
3023 if (resType == RESTYPE_RECLAIM) {
3024 std::string reclaimTag = mapPayload[RES_PARAM_RECLAIM_TAG];
3025 WLOGFI("handle reclaim type, reclaimTag=%{public}s", reclaimTag.c_str());
3026 if (reclaimTag == "true") {
3027 auto retId = SceneSessionManager::GetInstance().ReclaimPurgeableCleanMem();
3028 WLOGFI("trim ReclaimPurgeableCleanMem finished, retId:%{public}d", retId);
3029 return NapiGetUndefined(env);
3030 }
3031 }
3032 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3033 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, value, mapPayload);
3034 #endif
3035 return NapiGetUndefined(env);
3036 }
3037
OnGetRssData(napi_env env,napi_callback_info info)3038 napi_value JsSceneSessionManager::OnGetRssData(napi_env env, napi_callback_info info)
3039 {
3040 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3041 size_t argc = DEFAULT_ARG_COUNT;
3042 napi_value argv[DEFAULT_ARG_COUNT] = {nullptr};
3043 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3044 if (argc < ARG_INDEX_TWO) { // OnGetRssData args must be greater than two
3045 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
3046 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3047 "Input parameter is missing or invalid"));
3048 return NapiGetUndefined(env);
3049 }
3050 int32_t resType;
3051 if (!ConvertFromJsValue(env, argv[0], resType)) { // first args is int value
3052 WLOGFE("[NAPI]Failed to convert parameter to resType");
3053 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3054 "Input parameter is missing or invalid"));
3055 return NapiGetUndefined(env);
3056 }
3057 nlohmann::json payload;
3058 if (!ConvertJsonFromJs(env, argv[ARG_INDEX_ONE], payload)) {
3059 WLOGFE("[NAPI]Failed to convert parameter to payload");
3060 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3061 "Input parameter is missing or invalid"));
3062 return NapiGetUndefined(env);
3063 }
3064 static std::string pid = std::to_string(getprocpid());
3065 payload["srcPid"] = pid;
3066 nlohmann::json reply;
3067 ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply);
3068 return RssSession::DealRssReply(env, payload, reply);
3069 #endif
3070 return NapiGetUndefined(env);
3071 }
3072
OnRegisterRssData(napi_env env,napi_callback_info info)3073 napi_value JsSceneSessionManager::OnRegisterRssData(napi_env env, napi_callback_info info)
3074 {
3075 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3076 return RssSession::RegisterRssData(env, info);
3077 #endif
3078 return NapiGetUndefined(env);
3079 }
3080
OnUnregisterRssData(napi_env env,napi_callback_info info)3081 napi_value JsSceneSessionManager::OnUnregisterRssData(napi_env env, napi_callback_info info)
3082 {
3083 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3084 return RssSession::UnregisterRssData(env, info);
3085 #endif
3086 return NapiGetUndefined(env);
3087 }
3088
OnGetSessionSnapshotPixelMap(napi_env env,napi_callback_info info)3089 napi_value JsSceneSessionManager::OnGetSessionSnapshotPixelMap(napi_env env, napi_callback_info info)
3090 {
3091 size_t argc = 4;
3092 napi_value argv[4] = {nullptr};
3093 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3094 if (argc < ARGC_TWO) {
3095 WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
3096 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3097 "Input parameter is missing or invalid"));
3098 return NapiGetUndefined(env);
3099 }
3100 int32_t persistentId;
3101 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
3102 WLOGFE("[NAPI]Failed to convert parameter to persistentId");
3103 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3104 "Input parameter is missing or invalid"));
3105 return NapiGetUndefined(env);
3106 }
3107 double scaleValue;
3108 if (!ConvertFromJsValue(env, argv[1], scaleValue)) {
3109 WLOGFE("[NAPI]Failed to convert parameter to scaleValue");
3110 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3111 "Input parameter is missing or invalid"));
3112 return NapiGetUndefined(env);
3113 }
3114
3115 float scaleParam = GreatOrEqual(scaleValue, 0.0f) && LessOrEqual(scaleValue, 1.0f) ?
3116 static_cast<float>(scaleValue) : 0.0f;
3117 NapiAsyncTask::CompleteCallback complete =
3118 [persistentId, scaleParam](napi_env env, NapiAsyncTask& task, int32_t status) {
3119 auto pixelMap = SceneSessionManager::GetInstance().GetSessionSnapshotPixelMap(persistentId, scaleParam);
3120 napi_value nativeData = nullptr;
3121 if (pixelMap) {
3122 nativeData = Media::PixelMapNapi::CreatePixelMap(env, pixelMap);
3123 }
3124 if (nativeData) {
3125 WLOGD("[NAPI]pixelmap W x H = %{public}d x %{public}d", pixelMap->GetWidth(), pixelMap->GetHeight());
3126 task.Resolve(env, nativeData);
3127 } else {
3128 WLOGE("[NAPI]create native pixelmap fail");
3129 task.Reject(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3130 }
3131 };
3132 napi_value result = nullptr;
3133 napi_value lastParam = argv[1];
3134 NapiAsyncTask::Schedule("JsSceneSessionManager::OnGetSessionSnapshotPixelMap",
3135 env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
3136 return result;
3137 }
3138
OnGetSessionSnapshotPixelMapSync(napi_env env,napi_callback_info info)3139 napi_value JsSceneSessionManager::OnGetSessionSnapshotPixelMapSync(napi_env env, napi_callback_info info)
3140 {
3141 size_t argc = ARGC_FOUR;
3142 napi_value argv[ARGC_FOUR] = {nullptr};
3143 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3144 if (argc < ARGC_TWO) {
3145 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Argc is invalid: %{public}zu", argc);
3146 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3147 "Input parameter is missing or invalid"));
3148 return NapiGetUndefined(env);
3149 }
3150 int32_t persistentId = -1;
3151 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
3152 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert parameter to persistentId");
3153 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3154 "Input parameter is missing or invalid"));
3155 return NapiGetUndefined(env);
3156 }
3157 double scaleValue = 0.0;
3158 if (!ConvertFromJsValue(env, argv[1], scaleValue)) {
3159 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert parameter to scaleValue");
3160 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3161 "Input parameter is missing or invalid"));
3162 return NapiGetUndefined(env);
3163 }
3164 float scaleParam = GreatOrEqual(scaleValue, 0.0f) && LessOrEqual(scaleValue, 1.0f) ?
3165 static_cast<float>(scaleValue) : 0.0f;
3166 std::shared_ptr<Media::PixelMap> pixelPtr =
3167 SceneSessionManager::GetInstance().GetSessionSnapshotPixelMap(persistentId, scaleParam);
3168 if (pixelPtr == nullptr) {
3169 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to create pixlePtr");
3170 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
3171 "System is abnormal"));
3172 return NapiGetUndefined(env);
3173 }
3174 napi_value pixelMapObj = Media::PixelMapNapi::CreatePixelMap(env, pixelPtr);
3175 if (pixelMapObj == nullptr) {
3176 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to create pixel map object");
3177 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
3178 "System is abnormal"));
3179 return NapiGetUndefined(env);
3180 }
3181 return pixelMapObj;
3182 }
3183
OnSetAppDragResizeType(napi_env env,napi_callback_info info)3184 napi_value JsSceneSessionManager::OnSetAppDragResizeType(napi_env env, napi_callback_info info)
3185 {
3186 size_t argc = ARGC_FOUR;
3187 napi_value argv[ARGC_FOUR] = {nullptr};
3188 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3189 if (argc < ARGC_TWO) {
3190 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Argc is invalid: %{public}zu", argc);
3191 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3192 "Input parameter is missing or invalid"));
3193 return NapiGetUndefined(env);
3194 }
3195 std::string bundleName;
3196 if (!ConvertFromJsValue(env, argv[0], bundleName)) {
3197 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to bundleName");
3198 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3199 "Input parameter is missing or invalid"));
3200 return NapiGetUndefined(env);
3201 }
3202 DragResizeType dragResizeType;
3203 if (!ConvertDragResizeTypeFromJs(env, argv[ARGC_ONE], dragResizeType)) {
3204 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to dragResizeType");
3205 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3206 "Input parameter is missing or invalid"));
3207 return NapiGetUndefined(env);
3208 }
3209 TLOGD(WmsLogTag::WMS_LAYOUT, "[NAPI]dragResizeType: %{public}d, bundleName: %{public}s",
3210 dragResizeType, bundleName.c_str());
3211 WMError err = SceneSessionManager::GetInstance().SetAppDragResizeTypeInner(bundleName, dragResizeType);
3212 if (err != WMError::WM_OK) {
3213 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to call set method");
3214 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
3215 "System is abnormal"));
3216 return NapiGetUndefined(env);
3217 }
3218 return NapiGetUndefined(env);
3219 }
3220
GetCustomDecorHeight(napi_env env,napi_callback_info info)3221 napi_value JsSceneSessionManager::GetCustomDecorHeight(napi_env env, napi_callback_info info)
3222 {
3223 TLOGD(WmsLogTag::WMS_LAYOUT, "[NAPI]GetCustomDecorHeight");
3224 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
3225 return (me != nullptr) ? me->OnGetCustomDecorHeight(env, info) : nullptr;
3226 }
3227
OnGetCustomDecorHeight(napi_env env,napi_callback_info info)3228 napi_value JsSceneSessionManager::OnGetCustomDecorHeight(napi_env env, napi_callback_info info)
3229 {
3230 size_t argc = 4;
3231 napi_value argv[4] = {nullptr};
3232 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3233 if (argc < 1) {
3234 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Argc is invalid: %{public}zu", argc);
3235 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3236 "Input parameter is missing or invalid"));
3237 return NapiGetUndefined(env);
3238 }
3239 int32_t persistentId;
3240 if (!ConvertFromJsValue(env, argv[0], persistentId)) {
3241 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to persistentId");
3242 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3243 "Input parameter is missing or invalid"));
3244 return NapiGetUndefined(env);
3245 }
3246 int32_t customDecorHeight = SceneSessionManager::GetInstance().GetCustomDecorHeight(persistentId);
3247 napi_value result = nullptr;
3248 napi_create_int32(env, customDecorHeight, &result);
3249 return result;
3250 }
3251
OnSwitchFreeMultiWindow(napi_env env,napi_callback_info info)3252 napi_value JsSceneSessionManager::OnSwitchFreeMultiWindow(napi_env env, napi_callback_info info)
3253 {
3254 size_t argc = 4;
3255 napi_value argv[4] = {nullptr};
3256 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3257 if (argc < ARGC_ONE) {
3258 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI] Argc is invalid: %{public}zu", argc);
3259 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3260 "Input parameter is missing or invalid"));
3261 return NapiGetUndefined(env);
3262 }
3263 bool enable;
3264 if (!ConvertFromJsValue(env, argv[0], enable)) {
3265 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI] Failed to convert parameter to intoFreeMultiWindow bool value");
3266 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3267 "Input parameter is missing or invalid"));
3268 return NapiGetUndefined(env);
3269 }
3270 SceneSessionManager::GetInstance().SwitchFreeMultiWindow(enable);
3271 return NapiGetUndefined(env);
3272 }
3273
OnGetFreeMultiWindowConfig(napi_env env,napi_callback_info info)3274 napi_value JsSceneSessionManager::OnGetFreeMultiWindowConfig(napi_env env, napi_callback_info info)
3275 {
3276 auto systemConfig = SceneSessionManager::GetInstance().GetSystemSessionConfig();
3277 return JsWindowSceneConfig::CreateFreeMultiWindowConfig(env, systemConfig);
3278 }
3279
OnGetIsLayoutFullScreen(napi_env env,napi_callback_info info)3280 napi_value JsSceneSessionManager::OnGetIsLayoutFullScreen(napi_env env, napi_callback_info info)
3281 {
3282 bool isLayoutFullScreen = false;
3283 SceneSessionManager::GetInstance().GetIsLayoutFullScreen(isLayoutFullScreen);
3284 napi_value result = nullptr;
3285 napi_get_boolean(env, isLayoutFullScreen, &result);
3286 return result;
3287 }
3288
OnNotifyEnterRecentTask(napi_env env,napi_callback_info info)3289 napi_value JsSceneSessionManager::OnNotifyEnterRecentTask(napi_env env, napi_callback_info info)
3290 {
3291 size_t argc = 4;
3292 napi_value argv[4] = {nullptr};
3293 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3294
3295 if (argc < ARGC_ONE) {
3296 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Argc is invalid: %{public}zu", argc);
3297 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3298 "Input parameter is missing or invalid"));
3299 return NapiGetUndefined(env);
3300 }
3301 bool enterRecent = false;
3302 if (!ConvertFromJsValue(env, argv[0], enterRecent)) {
3303 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to enterRecent");
3304 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3305 "Input parameter is missing or invalid"));
3306 return NapiGetUndefined(env);
3307 }
3308
3309 SceneSessionManager::GetInstance().NotifyEnterRecentTask(enterRecent);
3310 return NapiGetUndefined(env);
3311 }
3312
GetJSCallback(const std::string & functionName)3313 std::shared_ptr<NativeReference> JsSceneSessionManager::GetJSCallback(const std::string& functionName)
3314 {
3315 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsSceneSessionManager::GetJSCallback[%s]", functionName.c_str());
3316 std::shared_ptr<NativeReference> jsCallBack = nullptr;
3317 std::shared_lock<std::shared_mutex> lock(jsCbMapMutex_);
3318 auto iter = jsCbMap_.find(functionName);
3319 if (iter == jsCbMap_.end()) {
3320 TLOGE(WmsLogTag::DEFAULT, "Can't find callback %{public}s", functionName.c_str());
3321 return jsCallBack;
3322 }
3323 jsCallBack = iter->second;
3324 if (jsCallBack == nullptr) {
3325 TLOGE(WmsLogTag::DEFAULT, "Find function name %{public}s, but callback is nullptr!", functionName.c_str());
3326 }
3327 return jsCallBack;
3328 }
3329
OnUpdateDisplayHookInfo(napi_env env,napi_callback_info info)3330 napi_value JsSceneSessionManager::OnUpdateDisplayHookInfo(napi_env env, napi_callback_info info)
3331 {
3332 size_t argc = 5;
3333 napi_value argv[5] = {nullptr};
3334 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3335
3336 if (argc < ARGC_FIVE) {
3337 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Argc is invalid: %{public}zu", argc);
3338 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3339 "Input parameter is missing or invalid"));
3340 return NapiGetUndefined(env);
3341 }
3342
3343 int32_t uid = 0;
3344 if (!ConvertFromJsValue(env, argv[0], uid)) {
3345 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to uid");
3346 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3347 "Input parameter is missing or invalid"));
3348 return NapiGetUndefined(env);
3349 }
3350
3351 uint32_t width;
3352 if (!ConvertFromJsValue(env, argv[ARGC_ONE], width)) {
3353 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to width");
3354 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3355 "Input parameter is missing or invalid"));
3356 return NapiGetUndefined(env);
3357 }
3358
3359 uint32_t height;
3360 if (!ConvertFromJsValue(env, argv[ARGC_TWO], height)) {
3361 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to height");
3362 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3363 "Input parameter is missing or invalid"));
3364 return NapiGetUndefined(env);
3365 }
3366
3367 double_t density = 1.0;
3368 if (!ConvertFromJsValue(env, argv[ARGC_THREE], density)) {
3369 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to density");
3370 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3371 "Input parameter is missing or invalid"));
3372 return NapiGetUndefined(env);
3373 }
3374
3375 bool enable;
3376 if (!ConvertFromJsValue(env, argv[ARGC_FOUR], enable)) {
3377 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to enable");
3378 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3379 "Input parameter is missing or invalid"));
3380 return NapiGetUndefined(env);
3381 }
3382 SceneSessionManager::GetInstance().UpdateDisplayHookInfo(uid, width, height, static_cast<float_t>(density), enable);
3383 return NapiGetUndefined(env);
3384 }
3385
OnUpdateAppHookDisplayInfo(napi_env env,napi_callback_info info)3386 napi_value JsSceneSessionManager::OnUpdateAppHookDisplayInfo(napi_env env, napi_callback_info info)
3387 {
3388 size_t argc = 3;
3389 napi_value argv[3] = {nullptr};
3390 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3391
3392 if (argc < ARGC_THREE) {
3393 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Argc is invalid: %{public}zu", argc);
3394 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3395 "Input parameter is missing or invalid"));
3396 return NapiGetUndefined(env);
3397 }
3398
3399 int32_t uid = 0;
3400 if (!ConvertFromJsValue(env, argv[0], uid)) {
3401 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to uid");
3402 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3403 "Input parameter is missing or invalid"));
3404 return NapiGetUndefined(env);
3405 }
3406
3407 HookInfo hookInfo;
3408 if (argv[1] == nullptr || !ConvertHookInfoFromJs(env, argv[1], hookInfo)) {
3409 WLOGFE("[NAPI]Failed to convert parameter to hookInfo");
3410 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3411 "Input parameter is missing or invalid"));
3412 return NapiGetUndefined(env);
3413 }
3414
3415 bool enable = false;
3416 if (!ConvertFromJsValue(env, argv[ARGC_TWO], enable)) {
3417 TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to enable");
3418 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3419 "Input parameter is missing or invalid"));
3420 return NapiGetUndefined(env);
3421 }
3422 SceneSessionManager::GetInstance().UpdateAppHookDisplayInfo(uid, hookInfo, enable);
3423 return NapiGetUndefined(env);
3424 }
3425
SetAppForceLandscapeConfig(napi_env env,napi_callback_info info)3426 napi_value JsSceneSessionManager::SetAppForceLandscapeConfig(napi_env env, napi_callback_info info)
3427 {
3428 JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
3429 return (me != nullptr) ? me->OnSetAppForceLandscapeConfig(env, info) : nullptr;
3430 }
3431
OnSetAppForceLandscapeConfig(napi_env env,napi_callback_info info)3432 napi_value JsSceneSessionManager::OnSetAppForceLandscapeConfig(napi_env env, napi_callback_info info)
3433 {
3434 size_t argc = 4;
3435 napi_value argv[4] = {nullptr};
3436 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3437 if (argc < ARGC_TWO) {
3438 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Argc is invalid: %{public}zu", argc);
3439 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3440 "Input parameter is missing or invalid"));
3441 return NapiGetUndefined(env);
3442 }
3443
3444 std::string bundleName;
3445 if (!ConvertFromJsValue(env, argv[0], bundleName)) {
3446 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to bundleName");
3447 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3448 "Input parameter is missing or invalid"));
3449 return NapiGetUndefined(env);
3450 }
3451
3452 int32_t mode;
3453 if (!ConvertFromJsValue(env, argv[1], mode)) {
3454 TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to forceLandscapeMode");
3455 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3456 "Input parameter is missing or invalid"));
3457 return NapiGetUndefined(env);
3458 }
3459
3460 std::string homePage;
3461 if (argc >= ARGC_THREE && ConvertFromJsValue(env, argv[ARGC_TWO], homePage)) {
3462 TLOGD(WmsLogTag::DEFAULT, "[NAPI]homePage: %{public}s", homePage.c_str());
3463 }
3464 AppForceLandscapeConfig config = { mode, homePage };
3465 SceneSessionManager::GetInstance().SetAppForceLandscapeConfig(bundleName, config);
3466 return NapiGetUndefined(env);
3467 }
3468
OnIsScbCoreEnabled(napi_env env,napi_callback_info info)3469 napi_value JsSceneSessionManager::OnIsScbCoreEnabled(napi_env env, napi_callback_info info)
3470 {
3471 size_t argc = 4;
3472 napi_value argv[4] = {nullptr};
3473 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3474 if (argc >= 1) {
3475 TLOGE(WmsLogTag::WMS_PIPELINE, "[NAPI]Argc is invalid: %{public}zu", argc);
3476 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3477 "Input parameter is missing or invalid"));
3478 return NapiGetUndefined(env);
3479 }
3480 napi_value result = nullptr;
3481 napi_get_boolean(env, Session::IsScbCoreEnabled(), &result);
3482 return result;
3483 }
3484
OnNotifyAboveLockScreen(napi_env env,napi_callback_info info)3485 napi_value JsSceneSessionManager::OnNotifyAboveLockScreen(napi_env env, napi_callback_info info)
3486 {
3487 size_t argc = ARGC_FOUR;
3488 napi_value argv[ARGC_FOUR] = { nullptr };
3489 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3490 if (argc != ARGC_ONE) {
3491 TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Argc is invalid: %{public}zu", argc);
3492 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3493 "Input parameter is missing or invalid"));
3494 return NapiGetUndefined(env);
3495 }
3496
3497 std::vector<int32_t> windowIds;
3498 if (!ConvertInt32ArrayFromJs(env, argv[0], windowIds)) {
3499 TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Failed to convert windowIds");
3500 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3501 "Input parameter is missing or invalid"));
3502 return NapiGetUndefined(env);
3503 }
3504
3505 TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: window list size: %{public}zu", windowIds.size());
3506 SceneSessionManager::GetInstance().OnNotifyAboveLockScreen(windowIds);
3507 return NapiGetUndefined(env);
3508 }
3509
OnGetWindowPid(napi_env env,napi_callback_info info)3510 napi_value JsSceneSessionManager::OnGetWindowPid(napi_env env, napi_callback_info info)
3511 {
3512 size_t argc = 4;
3513 napi_value argv[4] = {nullptr};
3514 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3515 if (argc < ARGC_ONE) {
3516 TLOGE(WmsLogTag::WMS_SCB, "[NAPI]Argc is invalid: %{public}zu", argc);
3517 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3518 "Input parameter is missing or invalid"));
3519 return NapiGetUndefined(env);
3520 }
3521 int32_t windowId;
3522 if (!ConvertFromJsValue(env, argv[0], windowId)) {
3523 TLOGE(WmsLogTag::WMS_SCB, "[NAPI]Failed to convert parameter to windowId");
3524 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3525 "Input parameter is missing or invalid"));
3526 return NapiGetUndefined(env);
3527 }
3528 int32_t pid = INVALID_PID;
3529 WMError ret = SceneSessionManager::GetInstance().CheckWindowId(windowId, pid);
3530 if (ret != WMError::WM_OK) {
3531 WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret);
3532 TLOGE(WmsLogTag::WMS_SCB, "[NAPI] Get window pid failed, return %{public}d", wmErrorCode);
3533 napi_throw(env, CreateJsError(env, static_cast<int32_t>(wmErrorCode), "Get window pid failed."));
3534 return NapiGetUndefined(env);
3535 }
3536 napi_value result = nullptr;
3537 napi_create_int32(env, pid, &result);
3538 return result;
3539 }
3540
OnCloseTargetFloatWindow(const std::string & bundleName)3541 void JsSceneSessionManager::OnCloseTargetFloatWindow(const std::string& bundleName)
3542 {
3543 TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "[NAPI]");
3544 auto task = [this, bundleName, jsCallBack = GetJSCallback(CLOSE_TARGET_FLOAT_WINDOW_CB), env = env_] {
3545 if (jsCallBack == nullptr) {
3546 TLOGNE(WmsLogTag::WMS_MULTI_WINDOW, "[NAPI]jsCallBack is nullptr");
3547 return;
3548 }
3549 napi_value jsBundleNameObj = CreateJsValue(env, bundleName);
3550 napi_value argv[] = {jsBundleNameObj};
3551 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
3552 };
3553 taskScheduler_->PostMainThreadTask(task, "OnCloseTargetFloatWindow bundleName:" + bundleName);
3554 }
3555
ProcessCloseTargetFloatWindow()3556 void JsSceneSessionManager::ProcessCloseTargetFloatWindow()
3557 {
3558 ProcessCloseTargetFloatWindowFunc func = [this](const std::string& bundleName) {
3559 TLOGND(WmsLogTag::WMS_MULTI_WINDOW, "ProcessCloseTargetFloatWindow. bundleName:%{public}s", bundleName.c_str());
3560 this->OnCloseTargetFloatWindow(bundleName);
3561 };
3562 SceneSessionManager::GetInstance().SetCloseTargetFloatWindowFunc(func);
3563 }
3564
OnSetIsWindowRectAutoSave(napi_env env,napi_callback_info info)3565 napi_value JsSceneSessionManager::OnSetIsWindowRectAutoSave(napi_env env, napi_callback_info info)
3566 {
3567 size_t argc = DEFAULT_ARG_COUNT;
3568 napi_value argv[DEFAULT_ARG_COUNT] = {nullptr};
3569 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3570 if (argc != ARGC_TWO) {
3571 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Argc is invalid: %{public}zu", argc);
3572 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3573 "Input parameter is missing or invalid"));
3574 return NapiGetUndefined(env);
3575 }
3576 std::string key;
3577 if (!ConvertFromJsValue(env, argv[ARG_INDEX_ZERO], key)) {
3578 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert key to %{public}s", key.c_str());
3579 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3580 "Input parameter is missing or invalid"));
3581 return NapiGetUndefined(env);
3582 }
3583 bool enabled = false;
3584 if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], enabled)) {
3585 TLOGE(WmsLogTag::WMS_MAIN, "[NAPI]Failed to convert enabled to %{public}d", enabled);
3586 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3587 "Input parameter is missing or invalid"));
3588 return NapiGetUndefined(env);
3589 }
3590 SceneSessionManager::GetInstance().SetIsWindowRectAutoSave(key, enabled);
3591 return NapiGetUndefined(env);
3592 }
3593
OnRemoveAppInfo(napi_env env,napi_callback_info info)3594 napi_value JsSceneSessionManager::OnRemoveAppInfo(napi_env env, napi_callback_info info)
3595 {
3596 size_t argc = ARGC_FOUR;
3597 napi_value argv[ARGC_FOUR] = { nullptr };
3598 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
3599 if (argc != ARGC_ONE) {
3600 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Argc is invalid: %{public}zu", argc);
3601 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3602 "Input parameter is missing or invalid"));
3603 return NapiGetUndefined(env);
3604 }
3605 std::string bundleName;
3606 if (!ConvertFromJsValue(env, argv[0], bundleName)) {
3607 TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Failed to convert parameter to bundleName");
3608 napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
3609 "Input parameter is missing or invalid"));
3610 return NapiGetUndefined(env);
3611 }
3612 SceneSessionManager::GetInstance().RemoveAppInfo(bundleName);
3613 return NapiGetUndefined(env);
3614 }
3615
CreateAppUseControlInfos(napi_env env,const std::vector<AppUseControlInfo> & controlList)3616 static napi_value CreateAppUseControlInfos(
3617 napi_env env, const std::vector<AppUseControlInfo>& controlList)
3618 {
3619 napi_value arrayValue = nullptr;
3620 napi_create_array_with_length(env, controlList.size(), &arrayValue);
3621 if (arrayValue == nullptr) {
3622 TLOGE(WmsLogTag::WMS_LIFE, "Failed to create napi array");
3623 return NapiGetUndefined(env);
3624 }
3625 int32_t index = 0;
3626 for (const auto& appUseControlInfo : controlList) {
3627 napi_value objValue = nullptr;
3628 napi_create_object(env, &objValue);
3629 if (objValue == nullptr) {
3630 TLOGE(WmsLogTag::WMS_LIFE, "failed to create napi object");
3631 return NapiGetUndefined(env);
3632 }
3633 napi_set_named_property(env, objValue, "bundleName", CreateJsValue(env, appUseControlInfo.bundleName_));
3634 napi_set_named_property(env, objValue, "appIndex", CreateJsValue(env, appUseControlInfo.appIndex_));
3635 napi_set_named_property(env, objValue, "isNeedControl", CreateJsValue(env, appUseControlInfo.isNeedControl_));
3636 napi_set_element(env, arrayValue, index++, objValue);
3637 }
3638 return arrayValue;
3639 }
3640
RegisterNotifyAppUseControlListCallback()3641 void JsSceneSessionManager::RegisterNotifyAppUseControlListCallback()
3642 {
3643 TLOGI(WmsLogTag::WMS_LIFE, "in");
3644 SceneSessionManager::GetInstance().RegisterNotifyAppUseControlListCallback(
3645 [this](ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList) {
3646 this->OnNotifyAppUseControlList(type, userId, controlList);
3647 });
3648 }
3649
OnNotifyAppUseControlList(ControlAppType type,int32_t userId,const std::vector<AppUseControlInfo> & controlList)3650 void JsSceneSessionManager::OnNotifyAppUseControlList(
3651 ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)
3652 {
3653 TLOGI(WmsLogTag::WMS_LIFE, "in");
3654 taskScheduler_->PostMainThreadTask([this, type, userId, controlList,
3655 jsCallBack = GetJSCallback(NOTIFY_APP_USE_CONTROL_LIST_CB), env = env_] {
3656 if (jsCallBack == nullptr) {
3657 TLOGNE(WmsLogTag::WMS_LIFE, "[NAPI]jsCallBack is nullptr");
3658 return;
3659 }
3660 napi_value typeValue = CreateJsValue(env, static_cast<uint8_t>(type));
3661 napi_value userIdValue = CreateJsValue(env, userId);
3662 napi_value controlListValue = CreateAppUseControlInfos(env, controlList);
3663 napi_value argv[] = { typeValue, userIdValue, controlListValue };
3664 napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr);
3665 }, __func__);
3666 }
3667 } // namespace OHOS::Rosen
3668