1 /*
2  * Copyright (c) 2022-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 "configuration_observer_proxy.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
ConfigurationObserverProxy(const sptr<IRemoteObject> & impl)23 ConfigurationObserverProxy::ConfigurationObserverProxy(
24     const sptr<IRemoteObject> &impl) : IRemoteProxy<IConfigurationObserver>(impl)
25 {}
26 
WriteInterfaceToken(MessageParcel & data)27 bool ConfigurationObserverProxy::WriteInterfaceToken(MessageParcel &data)
28 {
29     if (!data.WriteInterfaceToken(ConfigurationObserverProxy::GetDescriptor())) {
30         TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
31         return false;
32     }
33     return true;
34 }
35 
OnConfigurationUpdated(const Configuration & configuration)36 void ConfigurationObserverProxy::OnConfigurationUpdated(const Configuration& configuration)
37 {
38     MessageParcel data;
39     MessageParcel reply;
40     MessageOption option(MessageOption::TF_ASYNC);
41     if (!WriteInterfaceToken(data)) {
42         return;
43     }
44     data.WriteParcelable(&configuration);
45     sptr<IRemoteObject> remote = Remote();
46     if (remote == nullptr) {
47         TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
48         return;
49     }
50     int32_t ret = remote->SendRequest(
51         static_cast<uint32_t>(IConfigurationObserver::Message::TRANSACT_ON_CONFIGURATION_UPDATED),
52         data, reply, option);
53     if (ret != NO_ERROR) {
54         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
55     }
56 }
57 }
58 }
59