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 OHOS_ABILITY_RUNTIME_APP_PRELOADER_H
17 #define OHOS_ABILITY_RUNTIME_APP_PRELOADER_H
18 
19 #include <string>
20 
21 #include "ability_info.h"
22 #include "app_mgr_constants.h"
23 #include "remote_client_manager.h"
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 struct PreloadRequest {
29     std::shared_ptr<AbilityInfo> abilityInfo = nullptr;
30     std::shared_ptr<ApplicationInfo> appInfo = nullptr;
31     std::shared_ptr<AAFwk::Want> want = nullptr;
32     BundleInfo bundleInfo;
33     HapModuleInfo hapModuleInfo;
34     int32_t appIndex = 0; // not used
35 };
36 
37 class AppPreloader {
38 public:
39     AppPreloader(std::shared_ptr<RemoteClientManager> remoteClientManager);
40     ~AppPreloader() = default;
41 
42     int32_t GeneratePreloadRequest(const std::string &bundleName, int32_t userId, int32_t appIndex,
43         PreloadRequest &request);
44 
45     bool PreCheck(const std::string &bundleName, PreloadMode mode);
46 
47 private:
48     bool GetLaunchWant(const std::string &bundleName, int32_t userId, AAFwk::Want &want);
49 
50     bool GetLaunchAbilityInfo(const AAFwk::Want &want, int32_t userId, AbilityInfo &abilityInfo);
51 
52     bool GetBundleAndHapInfo(const std::string &bundleName, int32_t userId,
53         const AbilityInfo &abilityInfo, BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo);
54 
55     bool CheckPreloadConditions(const AbilityInfo &abilityInfo);
56 
57     std::shared_ptr<BundleMgrHelper> GetBundleManagerHelper();
58 
59     std::shared_ptr<RemoteClientManager> remoteClientManager_;
60 };
61 }  // namespace AppExecFwk
62 }  // namespace OHOS
63 #endif  // OHOS_ABILITY_RUNTIME_APP_PRELOADER_H
64