• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "device_profile.h"
17 #include "cJSON.h"
18 #include "distributed_device_profile_constants.h"
19 #include "macro_utils.h"
20 #include "profile_utils.h"
21 
22 namespace OHOS {
23 namespace DistributedDeviceProfile {
24 namespace {
25     const std::string TAG = "DeviceProfile";
26 }
GetDeviceId() const27 std::string DeviceProfile::GetDeviceId() const
28 {
29     return deviceId_;
30 }
31 
SetDeviceId(const std::string & deviceId)32 void DeviceProfile::SetDeviceId(const std::string& deviceId)
33 {
34     deviceId_ = deviceId;
35 }
36 
GetDeviceName() const37 std::string DeviceProfile::GetDeviceName() const
38 {
39     return deviceName_;
40 }
41 
SetDeviceName(const std::string & deviceName)42 void DeviceProfile::SetDeviceName(const std::string& deviceName)
43 {
44     deviceName_ = deviceName;
45 }
46 
GetManufactureName() const47 std::string DeviceProfile::GetManufactureName() const
48 {
49     return manufactureName_;
50 }
51 
SetManufactureName(std::string manufactureName)52 void DeviceProfile::SetManufactureName(std::string manufactureName)
53 {
54     manufactureName_ = manufactureName;
55 }
56 
GetDeviceModel() const57 std::string DeviceProfile::GetDeviceModel() const
58 {
59     return deviceModel_;
60 }
61 
SetDeviceModel(const std::string & deviceModel)62 void DeviceProfile::SetDeviceModel(const std::string& deviceModel)
63 {
64     deviceModel_ = deviceModel;
65 }
66 
GetStorageCapability() const67 int64_t DeviceProfile::GetStorageCapability() const
68 {
69     return storageCapability_;
70 }
71 
SetStorageCapability(int64_t storageCapability)72 void DeviceProfile::SetStorageCapability(int64_t storageCapability)
73 {
74     storageCapability_ = storageCapability;
75 }
76 
GetOsApiLevel() const77 int32_t DeviceProfile::GetOsApiLevel() const
78 {
79     return osApiLevel_;
80 }
81 
SetOsApiLevel(int32_t osApiLevel)82 void DeviceProfile::SetOsApiLevel(int32_t osApiLevel)
83 {
84     osApiLevel_ = osApiLevel;
85 }
86 
GetOsVersion() const87 std::string DeviceProfile::GetOsVersion() const
88 {
89     return osVersion_;
90 }
91 
SetOsVersion(const std::string & osVersion)92 void DeviceProfile::SetOsVersion(const std::string& osVersion)
93 {
94     osVersion_ = osVersion;
95 }
96 
GetOsType() const97 int32_t DeviceProfile::GetOsType() const
98 {
99     return osType_;
100 }
101 
SetOsType(int32_t osType)102 void DeviceProfile::SetOsType(int32_t osType)
103 {
104     osType_ = osType;
105 }
106 
GetOsSysCap() const107 std::string DeviceProfile::GetOsSysCap() const
108 {
109     return osSysCap_;
110 }
111 
SetOsSysCap(const std::string & osSysCap)112 void DeviceProfile::SetOsSysCap(const std::string& osSysCap)
113 {
114     osSysCap_ = osSysCap;
115 }
116 
IsMultiUser() const117 bool DeviceProfile::IsMultiUser() const
118 {
119     return isMultiUser_;
120 }
121 
SetIsMultiUser(bool isMultiUser)122 void DeviceProfile::SetIsMultiUser(bool isMultiUser)
123 {
124     isMultiUser_ = isMultiUser;
125 }
126 
GetUserId() const127 int32_t DeviceProfile::GetUserId() const
128 {
129     return userId_;
130 }
131 
SetUserId(int32_t userId)132 void DeviceProfile::SetUserId(int32_t userId)
133 {
134     userId_ = userId;
135 }
136 
GetId() const137 int32_t DeviceProfile::GetId() const
138 {
139     return id_;
140 }
141 
SetId(int32_t id)142 void DeviceProfile::SetId(int32_t id)
143 {
144     id_ = id;
145 }
146 
GetDevType() const147 std::string DeviceProfile::GetDevType() const
148 {
149     return devType_;
150 }
151 
SetDevType(const std::string & devType)152 void DeviceProfile::SetDevType(const std::string& devType)
153 {
154     devType_ = devType;
155 }
156 
GetManu() const157 std::string DeviceProfile::GetManu() const
158 {
159     return manu_;
160 }
161 
SetManu(const std::string & manu)162 void DeviceProfile::SetManu(const std::string& manu)
163 {
164     manu_ = manu;
165 }
166 
GetSn() const167 std::string DeviceProfile::GetSn() const
168 {
169     return sn_;
170 }
171 
SetSn(const std::string & sn)172 void DeviceProfile::SetSn(const std::string& sn)
173 {
174     sn_ = sn;
175 }
176 
GetProductId() const177 std::string DeviceProfile::GetProductId() const
178 {
179     return productId_;
180 }
181 
SetProductId(const std::string & productId)182 void DeviceProfile::SetProductId(const std::string& productId)
183 {
184     productId_ = productId;
185 }
186 
GetProductName() const187 std::string DeviceProfile::GetProductName() const
188 {
189     return productName_;
190 }
191 
SetProductName(const std::string & productName)192 void DeviceProfile::SetProductName(const std::string& productName)
193 {
194     productName_ = productName;
195 }
196 
GetSubProductId() const197 std::string DeviceProfile::GetSubProductId() const
198 {
199     return subProductId_;
200 }
201 
SetSubProductId(const std::string & subProductId)202 void DeviceProfile::SetSubProductId(const std::string& subProductId)
203 {
204     subProductId_ = subProductId;
205 }
206 
GetHiv() const207 std::string DeviceProfile::GetHiv() const
208 {
209     return hiv_;
210 }
211 
SetHiv(const std::string & hiv)212 void DeviceProfile::SetHiv(const std::string& hiv)
213 {
214     hiv_ = hiv;
215 }
216 
GetMac() const217 std::string DeviceProfile::GetMac() const
218 {
219     return mac_;
220 }
221 
SetMac(const std::string & mac)222 void DeviceProfile::SetMac(const std::string& mac)
223 {
224     mac_ = mac;
225 }
226 
GetFwv() const227 std::string DeviceProfile::GetFwv() const
228 {
229     return fwv_;
230 }
231 
SetFwv(const std::string & fwv)232 void DeviceProfile::SetFwv(const std::string& fwv)
233 {
234     fwv_ = fwv;
235 }
236 
GetHwv() const237 std::string DeviceProfile::GetHwv() const
238 {
239     return hwv_;
240 }
241 
SetHwv(const std::string & hwv)242 void DeviceProfile::SetHwv(const std::string& hwv)
243 {
244     hwv_ = hwv;
245 }
246 
GetSwv() const247 std::string DeviceProfile::GetSwv() const
248 {
249     return swv_;
250 }
251 
SetSwv(const std::string & swv)252 void DeviceProfile::SetSwv(const std::string& swv)
253 {
254     swv_ = swv;
255 }
256 
GetProtType() const257 int32_t DeviceProfile::GetProtType() const
258 {
259     return protType_;
260 }
261 
SetProtType(int32_t protType)262 void DeviceProfile::SetProtType(int32_t protType)
263 {
264     protType_ = protType;
265 }
266 
GetWiseUserId() const267 std::string DeviceProfile::GetWiseUserId() const
268 {
269     return wiseUserId_;
270 }
271 
SetWiseUserId(const std::string & wiseUserId)272 void DeviceProfile::SetWiseUserId(const std::string& wiseUserId)
273 {
274     wiseUserId_ = wiseUserId;
275 }
276 
GetWiseDeviceId() const277 std::string DeviceProfile::GetWiseDeviceId() const
278 {
279     return wiseDeviceId_;
280 }
281 
SetWiseDeviceId(const std::string & wiseDeviceId)282 void DeviceProfile::SetWiseDeviceId(const std::string& wiseDeviceId)
283 {
284     wiseDeviceId_ = wiseDeviceId;
285 }
286 
GetRegisterTime() const287 std::string DeviceProfile::GetRegisterTime() const
288 {
289     return registerTime_;
290 }
291 
SetRegisterTime(const std::string & registerTime)292 void DeviceProfile::SetRegisterTime(const std::string& registerTime)
293 {
294     registerTime_ = registerTime;
295 }
296 
GetModifyTime() const297 std::string DeviceProfile::GetModifyTime() const
298 {
299     return modifyTime_;
300 }
301 
SetModifyTime(std::string modifyTime)302 void DeviceProfile::SetModifyTime(std::string modifyTime)
303 {
304     modifyTime_ = modifyTime;
305 }
306 
GetShareTime() const307 std::string DeviceProfile::GetShareTime() const
308 {
309     return shareTime_;
310 }
311 
SetShareTime(const std::string & shareTime)312 void DeviceProfile::SetShareTime(const std::string& shareTime)
313 {
314     shareTime_ = shareTime;
315 }
316 
GetAccountId() const317 std::string DeviceProfile::GetAccountId() const
318 {
319     return accountId_;
320 }
321 
SetAccountId(const std::string & accountId)322 void DeviceProfile::SetAccountId(const std::string& accountId)
323 {
324     accountId_ = accountId;
325 }
326 
GetBleMac() const327 const std::string DeviceProfile::GetBleMac() const
328 {
329     return bleMac_;
330 }
331 
SetBleMac(const std::string & bleMac)332 void DeviceProfile::SetBleMac(const std::string& bleMac)
333 {
334     bleMac_ = bleMac;
335 }
336 
GetBrMac() const337 const std::string DeviceProfile::GetBrMac() const
338 {
339     return brMac_;
340 }
341 
SetBrMac(const std::string & brMac)342 void DeviceProfile::SetBrMac(const std::string& brMac)
343 {
344     brMac_ = brMac;
345 }
346 
GetSleMac() const347 const std::string DeviceProfile::GetSleMac() const
348 {
349     return sleMac_;
350 }
351 
SetSleMac(const std::string & sleMac)352 void DeviceProfile::SetSleMac(const std::string& sleMac)
353 {
354     sleMac_ = sleMac;
355 }
356 
GetSetupType() const357 int32_t DeviceProfile::GetSetupType() const
358 {
359     return setupType_;
360 }
361 
SetSetupType(int32_t setupType)362 void DeviceProfile::SetSetupType(int32_t setupType)
363 {
364     setupType_ = setupType;
365 }
366 
GetInternalModel() const367 std::string DeviceProfile::GetInternalModel() const
368 {
369     return internalModel_;
370 }
371 
SetInternalModel(const std::string & internalModel)372 void DeviceProfile::SetInternalModel(const std::string& internalModel)
373 {
374     internalModel_ = internalModel;
375 }
376 
Marshalling(MessageParcel & parcel) const377 bool DeviceProfile::Marshalling(MessageParcel& parcel) const
378 {
379     WRITE_HELPER_RET(parcel, String, deviceId_, false);
380     WRITE_HELPER_RET(parcel, String, deviceName_, false);
381     WRITE_HELPER_RET(parcel, String, manufactureName_, false);
382     WRITE_HELPER_RET(parcel, String, deviceModel_, false);
383     WRITE_HELPER_RET(parcel, Int64, storageCapability_, false);
384     WRITE_HELPER_RET(parcel, String, osSysCap_, false);
385     WRITE_HELPER_RET(parcel, Int32, osApiLevel_, false);
386     WRITE_HELPER_RET(parcel, String, osVersion_, false);
387     WRITE_HELPER_RET(parcel, Int32, osType_, false);
388     WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false);
389     WRITE_HELPER_RET(parcel, Int32, userId_, false);
390     WRITE_HELPER_RET(parcel, String, devType_, false);
391     WRITE_HELPER_RET(parcel, String, manu_, false);
392     WRITE_HELPER_RET(parcel, String, sn_, false);
393     WRITE_HELPER_RET(parcel, String, productId_, false);
394     WRITE_HELPER_RET(parcel, String, productName_, false);
395     WRITE_HELPER_RET(parcel, String, subProductId_, false);
396     WRITE_HELPER_RET(parcel, String, hiv_, false);
397     WRITE_HELPER_RET(parcel, String, mac_, false);
398     WRITE_HELPER_RET(parcel, String, fwv_, false);
399     WRITE_HELPER_RET(parcel, String, hwv_, false);
400     WRITE_HELPER_RET(parcel, String, swv_, false);
401     WRITE_HELPER_RET(parcel, Int32, protType_, false);
402     WRITE_HELPER_RET(parcel, String, wiseUserId_, false);
403     WRITE_HELPER_RET(parcel, String, wiseDeviceId_, false);
404     WRITE_HELPER_RET(parcel, String, registerTime_, false);
405     WRITE_HELPER_RET(parcel, String, modifyTime_, false);
406     WRITE_HELPER_RET(parcel, String, shareTime_, false);
407     WRITE_HELPER_RET(parcel, String, accountId_, false);
408     WRITE_HELPER_RET(parcel, String, internalModel_, false);
409     WRITE_HELPER_RET(parcel, String, bleMac_, false);
410     WRITE_HELPER_RET(parcel, String, brMac_, false);
411     WRITE_HELPER_RET(parcel, String, sleMac_, false);
412     WRITE_HELPER_RET(parcel, Int32, setupType_, false);
413     return true;
414 }
415 
UnMarshalling(MessageParcel & parcel)416 bool DeviceProfile::UnMarshalling(MessageParcel& parcel)
417 {
418     READ_HELPER_RET(parcel, String, deviceId_, false);
419     READ_HELPER_RET(parcel, String, deviceName_, false);
420     READ_HELPER_RET(parcel, String, manufactureName_, false);
421     READ_HELPER_RET(parcel, String, deviceModel_, false);
422     READ_HELPER_RET(parcel, Int64, storageCapability_, false);
423     READ_HELPER_RET(parcel, String, osSysCap_, false);
424     READ_HELPER_RET(parcel, Int32, osApiLevel_, false);
425     READ_HELPER_RET(parcel, String, osVersion_, false);
426     READ_HELPER_RET(parcel, Int32, osType_, false);
427     READ_HELPER_RET(parcel, Bool, isMultiUser_, false);
428     READ_HELPER_RET(parcel, Int32, userId_, false);
429     READ_HELPER_RET(parcel, String, devType_, false);
430     READ_HELPER_RET(parcel, String, manu_, false);
431     READ_HELPER_RET(parcel, String, sn_, false);
432     READ_HELPER_RET(parcel, String, productId_, false);
433     READ_HELPER_RET(parcel, String, productName_, false);
434     READ_HELPER_RET(parcel, String, subProductId_, false);
435     READ_HELPER_RET(parcel, String, hiv_, false);
436     READ_HELPER_RET(parcel, String, mac_, false);
437     READ_HELPER_RET(parcel, String, fwv_, false);
438     READ_HELPER_RET(parcel, String, hwv_, false);
439     READ_HELPER_RET(parcel, String, swv_, false);
440     READ_HELPER_RET(parcel, Int32, protType_, false);
441     READ_HELPER_RET(parcel, String, wiseUserId_, false);
442     READ_HELPER_RET(parcel, String, wiseDeviceId_, false);
443     READ_HELPER_RET(parcel, String, registerTime_, false);
444     READ_HELPER_RET(parcel, String, modifyTime_, false);
445     READ_HELPER_RET(parcel, String, shareTime_, false);
446     READ_HELPER_RET(parcel, String, accountId_, false);
447     READ_HELPER_RET(parcel, String, internalModel_, false);
448     READ_HELPER_RET(parcel, String, bleMac_, false);
449     READ_HELPER_RET(parcel, String, brMac_, false);
450     READ_HELPER_RET(parcel, String, sleMac_, false);
451     READ_HELPER_RET(parcel, Int32, setupType_, false);
452     return true;
453 }
454 
operator !=(const DeviceProfile & deviceProfile) const455 bool DeviceProfile::operator!=(const DeviceProfile& deviceProfile) const
456 {
457     bool isNotEqual = (deviceId_ != deviceProfile.GetDeviceId() || deviceName_ != deviceProfile.GetDeviceName() ||
458         manufactureName_ != deviceProfile.GetManufactureName() || deviceModel_ != deviceProfile.GetDeviceModel() ||
459         storageCapability_ != deviceProfile.GetStorageCapability() || osSysCap_ != deviceProfile.GetOsSysCap() ||
460         osApiLevel_ != deviceProfile.GetOsApiLevel() || osVersion_ != deviceProfile.GetOsVersion() ||
461         osType_ != deviceProfile.GetOsType() || isMultiUser_ != deviceProfile.IsMultiUser() ||
462         userId_ != deviceProfile.GetUserId() || devType_ != deviceProfile.GetDevType() ||
463         manu_ != deviceProfile.GetManu() || sn_ != deviceProfile.GetSn() ||
464         productId_ != deviceProfile.GetProductId() ||
465         productName_ != deviceProfile.GetProductName() || subProductId_ != deviceProfile.GetSubProductId() ||
466         hiv_ != deviceProfile.GetHiv() || mac_ != deviceProfile.GetMac() ||
467         fwv_ != deviceProfile.GetFwv() || hwv_ != deviceProfile.GetHwv() ||
468         swv_ != deviceProfile.GetSwv() || protType_ != deviceProfile.GetProtType() ||
469         wiseUserId_ != deviceProfile.GetWiseUserId() || wiseDeviceId_ != deviceProfile.GetWiseDeviceId() ||
470         registerTime_ != deviceProfile.GetRegisterTime() || internalModel_ != deviceProfile.GetInternalModel() ||
471         modifyTime_ != deviceProfile.GetModifyTime() || shareTime_ != deviceProfile.GetShareTime() ||
472         accountId_ != deviceProfile.GetAccountId() || id_ != deviceProfile.GetId() ||
473         bleMac_ != deviceProfile.bleMac_ || brMac_ != deviceProfile.brMac_ || sleMac_ != deviceProfile.sleMac_ ||
474         setupType_ != deviceProfile.setupType_);
475     if (isNotEqual) {
476         return true;
477     } else {
478         return false;
479     }
480 }
481 
dump() const482 std::string DeviceProfile::dump() const
483 {
484     cJSON* json = cJSON_CreateObject();
485     if (!cJSON_IsObject(json)) {
486         cJSON_Delete(json);
487         return EMPTY_STRING;
488     }
489     cJSON_AddStringToObject(json, DEVICE_ID.c_str(), ProfileUtils::GetAnonyString(deviceId_).c_str());
490     cJSON_AddStringToObject(json, DEVICE_NAME.c_str(), ProfileUtils::GetAnonyString(deviceName_).c_str());
491     cJSON_AddStringToObject(json, MANUFACTURE_NAME.c_str(), manu_ .c_str());
492     cJSON_AddStringToObject(json, DEVICE_MODEL.c_str(), deviceModel_.c_str());
493     cJSON_AddNumberToObject(json, STORAGE_CAPACITY.c_str(), storageCapability_);
494     cJSON_AddStringToObject(json, OS_SYS_CAPACITY.c_str(), osSysCap_.c_str());
495     cJSON_AddNumberToObject(json, OS_API_LEVEL.c_str(), osApiLevel_);
496     cJSON_AddStringToObject(json, OS_VERSION.c_str(), osVersion_.c_str());
497     cJSON_AddStringToObject(json, INTERNAL_MODEL.c_str(), internalModel_.c_str());
498     cJSON_AddNumberToObject(json, OS_TYPE.c_str(), osType_);
499     cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMultiUser_);
500     cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_);
501     char* jsonChars = cJSON_PrintUnformatted(json);
502     if (jsonChars == NULL) {
503         cJSON_Delete(json);
504         HILOGE("cJSON formatted to string failed!");
505         return EMPTY_STRING;
506     }
507     std::string jsonStr = jsonChars;
508     cJSON_Delete(json);
509     cJSON_free(jsonChars);
510     return jsonStr;
511 }
512 
AnnoymizeDump() const513 std::string DeviceProfile::AnnoymizeDump() const
514 {
515     cJSON* json = cJSON_CreateObject();
516     if (!cJSON_IsObject(json)) {
517         cJSON_Delete(json);
518         return EMPTY_STRING;
519     }
520     cJSON_AddStringToObject(json, DEVICE_ID.c_str(), ProfileUtils::GetAnonyString(deviceId_).c_str());
521     cJSON_AddStringToObject(json, DEVICE_NAME.c_str(), ProfileUtils::GetAnonyString(deviceName_).c_str());
522     cJSON_AddStringToObject(json, MANUFACTURE_NAME.c_str(), manu_.c_str());
523     cJSON_AddStringToObject(json, DEVICE_MODEL.c_str(), deviceModel_.c_str());
524     cJSON_AddStringToObject(json, STORAGE_CAPACITY.c_str(),
525         ProfileUtils::GetAnonyString(std::to_string(storageCapability_)).c_str());
526     cJSON_AddStringToObject(json, OS_SYS_CAPACITY.c_str(),
527         ProfileUtils::GetAnonyString(osSysCap_).c_str());
528     cJSON_AddStringToObject(json, OS_API_LEVEL.c_str(),
529         ProfileUtils::GetAnonyString(std::to_string(osApiLevel_)).c_str());
530     cJSON_AddStringToObject(json, OS_VERSION.c_str(),
531         ProfileUtils::GetAnonyString(osVersion_).c_str());
532     cJSON_AddStringToObject(json, OS_TYPE.c_str(),
533         ProfileUtils::GetAnonyString(std::to_string(osType_)).c_str());
534     cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMultiUser_);
535     cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_);
536     char* jsonChars = cJSON_PrintUnformatted(json);
537     if (jsonChars == NULL) {
538         cJSON_Delete(json);
539         HILOGE("cJSON formatted to string failed!");
540         return EMPTY_STRING;
541     }
542     std::string jsonStr = jsonChars;
543     cJSON_Delete(json);
544     cJSON_free(jsonChars);
545     return jsonStr;
546 }
547 } // namespace DistributedDeviceProfile
548 } // namespace OHOS
549