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_stub.h"
17 #include "appexecfwk_errors.h"
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
HandleOnAcceptWantResponse(MessageParcel & data,MessageParcel & reply)24 int32_t StartSpecifiedAbilityResponseStub::HandleOnAcceptWantResponse(MessageParcel &data, MessageParcel &reply)
25 {
26 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
27 if (want == nullptr) {
28 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
29 return ERR_INVALID_VALUE;
30 }
31
32 auto flag = Str16ToStr8(data.ReadString16());
33 OnAcceptWantResponse(*want, flag, data.ReadInt32());
34 delete want;
35 return NO_ERROR;
36 }
37
HandleOnTimeoutResponse(MessageParcel & data,MessageParcel & reply)38 int32_t StartSpecifiedAbilityResponseStub::HandleOnTimeoutResponse(MessageParcel &data, MessageParcel &reply)
39 {
40 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
41 if (want == nullptr) {
42 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
43 return ERR_INVALID_VALUE;
44 }
45
46 OnTimeoutResponse(*want, data.ReadInt32());
47 delete want;
48 return NO_ERROR;
49 }
50
HandleOnNewProcessRequestResponse(MessageParcel & data,MessageParcel & reply)51 int32_t StartSpecifiedAbilityResponseStub::HandleOnNewProcessRequestResponse(MessageParcel &data, MessageParcel &reply)
52 {
53 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
54 if (want == nullptr) {
55 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
56 return ERR_INVALID_VALUE;
57 }
58
59 auto flag = Str16ToStr8(data.ReadString16());
60 OnNewProcessRequestResponse(*want, flag, data.ReadInt32());
61 delete want;
62 return NO_ERROR;
63 }
64
HandleOnNewProcessRequestTimeoutResponse(MessageParcel & data,MessageParcel & reply)65 int32_t StartSpecifiedAbilityResponseStub::HandleOnNewProcessRequestTimeoutResponse(MessageParcel &data,
66 MessageParcel &reply)
67 {
68 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
69 if (want == nullptr) {
70 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
71 return ERR_INVALID_VALUE;
72 }
73
74 OnNewProcessRequestTimeoutResponse(*want, data.ReadInt32());
75 delete want;
76 return NO_ERROR;
77 }
78
HandleOnStartSpecifiedFailed(MessageParcel & data,MessageParcel & reply)79 int32_t StartSpecifiedAbilityResponseStub::HandleOnStartSpecifiedFailed(MessageParcel &data,
80 MessageParcel &reply)
81 {
82 OnStartSpecifiedFailed(data.ReadInt32());
83 return NO_ERROR;
84 }
85
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)86 int StartSpecifiedAbilityResponseStub::OnRemoteRequest(
87 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
88 {
89 TAG_LOGI(AAFwkTag::APPMGR, "StartSpecifiedAbilityResponseStub::OnReceived, code = %{public}u, flags= %{public}d.",
90 code, option.GetFlags());
91 std::u16string descriptor = StartSpecifiedAbilityResponseStub::GetDescriptor();
92 std::u16string remoteDescriptor = data.ReadInterfaceToken();
93 if (descriptor != remoteDescriptor) {
94 TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
95 return ERR_INVALID_STATE;
96 }
97
98 switch (code) {
99 case Message::ON_ACCEPT_WANT_RESPONSE: return HandleOnAcceptWantResponse(data, reply);
100 case Message::ON_TIMEOUT_RESPONSE: return HandleOnTimeoutResponse(data, reply);
101 case Message::ON_NEW_PROCESS_REQUEST_RESPONSE: return HandleOnNewProcessRequestResponse(data, reply);
102 case Message::ON_NEW_PROCESS_REQUEST_TIMEOUT_RESPONSE:
103 return HandleOnNewProcessRequestTimeoutResponse(data, reply);
104 case Message::ON_START_SPECIFIED_FAILED: return HandleOnStartSpecifiedFailed(data, reply);
105 default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
106 }
107 }
108 } // namespace AppExecFwk
109 } // namespace OHOS
110