1 /*
2 * Copyright (c) 2024 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 "account_log_wrapper.h"
17 #include "distributed_account_event_stub.h"
18
19 namespace OHOS {
20 namespace AccountSA {
DistributedAccountEventStub()21 DistributedAccountEventStub::DistributedAccountEventStub()
22 {}
23
~DistributedAccountEventStub()24 DistributedAccountEventStub::~DistributedAccountEventStub()
25 {}
26
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int DistributedAccountEventStub::OnRemoteRequest(uint32_t code,
28 MessageParcel &data, MessageParcel &reply, MessageOption &option)
29 {
30 if (data.ReadInterfaceToken() != GetDescriptor()) {
31 ACCOUNT_LOGE("Check descriptor failed, code=%{public}u.", code);
32 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
33 }
34
35 switch (code) {
36 case static_cast<uint32_t>(DistributedAccountEventInterfaceCode::ON_ACCOUNT_CHANGED) : {
37 std::shared_ptr<DistributedAccountEventData> dataPtr(data.ReadParcelable<DistributedAccountEventData>());
38 if (dataPtr == nullptr) {
39 ACCOUNT_LOGE("Read subscribe data failed.");
40 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
41 }
42 DistributedAccountEventData eventData;
43 eventData.id_ = dataPtr->id_;
44 eventData.type_ = dataPtr->type_;
45 OnAccountsChanged(eventData);
46 break;
47 }
48 default:
49 ACCOUNT_LOGE("Switch code failed, code=%{public}u, flags=%{public}u", code, option.GetFlags());
50 return IPC_PROXY_INVALID_CODE_ERR;
51 }
52
53 return ERR_OK;
54 }
55 } // namespace AccountSA
56 } // namespace OHOS
57