• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include "base/utils/device_config.h"
16 
17 #include "parameter.h"
18 #include "parameters.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 constexpr char PROPERTY_DEVICE_TYPE[] = "const.product.devicetype";
23 constexpr char PROPERTY_DEVICE_TYPE_DEFAULT[] = "default";
24 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
25 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
26 constexpr char PROPERTY_DEVICE_TYPE_TWOINONE[] = "2in1";
27 constexpr char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
28 constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
29 constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
30 
InitDeviceType()31 DeviceType InitDeviceType()
32 {
33     DeviceType realDeviceType { DeviceType::UNKNOWN };
34 
35     auto deviceProp = system::GetParameter(PROPERTY_DEVICE_TYPE, PROPERTY_DEVICE_TYPE_DEFAULT);
36     // Properties: "default", "tv", "tablet", "watch", "car"
37     if (deviceProp == PROPERTY_DEVICE_TYPE_TV) {
38         realDeviceType = DeviceType::TV;
39     } else if (deviceProp == PROPERTY_DEVICE_TYPE_CAR) {
40         realDeviceType = DeviceType::CAR;
41     } else if (deviceProp == PROPERTY_DEVICE_TYPE_WATCH) {
42         realDeviceType = DeviceType::WATCH;
43     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TABLET) {
44         realDeviceType = DeviceType::TABLET;
45     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TWOINONE) {
46         realDeviceType = DeviceType::TWO_IN_ONE;
47     } else if (deviceProp == PROPERTY_DEVICE_TYPE_WEARABLE) {
48         realDeviceType = DeviceType::WEARABLE;
49     } else {
50         realDeviceType = DeviceType::PHONE;
51     }
52     return realDeviceType;
53 }
54 } // namespace
55 const DeviceType DeviceConfig::realDeviceType = InitDeviceType();
56 } // namespace OHOS::Ace
57