1 /* 2 * Copyright (c) 2023-2024 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_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H 17 #define OHOS_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "ability_manager_client.h" 23 #include "ability_connect_callback_stub.h" 24 #include "want.h" 25 26 #include "i_appgallery_service.h" 27 28 namespace OHOS::FileManagement::Backup { 29 using namespace OHOS::AppExecFwk; 30 31 class AppGalleryConnection : public AbilityConnectionStub { 32 public: AppGalleryConnection(int32_t userId)33 AppGalleryConnection(int32_t userId) : userId(userId) {} 34 35 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 36 int resultCode); 37 38 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode); 39 40 bool ConnectExtAbility(std::string abilityName); 41 42 sptr<IRemoteObject> GetRemoteObj(); 43 44 private: 45 int32_t userId = 0; 46 std::mutex conditionMutex_; 47 std::condition_variable conditionVal_; 48 std::mutex connectMutex; 49 std::mutex appRemoteObjLock_; 50 sptr<IRemoteObject> appRemoteObj_; 51 }; 52 } // namespace OHOS::FileManagement::Backup 53 #endif // OHOS_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H