1 /* 2 * Copyright (c) 2021-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 FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H 17 #define FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H 18 19 #include "extension.h" 20 #include "lifecycle_state_info.h" 21 22 namespace OHOS { 23 class IRemoteObject; 24 namespace AAFwk { 25 class Want; 26 } 27 namespace AppExecFwk { 28 struct AbilityInfo; 29 class OHOSApplication; 30 class AbilityHandler; 31 class AbilityLocalRecord; 32 } 33 namespace AbilityRuntime { 34 /** 35 * @brief Responsible for managing and scheduling the life cycle of extension. 36 */ 37 class ExtensionImpl : public std::enable_shared_from_this<ExtensionImpl> { 38 public: 39 ExtensionImpl() = default; 40 virtual ~ExtensionImpl() = default; 41 42 /** 43 * @brief Init the object. 44 * 45 * @param application the application info. 46 * @param record the extension record. 47 * @param extension the extension object. 48 * @param handler the extension handler. 49 * @param token the remote token. 50 */ 51 void Init(std::shared_ptr<AppExecFwk::OHOSApplication> &application, 52 const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record, 53 std::shared_ptr<Extension> &extension, 54 std::shared_ptr<AppExecFwk::AbilityHandler> &handler, const sptr<IRemoteObject> &token); 55 56 /** 57 * @brief Connect the Extension. and Calling information back to Extension. 58 * 59 * @param want The Want object to connect to. 60 * @param targetState The terget state. 61 * 62 */ 63 virtual void HandleExtensionTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState); 64 65 /** 66 * @brief scheduling update configuration of extension. 67 * 68 * @param config Configuration 69 */ 70 void ScheduleUpdateConfiguration(const AppExecFwk::Configuration &config); 71 72 /** 73 * @brief Connect the Extension. and Calling information back to Extension. 74 * 75 * @param want The Want object to connect to. 76 * 77 */ 78 sptr<IRemoteObject> ConnectExtension(const Want &want); 79 80 /** 81 * @brief Disconnects the connected object. 82 * 83 * @param want The Want object to disconnect to. 84 */ 85 void DisconnectExtension(const Want &want); 86 87 /** 88 * @brief Command the Extension. and Calling information back to Extension. 89 * 90 * @param want The Want object to command to. 91 * 92 * * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being 93 * destroyed, and the value false indicates a normal startup. 94 * 95 * @param startId Indicates the number of times the Service Extension has been started. The startId is incremented 96 * by 1 every time the Extension is started. For example, if the Extension has been started for six times, the value 97 * of startId is 6. 98 */ 99 void CommandExtension(const Want &want, bool restart, int startId); 100 protected: 101 /** 102 * @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application 103 * that it belongs to of the lifecycle status. 104 * 105 * @param want The Want object to switch the life cycle. 106 */ 107 void Start(const Want &want); 108 109 /** 110 * @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INITIAL. And notifies the application 111 * that it belongs to of the lifecycle status. 112 * 113 */ 114 void Stop(); 115 116 int lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; 117 sptr<IRemoteObject> token_; 118 std::shared_ptr<Extension> extension_; 119 }; 120 } 121 } 122 #endif // FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H