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 FILE_ACCESS_EXT_CONNECTION_H 17 #define FILE_ACCESS_EXT_CONNECTION_H 18 19 #include <atomic> 20 #include <mutex> 21 22 #include "ability_connect_callback_stub.h" 23 #include "element_name.h" 24 #include "ifile_access_ext_base.h" 25 #include "iremote_object.h" 26 #include "refbase.h" 27 #include "want.h" 28 29 namespace OHOS { 30 namespace FileAccessFwk { 31 class FileAccessExtConnection : public AAFwk::AbilityConnectionStub { 32 public: 33 FileAccessExtConnection() = default; 34 virtual ~FileAccessExtConnection() = default; 35 36 void OnAbilityConnectDone( 37 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override; 38 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 39 void ConnectFileExtAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &token); 40 void DisconnectFileExtAbility(); 41 bool IsExtAbilityConnected(); 42 sptr<IFileAccessExtBase> GetFileExtProxy(); 43 44 private: 45 struct ThreadLockInfo { 46 std::condition_variable condition; 47 std::mutex mutex; 48 bool isReady = false; 49 }; 50 ThreadLockInfo connectLockInfo_; 51 52 static std::mutex mutex_; 53 std::atomic<bool> isConnected_ = {false}; 54 sptr<IFileAccessExtBase> fileExtProxy_; 55 }; 56 } // namespace FileAccessFwk 57 } // namespace OHOS 58 #endif // FILE_ACCESS_EXT_CONNECTION_H 59