• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 namespace OHOS::AbilityRuntime::WantAgent {
20 bool WantAgent::isMultithreadingSupported_ = false;
21 
WantAgent(const std::shared_ptr<PendingWant> & pendingWant)22 WantAgent::WantAgent(const std::shared_ptr<PendingWant> &pendingWant)
23 {
24     pendingWant_ = pendingWant;
25 }
26 
WantAgent(const std::shared_ptr<LocalPendingWant> & localPendingWant)27 WantAgent::WantAgent(const std::shared_ptr<LocalPendingWant> &localPendingWant)
28 {
29     localPendingWant_ = localPendingWant;
30     isLocal_ = true;
31 }
32 
GetPendingWant()33 std::shared_ptr<PendingWant> WantAgent::GetPendingWant()
34 {
35     return pendingWant_;
36 }
37 
GetLocalPendingWant()38 std::shared_ptr<LocalPendingWant> WantAgent::GetLocalPendingWant()
39 {
40     return localPendingWant_;
41 }
42 
SetPendingWant(const std::shared_ptr<PendingWant> & pendingWant)43 void WantAgent::SetPendingWant(const std::shared_ptr<PendingWant> &pendingWant)
44 {
45     pendingWant_ = pendingWant;
46 }
47 
Marshalling(Parcel & parcel) const48 bool WantAgent::Marshalling(Parcel &parcel) const
49 {
50     if (!parcel.WriteBool(isLocal_)) {
51         TAG_LOGE(AAFwkTag::WANTAGENT, "parcel WriteBool isLocal failed");
52         return false;
53     }
54 
55     if (isLocal_) {
56         if (!parcel.WriteParcelable(localPendingWant_.get())) {
57             TAG_LOGE(AAFwkTag::WANTAGENT, "parcel WritePracelable localPendingWant failed");
58             return false;
59         }
60     } else {
61         if (!parcel.WriteParcelable(pendingWant_.get())) {
62             TAG_LOGE(AAFwkTag::WANTAGENT, "parcel WriteParcelable pendingWant failed");
63             return false;
64         }
65     }
66     return true;
67 }
68 
Unmarshalling(Parcel & parcel)69 WantAgent *WantAgent::Unmarshalling(Parcel &parcel)
70 {
71     WantAgent *agent = nullptr;
72     const auto isLocal = parcel.ReadBool();
73     if (isLocal) {
74         std::shared_ptr<LocalPendingWant> localPendingWant(parcel.ReadParcelable<LocalPendingWant>());
75         agent = new (std::nothrow) WantAgent(localPendingWant);
76     } else {
77         std::shared_ptr<PendingWant> pendingWant(parcel.ReadParcelable<PendingWant>());
78         agent = new (std::nothrow) WantAgent(pendingWant);
79     }
80 
81     if (agent == nullptr) {
82         TAG_LOGE(AAFwkTag::WANTAGENT, "read from parcel failed");
83         return nullptr;
84     }
85     return agent;
86 }
87 
GetIsMultithreadingSupported()88 bool WantAgent::GetIsMultithreadingSupported()
89 {
90     return isMultithreadingSupported_;
91 }
92 
SetIsMultithreadingSupported(bool isMultithreadingSupported)93 void WantAgent::SetIsMultithreadingSupported(bool isMultithreadingSupported)
94 {
95     isMultithreadingSupported_ = isMultithreadingSupported;
96 }
97 
IsLocal()98 bool WantAgent::IsLocal()
99 {
100     return isLocal_;
101 }
102 }  // namespace OHOS::AbilityRuntime::WantAgent
103