• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "os_account_event_proxy.h"
19 
20 namespace OHOS {
21 namespace AccountSA {
OsAccountEventProxy(const sptr<IRemoteObject> & object)22 OsAccountEventProxy::OsAccountEventProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IOsAccountEvent>(object)
23 {}
24 
~OsAccountEventProxy()25 OsAccountEventProxy::~OsAccountEventProxy()
26 {}
27 
OnAccountsChanged(const int & localId)28 void OsAccountEventProxy::OnAccountsChanged(const int &localId)
29 {
30     MessageParcel data;
31     MessageParcel reply;
32 
33     if (!data.WriteInterfaceToken(GetDescriptor())) {
34         ACCOUNT_LOGE("failed to write descriptor!");
35         return;
36     }
37 
38     if (!data.WriteInt32(localId)) {
39         ACCOUNT_LOGE("failed to write WriteInt32 localId %{public}d.", localId);
40         return;
41     }
42 
43     ErrCode result = SendRequest(IOsAccountEvent::Message::ACCOUNT_CHANGED, data, reply);
44     if (result != ERR_OK) {
45         ACCOUNT_LOGE("SendRequest for account changed failed! result %{public}d, localId %{public}d.",
46             result, localId);
47         return;
48     }
49 }
50 
SendRequest(IOsAccountEvent::Message code,MessageParcel & data,MessageParcel & reply)51 ErrCode OsAccountEventProxy::SendRequest(IOsAccountEvent::Message code, MessageParcel &data, MessageParcel &reply)
52 {
53     sptr<IRemoteObject> remote = Remote();
54     if (remote == nullptr) {
55         ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
56         return ERR_OSACCOUNT_KIT_REMOTE_IS_NULLPTR;
57     }
58 
59     MessageOption option(MessageOption::TF_SYNC);
60     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
61     if (result != ERR_OK) {
62         ACCOUNT_LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
63         return ERR_OSACCOUNT_KIT_SEND_REQUEST_ERROR;
64     }
65 
66     return ERR_OK;
67 }
68 }  // namespace AccountSA
69 }  // namespace OHOS
70