1 /* 2 * Copyright (c) 2023 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_SERVICE_EXTENSION_H 17 #define OHOS_ABILITY_RUNTIME_SERVICE_EXTENSION_H 18 19 #include "extension_base.h" 20 21 namespace OHOS { 22 namespace NetManagerStandard { 23 using namespace AbilityRuntime; 24 class VpnExtensionContext; 25 class VpnExtension; 26 using CreatorFunc = std::function<VpnExtension* (const std::unique_ptr<Runtime>& runtime)>; 27 /** 28 * @brief Basic vpn components. 29 */ 30 class VpnExtension : public ExtensionBase<VpnExtensionContext> { 31 public: 32 VpnExtension() = default; 33 virtual ~VpnExtension() = default; 34 35 /** 36 * @brief Create and init context. 37 * 38 * @param record the extension record. 39 * @param application the application info. 40 * @param handler the extension handler. 41 * @param token the remote token. 42 * @return The created context. 43 */ 44 virtual std::shared_ptr<VpnExtensionContext> CreateAndInitContext( 45 const std::shared_ptr<AbilityLocalRecord> &record, 46 const std::shared_ptr<OHOSApplication> &application, 47 std::shared_ptr<AbilityHandler> &handler, 48 const sptr<IRemoteObject> &token) override; 49 50 /** 51 * @brief Init the extension. 52 * 53 * @param record the extension record. 54 * @param application the application info. 55 * @param handler the extension handler. 56 * @param token the remote token. 57 */ 58 virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record, 59 const std::shared_ptr<OHOSApplication> &application, 60 std::shared_ptr<AbilityHandler> &handler, 61 const sptr<IRemoteObject> &token) override; 62 63 /** 64 * @brief Create Extension. 65 * 66 * @param runtime The runtime. 67 * @return The VpnExtension instance. 68 */ 69 static VpnExtension* Create(const std::unique_ptr<OHOS::AbilityRuntime::Runtime>& runtime); 70 71 /** 72 * @brief Set a creator function. 73 * 74 * @param creator The function for create a vpn-extension ability. 75 */ 76 static void SetCreator(const CreatorFunc& creator); 77 78 /** 79 * @brief Called when the system configuration is updated. 80 * 81 * @param configuration Indicates the updated configuration information. 82 */ 83 void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; 84 85 private: 86 static CreatorFunc creator_; 87 }; 88 } // namespace NetManagerStandard 89 } // namespace OHOS 90 #endif // OHOS_ABILITY_RUNTIME_SERVICE_EXTENSION_H 91