• 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 #include "ipc_skeleton.h"
26 #include "iremote_stub.h"
27 #include "accesstoken_kit.h"
28 #include "config_policy_utils.h"
29 #include "privacy_kit.h"
30 #include "tokenid_kit.h"
31 
32 namespace OHOS {
33 namespace Cloud {
34 class OAIDSaDeathRecipient : public IRemoteObject::DeathRecipient {
35 public:
36     explicit OAIDSaDeathRecipient();
37     virtual ~OAIDSaDeathRecipient() override = default;
38     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
39 
40 private:
41     DISALLOW_COPY_AND_MOVE(OAIDSaDeathRecipient);
42 };
43 
44 class OAIDServiceClient : public RefBase {
45 public:
46     DISALLOW_COPY_AND_MOVE(OAIDServiceClient);
47     static sptr<OAIDServiceClient> GetInstance();
48 
49     /**
50      * Get open advertising id.
51      *
52      * @return std::string, OAID.
53      */
54     std::string GetOAID();
55 
56     /**
57      * Reset open advertising id.
58      */
59     int32_t ResetOAID();
60 
61     /**
62      * RegisterObserver
63      */
64     int32_t RegisterObserver(const sptr<IRemoteConfigObserver>& observer);
65 
66     void OnRemoteSaDied(const wptr<IRemoteObject>& object);
67 
68     void LoadServerFail();
69 
70     void LoadServerSuccess(const sptr<IRemoteObject>& remoteObject);
71 
72 private:
73     OAIDServiceClient();
74     virtual ~OAIDServiceClient() override;
75     static std::mutex instanceLock_;
76     static sptr<OAIDServiceClient> instance_;
77 
78     bool LoadService();
79     bool loadServiceReady_ = false;
80     std::mutex loadServiceLock_;
81     std::condition_variable loadServiceCondition_;
82     std::mutex loadServiceConditionLock_;
83     std::mutex getOaidProxyMutex_;
84 
85     sptr<IOAIDService> oaidServiceProxy_;
86     sptr<OAIDSaDeathRecipient> deathRecipient_;
87     bool CheckPermission(const std::string &permissionName);
88 };
89 } // namespace Cloud
90 } // namespace OHOS
91 #endif // OHOS_CLOUD_OAID_SERVICE_CLIENT_H