1 /*
2 * Copyright (c) 2022-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 "form_status_change_callback.h"
17 #include "access_token.h"
18 #include "accesstoken_log.h"
19 #include "access_token_error.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
24 namespace {
25 static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024;
26 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
27 LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormStateObserverStub"
28 };
29 }
30
FormStateObserverStub()31 FormStateObserverStub::FormStateObserverStub()
32 {
33 ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub Instance create.");
34 }
35
~FormStateObserverStub()36 FormStateObserverStub::~FormStateObserverStub()
37 {
38 ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub Instance destroy.");
39 }
40
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int32_t FormStateObserverStub::OnRemoteRequest(
42 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
43 {
44 if (data.ReadInterfaceToken() != GetDescriptor()) {
45 ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub: ReadInterfaceToken failed.");
46 return ERROR_IPC_REQUEST_FAIL;
47 }
48 switch (static_cast<IJsFormStateObserver::Message>(code)) {
49 case IJsFormStateObserver::Message::FORM_STATE_OBSERVER_NOTIFY_WHETHER_FORMS_VISIBLE: {
50 HandleNotifyWhetherFormsVisible(data, reply);
51 return NO_ERROR;
52 }
53 default: {
54 ACCESSTOKEN_LOG_DEBUG(LABEL, "Default case code: %{public}d.", code);
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57 }
58 return NO_ERROR;
59 }
60
HandleNotifyWhetherFormsVisible(MessageParcel & data,MessageParcel & reply)61 int32_t FormStateObserverStub::HandleNotifyWhetherFormsVisible(MessageParcel &data, MessageParcel &reply)
62 {
63 FormVisibilityType visibleType = static_cast<FormVisibilityType>(data.ReadInt32());
64 std::string bundleName = data.ReadString();
65 std::vector<FormInstance> formInstances;
66 int32_t infoSize = data.ReadInt32();
67 if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) {
68 ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid size: %{public}d.", infoSize);
69 return ERR_OVERSIZE;
70 }
71 for (int32_t i = 0; i < infoSize; i++) {
72 std::unique_ptr<FormInstance> info(data.ReadParcelable<FormInstance>());
73 if (info == nullptr) {
74 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Read Parcelable infos.");
75 return RET_FAILED;
76 }
77 formInstances.emplace_back(*info);
78 }
79 NotifyWhetherFormsVisible(visibleType, bundleName, formInstances);
80 return NO_ERROR;
81 }
82 } // namespace AccessToken
83 } // namespace Security
84 } // namespace OHOS
85