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 OHOS_CLOUD_OAID_SERVICE_CLIENT_H 17 #define OHOS_CLOUD_OAID_SERVICE_CLIENT_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "oaid_service_interface.h" 23 #include "iremote_object.h" 24 #include "refbase.h" 25 26 namespace OHOS { 27 namespace Cloud { 28 class OAIDSaDeathRecipient : public IRemoteObject::DeathRecipient { 29 public: 30 explicit OAIDSaDeathRecipient(); 31 virtual ~OAIDSaDeathRecipient() override = default; 32 void OnRemoteDied(const wptr<IRemoteObject>& object) override; 33 34 private: 35 DISALLOW_COPY_AND_MOVE(OAIDSaDeathRecipient); 36 }; 37 38 class OAIDServiceClient : public RefBase { 39 public: 40 DISALLOW_COPY_AND_MOVE(OAIDServiceClient); 41 static sptr<OAIDServiceClient> GetInstance(); 42 43 /** 44 * Get open advertising id. 45 * 46 * @return std::string, OAID. 47 */ 48 std::string GetOAID(); 49 50 /** 51 * Reset open advertising id. 52 */ 53 void ResetOAID(); 54 55 void OnRemoteSaDied(const wptr<IRemoteObject>& object); 56 57 void LoadServerFail(); 58 59 void LoadServerSuccess(const sptr<IRemoteObject>& remoteObject); 60 61 private: 62 OAIDServiceClient(); 63 virtual ~OAIDServiceClient() override; 64 static std::mutex instanceLock_; 65 static sptr<OAIDServiceClient> instance_; 66 67 bool LoadService(); 68 bool loadServiceReady_ = false; 69 std::mutex loadServiceLock_; 70 std::condition_variable loadServiceCondition_; 71 std::mutex loadServiceConditionLock_; 72 73 sptr<IOAIDService> oaidServiceProxy_; 74 sptr<OAIDSaDeathRecipient> deathRecipient_; 75 }; 76 } // namespace Cloud 77 } // namespace OHOS 78 #endif // OHOS_CLOUD_OAID_SERVICE_CLIENT_H