2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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.
20 #include "AppStatisticsTypes.h"
23 #define EMPTY_CHECKER_QID 999
25 ctx::AppDbInitializer::AppDbInitializer()
31 ctx::AppDbInitializer::~AppDbInitializer()
35 void ctx::AppDbInitializer::__createTable()
37 static bool done = false;
40 __dbManager.createTable(0, APP_TABLE_USAGE_LOG, APP_TABLE_USAGE_LOG_COLUMNS, NULL, NULL);
41 __dbManager.createTable(0, APP_TABLE_REMOVABLE_APP, APP_TABLE_REMOVABLE_APP_COLUMNS, NULL, NULL);
42 __dbManager.execute(0, APP_TEMP_USAGE_FREQ_SQL, NULL);
47 void ctx::AppDbInitializer::__checkAppList()
49 __dbManager.execute(EMPTY_CHECKER_QID, "SELECT * FROM " APP_TABLE_REMOVABLE_APP " LIMIT 1", this);
52 void ctx::AppDbInitializer::__duplicateAppList()
55 package_manager_filter_h filter;
57 err = package_manager_filter_create(&filter);
58 IF_FAIL_VOID_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_create() failed");
60 err = package_manager_filter_add_bool(filter, PACKAGE_MANAGER_PKGINFO_PROP_REMOVABLE, true);
61 IF_FAIL_CATCH_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_add_bool() failed");
63 err = package_manager_filter_foreach_package_info(filter, __packageInfoCb, this);
64 IF_FAIL_CATCH_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_foreach_package_info() failed");
68 package_manager_filter_destroy(filter);
71 bool ctx::AppDbInitializer::__packageInfoCb(package_info_h packageInfo, void *userData)
73 int err = package_info_foreach_app_from_package(packageInfo, PACKAGE_INFO_UIAPP, __appInfoCb, userData);
74 IF_FAIL_RETURN_TAG(err == PACKAGE_MANAGER_ERROR_NONE, false, _E, "package_info_foreach_app_from_package() failed");
78 bool ctx::AppDbInitializer::__appInfoCb(package_info_app_component_type_e compType, const char *appId, void *userData)
81 DatabaseManager dbManager;
83 data.set(NULL, KEY_APP_ID, appId);
84 return dbManager.insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
87 void ctx::AppDbInitializer::onTableCreated(unsigned int queryId, int error)
91 void ctx::AppDbInitializer::onInserted(unsigned int queryId, int error, int64_t rowId)
95 void ctx::AppDbInitializer::onExecuted(unsigned int queryId, int error, std::vector<Json>& records)
97 if (queryId != EMPTY_CHECKER_QID) {
98 _E("Unknown Query ID: %d", queryId);
104 __duplicateAppList();