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