summaryrefslogtreecommitdiff
path: root/installer
diff options
context:
space:
mode:
authorIlho Kim <ilho159.kim@samsung.com>2024-04-11 21:39:36 +0900
committerIlho Kim <ilho159.kim@samsung.com>2024-04-12 15:35:31 +0900
commita080a995b8fd1f6e51aa09e70a421919dd3c5920 (patch)
tree33c4c9b8e330d42f77d8f5318a81b1a7736920a0 /installer
parent83479a0499c82e3ee5509bedc6498fe339cf2590 (diff)
downloadslp-pkgmgr-a080a995b8fd1f6e51aa09e70a421919dd3c5920.tar.gz
slp-pkgmgr-a080a995b8fd1f6e51aa09e70a421919dd3c5920.tar.bz2
slp-pkgmgr-a080a995b8fd1f6e51aa09e70a421919dd3c5920.zip
Implement unimplemented APIs
pkgmgr_client_listen_pkg_upgrade_status pkgmgr_installer_send_pkg_upgrade_signal pkgmgr_installer_set_privilege_level pkgmgr_installer_info_get_privilege_level pkgmgr_installer_info_get_debug_mode pkgmgr_installer_info_get_skip_optimization pkgmgr_installer_error_to_string pkgmgr_installer_set_is_upgrade Change-Id: Iad57673b461980c3f59aea51358c37f2b3d68e12 Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
Diffstat (limited to 'installer')
-rw-r--r--installer/src/PkgSignal.cc46
-rw-r--r--installer/src/PkgSignal.h6
-rw-r--r--installer/src/api_stub.cc74
-rw-r--r--installer/src/control.cc16
-rw-r--r--installer/src/control.hh1
5 files changed, 134 insertions, 9 deletions
diff --git a/installer/src/PkgSignal.cc b/installer/src/PkgSignal.cc
index 7869ac3..216a9e8 100644
--- a/installer/src/PkgSignal.cc
+++ b/installer/src/PkgSignal.cc
@@ -346,6 +346,20 @@ void PkgSignal::EventCb(const char* event_name, bundle* event_data, void* user_d
break;
+ case static_cast<int>(MethodId::AsyncResultForPkgUpgrade):
+ {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ ptr->OnAsyncResultForPkgUpgrade(param1, param2);
+
+ }
+ break;
+
+
default:
_E("Unknown command(%d)", cmd);
@@ -424,6 +438,38 @@ void PkgSignal::AsyncResultForResource(std::string signal, int targetUid, std::s
throw InvalidIOException();
}
}
+
+void PkgSignal::AsyncResultForPkgUpgrade(std::string signal, int progress) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*> p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_);
+ rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::AsyncResultForPkgUpgrade));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, progress);
+
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != EVENT_ERROR_NONE) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
} // namespace group
} // namespace PkgSignal
} // namespace rpc_port
diff --git a/installer/src/PkgSignal.h b/installer/src/PkgSignal.h
index b7a319d..90888c8 100644
--- a/installer/src/PkgSignal.h
+++ b/installer/src/PkgSignal.h
@@ -207,6 +207,11 @@ class PkgSignal {
virtual void OnAsyncResultForResource(std::string signal, int targetUid, std::string reqId, std::string pkgid, std::string status, ExtraData extra) {}
+
+ void AsyncResultForPkgUpgrade(std::string signal, int progress);
+
+ virtual void OnAsyncResultForPkgUpgrade(std::string signal, int progress) {}
+
private:
@@ -215,6 +220,7 @@ class PkgSignal {
__Callback = 1,
AsyncResult = 2,
AsyncResultForResource = 3,
+ AsyncResultForPkgUpgrade = 4,
};
diff --git a/installer/src/api_stub.cc b/installer/src/api_stub.cc
index 8925d28..5932cf6 100644
--- a/installer/src/api_stub.cc
+++ b/installer/src/api_stub.cc
@@ -17,6 +17,7 @@
#include "pkgmgr_installer.h"
#include "pkgmgr_installer_debug.h"
+#include "pkgmgr_installer_error.h"
#include "pkgmgr_installer_info.h"
#include <tzplatform_config.h>
@@ -35,6 +36,9 @@
do { if (nullptr == pi) return (r); } while (0)
static uid_t g_target_uid;
+static int g_debug_mode;
+static int g_skip_optimization;
+static pkgmgr_privilege_level g_privilege_level = PM_PRIVILEGE_UNKNOWN;
API pkgmgr_installer* pkgmgr_installer_new() {
try {
@@ -70,6 +74,8 @@ API int pkgmgr_installer_receive_request(pkgmgr_installer *pi,
cls->GetRequest()->SetUid(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
g_target_uid = cls->GetRequest()->GetUid();
+ g_debug_mode = cls->GetRequest()->IsDebugMode() ? 1 : 0;
+ g_skip_optimization = cls->GetRequest()->IsSkipOptimization() ? 1 : 0;
return 0;
}
@@ -354,7 +360,8 @@ API int pkgmgr_installer_delete_certinfo(const char *pkgid) {
}
API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level) {
- //TODO
+ g_privilege_level = level;
+
return 0;
}
@@ -366,23 +373,57 @@ API int pkgmgr_installer_info_get_target_uid(uid_t *uid) {
API int pkgmgr_installer_info_get_privilege_level(
pkgmgr_privilege_level *level) {
- //TODO
+ *level = g_privilege_level;
+
return 0;
}
API int pkgmgr_installer_info_get_debug_mode(int *debug_mode) {
- //TODO
+ *debug_mode = g_debug_mode;
+
return 0;
}
API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization) {
- //TODO
+ *skip_optimization = g_skip_optimization;
+
return 0;
}
+#define CASE_TO_STR(ERRCODE) case ERRCODE: return ERRCODE##_STR
API const char* pkgmgr_installer_error_to_string(int error_code) {
- //TODO
- return nullptr;
+ switch (error_code) {
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CERT_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ERROR);
+ CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OK);
+ default:
+ return PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR_STR;
+ }
}
API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi,
@@ -410,7 +451,14 @@ API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid,
}
API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) {
- //TODO
+ if (pi == NULL)
+ return -1;
+
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return -1;
+
+ cls->GetRequest()->SetUpgrade(is_upgrade);
return 0;
}
@@ -448,6 +496,14 @@ API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi,
API int pkgmgr_installer_send_pkg_upgrade_signal(pkgmgr_installer *pi,
unsigned int progress) {
- //TODO
- return 0;
+ if (!pi) {
+ _E("invalid argument");
+ return -1;
+ }
+
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return -1;
+
+ return cls->SendSignalForPkgUpgrade(progress);
}
diff --git a/installer/src/control.cc b/installer/src/control.cc
index e9f6d30..e01db4b 100644
--- a/installer/src/control.cc
+++ b/installer/src/control.cc
@@ -437,6 +437,22 @@ int Control::SendSignalForResource(std::string pkgid, std::string status,
}
}
+int Control::SendSignalForPkgUpgrade(int progress) {
+ if (!signal_) {
+ _E("offline mode");
+ return -1;
+ }
+
+ try {
+ signal_->AsyncResultForPkgUpgrade(
+ PKGMGR_INSTALLER_PKG_UPGRADE_EVENT_STR, progress);
+ return 0;
+ } catch (...) {
+ _E("Exception occured");
+ return -1;
+ }
+}
+
static int __send_signal_to_agent(uid_t uid, void* data, size_t len) {
int fd;
struct sockaddr_un sa;
diff --git a/installer/src/control.hh b/installer/src/control.hh
index 6258a4f..99dfd88 100644
--- a/installer/src/control.hh
+++ b/installer/src/control.hh
@@ -43,6 +43,7 @@ class Control {
int SendSignals(std::string key, std::string val);
int SendSignalForResource(std::string pkgid, std::string status,
rpc_port::PkgSignal::ExtraData* event_info);
+ int SendSignalForPkgUpgrade(int progress);
int SendSignalForUid(uid_t uid, std::string pkg_type, std::string pkgid,
std::string appid, std::string key, std::string val);
int SendSignalsForUid(uid_t uid, std::string key, std::string val);