1 /* 2 * Copyright (c) 2025 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_APP_SERVICE_EXTENSION_CONTEXT_H 17 #define OHOS_ABILITY_RUNTIME_APP_SERVICE_EXTENSION_CONTEXT_H 18 19 #include "extension_context.h" 20 #include "ability_connect_callback.h" 21 #include "connection_manager.h" 22 #include "free_install_observer_interface.h" 23 #include "local_call_container.h" 24 #include "start_options.h" 25 #include "want.h" 26 27 namespace OHOS { 28 namespace AbilityRuntime { 29 /** 30 * @brief context supply for service 31 * 32 */ 33 class AppServiceExtensionContext : public ExtensionContext { 34 public: 35 AppServiceExtensionContext() = default; 36 virtual ~AppServiceExtensionContext() = default; 37 38 /** 39 * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. 40 * 41 * @param want Indicates the want containing information about the ability to connect 42 * 43 * @param conn Indicates the callback object when the target ability is connected. 44 * 45 * @return Returns zero on success, others on failure. 46 */ 47 ErrCode ConnectAbility( 48 const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const; 49 50 /** 51 * @brief Disconnects the current ability from an ability. 52 * 53 * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection 54 * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities. 55 * 56 * @return errCode ERR_OK on success, others on failure. 57 */ 58 ErrCode DisconnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback, 59 int32_t accountId = -1) const; 60 61 /** 62 * @brief Starts an ability. 63 * 64 * @param want Indicates the want containing information about the ability to start. 65 * 66 * @return Returns zero on success, others on failure. 67 */ 68 ErrCode StartAbility(const AAFwk::Want &want) const; 69 70 /** 71 * @brief Starts an ability. 72 * 73 * @param want Indicates the want containing information about the ability to start. 74 * 75 * @param startOptions Indicates the start options for the ability to start. 76 * 77 * @return Returns zero on success, others on failure. 78 */ 79 ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const; 80 81 /** 82 * @brief Destroys the current ability. 83 * 84 * @return errCode ERR_OK on success, others on failure. 85 */ 86 ErrCode TerminateSelf(); 87 }; 88 } // namespace AbilityRuntime 89 } // namespace OHOS 90 #endif // OHOS_ABILITY_RUNTIME_APP_SERVICE_EXTENSION_CONTEXT_H