1 /*
2 * Copyright (c) 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 "configuration_observer_stub.h"
17
18 #include "appexecfwk_errors.h"
19 #include "hilog_wrapper.h"
20 #include "hitrace_meter.h"
21 #include "ipc_types.h"
22 #include "iremote_object.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
ConfigurationObserverStub()26 ConfigurationObserverStub::ConfigurationObserverStub()
27 {
28 memberFuncMap_[static_cast<uint32_t>(
29 IConfigurationObserver::Message::TRANSACT_ON_CONFIGURATION_UPDATED)] =
30 &ConfigurationObserverStub::HandleOnConfigurationUpdated;
31 }
32
~ConfigurationObserverStub()33 ConfigurationObserverStub::~ConfigurationObserverStub()
34 {
35 memberFuncMap_.clear();
36 }
37
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int ConfigurationObserverStub::OnRemoteRequest(
39 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
40 {
41 HILOG_INFO("ConfigurationObserverStub::OnRemoteRequest, code = %{public}u, flags= %{public}d.",
42 code, option.GetFlags());
43 std::u16string descriptor = ConfigurationObserverStub::GetDescriptor();
44 std::u16string remoteDescriptor = data.ReadInterfaceToken();
45 if (descriptor != remoteDescriptor) {
46 HILOG_ERROR("local descriptor is not equal to remote");
47 return ERR_INVALID_STATE;
48 }
49
50 auto itFunc = memberFuncMap_.find(code);
51 if (itFunc != memberFuncMap_.end()) {
52 auto memberFunc = itFunc->second;
53 if (memberFunc != nullptr) {
54 return (this->*memberFunc)(data, reply);
55 }
56 }
57 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59
OnConfigurationUpdated(const Configuration & configuration)60 void ConfigurationObserverStub::OnConfigurationUpdated(const Configuration& configuration)
61 {}
62
HandleOnConfigurationUpdated(MessageParcel & data,MessageParcel & reply)63 int32_t ConfigurationObserverStub::HandleOnConfigurationUpdated(MessageParcel &data, MessageParcel &reply)
64 {
65 HITRACE_METER(HITRACE_TAG_APP);
66 std::unique_ptr<Configuration> configuration(data.ReadParcelable<Configuration>());
67 if (!configuration) {
68 HILOG_ERROR("ReadParcelable<Configuration> failed");
69 return ERR_APPEXECFWK_PARCEL_ERROR;
70 }
71
72 OnConfigurationUpdated(*configuration);
73 return NO_ERROR;
74 }
75 }
76 }
77