/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_APP_CONTEXT_H #define OHOS_ABILITY_RUNTIME_APP_CONTEXT_H #include "context_container.h" namespace OHOS { namespace AppExecFwk { class AppContext : public ContextContainer, public std::enable_shared_from_this { public: AppContext(); virtual ~AppContext(); /** * @brief Obtains information about the current ability. * The returned information includes the class name, bundle name, and other information about the current ability. * * @return Returns the AbilityInfo object for the current ability. */ const std::shared_ptr GetAbilityInfo() override; /** * @brief Starts a new ability. * An ability using the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE template uses this method * to start a specific ability. The system locates the target ability from installed abilities based on the value * of the want parameter and then starts it. You can specify the ability to start using the want parameter. * * @param want Indicates the Want containing information about the target ability to start. * * @param requestCode Indicates the request code returned after the ability using the AbilityInfo.AbilityType.PAGE * template is started. You can define the request code to identify the results returned by abilities. The value * ranges from 0 to 65535. This parameter takes effect only on abilities using the AbilityInfo.AbilityType.PAGE * template. * * @return errCode ERR_OK on success, others on failure. */ ErrCode StartAbility(const AAFwk::Want &want, int requestCode) override; /** * @brief Starts a new ability with special ability start setting. * * @param want Indicates the Want containing information about the target ability to start. * @param requestCode Indicates the request code returned after the ability is started. You can define the request * code to identify the results returned by abilities. The value ranges from 0 to 65535. * @param abilityStartSetting Indicates the special start setting used in starting ability. * * @return errCode ERR_OK on success, others on failure. */ ErrCode StartAbility(const Want &want, int requestCode, const AbilityStartSetting &abilityStartSetting) override; /** * @brief Destroys the current ability. * * @return errCode ERR_OK on success, others on failure. */ ErrCode TerminateAbility() override; /** * @brief Obtains the bundle name of the ability that called the current ability. * You can use the obtained bundle name to check whether the calling ability is allowed to receive the data you will * send. If you did not use Ability.startAbilityForResult(ohos.aafwk.content.Want, int, * ohos.aafwk.ability.startsetting.AbilityStartSetting) to start the calling ability, null is returned. * * @return Returns the bundle name of the calling ability; returns null if no calling ability is available. */ std::string GetCallingBundle() override; /** * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. * * @param want Indicates the want containing information about the ability to connect * * @param conn Indicates the callback object when the target ability is connected. * * @return True means success and false means failure */ bool ConnectAbility(const Want &want, const sptr &conn) override; /** * @brief Disconnects the current ability from an ability * * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities. * * @return errCode ERR_OK on success, others on failure. */ ErrCode DisconnectAbility(const sptr &conn) override; /** * @brief Destroys another ability that uses the AbilityInfo.AbilityType.SERVICE template. * The current ability using either the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE * template can call this method to destroy another ability that uses the AbilityInfo.AbilityType.SERVICE * template. The current ability itself can be destroyed by calling the terminateAbility() method. * * @param want Indicates the Want containing information about the ability to destroy. * * @return Returns true if the ability is destroyed successfully; returns false otherwise. */ bool StopAbility(const AAFwk::Want &want) override; /** * @brief Starts multiple abilities. * * @param wants Indicates the Want containing information array about the target ability to start. */ void StartAbilities(const std::vector &wants) override; /** * @brief Obtains the unique ID of the mission containing this ability. * * @return Returns the unique mission ID. */ int GetMissionId() override; protected: sptr GetToken() override; std::mutex mutex_; }; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_APP_CONTEXT_H