• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 <memory>
17 #include "app_domain_verify_agent_service_stub.h"
18 #include "agent_interface_code.h"
19 #include "errors.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 #include "app_domain_verify_parcel_util.h"
23 
24 namespace OHOS {
25 namespace AppDomainVerify {
26 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t AppDomainVerifyAgentServiceStub::OnRemoteRequest(
28     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
29 {
30     APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "onRemoteRequest##code = %{public}u", code);
31     std::u16string myDescripter = AppDomainVerifyAgentServiceStub::GetDescriptor();
32     std::u16string remoteDescripter = data.ReadInterfaceToken();
33     if (myDescripter != remoteDescripter) {
34         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "end##descriptor checked fail");
35         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
36     }
37     switch (code) {
38         case static_cast<uint32_t>(static_cast<uint32_t>(AgentInterfaceCode::SINGLE_VERIFY)):
39             return OnSingleVerify(data, reply);
40         case static_cast<uint32_t>(AgentInterfaceCode::CONVERT_TO_EXPLICIT_WANT):
41             return OnConvertToExplicitWant(data, reply);
42         case static_cast<uint32_t>(AgentInterfaceCode::COMMON_TRANSACT):
43             return OnCommonTransact(data, reply);
44         default:
45             APP_DOMAIN_VERIFY_HILOGW(
46                 APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "receive unknown code, code = %{public}d", code);
47             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48     }
49 }
50 
OnSingleVerify(MessageParcel & data,MessageParcel & reply)51 int32_t AppDomainVerifyAgentServiceStub::OnSingleVerify(MessageParcel& data, MessageParcel& reply)
52 {
53     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
54     std::unique_ptr<AppVerifyBaseInfo> info(data.ReadParcelable<AppVerifyBaseInfo>());
55     if (!info) {
56         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "read parcelable AppVerifyBaseInfo failed.");
57         return ERR_INVALID_VALUE;
58     }
59     AppVerifyBaseInfo appVerifyBaseInfo = *info;
60 
61     std::unique_ptr<VerifyResultInfo> result(data.ReadParcelable<VerifyResultInfo>());
62     if (!result) {
63         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "read parcelable VerifyResultInfo failed.");
64         return ERR_INVALID_VALUE;
65     }
66     VerifyResultInfo verifyBaseInfo = *result;
67 
68     SingleVerify(appVerifyBaseInfo, verifyBaseInfo);
69     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "call end");
70     return ERR_OK;
71 }
OnConvertToExplicitWant(MessageParcel & data,MessageParcel & reply)72 int32_t AppDomainVerifyAgentServiceStub::OnConvertToExplicitWant(MessageParcel& data, MessageParcel& reply)
73 {
74     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
75     OHOS::AAFwk::Want want;
76     std::unique_ptr<OHOS::AAFwk::Want> w(data.ReadParcelable<OHOS::AAFwk::Want>());
77     if (!w) {
78         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "read parcelable want failed.");
79         return ERR_INVALID_VALUE;
80     }
81     want = *w;
82     sptr<IRemoteObject> object = data.ReadRemoteObject();
83     if (object == nullptr) {
84         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "read failed");
85         return ERR_INVALID_VALUE;
86     }
87     sptr<IConvertCallback> cleanCacheCallback = iface_cast<IConvertCallback>(object);
88     ConvertToExplicitWant(want, cleanCacheCallback);
89     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
90     return ERR_OK;
91 }
OnCommonTransact(MessageParcel & data,MessageParcel & reply)92 int32_t AppDomainVerifyAgentServiceStub::OnCommonTransact(MessageParcel& data, MessageParcel& reply)
93 {
94     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
95     OHOS::AAFwk::Want want;
96     std::string request;
97     uint32_t opcode;
98     READ_PARCEL_AND_RETURN_INT_IF_FAIL(Uint32, data, opcode);
99     READ_PARCEL_AND_RETURN_INT_IF_FAIL(String, data, request);
100     std::string response;
101     auto status = CommonTransact(opcode, request, response);
102     WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(Int32, reply, status);
103     WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(String, reply, response);
104     APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
105     return ERR_OK;
106     return 0;
107 }
108 
109 }  // namespace AppDomainVerify
110 }  // namespace OHOS