• 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_CLIENT_H
17 #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H
18 
19 #include <condition_variable>
20 #include <functional>
21 #include <vector>
22 
23 #include "iquick_fix_manager.h"
24 #include "singleton.h"
25 #include "quick_fix_info.h"
26 
27 namespace OHOS {
28 namespace AAFwk {
29 using ClearProxyCallback = std::function<void(const wptr<IRemoteObject>&)>;
30 
31 class QuickFixManagerClient : public DelayedSingleton<QuickFixManagerClient>,
32                               public std::enable_shared_from_this<QuickFixManagerClient> {
33 public:
34     QuickFixManagerClient() = default;
35     virtual ~QuickFixManagerClient() = default;
36 
37     /**
38      * @brief Apply quick fix.
39      *
40      * @param quickFixFiles quick fix files need to apply, this value should include file path and file name.
41      * @param isDebug this value is for the quick fix debug mode selection.
42      * @param isReplace this value is for the quick fix replace mode selection.
43      * @return returns 0 on success, error code on failure.
44      */
45     int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles, bool isDebug = false, bool isReplace = false);
46 
47     /**
48      * @brief Get applyed quick fix info.
49      *
50      * @param bundleName bundle name of quick fix info.
51      * @param quickFixInfo quick fix info, including bundleName, bundleVersion and so on.
52      * @return int32_t returns 0 on success, error code on failure.
53      */
54     int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo);
55 
56     /**
57      * @brief Revoke quick fix by bundle name.
58      *
59      * @param bundleName quick fix files need to revoke.
60      * @return returns QUICK_FIX_OK on success, error code on failure.
61      */
62     int32_t RevokeQuickFix(const std::string &bundleName);
63 
64     void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
65     void OnLoadSystemAbilityFail();
66 
67 private:
68     sptr<IQuickFixManager> GetQuickFixMgrProxy();
69     void ClearProxy();
70     bool LoadQuickFixMgrService();
71     void SetQuickFixMgr(const sptr<IRemoteObject> &remoteObject);
72     sptr<IQuickFixManager> GetQuickFixMgr();
73 
74     class QfmsDeathRecipient : public IRemoteObject::DeathRecipient {
75     public:
QfmsDeathRecipient(const ClearProxyCallback & proxy)76         explicit QfmsDeathRecipient(const ClearProxyCallback &proxy) : proxy_(proxy) {}
77         virtual ~QfmsDeathRecipient() = default;
78         void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override;
79 
80     private:
81         ClearProxyCallback proxy_;
82     };
83 
84 private:
85     std::condition_variable loadSaCondation_;
86     std::mutex loadSaMutex_;
87     bool loadSaFinished_;
88     std::mutex mutex_;
89     sptr<IQuickFixManager> quickFixMgr_ = nullptr;
90 
91     DISALLOW_COPY_AND_MOVE(QuickFixManagerClient);
92 };
93 } // namespace AAFwk
94 } // namespace OHOS
95 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H
96