socket_ = std::make_unique<pkgmgr_common::socket::ClientSocket>(SOCK_PATH);
}
+PkgInfoClient::~PkgInfoClient() {
+ if (socket_ != nullptr)
+ socket_->Disconnect();
+}
+
bool PkgInfoClient::SendRequest() {
if (socket_ == nullptr) return false;
if (!socket_->Connect()) {
LOGE("Failed to connect client socket, try to direct access");
+ socket_->Disconnect();
is_offline_ = true;
return RequestHandlerDirectAccess();
}
if (socket_->SendData(&req_type_, sizeof(req_type_)) != 0) {
LOGE("fail to send data");
+ socket_->Disconnect();
return false;
}
if (socket_->SendData(&len, sizeof(len)) != 0) {
LOGE("fail to send data");
+ socket_->Disconnect();
return false;
}
if (socket_->SendData(&raw[0], len) != 0) {
LOGE("Fail to send data");
+ socket_->Disconnect();
return false;
}
int len = 0;
if (socket_->ReceiveData(&len, sizeof(len)) != 0) {
LOGE("Fail to receive data");
+ socket_->Disconnect();
return nullptr;
}
unsigned char* raw = new (std::nothrow) unsigned char[len];
if (raw == nullptr) {
LOGE("Out of memory");
+ socket_->Disconnect();
return nullptr;
}
if (socket_->ReceiveData(raw, len) != 0) {
LOGE("Fail to receive data");
+ socket_->Disconnect();
delete[] raw;
return nullptr;
}
+ socket_->Disconnect();
auto res = pkgmgr_common::parcel::ParcelableFactory::GetInst().CreateParcel(
raw, len);
public:
PkgInfoClient(std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcel,
uid_t uid, pkgmgr_common::ReqType req_type);
+ ~PkgInfoClient();
bool SendRequest();
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> GetResultParcel();