• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_info_collector.h"
17 
18 #include "device_profile_log.h"
19 #include "nlohmann/json.hpp"
20 #include "parameter.h"
21 #include "content_sensor_manager_utils.h"
22 
23 namespace OHOS {
24 namespace DeviceProfile {
25 namespace {
26 const std::string TAG = "DeviceInfoCollector";
27 
28 const std::string SERVICE_ID = "device";
29 const std::string SERVICE_TYPE = "device";
30 const std::string DEVICE_NAME = "deviceName";
31 const std::string DEVICE_MODEL = "model";
32 const std::string DEVICE_UDID = "udid";
33 const std::string DEVICE_TYPE = "devType";
34 const std::string DEVICE_MANU = "manu";
35 const std::string DEVICE_SN = "sn";
36 }
37 
ConvertToProfileData(ServiceCharacteristicProfile & profile)38 bool DeviceInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
39 {
40     profile.SetServiceId(SERVICE_ID);
41     profile.SetServiceType(SERVICE_TYPE);
42     nlohmann::json jsonData;
43     jsonData[DEVICE_NAME] = GetDeviceName();
44     jsonData[DEVICE_MODEL] = GetDeviceModel();
45     jsonData[DEVICE_UDID] = GetDeviceUdid();
46     jsonData[DEVICE_TYPE] = GetDevType();
47     jsonData[DEVICE_MANU] = GetDeviceManufacturer();
48     jsonData[DEVICE_SN] = GetDeviceSerial();
49     profile.SetCharacteristicProfileJson(jsonData.dump());
50     return true;
51 }
52 
GetDeviceModel()53 std::string DeviceInfoCollector::GetDeviceModel()
54 {
55     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainProductModel();
56 }
57 
GetDevType()58 std::string DeviceInfoCollector::GetDevType()
59 {
60     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainDeviceType();
61 }
62 
GetDeviceManufacturer()63 std::string DeviceInfoCollector::GetDeviceManufacturer()
64 {
65     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainManufacture();
66 }
67 
GetDeviceSerial()68 std::string DeviceInfoCollector::GetDeviceSerial()
69 {
70     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainSerial();
71 }
72 
GetDeviceName()73 std::string DeviceInfoCollector::GetDeviceName()
74 {
75     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainMarketName();
76 }
77 
GetDeviceUdid()78 std::string DeviceInfoCollector::GetDeviceUdid()
79 {
80     return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
81 }
82 } // namespace DeviceProfile
83 } // namespace OHOS