• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 #ifndef OHOS_FORM_FWK_FORM_BUNDLE_LOCK_MGR_H
16 #define OHOS_FORM_FWK_FORM_BUNDLE_LOCK_MGR_H
17 
18 #include <map>
19 #include <shared_mutex>
20 #include <singleton.h>
21 #include <string>
22 
23 #include "want.h"
24 #include "form_rdb_data_mgr.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 /**
29  * @class FormBundleLockMgr
30  * Form bundle lock manager.
31  */
32 class FormBundleLockMgr final : public DelayedRefSingleton<FormBundleLockMgr> {
33     DECLARE_DELAYED_REF_SINGLETON(FormBundleLockMgr)
34 public:
35     DISALLOW_COPY_AND_MOVE(FormBundleLockMgr);
36 
37     /**
38      * @brief Init form bundle lock mgr.
39      * @return True for sucessful init, false for failed init.
40      */
41     bool Init();
42 
43     /**
44      * @brief Get whether bundle is lock.
45      * @param bundleName Bundle name to be check.
46      * @return True for lock, false for not lock.
47      */
48     bool IsBundleLock(const std::string &bundleName, int64_t formId = 0);
49 
50     /**
51      * @brief Set whether bundle is lock.
52      * @param bundleName Bundle name to be set.
53      * @param isLock True fot lock, false for not lock.
54      */
55     void SetBundleLockStatus(const std::string &bundleName, bool isLock);
56 
57     /**
58      * @brief Get whether bundle is protect.
59      * @param bundleName Bundle name to be check.
60      * @return True for protect, false for not protect.
61      */
62     bool IsBundleProtect(const std::string &bundleName, int64_t formId = 0);
63 
64     /**
65      * @brief Set whether bundle is protect.
66      * @param bundleName Bundle name to be set.
67      * @param isProtect True for protect, false for not protect.
68      */
69     void SetBundleProtectStatus(const std::string &bundleName, bool isProtect);
70 private:
71     bool isInitialized_ = false;
72     std::set<std::string> formBundleLockSet_;
73     mutable std::shared_mutex bundleLockSetMutex_;
74     std::set<std::string> formBundleProtectSet_;
75     mutable std::shared_mutex bundleProtectSetMutex_;
76 };
77 }  // namespace AppExecFwk
78 }  // namespace OHOS
79 
80 #endif // OHOS_FORM_FWK_FORM_BUNDLE_LOCK_MGR_H
81