1 /*
2 * Copyright (c) 2021-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 "account_log_wrapper.h"
17
18 #include "app_account_event_stub.h"
19
20 namespace OHOS {
21 namespace AccountSA {
AppAccountEventStub()22 AppAccountEventStub::AppAccountEventStub()
23 {
24 ACCOUNT_LOGI("enter");
25 }
26
~AppAccountEventStub()27 AppAccountEventStub::~AppAccountEventStub()
28 {}
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int AppAccountEventStub::OnRemoteRequest(
31 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33 ACCOUNT_LOGI("enter");
34
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 ACCOUNT_LOGE("failed to check descriptor! code %{public}u.", code);
37 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
38 }
39
40 switch (code) {
41 case static_cast<uint32_t>(IAppAccountEvent::Message::ACCOUNT_CHANGED): {
42 std::vector<AppAccountInfo> accounts;
43 if (!ReadParcelableVector(accounts, data)) {
44 ACCOUNT_LOGE("failed to read parcelable vector for account info");
45 if (!reply.WriteInt32(ERR_APPACCOUNT_KIT_READ_PARCELABLE_VECTOR_ACCOUNT_INFO)) {
46 ACCOUNT_LOGE("failed to write reply");
47 return IPC_STUB_WRITE_PARCEL_ERR;
48 }
49 }
50 OnAccountsChanged(accounts);
51 break;
52 }
53 default:
54 ACCOUNT_LOGI("default, code = %{public}u, flags = %{public}u", code, option.GetFlags());
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57
58 return ERR_NONE;
59 }
60
61 template<typename T>
ReadParcelableVector(std::vector<T> & parcelableVector,MessageParcel & data)62 bool AppAccountEventStub::ReadParcelableVector(std::vector<T> &parcelableVector, MessageParcel &data)
63 {
64 ACCOUNT_LOGI("enter");
65
66 uint32_t size = 0;
67 if (!data.ReadUint32(size)) {
68 ACCOUNT_LOGE("failed to ReadInt32 for size");
69 return false;
70 }
71
72 parcelableVector.clear();
73 for (uint32_t index = 0; index < size; index += 1) {
74 std::shared_ptr<T> parcelable(data.ReadParcelable<T>());
75 if (parcelable == nullptr) {
76 ACCOUNT_LOGE("failed to ReadParcelable for T");
77 return false;
78 }
79 parcelableVector.emplace_back(*parcelable);
80 }
81
82 return true;
83 }
84 } // namespace AccountSA
85 } // namespace OHOS
86