1 /* 2 * Copyright (c) 2023 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 DATA_PROXY_AMS_PROXY_H 17 #define DATA_PROXY_AMS_PROXY_H 18 19 #include <memory> 20 #include <string> 21 22 #include "extension_manager_proxy.h" 23 namespace OHOS::DataShare { 24 class AmsMgrProxy { 25 public: 26 ~AmsMgrProxy(); 27 static AmsMgrProxy* GetInstance(); 28 int Connect(const std::string &uri, const sptr<IRemoteObject> &connect, const sptr<IRemoteObject> &callerToken); 29 int DisConnect(sptr<IRemoteObject> connect); 30 private: 31 using Proxy = AAFwk::ExtensionManagerProxy; 32 AmsMgrProxy() = default; 33 class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { 34 public: ServiceDeathRecipient(AmsMgrProxy * owner)35 explicit ServiceDeathRecipient(AmsMgrProxy* owner) : owner_(owner) 36 { 37 } OnRemoteDied(const wptr<IRemoteObject> & object)38 void OnRemoteDied(const wptr<IRemoteObject> &object) override 39 { 40 if (owner_ != nullptr) { 41 owner_->OnProxyDied(); 42 } 43 } 44 45 private: 46 AmsMgrProxy* owner_; 47 }; 48 void OnProxyDied(); 49 bool ConnectSA(); 50 static std::mutex pmutex_; 51 std::mutex mutex_; 52 sptr<IRemoteObject> sa_; 53 sptr<Proxy> proxy_; 54 sptr<AmsMgrProxy::ServiceDeathRecipient> deathRecipient_; 55 }; 56 } // namespace OHOS::DataShare 57 #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H 58