• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_SYSTEM_DEVICE_ID_KITS_S
17 #define OHOS_SYSTEM_DEVICE_ID_KITS_S
18 #include <mutex>
19 #include "idevice_info.h"
20 #include "singleton.h"
21 #include "beget_ext.h"
22 
23 namespace OHOS {
24 namespace device_info {
25 class INIT_LOCAL_API DeviceInfoKits final : public DelayedRefSingleton<DeviceInfoKits> {
26     DECLARE_DELAYED_REF_SINGLETON(DeviceInfoKits);
27 public:
28     DISALLOW_COPY_AND_MOVE(DeviceInfoKits);
29 
30     static DeviceInfoKits &GetInstance();
31     int32_t GetUdid(std::string& result);
32     int32_t GetSerialID(std::string& result);
33 
34     void FinishStartSASuccess(const sptr<IRemoteObject> &remoteObject);
35     void FinishStartSAFailed();
36     void ResetService(const wptr<IRemoteObject> &remote);
37 private:
38     // For death event procession
39     class DeathRecipient final : public IRemoteObject::DeathRecipient {
40     public:
41         DeathRecipient(void) = default;
42         ~DeathRecipient(void) final = default;
43         DISALLOW_COPY_AND_MOVE(DeathRecipient);
44         void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
45     };
GetDeathRecipient(void)46     sptr<IRemoteObject::DeathRecipient> GetDeathRecipient(void)
47     {
48         return deathRecipient_;
49     }
50 
51     static const int DEVICEINFO_LOAD_SA_TIMEOUT_MS = 60000;
52     void LoadDeviceInfoSa();
53     sptr<IDeviceInfo> GetService();
54     std::mutex lock_;
55     std::condition_variable deviceInfoLoadCon_;
56     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
57     sptr<IDeviceInfo> deviceInfoService_ {};
58 };
59 } // namespace device_info
60 } // namespace OHOS
61 #endif // OHOS_SYSTEM_DEVICE_ID_KITS_S
62