2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "app_info.hh"
19 #include <bundle_internal.h>
21 #include "include/aul_key.h"
22 #include "src/aul_util.h"
24 namespace aul::internal {
25 namespace boot_sequence {
28 constexpr const char METADATA_KEY_ONBOOT_PRIORITY[] =
29 "http://tizen.org/metadata/on-boot/priority";
30 constexpr const int MIN_PRIORITY = 1;
31 constexpr const int MAX_PRIORITY = 99;
32 constexpr const char K_BG_LAUNCH[] = "__K_BG_LAUNCH";
33 constexpr const unsigned int DEFAULT_TIMEOUT = 5000;
37 AppInfo::Builder& AppInfo::Builder::SetAppId(const tizen_base::Bundle& args) {
38 appid_ = args.GetString(AUL_K_APPID);
42 AppInfo::Builder& AppInfo::Builder::SetUid(const tizen_base::Bundle& args) {
43 uid_ = static_cast<uid_t>(std::stoi(args.GetString(AUL_K_TARGET_UID)));
47 AppInfo::Builder& AppInfo::Builder::SetPriority(
48 const tizen_base::Bundle& args) {
49 priority_ = std::stoi(args.GetString(AUL_K_BOOT_SEQUENCE_PRIORITY));
53 AppInfo::Builder& AppInfo::Builder::SetAfter(const tizen_base::Bundle& args) {
54 auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_AFTER);
55 after_.insert(apps.begin(), apps.end());
59 AppInfo::Builder& AppInfo::Builder::SetBefore(const tizen_base::Bundle& args) {
60 auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_BEFORE);
61 before_.insert(apps.begin(), apps.end());
65 AppInfo::Builder& AppInfo::Builder::SetRequires(
66 const tizen_base::Bundle& args) {
67 auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_REQUIRES);
68 requires_.insert(apps.begin(), apps.end());
72 AppInfo::Builder& AppInfo::Builder::SetConflicts(
73 const tizen_base::Bundle& args) {
74 auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_CONFLICTS);
75 conflicts_.insert(apps.begin(), apps.end());
79 AppInfo::Builder& AppInfo::Builder::SetArgs(
80 const tizen_base::Bundle& args) {
81 static const std::vector<std::string> internal_keys{
86 auto arg_json = args.GetString(AUL_K_ARGS);
88 if (bundle_from_json(arg_json.c_str(), &b) != BUNDLE_ERROR_NONE) {
89 _E("bundle_from_json() is failed");
91 args_ = tizen_base::Bundle(b, false, true);
92 for (auto& key : internal_keys)
99 AppInfo::Builder& AppInfo::Builder::SetBackgroundLaunch(
100 const tizen_base::Bundle& args) {
101 background_launch_ = (args.GetString(AUL_K_ALLOWED_BG) == "true");
105 AppInfo::Builder& AppInfo::Builder::SetWaitUntilReady(
106 const tizen_base::Bundle& args) {
108 (args.GetString(AUL_K_BOOT_SEQUENCE_READY_WAIT) == "true");
112 AppInfo::Builder& AppInfo::Builder::SetTimeout(
113 const tizen_base::Bundle& args) {
114 auto timeout_str = args.GetString(AUL_K_TIMEOUT);
115 if (isdigit(timeout_str[0]))
116 timeout_ = static_cast<unsigned int>(std::stoi(timeout_str));
118 timeout_ = DEFAULT_TIMEOUT;
123 AppInfo::Builder& AppInfo::Builder::SetActiveState(
124 const tizen_base::Bundle& args) {
125 active_state_ = args.GetString(AUL_K_STATUS);
129 AppInfo::Builder& AppInfo::Builder::SetSubState(
130 const tizen_base::Bundle& args) {
131 sub_state_ = args.GetString(AUL_K_SUB_STATUS);
135 AppInfo::Builder& AppInfo::Builder::SetBeginTimestamp(
136 const tizen_base::Bundle& args) {
137 begin_timestamp_ = args.GetString(AUL_K_BEGIN_TIMESTAMP);
141 AppInfo::Builder& AppInfo::Builder::SetEndTimestamp(
142 const tizen_base::Bundle& args) {
143 end_timestamp_ = args.GetString(AUL_K_END_TIMESTAMP);
147 AppInfo::Builder& AppInfo::Builder::SetSocketReadyTimestamp(
148 const tizen_base::Bundle& args) {
149 socket_ready_timestamp_ = args.GetString(AUL_K_SOCKET_READY_TIMESTAMP);
153 AppInfo::Builder& AppInfo::Builder::SetTerminatedTimestamp(
154 const tizen_base::Bundle& args) {
155 terminated_timestamp_ = args.GetString(AUL_K_TERMINATED_TIMESTAMP);
159 AppInfo::Builder& AppInfo::Builder::SetStatusMessage(
160 const tizen_base::Bundle& args) {
161 status_msg_ = args.GetString(AUL_K_STATUS_MSG);
165 AppInfo* AppInfo::Builder::Build() const {
166 return new (std::nothrow) AppInfo(
172 std::move(requires_),
173 std::move(conflicts_),
175 std::move(active_state_),
176 std::move(sub_state_),
177 std::move(begin_timestamp_),
178 std::move(end_timestamp_),
179 std::move(socket_ready_timestamp_),
180 std::move(terminated_timestamp_),
181 std::move(status_msg_),
187 AppInfo::AppInfo(std::string appid, uid_t uid, int priority,
188 std::set<std::string> after, std::set<std::string> before,
189 std::set<std::string> requires, std::set<std::string> conflicts,
190 tizen_base::Bundle args,
191 std::string active_state, std::string sub_state,
192 std::string begin_timestamp, std::string end_timestamp,
193 std::string socket_ready_timestamp, std::string terminated_timestamp,
194 std::string status_msg,
195 bool background_launch, bool wait_until_ready, unsigned int timeout)
196 : appid_(std::move(appid)),
199 after_(std::move(after)),
200 before_(std::move(before)),
201 requires_(std::move(requires)),
202 conflicts_(std::move(conflicts)),
203 args_(std::move(args)),
204 active_state_(std::move(active_state)),
205 sub_state_(std::move(sub_state)),
206 begin_timestamp_(std::move(begin_timestamp)),
207 end_timestamp_(std::move(end_timestamp)),
208 socket_ready_timestamp_(std::move(socket_ready_timestamp)),
209 terminated_timestamp_(std::move(terminated_timestamp)),
210 background_launch_(background_launch),
211 wait_until_ready_(wait_until_ready),
213 status_msg_(std::move(status_msg)) {
214 if (background_launch_) {
215 args_.Delete(K_BG_LAUNCH);
216 args_.Add(K_BG_LAUNCH, "enable");
220 const std::string& AppInfo::GetAppId() const {
224 uid_t AppInfo::GetUid() const {
228 int AppInfo::GetPriority() const {
233 bool AppInfo::AfterContains(const std::string& appid) {
234 return after_.find(appid) != after_.end();
237 const std::set<std::string>& AppInfo::AfterGet() const {
242 bool AppInfo::BeforeContains(const std::string& appid) {
243 return before_.find(appid) != before_.end();
246 const std::set<std::string>& AppInfo::BeforeGet() const {
251 bool AppInfo::RequiresContains(const std::string& appid) {
252 return requires_.find(appid) != requires_.end();
255 const std::set<std::string>& AppInfo::RequiresGet() const {
260 bool AppInfo::ConflictsContains(const std::string& appid) {
261 return conflicts_.find(appid) != conflicts_.end();
264 const std::set<std::string>& AppInfo::ConflictsGet() const {
268 const tizen_base::Bundle& AppInfo::GetArgs() const {
272 bool AppInfo::IsBackgroundLaunch() const {
273 return background_launch_;
276 bool AppInfo::WaitUntilReady() const {
277 return wait_until_ready_;
280 unsigned int AppInfo::GetTimeout() const {
284 const std::string& AppInfo::GetActiveState() const {
285 return active_state_;
288 const std::string& AppInfo::GetSubState() const {
292 const std::string& AppInfo::GetBeginTimestamp() const {
293 return begin_timestamp_;
296 const std::string& AppInfo::GetEndTimestamp() const {
297 return end_timestamp_;
300 const std::string& AppInfo::GetSocketReadyTimestamp() const {
301 return socket_ready_timestamp_;
304 const std::string& AppInfo::GetTerminatedTimestamp() const {
305 return terminated_timestamp_;
308 const std::string& AppInfo::GetStatusMessage() const {
312 } // namespace boot_sequence
313 } // namespace aul::internal