1 /*
2  * Copyright (c) 2021-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 "hilog_tag_wrapper.h"
17 #include "want_agent.h"
18 #include "want_agent_log_wrapper.h"
19 
20 namespace OHOS::AbilityRuntime::WantAgent {
WantAgent(const std::shared_ptr<PendingWant> & pendingWant)21 WantAgent::WantAgent(const std::shared_ptr<PendingWant> &pendingWant)
22 {
23     pendingWant_ = pendingWant;
24 }
25 
GetPendingWant()26 std::shared_ptr<PendingWant> WantAgent::GetPendingWant()
27 {
28     return pendingWant_;
29 }
30 
SetPendingWant(const std::shared_ptr<PendingWant> & pendingWant)31 void WantAgent::SetPendingWant(const std::shared_ptr<PendingWant> &pendingWant)
32 {
33     pendingWant_ = pendingWant;
34 }
35 
Marshalling(Parcel & parcel) const36 bool WantAgent::Marshalling(Parcel &parcel) const
37 {
38     if (!parcel.WriteParcelable(pendingWant_.get())) {
39         TAG_LOGE(AAFwkTag::WANTAGENT, "parcel WriteString failed");
40         return false;
41     }
42 
43     return true;
44 }
45 
Unmarshalling(Parcel & parcel)46 WantAgent *WantAgent::Unmarshalling(Parcel &parcel)
47 {
48     WantAgent *agent = new (std::nothrow) WantAgent();
49     if (agent == nullptr) {
50         TAG_LOGE(AAFwkTag::WANTAGENT, "read from parcel failed");
51         return nullptr;
52     }
53     std::shared_ptr<PendingWant> pendingWant(parcel.ReadParcelable<PendingWant>());
54     agent->SetPendingWant(pendingWant);
55 
56     return agent;
57 }
58 }  // namespace OHOS::AbilityRuntime::WantAgent
59