• 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 #ifndef PKG_DATABASE_H
16 #define PKG_DATABASE_H
17 
18 #include <pthread.h>
19 
20 #include "data_ability_predicates.h"
21 #include "rdb_errno.h"
22 #include "rdb_helper.h"
23 #include "rdb_open_callback.h"
24 #include "rdb_predicates.h"
25 #include "rdb_store.h"
26 #include "result_set.h"
27 #include "value_object.h"
28 
29 namespace OHOS {
30 namespace ExternalDeviceManager {
31 static std::string PKG_DB_PATH = "/data/service/el1/public/pkg_service/";
32 
33 constexpr const char *PKG_DB_NAME = "pkg.db";
34 constexpr const char *PKG_TABLE_NAME = "pkgInfoTable";
35 constexpr int32_t DATABASE_OPEN_VERSION = 1;
36 constexpr int32_t DATABASE_NEW_VERSION = 2;
37 
38 constexpr const char *CREATE_PKG_TABLE = "CREATE TABLE IF NOT EXISTS [pkgInfoTable]("
39                                                "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
40                                                "[bundleName] TEXT,"
41                                                "[bundleAbility] TEXT,"
42                                                "[driverInfo] TEXT );";
43 
44 class PkgDataBase {
45 public:
46     static std::shared_ptr<PkgDataBase> GetInstance();
47     int64_t Insert(const OHOS::NativeRdb::ValuesBucket &insertValues);
48     int32_t Update(int32_t &changedRows, const OHOS::NativeRdb::ValuesBucket &values,
49         const OHOS::NativeRdb::RdbPredicates &predicates);
50     int32_t Update(int32_t &changedRows, const OHOS::NativeRdb::ValuesBucket &values, const std::string &whereClause,
51         const std::vector<std::string> &whereArgs);
52     int32_t Delete(const OHOS::NativeRdb::RdbPredicates &rdbPredicates);
53     int32_t Delete(int32_t &changedRows, const std::string &whereClause, const std::vector<std::string> &whereArgs);
54     std::shared_ptr<OHOS::NativeRdb::ResultSet> Query(
55         const OHOS::NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> &columns);
56     int32_t BeginTransaction();
57     int32_t Commit();
58     int32_t RollBack();
59     bool InitDB();
60 
61 private:
62     PkgDataBase();
63     DISALLOW_COPY_AND_MOVE(PkgDataBase);
64     static std::shared_ptr<PkgDataBase> instance_;
65     std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
66 };
67 
68 class PkgDataBaseCallBack : public OHOS::NativeRdb::RdbOpenCallback {
69 public:
70     int32_t OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
71     int32_t OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
72     int32_t OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int32_t currentVersion, int32_t targetVersion) override;
73 };
74 } // namespace USB
75 } // namespace OHOS
76 
77 #endif
78