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
23namespace OHOS {
24namespace device_info {
25class INIT_LOCAL_API DeviceInfoKits final : public DelayedRefSingleton<DeviceInfoKits> {
26    DECLARE_DELAYED_REF_SINGLETON(DeviceInfoKits);
27public:
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);
37private:
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    };
46    sptr<IRemoteObject::DeathRecipient> GetDeathRecipient(void)
47    {
48        return deathRecipient_;
49    }
50
51    void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock);
52    sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock);
53    std::mutex lock_;
54    std::condition_variable deviceInfoLoadCon_;
55    sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
56    sptr<IDeviceInfo> deviceInfoService_ {};
57};
58} // namespace device_info
59} // namespace OHOS
60#endif // OHOS_SYSTEM_DEVICE_ID_KITS_S
61