• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "data_ability_observer_proxy.h"
17 #include "hilog_wrapper.h"
18 #include "message_parcel.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
DataAbilityObserverProxy(const sptr<IRemoteObject> & remote)22 DataAbilityObserverProxy::DataAbilityObserverProxy(const sptr<IRemoteObject> &remote)
23     : IRemoteProxy<IDataAbilityObserver>(remote)
24 {}
~DataAbilityObserverProxy()25 DataAbilityObserverProxy::~DataAbilityObserverProxy()
26 {}
27 /**
28  * @brief Called back to notify that the data being observed has changed.
29  *
30  * @param uri Indicates the path of the data to operate.
31  */
OnChange()32 void DataAbilityObserverProxy::OnChange()
33 {
34     auto remote = Remote();
35     if (remote == nullptr) {
36         HILOG_ERROR("%{public}s remote is nullptr", __func__);
37         return;
38     }
39 
40     OHOS::MessageParcel data;
41     OHOS::MessageParcel reply;
42     MessageOption option(MessageOption::TF_ASYNC);
43 
44     if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) {
45         HILOG_ERROR("%{public}s data.WriteInterfaceToken(GetDescriptor()) return false", __func__);
46         return;
47     }
48 
49     int result = remote->SendRequest(IDataAbilityObserver::DATA_ABILITY_OBSERVER_CHANGE, data, reply, option);
50     if (result != ERR_NONE) {
51         HILOG_ERROR("%{public}s SendRequest error, result=%{public}d", __func__, result);
52     }
53 }
54 }  // namespace AAFwk
55 }  // namespace OHOS
56