1 /* 2 * Copyright (c) 2022 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 PRINT_EXTENSION_CONTEXT_H 17 #define PRINT_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 AbilityRuntime { 27 /** 28 * @brief context supply for Print 29 * 30 */ 31 class PrintExtensionContext : public ExtensionContext { 32 public: 33 PrintExtensionContext() = default; 34 virtual ~PrintExtensionContext() = default; 35 36 /** 37 * @brief Starts a new ability. 38 * An ability using the AbilityInfo.AbilityType.Print or AbilityInfo.AbilityType.PAGE template uses this method 39 * to start a specific ability. The system locates the target ability from installed abilities based on the value 40 * of the want parameter and then starts it. You can specify the ability to start using the want parameter. 41 * 42 * @param want Indicates the Want containing information about the target ability to start. 43 * 44 * @return errCode ERR_OK on success, others on failure. 45 */ 46 ErrCode StartAbility(const AAFwk::Want &want) const; 47 48 ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const; 49 50 /** 51 * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.Print template. 52 * 53 * @param want Indicates the want containing information about the ability to connect 54 * 55 * @param conn Indicates the callback object when the target ability is connected. 56 * 57 * @return True means success and false means failure 58 */ 59 bool ConnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const; 60 61 /** 62 * @brief Starts a new ability. 63 * An ability using the AbilityInfo.AbilityType.Print or AbilityInfo.AbilityType.PAGE template uses this method 64 * to start a specific ability. The system locates the target ability from installed abilities based on the value 65 * of the want parameter and then starts it. You can specify the ability to start using the want parameter. 66 * 67 * @param want Indicates the Want containing information about the target ability to start. 68 * @param accountId caller user. 69 * 70 * @return errCode ERR_OK on success, others on failure. 71 */ 72 ErrCode StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const; 73 74 ErrCode StartAbilityWithAccount( 75 const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const; 76 77 /** 78 * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.Print template. 79 * 80 * @param want Indicates the want containing information about the ability to connect. 81 * 82 * @param accountId caller user. 83 * 84 * @param conn Indicates the callback object when the target ability is connected. 85 * 86 * @return True means success and false means failure. 87 */ 88 bool ConnectAbilityWithAccount( 89 const AAFwk::Want &want, int accountId, const sptr<AbilityConnectCallback> &connectCallback) const; 90 91 /** 92 * @brief Disconnects the current ability from an ability. 93 * 94 * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection 95 * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities. 96 * 97 * @return errCode ERR_OK on success, others on failure. 98 */ 99 ErrCode DisconnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const; 100 101 /** 102 * @brief Destroys the current ability. 103 * 104 * @return errCode ERR_OK on success, others on failure. 105 */ 106 ErrCode TerminateAbility(); 107 108 using SelfType = PrintExtensionContext; 109 static const size_t CONTEXT_TYPE_ID; 110 111 protected: IsContext(size_t contextTypeId)112 bool IsContext(size_t contextTypeId) override 113 { 114 return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); 115 } 116 117 private: 118 static int ILLEGAL_REQUEST_CODE; 119 120 /** 121 * @brief Get Current Ability Type 122 * 123 * @return Current Ability Type 124 */ 125 OHOS::AppExecFwk::AbilityType GetAbilityInfoType() const; 126 }; 127 } // namespace AbilityRuntime 128 } // namespace OHOS 129 #endif // PRINT_EXTENSION_CONTEXT_H