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_DISTRIBUTED_EXTENSION_CONTEXT_H 17 #define OHOS_DISTRIBUTED_EXTENSION_CONTEXT_H 18 19 #include "ability_connect_callback.h" 20 #include "connection_manager.h" 21 #include "extension_context.h" 22 #include "start_options.h" 23 #include "want.h" 24 25 namespace OHOS { 26 namespace DistributedSchedule { 27 using namespace AbilityRuntime; 28 class DistributedExtensionContext : public AbilityRuntime::ExtensionContext { 29 public: DistributedExtensionContext()30 DistributedExtensionContext() {}; 31 ~DistributedExtensionContext() override = default; 32 33 static inline size_t CONTEXT_TYPE_ID = std::hash<const char *> {}("distributedExtensionContext"); 34 35 /** 36 * @brief Connects the current ability to an ability using the 37 * AbilityInfo.AbilityType.INPUTMETHOD template. 38 * 39 * @param want Indicates the want containing information about the ability to 40 * connect 41 * 42 * @param conn Indicates the callback object when the target ability is 43 * connected. 44 * 45 * @return True means success and false means failure 46 */ 47 bool ConnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const; 48 49 /** 50 * @brief Disconnects the current ability from an ability. 51 * 52 * @param conn Indicates the IAbilityConnection callback object passed by 53 * connectAbility after the connection is set up. The IAbilityConnection 54 * 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) const; 59 60 protected: IsContext(size_t contextTypeId)61 bool IsContext(size_t contextTypeId) override 62 { 63 return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); 64 } 65 }; 66 } 67 } 68 69 #endif // OHOS_DISTRIBUTED_EXTENSION_CONTEXT_H 70