1 /*
2 * Copyright (c) 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 "ui_appearance_ability_proxy.h"
17
18 #include "message_parcel.h"
19 #include "ui_appearance_ipc_interface_code.h"
20 #include "ui_appearance_log.h"
21
22 namespace OHOS {
23 namespace ArkUi::UiAppearance {
SetDarkMode(UiAppearanceAbilityInterface::DarkMode mode)24 int32_t UiAppearanceAbilityProxy::SetDarkMode(UiAppearanceAbilityInterface::DarkMode mode)
25 {
26 MessageParcel data, reply;
27 MessageOption option;
28
29 if (!data.WriteInterfaceToken(GetDescriptor())) {
30 LOGE("Write descriptor failed!");
31 return SYS_ERR;
32 }
33 if (!data.WriteInt32(mode)) {
34 LOGE("Write mode failed!");
35 return SYS_ERR;
36 }
37
38 auto res =
39 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::SET_DARK_MODE), data, reply, option);
40 if (res != ERR_NONE) {
41 LOGE("SendRequest failed.");
42 return SYS_ERR;
43 }
44
45 return reply.ReadInt32();
46 }
47
GetDarkMode()48 int32_t UiAppearanceAbilityProxy::GetDarkMode()
49 {
50 MessageParcel data, reply;
51 MessageOption option;
52
53 if (!data.WriteInterfaceToken(GetDescriptor())) {
54 LOGE("Write descriptor failed!");
55 return SYS_ERR;
56 }
57
58 auto res =
59 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::GET_DARK_MODE), data, reply, option);
60 if (res != ERR_NONE) {
61 LOGE("SendRequest failed.");
62 return SYS_ERR;
63 }
64
65 return reply.ReadInt32();
66 }
SetFontScale(std::string & fontScale)67 int32_t UiAppearanceAbilityProxy::SetFontScale(std::string &fontScale)
68 {
69 MessageParcel data, reply;
70 MessageOption option;
71
72 if (!data.WriteInterfaceToken(GetDescriptor())) {
73 LOGE("Write descriptor failed!");
74 return SYS_ERR;
75 }
76 if (!data.WriteString(fontScale)) {
77 LOGE("Write fontScale failed!");
78 return SYS_ERR;
79 }
80
81 auto res =
82 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::SET_FONT_SCALE), data, reply, option);
83 if (res != ERR_NONE) {
84 LOGE("SendRequest failed.");
85 return SYS_ERR;
86 }
87
88 return reply.ReadInt32();
89 }
90
GetFontScale(std::string & fontScale)91 int32_t UiAppearanceAbilityProxy::GetFontScale(std::string &fontScale)
92 {
93 MessageParcel data, reply;
94 MessageOption option;
95
96 if (!data.WriteInterfaceToken(GetDescriptor())) {
97 LOGE("Write descriptor failed!");
98 return SYS_ERR;
99 }
100
101 auto res =
102 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::GET_FONT_SCALE), data, reply, option);
103 if (res != ERR_NONE) {
104 LOGE("SendRequest failed.");
105 return SYS_ERR;
106 }
107
108 res = reply.ReadInt32();
109
110 if (!reply.ReadString(fontScale)) {
111 LOGE("Read FontScale failed!");
112 return SYS_ERR;
113 }
114
115 return res;
116 }
117
SetFontWeightScale(std::string & fontWeightScale)118 int32_t UiAppearanceAbilityProxy::SetFontWeightScale(std::string& fontWeightScale)
119 {
120 MessageParcel data, reply;
121 MessageOption option;
122
123 if (!data.WriteInterfaceToken(GetDescriptor())) {
124 LOGE("Write descriptor failed!");
125 return SYS_ERR;
126 }
127 if (!data.WriteString(fontWeightScale)) {
128 LOGE("Write fontScale failed!");
129 return SYS_ERR;
130 }
131
132 auto res =
133 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::SET_FONT_Weight_SCALE),
134 data, reply, option);
135 if (res != ERR_NONE) {
136 LOGE("SendRequest failed.");
137 return SYS_ERR;
138 }
139
140 return reply.ReadInt32();
141 }
142
GetFontWeightScale(std::string & fontWeightScale)143 int32_t UiAppearanceAbilityProxy::GetFontWeightScale(std::string &fontWeightScale)
144 {
145 MessageParcel data, reply;
146 MessageOption option;
147
148 if (!data.WriteInterfaceToken(GetDescriptor())) {
149 LOGE("##Write descriptor failed!");
150 return SYS_ERR;
151 }
152
153 auto res =
154 Remote()->SendRequest(static_cast<uint32_t>(UiAppearanceInterfaceCode::GET_FONT_Weight_SCALE),
155 data, reply, option);
156 if (res != ERR_NONE) {
157 LOGE("SendRequest failed.");
158 return SYS_ERR;
159 }
160
161 res = reply.ReadInt32();
162
163 if (!reply.ReadString(fontWeightScale)) {
164 LOGE("Read FontScale failed!");
165 return SYS_ERR;
166 }
167
168 return res;
169 }
170 } // namespace ArkUi::UiAppearance
171 } // namespace OHOS
172