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