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_MODAL_SYSTEM_APP_FREEZE_UIEXTENSION_H 17 #define OHOS_ABILITY_RUNTIME_MODAL_SYSTEM_APP_FREEZE_UIEXTENSION_H 18 19 #ifdef APP_NO_RESPONSE_DIALOG 20 21 #include <iremote_broker.h> 22 #include <semaphore.h> 23 #include <functional> 24 25 #include "ability_connect_callback_stub.h" 26 #include "ability_manager_client.h" 27 #include "ability_state.h" 28 #include "fault_data.h" 29 #include "iremote_stub.h" 30 #include "task_handler_wrap.h" 31 #include "want.h" 32 33 namespace OHOS { 34 namespace AppExecFwk { 35 36 constexpr const char* APP_NO_RESPONSE_ABILITY = "AppAbnormalAbility"; 37 38 class ModalSystemAppFreezeUIExtension { 39 public: 40 static ModalSystemAppFreezeUIExtension &GetInstance(); 41 ModalSystemAppFreezeUIExtension() = default; 42 virtual ~ModalSystemAppFreezeUIExtension(); 43 44 void ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, std::string bundleName, 45 std::function<void()> callback, bool isDialogExist); 46 47 private: 48 bool CreateModalUIExtension(std::string pid, std::string bundleName); 49 AAFwk::Want CreateSystemDialogWant(std::string pid, std::string bundleName); 50 51 private: 52 class AppFreezeDialogConnection : public AAFwk::AbilityConnectionStub { 53 public: 54 AppFreezeDialogConnection() = default; 55 virtual ~AppFreezeDialogConnection() = default; 56 57 void SetReqeustAppFreezeDialogWant(const AAFwk::Want &want); 58 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 59 int resultCode) override; 60 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 61 62 private: 63 AAFwk::Want want_; 64 }; 65 66 private: 67 sptr<AppFreezeDialogConnection> GetConnection(); 68 69 std::mutex appFreezeResultMutex_; 70 std::mutex dialogConnectionMutex_; 71 std::string lastFreezePid; 72 sptr<AppFreezeDialogConnection> dialogConnectionCallback_; 73 }; 74 } // namespace AppExecFwk 75 } // namespace OHOS 76 #endif // APP_NO_RESPONSE_DIALOG 77 #endif // OHOS_ABILITY_RUNTIME_MODAL_SYSTEM_APP_FREEZE_UIEXTENSION_H