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 FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_RDB
17 #define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_RDB
18 
19 #include "default_app_db_interface.h"
20 #include "rdb_data_manager.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 class DefaultAppRdb final :
25     public IDefaultAppDb,
26     public std::enable_shared_from_this<DefaultAppRdb> {
27 public:
28     DefaultAppRdb();
29     ~DefaultAppRdb();
30     bool GetDefaultApplicationInfos(int32_t userId, std::map<std::string, Element>& infos) override;
31     bool GetDefaultApplicationInfo(int32_t userId, const std::string& type, Element& element) override;
32     bool SetDefaultApplicationInfos(int32_t userId, const std::map<std::string, Element>& infos) override;
33     bool SetDefaultApplicationInfo(int32_t userId, const std::string& type, const Element& element) override;
34     bool DeleteDefaultApplicationInfos(int32_t userId) override;
35     bool DeleteDefaultApplicationInfo(int32_t userId, const std::string& type) override;
36     void RegisterDeathListener() override;
37     void UnRegisterDeathListener() override;
38 
39 private:
40     bool ParseConfig(const std::string& relativePath, DefaultAppData& defaultAppData);
41     void LoadDefaultApplicationConfig();
42     void LoadBackUpDefaultApplicationConfig();
43     void ConvertMimeTypeToUtd();
44     bool GetDataFromDb(int32_t userId, std::map<std::string, Element>& infos);
45     bool SaveDataToDb(int32_t userId, const std::map<std::string, Element>& infos);
46     bool DeleteDataFromDb(int32_t userId);
47 
48     std::shared_ptr<RdbDataManager> rdbDataManager_;
49 };
50 } // namespace AppExecFwk
51 } // namespace OHOS
52 #endif // FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_RDB
53