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