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 #ifndef OHOS_ABILITY_RUNTIME_ASSERT_FAULT_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_ASSERT_FAULT_PROXY_H 18 19 #include <chrono> 20 #include <mutex> 21 #include <queue> 22 23 #include "iremote_broker.h" 24 #include "iremote_object.h" 25 #include "iremote_proxy.h" 26 #include "ability_connect_callback_stub.h" 27 #include "assert_fault_interface.h" 28 #include "singleton.h" 29 30 namespace OHOS { 31 namespace AbilityRuntime { 32 class AssertFaultProxy : public IRemoteProxy<IAssertFaultInterface> { 33 public: 34 explicit AssertFaultProxy(const sptr<IRemoteObject> &impl); 35 virtual ~AssertFaultProxy() = default; 36 /** 37 * Notify listeners of user operation results. 38 * 39 * @param status - User action result. 40 */ 41 void NotifyDebugAssertResult(AAFwk::UserStatus status) override; 42 43 private: 44 static inline BrokerDelegator<AssertFaultProxy> delegator_; 45 }; 46 47 class AssertFaultRemoteDeathRecipient : public IRemoteObject::DeathRecipient { 48 public: 49 using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>; 50 explicit AssertFaultRemoteDeathRecipient(RemoteDiedHandler handler); 51 virtual ~AssertFaultRemoteDeathRecipient() = default; 52 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 53 54 private: 55 RemoteDiedHandler handler_; 56 }; 57 58 class ModalSystemAssertUIExtension { 59 public: 60 static ModalSystemAssertUIExtension &GetInstance(); 61 ModalSystemAssertUIExtension() = default; 62 virtual ~ModalSystemAssertUIExtension(); 63 64 bool CreateModalUIExtension(const AAFwk::Want &want); 65 66 friend class AssertFaultProxy; 67 68 private: 69 class AssertDialogConnection : public OHOS::AAFwk::AbilityConnectionStub { 70 public: 71 AssertDialogConnection() = default; 72 virtual ~AssertDialogConnection() = default; 73 74 void SetReqeustAssertDialogWant(const AAFwk::Want &want); 75 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 76 int resultCode) override; 77 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 78 79 private: 80 AAFwk::Want want_; 81 }; 82 83 private: 84 bool DisconnectSystemUI(); 85 void TryNotifyOneWaitingThread(); 86 void TryNotifyOneWaitingThreadInner(); 87 88 std::mutex assertResultMutex_; 89 std::condition_variable assertResultCV_; 90 int32_t reqeustCount_ = 0; 91 sptr<AssertDialogConnection> GetConnection(); 92 std::mutex dialogConnectionMutex_; 93 sptr<AssertDialogConnection> dialogConnectionCallback_; 94 }; 95 } // namespace AbilityRuntime 96 } // namespace OHOS 97 #endif // OHOS_ABILITY_RUNTIME_ASSERT_FAULT_PROXY_H