1 /*
2  * Copyright (c) 2023-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 "window_focus_changed_listener.h"
17 
18 #include "ability_manager_service.h"
19 #include "hilog_tag_wrapper.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
23 using namespace OHOS::Rosen;
OnFocused(const sptr<FocusChangeInfo> & focusChangeInfo)24 void WindowFocusChangedListener::OnFocused(const sptr<FocusChangeInfo> &focusChangeInfo)
25 {
26     if (!focusChangeInfo) {
27         TAG_LOGW(AAFwkTag::ABILITYMGR, "OnFocused invalid focusChangeInfo.");
28         return;
29     }
30 
31     if (taskHandler_) {
32         auto task = [inner = owner_, focusChangeInfo] {
33             auto owner = inner.lock();
34             if (!owner) {
35                 TAG_LOGW(AAFwkTag::ABILITYMGR, "OnUnfocused failed to get app mgr service inner.");
36                 return;
37             }
38             owner->HandleFocused(focusChangeInfo);
39         };
40         taskHandler_->SubmitTask(task);
41     }
42 }
43 
OnUnfocused(const sptr<FocusChangeInfo> & focusChangeInfo)44 void WindowFocusChangedListener::OnUnfocused(const sptr<FocusChangeInfo> &focusChangeInfo)
45 {
46     if (!focusChangeInfo) {
47         TAG_LOGW(AAFwkTag::ABILITYMGR, "OnUnfocused invalid focusChangeInfo.");
48         return;
49     }
50 
51     if (taskHandler_) {
52         auto task = [inner = owner_, focusChangeInfo] {
53             auto owner = inner.lock();
54             if (!owner) {
55                 TAG_LOGW(AAFwkTag::ABILITYMGR, "OnUnfocused failed to get app mgr service inner.");
56                 return;
57             }
58             owner->HandleUnfocused(focusChangeInfo);
59         };
60         taskHandler_->SubmitTask(task);
61     }
62 }
63 }  // namespace AAFwk
64 }  // namespace OHOS
65