• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "session/host/include/main_session.h"
17 
18 #include <ui/rs_surface_node.h>
19 
20 #include "session_helper.h"
21 #include "session/host/include/scene_persistent_storage.h"
22 #include "window_manager_hilog.h"
23 
24 namespace OHOS::Rosen {
25 namespace {
26 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "MainSession" };
27 } // namespace
28 
MainSession(const SessionInfo & info,const sptr<SpecificSessionCallback> & specificCallback)29 MainSession::MainSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback)
30     : SceneSession(info, specificCallback)
31 {
32     scenePersistence_ = new ScenePersistence(info.bundleName_, GetPersistentId());
33     if (info.persistentId_ != 0 && info.persistentId_ != GetPersistentId()) {
34         // persistentId changed due to id conflicts. Need to rename the old snapshot if exists
35         scenePersistence_->RenameSnapshotFromOldPersistentId(info.persistentId_);
36     }
37     moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId());
38     if (moveDragController_  != nullptr && specificCallback != nullptr &&
39         specificCallback->onWindowInputPidChangeCallback_ != nullptr) {
40         moveDragController_->SetNotifyWindowPidChangeCallback(specificCallback_->onWindowInputPidChangeCallback_);
41     }
42     SetMoveDragCallback();
43     std::string key = GetRatioPreferenceKey();
44     if (!key.empty()) {
45         if (ScenePersistentStorage::HasKey(key, ScenePersistentStorageType::ASPECT_RATIO)) {
46             ScenePersistentStorage::Get(key, aspectRatio_, ScenePersistentStorageType::ASPECT_RATIO);
47             WLOGD("SceneSession init aspectRatio , key %{public}s, value: %{public}f", key.c_str(), aspectRatio_);
48             if (moveDragController_) {
49                 moveDragController_->SetAspectRatio(aspectRatio_);
50             }
51         }
52     }
53 
54     WLOGFD("Create MainSession");
55 }
56 
~MainSession()57 MainSession::~MainSession()
58 {
59     WLOGD("~MainSession, id: %{public}d", GetPersistentId());
60 }
61 
ProcessPointDownSession(int32_t posX,int32_t posY)62 WSError MainSession::ProcessPointDownSession(int32_t posX, int32_t posY)
63 {
64     const auto& id = GetPersistentId();
65     WLOGFI("id: %{public}d, type: %{public}d", id, GetWindowType());
66     if (CheckDialogOnForeground()) {
67         HandlePointDownDialog();
68         return WSError::WS_OK;
69     }
70     PresentFocusIfPointDown();
71     return SceneSession::ProcessPointDownSession(posX, posY);
72 }
73 } // namespace OHOS::Rosen
74