Add new features into boot sequence app info
[platform/core/appfw/aul-1.git] / tool / aulctl / operation / status_all_operation.cc
1 /*
2  * Copyright (c) 2022 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 "status_all_operation.hh"
18
19 #include <bundle.h>
20 #include <bundle_cpp.h>
21
22 #include <iostream>
23 #include <string>
24 #include <utility>
25
26 #include "aul/api/aul_app_context.h"
27 #include "boot_sequence/boot_sequence_manager.hh"
28
29 namespace aul {
30
31 bool StatusAllOperation::Process() {
32   auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
33   auto app_list = manager.GetAppInfoList(getuid());
34   if (app_list.empty()) {
35     std::cerr << "Failed to get boot sequence app list." << std::endl;
36     return false;
37   }
38
39   for (const auto& app : app_list) {
40     std::cout << "===========================================" << std::endl;
41     std::cout << "appid: " << app->GetAppId() << std::endl;
42
43     std::cout << "status: " << app->GetActiveState() << std::endl;
44     std::cout << "sub status: " << app->GetSubState() << std::endl;
45     if (app->GetSubState() == "fail")
46       std::cout << "  message: " << app->GetStatusMessage() << std::endl;
47
48     aul_app_context_h context;
49     int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
50     if (ret == 0) {
51       const char* val = nullptr;
52       aul_app_context_get_app_path(context, const_cast<char**>(&val));
53       std::cout << "app path: " << val << std::endl;
54       std::free(const_cast<char*>(val));
55       pid_t pid = -1;
56       aul_app_context_get_pid(context, &pid);
57       std::cout << "pid: " << pid << std::endl;
58       aul_app_context_destroy(context);
59     }
60
61     std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
62     std::cout << "end: " << app->GetEndTimestamp() << std::endl;
63
64     std::cout << "started time: " << app->GetSocketReadyTimestamp()
65               << std::endl;
66
67     std::cout << "termiated time: " << app->GetTerminatedTimestamp()
68               << std::endl;
69
70     std::cout << "requires: ";
71     for (auto& appid : app->RequiresGet())
72       std::cout << appid << " ";
73
74     std::cout << std::endl;
75
76     std::cout << "before: ";
77     for (auto& appid : app->BeforeGet())
78       std::cout << appid << " ";
79
80     std::cout << std::endl;
81
82     std::cout << "after: ";
83     for (auto& appid : app->AfterGet())
84       std::cout << appid << " ";
85
86     std::cout << std::endl;
87
88     std::cout << "conflict: ";
89     for (auto& appid : app->ConflictsGet())
90       std::cout << appid << " ";
91
92     std::cout << std::endl;
93
94     std::cout << "args: {\n";
95     auto& b = app->GetArgs();
96     bundle_foreach(
97         b.GetHandle(),
98         [](const char* key, const int type,
99            const bundle_keyval_t* kv, void* data) {
100           auto& kb = *static_cast<tizen_base::Bundle*>(data);
101           std::cout << key << ": ";
102           switch (type) {
103           case BUNDLE_TYPE_STR:
104             std::cout << kb.GetString(key) << std::endl;
105             break;
106           case BUNDLE_TYPE_STR_ARRAY:
107             std::cout << "[ ";
108             for (auto& val : kb.GetStringArray(key))
109               std::cout << val << ", ";
110
111             std::cout << "]" << std::endl;
112             break;
113           default:
114             break;
115           }
116         },
117         const_cast<tizen_base::Bundle*>(&b));
118     std::cout << "}" << std::endl;
119
120     std::cout << "bg-launch: " << app->IsBackgroundLaunch() << std::endl;
121     std::cout << "===========================================" << std::endl;
122   }
123
124   return true;
125 }
126
127 }  // namespace aul