+++ /dev/null
-/*
- * Generated by tidlc 2.0.4.
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <dlog.h>
-
-#include "PkgMgrProxy.h"
-
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "RPC_PORT_PROXY"
-
-#ifdef _E
-#undef _E
-#endif
-
-#ifdef _W
-#undef _W
-#endif
-
-#ifdef _I
-#undef _I
-#endif
-
-#ifdef _D
-#undef _D
-#endif
-
-#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-
-#ifndef TIDL_VERSION
-#define TIDL_VERSION "2.0.4"
-#endif
-
-namespace rpc_port {
-namespace PkgMgrProxy {
-
-ResPath::ResPath() {}
-
-ResPath::ResPath(std::string From, std::string To)
- : From_(std::move(From)), To_(std::move(To)) {}
-
-
-namespace proxy {
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const ResPath& param);
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, ResPath& param);
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const std::vector<ResPath>& param);
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, std::vector<ResPath>& param);
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const std::vector<std::string>& param);
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, std::vector<std::string>& param);
-
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const ResPath& param) {
- rpc_port_parcel_write_string(h, param.GetFrom().c_str());
- rpc_port_parcel_write_string(h, param.GetTo().c_str());
- return h;
-}
-
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, ResPath& param) {
- char* From_raw = nullptr;
- rpc_port_parcel_read_string(h, &From_raw);
- std::string From(From_raw);
- free(From_raw);
- param.SetFrom(std::move(From));
-
- char* To_raw = nullptr;
- rpc_port_parcel_read_string(h, &To_raw);
- std::string To(To_raw);
- free(To_raw);
- param.SetTo(std::move(To));
-
- return h;
-}
-
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const std::vector<ResPath>& param) {
- rpc_port_parcel_write_array_count(h, param.size());
- for (const auto& i : param) {
- h << i;
-
- }
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, std::vector<ResPath>& param) {
- int l = 0;
- rpc_port_parcel_read_array_count(h, &l);
-
- for (int i = 0; i < l; i++) {
- ResPath v;
- h >> v;
-
- param.push_back(std::move(v));
- }
-
- return h;
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const std::vector<std::string>& param) {
- rpc_port_parcel_write_array_count(h, param.size());
- for (const auto& i : param) {
- rpc_port_parcel_write_string(h, i.c_str());
-
- }
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, std::vector<std::string>& param) {
- int l = 0;
- rpc_port_parcel_read_array_count(h, &l);
-
- for (int i = 0; i < l; i++) {
- char* v_raw = nullptr;
- rpc_port_parcel_read_string(h, &v_raw);
- std::string v(v_raw);
- free(v_raw);
-
- param.push_back(std::move(v));
- }
-
- return h;
-}
-
-std::atomic<int> PkgMgrForClearCache::CallbackBase::seq_num_ { 0 };
-
-PkgMgrForClearCache::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int PkgMgrForClearCache::CallbackBase::GetId() const {
- return id_;
-}
-
-int PkgMgrForClearCache::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool PkgMgrForClearCache::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string PkgMgrForClearCache::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const PkgMgrForClearCache::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, PkgMgrForClearCache::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-PkgMgrForClearCache::PkgMgrForClearCache(IEventListener* listener, const std::string& target_appid)
- : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
- listener_(listener), target_appid_(target_appid) {
- int r = rpc_port_proxy_create(&proxy_);
-
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create proxy");
- throw InvalidIOException();
- }
-
- rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
- rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
- rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
- rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-
-PkgMgrForClearCache::~PkgMgrForClearCache() {
- if (proxy_)
- rpc_port_proxy_destroy(proxy_);
-}
-
-void PkgMgrForClearCache::Connect(bool sync) {
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "PkgMgrForClearCache");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "PkgMgrForClearCache");
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to connect PkgMgrForClearCache");
- switch (ret) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- throw InvalidIDException();
-
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
-
- case RPC_PORT_ERROR_PERMISSION_DENIED:
- throw PermissionDeniedException();
- }
- }
-}
-
-void PkgMgrForClearCache::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect PkgMgrForClearCache");
- throw InvalidIDException();
- }
-}
-
-void PkgMgrForClearCache::DisposeCallback(const std::string& tag) {
- for (auto& i : delegate_list_) {
- if (i->GetTag() == tag) {
- delegate_list_.remove(i);
- return;
- }
- }
-}
-
-void PkgMgrForClearCache::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
- int id = 0;
- int seq_id = 0;
- bool once = false;
-
- rpc_port_parcel_read_int32(parcel, &id);
- rpc_port_parcel_read_int32(parcel, &seq_id);
- rpc_port_parcel_read_bool(parcel, &once);
-
- for (auto& i : delegate_list_) {
- if (i->GetId() == id && i->GetSeqId() == seq_id) {
- i->OnReceivedEvent(parcel);
- if (i->IsOnce())
- delegate_list_.remove(i);
- break;
- }
- }
-}
-
-void PkgMgrForClearCache::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
- do {
- rpc_port_parcel_h p;
- int ret = rpc_port_parcel_create_from_port(&p, port);
- int cmd;
-
- if (ret != 0)
- break;
- rpc_port_parcel_read_int32(p, &cmd);
- if (cmd == static_cast<int>(MethodId::__Result)) {
- *parcel = p;
- return;
- }
-
- rpc_port_parcel_destroy(p);
- *parcel = nullptr;
- } while (true);
- *parcel = nullptr;
-}
-
-void PkgMgrForClearCache::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
- PkgMgrForClearCache* l = static_cast<PkgMgrForClearCache*>(data);
- rpc_port_h cb_port;
-
- l->port_ = port;
- rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
- l->callback_port_ = cb_port;
- l->listener_->OnConnected();
-}
-
-void PkgMgrForClearCache::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrForClearCache* l = static_cast<PkgMgrForClearCache*>(data);
- l->delegate_list_.clear();
- l->listener_->OnDisconnected();
-}
-
-void PkgMgrForClearCache::OnRejectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrForClearCache* l = static_cast<PkgMgrForClearCache*>(data);
- l->listener_->OnRejected();
-}
-
-void PkgMgrForClearCache::OnReceivedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrForClearCache* l = static_cast<PkgMgrForClearCache*>(data);
- int cmd;
- rpc_port_parcel_h parcel_received;
-
- if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
- _E("Failed to create parcel from port");
- return;
- }
-
- rpc_port_parcel_read_int32(parcel_received, &cmd);
- if (cmd != static_cast<int>(MethodId::__Callback)) {
- rpc_port_parcel_destroy(parcel_received);
- return;
- }
-
- l->ProcessReceivedEvent(parcel_received);
- rpc_port_parcel_destroy(parcel_received);
-}
-
-
-int PkgMgrForClearCache::ClearCache(int uid, std::string pkgid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ClearCache));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-std::atomic<int> PkgMgr::CallbackBase::seq_num_ { 0 };
-
-PkgMgr::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int PkgMgr::CallbackBase::GetId() const {
- return id_;
-}
-
-int PkgMgr::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool PkgMgr::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string PkgMgr::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const PkgMgr::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, PkgMgr::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-PkgMgr::PkgMgr(IEventListener* listener, const std::string& target_appid)
- : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
- listener_(listener), target_appid_(target_appid) {
- int r = rpc_port_proxy_create(&proxy_);
-
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create proxy");
- throw InvalidIOException();
- }
-
- rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
- rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
- rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
- rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-
-PkgMgr::~PkgMgr() {
- if (proxy_)
- rpc_port_proxy_destroy(proxy_);
-}
-
-void PkgMgr::Connect(bool sync) {
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "PkgMgr");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "PkgMgr");
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to connect PkgMgr");
- switch (ret) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- throw InvalidIDException();
-
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
-
- case RPC_PORT_ERROR_PERMISSION_DENIED:
- throw PermissionDeniedException();
- }
- }
-}
-
-void PkgMgr::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect PkgMgr");
- throw InvalidIDException();
- }
-}
-
-void PkgMgr::DisposeCallback(const std::string& tag) {
- for (auto& i : delegate_list_) {
- if (i->GetTag() == tag) {
- delegate_list_.remove(i);
- return;
- }
- }
-}
-
-void PkgMgr::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
- int id = 0;
- int seq_id = 0;
- bool once = false;
-
- rpc_port_parcel_read_int32(parcel, &id);
- rpc_port_parcel_read_int32(parcel, &seq_id);
- rpc_port_parcel_read_bool(parcel, &once);
-
- for (auto& i : delegate_list_) {
- if (i->GetId() == id && i->GetSeqId() == seq_id) {
- i->OnReceivedEvent(parcel);
- if (i->IsOnce())
- delegate_list_.remove(i);
- break;
- }
- }
-}
-
-void PkgMgr::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
- do {
- rpc_port_parcel_h p;
- int ret = rpc_port_parcel_create_from_port(&p, port);
- int cmd;
-
- if (ret != 0)
- break;
- rpc_port_parcel_read_int32(p, &cmd);
- if (cmd == static_cast<int>(MethodId::__Result)) {
- *parcel = p;
- return;
- }
-
- rpc_port_parcel_destroy(p);
- *parcel = nullptr;
- } while (true);
- *parcel = nullptr;
-}
-
-void PkgMgr::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
- PkgMgr* l = static_cast<PkgMgr*>(data);
- rpc_port_h cb_port;
-
- l->port_ = port;
- rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
- l->callback_port_ = cb_port;
- l->listener_->OnConnected();
-}
-
-void PkgMgr::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgr* l = static_cast<PkgMgr*>(data);
- l->delegate_list_.clear();
- l->listener_->OnDisconnected();
-}
-
-void PkgMgr::OnRejectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgr* l = static_cast<PkgMgr*>(data);
- l->listener_->OnRejected();
-}
-
-void PkgMgr::OnReceivedCB(const char *ep, const char *port_name, void *data) {
- PkgMgr* l = static_cast<PkgMgr*>(data);
- int cmd;
- rpc_port_parcel_h parcel_received;
-
- if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
- _E("Failed to create parcel from port");
- return;
- }
-
- rpc_port_parcel_read_int32(parcel_received, &cmd);
- if (cmd != static_cast<int>(MethodId::__Callback)) {
- rpc_port_parcel_destroy(parcel_received);
- return;
- }
-
- l->ProcessReceivedEvent(parcel_received);
- rpc_port_parcel_destroy(parcel_received);
-}
-
-
-int PkgMgr::GetSize(int uid, std::string pkgid, int getType, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GetSize));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
- rpc_port_parcel_write_int32(p, getType);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgr::GetSizeSync(int uid, std::string pkgid, int getType, std::string& ReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GetSizeSync));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
- rpc_port_parcel_write_int32(p, getType);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* ReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &ReqKey_raw);
- ReqKey = ReqKey_raw;
- free(ReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgr::GetSizeSyncResult(std::string reqKey, int& result, long long& sizeInfo) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GetSizeSyncResult));
- rpc_port_parcel_write_string(p, reqKey.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &result);
- rpc_port_parcel_read_int64(parcel_received, &sizeInfo);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgr::Check(int uid, std::string pkgid, int& pid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Check));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &pid);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-std::atomic<int> PkgMgrAdmin::CallbackBase::seq_num_ { 0 };
-
-PkgMgrAdmin::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int PkgMgrAdmin::CallbackBase::GetId() const {
- return id_;
-}
-
-int PkgMgrAdmin::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool PkgMgrAdmin::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string PkgMgrAdmin::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const PkgMgrAdmin::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, PkgMgrAdmin::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-PkgMgrAdmin::PkgMgrAdmin(IEventListener* listener, const std::string& target_appid)
- : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
- listener_(listener), target_appid_(target_appid) {
- int r = rpc_port_proxy_create(&proxy_);
-
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create proxy");
- throw InvalidIOException();
- }
-
- rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
- rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
- rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
- rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-
-PkgMgrAdmin::~PkgMgrAdmin() {
- if (proxy_)
- rpc_port_proxy_destroy(proxy_);
-}
-
-void PkgMgrAdmin::Connect(bool sync) {
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "PkgMgrAdmin");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "PkgMgrAdmin");
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to connect PkgMgrAdmin");
- switch (ret) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- throw InvalidIDException();
-
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
-
- case RPC_PORT_ERROR_PERMISSION_DENIED:
- throw PermissionDeniedException();
- }
- }
-}
-
-void PkgMgrAdmin::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect PkgMgrAdmin");
- throw InvalidIDException();
- }
-}
-
-void PkgMgrAdmin::DisposeCallback(const std::string& tag) {
- for (auto& i : delegate_list_) {
- if (i->GetTag() == tag) {
- delegate_list_.remove(i);
- return;
- }
- }
-}
-
-void PkgMgrAdmin::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
- int id = 0;
- int seq_id = 0;
- bool once = false;
-
- rpc_port_parcel_read_int32(parcel, &id);
- rpc_port_parcel_read_int32(parcel, &seq_id);
- rpc_port_parcel_read_bool(parcel, &once);
-
- for (auto& i : delegate_list_) {
- if (i->GetId() == id && i->GetSeqId() == seq_id) {
- i->OnReceivedEvent(parcel);
- if (i->IsOnce())
- delegate_list_.remove(i);
- break;
- }
- }
-}
-
-void PkgMgrAdmin::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
- do {
- rpc_port_parcel_h p;
- int ret = rpc_port_parcel_create_from_port(&p, port);
- int cmd;
-
- if (ret != 0)
- break;
- rpc_port_parcel_read_int32(p, &cmd);
- if (cmd == static_cast<int>(MethodId::__Result)) {
- *parcel = p;
- return;
- }
-
- rpc_port_parcel_destroy(p);
- *parcel = nullptr;
- } while (true);
- *parcel = nullptr;
-}
-
-void PkgMgrAdmin::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
- PkgMgrAdmin* l = static_cast<PkgMgrAdmin*>(data);
- rpc_port_h cb_port;
-
- l->port_ = port;
- rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
- l->callback_port_ = cb_port;
- l->listener_->OnConnected();
-}
-
-void PkgMgrAdmin::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrAdmin* l = static_cast<PkgMgrAdmin*>(data);
- l->delegate_list_.clear();
- l->listener_->OnDisconnected();
-}
-
-void PkgMgrAdmin::OnRejectedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrAdmin* l = static_cast<PkgMgrAdmin*>(data);
- l->listener_->OnRejected();
-}
-
-void PkgMgrAdmin::OnReceivedCB(const char *ep, const char *port_name, void *data) {
- PkgMgrAdmin* l = static_cast<PkgMgrAdmin*>(data);
- int cmd;
- rpc_port_parcel_h parcel_received;
-
- if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
- _E("Failed to create parcel from port");
- return;
- }
-
- rpc_port_parcel_read_int32(parcel_received, &cmd);
- if (cmd != static_cast<int>(MethodId::__Callback)) {
- rpc_port_parcel_destroy(parcel_received);
- return;
- }
-
- l->ProcessReceivedEvent(parcel_received);
- rpc_port_parcel_destroy(parcel_received);
-}
-
-
-int PkgMgrAdmin::Install(int uid, std::string pkgType, std::string pkgPath, std::vector<std::string> args, std::string reqId, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Install));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgType.c_str());
- rpc_port_parcel_write_string(p, pkgPath.c_str());
- p << args;
- rpc_port_parcel_write_string(p, reqId.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::InstallPkgs(int uid, std::vector<std::string> pkgs, std::vector<std::string> args, std::string reqId, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::InstallPkgs));
- rpc_port_parcel_write_int32(p, uid);
- p << pkgs;
- p << args;
- rpc_port_parcel_write_string(p, reqId.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::Reinstall(int uid, std::string pkgid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Reinstall));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::MountInstall(int uid, std::string pkgType, std::string pkgPath, std::vector<std::string> args, std::string reqId, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::MountInstall));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgType.c_str());
- rpc_port_parcel_write_string(p, pkgPath.c_str());
- p << args;
- rpc_port_parcel_write_string(p, reqId.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::MountInstallPkgs(int uid, std::vector<std::string> pkgs, std::string reqId, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::MountInstallPkgs));
- rpc_port_parcel_write_int32(p, uid);
- p << pkgs;
- rpc_port_parcel_write_string(p, reqId.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::Uninstall(int uid, std::string pkgid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Uninstall));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::UninstallPkgs(int uid, std::vector<std::string> pkgs, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::UninstallPkgs));
- rpc_port_parcel_write_int32(p, uid);
- p << pkgs;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::Move(int uid, std::string pkgId, int moveType, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Move));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgId.c_str());
- rpc_port_parcel_write_int32(p, moveType);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::EnablePkgs(int uid, std::vector<std::string> pkgIds, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::EnablePkgs));
- rpc_port_parcel_write_int32(p, uid);
- p << pkgIds;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DisablePkgs(int uid, std::vector<std::string> pkgIds, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DisablePkgs));
- rpc_port_parcel_write_int32(p, uid);
- p << pkgIds;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::RegisterPkgUpdateInfo(int uid, std::string pkgid, std::string version, int type, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::RegisterPkgUpdateInfo));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
- rpc_port_parcel_write_string(p, version.c_str());
- rpc_port_parcel_write_int32(p, type);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::UnregisterPkgUpdateInfo(int uid, std::string pkgid, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::UnregisterPkgUpdateInfo));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::UnregisterAllPkgUpdateInfo(int uid, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::UnregisterAllPkgUpdateInfo));
- rpc_port_parcel_write_int32(p, uid);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::EnableApp(int uid, std::string appid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::EnableApp));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DisableApp(int uid, std::string appid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DisableApp));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::EnableApps(int uid, std::vector<std::string> appIds, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::EnableApps));
- rpc_port_parcel_write_int32(p, uid);
- p << appIds;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DisableApps(int uid, std::vector<std::string> appIds, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DisableApps));
- rpc_port_parcel_write_int32(p, uid);
- p << appIds;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::EnableGlobalAppForUid(int uid, std::string appid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::EnableGlobalAppForUid));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DisableGlobalAppForUid(int uid, std::string appid, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DisableGlobalAppForUid));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::Kill(int uid, std::string pkgid, int& pid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Kill));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &pid);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::GenerateLicenseRequest(std::string respData, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GenerateLicenseRequest));
- rpc_port_parcel_write_string(p, respData.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::GetGenerateLicenseResult(std::string reqKey, int& result, std::string& reqData, std::string& licenseUrl) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GetGenerateLicenseResult));
- rpc_port_parcel_write_string(p, reqKey.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &result);
- char* reqData_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqData_raw);
- reqData = reqData_raw;
- free(reqData_raw);
- char* licenseUrl_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &licenseUrl_raw);
- licenseUrl = licenseUrl_raw;
- free(licenseUrl_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::RegisterLicense(std::string respData, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::RegisterLicense));
- rpc_port_parcel_write_string(p, respData.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DecryptPackage(std::string drmFilePath, std::string decryptedFilePath, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DecryptPackage));
- rpc_port_parcel_write_string(p, drmFilePath.c_str());
- rpc_port_parcel_write_string(p, decryptedFilePath.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::EnableAppSplashScreen(int uid, std::string appid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::EnableAppSplashScreen));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::DisableAppSplashScreen(int uid, std::string appid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::DisableAppSplashScreen));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::SetAppLabel(int uid, std::string appid, std::string label, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::SetAppLabel));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
- rpc_port_parcel_write_string(p, label.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::SetAppIcon(int uid, std::string appid, std::string iconPath, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::SetAppIcon));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, appid.c_str());
- rpc_port_parcel_write_string(p, iconPath.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::MigrateExternalImage(int uid, std::string pkgid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::MigrateExternalImage));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ResCopy(std::vector<ResPath> copyPathsPair, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ResCopy));
- p << copyPathsPair;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ResCreateDir(std::vector<std::string> createDirPaths, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ResCreateDir));
- p << createDirPaths;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ResRemove(std::vector<std::string> removePaths, std::string& reqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ResRemove));
- p << removePaths;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* reqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &reqKey_raw);
- reqKey = reqKey_raw;
- free(reqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ResUninstall(int uid, std::string pkgid, std::string& delayedReqKey) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ResUninstall));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- char* delayedReqKey_raw = nullptr;
- rpc_port_parcel_read_string(parcel_received, &delayedReqKey_raw);
- delayedReqKey = delayedReqKey_raw;
- free(delayedReqKey_raw);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ClearData(int uid, std::string pkgid) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ClearData));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-int PkgMgrAdmin::ClearDataWithPath(int uid, std::string pkgid, std::string filePath) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::ClearDataWithPath));
- rpc_port_parcel_write_int32(p, uid);
- rpc_port_parcel_write_string(p, pkgid.c_str());
- rpc_port_parcel_write_string(p, filePath.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-
-std::atomic<int> DelayedResult::CallbackBase::seq_num_ { 0 };
-
-DelayedResult::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int DelayedResult::CallbackBase::GetId() const {
- return id_;
-}
-
-int DelayedResult::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool DelayedResult::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string DelayedResult::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const DelayedResult::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, DelayedResult::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-DelayedResult::DelayedResult(IEventListener* listener, const std::string& target_appid)
- : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
- listener_(listener), target_appid_(target_appid) {
- int r = rpc_port_proxy_create(&proxy_);
-
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create proxy");
- throw InvalidIOException();
- }
-
- rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
- rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
- rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
- rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-
-DelayedResult::~DelayedResult() {
- if (proxy_)
- rpc_port_proxy_destroy(proxy_);
-}
-
-void DelayedResult::Connect(bool sync) {
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "DelayedResult");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "DelayedResult");
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to connect DelayedResult");
- switch (ret) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- throw InvalidIDException();
-
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
-
- case RPC_PORT_ERROR_PERMISSION_DENIED:
- throw PermissionDeniedException();
- }
- }
-}
-
-void DelayedResult::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect DelayedResult");
- throw InvalidIDException();
- }
-}
-
-void DelayedResult::DisposeCallback(const std::string& tag) {
- for (auto& i : delegate_list_) {
- if (i->GetTag() == tag) {
- delegate_list_.remove(i);
- return;
- }
- }
-}
-
-void DelayedResult::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
- int id = 0;
- int seq_id = 0;
- bool once = false;
-
- rpc_port_parcel_read_int32(parcel, &id);
- rpc_port_parcel_read_int32(parcel, &seq_id);
- rpc_port_parcel_read_bool(parcel, &once);
-
- for (auto& i : delegate_list_) {
- if (i->GetId() == id && i->GetSeqId() == seq_id) {
- i->OnReceivedEvent(parcel);
- if (i->IsOnce())
- delegate_list_.remove(i);
- break;
- }
- }
-}
-
-void DelayedResult::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
- do {
- rpc_port_parcel_h p;
- int ret = rpc_port_parcel_create_from_port(&p, port);
- int cmd;
-
- if (ret != 0)
- break;
- rpc_port_parcel_read_int32(p, &cmd);
- if (cmd == static_cast<int>(MethodId::__Result)) {
- *parcel = p;
- return;
- }
-
- rpc_port_parcel_destroy(p);
- *parcel = nullptr;
- } while (true);
- *parcel = nullptr;
-}
-
-void DelayedResult::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
- DelayedResult* l = static_cast<DelayedResult*>(data);
- rpc_port_h cb_port;
-
- l->port_ = port;
- rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
- l->callback_port_ = cb_port;
- l->listener_->OnConnected();
-}
-
-void DelayedResult::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
- DelayedResult* l = static_cast<DelayedResult*>(data);
- l->delegate_list_.clear();
- l->listener_->OnDisconnected();
-}
-
-void DelayedResult::OnRejectedCB(const char *ep, const char *port_name, void *data) {
- DelayedResult* l = static_cast<DelayedResult*>(data);
- l->listener_->OnRejected();
-}
-
-void DelayedResult::OnReceivedCB(const char *ep, const char *port_name, void *data) {
- DelayedResult* l = static_cast<DelayedResult*>(data);
- int cmd;
- rpc_port_parcel_h parcel_received;
-
- if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
- _E("Failed to create parcel from port");
- return;
- }
-
- rpc_port_parcel_read_int32(parcel_received, &cmd);
- if (cmd != static_cast<int>(MethodId::__Callback)) {
- rpc_port_parcel_destroy(parcel_received);
- return;
- }
-
- l->ProcessReceivedEvent(parcel_received);
- rpc_port_parcel_destroy(parcel_received);
-}
-
-
-int DelayedResult::GetResult(std::string reqKey, int& result) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- 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_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::GetResult));
- rpc_port_parcel_write_string(p, reqKey.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &result);
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-} // namespace proxy
-} // namespace PkgMgrProxy
-} // namespace rpc_port