1 /*
2  * Copyright (c) 2021-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_APPEXECFWK_SERVICES_BUNDLE_EXCEPTION_HANDLE_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLE_EXCEPTION_HANDLE_H
18 
19 #include "bundle_data_storage_interface.h"
20 #include "inner_bundle_info.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 class BundleExceptionHandler {
25 public:
26     explicit BundleExceptionHandler(const std::shared_ptr<IBundleDataStorage> &dataStorage);
27     virtual ~BundleExceptionHandler();
28 
29     /**
30      * @brief to handle the invalid bundle in the storage.
31      * @param info Indicates the bundle info of the application.
32      * @param path Indicates the base bundle path or data path.
33      */
34     void HandleInvalidBundle(InnerBundleInfo &info, bool &isBundleValid);
35     /**
36      * @brief to remove the bundle path and data path according to the input bundle or data path.
37      * @param info Indicates the bundle info of the application.
38      * @param dataDir Indicates the dir needs to be removed.
39      * @return Returns true for remove successfully, returns false otherwise.
40      */
41     bool RemoveBundleAndDataDir(const std::string &bundleDir, const std::string &bundleOrMoudleDir,
42         int32_t userId) const;
43     /**
44      * @brief to obtain the bundle path and data path according to the input base bundle or data path.
45      * @param info Indicates the bundle info of the application.
46      * @param basePath Indicates the base bundle path or data path.
47      * @return Returns string of the bundle or data path.
48      */
49     std::string GetBundleAndDataDir(const InnerBundleInfo &info, const std::string &basePath);
50     /**
51      * @brief to delete the bundle info from the storage.
52      * @param info Indicates the bundle info of the application.
53      */
54     void DeleteBundleInfoFromStorage(const InnerBundleInfo &info);
55 
56     bool IsBundleHapPathExist(const InnerBundleInfo &info);
57 
58 private:
59     void InnerHandleInvalidBundle(InnerBundleInfo &info, bool &isBundleValid);
60 
61     std::weak_ptr<IBundleDataStorage> dataStorage_;
62 };
63 }  // namespace AppExecFwk
64 }  // namespace OHOS
65 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLE_EXCEPTION_HANDLE_H