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 #include "distributed_device_profile_constants.h"
17 
18 namespace OHOS {
19 namespace DistributedDeviceProfile {
20 namespace {
21     const std::string TAG = "DeviceProfileConstants";
22 }
23 /* DeviceProfile Attribute */
24 const std::string DEVICE_ID = "deviceId";
25 const std::string DEVICE_TYPE_ID = "deviceTypeId";
26 const std::string DEVICE_TYPE_NAME = "deviceTypeName";
27 const std::string DEVICE_NAME = "deviceIdName";
28 const std::string MANUFACTURE_NAME = "manufactureName";
29 const std::string DEVICE_MODEL = "deviceModel";
30 const std::string STORAGE_CAPACITY = "storageCapacity";
31 const std::string OS_SYS_CAPACITY = "osSysCapacity";
32 const std::string OS_API_LEVEL = "osApiLevel";
33 const std::string OS_VERSION = "osVersion";
34 const std::string OS_TYPE = "osType";
35 const std::string OH_PROFILE_SUFFIX = "_OH";
36 /* ServiceProfile Attribute */
37 const std::string SERVICE_NAME = "serviceName";
38 const std::string SERVICE_TYPE = "serviceType";
39 /* CharacteristicProfile Attribute */
40 const std::string CHARACTERISTIC_KEY = "characteristicKey";
41 const std::string CHARACTERISTIC_VALUE = "characteristicValue";
42 /* TrustDeviceProfile Attribute */
43 const std::string SUBSCRIBE_TRUST_DEVICE_PROFILE = "trust_device_profile";
44 const std::string DEVICE_ID_TYPE = "deviceIdType";
45 const std::string DEVICE_ID_HASH = "deviceIdHash";
46 /* AccessControlProfile Attribute */
47 const std::string ACCESS_CONTROL_ID = "accessControlId";
48 const std::string ACCESSER_ID = "accesserId";
49 const std::string ACCESSEE_ID = "accesseeId";
50 const std::string TRUST_DEVICE_ID = "trustDeviceId";
51 const std::string SESSION_KEY = "sessionKey";
52 const std::string BIND_TYPE = "bindType";
53 const std::string AUTHENTICATION_TYPE = "authenticationType";
54 const std::string BIND_LEVEL = "bindLevel";
55 const std::string STATUS = "status";
56 const std::string VALID_PERIOD = "validPeriod";
57 const std::string LAST_AUTH_TIME = "lastAuthTime";
58 /* Accesser Attribute */
59 const std::string ACCESSER_DEVICE_ID = "accesserDeviceId";
60 const std::string ACCESSER_USER_ID = "accesserUserId";
61 const std::string ACCESSER_ACCOUNT_ID = "accesserAccountId";
62 const std::string ACCESSER_TOKEN_ID = "accesserTokenId";
63 const std::string ACCESSER_BUNDLE_NAME = "accesserBundleName";
64 const std::string ACCESSER_HAP_SIGNATURE = "accesserHapSignature";
65 const std::string ACCESSER_BIND_LEVEL = "accesserBindLevel";
66 /* Accessee Attribute */
67 const std::string ACCESSEE_DEVICE_ID = "accesseeDeviceId";
68 const std::string ACCESSEE_USER_ID = "accesseeUserId";
69 const std::string ACCESSEE_ACCOUNT_ID = "accesseeAccountId";
70 const std::string ACCESSEE_TOKEN_ID = "accesseeTokenId";
71 const std::string ACCESSEE_BUNDLE_NAME = "accesseeBundleName";
72 const std::string ACCESSEE_HAP_SIGNATURE = "accesseeHapSignature";
73 const std::string ACCESSEE_BIND_LEVEL = "accesseeBindLevel";
74 /* subscribe info */
75 const std::string SA_ID = "saId";
76 const std::string SUBSCRIBE_KEY = "subscribeKey";
77 const std::string SUBSCRIBE_CHANGE_TYPES = "subscribeChangeTypes";
78 /* syncOptions */
79 const std::string SYNC_MODE = "syncMode";
80 const std::string SYNC_DEVICE_IDS = "syncDevices";
81 /* Interface Name */
82 const std::string PUT_ACCESS_CONTROL_PROFILE = "PutAccessControlProfile";
83 const std::string UPDATE_ACCESS_CONTROL_PROFILE = "UpdateAccessControlProfile";
84 const std::string GET_ACCESS_CONTROL_PROFILE = "GetAccessControlProfile";
85 const std::string DELETE_ACCESS_CONTROL_PROFILE = "DeleteAccessControlProfile";
86 const std::string GET_TRUST_DEVICE_PROFILE = "GetTrustDeviceProfile";
87 const std::string GET_ALL_TRUST_DEVICE_PROFILE = "GetAllTrustDeviceProfile";
88 const std::string GET_ALL_ACCESS_CONTROL_PROFILE = "GetAllAccessControlProfile";
89 const std::string PUT_SERVICE_PROFILE = "PutServiceProfile";
90 const std::string PUT_SERVICE_PROFILE_BATCH = "PutServiceProfileBatch";
91 const std::string PUT_CHARACTERISTIC_PROFILE = "PutCharacteristicProfile";
92 const std::string PUT_CHARACTERISTIC_PROFILE_BATCH = "PutCharacteristicProfileBatch";
93 const std::string GET_DEVICE_PROFILE = "GetDeviceProfile";
94 const std::string GET_SERVICE_PROFILE = "GetServiceProfile";
95 const std::string GET_CHARACTERISTIC_PROFILE = "GetCharacteristicProfile";
96 const std::string DELETE_SERVICE_PROFILE = "DeleteServiceProfile";
97 const std::string DELETE_CHARACTERISTIC_PROFILE = "DeleteCharacteristicProfile";
98 const std::string SUBSCRIBE_DEVICE_PROFILE = "SubscribeDeviceProfile";
99 const std::string UNSUBSCRIBE_DEVICE_PROFILE = "UnSubscribeDeviceProfile";
100 const std::string SYNC_DEVICE_PROFILE = "SyncDeviceProfile";
101 /* Common constants */
102 const std::string SEPARATOR = "#";
103 const std::string DEV_PREFIX = "dev";
104 const std::string SVR_PREFIX = "svr";
105 const std::string CHAR_PREFIX = "char";
106 const std::string USER_ID = "user_id";
107 const std::string TOKEN_ID = "token_id";
108 const std::string ALL_PROC = "all";
109 const std::string DP_PKG_NAME = "ohos.deviceprofile";
110 const std::string IS_NUMSTRING_RULES = "^[-+]?[0-9]+$";
111 /* rdb constants */
112 const std::string RDB_PATH = "/data/service/el1/public/database/distributed_device_profile_service/";
113 const std::string DATABASE_NAME = "dp_rdb.db";
114 /* TrustProfile Manager */
115 const std::string USERID = "userId";
116 const std::string BUNDLENAME = "bundleName";
117 const std::string TOKENID = "tokenId";
118 const std::string ACCOUNTID = "accountId";
119 const std::string DEVICEID_EQUAL_CONDITION = "deviceId = ?";
120 const std::string ACCESSCONTROLID_EQUAL_CONDITION = "accessControlId = ?";
121 const std::string ACCESSERID_EQUAL_CONDITION = "accesserId = ? ";
122 const std::string ACCESSEEID_EQUAL_CONDITION = "accesseeId = ? ";
123 const std::string CREATE_TURST_DEVICE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS trust_device_table\
124 (\
125     deviceId        TEXT PRIMARY KEY,\
126     deviceIdType    INTEGER,\
127     deviceIdHash    TEXT,\
128     status          INTEGER);";
129 const std::string CREATE_ACCESS_CONTROL_TABLE_SQL = "CREATE TABLE IF NOT EXISTS access_control_table\
130 (\
131     accessControlId    INTEGER PRIMARY KEY,\
132     accesserId         INTEGER,\
133     accesseeId         INTEGER,\
134     trustDeviceId      TEXT,\
135     sessionKey         TEXT,\
136     bindType           INTEGER,\
137     authenticationType INTEGER,\
138     deviceIdType       INTEGER,\
139     deviceIdHash       TEXT,\
140     status             INTEGER,\
141     validPeriod        INTEGER,\
142     lastAuthTime       INTEGER,\
143     bindLevel          INTEGER);";
144 const std::string CREATE_ACCESSER_TABLE_SQL = "CREATE TABLE IF NOT EXISTS accesser_table\
145 (\
146     accesserId           INTEGER PRIMARY KEY,\
147     accesserDeviceId     TEXT,\
148     accesserUserId       INTEGER,\
149     accesserAccountId    TEXT,\
150     accesserTokenId      INTEGER,\
151     accesserBundleName   TEXT,\
152     accesserHapSignature TEXT,\
153     accesserBindLevel    INTEGER\
154 );";
155 const std::string CREATE_ACCESSEE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS accessee_table\
156 (\
157     accesseeId           INTEGER PRIMARY KEY,\
158     accesseeDeviceId     TEXT,\
159     accesseeUserId       INTEGER,\
160     accesseeAccountId    TEXT,\
161     accesseeTokenId      INTEGER,\
162     accesseeBundleName   TEXT,\
163     accesseeHapSignature TEXT,\
164     accesseeBindLevel    INTEGER\
165 );";
166 const std::string CREATE_TURST_DEVICE_TABLE_UNIQUE_INDEX_SQL =
167 "CREATE UNIQUE INDEX if not exists unique_trust_device_table ON trust_device_table \
168 (\
169     deviceId,\
170     deviceIdType,\
171     deviceIdHash,\
172     status);";
173 const std::string CREATE_ACCESS_CONTROL_TABLE_UNIQUE_INDEX_SQL =
174 "CREATE UNIQUE INDEX if not exists unique_access_control_table ON access_control_table \
175 (\
176     accesserId,\
177     accesseeId,\
178     trustDeviceId,\
179     sessionKey,\
180     bindType,\
181     authenticationType,\
182     deviceIdType,\
183     deviceIdHash,\
184     status,\
185     validPeriod,\
186     lastAuthTime,\
187     bindLevel);";
188 const std::string CREATE_ACCESSER_TABLE_UNIQUE_INDEX_SQL =
189 "CREATE UNIQUE INDEX if not exists unique_accesser_table ON accesser_table \
190 (\
191     accesserDeviceId,\
192     accesserUserId,\
193     accesserAccountId,\
194     accesserTokenId,\
195     accesserBundleName,\
196     accesserHapSignature,\
197     accesserBindLevel);";
198 const std::string CREATE_ACCESSEE_TABLE_UNIQUE_INDEX_SQL =
199 "CREATE UNIQUE INDEX if not exists unique_accessee_table ON accessee_table \
200 (\
201     accesseeDeviceId,\
202     accesseeUserId,\
203     accesseeAccountId,\
204     accesseeTokenId,\
205     accesseeBundleName,\
206     accesseeHapSignature,\
207     accesseeBindLevel);";
208 const std::string TRUST_DEVICE_TABLE = "trust_device_table";
209 const std::string ACCESS_CONTROL_TABLE = "access_control_table";
210 const std::string ACCESSER_TABLE = "accesser_table";
211 const std::string ACCESSEE_TABLE = "accessee_table";
212 const std::string SELECT_TRUST_DEVICE_TABLE = "SELECT * FROM trust_device_table";
213 const std::string SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID =
214     "SELECT * FROM trust_device_table WHERE deviceId = ?";
215 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID =
216     "SELECT * FROM access_control_table WHERE accessControlId = ?";
217 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSEEID =
218     "SELECT * FROM access_control_table WHERE accesseeId = ? ";
219 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID =
220     "SELECT * FROM access_control_table WHERE accesserId = ? ";
221 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS =
222     "SELECT * FROM access_control_table WHERE bindType = ? and status = ? ";
223 const std::string SELECT_ACCESS_CONTROL_TABLE = "SELECT * FROM access_control_table";
224 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID =
225     "SELECT * FROM access_control_table WHERE trustDeviceId = ? ";
226 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID_AND_STATUS =
227     "SELECT * FROM access_control_table WHERE trustDeviceId = ? and status = ?";
228 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_STATUS =
229     "SELECT * FROM access_control_table WHERE status = ?";
230 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID = "SELECT * FROM accessee_table WHERE accesseeId = ? ";
231 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID = "SELECT * FROM accesser_table WHERE accesserId = ? ";
232 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERTOKENID =
233     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserTokenId = ?";
234 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEETOKENID =
235     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeTokenId = ?";
236 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERBUNDLENAME =
237     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserBundleName = ?";
238 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEEBUNDLENAME =
239     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeBundleName = ?";
240 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID_ACCESSERACCOUNTID =
241     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? and accesserAccountId = ?";
242 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSEEID_ACCESSEEACCOUNTID =
243     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? and accesseeAccountId = ?";
244 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSERID =
245     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserUserId = ? ";
246 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSERID =
247     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeUserId = ? ";
248 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_ACCESSERTOKENID =
249     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserDeviceId = ? and accesserTokenId = ? ";
250 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_ACCESSEETOKENID =
251     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeDeviceId = ? and accesseeTokenId = ? ";
252 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERDEVICEID =
253     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserDeviceId = ? ";
254 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEDEVICEID =
255     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeDeviceId = ? ";
256 const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERBUNDLENAME =
257     "SELECT * FROM accesser_table WHERE accesserId = ? and accesserBundleName = ? ";
258 const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEBUNDLENAME =
259     "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeBundleName = ? ";
260 const std::string SELECT_ACCESSEE_TABLE = "SELECT * FROM accessee_table ";
261 const std::string SELECT_ACCESSER_TABLE = "SELECT * FROM accesser_table ";
262 const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL =
263     "SELECT * FROM access_control_table WHERE accesserId = ? and accesseeId = ? and trustDeviceId = ? and \
264     sessionKey = ? and bindType = ? and authenticationType = ? and deviceIdType = ? and deviceIdHash = ? \
265     and status = ? and validPeriod = ? and lastAuthTime = ? and bindLevel = ? ";
266 const std::string SELECT_ACCESSER_TABLE_WHERE_ALL =
267     "SELECT * FROM accesser_table WHERE accesserDeviceId = ? and accesserUserId = ? and accesserAccountId = ? and \
268     accesserTokenId = ? and accesserBundleName = ? and accesserHapSignature = ? and accesserBindLevel = ? ";
269 const std::string SELECT_ACCESSEE_TABLE_WHERE_ALL =
270     "SELECT * FROM accessee_table WHERE accesseeDeviceId = ? and accesseeUserId = ? and accesseeAccountId = ? and \
271     accesseeTokenId = ? and accesseeBundleName = ? and accesseeHapSignature = ? and accesseeBindLevel = ? ";
272 /* SubscribeTrustInfoManager */
273 const std::string SUBSCRIBE_TRUST_INFO_TABLE = "subscribe_trust_info_table";
274 const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_SQL =
275     "CREATE TABLE IF NOT EXISTS subscribe_trust_info_table\
276     (\
277         saId                 INTEGER PRIMARY KEY,\
278         subscribeTable       TEXT,\
279     );";
280 const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_UNIQUE_INDEX_SQL =
281     "CREATE UNIQUE INDEX if not exists unique_subscribe_trust_info_table ON subscribe_trust_info_table \
282     (said,\
283     subscribeTable);";
284 const std::string TRUST_DEVICE_DELETE = "TrustDeviceDelete";
285 const std::string TRUST_DEVICE_ADD = "TrustDeviceAdd";
286 const std::string TRUST_DEVICE_UPDATE = "TrustDeviceUpdate";
287 /* event handler factory */
288 const std::string DP_HANDLER = "dp_handler";
289 const std::string EMPTY_STRING = "";
290 /* switch attribute */
291 const std::string SWITCH_CAPABILITY_PATH = "etc/deviceprofile/dp_switch_status_cfg.json";
292 const std::string SWITCH_CALLERS = "DP_Callers";
293 const std::string SWITCH_SERVICE_NAMES = "name";
294 const std::string SWITCH_STATUS = "SwitchStatus";
295 const std::string SWITCH_ON = "1";
296 const std::string SWITCH_OFF = "0";
297 const std::string SWITCH_OPERATE_PUT = "PutSwitch";
298 const std::string SWITCH_OPERATE_GET = "GetSwitch";
299 /* static attribute */
300 const std::string STATIC_CAPABILITY_SVR_ID = "static_cap_svr_id";
301 const std::string STATIC_CAPABILITY_CHAR_ID = "static_capability";
302 const std::string STATIC_CAPABILITY_PATH = "etc/deviceprofile/dp_static_capability_cfg.json";
303 const std::string STATIC_INFO_PATH = "etc/deviceprofile/dp_static_info_cfg.json";
304 const std::string STATIC_CAPABILITY_ATTRIBUTE = "static_capability";
305 const std::string STATIC_INFO = "static_info";
306 const std::string DEFAULT_STATIC_VAL = "0";
307 const std::string STATIC_CHARACTERISTIC_KEY = "static_capability";
308 const std::string STATIC_CAPABILITY_VERSION = "staticCapabilityVersion";
309 const std::string STATIC_CAPABILITY_VALUE = "staticCapabilityValue";
310 const std::string DP_VERSION = "DPVersion";
311 const std::string ABILITIES = "abilities";
312 const std::string ABILITY_KEY = "abilityKey";
313 const std::string ABILITY_VALUE = "abilityValue";
314 const std::string STATIC_CAP_HANDLER_NAME = "service_name";
315 const std::string STATIC_CAP_HANDLER_LOC = "handler_loc";
316 const std::string DMS_HANDLER_LOC = "libdistributed_sdk.z.so";
317 const std::string STATIC_VERSION_RULES = "^(\\d+\\.){3}\\d+$";
318 } // namespace DistributedDeviceProfile
319 } // namespace OHOS