2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @file backendlib.cpp
20 * @author Soyoung Kim (sy037.kim@samsung.com)
22 * @brief This is implementation file for providing widget information
25 #include "package-manager-plugin.h"
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <vcore/VCore.h>
29 #include <dpl/wrt-dao-ro/WrtDatabase.h>
30 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
31 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
32 #include <dpl/wrt-dao-ro/widget_config.h>
34 #include <dpl/db/sql_connection.h>
35 #include <dpl/log/log.h>
36 #include <dpl/foreach.h>
37 #include <dpl/utils/folder_size.h>
38 #include <dpl/wrt-dao-ro/wrt_db_types.h>
40 using namespace WrtDB;
46 #define GET_DIRECTORY_SIZE_KB(x) (x)/1024
53 static void pkg_native_plugin_on_unload();
54 static int pkg_plugin_app_is_installed(const char *pkg_name);
55 static int pkg_plugin_get_installed_apps_list(const char *category,
56 const char *option, package_manager_pkg_info_t **list, int *count);
57 static int pkg_plugin_get_app_detail_info(const char *pkg_name,
58 package_manager_pkg_detail_info_t *pkg_detail_info);
59 static int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
60 package_manager_pkg_detail_info_t *pkg_detail_info);
62 static void pkg_native_plugin_on_unload()
64 LogDebug("pkg_native_plugin_unload() is called");
67 static int pkg_plugin_app_is_installed(const char *pkg_name)
69 LogDebug("pkg_plugin_app_is_installed() is called");
71 WrtDB::WrtDatabase::attachToThreadRO();
73 bool result = WidgetDAOReadOnly::isWidgetInstalled(
74 DPL::FromUTF8String(pkg_name));
75 WrtDB::WrtDatabase::detachFromThread();
84 static int pkg_plugin_get_installed_apps_list(const char * /*category*/,
85 const char * /*option*/, package_manager_pkg_info_t **list, int *count)
87 LogDebug("pkg_plugin_get_installed_apps_list() is called");
89 package_manager_pkg_info_t *pkg_list = NULL;
90 package_manager_pkg_info_t *pkg_last = NULL;
93 WrtDB::WrtDatabase::attachToThreadRO();
94 WidgetPkgNameList pkgnameslList = WidgetDAOReadOnly::getPkgnameList();
97 FOREACH(iterator, pkgnameslList) {
98 package_manager_pkg_info_t *pkg_info =
99 static_cast<package_manager_pkg_info_t*>
100 (malloc(sizeof(package_manager_pkg_info_t)));
102 if (NULL == pkg_list) {
106 pkg_last->next = pkg_info;
109 WidgetPkgName pkgname = *iterator;
110 WidgetDAOReadOnly widget(pkgname);
111 strncpy(pkg_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
112 snprintf(pkg_info->pkg_name, PKG_NAME_STRING_LEN_MAX, "%s",
113 DPL::ToUTF8String(pkgname).c_str());
115 DPL::Optional<DPL::String> version = widget.getVersion();
116 if (!version.IsNull()) {
117 strncpy(pkg_info->version,
118 DPL::ToUTF8String(*version).c_str(),
119 PKG_VERSION_STRING_LEN_MAX - 1);
126 WrtDB::WrtDatabase::detachFromThread();
131 static int pkg_plugin_get_app_detail_info(const char *pkg_name,
132 package_manager_pkg_detail_info_t *pkg_detail_info)
134 LogDebug("pkg_plugin_get_app_detail_info() is called");
137 WrtDB::WrtDatabase::attachToThreadRO();
138 int handle = WidgetDAOReadOnly::getHandle(
139 DPL::FromUTF8String(pkg_name));
140 WidgetDAOReadOnly widget(handle);
142 DPL::Optional<DPL::String> version = widget.getVersion();
143 DPL::Optional<DPL::String> id = widget.getGUID();
144 DPL::Optional<DPL::String> locale = widget.getDefaultlocale();
146 if (!version.IsNull()) {
147 strncpy(pkg_detail_info->version,
148 DPL::ToUTF8String(*version).c_str(),
149 PKG_VERSION_STRING_LEN_MAX - 1);
151 snprintf(pkg_detail_info->optional_id, PKG_NAME_STRING_LEN_MAX, "%d",
153 WidgetLocalizedInfo localizedInfo;
155 if (locale.IsNull()) {
157 DPL::String languageTag(L"");
158 localizedInfo = widget.getLocalizedInfo(languageTag);
160 localizedInfo = widget.getLocalizedInfo(*locale);
162 DPL::Optional<DPL::String> desc(localizedInfo.description);
164 if (!desc.IsNull()) {
165 strncpy(pkg_detail_info->pkg_description,
166 DPL::ToUTF8String(*desc).c_str(),
167 PKG_VALUE_STRING_LEN_MAX - 1);
169 strncpy(pkg_detail_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
170 strncpy(pkg_detail_info->pkg_name, pkg_name, PKG_NAME_STRING_LEN_MAX - 1);
172 /* set installed time */
173 pkg_detail_info->installed_time = widget.getInstallTime();
175 /* set Widget size */
176 DPL::String pkgName = DPL::FromUTF8String(pkg_name);
177 std::string installPath = WidgetConfig::GetWidgetBasePath(pkgName);
178 std::string persistentPath =
179 WidgetConfig::GetWidgetPersistentStoragePath(pkgName);
180 std::string tempPath =
181 WidgetConfig::GetWidgetTemporaryStoragePath(pkgName);
184 persistentPath += "/";
186 size_t installedSize = Utils::getFolderSize(installPath);
187 size_t persistentSize = Utils::getFolderSize(persistentPath);
188 size_t appSize = installedSize - persistentSize;
189 size_t dataSize = persistentSize + Utils::getFolderSize(tempPath);
191 pkg_detail_info->installed_size = GET_DIRECTORY_SIZE_KB(installedSize);
192 pkg_detail_info->app_size = GET_DIRECTORY_SIZE_KB(appSize);
193 pkg_detail_info->data_size = GET_DIRECTORY_SIZE_KB(dataSize);
195 WrtDB::WrtDatabase::detachFromThread();
199 static int pkg_plugin_get_app_detail_info_from_package(
200 const char * /*pkg_path*/,
201 package_manager_pkg_detail_info_t * /*pkg_detail_info*/)
203 LogDebug("pkg_plugin_get_app_detail_info_from_package() is called");
208 __attribute__ ((visibility("default")))
209 int pkg_plugin_on_load(pkg_plugin_set *set)
211 DPL::Log::LogSystemSingleton::Instance().SetTag("WGT-BACKLIB");
215 memset(set, 0x00, sizeof(pkg_plugin_set));
217 set->plugin_on_unload = pkg_native_plugin_on_unload;
218 set->pkg_is_installed = pkg_plugin_app_is_installed;
219 set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list;
220 set->get_pkg_detail_info = pkg_plugin_get_app_detail_info;
221 set->get_pkg_detail_info_from_package =
222 pkg_plugin_get_app_detail_info_from_package;