• 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 Licenses 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 be 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 "window_adapter_lite.h"
17 #include "window_manager_hilog.h"
18 #include "session_manager_lite.h"
19 #include "focus_change_info.h"
20 #include "singleton_delegator.h"
21 
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAdapterLite"};
27 }
WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapterLite)28 WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapterLite)
29 
30 #define INIT_PROXY_CHECK_RETURN(ret)        \
31     do {                                    \
32         if (!InitSSMProxy()) {              \
33             WLOGFE("InitSSMProxy failed!"); \
34             return ret;                     \
35         }                                   \
36     } while (false)
37 
38 bool WindowAdapterLite::InitSSMProxy()
39 {
40     std::lock_guard<std::recursive_mutex> lock(mutex_);
41     if (!isProxyValid_) {
42         windowManagerServiceProxy_ = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy();
43         if ((!windowManagerServiceProxy_) || (!windowManagerServiceProxy_->AsObject())) {
44             WLOGFE("Failed to get system scene session manager services");
45             return false;
46         }
47 
48         wmsDeath_ = new (std::nothrow) WMSDeathRecipient();
49         if (!wmsDeath_) {
50             WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
51             return false;
52         }
53         sptr<IRemoteObject> remoteObject = windowManagerServiceProxy_->AsObject();
54         if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) {
55             WLOGFE("Failed to add death recipient");
56             return false;
57         }
58         isProxyValid_ = true;
59     }
60     return true;
61 }
62 
ClearWindowAdapter()63 void WindowAdapterLite::ClearWindowAdapter()
64 {
65     WLOGD("ClearWindowAdapter");
66     if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) {
67         windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_);
68     }
69 
70     std::lock_guard<std::recursive_mutex> lock(mutex_);
71     isProxyValid_ = false;
72 }
73 
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)74 void WMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
75 {
76     WLOGD("OnRemoteDied");
77     if (wptrDeath == nullptr) {
78         WLOGFE("wptrDeath is null");
79         return;
80     }
81     WLOGD("promote Death");
82     sptr<IRemoteObject> object = wptrDeath.promote();
83     if (!object) {
84         WLOGFE("object is null");
85         return;
86     }
87     WLOGI("wms OnRemoteDied");
88     SingletonContainer::Get<WindowAdapterLite>().ClearWindowAdapter();
89     SingletonContainer::Get<SessionManagerLite>().ClearSessionManagerProxy();
90 }
91 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)92 void WindowAdapterLite::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
93 {
94     INIT_PROXY_CHECK_RETURN();
95     WLOGFI("use Foucus window info proxy");
96     return windowManagerServiceProxy_->GetFocusWindowInfo(focusInfo);
97 }
98 
99 } // namespace Rosen
100 } // namespace OHOS
101