• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bridge/common/plugin_adapter/plugin_bridge.h"
17 
18 #include "base/utils/system_properties.h"
19 #include "core/common/ace_application_info.h"
20 #include "core/common/container.h"
21 
22 namespace OHOS::Ace::Framework {
ProcessSystemParam(std::unique_ptr<JsonValue> & infoList)23 void PluginBridge::ProcessSystemParam(std::unique_ptr<JsonValue>& infoList)
24 {
25     std::string tmp = SystemProperties::GetBrand();
26     if (tmp != SystemProperties::INVALID_PARAM) {
27         infoList->Put("brand", tmp.c_str());
28     }
29     tmp = SystemProperties::GetManufacturer();
30     if (tmp != SystemProperties::INVALID_PARAM) {
31         infoList->Put("manufacturer", tmp.c_str());
32     }
33     tmp = SystemProperties::GetModel();
34     if (tmp != SystemProperties::INVALID_PARAM) {
35         infoList->Put("model", tmp.c_str());
36     }
37     tmp = SystemProperties::GetProduct();
38     if (tmp != SystemProperties::INVALID_PARAM) {
39         infoList->Put("product", tmp.c_str());
40     }
41     tmp = SystemProperties::GetApiVersion();
42     if (tmp != SystemProperties::INVALID_PARAM) {
43         char* tmpEnd = nullptr;
44         infoList->Put(
45             "apiVersion", static_cast<int32_t>(std::strtol(SystemProperties::GetApiVersion().c_str(), &tmpEnd, 10)));
46     }
47     tmp = SystemProperties::GetReleaseType();
48     if (tmp != SystemProperties::INVALID_PARAM) {
49         infoList->Put("releaseType", tmp.c_str());
50     }
51     tmp = SystemProperties::GetParamDeviceType();
52     if (tmp != SystemProperties::INVALID_PARAM) {
53         infoList->Put("deviceType", tmp.c_str());
54     }
55 
56     tmp = SystemProperties::GetLanguage();
57     if (tmp != SystemProperties::INVALID_PARAM) {
58         infoList->Put("language", tmp.c_str());
59     }
60 
61     tmp = SystemProperties::GetRegion();
62     if (tmp != SystemProperties::INVALID_PARAM) {
63         infoList->Put("region", tmp.c_str());
64     }
65 }
66 
GetDeviceInfo()67 std::pair<std::string, bool> PluginBridge::GetDeviceInfo()
68 {
69     static constexpr uint8_t paramNumber = 13;
70     auto infoList = JsonUtil::Create(true);
71     ProcessSystemParam(infoList);
72 
73     auto container = Container::Current();
74     int32_t width = container ? container->GetViewWidth() : 0;
75     if (width != 0) {
76         infoList->Put("windowWidth", width);
77     }
78     int32_t height = container ? container->GetViewHeight() : 0;
79     if (height != 0) {
80         infoList->Put("windowHeight", height);
81     }
82     infoList->Put("screenDensity", SystemProperties::GetResolution());
83 
84     bool isRound = SystemProperties::GetIsScreenRound();
85     if (isRound) {
86         infoList->Put("screenShape", "circle");
87     } else {
88         infoList->Put("screenShape", "rect");
89     }
90 
91     bool isParamValid = false;
92     uint8_t count = 0;
93     auto child = infoList->GetChild();
94     while (child->IsValid()) {
95         child = child->GetNext();
96         ++count;
97     }
98     if (count == paramNumber) {
99         isParamValid = true;
100     }
101     return std::make_pair<std::string, bool>(infoList->ToString(), std::move(isParamValid));
102 }
103 } // namespace OHOS::Ace
104