• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t ResetOAID();
54 
55     /**
56      * RegisterObserver
57      */
58     int32_t RegisterObserver(const sptr<IRemoteConfigObserver>& observer);
59 
60     void OnRemoteSaDied(const wptr<IRemoteObject>& object);
61 
62     void LoadServerFail();
63 
64     void LoadServerSuccess(const sptr<IRemoteObject>& remoteObject);
65 
66 private:
67     OAIDServiceClient();
68     virtual ~OAIDServiceClient() override;
69     static std::mutex instanceLock_;
70     static sptr<OAIDServiceClient> instance_;
71 
72     bool LoadService();
73     bool loadServiceReady_ = false;
74     std::mutex loadServiceLock_;
75     std::condition_variable loadServiceCondition_;
76     std::mutex loadServiceConditionLock_;
77     std::mutex getOaidProxyMutex_;
78 
79     sptr<IOAIDService> oaidServiceProxy_;
80     sptr<OAIDSaDeathRecipient> deathRecipient_;
81 };
82 } // namespace Cloud
83 } // namespace OHOS
84 #endif // OHOS_CLOUD_OAID_SERVICE_CLIENT_H