#include <sys/types.h>
+#include "sqlite3.h"
#include "glib.h"
#include "pkgmgrinfo_private.h"
#include "common/parcel/appinfo_parcelable.hh"
#include "common/parcel/filter_parcelable.hh"
#include "common/parcel/pkginfo_parcelable.hh"
+#include "common/parcel/query_parcelable.hh"
#include "common/parcel/result_parcelable.hh"
#include "client/pkginfo_client.hh"
}
return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API char *_appinfo_get_localed_label(
+ const char *appid, const char *locale, uid_t uid) {
+ char *query = nullptr;
+ query = sqlite3_mprintf(
+ "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
+ "WHERE app_id=%Q AND app_locale=%Q),"
+ "(SELECT app_label FROM package_app_localized_info WHERE "
+ "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
+ if (query == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return nullptr;
+ }
+
+ std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
+ new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query)));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid);
+ if (!client.SendRequest())
+ return nullptr;
+ sqlite3_free(query);
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
+ client.GetResultParcel()));
+ tizen_base::Parcel parcel;
+ parcel.ReadParcelable(return_parcel.get());
+
+ // result_list is vector of string vector
+ char *label;
+ auto result_list = return_parcel->GetResult();
+ for (auto result : result_list) {
+ // result is string vector
+ // it only has one string or not.
+ if (result.front().empty() || result.front().length() == 0)
+ return nullptr;
+ label = strdup(result.front().c_str());
+ if (label == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return nullptr;
+ }
+ }
+
+ return label;
}
\ No newline at end of file
char *val;
retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
-
- val = _get_localed_label(appid, locale, uid);
- if (val == NULL)
- val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
-
- if (val == NULL) {
- val = _get_localed_label(appid, locale, GLOBAL_USER);
- if (val == NULL)
- val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
- }
-
+ val = _appinfo_get_localed_label();
if (val == NULL)
return PMINFO_R_ERROR;
*label = val;
-
return PMINFO_R_OK;
}