• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H
18 
19 #include "inner_bundle_info.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 class PreInstallBundleInfo {
24 public:
25     /**
26      * @brief Transform the PreInstallBundleInfo object to json.
27      * @param jsonObject Indicates the obtained json object.
28      * @return
29      */
30     void ToJson(nlohmann::json &jsonObject) const;
31     /**
32      * @brief Transform the json object to PreInstallBundleInfo object.
33      * @param jsonObject Indicates the obtained json object.
34      * @return Returns 0 if the json object parsed successfully; returns error code otherwise.
35      */
36     int32_t FromJson(const nlohmann::json &jsonObject);
37     /**
38      * @brief Transform the PreInstallBundleInfo object to string.
39      * @return Returns the string object
40      */
41     std::string ToString() const;
42     /**
43      * @brief Calculate Hap Total Size.
44      */
45     void CalculateHapTotalSize();
46     /**
47      * @brief Get HapTotalSize.
48      * @return Returns the HapTotalSize.
49      */
GetHapTotalSize()50     int64_t GetHapTotalSize() const
51     {
52         return hapTotalSize_;
53     }
54     /**
55      * @brief Add bundle path.
56      * @param bundlePath bundle path.
57      */
AddBundlePath(const std::string & bundlePath)58     void AddBundlePath(const std::string &bundlePath)
59     {
60         bool ret = std::find(
61             bundlePaths_.begin(), bundlePaths_.end(), bundlePath) != bundlePaths_.end();
62         if (!ret) {
63             bundlePaths_.emplace_back(bundlePath);
64         }
65     }
66     /**
67      * @brief Delete bundle path.
68      * @param bundlePath bundle path.
69      */
DeleteBundlePath(const std::string & bundlePath)70     void DeleteBundlePath(const std::string &bundlePath)
71     {
72         auto iter = std::find(bundlePaths_.begin(), bundlePaths_.end(), bundlePath);
73         if (iter != bundlePaths_.end()) {
74             bundlePaths_.erase(iter);
75         }
76     }
77     /**
78      * @brief Has bundle path.
79      * @param bundlePath bundle path.
80      */
HasBundlePath(const std::string & bundlePath)81     bool HasBundlePath(const std::string &bundlePath)
82     {
83         return std::find(bundlePaths_.begin(), bundlePaths_.end(), bundlePath)
84             != bundlePaths_.end();
85     }
86     /**
87      * @brief operator.
88      * @param PreInstallBundleInfo Indicates the PreInstallBundleInfo.
89      */
operator()90     bool operator() (const PreInstallBundleInfo& info) const
91     {
92         return bundleName_ == info.GetBundleName();
93     }
94 
95     bool operator < (const PreInstallBundleInfo &preInstallBundleInfo) const
96     {
97         if (bundlePaths_.size() == preInstallBundleInfo.GetBundlePaths().size()) {
98             return hapTotalSize_ >= preInstallBundleInfo.GetHapTotalSize();
99         }
100 
101         return bundlePaths_.size() > preInstallBundleInfo.GetBundlePaths().size();
102     }
103 
104     BMS_DEFINE_PROPERTY(AppType, appType_, Constants::AppType);
105     BMS_DEFINE_PROPERTY(Removable, removable_, bool);
106     BMS_DEFINE_PROPERTY(IsUninstalled, isUninstalled_, bool);
107     BMS_DEFINE_PROPERTY(BundleName, bundleName_, std::string);
108     BMS_DEFINE_PROPERTY(VersionCode, versionCode_, uint32_t);
109     BMS_DEFINE_PROPERTY_GET(BundlePaths, bundlePaths_, std::vector<std::string>);
110 private:
111     std::string bundleName_;
112     int64_t hapTotalSize_ = 0;
113     uint32_t versionCode_;
114     std::vector<std::string> bundlePaths_;
115     bool removable_ = true;
116     bool isUninstalled_ = false;
117     Constants::AppType appType_ = Constants::AppType::SYSTEM_APP;
118 };
119 }  // namespace AppExecFwk
120 }  // namespace OHOS
121 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H
122