1 /*
2 * Copyright (c) 2023 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 "hilog/log.h"
17 #include "message_parcel.h"
18 #include "i18n_service_ability_proxy.h"
19
20 namespace OHOS {
21 namespace Global {
22 namespace I18n {
23 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityProxy" };
24 using namespace OHOS::HiviewDFX;
25 static const std::u16string DESCRIPTOR = u"OHOS.global.II18nServiceAbility";
26
I18nServiceAbilityProxy(const sptr<IRemoteObject> & impl)27 I18nServiceAbilityProxy::I18nServiceAbilityProxy(const sptr<IRemoteObject> &impl)
28 : IRemoteProxy<II18nServiceAbility>(impl)
29 {
30 }
31
SetSystemLanguage(const std::string & language)32 I18nErrorCode I18nServiceAbilityProxy::SetSystemLanguage(const std::string &language)
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option;
37 data.WriteInterfaceToken(DESCRIPTOR);
38 data.WriteString(language);
39 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::SET_SYSTEM_LANGUAGE), data,
40 reply, option);
41 return ProcessReply(reply.ReadInt32());
42 }
43
SetSystemRegion(const std::string & region)44 I18nErrorCode I18nServiceAbilityProxy::SetSystemRegion(const std::string ®ion)
45 {
46 MessageParcel data;
47 MessageParcel reply;
48 MessageOption option;
49 data.WriteInterfaceToken(DESCRIPTOR);
50 data.WriteString(region);
51 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::SET_SYSTEM_REGION), data,
52 reply, option);
53 return ProcessReply(reply.ReadInt32());
54 }
55
SetSystemLocale(const std::string & locale)56 I18nErrorCode I18nServiceAbilityProxy::SetSystemLocale(const std::string &locale)
57 {
58 MessageParcel data;
59 MessageParcel reply;
60 MessageOption option;
61 data.WriteInterfaceToken(DESCRIPTOR);
62 data.WriteString(locale);
63 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::SET_SYSTEM_LOCALE), data,
64 reply, option);
65 return ProcessReply(reply.ReadInt32());
66 }
67
Set24HourClock(const std::string & flag)68 I18nErrorCode I18nServiceAbilityProxy::Set24HourClock(const std::string &flag)
69 {
70 MessageParcel data;
71 MessageParcel reply;
72 MessageOption option;
73 data.WriteInterfaceToken(DESCRIPTOR);
74 data.WriteString(flag);
75 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::SET_24_HOUR_CLOCK), data,
76 reply, option);
77 return ProcessReply(reply.ReadInt32());
78 }
79
SetUsingLocalDigit(bool flag)80 I18nErrorCode I18nServiceAbilityProxy::SetUsingLocalDigit(bool flag)
81 {
82 MessageParcel data;
83 MessageParcel reply;
84 MessageOption option;
85 data.WriteInterfaceToken(DESCRIPTOR);
86 data.WriteBool(flag);
87 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::SET_USING_LOCAL_DIGIT), data,
88 reply, option);
89 return ProcessReply(reply.ReadInt32());
90 }
91
AddPreferredLanguage(const std::string & language,int32_t index)92 I18nErrorCode I18nServiceAbilityProxy::AddPreferredLanguage(const std::string &language, int32_t index)
93 {
94 MessageParcel data;
95 MessageParcel reply;
96 MessageOption option;
97 data.WriteInterfaceToken(DESCRIPTOR);
98 data.WriteString(language);
99 data.WriteInt32(index);
100 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::ADD_PREFERRED_LANGUAGE), data,
101 reply, option);
102 return ProcessReply(reply.ReadInt32());
103 }
104
RemovePreferredLanguage(int32_t index)105 I18nErrorCode I18nServiceAbilityProxy::RemovePreferredLanguage(int32_t index)
106 {
107 MessageParcel data;
108 MessageParcel reply;
109 MessageOption option;
110 data.WriteInterfaceToken(DESCRIPTOR);
111 data.WriteInt32(index);
112 Remote()->SendRequest(static_cast<uint32_t>(ILocaleConfigAbilityCode::REMOVE_PREFERRED_LANGUAGE),
113 data, reply, option);
114 return ProcessReply(reply.ReadInt32());
115 }
116
ProcessReply(int32_t reply)117 I18nErrorCode I18nServiceAbilityProxy::ProcessReply(int32_t reply)
118 {
119 I18nErrorCode err = static_cast<I18nErrorCode>(reply);
120 if (err != I18nErrorCode::SUCCESS) {
121 HiLog::Error(LABEL,
122 "I18nServiceAbilityProxy::ProcessReply failed with errorcode=%{public}d", reply);
123 }
124 return err;
125 }
126 } // namespace I18n
127 } // namespace Global
128 } // namespace OHOS