• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     const int32_t NOPERMISSION = 305;
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         if (result == NOPERMISSION) {
45             OAIDError curErrorCode = ERR_PERMISSION_ERROR;
46             result = curErrorCode;
47             OAID_HILOGE(OAID_MODULE_CLIENT, "Get OAID failed of No permission, error code is: %{public}d", result);
48         } else {
49             OAIDError curError = ERR_SYSYTEM_ERROR;
50             result = curError;
51             OAID_HILOGE(OAID_MODULE_CLIENT, "Get OAID failed of System error, error code is: %{public}d", result);
52         }
53         return "";
54     }
55     auto oaid = reply.ReadString();
56 
57     return oaid;
58 }
59 
ResetOAID()60 int32_t OAIDServiceProxy::ResetOAID()
61 {
62     OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID Begin.");
63     MessageParcel data;
64     MessageParcel reply;
65     MessageOption option;
66 
67     if (!data.WriteInterfaceToken(GetDescriptor())) {
68         OAID_HILOGE(OAID_MODULE_CLIENT, "Failed to write parcelable");
69     }
70 
71     int32_t result = Remote()->SendRequest(static_cast<uint32_t>(OAIDInterfaceCode::RESET_OAID), data, reply, option);
72     if (result != ERR_NONE) {
73         OAID_HILOGE(OAID_MODULE_CLIENT, "Reset OAID failed, error code is: %{public}d", result);
74     }
75     OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID End.");
76     int32_t errorCode = reply.ReadInt32();
77     OAID_HILOGI(OAID_MODULE_CLIENT, "Reset OAID End.errorCode = %{public}d", errorCode);
78     return errorCode;
79 }
80 
RegisterObserver(const sptr<IRemoteConfigObserver> & observer)81 int32_t OAIDServiceProxy::RegisterObserver(const sptr<IRemoteConfigObserver> &observer)
82 {
83     if (!observer) {
84         OAID_HILOGE(OAID_MODULE_CLIENT, "Observer is null, error code is: %{public}d", ERR_NULL_POINTER);
85         return ERR_NULL_POINTER;
86     }
87     MessageParcel data;
88     MessageParcel reply;
89     MessageOption option;
90 
91     if (!data.WriteInterfaceToken(GetDescriptor())) {
92         OAID_HILOGE(OAID_MODULE_CLIENT,
93             "Failed to write RegisterObserver InterfaceToken, error code is: %{public}d",
94             ERR_WRITE_PARCEL_FAILED);
95         return ERR_WRITE_PARCEL_FAILED;
96     }
97     if (!data.WriteRemoteObject(observer->AsObject())) {
98         OAID_HILOGE(OAID_MODULE_CLIENT, "Observer write failed, error code is: %{public}d", ERR_WRITE_PARCEL_FAILED);
99         return ERR_WRITE_PARCEL_FAILED;
100     }
101     std::unique_lock<std::mutex> lock(registerObserverMutex_);
102     sptr<IRemoteObject> remote = Remote();
103     if (remote == nullptr) {
104         OAID_HILOGI(OAID_MODULE_CLIENT, "remote is null");
105         return ERR_NULL_POINTER;
106     }
107     OAID_HILOGE(OAID_MODULE_CLIENT, "RegisterObserver proxy");
108     return remote->SendRequest(
109         static_cast<uint32_t>(OAIDInterfaceCode::REGISTER_CONTROL_CONFIG_OBSERVER), data, reply, option);
110 }
111 }  // namespace Cloud
112 }  // namespace OHOS