Close all fds while creating process pool
[platform/core/appfw/launchpad.git] / src / lib / launchpad-glib / app_info.cc
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "launchpad-glib/app_info.hh"
18
19 #include <bundle_internal.h>
20
21 #include <utility>
22
23 #include <aul_keys.hh>
24
25 namespace launchpad {
26
27 AppInfo::Builder& AppInfo::Builder::SetAppId(const tizen_base::Bundle& b) {
28   app_id_ = b.GetString(kAulAppId);
29   return *this;
30 }
31
32 AppInfo::Builder& AppInfo::Builder::SetAppPath(const tizen_base::Bundle& b) {
33   app_path_ = b.GetString(kAulExec);
34   return *this;
35 }
36
37 AppInfo::Builder& AppInfo::Builder::SetOriginalAppPath(
38     const tizen_base::Bundle& b) {
39   original_app_path_ = b.GetString(kAulExec);
40   return *this;
41 }
42
43 AppInfo::Builder& AppInfo::Builder::SetPkgType(const tizen_base::Bundle& b) {
44   pkg_type_ = b.GetString(kAulPackageType);
45   return *this;
46 }
47
48 AppInfo::Builder& AppInfo::Builder::SetAppType(const tizen_base::Bundle& b) {
49   app_type_ = b.GetString(kAulAppType);
50   return *this;
51 }
52
53 AppInfo::Builder& AppInfo::Builder::SetHwacc(const tizen_base::Bundle& b) {
54   hwacc_ = b.GetString(kAulHwAcc);
55   return *this;
56 }
57
58 AppInfo::Builder& AppInfo::Builder::SetTaskmanage(const tizen_base::Bundle& b) {
59   taskmanage_ = b.GetString(kAulTaskManage);
60   return *this;
61 }
62
63 AppInfo::Builder& AppInfo::Builder::SetPkgId(const tizen_base::Bundle& b) {
64   pkg_id_ = b.GetString(kAulPkgId);
65   return *this;
66 }
67
68 AppInfo::Builder& AppInfo::Builder::SetCompType(const tizen_base::Bundle& b) {
69   comp_type_ = b.GetString(kAulCompType);
70   return *this;
71 }
72
73 AppInfo::Builder& AppInfo::Builder::SetInternalPool(
74     const tizen_base::Bundle& b) {
75   internal_pool_ = b.GetString(kAulInternalPool);
76   return *this;
77 }
78
79 AppInfo::Builder& AppInfo::Builder::SetRootPath(const tizen_base::Bundle& b) {
80   root_path_ = b.GetString(kAulRootPath);
81   return *this;
82 }
83
84 AppInfo::Builder& AppInfo::Builder::SetLoaderName(const tizen_base::Bundle& b) {
85   loader_name_ = b.GetString(kAulLoaderName);
86   return *this;
87 }
88
89 AppInfo::Builder& AppInfo::Builder::SetGlobal(const tizen_base::Bundle& b) {
90   if (b.GetString(kAulIsGlobal) == "true")
91     global_ = true;
92   else
93     global_ = false;
94
95   return *this;
96 }
97
98 AppInfo::Builder& AppInfo::Builder::SetBundle(tizen_base::Bundle b) {
99   b_ = std::move(b);
100   return *this;
101 }
102
103 AppInfo::Builder::operator AppInfo*() {
104   return new (std::nothrow) AppInfo(std::move(app_id_), std::move(app_path_),
105       std::move(original_app_path_), std::move(pkg_type_), std::move(app_type_),
106       std::move(hwacc_), std::move(taskmanage_), std::move(pkg_id_),
107       std::move(comp_type_), std::move(internal_pool_), std::move(root_path_),
108       std::move(loader_name_), global_, std::move(b_));
109 }
110
111 AppInfo* AppInfo::Create(tizen_base::Bundle b) {
112   return Builder().SetAppId(b)
113       .SetAppPath(b)
114       .SetOriginalAppPath(b)
115       .SetPkgType(b)
116       .SetAppType(b)
117       .SetHwacc(b)
118       .SetTaskmanage(b)
119       .SetPkgId(b)
120       .SetCompType(b)
121       .SetInternalPool(b)
122       .SetRootPath(b)
123       .SetLoaderName(b)
124       .SetGlobal(b)
125       .SetBundle(std::move(b));
126 }
127
128 const std::string& AppInfo::GetAppId() const {
129   return app_id_;
130 }
131
132 const std::string& AppInfo::GetAppPath() const {
133   return app_path_;
134 }
135
136 const std::string& AppInfo::GetOriginalAppPath() const {
137   return original_app_path_;
138 }
139
140 const std::string& AppInfo::GetPkgType() const {
141   return pkg_type_;
142 }
143
144 const std::string& AppInfo::GetAppType() const {
145   return app_type_;
146 }
147
148 const std::string& AppInfo::GetHwacc() const {
149   return hwacc_;
150 }
151
152 const std::string& AppInfo::GetTaskmanage() const {
153   return taskmanage_;
154 }
155
156 const std::string& AppInfo::GetPkgId() const {
157   return pkg_id_;
158 }
159
160 const std::string& AppInfo::GetCompType() const {
161   return comp_type_;
162 }
163
164 const std::string& AppInfo::GetInternalPool() const {
165   return internal_pool_;
166 }
167
168 const std::string& AppInfo::GetRootPath() const {
169   return root_path_;
170 }
171
172 const std::string& AppInfo::GetLoaderName() const {
173   return loader_name_;
174 }
175
176 const bool AppInfo::IsGlobal() const {
177   return global_;
178 }
179
180 const tizen_base::Bundle& AppInfo::GetBundle() const {
181   return b_;
182 }
183
184 void AppInfo::WriteToParcel(tizen_base::Parcel* parcel) const {
185   parcel->WriteString(app_id_);
186   parcel->WriteString(app_path_);
187   parcel->WriteString(original_app_path_);
188   parcel->WriteString(pkg_type_);
189   parcel->WriteString(app_type_);
190   parcel->WriteString(hwacc_);
191   parcel->WriteString(taskmanage_);
192   parcel->WriteString(pkg_id_);
193   parcel->WriteString(comp_type_);
194   parcel->WriteString(internal_pool_);
195   parcel->WriteString(root_path_);
196   parcel->WriteString(loader_name_);
197   parcel->WriteBool(global_);
198
199   bundle_raw* b_raw = nullptr;
200   int len = 0;
201   bundle_encode(b_.GetHandle(), &b_raw, &len);
202   std::string raw(b_raw != nullptr ? reinterpret_cast<const char*>(b_raw) : "");
203   bundle_free_encoded_rawdata(&b_raw);
204   parcel->WriteString(raw);
205 }
206
207 void AppInfo::ReadFromParcel(tizen_base::Parcel* parcel) {
208   app_id_ = parcel->ReadString();
209   app_path_ = parcel->ReadString();
210   original_app_path_ = parcel->ReadString();
211   pkg_type_ = parcel->ReadString();
212   app_type_ = parcel->ReadString();
213   hwacc_ = parcel->ReadString();
214   taskmanage_ = parcel->ReadString();
215   pkg_id_ = parcel->ReadString();
216   comp_type_ = parcel->ReadString();
217   internal_pool_ = parcel->ReadString();
218   root_path_ = parcel->ReadString();
219   loader_name_ = parcel->ReadString();
220   parcel->ReadBool(&global_);
221
222   auto raw = parcel->ReadString();
223   if (!raw.empty())
224     b_ = tizen_base::Bundle(raw);
225 }
226
227 AppInfo::AppInfo(std::string app_id, std::string app_path,
228     std::string original_app_path, std::string pkg_type, std::string app_type,
229     std::string hwacc, std::string taskmanage, std::string pkg_id,
230     std::string comp_type, std::string internal_pool, std::string root_path,
231     std::string loader_name, bool global, tizen_base::Bundle b)
232     : app_id_(std::move(app_id)),
233       app_path_(std::move(app_path)),
234       original_app_path_(std::move(original_app_path)),
235       pkg_type_(std::move(pkg_type)),
236       app_type_(std::move(app_type)),
237       hwacc_(std::move(hwacc)),
238       taskmanage_(std::move(taskmanage)),
239       pkg_id_(std::move(pkg_id)),
240       comp_type_(std::move(comp_type)),
241       internal_pool_(std::move(internal_pool)),
242       root_path_(std::move(root_path)),
243       loader_name_(std::move(loader_name)),
244       global_(global),
245       b_(std::move(b)) {}
246
247 }  // namespace launchpad