1 /*
2  * Copyright (c) 2024 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_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H
17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H
18 
19 #include "extend_resource_manager_host.h"
20 #include "inner_bundle_info.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 class ExtendResourceManagerHostImpl : public ExtendResourceManagerHost {
25 public:
26     ExtendResourceManagerHostImpl();
27     virtual ~ExtendResourceManagerHostImpl();
28 
29     ErrCode AddExtResource(
30         const std::string &bundleName, const std::vector<std::string> &filePaths) override;
31     ErrCode RemoveExtResource(
32         const std::string &bundleName, const std::vector<std::string> &moduleNames) override;
33     ErrCode GetExtResource(
34         const std::string &bundleName, std::vector<std::string> &moduleNames) override;
35     ErrCode EnableDynamicIcon(
36         const std::string &bundleName, const std::string &moduleName) override;
37     ErrCode DisableDynamicIcon(const std::string &bundleName) override;
38     ErrCode GetDynamicIcon(const std::string &bundleName, std::string &moudleName) override;
39     ErrCode CreateFd(const std::string &fileName, int32_t &fd, std::string &path) override;
40 
41 private:
42     ErrCode BeforeAddExtResource(
43         const std::string &bundleName, const std::vector<std::string> &filePaths);
44     bool CheckFileParam(const std::string &filePath);
45     ErrCode ProcessAddExtResource(
46         const std::string &bundleName, const std::vector<std::string> &filePaths);
47     ErrCode CopyToTempDir(const std::string &bundleName,
48         const std::vector<std::string> &oldFilePaths, std::vector<std::string> &newFilePaths);
49     bool GetInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info);
50     void RollBack(const std::vector<std::string> &filePaths);
51     ErrCode MkdirIfNotExist(const std::string &dir);
52     ErrCode ParseExtendResourceFile(
53         const std::string &bundleName,
54         const std::vector<std::string> &filePaths,
55         std::vector<ExtendResourceInfo> &extendResourceInfos);
56     bool UpateExtResourcesDb(const std::string &bundleName,
57         const std::vector<ExtendResourceInfo> &extendResourceInfos);
58     bool RemoveExtResourcesDb(
59         const std::string &bundleName, const std::vector<std::string> &moduleNames);
60     void InnerSaveExtendResourceInfo(
61         const std::string &bundleName, const std::vector<std::string> &filePaths,
62         const std::vector<ExtendResourceInfo> &extendResourceInfos);
63     ErrCode CheckModuleExist(
64         const std::string &bundleName, const std::vector<std::string> &moduleNames,
65         std::vector<ExtendResourceInfo> &collectorExtResourceInfos);
66     void InnerRemoveExtendResources(
67         const std::string &bundleName, const std::vector<std::string> &moduleNames,
68         std::vector<ExtendResourceInfo> &extResourceInfos);
69     ErrCode GetExtendResourceInfo(const std::string &bundleName,
70         const std::string &moduleName, ExtendResourceInfo &extendResourceInfo);
71     bool ParseBundleResource(
72         const std::string &bundleName, const ExtendResourceInfo &extendResourceInfo);
73     void SendBroadcast(const std::string &bundleName, bool isEnableDynamicIcon);
74     void SaveCurDynamicIcon(const std::string &bundleName, const std::string &moduleName);
75     bool ResetBundleResourceIcon(const std::string &bundleName);
76 
77     std::atomic<uint32_t> id_ = 0;
78 };
79 } // AppExecFwk
80 } // OHOS
81 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H
82