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