1 /* 2 * Copyright (c) 2021 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_BASE_H 17 #define OHOS_ABILITY_RUNTIME_EXTENSION_BASE_H 18 19 #include <string> 20 21 #include "ability_local_record.h" 22 #include "extension.h" 23 #include "extension_common.h" 24 #include "iremote_object.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 class OHOSApplication; 29 class AbilityHandler; 30 } 31 namespace AbilityRuntime { 32 using namespace OHOS::AppExecFwk; 33 class ExtensionContext; 34 /** 35 * @brief The ExtensionBase class for all extensions. 36 */ 37 template<class C = ExtensionContext> 38 class ExtensionBase : public Extension { 39 public: 40 ExtensionBase() = default; 41 virtual ~ExtensionBase() = default; 42 43 /** 44 * @brief Init the extension. 45 * 46 * @param record the extension record. 47 * @param application the application info. 48 * @param handler the extension handler. 49 * @param token the remote token. 50 */ 51 virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record, 52 const std::shared_ptr<OHOSApplication> &application, 53 std::shared_ptr<AbilityHandler> &handler, 54 const sptr<IRemoteObject> &token) override; 55 56 /** 57 * @brief Create and init context. 58 * 59 * @param record the extension record. 60 * @param application the application info. 61 * @param handler the extension handler. 62 * @param token the remote token. 63 * @return The created context. 64 */ 65 virtual std::shared_ptr<C> CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> &record, 66 const std::shared_ptr<OHOSApplication> &application, 67 std::shared_ptr<AbilityHandler> &handler, 68 const sptr<IRemoteObject> &token); 69 70 /** 71 * @brief Get context. 72 * 73 * @return The context object. 74 */ 75 virtual std::shared_ptr<C> GetContext(); 76 77 /** 78 * @brief Called when the system configuration is updated. 79 * 80 * @param configuration Indicates the updated configuration information. 81 */ 82 virtual void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; 83 84 /** 85 * @brief Notify current memory level. 86 * 87 * @param level Current memory level. 88 */ 89 virtual void OnMemoryLevel(int level) override; 90 91 void SetExtensionCommon(const std::shared_ptr<ExtensionCommon> &common); 92 private: 93 std::shared_ptr<C> context_ = nullptr; 94 std::shared_ptr<ExtensionCommon> extensionCommon_ = nullptr; 95 }; 96 } // namespace AbilityRuntime 97 } // namespace OHOS 98 #include "extension_base.inl" 99 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_BASE_H 100