2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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.
18 #include "pkgmgr_installer.h"
19 #include "pkgmgr_installer_debug.h"
20 #include "pkgmgr_installer_info.h"
22 #include <tzplatform_config.h>
27 #include <pkgmgr-info.h>
32 #define API __attribute__ ((visibility("default")))
34 #define CHK_PI_RET(r) \
35 do { if (nullptr == pi) return (r); } while (0)
37 static uid_t g_target_uid;
39 API pkgmgr_installer* pkgmgr_installer_new() {
41 return new pkgmgr::installer::Control();
43 _E("pkgmgr_installer_new fail");
50 API pkgmgr_installer* pkgmgr_installer_offline_new() {
51 return new pkgmgr::installer::Control(true);
54 API int pkgmgr_installer_free(pkgmgr_installer* pi) {
55 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
60 API int pkgmgr_installer_receive_request(pkgmgr_installer *pi,
61 const int argc, char **argv) {
62 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
64 int ret = cls->SetRequestFromArgv(argc, argv);
68 /* if target user is not set, set as tizenglobalapp user */
69 if (cls->GetRequest()->GetUid() == 0)
70 cls->GetRequest()->SetUid(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
72 g_target_uid = cls->GetRequest()->GetUid();
77 API int pkgmgr_installer_get_request_type(pkgmgr_installer *pi) {
78 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
79 if (!cls->GetRequest())
80 return PKGMGR_REQ_INVALID;
81 return cls->GetRequest()->GetRequestType();
84 API uid_t pkgmgr_installer_get_uid(pkgmgr_installer *pi) {
85 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
86 if (!cls->GetRequest())
87 return PKGMGR_REQ_INVALID;
88 return cls->GetRequest()->GetUid();
91 API const char* pkgmgr_installer_get_request_info(pkgmgr_installer *pi) {
92 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
93 if (!cls->GetRequest())
95 return cls->GetRequest()->GetRequestInfo().c_str();
98 API const char* pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi,
101 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
102 auto& rq = cls->GetRequest();
106 const auto& requests = rq->GetRequests();
107 if (requests.size() <= at)
110 return requests[at].c_str();
113 API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi) {
114 CHK_PI_RET(PKGMGR_REQ_INVALID);
115 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
116 auto& rq = cls->GetRequest();
118 return PKGMGR_REQ_INVALID;
120 return rq->GetRequests().size();
123 API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi) {
124 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
125 if (!cls->GetRequest())
127 return cls->GetRequest()->GetTepPath().c_str();
130 API int pkgmgr_installer_get_tep_move_type(pkgmgr_installer *pi) {
131 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
132 if (!cls->GetRequest())
133 return PKGMGR_REQ_INVALID;
134 return cls->GetRequest()->IsTepMove() ? 1 : 0;
137 API const char* pkgmgr_installer_get_session_id(pkgmgr_installer *pi) {
138 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
139 if (!cls->GetRequest())
141 return cls->GetRequest()->GetSessionId().c_str();
144 API const char* pkgmgr_installer_get_license_path(pkgmgr_installer *pi) {
145 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
146 if (!cls->GetRequest())
148 return cls->GetRequest()->GetLicensePath().c_str();
151 API const char* pkgmgr_installer_get_optional_data(pkgmgr_installer *pi) {
152 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
153 if (!cls->GetRequest())
155 return cls->GetRequest()->GetOptionalData().c_str();
158 API int pkgmgr_installer_is_quiet(pkgmgr_installer *pi) {
162 API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi) {
163 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
164 if (!cls->GetRequest())
165 return PKGMGR_REQ_INVALID;
166 return cls->GetRequest()->GetMoveType();
169 API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi) {
170 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
171 if (!cls->GetRequest())
173 return cls->GetRequest()->GetCallerPkgid().c_str();
176 API int pkgmgr_installer_get_is_preload(pkgmgr_installer *pi) {
177 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
178 if (!cls->GetRequest())
179 return PKGMGR_REQ_INVALID;
180 return cls->GetRequest()->IsPreload() ? 1 : 0;
183 API int pkgmgr_installer_get_force_removal(pkgmgr_installer *pi) {
184 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
185 if (!cls->GetRequest())
186 return PKGMGR_REQ_INVALID;
187 return cls->GetRequest()->IsForceRemoval() ? 1 : 0;
190 API int pkgmgr_installer_get_is_preload_rw(pkgmgr_installer *pi) {
191 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
192 if (!cls->GetRequest())
193 return PKGMGR_REQ_INVALID;
194 return cls->GetRequest()->IsPreloadRw() ? 1 : 0;
197 API int pkgmgr_installer_get_no_removal(pkgmgr_installer *pi) {
198 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
199 if (!cls->GetRequest())
200 return PKGMGR_REQ_INVALID;
201 return cls->GetRequest()->IsNoRemoval() ? 1 : 0;
204 API int pkgmgr_installer_get_keep_rwdata(pkgmgr_installer *pi) {
205 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
206 if (!cls->GetRequest())
207 return PKGMGR_REQ_INVALID;
208 return cls->GetRequest()->IsKeepRwData() ? 1 : 0;
211 API int pkgmgr_installer_get_partial_rw(pkgmgr_installer *pi) {
212 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
213 if (!cls->GetRequest())
214 return PKGMGR_REQ_INVALID;
215 return cls->GetRequest()->IsPartialRw() ? 1 : 0;
218 API int pkgmgr_installer_get_debug_mode(pkgmgr_installer *pi) {
219 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
220 if (!cls->GetRequest())
221 return PKGMGR_REQ_INVALID;
222 return cls->GetRequest()->IsDebugMode() ? 1 : 0;
225 API int pkgmgr_installer_get_skip_check_reference(pkgmgr_installer *pi) {
226 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
227 if (!cls->GetRequest())
228 return PKGMGR_REQ_INVALID;
229 return cls->GetRequest()->IsSkipCheckReference() ? 1 : 0;
232 API int pkgmgr_installer_get_skip_optimization(pkgmgr_installer *pi) {
233 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
234 if (!cls->GetRequest())
235 return PKGMGR_REQ_INVALID;
236 return cls->GetRequest()->IsSkipOptimization() ? 1 : 0;
239 API int pkgmgr_installer_get_recovery_cleanup(pkgmgr_installer *pi) {
240 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
241 if (!cls->GetRequest())
242 return PKGMGR_REQ_INVALID;
243 return cls->GetRequest()->IsRecoveryCleanup() ? 1 : 0;
246 API int pkgmgr_installer_send_app_uninstall_signal(pkgmgr_installer *pi,
247 const char *pkg_type, const char *pkgid, const char *val) {
248 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
249 if (!cls->GetRequest())
251 return cls->SendSignal(pkg_type, pkgid, "", PKGMGR_INSTALLER_APPID_KEY_STR, val);
254 API int pkgmgr_installer_send_app_uninstall_signal_for_uid(
255 pkgmgr_installer *pi, uid_t uid, const char *pkg_type,
256 const char *pkgid, const char *val) {
257 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
258 if (!cls->GetRequest())
260 return cls->SendSignalForUid(uid, pkg_type, pkgid, "", PKGMGR_INSTALLER_APPID_KEY_STR, val);
263 API int pkgmgr_installer_set_uid(pkgmgr_installer *pi, uid_t uid) {
267 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
268 if (!cls->GetRequest())
271 cls->GetRequest()->SetUid(uid);
278 API int pkgmgr_installer_send_app_signal(pkgmgr_installer *pi,
279 const char *pkg_type, const char *pkgid, const char *appid,
280 const char *key, const char *val) {
281 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
282 if (!cls->GetRequest())
284 return cls->SendSignal(pkg_type, pkgid, appid, key, val);
287 API int pkgmgr_installer_send_signal(pkgmgr_installer *pi,
288 const char *pkg_type, const char *pkgid, const char *key,
290 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
291 if (!cls->GetRequest())
293 return cls->SendSignal(pkg_type, pkgid, "", key, val);
296 API int pkgmgr_installer_send_app_signal_for_uid(pkgmgr_installer *pi,
297 uid_t uid, const char *pkg_type, const char *pkgid,
298 const char *appid, const char *key, const char *val) {
299 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
300 if (!cls->GetRequest())
302 return cls->SendSignalForUid(uid, pkg_type, pkgid, appid, key, val);
305 API int pkgmgr_installer_send_signal_for_uid(pkgmgr_installer *pi,
306 uid_t uid, const char *pkg_type, const char *pkgid,
307 const char *key, const char *val) {
308 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
309 if (!cls->GetRequest())
311 return cls->SendSignalForUid(uid, pkg_type, pkgid, "", key, val);
314 API int pkgmgr_installer_set_request_type(pkgmgr_installer *pi,
316 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
317 if (!cls->GetRequest())
319 cls->GetRequest()->SetRequestType(request_type);
323 API int pkgmgr_installer_set_session_id(pkgmgr_installer *pi,
324 const char *session_id) {
325 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
326 if (!cls->GetRequest())
328 cls->GetRequest()->SetSessionId(std::string(session_id));
332 API int pkgmgr_installer_create_certinfo_set_handle(
333 pkgmgr_instcertinfo_h *handle) {
334 return pkgmgrinfo_create_certinfo_set_handle(handle);
337 API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle,
338 pkgmgr_instcert_type cert_type, char *cert_value) {
339 return pkgmgrinfo_set_cert_value(handle, static_cast<pkgmgrinfo_instcert_type>(cert_type), cert_value);
342 API int pkgmgr_installer_save_certinfo(const char *pkgid,
343 pkgmgr_instcertinfo_h handle, uid_t uid) {
344 return pkgmgrinfo_save_certinfo(pkgid, handle, uid);
347 API int pkgmgr_installer_destroy_certinfo_set_handle(
348 pkgmgr_instcertinfo_h handle) {
349 return pkgmgrinfo_destroy_certinfo_set_handle(handle);
352 API int pkgmgr_installer_delete_certinfo(const char *pkgid) {
353 return pkgmgrinfo_delete_certinfo(pkgid);
356 API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level) {
361 API int pkgmgr_installer_info_get_target_uid(uid_t *uid) {
367 API int pkgmgr_installer_info_get_privilege_level(
368 pkgmgr_privilege_level *level) {
373 API int pkgmgr_installer_info_get_debug_mode(int *debug_mode) {
378 API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization) {
383 API const char* pkgmgr_installer_error_to_string(int error_code) {
388 API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi,
389 const char *pkgid, const char *pkg_type) {
390 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
391 cls->AddPkg(pkgid, pkg_type);
396 API int pkgmgr_installer_send_signals(pkgmgr_installer *pi,
397 const char *key, const char *val) {
398 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
399 if (!cls->GetRequest())
401 return cls->SendSignals(key, val);
404 API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid,
405 const char *key, const char *val) {
406 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
407 if (!cls->GetRequest())
409 return cls->SendSignalsForUid(uid, key, val);
412 API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) {
417 API int pkgmgr_installer_send_res_signal(pkgmgr_installer *pi,
418 const char *pkgid, const char *status,
419 pkgmgr_res_event_info *event_info) {
420 if (!pi || !pkgid || !status || !event_info) {
421 _E("invalid argument");
425 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
426 if (!cls->GetRequest())
429 return cls->SendSignalForResource(pkgid, status,
430 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(event_info));
433 API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi,
434 uid_t uid, const char *pkgid, const char *status,
435 pkgmgr_res_event_info *event_info) {
436 if (!pi || !pkgid || !status || !event_info) {
437 _E("invalid argument");
441 auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
442 if (!cls->GetRequest())
445 return cls->SendSignalForResourceForUid(uid, pkgid, status,
446 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(event_info));
449 API int pkgmgr_installer_send_pkg_upgrade_signal(pkgmgr_installer *pi,
450 unsigned int progress) {