• 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 
29 namespace OHOS {
30 namespace ExternalDeviceManager {
31 class PkgDbHelper {
32 public:
33     static std::shared_ptr<PkgDbHelper> GetInstance();
34     /* query (user) record */
35     /* query (user, device) record */
36     /* query (user, device, app) record */
37     /* query users */
38     int32_t QueryRightRecordUids(std::vector<std::string> &uids);
39     /* query apps */
40     int32_t QueryRightRecordApps(int32_t uid, std::vector<std::string> &apps);
41 
42     /* update (user, device, app) record */
43     int32_t QueryAllDriverInfos(std::vector<std::string> &driverInfos);
44     /* add or update (user, device, app) record */
45     int32_t AddOrUpdateRightRecord(
46         const std::string &bundleName, const std::string &bundleAbility, const std::string &driverInfo);
47     std::string QueryBundleInfoNames(const std::string &driverInfo);
48     int32_t QueryAllBundleAbilityNames(const std::string &bundleName, std::vector<std::string> &bundleAbilityNames);
49     /* delete (user, device, app) record */
50     int32_t DeleteRightRecord(const std::string &bundleName);
51     /* delete (user, device) record */
52     int32_t DeleteDeviceRightRecord(int32_t uid, const std::string &deviceName);
53     /* delete (user, app) record */
54     int32_t DeleteAppRightRecord(int32_t uid, const std::string &bundleName);
55     /* delete (user, apps) record */
56     int32_t DeleteAppsRightRecord(int32_t uid, const std::vector<std::string> &bundleNames);
57     /* delete (user) record */
58     int32_t DeleteUidRightRecord(int32_t uid);
59     /* delete (user, time) expired record */
60     int32_t DeleteNormalExpiredRightRecord(int32_t uid, uint64_t expiredTime);
61     /* delete (validTime, device) record */
62     int32_t DeleteValidPeriodRightRecord(long validPeriod, const std::string &deviceName);
63     int32_t CheckIfNeedUpdateEx(
64         bool &isUpdate, const std::string &bundleName);
65     int32_t QueryAllSize(std::vector<std::string> &allBundleAbility);
66 private:
67     PkgDbHelper();
68     DISALLOW_COPY_AND_MOVE(PkgDbHelper);
69     int32_t AddOrUpdateRightRecordEx(bool isUpdate, const std::string &bundleName,
70         const std::string &bundleAbility, const std::string &driverInfo);
71     int32_t QueryRightRecordCount(void);
72     int32_t QueryAndGetResultColumnValues(const OHOS::NativeRdb::RdbPredicates &rdbPredicates,
73         const std::vector<std::string> &columns, const std::string &columnName, std::vector<std::string> &columnValues);
74     int32_t DeleteAndNoOtherOperation(const std::string &whereClause, const std::vector<std::string> &whereArgs);
75     int32_t DeleteAndNoOtherOperation(const OHOS::NativeRdb::RdbPredicates &rdbPredicates);
76 
77     static std::shared_ptr<PkgDbHelper> instance_;
78     std::mutex databaseMutex_;
79     std::shared_ptr<PkgDataBase> rightDatabase_;
80 };
81 } // namespace USB
82 } // namespace OHOS
83 
84 #endif
85