• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "singleton.h"
24 #include "quick_fix_manager_interface.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      * @return returns 0 on success, error code on failure.
42      */
43     int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles);
44 
45     /**
46      * @brief Get applyed quick fix info.
47      *
48      * @param bundleName bundle name of quick fix info.
49      * @param quickFixInfo quick fix info, including bundleName, bundleVersion and so on.
50      * @return int32_t returns 0 on success, error code on failure.
51      */
52     int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo);
53 
54     void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
55     void OnLoadSystemAbilityFail();
56 
57 private:
58     sptr<IQuickFixManager> GetQuickFixMgrProxy();
59     void ClearProxy();
60     bool LoadQuickFixMgrService();
61     void SetQuickFixMgr(const sptr<IRemoteObject> &remoteObject);
62     sptr<IQuickFixManager> GetQuickFixMgr();
63 
64     class QfmsDeathRecipient : public IRemoteObject::DeathRecipient {
65     public:
QfmsDeathRecipient(const ClearProxyCallback & proxy)66         explicit QfmsDeathRecipient(const ClearProxyCallback &proxy) : proxy_(proxy) {}
67         virtual ~QfmsDeathRecipient() = default;
68         void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override;
69 
70     private:
71         ClearProxyCallback proxy_;
72     };
73 
74 private:
75     std::condition_variable loadSaCondation_;
76     std::mutex loadSaMutex_;
77     bool loadSaFinished_;
78     std::mutex mutex_;
79     sptr<IQuickFixManager> quickFixMgr_ = nullptr;
80 
81     DISALLOW_COPY_AND_MOVE(QuickFixManagerClient);
82 };
83 } // namespace AAFwk
84 } // namespace OHOS
85 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H
86