1 /*
2 * Copyright (c) 2022 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_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 HILOG_ERROR("write interface token failed");
30 return false;
31 }
32 return true;
33 }
34
OnAcceptWantResponse(const AAFwk::Want & want,const std::string & flag)35 void StartSpecifiedAbilityResponseProxy::OnAcceptWantResponse(
36 const AAFwk::Want &want, const std::string &flag)
37 {
38 HILOG_DEBUG("On accept want by proxy.");
39 MessageParcel data;
40 MessageParcel reply;
41 MessageOption option(MessageOption::TF_SYNC);
42 if (!WriteInterfaceToken(data)) {
43 return;
44 }
45 if (!data.WriteParcelable(&want) || !data.WriteString(flag)) {
46 HILOG_ERROR("Write data failed.");
47 return;
48 }
49
50 sptr<IRemoteObject> remote = Remote();
51 if (remote == nullptr) {
52 HILOG_ERROR("Remote is nullptr.");
53 return;
54 }
55 int32_t ret = remote->SendRequest(
56 static_cast<uint32_t>(IStartSpecifiedAbilityResponse::Message::ON_ACCEPT_WANT_RESPONSE), data, reply, option);
57 if (ret != NO_ERROR) {
58 HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
59 }
60 }
61
OnTimeoutResponse(const AAFwk::Want & want)62 void StartSpecifiedAbilityResponseProxy::OnTimeoutResponse(const AAFwk::Want &want)
63 {
64 HILOG_DEBUG("On timeout response by proxy.");
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option(MessageOption::TF_SYNC);
68 if (!WriteInterfaceToken(data)) {
69 return;
70 }
71 if (!data.WriteParcelable(&want)) {
72 HILOG_ERROR("Write data failed.");
73 return;
74 }
75
76 sptr<IRemoteObject> remote = Remote();
77 if (remote == nullptr) {
78 HILOG_ERROR("Remote is nullptr.");
79 return;
80 }
81 int32_t ret = remote->SendRequest(static_cast<uint32_t>(
82 IStartSpecifiedAbilityResponse::Message::ON_TIMEOUT_RESPONSE), data, reply, option);
83 if (ret != NO_ERROR) {
84 HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
85 }
86 }
87 } // namespace AppExecFwk
88 } // namespace OHOS
89