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* AppInfo::Builder::Build() const {
148 return new (std::nothrow) AppInfo(
154 std::move(requires_),
155 std::move(conflicts_),
157 std::move(active_state_),
158 std::move(sub_state_),
159 std::move(begin_timestamp_),
160 std::move(end_timestamp_),
166 AppInfo::AppInfo(std::string appid, uid_t uid, int priority,
167 std::set<std::string> after, std::set<std::string> before,
168 std::set<std::string> requires, std::set<std::string> conflicts,
169 tizen_base::Bundle args,
170 std::string active_state, std::string sub_state,
171 std::string begin_timestamp, std::string end_timestamp,
172 bool background_launch, bool wait_until_ready, unsigned int timeout)
173 : appid_(std::move(appid)),
176 after_(std::move(after)),
177 before_(std::move(before)),
178 requires_(std::move(requires)),
179 conflicts_(std::move(conflicts)),
180 args_(std::move(args)),
181 active_state_(std::move(active_state)),
182 sub_state_(std::move(sub_state)),
183 begin_timestamp_(std::move(begin_timestamp)),
184 end_timestamp_(std::move(end_timestamp)),
185 background_launch_(background_launch),
186 wait_until_ready_(wait_until_ready),
188 if (background_launch_) {
189 args_.Delete(K_BG_LAUNCH);
190 args_.Add(K_BG_LAUNCH, "enable");
194 const std::string& AppInfo::GetAppId() const {
198 uid_t AppInfo::GetUid() const {
202 int AppInfo::GetPriority() const {
207 bool AppInfo::AfterContains(const std::string& appid) {
208 return after_.find(appid) != after_.end();
211 const std::set<std::string>& AppInfo::AfterGet() const {
216 bool AppInfo::BeforeContains(const std::string& appid) {
217 return before_.find(appid) != before_.end();
220 const std::set<std::string>& AppInfo::BeforeGet() const {
225 bool AppInfo::RequiresContains(const std::string& appid) {
226 return requires_.find(appid) != requires_.end();
229 const std::set<std::string>& AppInfo::RequiresGet() const {
234 bool AppInfo::ConflictsContains(const std::string& appid) {
235 return conflicts_.find(appid) != conflicts_.end();
238 const std::set<std::string>& AppInfo::ConflictsGet() const {
242 const tizen_base::Bundle& AppInfo::GetArgs() const {
246 bool AppInfo::IsBackgroundLaunch() const {
247 return background_launch_;
250 bool AppInfo::WaitUntilReady() const {
251 return wait_until_ready_;
254 unsigned int AppInfo::GetTimeout() const {
258 const std::string& AppInfo::GetActiveState() const {
259 return active_state_;
262 const std::string& AppInfo::GetSubState() const {
266 const std::string& AppInfo::GetBeginTimestamp() const {
267 return begin_timestamp_;
270 const std::string& AppInfo::GetEndTimestamp() const {
271 return end_timestamp_;
274 const std::string& AppInfo::GetStatusMessage() const {
278 } // namespace boot_sequence
279 } // namespace aul::internal