• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_QUICK_FIX_MANAGER_APPLY_TASK_H
17 #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_APPLY_TASK_H
18 
19 #include "app_mgr_interface.h"
20 #include "event_handler.h"
21 #include "quick_fix_result_info.h"
22 #include "quick_fix/quick_fix_manager_interface.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 class QuickFixManagerService;
27 class QuickFixManagerApplyTask : public std::enable_shared_from_this<QuickFixManagerApplyTask> {
28 public:
QuickFixManagerApplyTask(sptr<AppExecFwk::IQuickFixManager> bundleQfMgr,sptr<AppExecFwk::IAppMgr> appMgr,std::shared_ptr<AppExecFwk::EventHandler> handler,wptr<QuickFixManagerService> service)29     QuickFixManagerApplyTask(sptr<AppExecFwk::IQuickFixManager> bundleQfMgr, sptr<AppExecFwk::IAppMgr> appMgr,
30         std::shared_ptr<AppExecFwk::EventHandler> handler, wptr<QuickFixManagerService> service)
31         : bundleQfMgr_(bundleQfMgr), appMgr_(appMgr), eventHandler_(handler), quickFixMgrService_(service)
32     {}
33 
34     virtual ~QuickFixManagerApplyTask();
35 
36     enum TaskType {
37         QUICK_FIX_APPLY,
38         QUICK_FIX_REVOKE,
39     };
40 
41     void Run(const std::vector<std::string> &quickFixFiles, bool isDebug = false);
42     void HandlePatchDeployed();
43     void HandlePatchSwitched();
44     void HandlePatchDeleted();
45 
46     bool SetQuickFixInfo(const std::shared_ptr<AppExecFwk::QuickFixResult> &result);
47     bool GetRunningState();
48 
49     void RemoveTimeoutTask();
50     void NotifyApplyStatus(int32_t resultCode);
51     void RemoveSelf();
52 
53     void PostSwitchQuickFixTask();
54     void PostDeleteQuickFixTask();
55 
56     void UnregAppStateObserver();
57 
58     void RunRevoke();
59     void InitRevokeTask(const std::string &bundleName, bool isSoContained);
60     std::string GetBundleName();
61     TaskType GetTaskType();
62     void HandleRevokePatchDeleted();
63     void HandleRevokePatchSwitched();
64     void PostRevokeQuickFixDeleteTask();
65     void PostRevokeQuickFixProcessDiedTask();
66 private:
67     void PostDeployQuickFixTask(const std::vector<std::string> &quickFixFiles, bool isDebug = false);
68     void PostTimeOutTask();
69     void PostNotifyLoadRepairPatchTask();
70     void PostNotifyUnloadRepairPatchTask();
71     void PostNotifyHotReloadPageTask();
72     void RegAppStateObserver();
73     void PostRevokeQuickFixTask();
74     void HandleRevokeQuickFixAppRunning();
75     void PostRevokeQuickFixNotifyUnloadPatchTask();
76     void HandleRevokeQuickFixAppStop();
77 
78     sptr<AppExecFwk::IQuickFixManager> bundleQfMgr_ = nullptr;
79     sptr<AppExecFwk::IAppMgr> appMgr_ = nullptr;
80     sptr<AppExecFwk::IApplicationStateObserver> appStateCallback_ = nullptr;
81     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
82     wptr<QuickFixManagerService> quickFixMgrService_ = nullptr;
83     std::string bundleName_;
84     int bundleVersionCode_ = 0;
85     int patchVersionCode_ = 0;
86     bool isRunning_ = false;
87     bool isSoContained_ = false;
88     AppExecFwk::QuickFixType type_ = AppExecFwk::QuickFixType::UNKNOWN;
89     std::vector<std::string> moduleNames_;
90     TaskType taskType_ = TaskType::QUICK_FIX_APPLY;
91 };
92 } // namespace AAFwk
93 } // namespace OHOS
94 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_APPLY_TASK_H
95