1 /* 2 * Copyright (c) 2021 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 "system_info_collector.h" 17 18 #include "device_profile_errors.h" 19 #include "device_profile_log.h" 20 21 #include "nlohmann/json.hpp" 22 #include "parameters.h" 23 24 namespace OHOS { 25 namespace DeviceProfile { 26 namespace { 27 const std::string TAG = "SystemInfoCollector"; 28 29 const std::string SERVICE_ID = "system"; 30 const std::string SERVICE_TYPE = "system"; 31 const std::string EMPTY_PARAM = ""; 32 const std::string SYSTEM_OS_TYPE = "type"; 33 const std::string DEVICE_OHOS_VERSION = "harmonyVersion"; 34 const std::string DEVICE_API_LEVEL = "harmonyApiLevel"; 35 const std::string SYSTEM_OS_TYPE_PARAM = "hw_sc.build.os.enable"; 36 const std::string DEVICE_API_LEVEL_PARAM = "hw_sc.build.os.apiversion"; 37 const std::string DEVICE_OHOS_VERSION_PARAM = "hw_sc.build.os.version"; 38 constexpr int32_t OHOS_TYPE = 11; 39 } 40 ConvertToProfileData(ServiceCharacteristicProfile & profile)41void SystemInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) 42 { 43 profile.SetServiceId(SERVICE_ID); 44 profile.SetServiceType(SERVICE_TYPE); 45 nlohmann::json jsonData; 46 jsonData[SYSTEM_OS_TYPE] = GetOsType(); 47 jsonData[DEVICE_OHOS_VERSION] = GetOsVersion(); 48 jsonData[DEVICE_API_LEVEL] = GetApiVersion(); 49 profile.SetCharacteristicProfileJson(jsonData.dump()); 50 } 51 GetOsType()52int32_t SystemInfoCollector::GetOsType() 53 { 54 return OHOS_TYPE; 55 } 56 GetApiVersion()57std::string SystemInfoCollector::GetApiVersion() 58 { 59 return system::GetParameter(DEVICE_API_LEVEL_PARAM, EMPTY_PARAM); 60 } 61 GetOsVersion()62std::string SystemInfoCollector::GetOsVersion() 63 { 64 return system::GetParameter(DEVICE_OHOS_VERSION_PARAM, EMPTY_PARAM); 65 } 66 } // namespace DeviceProfile 67 } // namespace OHOS