1 /*
2 * Copyright (c) 2021-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
18 #include "os_account_event_stub.h"
19
20 namespace OHOS {
21 namespace AccountSA {
OsAccountEventStub()22 OsAccountEventStub::OsAccountEventStub()
23 {}
24
~OsAccountEventStub()25 OsAccountEventStub::~OsAccountEventStub()
26 {}
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int OsAccountEventStub::OnRemoteRequest(uint32_t code, 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>(OsAccountEventInterfaceCode::ACCOUNT_CHANGED): {
37 int id;
38 if (!data.ReadInt32(id)) {
39 ACCOUNT_LOGE("failed to read localId");
40 return ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR;
41 }
42 OnAccountsChanged(id);
43 break;
44 }
45 case static_cast<uint32_t>(OsAccountEventInterfaceCode::ACCOUNT_SWITCHED): {
46 int newId;
47 if (!data.ReadInt32(newId)) {
48 ACCOUNT_LOGE("Read newId failed.");
49 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
50 }
51 int oldId;
52 if (!data.ReadInt32(oldId)) {
53 ACCOUNT_LOGE("Read oldId failed.");
54 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
55 }
56 OnAccountsSwitch(newId, oldId);
57 break;
58 }
59 default:
60 ACCOUNT_LOGI("default, code = %{public}u, flags = %{public}u", code, option.GetFlags());
61 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62 }
63
64 return ERR_OK;
65 }
66 } // namespace AccountSA
67 } // namespace OHOS
68