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