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 HILOG_ERROR("Write descriptor failed!");
31 return SYS_ERR;
32 }
33 if (!data.WriteInt32(mode)) {
34 HILOG_ERROR("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 HILOG_ERROR("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 HILOG_ERROR("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 HILOG_ERROR("SendRequest failed.");
62 return SYS_ERR;
63 }
64
65 return reply.ReadInt32();
66 }
67 } // namespace ArkUi::UiAppearance
68 } // namespace OHOS