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 RUST_PROJ_MOCK_CONNECT_H 17 #define RUST_PROJ_MOCK_CONNECT_H 18 19 #include <mutex> 20 #include <condition_variable> 21 #include "ability_connect_callback_stub.h" 22 #include "extension_manager_client.h" 23 #include "extension_manager_proxy.h" 24 #include "iservice_registry.h" 25 #include "system_ability_definition.h" 26 #include "iremote_broker.h" 27 28 class Connect : public OHOS::AAFwk::AbilityConnectionStub { 29 public: 30 void OnAbilityConnectDone(const OHOS::AppExecFwk::ElementName &element, 31 const OHOS::sptr<OHOS::IRemoteObject> &remoteObject, 32 int resultCode) override; 33 34 void OnAbilityDisconnectDone(const OHOS::AppExecFwk::ElementName &element, 35 int resultCode) override; 36 bool IsConnect(); 37 void WaitConnect(); 38 39 public: 40 OHOS::sptr<OHOS::IRemoteObject> remoteObject_ = nullptr; 41 std::mutex mtx_; 42 std::condition_variable cv_; 43 // Used to avoid wake-up loss 44 bool flag_ = false; 45 static constexpr int32_t CONNECT_TIMEOUT = 5; 46 }; 47 48 namespace ConnectInner { 49 void DoConnect(int userId); 50 OHOS::sptr<OHOS::IRemoteObject> ConnectServiceInner(int userId); 51 } 52 #endif // RUST_PROJ_MOCK_CONNECT_H 53