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_EXTENSION_RECORD_FACTORY_H 17 #define OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_FACTORY_H 18 19 #include "ability_record.h" 20 #include "extension_record.h" 21 22 namespace OHOS { 23 namespace AbilityRuntime { 24 constexpr const char *PROCESS_MODE_HOST_SPECIFIED_KEY = "ohos.extension.processMode.hostSpecified"; 25 constexpr const char *PROCESS_MODE_HOST_INSTANCE_KEY = "ohos.extension.processMode.hostInstance"; 26 constexpr uint32_t PROCESS_MODE_INSTANCE = 1 << static_cast<uint32_t>(AppExecFwk::ExtensionProcessMode::INSTANCE); 27 constexpr uint32_t PROCESS_MODE_TYPE = 1 << static_cast<uint32_t>(AppExecFwk::ExtensionProcessMode::TYPE); 28 constexpr uint32_t PROCESS_MODE_BUNDLE = 1 << static_cast<uint32_t>(AppExecFwk::ExtensionProcessMode::BUNDLE); 29 constexpr uint32_t PROCESS_INNER_MODE_OFFSET = 16; 30 constexpr uint32_t PROCESS_MODE_HOST_SPECIFIED = 1 << (PROCESS_INNER_MODE_OFFSET + 0); 31 constexpr uint32_t PROCESS_MODE_HOST_INSTANCE = 1 << (PROCESS_INNER_MODE_OFFSET + 1); 32 constexpr uint32_t PROCESS_MODE_SUPPORT_DEFAULT = PROCESS_MODE_BUNDLE | PROCESS_MODE_TYPE | PROCESS_MODE_INSTANCE; 33 constexpr uint32_t PRE_CHECK_FLAG_NONE = 0; 34 constexpr uint32_t PRE_CHECK_FLAG_CALLED_WITHIN_THE_BUNDLE = 1 << 0; 35 constexpr uint32_t PRE_CHECK_FLAG_MULTIPLE_PROCESSES = 1 << 1; 36 struct ExtensionRecordConfig { 37 uint32_t processModeDefault = PROCESS_MODE_BUNDLE; 38 uint32_t processModeSupport = PROCESS_MODE_SUPPORT_DEFAULT; 39 uint32_t preCheckFlag = PRE_CHECK_FLAG_NONE; 40 }; 41 42 class ExtensionRecordFactory : public std::enable_shared_from_this<ExtensionRecordFactory> { 43 public: 44 ExtensionRecordFactory(); 45 46 virtual ~ExtensionRecordFactory(); 47 48 /** 49 * @brief Check whether the existing extensionRecord needs to be reused. 50 * 51 * @param abilityRequest Indicates the request of the extension ability to start. 52 * @param extensionRecordId Indicates the ID of the reused extension record. 53 * @return bool Returns true if the extension record need to be reused. 54 */ 55 virtual bool NeedReuse(const AAFwk::AbilityRequest &abilityRequest, int32_t &extensionRecordId); 56 57 /** 58 * @brief Check the request of the extension ability to start. 59 * 60 * @param abilityRequest Indicates the request of the extension ability to start. 61 * @param hostBundleName Indicates the bundle name of the host. 62 * @return int32_t Returns ERR_OK on success, others on failure. 63 */ 64 virtual int32_t PreCheck(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName); 65 66 /** 67 * @brief Create extension record based on the abilityRequest. 68 * 69 * @param abilityRequest Indicates the request of the extension ability to start. 70 * @param extensionRecord Indicates the created extension record. 71 * @return int32_t Returns ERR_OK on success, others on failure. 72 */ 73 virtual int32_t CreateRecord( 74 const AAFwk::AbilityRequest &abilityRequest, std::shared_ptr<ExtensionRecord> &extensionRecord); 75 76 protected: 77 uint32_t GetExtensionProcessMode(const AAFwk::AbilityRequest &abilityRequest, bool &isHostSpecified); 78 }; 79 } // namespace AbilityRuntime 80 } // namespace OHOS 81 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_FACTORY_H 82