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