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 "ui_extension_record.h"
17 
18 #include "ability_util.h"
19 #include "session/host/include/zidl/session_interface.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
UIExtensionRecord(const std::shared_ptr<AAFwk::AbilityRecord> & abilityRecord)23 UIExtensionRecord::UIExtensionRecord(const std::shared_ptr<AAFwk::AbilityRecord> &abilityRecord)
24     : ExtensionRecord(abilityRecord)
25 {}
26 
27 UIExtensionRecord::~UIExtensionRecord() = default;
28 
ContinueToGetCallerToken()29 bool UIExtensionRecord::ContinueToGetCallerToken()
30 {
31     return true;
32 }
33 
Update(const AAFwk::AbilityRequest & abilityRequest)34 void UIExtensionRecord::Update(const AAFwk::AbilityRequest &abilityRequest)
35 {
36     if (abilityRecord_ == nullptr) {
37         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityRecord_ is null");
38         return;
39     }
40     abilityRecord_->SetSessionInfo(abilityRequest.sessionInfo);
41 }
42 
HandleNotifyUIExtensionTimeout(ErrorCode code)43 void UIExtensionRecord::HandleNotifyUIExtensionTimeout(ErrorCode code)
44 {
45     CHECK_POINTER(abilityRecord_);
46     auto sessionInfo = abilityRecord_->GetSessionInfo();
47     CHECK_POINTER(sessionInfo);
48     sptr<Rosen::ISession> sessionProxy = iface_cast<Rosen::ISession>(sessionInfo->sessionToken);
49     if (sessionProxy == nullptr) {
50         TAG_LOGD(AAFwkTag::ABILITYMGR, "Parsing session failed, is nullptr.");
51         return;
52     }
53     sessionProxy->NotifyExtensionTimeout(code);
54 }
55 
LoadTimeout()56 void UIExtensionRecord::LoadTimeout()
57 {
58     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
59     HandleNotifyUIExtensionTimeout(ErrorCode::LOAD_TIMEOUT);
60     TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify wms, the uiextension load time out.");
61 }
62 
ForegroundTimeout()63 void UIExtensionRecord::ForegroundTimeout()
64 {
65     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
66     HandleNotifyUIExtensionTimeout(ErrorCode::FOREGROUND_TIMEOUT);
67     TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify wms, the uiextension move foreground time out.");
68 }
69 
BackgroundTimeout()70 void UIExtensionRecord::BackgroundTimeout()
71 {
72     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
73     HandleNotifyUIExtensionTimeout(ErrorCode::BACKGROUND_TIMEOUT);
74     TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify wms, the uiextension move background time out.");
75 }
76 
TerminateTimeout()77 void UIExtensionRecord::TerminateTimeout()
78 {
79     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
80     HandleNotifyUIExtensionTimeout(ErrorCode::TERMINATE_TIMEOUT);
81     TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify wms, the uiextension terminate time out.");
82 }
83 } // namespace AbilityRuntime
84 } // namespace OHOS
85