• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 "ability_start_with_wait_observer_stub.h"
17 
18 #include "ability_manager_errors.h"
19 #include "hilog_tag_wrapper.h"
20 #include "appexecfwk_errors.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int32_t AbilityStartWithWaitObserverStub::OnRemoteRequest(
26     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28     TAG_LOGD(AAFwkTag::ABILITYMGR, "msgCode:%{public}d", code);
29     std::u16string descriptor = AbilityStartWithWaitObserverStub::GetDescriptor();
30     std::u16string remoteDescriptor = data.ReadInterfaceToken();
31     if (descriptor != remoteDescriptor) {
32         TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid descriptor");
33         return ERR_INVALID_STATE;
34     }
35     if (code == static_cast<uint32_t>(IAbilityStartWithWaitObserver::Message::NOTIFY_AA_TERMINATE_WAIT)) {
36         return OnNotifyAATerminateWithWait(data, reply);
37     }
38     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
39 }
40 
OnNotifyAATerminateWithWait(MessageParcel & data,MessageParcel & reply)41 int32_t AbilityStartWithWaitObserverStub::OnNotifyAATerminateWithWait(MessageParcel& data, MessageParcel& reply)
42 {
43     std::unique_ptr<AbilityStartWithWaitObserverData> info(data.ReadParcelable<AbilityStartWithWaitObserverData>());
44     if (!info) {
45         TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<info> failed");
46         return ERR_AAFWK_PARCEL_FAIL;
47     }
48     int32_t result = NotifyAATerminateWait(*info);
49     if (!reply.WriteInt32(result)) {
50         TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
51         return IPC_STUB_ERR;
52     }
53     return ERR_OK;
54 }
55 
AbilityStartWithWaitObserverRecipient(RemoteDiedHandler handler)56 AbilityStartWithWaitObserverRecipient::AbilityStartWithWaitObserverRecipient(RemoteDiedHandler handler)
57     : handler_(handler)
58 {}
59 
OnRemoteDied(const wptr<IRemoteObject> & remote)60 void AbilityStartWithWaitObserverRecipient::OnRemoteDied(const wptr<IRemoteObject> &__attribute__((unused)) remote)
61 {
62     TAG_LOGE(AAFwkTag::ABILITYMGR, "Remote died");
63     if (handler_) {
64         handler_(remote);
65     }
66 }
67 } // namespace AAFwk
68 } // namespace OHOS