• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t appIndex = 0; // not used
30     AppExecFwk::PreloadMode preloadMode;
31     std::shared_ptr<AbilityInfo> abilityInfo = nullptr;
32     std::shared_ptr<ApplicationInfo> appInfo = nullptr;
33     std::shared_ptr<AAFwk::Want> want = nullptr;
34     BundleInfo bundleInfo;
35     HapModuleInfo hapModuleInfo;
36     PreloadPhase preloadPhase = PreloadPhase::UNSPECIFIED;
37 };
38 
39 class AppPreloader {
40 public:
41     AppPreloader(std::shared_ptr<RemoteClientManager> remoteClientManager);
42     ~AppPreloader() = default;
43 
44     int32_t GeneratePreloadRequest(const std::string &bundleName, int32_t userId, int32_t appIndex,
45         PreloadRequest &request);
46 
47     bool PreCheck(const std::string &bundleName, PreloadMode mode);
48 
49 private:
50     bool GetLaunchWant(const std::string &bundleName, int32_t userId, AAFwk::Want &want);
51 
52     bool GetLaunchAbilityInfo(const AAFwk::Want &want, int32_t userId, AbilityInfo &abilityInfo);
53 
54     bool GetBundleAndHapInfo(const std::string &bundleName, int32_t userId,
55         const AbilityInfo &abilityInfo, BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo);
56 
57     bool CheckPreloadConditions(const AbilityInfo &abilityInfo);
58 
59     std::shared_ptr<BundleMgrHelper> GetBundleManagerHelper();
60 
61     std::shared_ptr<RemoteClientManager> remoteClientManager_;
62 };
63 }  // namespace AppExecFwk
64 }  // namespace OHOS
65 #endif  // OHOS_ABILITY_RUNTIME_APP_PRELOADER_H
66