#include <tzplatform_config.h>
#include <pkgmgr-info.h>
#include <pkgmgr_installer_info.h>
+#include <vconf.h>
#include "watchface-complication/db-manager.h"
#define LOG_TAG "WATCHFACE_COMPLICATION"
+#define DEFAULT_LOCALE "No Locale"
#define ROOT_USER 0
namespace watchface_complication {
return privlege_list;
}
+char* DBManager::GetSystemLocale() {
+ char* lang;
+ char* locale;
+ char* ptr;
+ char* tmp;
+
+ lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang == NULL) {
+ locale = strdup(DEFAULT_LOCALE);
+ if (locale == NULL) {
+ LOGE("out of memory");
+ return NULL;
+ }
+ return locale;
+ }
+
+ tmp = strtok_r(lang, ".", &ptr);
+ if (tmp == NULL) {
+ LOGE("failed to get language");
+ free(lang);
+ return NULL;
+ }
+
+ locale = strdup(tmp);
+ if (locale == NULL) {
+ LOGE("out of memory");
+ free(lang);
+ return NULL;
+ }
+
+ for (int i = 0; i < (int)strlen(locale); i++) {
+ if (locale[i] == '_')
+ locale[i] = '-';
+
+ if (isupper(locale[i]))
+ locale[i] = tolower(locale[i]);
+ }
+
+ free(lang);
+
+ return locale;
+}
+
+std::string DBManager::GetLabel(const char* provider_id) {
+ int ret;
+ std::string label;
+ sqlite3_stmt *stmt;
+ sqlite3* db;
+ char* locale = NULL;
+
+ static const char query[] =
+ "SELECT provider_label FROM provider_localized_info "
+ "WHERE provider_id=? AND locale=?";
+
+ db = OpenDB();
+ if (db == NULL) {
+ LOGE("parser db not exist");
+ return std::string();
+ }
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query),
+ &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare error: %s", sqlite3_errmsg(db));
+ CloseDB(db);
+ return std::string();
+ }
+
+ locale = GetSystemLocale();
+ if (locale == NULL) {
+ sqlite3_finalize(stmt);
+ CloseDB(db);
+ return std::string();
+ }
+
+ sqlite3_bind_text(stmt, 1, provider_id, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, locale, -1, SQLITE_TRANSIENT);
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ label = std::string(reinterpret_cast<const char*>(
+ sqlite3_column_text(stmt, 0)));
+
+ if (label.empty()) {
+ sqlite3_reset(stmt);
+ sqlite3_clear_bindings(stmt);
+
+ sqlite3_bind_text(stmt, 1, provider_id, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, DEFAULT_LOCALE, -1, SQLITE_TRANSIENT);
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ label = std::string(reinterpret_cast<const char*>(
+ sqlite3_column_text(stmt, 0)));
+ }
+
+ sqlite3_finalize(stmt);
+ CloseDB(db);
+ free(locale);
+
+ return label;
+}
+
const char* DBManager::GetParserDataPath() {
uid_t target_uid;
const char *path;
int support_types);
static int GetSupportTypes(std::string& provider_id, int* types);
static int GetProviderPeriod(std::string& provider_id, int* period);
+ static std::string GetLabel(const char* provider_id);
private:
DBManager();
static sqlite3* OpenDB();
static void CloseDB(sqlite3* db);
static const char* GetParserDataPath();
+ static char* GetSystemLocale();
};
} // namespace watchface_complication
-#endif // WATCHFACE_COMPLICATION_DB_MANAGER_H_
\ No newline at end of file
+#endif // WATCHFACE_COMPLICATION_DB_MANAGER_H_