• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H
17 #define OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H
18 
19 #include <shared_mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "b_json/b_json_entity_extension_config.h"
24 #include "b_resources/b_constants.h"
25 #include "ext_backup_js.h"
26 #include "ext_extension_stub.h"
27 #include "thread_pool.h"
28 
29 namespace OHOS::FileManagement::Backup {
30 class BackupExtExtension : public ExtExtensionStub {
31 public:
32     UniqueFd GetFileHandle(const std::string &fileName) override;
33     ErrCode HandleClear() override;
34     ErrCode PublishFile(const std::string &fileName) override;
35     ErrCode HandleBackup() override;
36 
37     void AsyncTaskRestoreForUpgrade(void);
38 
39 public:
BackupExtExtension(const std::shared_ptr<Backup::ExtBackup> & extension)40     explicit BackupExtExtension(const std::shared_ptr<Backup::ExtBackup> &extension) : extension_(extension)
41     {
42         threadPool_.Start(BConstants::EXTENSION_THREAD_POOL_COUNT);
43     }
~BackupExtExtension()44     ~BackupExtExtension()
45     {
46         threadPool_.Stop();
47     }
48 
49 private:
50     /**
51      * @brief verify caller uid
52      *
53      */
54     void VerifyCaller();
55 
56     /**
57      * @brief backup
58      *
59      * @param usrConfig user configure
60      */
61     int DoBackup(const BJsonEntityExtensionConfig &usrConfig);
62 
63     /**
64      * @brief restore
65      *
66      * @param fileName name of the file that to be untar
67      */
68     int DoRestore(const string &fileName);
69 
70     /** @brief clear backup restore data */
71     void DoClear();
72 
73     /**
74      * @brief extension backup restore is done
75      *
76      * @param errCode
77      */
78     void AppDone(ErrCode errCode);
79 
80     /**
81      * @brief Executing Backup Tasks Asynchronously
82      *
83      * @param extAction action
84      *
85      * @param config user configure
86      */
87     void AsyncTaskBackup(const std::string config);
88 
89     /**
90      * @brief Executing Restoration Tasks Asynchronously
91      *
92      */
93     void AsyncTaskRestore();
94 
95 private:
96     std::shared_mutex lock_;
97     std::shared_ptr<ExtBackup> extension_;
98     std::vector<std::string> tars_;
99     OHOS::ThreadPool threadPool_;
100 };
101 } // namespace OHOS::FileManagement::Backup
102 
103 #endif // OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H