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 "oaid_service_proxy.h"
17 #include "iremote_broker.h"
18 #include "oaid_common.h"
19 #include "oaid_service_interface.h"
20 #include "oaid_service_ipc_interface_code.h"
21 #include "oaid_iremote_config_observer.h"
22
23 namespace OHOS {
24 namespace Cloud {
25 using namespace OHOS::HiviewDFX;
26
OAIDServiceProxy(const sptr<IRemoteObject> & object)27 OAIDServiceProxy::OAIDServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IOAIDService>(object)
28 {}
29
GetOAID()30 std::string OAIDServiceProxy::GetOAID()
31 {
32 OAID_HILOGI(OAID_MODULE_CLIENT, "GetOAID Begin.");
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option;
36
37 if (!data.WriteInterfaceToken(GetDescriptor())) {
38 OAID_HILOGE(OAID_MODULE_CLIENT, "Failed to write parcelable");
39 return "";
40 }
41
42 int32_t result = Remote()->SendRequest(static_cast<uint32_t>(OAIDInterfaceCode::GET_OAID), data, reply, option);
43 if (result != ERR_NONE) {
44 OAID_HILOGE(OAID_MODULE_CLIENT, "Get OAID failed, error code is: %{public}d", result);
45 return "";
46 }
47 auto oaid = reply.ReadString();
48
49 return oaid;
50 }
51
ResetOAID()52 int32_t OAIDServiceProxy::ResetOAID()
53 {
54 OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID Begin.");
55 MessageParcel data;
56 MessageParcel reply;
57 MessageOption option;
58
59 if (!data.WriteInterfaceToken(GetDescriptor())) {
60 OAID_HILOGE(OAID_MODULE_CLIENT, "Failed to write parcelable");
61 }
62
63 int32_t result = Remote()->SendRequest(static_cast<uint32_t>(OAIDInterfaceCode::RESET_OAID), data, reply, option);
64 if (result != ERR_NONE) {
65 OAID_HILOGE(OAID_MODULE_CLIENT, "Reset OAID failed, error code is: %{public}d", result);
66 }
67 OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID End.");
68 int32_t errorCode = reply.ReadInt32();
69 OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID End.errorCode = %{public}d", errorCode);
70 return errorCode;
71 }
72
RegisterObserver(const sptr<IRemoteConfigObserver> & observer)73 int32_t OAIDServiceProxy::RegisterObserver(const sptr<IRemoteConfigObserver> &observer)
74 {
75 if (!observer) {
76 OAID_HILOGE(OAID_MODULE_CLIENT, "Observer is null, error code is: %{public}d", ERR_NULL_POINTER);
77 return ERR_NULL_POINTER;
78 }
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option;
82
83 if (!data.WriteInterfaceToken(GetDescriptor())) {
84 OAID_HILOGE(OAID_MODULE_CLIENT,
85 "Failed to write RegisterObserver InterfaceToken, error code is: %{public}d",
86 ERR_WRITE_PARCEL_FAILED);
87 return ERR_WRITE_PARCEL_FAILED;
88 }
89 if (!data.WriteRemoteObject(observer->AsObject())) {
90 OAID_HILOGE(OAID_MODULE_CLIENT, "Observer write failed, error code is: %{public}d", ERR_WRITE_PARCEL_FAILED);
91 return ERR_WRITE_PARCEL_FAILED;
92 }
93 OAID_HILOGE(OAID_MODULE_CLIENT, "RegisterObserver proxy");
94 return Remote()->SendRequest(
95 static_cast<uint32_t>(OAIDInterfaceCode::REGISTER_CONTROL_CONFIG_OBSERVER), data, reply, option);
96 }
97 } // namespace Cloud
98 } // namespace OHOS