• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_CONSTANTS_H
17 #define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_CONSTANTS_H
18 
19 #include <unordered_set>
20 #include <string>
21 #include <unistd.h>
22 
23 #ifdef __LP64__
24 constexpr const char* LIB_LOAD_PATH = "/system/lib64/";
25 #else
26 constexpr const char* LIB_LOAD_PATH = "/system/lib/";
27 #endif
28 
29 namespace OHOS {
30 namespace DistributedDeviceProfile {
31 /* DeviceProfile Attribute */
32 const std::string DEVICE_ID = "deviceId";
33 const std::string DEVICE_TYPE_ID = "deviceTypeId";
34 const std::string DEVICE_TYPE_NAME = "deviceTypeName";
35 const std::string DEVICE_NAME = "deviceIdName";
36 const std::string MANUFACTURE_NAME = "manufactureName";
37 const std::string DEVICE_MODEL = "deviceModel";
38 const std::string SERIAL_NUMBER_ID = "serialNumberId";
39 const std::string STORAGE_CAPACITY = "storageCapacity";
40 const std::string OS_SYS_CAPACITY = "osSysCapacity";
41 const std::string OS_API_LEVEL = "osApiLevel";
42 const std::string OS_VERSION = "osVersion";
43 const std::string OS_TYPE = "osType";
44 /* ServiceProfile Attribute */
45 const std::string SERVICE_NAME = "serviceName";
46 const std::string SERVICE_TYPE = "serviceType";
47 /* CharacteristicProfile Attribute */
48 const std::string CHARACTERISTIC_KEY = "characteristicKey";
49 const std::string CHARACTERISTIC_VALUE = "characteristicValue";
50 /* TrustDeviceProfile Attribute */
51 const std::string SUBSCRIBE_TRUST_DEVICE_PROFILE = "trust_device_profile";
52 const std::string DEVICE_ID_TYPE = "deviceIdType";
53 const std::string DEVICE_ID_HASH = "deviceIdHash";
54 /* AccessControlProfile Attribute */
55 const std::string ACCESS_CONTROL_ID = "accessControlId";
56 const std::string ACCESSER_ID = "accesserId";
57 const std::string ACCESSEE_ID = "accesseeId";
58 const std::string TRUST_DEVICE_ID = "trustDeviceId";
59 const std::string SESSION_KEY = "sessionKey";
60 const std::string BIND_TYPE = "bindType";
61 const std::string AUTHENTICATION_TYPE = "authenticationType";
62 const std::string BIND_LEVEL = "bindLevel";
63 const std::string STATUS = "status";
64 const std::string VALID_PERIOD = "validPeriod";
65 const std::string LAST_AUTH_TIME = "lastAuthTime";
66 /* Accesser Attribute */
67 const std::string ACCESSER_DEVICE_ID = "accesserDeviceId";
68 const std::string ACCESSER_USER_ID = "accesserUserId";
69 const std::string ACCESSER_ACCOUNT_ID = "accesserAccountId";
70 const std::string ACCESSER_TOKEN_ID = "accesserTokenId";
71 const std::string ACCESSER_BUNDLE_NAME = "accesserBundleName";
72 const std::string ACCESSER_HAP_SIGNATURE = "accesserHapSignature";
73 const std::string ACCESSER_BIND_LEVEL = "accesserBindLevel";
74 /* Accessee Attribute */
75 const std::string ACCESSEE_DEVICE_ID = "accesseeDeviceId";
76 const std::string ACCESSEE_USER_ID = "accesseeUserId";
77 const std::string ACCESSEE_ACCOUNT_ID = "accesseeAccountId";
78 const std::string ACCESSEE_TOKEN_ID = "accesseeTokenId";
79 const std::string ACCESSEE_BUNDLE_NAME = "accesseeBundleName";
80 const std::string ACCESSEE_HAP_SIGNATURE = "accesseeHapSignature";
81 const std::string ACCESSEE_BIND_LEVEL = "accesseeBindLevel";
82 /* subscribe info */
83 const std::string SA_ID = "saId";
84 const std::string SUBSCRIBE_KEY = "subscribeKey";
85 const std::string SUBSCRIBE_CHANGE_TYPES = "subscribeChangeTypes";
86 /* syncOptions */
87 const std::string SYNC_MODE = "syncMode";
88 const std::string SYNC_DEVICE_IDS = "syncDevices";
89 /* Interface Name */
90 const std::string PUT_ACCESS_CONTROL_PROFILE = "PutAccessControlProfile";
91 const std::string UPDATE_ACCESS_CONTROL_PROFILE = "UpdateAccessControlProfile";
92 const std::string GET_ACCESS_CONTROL_PROFILE = "GetAccessControlProfile";
93 const std::string DELETE_ACCESS_CONTROL_PROFILE = "DeleteAccessControlProfile";
94 const std::string GET_TRUST_DEVICE_PROFILE = "GetTrustDeviceProfile";
95 const std::string GET_ALL_TRUST_DEVICE_PROFILE = "GetAllTrustDeviceProfile";
96 const std::string GET_ALL_ACCESS_CONTROL_PROFILE = "GetAllAccessControlProfile";
97 const std::string PUT_SERVICE_PROFILE = "PutServiceProfile";
98 const std::string PUT_SERVICE_PROFILE_BATCH = "PutServiceProfileBatch";
99 const std::string PUT_CHARACTERISTIC_PROFILE = "PutCharacteristicProfile";
100 const std::string PUT_CHARACTERISTIC_PROFILE_BATCH = "PutCharacteristicProfileBatch";
101 const std::string GET_DEVICE_PROFILE = "GetDeviceProfile";
102 const std::string GET_SERVICE_PROFILE = "GetServiceProfile";
103 const std::string GET_CHARACTERISTIC_PROFILE = "GetCharacteristicProfile";
104 const std::string DELETE_SERVICE_PROFILE = "DeleteServiceProfile";
105 const std::string DELETE_CHARACTERISTIC_PROFILE = "DeleteCharacteristicProfile";
106 const std::string SUBSCRIBE_DEVICE_PROFILE = "SubscribeDeviceProfile";
107 const std::string UNSUBSCRIBE_DEVICE_PROFILE = "UnSubscribeDeviceProfile";
108 const std::string SYNC_DEVICE_PROFILE = "SyncDeviceProfile";
109 /* Common constants */
110 constexpr int32_t MIN_STRING_LEN = 0;
111 constexpr int32_t MAX_STRING_LEN = 4096;
112 constexpr int64_t MIN_STORAGE_KB = 0;
113 constexpr int64_t MAX_STORAGE_KB = 5368709120;
114 constexpr int32_t MIN_OS_API_LEVEL = 0;
115 constexpr int32_t MAX_OS_API_LEVEL = 10000;
116 constexpr int32_t MIN_OS_TYPE = 0;
117 constexpr int32_t MAX_OS_TYPE = 10000;
118 constexpr int32_t MAX_PARAM_SIZE = 20;
119 constexpr int32_t MAX_PROFILE_SIZE = 10000;
120 constexpr int32_t MAX_DEVICE_SIZE = 1000;
121 constexpr int32_t MAX_SERVICE_SIZE = 1000;
122 constexpr int32_t MAX_CHAR_SIZE = 1000;
123 constexpr int32_t MAX_DB_SIZE = 1000;
124 constexpr int32_t MAX_LISTENER_SIZE = 100;
125 constexpr int32_t MAX_EVENT_HANDLER_SIZE = 50;
126 constexpr int32_t MAX_DB_RECORD_SIZE = 10000;
127 constexpr int32_t MAX_SUBSCRIBE_CHANGE_SIZE = 3;
128 constexpr int32_t MAX_INTERFACE_SIZE = 20;
129 constexpr int32_t MAX_SUBSCRIBE_INFO_SIZE = 500;
130 constexpr int32_t MAX_SYNC_RESULTS_SIZE = 50;
131 const std::string SEPARATOR = "#";
132 const std::string DEV_PREFIX = "dev";
133 const std::string SVR_PREFIX = "svr";
134 const std::string CHAR_PREFIX = "char";
135 const std::string USER_ID = "user_id";
136 const std::string TOKEN_ID = "token_id";
137 const std::string PKG_NAME = "DBinderBus_" + std::to_string(getpid());
138 const std::string ALL_PROC = "all";
139 constexpr int32_t NUM_1 = 1;
140 constexpr int32_t NUM_2 = 2;
141 constexpr int32_t NUM_3 = 3;
142 /* rdb constants */
143 const std::string RDB_PATH = "/data/service/el1/public/database/distributed_device_profile_service/";
144 const std::string DATABASE_NAME = "dp_rdb.db";
145 constexpr int32_t RDB_VERSION = 1;
146 constexpr int32_t RDB_INIT_MAX_TIMES = 30;
147 constexpr int32_t RDB_INIT_INTERVAL_TIME = 100000;
148 /* TrustProfile Manager */
149 const std::string USERID = "userId";
150 const std::string BUNDLENAME = "bundleName";
151 const std::string TOKENID = "tokenId";
152 const std::string ACCOUNTID = "accountId";
153 const std::string DEVICEID_EQUAL_CONDITION = "deviceId = ?";
154 const std::string ACCESSCONTROLID_EQUAL_CONDITION = "accessControlId = ?";
155 const std::string ACCESSERID_EQUAL_CONDITION = "accesserId = ? ";
156 const std::string ACCESSEEID_EQUAL_CONDITION = "accesseeId = ? ";
157 constexpr int32_t ROWCNT_INIT = -1;
158 constexpr int32_t RET_INIT = -1;
159 constexpr int32_t ROWCOUNT_INIT = -1;
160 constexpr int32_t CHANGEROWCNT_INIT = -1;
161 constexpr int32_t COLUMNINDEX_INIT = -1;
162 constexpr int32_t STATUS_INIT = 0;
163 constexpr int32_t BINDTYPE_INIT = -1;
164 constexpr int32_t BINDLEVEL_INIT = -1;
165 constexpr int32_t DELETEROWS_INIT = -1;
166 constexpr int32_t DELETE_ACCESSER_CONDITION = 1;
167 constexpr int32_t DELETE_ACCESSEE_CONDITION = 1;
168 constexpr int32_t DELETE_TRUST_CONDITION = 0;
169 constexpr int64_t ROWID_INIT = -1;
170 constexpr int64_t ACCESSERID_INIT = -1;
171 constexpr int64_t ACCESSEEID_INIT = -1;
172 constexpr int64_t ACCESSCONTROLID_INIT = -1;
173 const std::string CREATE_TURST_DEVICE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS trust_device_table\
174 (\
175     deviceId        TEXT PRIMARY KEY,\
176     deviceIdType    INTEGER,\
177     deviceIdHash    TEXT,\
178     status          INTEGER);";
179 const std::string CREATE_ACCESS_CONTROL_TABLE_SQL = "CREATE TABLE IF NOT EXISTS access_control_table\
180 (\
181     accessControlId    INTEGER PRIMARY KEY,\
182     accesserId         INTEGER,\
183     accesseeId         INTEGER,\
184     trustDeviceId      TEXT,\
185     sessionKey         TEXT,\
186     bindType           INTEGER,\
187     authenticationType INTEGER,\
188     deviceIdType       INTEGER,\
189     deviceIdHash       TEXT,\
190     status             INTEGER,\
191     validPeriod        INTEGER,\
192     lastAuthTime       INTEGER,\
193     bindLevel          INTEGER);";
194 const std::string CREATE_ACCESSER_TABLE_SQL = "CREATE TABLE IF NOT EXISTS accesser_table\
195 (\
196     accesserId           INTEGER PRIMARY KEY,\
197     accesserDeviceId     TEXT,\
198     accesserUserId       INTEGER,\
199     accesserAccountId    TEXT,\
200     accesserTokenId      INTEGER,\
201     accesserBundleName   TEXT,\
202     accesserHapSignature TEXT,\
203     accesserBindLevel    INTEGER\
204 );";
205 const std::string CREATE_ACCESSEE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS accessee_table\
206 (\
207     accesseeId           INTEGER PRIMARY KEY,\
208     accesseeDeviceId     TEXT,\
209     accesseeUserId       INTEGER,\
210     accesseeAccountId    TEXT,\
211     accesseeTokenId      INTEGER,\
212     accesseeBundleName   TEXT,\
213     accesseeHapSignature TEXT,\
214     accesseeBindLevel    INTEGER\
215 );";
216 const std::string CREATE_TURST_DEVICE_TABLE_UNIQUE_INDEX_SQL =
217 "CREATE UNIQUE INDEX if not exists unique_trust_device_table ON trust_device_table \
218 (\
219     deviceId,\
220     deviceIdType,\
221     deviceIdHash,\
222     status);";
223 const std::string CREATE_ACCESS_CONTROL_TABLE_UNIQUE_INDEX_SQL =
224 "CREATE UNIQUE INDEX if not exists unique_access_control_table ON access_control_table \
225 (\
226     accesserId,\
227     accesseeId,\
228     trustDeviceId,\
229     sessionKey,\
230     bindType,\
231     authenticationType,\
232     deviceIdType,\
233     deviceIdHash,\
234     status,\
235     validPeriod,\
236     lastAuthTime,\
237     bindLevel);";
238 const std::string CREATE_ACCESSER_TABLE_UNIQUE_INDEX_SQL =
239 "CREATE UNIQUE INDEX if not exists unique_accesser_table ON accesser_table \
240 (\
241     accesserDeviceId,\
242     accesserUserId,\
243     accesserAccountId,\
244     accesserTokenId,\
245     accesserBundleName,\
246     accesserHapSignature,\
247     accesserBindLevel);";
248 const std::string CREATE_ACCESSEE_TABLE_UNIQUE_INDEX_SQL =
249 "CREATE UNIQUE INDEX if not exists unique_accessee_table ON accessee_table \
250 (\
251     accesseeDeviceId,\
252     accesseeUserId,\
253     accesseeAccountId,\
254     accesseeTokenId,\
255     accesseeBundleName,\
256     accesseeHapSignature,\
257     accesseeBindLevel);";
258 const std::string TRUST_DEVICE_TABLE = "trust_device_table";
259 const std::string ACCESS_CONTROL_TABLE = "access_control_table";
260 const std::string ACCESSER_TABLE = "accesser_table";
261 const std::string ACCESSEE_TABLE = "accessee_table";
262 const std::string SELECT_TRUST_DEVICE_TABLE = "SELECT * FROM trust_device_table";
263 const std::string SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID =
264     "SELECT * FROM trust_device_table WHERE deviceId = ?";
265 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID =
266     "SELECT * FROM access_control_table WHERE accessControlId = ?";
267 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSEEID =
268     "SELECT * FROM access_control_table WHERE accesseeId = ? ";
269 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID =
270     "SELECT * FROM access_control_table WHERE accesserId = ? ";
271 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS =
272     "SELECT * FROM access_control_table WHERE bindType = ? and status = ? ";
273 const std::string SELECT_ACCESS_CONTROL_TABLE = "SELECT * FROM access_control_table";
274 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID =
275     "SELECT * FROM access_control_table WHERE trustDeviceId = ? ";
276 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID_AND_STATUS =
277     "SELECT * FROM access_control_table WHERE trustDeviceId = ? and status = ?";
278 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID = "SELECT * FROM accessee_table WHERE accesseeId = ? ";
279 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID = "SELECT * FROM accesser_table WHERE accesserId = ? ";
280 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERTOKENID =
281     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserTokenId = ?";
282 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEETOKENID =
283     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeTokenId = ?";
284 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERBUNDLENAME =
285     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserBundleName = ?";
286 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEEBUNDLENAME =
287     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeBundleName = ?";
288 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERACCOUNTID =
289     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserAccountId = ?";
290 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEEACCOUNTID =
291     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeAccountId = ?";
292 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID =
293     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? ";
294 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSERID =
295     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? ";
296 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERTOKENID =
297     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserTokenId = ? ";
298 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEETOKENID =
299     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeTokenId = ? ";
300 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEDEVICEID =
301     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeDeviceId = ? ";
302 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERBUNDLENAME =
303     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserBundleName = ? ";
304 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEBUNDLENAME =
305     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeBundleName = ? ";
306 const std::string SELECT_ACCESSEE_TABLE = "SELECT * FROM accessee_table ";
307 const std::string SELECT_ACCESSER_TABLE = "SELECT * FROM accesser_table ";
308 const std::string SELECT_ACCESSER_TABLE_WHERE_ALL =
309     "SELECT * FROM accesser_table WHERE accesserDeviceId = ? and accesserUserId = ? and accesserAccountId = ? and \
310     accesserTokenId = ? and accesserBundleName = ? and accesserHapSignature = ? and accesserBindLevel = ? ";
311 const std::string SELECT_ACCESSEE_TABLE_WHERE_ALL =
312     "SELECT * FROM accessee_table WHERE accesseeDeviceId = ? and accesseeUserId = ? and accesseeAccountId = ? and \
313     accesseeTokenId = ? and accesseeBundleName = ? and accesseeHapSignature = ? and accesseeBindLevel = ? ";
314 /* SubscribeTrustInfoManager */
315 const std::string SUBSCRIBE_TRUST_INFO_TABLE = "subscribe_trust_info_table";
316 const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_SQL =
317     "CREATE TABLE IF NOT EXISTS subscribe_trust_info_table\
318     (\
319         saId                 INTEGER PRIMARY KEY,\
320         subscribeTable       TEXT,\
321     );";
322 const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_UNIQUE_INDEX_SQL =
323     "CREATE UNIQUE INDEX if not exists unique_subscribe_trust_info_table ON subscribe_trust_info_table \
324     (said,\
325     subscribeTable);";
326 const std::string TRUST_DEVICE_DELETE = "TrustDeviceDelete";
327 const std::string TRUST_DEVICE_ADD = "TrustDeviceAdd";
328 const std::string TRUST_DEVICE_UPDATE = "TrustDeviceUpdate";
329 /* event handler factory */
330 const std::string UNLOAD_DP_SA_HANDLER = "unload_dp_sa_handler";
331 const std::string KV_DEATH_HANDLER = "kv_store_death_handler";
332 const std::string ON_SYNC_HANDLER = "kv_sync_completed_handler";
333 const std::string AUTO_SYNC_HANDLER = "auto_sync_handler";
334 } // namespace DistributedDeviceProfile
335 } // namespace OHOS
336 #endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_CONSTANTS_H
337