1 /* 2 * Copyright (c) 2023-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_EXTENSION_MANAGER_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_EXTENSION_MANAGER_CLIENT_H 18 19 #include <mutex> 20 21 #include "extension_manager_interface.h" 22 #include "iremote_object.h" 23 24 namespace OHOS { 25 namespace AAFwk { 26 /** 27 * @class ExtensionManagerClient 28 * ExtensionManagerClient is used to access ability manager services. 29 */ 30 class ExtensionManagerClient { 31 public: 32 ExtensionManagerClient() = default; 33 virtual ~ExtensionManagerClient() = default; 34 static ExtensionManagerClient& GetInstance(); 35 36 ErrCode ConnectServiceExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect, int32_t userId); 37 38 ErrCode ConnectServiceExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect, 39 const sptr<IRemoteObject> &callerToken, int32_t userId); 40 41 ErrCode ConnectEnterpriseAdminExtensionAbility(const Want &want, 42 const sptr<IRemoteObject> &connect, const sptr<IRemoteObject> &callerToken, int32_t userId); 43 44 /** 45 * Connect extension ability. 46 * 47 * @param want special want for the extension ability. 48 * @param connect callback used to notify caller the result of connecting. 49 * @param userId the extension runs in. 50 * @return Returns ERR_OK on success, others on failure. 51 */ 52 ErrCode ConnectExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect, 53 int32_t userId = DEFAULT_INVALID_USER_ID); 54 55 /** 56 * Disconnect session with extension ability. 57 * 58 * @param connect Callback used to notify caller the result of disconnecting. 59 * @return Returns ERR_OK on success, others on failure. 60 */ 61 ErrCode DisconnectAbility(const sptr<IRemoteObject> &connect); 62 63 ErrCode Release(); 64 65 /** 66 * @brief Get the extension running information. 67 * 68 * @param upperLimit The maximum limit of information wish to get. 69 * @param info Extension running information. 70 * @return Returns ERR_OK on success, others on failure. 71 */ 72 ErrCode GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info); 73 74 /** 75 * Transfer resultCode & want to abms. 76 * 77 * @param callerToken caller ability token. 78 * @param requestCode the resultCode of the ability to start. 79 * @param want Indicates the ability to start. 80 * @return Returns ERR_OK on success, others on failure. 81 */ 82 int32_t TransferAbilityResultForExtension(const sptr<IRemoteObject> &callerToken, int32_t resultCode, 83 const Want &want); 84 private: 85 class ExtensionMgrDeathRecipient : public IRemoteObject::DeathRecipient { 86 public: 87 ExtensionMgrDeathRecipient() = default; 88 ~ExtensionMgrDeathRecipient() = default; 89 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 90 private: 91 DISALLOW_COPY_AND_MOVE(ExtensionMgrDeathRecipient); 92 }; 93 94 sptr<IExtensionManager> GetExtensionManager(); 95 void Connect(); 96 void ResetProxy(const wptr<IRemoteObject> &remote); 97 ErrCode RemoveDeathRecipient(); 98 99 std::mutex mutex_; 100 sptr<IExtensionManager> proxy_; 101 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 102 }; 103 } // namespace AAFwk 104 } // namespace OHOS 105 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_MANAGER_CLIENT_H 106