• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "display_change_event_listener.h"
17 
18 namespace OHOS {
19 namespace Msdp {
20 namespace DeviceStatus {
21 namespace {
22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DisplayChangeEventListener" };
23 } // namespace
24 
DisplayChangeEventListener(IContext * context)25 DisplayChangeEventListener::DisplayChangeEventListener(IContext *context)
26     : context_(context)
27 {
28 }
29 
OnCreate(Rosen::DisplayId displayId)30 void DisplayChangeEventListener::OnCreate(Rosen::DisplayId displayId)
31 {
32     FI_HILOGI("display:%{public}" PRIu64"", displayId);
33 }
34 
OnDestroy(Rosen::DisplayId displayId)35 void DisplayChangeEventListener::OnDestroy(Rosen::DisplayId displayId)
36 {
37     FI_HILOGI("display:%{public}" PRIu64"", displayId);
38 }
39 
OnChange(Rosen::DisplayId displayId)40 void DisplayChangeEventListener::OnChange(Rosen::DisplayId displayId)
41 {
42     if (Rosen::DisplayManager::GetInstance().IsFoldable()) {
43         Rosen::FoldDisplayMode foldMode = Rosen::DisplayManager::GetInstance().GetFoldDisplayMode();
44         if (foldMode == Rosen::FoldDisplayMode::FULL) {
45             if (lastRotation_ == Rosen::Rotation::ROTATION_0) {
46                 FI_HILOGD("FoldDisplayMode is full");
47                 return;
48             }
49             lastRotation_ = Rosen::Rotation::ROTATION_0;
50             CHKPV(context_);
51             int32_t ret = context_->GetDelegateTasks().PostAsyncTask(
52                 std::bind(&IDragManager::RotateDragWindow, &context_->GetDragManager(), Rosen::Rotation::ROTATION_0));
53             if (ret != RET_OK) {
54                 FI_HILOGE("Post async task failed");
55             }
56             return;
57         }
58     }
59     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId);
60     if (display == nullptr) {
61         FI_HILOGD("Get display info failed, display:%{public}" PRIu64"", displayId);
62         display = Rosen::DisplayManager::GetInstance().GetDisplayById(0);
63         if (display == nullptr) {
64             FI_HILOGE("Get display info failed, display is nullptr");
65             return;
66         }
67     }
68     Rosen::Rotation currentRotation = display->GetRotation();
69     if (currentRotation == lastRotation_) {
70         return;
71     }
72     lastRotation_ = currentRotation;
73     CHKPV(context_);
74     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(
75         std::bind(&IDragManager::RotateDragWindow, &context_->GetDragManager(), currentRotation));
76     if (ret != RET_OK) {
77         FI_HILOGE("Post async task failed");
78     }
79 }
80 
DisplayAbilityStatusChange(IContext * context)81 DisplayAbilityStatusChange::DisplayAbilityStatusChange(IContext *context)
82     : context_(context)
83 {}
84 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)85 void DisplayAbilityStatusChange::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
86 {
87     FI_HILOGI("systemAbilityId:%{public}d", systemAbilityId);
88     if (systemAbilityId != DISPLAY_MANAGER_SERVICE_SA_ID) {
89         FI_HILOGE("systemAbilityId is not DISPLAY_MANAGER_SERVICE_SA_ID");
90         return;
91     }
92     CHKPV(context_);
93     displayChangeEventListener_ = sptr<DisplayChangeEventListener>::MakeSptr(context_);
94     CHKPV(displayChangeEventListener_);
95     Rosen::DisplayManager::GetInstance().RegisterDisplayListener(displayChangeEventListener_);
96 }
97 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)98 void DisplayAbilityStatusChange::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
99 {
100     FI_HILOGI("systemAbilityId:%{public}d", systemAbilityId);
101 }
102 } // namespace DeviceStatus
103 } // namespace Msdp
104 } // namespace OHOS