• 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     int32_t GetDiskSN(std::string& result);
34 
35     void FinishStartSASuccess(const sptr<IRemoteObject> &remoteObject);
36     void FinishStartSAFailed();
37     void ResetService(const wptr<IRemoteObject> &remote);
38 private:
39     // For death event procession
40     class DeathRecipient final : public IRemoteObject::DeathRecipient {
41     public:
42         DeathRecipient(void) = default;
43         ~DeathRecipient(void) final = default;
44         DISALLOW_COPY_AND_MOVE(DeathRecipient);
45         void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
46     };
GetDeathRecipient(void)47     sptr<IRemoteObject::DeathRecipient> GetDeathRecipient(void)
48     {
49         return deathRecipient_;
50     }
51 
52     void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock);
53     sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock);
54     std::mutex lock_;
55     std::condition_variable deviceInfoLoadCon_;
56     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
57     sptr<IDeviceInfo> deviceInfoService_ {};
58     sptr<IDeviceInfo> RetryGetService(std::unique_lock<std::mutex> &lock);
59 };
60 } // namespace device_info
61 } // namespace OHOS
62 
63 #ifndef DINFO_DOMAIN
64 #define DINFO_DOMAIN (BASE_DOMAIN + 8)
65 #endif
66 
67 #ifndef DINFO_TAG
68 #define DINFO_TAG "DeviceInfoKits"
69 #endif
70 
71 #define DINFO_LOGI(fmt, ...) STARTUP_LOGI(DINFO_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
72 #define DINFO_LOGE(fmt, ...) STARTUP_LOGE(DINFO_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
73 #define DINFO_LOGV(fmt, ...) STARTUP_LOGV(DINFO_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
74 
75 #define DINFO_CHECK(ret, exper, ...) \
76     if (!(ret)) { \
77         DINFO_LOGE(__VA_ARGS__); \
78         exper; \
79     }
80 #define DINFO_ONLY_CHECK(ret, exper, ...) \
81     if (!(ret)) { \
82         exper; \
83     }
84 
85 #endif // OHOS_SYSTEM_DEVICE_ID_KITS_S
86