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.
19 #include <types_internal.h>
21 #include <zone_util.h>
22 #include "app_stats_types.h"
25 #define EMPTY_CHECKER_QID 999
27 ctx::app_db_initializer::app_db_initializer()
33 ctx::app_db_initializer::~app_db_initializer()
37 void ctx::app_db_initializer::create_table()
39 static bool done = false;
42 db_manager::create_table(0, APP_TABLE_USAGE_LOG, APP_TABLE_USAGE_LOG_COLUMNS, NULL, NULL);
43 db_manager::create_table(0, APP_TABLE_REMOVABLE_APP, APP_TABLE_REMOVABLE_APP_COLUMNS, NULL, NULL);
44 db_manager::execute(0, APP_TEMP_USAGE_FREQ_SQL, NULL);
49 void ctx::app_db_initializer::check_app_list()
51 db_manager::execute(EMPTY_CHECKER_QID, "SELECT * FROM " APP_TABLE_REMOVABLE_APP " LIMIT 1", this);
54 void ctx::app_db_initializer::duplicate_app_list()
57 package_manager_filter_h filter;
59 scope_zone_joiner sz(zone_util::default_zone());
61 err = package_manager_filter_create(&filter);
62 IF_FAIL_VOID_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_create() failed");
64 err = package_manager_filter_add_bool(filter, PACKAGE_MANAGER_PKGINFO_PROP_REMOVABLE, true);
65 IF_FAIL_CATCH_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_add_bool() failed");
67 err = package_manager_filter_foreach_package_info(filter, package_info_cb, this);
68 IF_FAIL_CATCH_TAG(err == PACKAGE_MANAGER_ERROR_NONE, _E, "package_manager_filter_foreach_package_info() failed");
72 package_manager_filter_destroy(filter);
75 bool ctx::app_db_initializer::package_info_cb(package_info_h package_info, void *user_data)
77 int err = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_UIAPP, app_info_cb, user_data);
78 IF_FAIL_RETURN_TAG(err == PACKAGE_MANAGER_ERROR_NONE, false, _E, "package_info_foreach_app_from_package() failed");
82 bool ctx::app_db_initializer::app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
85 data.set(NULL, STATS_APP_ID, app_id);
86 return db_manager::insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
89 void ctx::app_db_initializer::on_creation_result_received(unsigned int query_id, int error)
93 void ctx::app_db_initializer::on_insertion_result_received(unsigned int query_id, int error, int64_t row_id)
97 void ctx::app_db_initializer::on_query_result_received(unsigned int query_id, int error, std::vector<json>& records)
99 if (query_id != EMPTY_CHECKER_QID) {
100 _E("Unknown Query ID: %d", query_id);
106 duplicate_app_list();