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_FORM_FWK_FORM_RENDER_SERVICE_EXTENSION_H 17 #define OHOS_ABILITY_FORM_FWK_FORM_RENDER_SERVICE_EXTENSION_H 18 19 #include "configuration.h" 20 #include "service_extension.h" 21 #include "runtime.h" 22 23 namespace OHOS { 24 namespace AbilityRuntime { 25 /** 26 * @brief FormRenderService, for ets form. 27 */ 28 class FormRenderServiceExtension : public ServiceExtension, 29 public std::enable_shared_from_this<FormRenderServiceExtension> { 30 public: 31 explicit FormRenderServiceExtension(Runtime &runtime); 32 ~FormRenderServiceExtension() override; 33 34 /** 35 * @brief Create FormRenderServiceExtension. 36 * 37 * @param runtime The runtime. 38 * @return The FormRenderServiceExtension instance. 39 */ 40 static FormRenderServiceExtension* Create(const std::unique_ptr<Runtime> &runtime); 41 42 /** 43 * @brief Init the extension. 44 * 45 * @param record the extension record. 46 * @param application the application info. 47 * @param handler the extension handler. 48 * @param token the remote token. 49 */ 50 void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record, 51 const std::shared_ptr<AppExecFwk::OHOSApplication> &application, 52 std::shared_ptr<AppExecFwk::AbilityHandler> &handler, 53 const sptr<IRemoteObject> &token) override; 54 55 /** 56 * @brief Called when this extension is started. You must override this function if you want to perform some 57 * initialization operations during extension startup. 58 * 59 * This function can be called only once in the entire lifecycle of an extension. 60 * @param Want Indicates the {@link Want} structure containing startup information about the extension. 61 */ 62 void OnStart(const AAFwk::Want &want) override; 63 64 /** 65 * @brief Called when this Service extension is connected for the first time. 66 * 67 * You can override this function to implement your own processing logic. 68 * 69 * @param want Indicates the {@link Want} structure containing connection information about the Service extension. 70 * @return Returns a pointer to the <b>sid</b> of the connected Service extension. 71 */ 72 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 73 74 /** 75 * @brief Called when this Service extension is connected for the first time. 76 * 77 * You can override this function to implement your own processing logic. 78 * 79 * @param want Indicates the {@link Want} structure containing connection information about the Service extension. 80 * @param callbackInfo Indicates the lifecycle transaction callback information 81 * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback 82 * @return Returns a pointer to the <b>sid</b> of the connected Service extension. 83 */ 84 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want, 85 AppExecFwk::AbilityTransactionCallbackInfo<sptr<IRemoteObject>> *callbackInfo, bool &isAsyncCallback) override; 86 87 /** 88 * @brief Called when all abilities connected to this Service extension are disconnected. 89 * 90 * You can override this function to implement your own processing logic. 91 * 92 */ 93 void OnDisconnect(const AAFwk::Want &want) override; 94 95 /** 96 * @brief Called when all abilities connected to this Service extension are disconnected. 97 * 98 * You can override this function to implement your own processing logic. 99 * @param callbackInfo Indicates the lifecycle transaction callback information 100 * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback 101 */ 102 void OnDisconnect(const AAFwk::Want &want, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, 103 bool &isAsyncCallback) override; 104 105 /** 106 * @brief Called back when Service is started. 107 * This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start 108 * Service. Then the system calls back the current method to use the transferred want parameter to execute its own 109 * logic. 110 * 111 * @param want Indicates the want of Service to start. 112 * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being 113 * destroyed, and the value false indicates a normal startup. 114 * @param startId Indicates the number of times the Service extension has been started. The startId is incremented 115 * by 1 every time the extension is started. For example, if the extension has been started for six times, the 116 * value of startId is 6. 117 */ 118 void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; 119 120 /** 121 * @brief Called when this extension enters the <b>STATE_STOP</b> state. 122 * 123 * The extension in the <b>STATE_STOP</b> is being destroyed. 124 * You can override this function to implement your own processing logic. 125 */ 126 void OnStop() override; 127 128 /** 129 * @brief Called when the system configuration is updated. 130 * 131 * @param configuration Indicates the updated configuration information. 132 */ 133 void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override; 134 135 private: 136 void GetSrcPath(std::string &srcPath); 137 138 Runtime& runtime_; 139 }; 140 } // namespace AbilityRuntime 141 } // namespace OHOS 142 #endif // OHOS_ABILITY_FORM_FWK_FORM_RENDER_SERVICE_EXTENSION_H 143