1 /*
2 * Copyright (c) 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 "assert_fault_callback.h"
17 #include "assert_fault_task_thread.h"
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
AssertFaultCallback(const std::weak_ptr<AssertFaultTaskThread> &assertFaultThread)22 AssertFaultCallback::AssertFaultCallback(const std::weak_ptr<AssertFaultTaskThread> &assertFaultThread)
23 {
24 assertFaultThread_ = assertFaultThread;
25 status_ = AAFwk::UserStatus::ASSERT_TERMINATE;
26 }
27
OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)28 int32_t AssertFaultCallback::OnRemoteRequest(
29 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31 std::u16string descriptor = AssertFaultCallback::GetDescriptor();
32 std::u16string remoteDescriptor = data.ReadInterfaceToken();
33 if (descriptor != remoteDescriptor) {
34 TAG_LOGE(AAFwkTag::APPKIT, "Local descriptor is not equal to remote");
35 return ERR_INVALID_STATE;
36 }
37
38 if (code == static_cast<uint32_t>(MessageCode::NOTIFY_DEBUG_ASSERT_RESULT)) {
39 auto status = static_cast<AAFwk::UserStatus>(data.ReadInt32());
40 NotifyDebugAssertResult(status);
41 return NO_ERROR;
42 }
43
44 TAG_LOGW(AAFwkTag::APPKIT, "Unexpected event ID, for default handling");
45 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
46 }
47
NotifyDebugAssertResult(AAFwk::UserStatus status)48 void AssertFaultCallback::NotifyDebugAssertResult(AAFwk::UserStatus status)
49 {
50 TAG_LOGD(AAFwkTag::APPKIT, "Notify user action result to assert fault thread");
51 status_ = status;
52 auto assertThread = assertFaultThread_.lock();
53 if (assertThread == nullptr) {
54 TAG_LOGE(AAFwkTag::APPKIT, "Failed to obtain assert fault thread");
55 return;
56 }
57 assertThread->NotifyReleaseLongWaiting();
58 }
59
GetAssertResult()60 AAFwk::UserStatus AssertFaultCallback::GetAssertResult()
61 {
62 return status_;
63 }
64 } // namespace AbilityRuntime
65 } // namespace OHOS