• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 PKG_DB_HELPER_H
17 #define PKG_DB_HELPER_H
18 
19 #include "data_ability_predicates.h"
20 #include "rdb_errno.h"
21 #include "rdb_helper.h"
22 #include "rdb_open_callback.h"
23 #include "rdb_predicates.h"
24 #include "rdb_store.h"
25 #include "result_set.h"
26 #include "pkg_database.h"
27 #include "value_object.h"
28 #include "pkg_tables.h"
29 #include <unordered_set>
30 
31 namespace OHOS {
32 namespace ExternalDeviceManager {
33 class PkgDbHelper {
34 public:
35     static std::shared_ptr<PkgDbHelper> GetInstance();
36 
37     /* update (user, device, app) record */
38     int32_t QueryAllDriverInfos(std::vector<std::string> &driverInfos);
39     int32_t QueryPkgInfos(std::vector<PkgInfoTable> &pkgInfos,
40         bool isByDriverUid = false, const std::string &driverUid = "");
41     int32_t QueryPkgInfos(const std::string &bundleName, std::vector<PkgInfoTable> &pkgInfos);
42     /* add or update (user, device, app) record */
43     int32_t AddOrUpdateRightRecord(
44         const std::string &bundleName, const std::string &bundleAbility, const std::string &driverInfo);
45     std::string QueryBundleInfoNames(const std::string &driverInfo);
46     int32_t QueryAllBundleAbilityNames(const std::string &bundleName, std::vector<std::string> &bundleAbilityNames);
47     /* delete (user, device, app) record */
48     int32_t DeleteRightRecord(const std::string &bundleName);
49 
50     int32_t CheckIfNeedUpdateEx(
51         bool &isUpdate, const std::string &bundleName);
52     int32_t QueryAllSize(std::vector<std::string> &allBundleAbility);
53     int32_t AddOrUpdatePkgInfo(const std::vector<PkgInfoTable> &pkgInfos, const std::string &bundleName = "");
54 
55 private:
56     PkgDbHelper();
57     DISALLOW_COPY_AND_MOVE(PkgDbHelper);
58     int32_t AddOrUpdateRightRecordEx(bool isUpdate, const std::string &bundleName,
59         const std::string &bundleAbility, const std::string &driverInfo);
60     int32_t QueryAndGetResultColumnValues(const OHOS::NativeRdb::RdbPredicates &rdbPredicates,
61         const std::vector<std::string> &columns, const std::string &columnName, std::vector<std::string> &columnValues);
62     int32_t DeleteAndNoOtherOperation(const std::string &whereClause, const std::vector<std::string> &whereArgs);
63 
64     int32_t QueryPkgInfos(const std::string &whereKey, const std::string &whereValue,
65         std::vector<PkgInfoTable> &pkgInfos);
66 
67     static std::shared_ptr<PkgDbHelper> instance_;
68     std::mutex databaseMutex_;
69     std::shared_ptr<PkgDataBase> rightDatabase_;
70 };
71 } // namespace USB
72 } // namespace OHOS
73 
74 #endif
75