1 /*
2  * Copyright (c) 2021-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 "zidl/convert_callback_stub.h"
17 #include "zidl/convert_callback_interface_code.h"
18 #include "app_domain_verify_hilog.h"
19 #include "app_domain_verify_parcel_util.h"
20 
21 namespace OHOS {
22 namespace AppDomainVerify {
ConvertCallbackStub()23 ConvertCallbackStub::ConvertCallbackStub()
24 {
25     APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "new instance created.");
26 }
27 
~ConvertCallbackStub()28 ConvertCallbackStub::~ConvertCallbackStub()
29 {
30     APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "instance dead.");
31 }
32 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int ConvertCallbackStub::OnRemoteRequest(
34     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
35 {
36     APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT,
37         "ConvertCallbackStub callback host onReceived message, the message code is %{public}u", code);
38     std::u16string descripter = ConvertCallbackStub::GetDescriptor();
39     std::u16string remoteDescripter = data.ReadInterfaceToken();
40     if (descripter != remoteDescripter) {
41         APP_DOMAIN_VERIFY_HILOGE(
42             APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "fail to write reply message in convert due to the reply is nullptr");
43         return OBJECT_NULL;
44     }
45 
46     switch (code) {
47         case static_cast<uint32_t>(ConvertCallbackInterfaceCode::ON_CONVERT_CALLBACK): {
48             int32_t retCode = data.ReadInt32();
49             std::unique_ptr<OHOS::AAFwk::Want> w(data.ReadParcelable<OHOS::AAFwk::Want>());
50             OHOS::AAFwk::Want want;
51             if (!w) {
52                 APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "read parcelable want failed.");
53                 return ERR_INVALID_VALUE;
54             }
55             want = *w;
56             OnConvert(retCode, want);
57             break;
58         }
59         default:
60             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61     }
62     return NO_ERROR;
63 }
64 }  // namespace AppExecFwk
65 }  // namespace OHOS
66