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_stub.h"
17
18 #include "appexecfwk_errors.h"
19 #include "hilog_tag_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
~ConfigurationObserverStub()28 ConfigurationObserverStub::~ConfigurationObserverStub() {}
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int ConfigurationObserverStub::OnRemoteRequest(
31 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33 TAG_LOGI(AAFwkTag::APPMGR, "ConfigurationObserverStub::OnRemoteRequest, code = %{public}u, flags= %{public}d.",
34 code, option.GetFlags());
35 std::u16string descriptor = ConfigurationObserverStub::GetDescriptor();
36 std::u16string remoteDescriptor = data.ReadInterfaceToken();
37 if (descriptor != remoteDescriptor) {
38 TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equivalent to remote");
39 return ERR_INVALID_STATE;
40 }
41
42 if (code == static_cast<uint32_t>(IConfigurationObserver::Message::TRANSACT_ON_CONFIGURATION_UPDATED)) {
43 return HandleOnConfigurationUpdated(data, reply);
44 }
45
46 TAG_LOGI(AAFwkTag::APPMGR, "ConfigurationObserverStub::OnRemoteRequest end");
47 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49
OnConfigurationUpdated(const Configuration & configuration)50 void ConfigurationObserverStub::OnConfigurationUpdated(const Configuration& configuration)
51 {}
52
HandleOnConfigurationUpdated(MessageParcel & data,MessageParcel & reply)53 int32_t ConfigurationObserverStub::HandleOnConfigurationUpdated(MessageParcel &data, MessageParcel &reply)
54 {
55 HITRACE_METER(HITRACE_TAG_APP);
56 std::unique_ptr<Configuration> configuration(data.ReadParcelable<Configuration>());
57 if (!configuration) {
58 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<Configuration> failed");
59 return ERR_APPEXECFWK_PARCEL_ERROR;
60 }
61
62 OnConfigurationUpdated(*configuration);
63 return NO_ERROR;
64 }
65 }
66 }
67