• 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_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     OnTimeoutResponse(data.ReadInt32());
41     return NO_ERROR;
42 }
43 
HandleOnNewProcessRequestResponse(MessageParcel & data,MessageParcel & reply)44 int32_t StartSpecifiedAbilityResponseStub::HandleOnNewProcessRequestResponse(MessageParcel &data, MessageParcel &reply)
45 {
46     auto flag = Str16ToStr8(data.ReadString16());
47     auto requestId = data.ReadInt32();
48     auto callerProcessName = Str16ToStr8(data.ReadString16());
49     OnNewProcessRequestResponse(flag, requestId, callerProcessName);
50     return NO_ERROR;
51 }
52 
HandleOnNewProcessRequestTimeoutResponse(MessageParcel & data,MessageParcel & reply)53 int32_t StartSpecifiedAbilityResponseStub::HandleOnNewProcessRequestTimeoutResponse(MessageParcel &data,
54     MessageParcel &reply)
55 {
56     OnNewProcessRequestTimeoutResponse(data.ReadInt32());
57     return NO_ERROR;
58 }
59 
HandleOnStartSpecifiedFailed(MessageParcel & data,MessageParcel & reply)60 int32_t StartSpecifiedAbilityResponseStub::HandleOnStartSpecifiedFailed(MessageParcel &data,
61     MessageParcel &reply)
62 {
63     OnStartSpecifiedFailed(data.ReadInt32());
64     return NO_ERROR;
65 }
66 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)67 int StartSpecifiedAbilityResponseStub::OnRemoteRequest(
68     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
69 {
70     TAG_LOGI(AAFwkTag::APPMGR, "StartSpecifiedAbilityResponseStub::OnReceived, code = %{public}u, flags= %{public}d.",
71         code, option.GetFlags());
72     std::u16string descriptor = StartSpecifiedAbilityResponseStub::GetDescriptor();
73     std::u16string remoteDescriptor = data.ReadInterfaceToken();
74     if (descriptor != remoteDescriptor) {
75         TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
76         return ERR_INVALID_STATE;
77     }
78 
79     switch (code) {
80         case Message::ON_ACCEPT_WANT_RESPONSE: return HandleOnAcceptWantResponse(data, reply);
81         case Message::ON_TIMEOUT_RESPONSE: return HandleOnTimeoutResponse(data, reply);
82         case Message::ON_NEW_PROCESS_REQUEST_RESPONSE: return HandleOnNewProcessRequestResponse(data, reply);
83         case Message::ON_NEW_PROCESS_REQUEST_TIMEOUT_RESPONSE:
84             return HandleOnNewProcessRequestTimeoutResponse(data, reply);
85         case Message::ON_START_SPECIFIED_FAILED: return HandleOnStartSpecifiedFailed(data, reply);
86         default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
87     }
88 }
89 }  // namespace AppExecFwk
90 }  // namespace OHOS
91