1 /*
2  * Copyright (c) 2021 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 "want_agent_info.h"
17 #include "want.h"
18 #include "want_params.h"
19 
20 using namespace OHOS::AAFwk;
21 
22 namespace OHOS::AbilityRuntime::WantAgent {
WantAgentInfo()23 WantAgentInfo::WantAgentInfo() : WantAgentInfo(nullptr)
24 {}
25 
WantAgentInfo(int requestCode,const WantAgentConstant::OperationType & operationType,WantAgentConstant::Flags flag,std::vector<std::shared_ptr<Want>> & wants,const std::shared_ptr<WantParams> & extraInfo)26 WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType,
27     WantAgentConstant::Flags flag, std::vector<std::shared_ptr<Want>> &wants,
28     const std::shared_ptr<WantParams> &extraInfo)
29 {
30     requestCode_ = requestCode;
31     operationType_ = operationType;
32     flags_.push_back(flag);
33     if (!wants.empty()) {
34         for (auto want : wants) {
35             if (want != nullptr) {
36                 wants_.push_back(std::make_shared<Want>(*want));
37             }
38         }
39     }
40     if (extraInfo != nullptr) {
41         extraInfo_ = std::make_shared<WantParams>(*extraInfo);
42     }
43 }
44 
WantAgentInfo(int requestCode,const WantAgentConstant::OperationType & operationType,const std::vector<WantAgentConstant::Flags> & flags,std::vector<std::shared_ptr<Want>> & wants,const std::shared_ptr<WantParams> & extraInfo)45 WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType,
46     const std::vector<WantAgentConstant::Flags> &flags, std::vector<std::shared_ptr<Want>> &wants,
47     const std::shared_ptr<WantParams> &extraInfo)
48 {
49     requestCode_ = requestCode;
50     operationType_ = operationType;
51     if (!flags.empty()) {
52         flags_.insert(flags_.end(), flags.begin(), flags.end());
53     }
54     if (!wants.empty()) {
55         for (auto want : wants) {
56             if (want != nullptr) {
57                 wants_.push_back(std::make_shared<Want>(*want));
58             }
59         }
60     }
61     if (extraInfo != nullptr) {
62         extraInfo_ = std::make_shared<WantParams>(*extraInfo);
63     }
64 }
65 
WantAgentInfo(const std::shared_ptr<WantAgentInfo> & paramInfo)66 WantAgentInfo::WantAgentInfo(const std::shared_ptr<WantAgentInfo> &paramInfo)
67 {
68     if (paramInfo != nullptr) {
69         requestCode_ = paramInfo->GetRequestCode();
70         operationType_ = paramInfo->GetOperationType();
71         std::vector<WantAgentConstant::Flags> tempFlags = paramInfo->GetFlags();
72         flags_.insert(flags_.end(), tempFlags.begin(), tempFlags.end());
73         if (!paramInfo->GetWants().empty()) {
74             for (auto want : paramInfo->GetWants()) {
75                 wants_.push_back(std::make_shared<Want>(*want));
76             }
77         }
78         if (paramInfo->GetExtraInfo() != nullptr) {
79             extraInfo_ = std::make_shared<WantParams>(*paramInfo->GetExtraInfo());
80         }
81     }
82 }
83 
GetRequestCode() const84 int WantAgentInfo::GetRequestCode() const
85 {
86     return requestCode_;
87 }
88 
GetOperationType() const89 WantAgentConstant::OperationType WantAgentInfo::GetOperationType() const
90 {
91     return operationType_;
92 }
93 
GetFlags() const94 std::vector<WantAgentConstant::Flags> WantAgentInfo::GetFlags() const
95 {
96     return flags_;
97 }
98 
GetWants() const99 std::vector<std::shared_ptr<Want>> WantAgentInfo::GetWants() const
100 {
101     return wants_;
102 }
103 
GetExtraInfo() const104 std::shared_ptr<WantParams> WantAgentInfo::GetExtraInfo() const
105 {
106     return extraInfo_;
107 }
108 }  // namespace OHOS::AbilityRuntime::WantAgent
109