• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_DATABASE_ADAPTER_INTERFACE_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_DATABASE_ADAPTER_INTERFACE_H
18 
19 #include <errors.h>
20 #include <string>
21 
22 namespace OHOS {
23 namespace AccountSA {
24 enum DbAdapterSecurityLevel : int32_t {
25     INVALID_LABEL = -1,
26     NO_LABEL,
27     S0,
28     S1,
29     S2,
30     S3_EX,
31     S3,
32     S4,
33 };
34 
35 enum DbAdapterArea : int32_t {
36     INVALID_AREA = -1,
37     EL0,
38     EL1,
39     EL2,
40     EL3,
41     EL4
42 };
43 
44 enum DbAdapterStatus : int32_t {
45     SUCCESS = ERR_OK,
46     IPC_ERROR,
47     INTERNAL_ERROR,
48     KEY_NOT_EXIST,
49 };
50 
51 struct DbAdapterOptions {
52     bool encrypt = false;
53     bool autoSync = false;
54     DbAdapterSecurityLevel securityLevel = DbAdapterSecurityLevel::S1;
55     DbAdapterArea area = DbAdapterArea::EL1;
56     std::string baseDir;
57 };
58 
59 struct DbAdapterEntry {
60     std::string key;
61     std::string value;
62 };
63 
64 class IDbAdapterSingleStore {
65 public:
66     virtual ~IDbAdapterSingleStore() = default;
67     virtual DbAdapterStatus Get(const std::string &keyStr, std::string &valueStr) = 0;
68     virtual DbAdapterStatus Delete(const std::string &keyStr) = 0;
69     virtual DbAdapterStatus Put(const std::string &keyStr, const std::string &valueStr) = 0;
70     virtual DbAdapterStatus GetEntries(const std::string subId,
71         std::vector<DbAdapterEntry> &allEntries) = 0;
72 #ifndef SQLITE_DLCLOSE_ENABLE
73     virtual DbAdapterStatus PutBatch(const std::vector<DbAdapterEntry> &entries) = 0;
74 #endif // SQLITE_DLCLOSE_ENABLE
75 };
76 
77 class IDbAdapterDataManager {
78 public:
79     virtual ~IDbAdapterDataManager() = default;
80     virtual DbAdapterStatus CloseKvStore(const std::string appIdStr,
81         std::shared_ptr<IDbAdapterSingleStore> &kvStorePtr) = 0;
82     virtual DbAdapterStatus GetSingleKvStore(const DbAdapterOptions &options, const std::string &appIdStr,
83         const std::string &storeIdStr, std::shared_ptr<IDbAdapterSingleStore> &kvStorePtr) = 0;
84 #ifndef SQLITE_DLCLOSE_ENABLE
85     virtual DbAdapterStatus DeleteKvStore(const std::string &appIdStr, const std::string &storeIdStr,
86         const std::string &baseDir) = 0;
87     virtual DbAdapterStatus GetAllKvStoreId(const std::string &appIdStr, std::vector<std::string> &storeIdList) = 0;
88 #endif // SQLITE_DLCLOSE_ENABLE
89 };
90 }  // namespace AccountSA
91 }  // namespace OHOS
92 
93 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_DATABASE_ADAPTER_INTERFACE_H
94