support_events INTEGER DEFAULT 1,
FOREIGN KEY (provider_id) REFERENCES complication_provider(provider_id) ON DELETE CASCADE
);
+CREATE TABLE IF NOT EXISTS provider_icon (
+ provider_id TEXT NOT NULL,
+ locale TEXT NOT NULL DEFAULT 'No Locale',
+ icon_path TEXT,
+ UNIQUE (provider_id, locale),
+ FOREIGN KEY (provider_id) REFERENCES complication_provider(provider_id) ON DELETE CASCADE
+);
INSERT INTO complication_provider (
pkgid, appid, provider_id, trusted, period) VALUES (
1
);
+INSERT INTO provider_icon (
+ provider_id, locale, icon_path) VALUES (
+ 'org.tizen.gmock_comp_provider/test',
+ 'No Locale',
+ 'icon_path'
+);
+
+INSERT INTO provider_localized_info (
+ provider_id, locale, provider_label) VALUES (
+ 'org.tizen.gmock_comp_provider/test',
+ 'No Locale',
+ 'provider_label'
+);
+
INSERT INTO provider_support_types (
provider_id, support_type, default_data) VALUES (
'org.tizen.gmock_comp_provider/test',
#include <gtest/gtest.h>
#include <gmock/gmock.h>
-#include "watchface-complication/db-manager.hh"
+#include "watchface-common/db-manager.hh"
using namespace std;
using namespace watchface_complication;
#include "watchface-complication/design-element.hh"
#include "watchface-complication/editables-container.hh"
#include "watchface-complication/received-editable.hh"
+#include "watchface-common/db-manager.hh"
#include "mock/system_info_mock.h"
#include "mock/tzplatform_config_mock.h"
return 0;
}
+void __all_provider_foreach_cb(const provider_info_h info, void *user_data) {
+ int* count = static_cast<int*>(user_data);
+ (*count)++;
+}
+
+void __provider_foreach_cb(const provider_info_h info, void *user_data) {
+ char* str_value;
+ int types;
+
+ watchface_complication_provider_info_get_id(info, &str_value);
+ EXPECT_STREQ(str_value, "org.tizen.gmock_comp_provider/test");
+ free(str_value);
+
+ watchface_complication_provider_info_get_app_id(info, &str_value);
+ EXPECT_STREQ(str_value, "org.tizen.gmock_comp_provider");
+ free(str_value);
+
+ watchface_complication_provider_info_get_label(info, &str_value);
+ EXPECT_STREQ(str_value, "provider_label");
+ free(str_value);
+
+ watchface_complication_provider_info_get_icon(info, &str_value);
+ EXPECT_STREQ(str_value, "icon_path");
+ free(str_value);
+
+ watchface_complication_provider_info_get_types(info, &types);
+ EXPECT_EQ(WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT |
+ WATCHFACE_COMPLICATION_TYPE_LONG_TEXT |
+ WATCHFACE_COMPLICATION_TYPE_RANGED_VALUE |
+ WATCHFACE_COMPLICATION_TYPE_TIME |
+ WATCHFACE_COMPLICATION_TYPE_ICON |
+ WATCHFACE_COMPLICATION_TYPE_IMAGE |
+ WATCHFACE_COMPLICATION_TYPE_SMALL_IMAGE,
+ types);
+
+}
+
class CWCP : public ::testing::Test {
public:
void RunLoop() {
EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
}
-}
\ No newline at end of file
+TEST_F(CWCP, watchface_complication_provider_foreach_info)
+{
+ int ret, count = 0;
+
+ ret = watchface_complication_provider_foreach_info(
+ nullptr, __all_provider_foreach_cb, &count);
+ EXPECT_EQ(5, count);
+ EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+
+ ret = watchface_complication_provider_foreach_info(
+ "org.tizen.gmock_comp_provider", __provider_foreach_cb, nullptr);
+ EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+
+}
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <unistd.h>
+#include <sqlite3.h>
+#include <tzplatform_config.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer_info.h>
+#include <vconf.h>
+
+#include "watchface-complication/complication-internal.hh"
+#include "watchface-common/db-manager.hh"
+#include "watchface-common/watchface-util.hh"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCHFACE_COMPLICATION"
+#define DEFAULT_LOCALE "No Locale"
+
+using namespace tizen_base;
+namespace watchface_complication {
+
+DBManager::DBManager() = default;
+DBManager::~DBManager() = default;
+
+std::unique_ptr<Bundle> DBManager::GetDefaultData(const char* provider_id,
+ int support_type) {
+ static const char query[] =
+ "SELECT trusted, appid, default_data FROM complication_provider as A "
+ "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
+ "WHERE A.provider_id=? AND support_type=?";
+
+ util::DBHelper db;
+
+ if (!db.Open())
+ return nullptr;
+
+ if (!db.Prepare(query))
+ return nullptr;
+
+ if (!db.Bind(1, provider_id))
+ return nullptr;
+
+ if (!db.Bind(2, support_type))
+ return nullptr;
+
+ if (db.Step() != SQLITE_ROW)
+ return nullptr;
+
+ int trusted = db.GetInt(0);
+ const char* app_id = db.GetText(1);
+ if (app_id == nullptr) {
+ LOGE("app_id is nullptr");
+ return nullptr;
+ }
+
+ std::string provider_app_id = app_id;
+ if (trusted && util::CheckCertificate(provider_app_id) == false)
+ return nullptr;
+
+ const char* raw_data = db.GetText(2);
+ if (raw_data == nullptr) {
+ LOGE("raw_data is nullptr");
+ return nullptr;
+ }
+
+ std::unique_ptr<Bundle> default_data;
+ try {
+ default_data = std::unique_ptr<Bundle>(new Bundle(std::string(raw_data)));
+ } catch (const std::exception& e) {
+ LOGE("Exception occurred : %s", e.what());
+ return nullptr;
+ }
+
+ util::ConvertPathToAppPath(provider_app_id.c_str(),
+ default_data.get()->GetHandle());
+
+ return default_data;
+}
+
+int DBManager::GetProviderPeriod(std::string& provider_id, int* period) {
+ static const char query[] =
+ "SELECT period FROM complication_provider WHERE provider_id=?";
+
+ util::DBHelper db;
+
+ if (!db.Open())
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Prepare(query))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Bind(1, provider_id))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ /* complication_provider table's default value of period is -1.
+ * So, if nothing specified in period, it will return -1
+ */
+ if (db.Step() == SQLITE_ROW)
+ *period = db.GetInt(0);
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+bool DBManager::IsProviderExist(std::string& provider_id, int support_type) {
+ static const char query[] =
+ "SELECT trusted, appid FROM complication_provider as A "
+ "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
+ "WHERE A.provider_id=? AND support_type=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return false;
+
+ if (!db.Prepare(query))
+ return false;
+
+ if (!db.Bind(1, provider_id))
+ return false;
+
+ if (!db.Bind(2, support_type))
+ return false;
+
+ bool is_exist = false;
+ if (db.Step() == SQLITE_ROW) {
+ int trusted;
+
+ trusted = db.GetInt(0);
+ const char* app_id = db.GetText(1);
+ if (app_id == nullptr) {
+ LOGE("app_id is nullptr");
+ return false;
+ }
+ std::string provider_app_id = app_id;
+ if (trusted && util::CheckCertificate(provider_app_id) == false)
+ is_exist = false;
+ else
+ is_exist = true;
+ }
+
+ return is_exist;
+}
+
+std::string DBManager::GetProviderAppId(const char* provider_id) {
+ static const char query[] =
+ "SELECT trusted, appid FROM complication_provider WHERE provider_id=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return std::string();
+
+ if (!db.Prepare(query))
+ return std::string();
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+
+ if (db.Step() != SQLITE_ROW)
+ return std::string();
+
+ int trusted = db.GetInt(0);
+ const char* app_id = db.GetText(1);
+
+ if (app_id == nullptr) {
+ LOGE("app_id is nullptr");
+ return std::string();
+ }
+
+ std::string provider_app_id = app_id;
+ if (trusted && util::CheckCertificate(provider_app_id) == false)
+ return std::string();
+
+ return provider_app_id;
+}
+
+std::list<std::unique_ptr<DBManager::ProviderInfo>>
+DBManager::GetProviderListWithTypes(int supported_types) {
+ static const char query[] =
+ "SELECT trusted, appid, A.provider_id, support_type FROM "
+ "complication_provider as A LEFT JOIN provider_support_types as B "
+ "ON A.provider_id = B.provider_id "
+ "WHERE (support_type & ?) > 0";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return {};
+
+ if (!db.Prepare(query))
+ return {};
+
+ if (!db.Bind(1, supported_types))
+ return {};
+
+ std::list<std::unique_ptr<DBManager::ProviderInfo>> provider_list;
+ while (db.Step() == SQLITE_ROW) {
+ int trusted = db.GetInt(0);
+ const char* app_id = db.GetText(1);
+ if (app_id == nullptr) {
+ LOGE("app_id is nullptr");
+ continue;
+ }
+
+ if (trusted && util::CheckCertificate(std::string(app_id)) == false)
+ continue;
+
+ const char* provider_id = db.GetText(2);
+ if (provider_id == nullptr) {
+ LOGE("prodiver_id is nullptr");
+ continue;
+ }
+ int type = db.GetInt(3);
+ provider_list.emplace_back(
+ std::unique_ptr<ProviderInfo>(new ProviderInfo(provider_id, type)));
+ }
+
+ return provider_list;
+}
+
+std::list<std::string> DBManager::GetProviderListWithAppId(
+ const char* provider_app_id) {
+ static const char query[] =
+ "SELECT DISTINCT provider_id FROM complication_provider WHERE appid=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return {};
+
+ if (!db.Prepare(query))
+ return {};
+
+ if (!db.Bind(1, std::string(provider_app_id)))
+ return {};
+
+ std::list<std::string> provider_list;
+ while (db.Step() == SQLITE_ROW) {
+ const char* provider = db.GetText(0);
+ if (provider == nullptr) {
+ LOGW("provider is nullptr");
+ continue;
+ }
+ provider_list.push_back(std::string(provider));
+ }
+
+ return provider_list;
+}
+
+int DBManager::GetSupportTypes(std::string& provider_id, int* types) {
+ static const char query[] =
+ "SELECT trusted, appid, SUM(support_type) FROM complication_provider as A "
+ "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
+ "WHERE A.provider_id = ?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Prepare(query))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Bind(1, provider_id))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ int supported_types = 0;
+ if (db.Step() == SQLITE_ROW) {
+ int trusted = db.GetInt(0);
+ const char* app_id = db.GetText(1);
+ if (app_id == nullptr) {
+ LOGE("app_id is nullptr");
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+ }
+ std::string provider_app_id = app_id;
+ if (trusted && util::CheckCertificate(provider_app_id) == false)
+ supported_types = 0;
+ else
+ supported_types = db.GetInt(2);
+ }
+
+ *types = supported_types;
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+std::list<std::string> DBManager::GetRequiredPrivilegeList(
+ std::string& provider_id) {
+ static const char query[] =
+ "SELECT DISTINCT privilege FROM provider_privilege WHERE provider_id=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return {};
+
+ if (!db.Prepare(query))
+ return {};
+
+ if (!db.Bind(1, provider_id))
+ return {};
+
+ std::list<std::string> privlege_list;
+ while (db.Step() == SQLITE_ROW) {
+ const char* privilege = db.GetText(0);
+ if (privilege == nullptr) {
+ LOGW("privilege is nullptr");
+ continue;
+ }
+ privlege_list.push_back(std::string(privilege));
+ }
+
+ return privlege_list;
+}
+
+/*
+Return WATCHFACE_COMPLICATION_EVENT_NONE if there is no required events.
+Return bigger than 1 value if there is at least one required event.
+Return -1 if error occurs.
+*/
+int DBManager::GetRequiredSupportEvents(
+ std::string& provider_id) {
+ int support_events = WATCHFACE_COMPLICATION_EVENT_NONE;
+ static const char query[] =
+ "SELECT support_events FROM provider_support_events WHERE provider_id=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return -1;
+
+ if (!db.Prepare(query))
+ return -1;
+
+ if (!db.Bind(1, provider_id))
+ return -1;
+
+ if (db.Step() == SQLITE_ROW)
+ support_events = db.GetInt(0);
+
+ return support_events;
+}
+
+std::string DBManager::GetSystemLocale() {
+ char* lang;
+ std::string locale;
+ char* ptr;
+ char* tmp;
+
+ lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang == nullptr)
+ return std::string(DEFAULT_LOCALE);
+
+ tmp = strtok_r(lang, ".", &ptr);
+ free(lang);
+ if (tmp == nullptr) {
+ LOGE("failed to get language");
+ return "";
+ }
+
+ locale = std::string(tmp);
+ for (int i = 0; i < (int)locale.size(); i++) {
+ if (locale[i] == '_')
+ locale[i] = '-';
+
+ if (isupper(locale[i]))
+ locale[i] = tolower(locale[i]);
+ }
+ return locale;
+}
+
+std::string DBManager::GetLabel(const char* provider_id) {
+ static const char query[] =
+ "SELECT provider_label FROM provider_localized_info "
+ "WHERE provider_id=? AND locale=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return std::string();
+
+ if (!db.Prepare(query))
+ return std::string();
+
+ std::string locale = GetSystemLocale();
+ if (locale.empty())
+ return "";
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+
+ if (!db.Bind(2, locale))
+ return std::string();
+
+ std::string label;
+ if (db.Step() == SQLITE_ROW) {
+ const char* lb = db.GetText(0);
+ if (lb == nullptr) {
+ LOGW("lb is nullptr");
+ } else {
+ label = lb;
+ }
+ }
+
+ if (label.empty()) {
+ sqlite3_reset(db.GetCursor().get());
+ sqlite3_clear_bindings(db.GetCursor().get());
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+ if (!db.Bind(2, DEFAULT_LOCALE))
+ return std::string();
+
+ if (db.Step() == SQLITE_ROW) {
+ const char* lb = db.GetText(0);
+ if (lb == nullptr) {
+ LOGW("lb is nullptr");
+ } else {
+ label = lb;
+ }
+ }
+ }
+
+ return label;
+}
+
+std::string DBManager::GetIcon(std::string provider_id, std::string locale) {
+ static const char query[] =
+ "SELECT icon_path FROM provider_icon "
+ "WHERE provider_id=? AND locale=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return std::string();
+
+ if (!db.Prepare(query))
+ return std::string();
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+
+ if (!db.Bind(2, locale))
+ return std::string();
+
+ std::string icon;
+ if (db.Step() == SQLITE_ROW) {
+ const char* ic = db.GetText(0);
+ if (ic == nullptr) {
+ LOGW("ic is nullptr");
+ } else {
+ icon = ic;
+ }
+ }
+
+ if (!icon.empty())
+ return icon;
+
+ sqlite3_reset(db.GetCursor().get());
+ sqlite3_clear_bindings(db.GetCursor().get());
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+ if (!db.Bind(2, DEFAULT_LOCALE))
+ return std::string();
+
+ if (db.Step() == SQLITE_ROW) {
+ const char* ic = db.GetText(0);
+ if (ic == nullptr) {
+ LOGW("ic is nullptr");
+ } else {
+ icon = ic;
+ }
+ }
+
+ return icon;
+}
+
+std::string DBManager::GetSetupAppId(const char* provider_id) {
+ static const char query[] =
+ "SELECT DISTINCT setup_appid FROM provider_setup_appid WHERE provider_id=?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return std::string();
+
+ if (!db.Prepare(query))
+ return std::string();
+
+ if (!db.Bind(1, provider_id))
+ return std::string();
+
+ std::string setup_appid;
+ if (db.Step() == SQLITE_ROW) {
+ const char* appid = db.GetText(0);
+ if (appid == nullptr) {
+ LOGE("appid is nullptr");
+ return std::string();
+ }
+ setup_appid = appid;
+ }
+
+ return setup_appid;
+}
+
+int DBManager::GetTrustedInfo(std::string& provider_id, bool* trusted) {
+ static const char query[] =
+ "SELECT trusted FROM complication_provider WHERE provider_id = ?";
+ util::DBHelper db;
+
+ if (!db.Open())
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Prepare(query))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (!db.Bind(1, provider_id))
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ if (db.Step() != SQLITE_ROW)
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+
+ int trusted_info = db.GetInt(0);
+ if (trusted_info == 0)
+ *trusted = false;
+ else if (trusted_info == 1)
+ *trusted = true;
+ else
+ return WATCHFACE_COMPLICATION_ERROR_DB;
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+std::list<std::shared_ptr<DBManager::ProviderInfo>>
+DBManager::GetProviderList(std::string& app_id) {
+ std::string query =
+ "SELECT A.provider_id, appid, SUM(support_type) FROM complication_provider as A "
+ "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id";
+
+ if (app_id.empty() == false)
+ query += " WHERE A.appid = ? GROUP BY A.provider_id";
+ else
+ query += " GROUP BY A.provider_id";
+
+ util::DBHelper db;
+
+ if (!db.Open())
+ return {};
+
+ if (!db.Prepare(query))
+ return {};
+
+ if (app_id.empty() == false) {
+ if (!db.Bind(1, app_id))
+ return {};
+ }
+
+ std::string locale = DBManager::GetSystemLocale();
+
+ std::list<std::shared_ptr<DBManager::ProviderInfo>> provider_list;
+ while (db.Step() == SQLITE_ROW) {
+ std::string provider_id = db.GetText(0);
+ std::string app_id = db.GetText(1);
+ int support_types = db.GetInt(2);
+ std::string icon = GetIcon(provider_id, locale);
+ std::string label = GetLabel(provider_id.c_str());
+
+ provider_list.emplace_back(
+ std::shared_ptr<ProviderInfo>(
+ new ProviderInfo(provider_id, support_types, app_id, label, icon)));
+ }
+
+ return provider_list;
+
+}
+
+} // namespace watchface_complication
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WATCHFACE_COMPLICATION_DB_MANAGER_H_
+#define WATCHFACE_COMPLICATION_DB_MANAGER_H_
+
+#include <gio/gio.h>
+#include <sqlite3.h>
+#include <watchface-common.h>
+#include <bundle_cpp.h>
+
+#include <string>
+#include <memory>
+#include <list>
+
+namespace watchface_complication {
+
+class EXPORT_API DBManager {
+ public:
+ class ProviderInfo {
+ std::string provider_id_;
+ int type_;
+ std::string app_id_;
+ std::string label_;
+ std::string icon_;
+
+ public:
+ ProviderInfo(std::string provider_id, int type,
+ std::string app_id = "", std::string label = "", std::string icon = "")
+ : provider_id_(provider_id), type_(type),
+ app_id_(app_id), label_(label), icon_(icon) {
+ }
+ std::string& GetProviderId() {
+ return provider_id_;
+ }
+ std::string& GetAppId() {
+ return app_id_;
+ }
+ std::string& GetLabel() {
+ return label_;
+ }
+ std::string& GetIcon() {
+ return icon_;
+ }
+ int GetType() {
+ return type_;
+ }
+ };
+ static std::unique_ptr<tizen_base::Bundle> GetDefaultData(
+ const char* provider_id, int support_type);
+ static std::string GetProviderAppId(const char* provider_id);
+ static std::list<std::string> GetRequiredPrivilegeList(
+ std::string& provider_id);
+ static int GetRequiredSupportEvents(std::string& provider_id);
+ static std::list<std::unique_ptr<ProviderInfo>> GetProviderListWithTypes(
+ int supported_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);
+ static std::string GetIcon(std::string provider_id, std::string locale);
+ static std::string GetSetupAppId(const char* provider_id);
+ static bool IsProviderExist(std::string& provider_id, int support_type);
+ static std::list<std::string> GetProviderListWithAppId(const char* provider_id);
+ static int GetTrustedInfo(std::string& provider_id, bool* trusted);
+ static std::string GetSystemLocale();
+ static std::list<std::shared_ptr<ProviderInfo>> GetProviderList(std::string& app_id);
+
+ private:
+ DBManager(); /* LCOV_EXCL_LINE */
+ virtual ~DBManager(); /* LCOV_EXCL_LINE */
+};
+
+} // namespace watchface_complication
+
+#endif // WATCHFACE_COMPLICATION_DB_MANAGER_H_
void watchface_complication_provider_set_consumer_status_cb(
watchface_complication_consumer_status_cb callback, void *user_data);
+typedef void *provider_info_h;
+
+typedef void (*complication_provider_foreach_cb)
+ (const provider_info_h info, void *user_data);
+
+int watchface_complication_provider_foreach_info(
+ const char *appid, complication_provider_foreach_cb callback,
+ void *user_data);
+int watchface_complication_provider_info_get_id(const provider_info_h info, char** id);
+int watchface_complication_provider_info_get_app_id(const provider_info_h info, char** app_id);
+int watchface_complication_provider_info_get_label(const provider_info_h info, char** label);
+int watchface_complication_provider_info_get_icon(const provider_info_h info, char** icon);
+int watchface_complication_provider_info_get_types(const provider_info_h info, int* types);
+
#ifdef __cplusplus
}
#endif
#include "watchface-complication-provider/complication-provider.hh"
#include "watchface-complication-provider/include/watchface-complication-provider.h"
#include "watchface-complication-provider/include/watchface-complication-provider-internal.h"
-#include "watchface-complication/db-manager.hh"
+#include "watchface-common/db-manager.hh"
#include "watchface-complication/complication-internal.hh"
#ifdef LOG_TAG
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_foreach_info(
+ const char *appid, complication_provider_foreach_cb callback,
+ void *user_data) {
+ if (callback == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ std::string tmp_appid;
+ if (appid != nullptr && strlen(appid) > 0)
+ tmp_appid = appid;
+
+ std::list<std::shared_ptr<DBManager::ProviderInfo>> provider_list =
+ DBManager::GetProviderList(tmp_appid);
+
+ for (auto& i : provider_list)
+ callback(static_cast<provider_info_h>(i.get()), user_data);
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_info_get_id(
+ const provider_info_h info, char** id) {
+ if (info == nullptr || id == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ DBManager::ProviderInfo* p_info = static_cast<DBManager::ProviderInfo*>(info);
+ string provider_id_ = p_info->GetProviderId();
+ if (provider_id_.empty())
+ return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+
+ char* tmp_id = strdup(provider_id_.c_str());
+ if (tmp_id == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ *id = tmp_id;
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_info_get_app_id(
+ const provider_info_h info, char** app_id) {
+ if (info == nullptr || app_id == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ DBManager::ProviderInfo* p_info = static_cast<DBManager::ProviderInfo*>(info);
+ string app_id_ = p_info->GetAppId();
+ if (app_id_.empty())
+ return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+
+ char* tmp_app_id = strdup(app_id_.c_str());
+ if (tmp_app_id == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ *app_id = tmp_app_id;
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_info_get_label(
+ const provider_info_h info, char** label) {
+ if (info == nullptr || label == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ DBManager::ProviderInfo* p_info = static_cast<DBManager::ProviderInfo*>(info);
+ string label_ = p_info->GetLabel();
+ if (label_.empty())
+ return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+
+ char* tmp_label = strdup(label_.c_str());
+ if (tmp_label == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ *label = tmp_label;
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_info_get_icon(
+ const provider_info_h info, char** icon) {
+ if (info == nullptr || icon == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ DBManager::ProviderInfo* p_info = static_cast<DBManager::ProviderInfo*>(info);
+ string icon_ = p_info->GetIcon();
+ if (icon_.empty())
+ return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+
+ char* tmp_icon = strdup(icon_.c_str());
+ if (tmp_icon == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ *icon = tmp_icon;
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API
+int watchface_complication_provider_info_get_types(
+ const provider_info_h info, int* types) {
+ if (info == nullptr || types == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ DBManager::ProviderInfo* p_info = static_cast<DBManager::ProviderInfo*>(info);
+ *types = p_info->GetType();
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
#include "watchface-complication/gdbus-interface.hh"
#include "watchface-complication/complication-connector.hh"
#include "watchface-complication/editables-manager.hh"
-#include "watchface-complication/db-manager.hh"
+#include "watchface-common/db-manager.hh"
#include "watchface-common/watchface-exception.hh"
#include "watchface-complication-provider/include/watchface-complication-provider-internal.h"
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dlog.h>
-#include <unistd.h>
-#include <sqlite3.h>
-#include <tzplatform_config.h>
-#include <pkgmgr-info.h>
-#include <pkgmgr_installer_info.h>
-#include <vconf.h>
-
-#include "watchface-complication/complication-internal.hh"
-#include "watchface-complication/db-manager.hh"
-#include "watchface-common/watchface-util.hh"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "WATCHFACE_COMPLICATION"
-#define DEFAULT_LOCALE "No Locale"
-
-using namespace tizen_base;
-namespace watchface_complication {
-
-DBManager::DBManager() = default;
-DBManager::~DBManager() = default;
-
-std::unique_ptr<Bundle> DBManager::GetDefaultData(const char* provider_id,
- int support_type) {
- static const char query[] =
- "SELECT trusted, appid, default_data FROM complication_provider as A "
- "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
- "WHERE A.provider_id=? AND support_type=?";
-
- util::DBHelper db;
-
- if (!db.Open())
- return nullptr;
-
- if (!db.Prepare(query))
- return nullptr;
-
- if (!db.Bind(1, provider_id))
- return nullptr;
-
- if (!db.Bind(2, support_type))
- return nullptr;
-
- if (db.Step() != SQLITE_ROW)
- return nullptr;
-
- int trusted = db.GetInt(0);
- const char* app_id = db.GetText(1);
- if (app_id == nullptr) {
- LOGE("app_id is nullptr");
- return nullptr;
- }
-
- std::string provider_app_id = app_id;
- if (trusted && util::CheckCertificate(provider_app_id) == false)
- return nullptr;
-
- const char* raw_data = db.GetText(2);
- if (raw_data == nullptr) {
- LOGE("raw_data is nullptr");
- return nullptr;
- }
-
- std::unique_ptr<Bundle> default_data;
- try {
- default_data = std::unique_ptr<Bundle>(new Bundle(std::string(raw_data)));
- } catch (const std::exception& e) {
- LOGE("Exception occurred : %s", e.what());
- return nullptr;
- }
-
- util::ConvertPathToAppPath(provider_app_id.c_str(),
- default_data.get()->GetHandle());
-
- return default_data;
-}
-
-int DBManager::GetProviderPeriod(std::string& provider_id, int* period) {
- static const char query[] =
- "SELECT period FROM complication_provider WHERE provider_id=?";
-
- util::DBHelper db;
-
- if (!db.Open())
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Prepare(query))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Bind(1, provider_id))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- /* complication_provider table's default value of period is -1.
- * So, if nothing specified in period, it will return -1
- */
- if (db.Step() == SQLITE_ROW)
- *period = db.GetInt(0);
-
- return WATCHFACE_COMPLICATION_ERROR_NONE;
-}
-
-bool DBManager::IsProviderExist(std::string& provider_id, int support_type) {
- static const char query[] =
- "SELECT trusted, appid FROM complication_provider as A "
- "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
- "WHERE A.provider_id=? AND support_type=?";
- util::DBHelper db;
-
- if (!db.Open())
- return false;
-
- if (!db.Prepare(query))
- return false;
-
- if (!db.Bind(1, provider_id))
- return false;
-
- if (!db.Bind(2, support_type))
- return false;
-
- bool is_exist = false;
- if (db.Step() == SQLITE_ROW) {
- int trusted;
-
- trusted = db.GetInt(0);
- const char* app_id = db.GetText(1);
- if (app_id == nullptr) {
- LOGE("app_id is nullptr");
- return false;
- }
- std::string provider_app_id = app_id;
- if (trusted && util::CheckCertificate(provider_app_id) == false)
- is_exist = false;
- else
- is_exist = true;
- }
-
- return is_exist;
-}
-
-std::string DBManager::GetProviderAppId(const char* provider_id) {
- static const char query[] =
- "SELECT trusted, appid FROM complication_provider WHERE provider_id=?";
- util::DBHelper db;
-
- if (!db.Open())
- return std::string();
-
- if (!db.Prepare(query))
- return std::string();
-
- if (!db.Bind(1, provider_id))
- return std::string();
-
- if (db.Step() != SQLITE_ROW)
- return std::string();
-
- int trusted = db.GetInt(0);
- const char* app_id = db.GetText(1);
-
- if (app_id == nullptr) {
- LOGE("app_id is nullptr");
- return std::string();
- }
-
- std::string provider_app_id = app_id;
- if (trusted && util::CheckCertificate(provider_app_id) == false)
- return std::string();
-
- return provider_app_id;
-}
-
-std::list<std::unique_ptr<DBManager::ProviderInfo>>
-DBManager::GetProviderListWithTypes(int supported_types) {
- static const char query[] =
- "SELECT trusted, appid, A.provider_id, support_type FROM "
- "complication_provider as A LEFT JOIN provider_support_types as B "
- "ON A.provider_id = B.provider_id "
- "WHERE (support_type & ?) > 0";
- util::DBHelper db;
-
- if (!db.Open())
- return {};
-
- if (!db.Prepare(query))
- return {};
-
- if (!db.Bind(1, supported_types))
- return {};
-
- std::list<std::unique_ptr<DBManager::ProviderInfo>> provider_list;
- while (db.Step() == SQLITE_ROW) {
- int trusted = db.GetInt(0);
- const char* app_id = db.GetText(1);
- if (app_id == nullptr) {
- LOGE("app_id is nullptr");
- continue;
- }
-
- if (trusted && util::CheckCertificate(std::string(app_id)) == false)
- continue;
-
- const char* provider_id = db.GetText(2);
- if (provider_id == nullptr) {
- LOGE("prodiver_id is nullptr");
- continue;
- }
- int type = db.GetInt(3);
- provider_list.emplace_back(
- std::unique_ptr<ProviderInfo>(new ProviderInfo(provider_id, type)));
- }
-
- return provider_list;
-}
-
-std::list<std::string> DBManager::GetProviderListWithAppId(
- const char* provider_app_id) {
- static const char query[] =
- "SELECT DISTINCT provider_id FROM complication_provider WHERE appid=?";
- util::DBHelper db;
-
- if (!db.Open())
- return {};
-
- if (!db.Prepare(query))
- return {};
-
- if (!db.Bind(1, std::string(provider_app_id)))
- return {};
-
- std::list<std::string> provider_list;
- while (db.Step() == SQLITE_ROW) {
- const char* provider = db.GetText(0);
- if (provider == nullptr) {
- LOGW("provider is nullptr");
- continue;
- }
- provider_list.push_back(std::string(provider));
- }
-
- return provider_list;
-}
-
-int DBManager::GetSupportTypes(std::string& provider_id, int* types) {
- static const char query[] =
- "SELECT trusted, appid, SUM(support_type) FROM complication_provider as A "
- "LEFT JOIN provider_support_types as B ON A.provider_id = B.provider_id "
- "WHERE A.provider_id = ?";
- util::DBHelper db;
-
- if (!db.Open())
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Prepare(query))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Bind(1, provider_id))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- int supported_types = 0;
- if (db.Step() == SQLITE_ROW) {
- int trusted = db.GetInt(0);
- const char* app_id = db.GetText(1);
- if (app_id == nullptr) {
- LOGE("app_id is nullptr");
- return WATCHFACE_COMPLICATION_ERROR_DB;
- }
- std::string provider_app_id = app_id;
- if (trusted && util::CheckCertificate(provider_app_id) == false)
- supported_types = 0;
- else
- supported_types = db.GetInt(2);
- }
-
- *types = supported_types;
-
- return WATCHFACE_COMPLICATION_ERROR_NONE;
-}
-
-std::list<std::string> DBManager::GetRequiredPrivilegeList(
- std::string& provider_id) {
- static const char query[] =
- "SELECT DISTINCT privilege FROM provider_privilege WHERE provider_id=?";
- util::DBHelper db;
-
- if (!db.Open())
- return {};
-
- if (!db.Prepare(query))
- return {};
-
- if (!db.Bind(1, provider_id))
- return {};
-
- std::list<std::string> privlege_list;
- while (db.Step() == SQLITE_ROW) {
- const char* privilege = db.GetText(0);
- if (privilege == nullptr) {
- LOGW("privilege is nullptr");
- continue;
- }
- privlege_list.push_back(std::string(privilege));
- }
-
- return privlege_list;
-}
-
-/*
-Return WATCHFACE_COMPLICATION_EVENT_NONE if there is no required events.
-Return bigger than 1 value if there is at least one required event.
-Return -1 if error occurs.
-*/
-int DBManager::GetRequiredSupportEvents(
- std::string& provider_id) {
- int support_events = WATCHFACE_COMPLICATION_EVENT_NONE;
- static const char query[] =
- "SELECT support_events FROM provider_support_events WHERE provider_id=?";
- util::DBHelper db;
-
- if (!db.Open())
- return -1;
-
- if (!db.Prepare(query))
- return -1;
-
- if (!db.Bind(1, provider_id))
- return -1;
-
- if (db.Step() == SQLITE_ROW)
- support_events = db.GetInt(0);
-
- return support_events;
-}
-
-std::string DBManager::GetSystemLocale() {
- char* lang;
- std::string locale;
- char* ptr;
- char* tmp;
-
- lang = vconf_get_str(VCONFKEY_LANGSET);
- if (lang == nullptr)
- return std::string(DEFAULT_LOCALE);
-
- tmp = strtok_r(lang, ".", &ptr);
- free(lang);
- if (tmp == nullptr) {
- LOGE("failed to get language");
- return "";
- }
-
- locale = std::string(tmp);
- for (int i = 0; i < (int)locale.size(); i++) {
- if (locale[i] == '_')
- locale[i] = '-';
-
- if (isupper(locale[i]))
- locale[i] = tolower(locale[i]);
- }
- return locale;
-}
-
-std::string DBManager::GetLabel(const char* provider_id) {
- static const char query[] =
- "SELECT provider_label FROM provider_localized_info "
- "WHERE provider_id=? AND locale=?";
- util::DBHelper db;
-
- if (!db.Open())
- return std::string();
-
- if (!db.Prepare(query))
- return std::string();
-
- std::string locale = GetSystemLocale();
- if (locale.empty())
- return "";
-
- if (!db.Bind(1, provider_id))
- return std::string();
-
- if (!db.Bind(2, locale))
- return std::string();
-
- std::string label;
- if (db.Step() == SQLITE_ROW) {
- const char* lb = db.GetText(0);
- if (lb == nullptr) {
- LOGW("lb is nullptr");
- } else {
- label = lb;
- }
- }
-
- if (label.empty()) {
- sqlite3_reset(db.GetCursor().get());
- sqlite3_clear_bindings(db.GetCursor().get());
-
- if (!db.Bind(1, provider_id))
- return std::string();
- if (!db.Bind(2, DEFAULT_LOCALE))
- return std::string();
-
- if (db.Step() == SQLITE_ROW) {
- const char* lb = db.GetText(0);
- if (lb == nullptr) {
- LOGW("lb is nullptr");
- } else {
- label = lb;
- }
- }
- }
-
- return label;
-}
-
-std::string DBManager::GetIcon(std::string provider_id, std::string locale) {
- static const char query[] =
- "SELECT icon_path FROM provider_icon "
- "WHERE provider_id=? AND locale=?";
- util::DBHelper db;
-
- if (!db.Open())
- return std::string();
-
- if (!db.Prepare(query))
- return std::string();
-
- if (!db.Bind(1, provider_id))
- return std::string();
-
- if (!db.Bind(2, locale))
- return std::string();
-
- std::string icon;
- if (db.Step() == SQLITE_ROW) {
- const char* ic = db.GetText(0);
- if (ic == nullptr) {
- LOGW("ic is nullptr");
- } else {
- icon = ic;
- }
- }
-
- if (!icon.empty())
- return icon;
-
- sqlite3_reset(db.GetCursor().get());
- sqlite3_clear_bindings(db.GetCursor().get());
-
- if (!db.Bind(1, provider_id))
- return std::string();
- if (!db.Bind(2, DEFAULT_LOCALE))
- return std::string();
-
- if (db.Step() == SQLITE_ROW) {
- const char* ic = db.GetText(0);
- if (ic == nullptr) {
- LOGW("ic is nullptr");
- } else {
- icon = ic;
- }
- }
-
- return icon;
-}
-
-std::string DBManager::GetSetupAppId(const char* provider_id) {
- static const char query[] =
- "SELECT DISTINCT setup_appid FROM provider_setup_appid WHERE provider_id=?";
- util::DBHelper db;
-
- if (!db.Open())
- return std::string();
-
- if (!db.Prepare(query))
- return std::string();
-
- if (!db.Bind(1, provider_id))
- return std::string();
-
- std::string setup_appid;
- if (db.Step() == SQLITE_ROW) {
- const char* appid = db.GetText(0);
- if (appid == nullptr) {
- LOGE("appid is nullptr");
- return std::string();
- }
- setup_appid = appid;
- }
-
- return setup_appid;
-}
-
-int DBManager::GetTrustedInfo(std::string& provider_id, bool* trusted) {
- static const char query[] =
- "SELECT trusted FROM complication_provider WHERE provider_id = ?";
- util::DBHelper db;
-
- if (!db.Open())
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Prepare(query))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (!db.Bind(1, provider_id))
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- if (db.Step() != SQLITE_ROW)
- return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
-
- int trusted_info = db.GetInt(0);
- if (trusted_info == 0)
- *trusted = false;
- else if (trusted_info == 1)
- *trusted = true;
- else
- return WATCHFACE_COMPLICATION_ERROR_DB;
-
- return WATCHFACE_COMPLICATION_ERROR_NONE;
-}
-
-} // namespace watchface_complication
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef WATCHFACE_COMPLICATION_DB_MANAGER_H_
-#define WATCHFACE_COMPLICATION_DB_MANAGER_H_
-
-#include <gio/gio.h>
-#include <sqlite3.h>
-#include <watchface-common.h>
-#include <bundle_cpp.h>
-
-#include <string>
-#include <memory>
-#include <list>
-
-namespace watchface_complication {
-
-class EXPORT_API DBManager {
- public:
- class ProviderInfo {
- std::string provider_id_;
- int type_;
- public:
- ProviderInfo(std::string provider_id, int type)
- : provider_id_(provider_id), type_(type) {
- }
- std::string& GetProviderId() {
- return provider_id_;
- }
- int GetType() {
- return type_;
- }
- };
- static std::unique_ptr<tizen_base::Bundle> GetDefaultData(
- const char* provider_id, int support_type);
- static std::string GetProviderAppId(const char* provider_id);
- static std::list<std::string> GetRequiredPrivilegeList(
- std::string& provider_id);
- static int GetRequiredSupportEvents(std::string& provider_id);
- static std::list<std::unique_ptr<ProviderInfo>> GetProviderListWithTypes(
- int supported_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);
- static std::string GetIcon(std::string provider_id, std::string locale);
- static std::string GetSetupAppId(const char* provider_id);
- static bool IsProviderExist(std::string& provider_id, int support_type);
- static std::list<std::string> GetProviderListWithAppId(const char* provider_id);
- static int GetTrustedInfo(std::string& provider_id, bool* trusted);
- static std::string GetSystemLocale();
-
- private:
- DBManager(); /* LCOV_EXCL_LINE */
- virtual ~DBManager(); /* LCOV_EXCL_LINE */
-};
-
-} // namespace watchface_complication
-
-#endif // WATCHFACE_COMPLICATION_DB_MANAGER_H_