2 * Copyright (c) 2020 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.
17 #include <tzplatform_config.h>
21 #include "allowed-appid/appsvc_db.hh"
22 #include "common/log_private.hh"
26 static const uid_t ROOT_UID = 0;
27 static const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
29 AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
32 AppSvcDB::~AppSvcDB() = default;
34 void AppSvcDB::Insert(const std::string& appid,
35 const std::string& allowed_appid) {
36 static const char query[] = "INSERT OR REPLACE INTO "
37 "allowed_info(appid, allowed_appid) VALUES(?, ?);";
39 __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
40 std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
41 stmt, sqlite3_finalize);
42 __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
43 __BIND_TEXT(GetHandle(), stmt, 2, allowed_appid.c_str());
44 __STEP(GetHandle(), stmt);
47 void AppSvcDB::Delete(const std::string& appid) {
48 static const char query[] = "DELETE FROM allowed_info WHERE appid = ?;";
50 __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
51 std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
52 stmt, sqlite3_finalize);
53 __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
54 __STEP(GetHandle(), stmt);
57 std::string AppSvcDB::GetDBPath(uid_t uid) {
59 if (uid == ROOT_UID || uid == GLOBAL_USER) {
60 db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
62 db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
63 std::to_string(uid) + "/.appsvc.db";