• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "start_specified_ability_response_proxy.h"
17 #include "ipc_types.h"
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
StartSpecifiedAbilityResponseProxy(const sptr<IRemoteObject> & impl)22 StartSpecifiedAbilityResponseProxy::StartSpecifiedAbilityResponseProxy(const sptr<IRemoteObject> &impl)
23     : IRemoteProxy<IStartSpecifiedAbilityResponse>(impl)
24 {}
25 
WriteInterfaceToken(MessageParcel & data)26 bool StartSpecifiedAbilityResponseProxy::WriteInterfaceToken(MessageParcel &data)
27 {
28     if (!data.WriteInterfaceToken(StartSpecifiedAbilityResponseProxy::GetDescriptor())) {
29         TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
30         return false;
31     }
32     return true;
33 }
34 
OnAcceptWantResponse(const AAFwk::Want & want,const std::string & flag,int32_t requestId)35 void StartSpecifiedAbilityResponseProxy::OnAcceptWantResponse(
36     const AAFwk::Want &want, const std::string &flag, int32_t requestId)
37 {
38     TAG_LOGD(AAFwkTag::APPMGR, "On accept want by proxy.");
39     MessageParcel data;
40     MessageParcel reply;
41     MessageOption option(MessageOption::TF_ASYNC);
42     if (!WriteInterfaceToken(data)) {
43         return;
44     }
45     if (!data.WriteParcelable(&want) || !data.WriteString(flag) ||
46         !data.WriteInt32(requestId)) {
47         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
48         return;
49     }
50 
51     int32_t ret = SendTransactCmd(
52         static_cast<uint32_t>(IStartSpecifiedAbilityResponse::Message::ON_ACCEPT_WANT_RESPONSE), data, reply, option);
53     if (ret != NO_ERROR) {
54         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
55     }
56 }
57 
OnTimeoutResponse(int32_t requestId)58 void StartSpecifiedAbilityResponseProxy::OnTimeoutResponse(int32_t requestId)
59 {
60     TAG_LOGD(AAFwkTag::APPMGR, "On timeout response by proxy.");
61     MessageParcel data;
62     MessageParcel reply;
63     MessageOption option(MessageOption::TF_ASYNC);
64     if (!WriteInterfaceToken(data)) {
65         return;
66     }
67     if (!data.WriteInt32(requestId)) {
68         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
69         return;
70     }
71 
72     int32_t ret = SendTransactCmd(static_cast<uint32_t>(
73         IStartSpecifiedAbilityResponse::Message::ON_TIMEOUT_RESPONSE), data, reply, option);
74     if (ret != NO_ERROR) {
75         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
76     }
77 }
78 
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)79 int32_t StartSpecifiedAbilityResponseProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
80     MessageParcel &reply, MessageOption &option)
81 {
82     sptr<IRemoteObject> remote = Remote();
83     if (remote == nullptr) {
84         TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
85         return ERR_NULL_OBJECT;
86     }
87 
88     return remote->SendRequest(code, data, reply, option);
89 }
90 
OnNewProcessRequestResponse(const std::string & flag,int32_t requestId,const std::string & callerProcessName)91 void StartSpecifiedAbilityResponseProxy::OnNewProcessRequestResponse(const std::string &flag,
92     int32_t requestId, const std::string &callerProcessName)
93 {
94     TAG_LOGD(AAFwkTag::APPMGR, "On satrt specified process response by proxy.");
95     MessageParcel data;
96     MessageParcel reply;
97     MessageOption option(MessageOption::TF_ASYNC);
98     if (!WriteInterfaceToken(data)) {
99         return;
100     }
101     if (!data.WriteString(flag) || !data.WriteInt32(requestId) || !data.WriteString(callerProcessName)) {
102         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
103         return;
104     }
105 
106     sptr<IRemoteObject> remote = Remote();
107     if (remote == nullptr) {
108         TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
109         return;
110     }
111     int32_t ret = remote->SendRequest(
112         static_cast<uint32_t>(IStartSpecifiedAbilityResponse::Message::ON_NEW_PROCESS_REQUEST_RESPONSE),
113         data, reply, option);
114     if (ret != NO_ERROR) {
115         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
116     }
117 }
118 
OnNewProcessRequestTimeoutResponse(int32_t requestId)119 void StartSpecifiedAbilityResponseProxy::OnNewProcessRequestTimeoutResponse(int32_t requestId)
120 {
121     TAG_LOGD(AAFwkTag::APPMGR, "On start specified process timeout response by proxy.");
122     MessageParcel data;
123     MessageParcel reply;
124     MessageOption option(MessageOption::TF_ASYNC);
125     if (!WriteInterfaceToken(data)) {
126         return;
127     }
128     if (data.WriteInt32(requestId)) {
129         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
130         return;
131     }
132 
133     sptr<IRemoteObject> remote = Remote();
134     if (remote == nullptr) {
135         TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
136         return;
137     }
138     int32_t ret = remote->SendRequest(static_cast<uint32_t>(
139         IStartSpecifiedAbilityResponse::Message::ON_NEW_PROCESS_REQUEST_TIMEOUT_RESPONSE),
140         data, reply, option);
141     if (ret != NO_ERROR) {
142         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
143     }
144 }
145 
OnStartSpecifiedFailed(int32_t requestId)146 void StartSpecifiedAbilityResponseProxy::OnStartSpecifiedFailed(int32_t requestId)
147 {
148     MessageParcel data;
149     MessageParcel reply;
150     MessageOption option(MessageOption::TF_ASYNC);
151     if (!WriteInterfaceToken(data)) {
152         return;
153     }
154     if (!data.WriteInt32(requestId)) {
155         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
156         return;
157     }
158 
159     int32_t ret = SendTransactCmd(
160         static_cast<uint32_t>(IStartSpecifiedAbilityResponse::Message::ON_START_SPECIFIED_FAILED), data, reply, option);
161     if (ret != NO_ERROR) {
162         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
163     }
164 }
165 }  // namespace AppExecFwk
166 }  // namespace OHOS
167