1 // Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "get_appinfo_request_handler.hh"
9 #include "appinfo_db_handler.hh"
10 #include "filter_parcelable.hh"
11 #include "parcelable_factory.hh"
12 #include "pkgmgrinfo_debug.h"
13 #include "utils/logging.hh"
15 namespace pcp = pkgmgr_common::parcel;
16 namespace psd = pkgmgr_server::database;
18 namespace pkgmgr_server {
19 namespace request_handler {
21 bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data,
22 int size, const std::string& locale) {
23 auto abstract_parcel =
24 pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
26 if (abstract_parcel == nullptr ||
27 abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
28 LOG(ERROR) << "Invalid parcel or type";
29 result_ = std::make_shared<pcp::AppInfoParcelable>(
30 PMINFO_R_ERROR, std::vector<std::shared_ptr<application_x>>{});
34 auto* parcel = dynamic_cast<pcp::FilterParcelable*>(abstract_parcel.get());
35 if (parcel == nullptr) {
36 LOG(ERROR) << "Parcel is empty";
37 result_ = std::make_shared<pcp::AppInfoParcelable>(
38 PMINFO_R_ERROR, std::vector<std::shared_ptr<application_x>>{});
42 psd::AppInfoDBHandler db(parcel->GetUid(), GetPID());
44 db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
45 int ret = db.Execute();
47 result_ = std::make_shared<pcp::AppInfoParcelable>(ret, db.DetachAppHandle());
52 } // namespace request_handler
53 } // namespace pkgmgr_server