• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "appexecfwk_errors.h"
23 #include "bundle_data_storage_interface.h"
24 #include "bundle_constants.h"
25 #include "inner_bundle_info.h"
26 #include "singleton.h"
27 
28 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
29 #include "bundle_sandbox_data_mgr.h"
30 #endif
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class BundleSandboxAppHelper : public DelayedSingleton<BundleSandboxAppHelper> {
35 public:
36     // BundleSandboxDataMgr interface
37     void SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex);
38     void DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex);
39     ErrCode GetSandboxAppBundleInfo(
40         const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const;
41     int32_t GenerateSandboxAppIndex(const std::string &bundleName);
42     bool DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex);
43     std::unordered_map<std::string, InnerBundleInfo> GetSandboxAppInfoMap() const;
44     ErrCode GetSandboxAppInfo(
45         const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const;
46     ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
47         HapModuleInfo &hapModuleInfo) const;
48     ErrCode GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const;
49 
50     // BundleSandboxExceptionHandler interface
51     void RemoveSandboxApp(const std::shared_ptr<IBundleDataStorage> &dataStorage, InnerBundleInfo &info);
52 
53     // BundleSandboxInstaller interface
54     ErrCode InstallSandboxApp(const std::string &bundleName, const int32_t &dlpType, const int32_t &userId,
55         int32_t &appIndex);
56 
57     ErrCode UninstallSandboxApp(const std::string &bundleName, const int32_t &appIndex, const int32_t &userId);
58 
59     ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID);
60 
61 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
GetSandboxDataMgr()62     std::shared_ptr<BundleSandboxDataMgr> GetSandboxDataMgr() const
63     {
64         return sandboxDataMgr_;
65     }
66 #endif
67 
68 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
69 private:
70     std::shared_ptr<BundleSandboxDataMgr> sandboxDataMgr_ = std::make_shared<BundleSandboxDataMgr>();
71 #endif
72 };
73 } // AppExecFwk
74 } // OHOS
75 
76 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H