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 "observer_callback_proxy.h"
17 #include "user_access_tracer.h"
18 #include "file_access_framework_errno.h"
19 #include "hilog_wrapper.h"
20 #include "hitrace_meter.h"
21 #include "ipc_types.h"
22 #include "message_option.h"
23 #include "message_parcel.h"
24 
25 namespace OHOS {
26 namespace FileAccessFwk {
OnChange(NotifyMessage & notifyMessage)27 void ObserverCallbackProxy::OnChange(NotifyMessage &notifyMessage)
28 {
29     UserAccessTracer trace;
30     trace.Start("OnChange");
31     MessageParcel data;
32     if (!data.WriteInterfaceToken(ObserverCallbackProxy::GetDescriptor())) {
33         HILOG_ERROR("WriteInterfaceToken failed");
34         return;
35     }
36 
37     if (!data.WriteParcelable(&notifyMessage)) {
38         HILOG_ERROR("fail to WriteParcelable notifyMessage");
39         return;
40     }
41 
42     MessageParcel reply;
43     MessageOption option;
44     auto remote = Remote();
45     if (!remote) {
46         HILOG_ERROR("failed to get remote");
47         return;
48     }
49     int err = remote->SendRequest(CMD_ONCHANGE, data, reply, option);
50     if (err != ERR_OK) {
51         HILOG_ERROR("fail to SendRequest. err: %{public}d", err);
52         return;
53     }
54 
55     int ret = E_IPCS;
56     if (!reply.ReadInt32(ret)) {
57         HILOG_ERROR("fail to ReadInt32 ret");
58         return;
59     }
60 
61     if (ret != ERR_OK) {
62         HILOG_ERROR("OnChange operation failed ret : %{public}d", ret);
63         return;
64     }
65     return;
66 }
67 } // namespace FileAccessFwk
68 } // namespace OHOS
69