2 * Copyright (c) 2000 - 2016 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 * @author Hyunho Kang (hhstark.kang@samsung.com)
27 #include <sys/types.h>
32 #include "rua_stat_internal.h"
36 int rua_stat_update_for_uid(char *caller, char *tag, uid_t uid)
41 r = _rua_util_check_uid(uid);
45 if (caller == NULL || tag == NULL) {
46 LOGE("invalid param");
52 LOGE("bundle_create fail out of memory.");
55 bundle_add_str(b, AUL_SVC_K_RUA_STAT_CALLER, caller);
56 bundle_add_str(b, AUL_SVC_K_RUA_STAT_TAG, tag);
57 r = aul_update_rua_stat_for_uid(b, uid);
58 LOGI("rua_add_history_for_uid result : %d ", r);
63 int rua_stat_get_stat_tags(char *caller,
64 int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
67 return rua_stat_get_stat_tags_for_uid(caller, rua_stat_tag_iter_fn, data, getuid());
70 int rua_stat_get_stat_tags_for_uid(char *caller,
71 int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
72 void *data, uid_t uid)
76 char query[QUERY_MAXLEN];
77 const unsigned char *ct;
80 r = _rua_util_check_uid(uid);
84 r = _rua_stat_init(&db, RUA_STAT_DB_NAME, SQLITE_OPEN_READONLY, uid);
86 LOGE("__rua_stat_init fail");
90 sqlite3_snprintf(QUERY_MAXLEN, query,
91 "SELECT rua_stat_tag FROM rua_panel_stat WHERE caller_panel = ? ORDER BY score DESC");
93 r = sqlite3_prepare(db, query, sizeof(query), &stmt, NULL);
95 LOGE("sqlite3_prepare error(%d , %d, %s)", r, sqlite3_extended_errcode(db), sqlite3_errmsg(db));
99 r = sqlite3_bind_text(stmt, 1, caller, strlen(caller), SQLITE_STATIC);
100 if (r != SQLITE_OK) {
101 LOGE("caller bind error(%d) \n", r);
105 while (sqlite3_step(stmt) == SQLITE_ROW) {
106 ct = sqlite3_column_text(stmt, 0);
107 if (ct == NULL || ct[0] == '\0')
108 LOGW("sqlite3_column_text null");
110 rua_stat_tag_iter_fn((const char *)ct, data);
115 sqlite3_finalize(stmt);