1d9f0492fSopenharmony_ci/*
2d9f0492fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3d9f0492fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d9f0492fSopenharmony_ci * you may not use this file except in compliance with the License.
5d9f0492fSopenharmony_ci * You may obtain a copy of the License at
6d9f0492fSopenharmony_ci *
7d9f0492fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d9f0492fSopenharmony_ci *
9d9f0492fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d9f0492fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d9f0492fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d9f0492fSopenharmony_ci * See the License for the specific language governing permissions and
13d9f0492fSopenharmony_ci * limitations under the License.
14d9f0492fSopenharmony_ci */
15d9f0492fSopenharmony_ci
16d9f0492fSopenharmony_ci#ifndef OHOS_SYSTEM_DEVICE_ID_KITS_S
17d9f0492fSopenharmony_ci#define OHOS_SYSTEM_DEVICE_ID_KITS_S
18d9f0492fSopenharmony_ci#include <mutex>
19d9f0492fSopenharmony_ci#include "idevice_info.h"
20d9f0492fSopenharmony_ci#include "singleton.h"
21d9f0492fSopenharmony_ci#include "beget_ext.h"
22d9f0492fSopenharmony_ci
23d9f0492fSopenharmony_cinamespace OHOS {
24d9f0492fSopenharmony_cinamespace device_info {
25d9f0492fSopenharmony_ciclass INIT_LOCAL_API DeviceInfoKits final : public DelayedRefSingleton<DeviceInfoKits> {
26d9f0492fSopenharmony_ci    DECLARE_DELAYED_REF_SINGLETON(DeviceInfoKits);
27d9f0492fSopenharmony_cipublic:
28d9f0492fSopenharmony_ci    DISALLOW_COPY_AND_MOVE(DeviceInfoKits);
29d9f0492fSopenharmony_ci
30d9f0492fSopenharmony_ci    static DeviceInfoKits &GetInstance();
31d9f0492fSopenharmony_ci    int32_t GetUdid(std::string& result);
32d9f0492fSopenharmony_ci    int32_t GetSerialID(std::string& result);
33d9f0492fSopenharmony_ci
34d9f0492fSopenharmony_ci    void FinishStartSASuccess(const sptr<IRemoteObject> &remoteObject);
35d9f0492fSopenharmony_ci    void FinishStartSAFailed();
36d9f0492fSopenharmony_ci    void ResetService(const wptr<IRemoteObject> &remote);
37d9f0492fSopenharmony_ciprivate:
38d9f0492fSopenharmony_ci    // For death event procession
39d9f0492fSopenharmony_ci    class DeathRecipient final : public IRemoteObject::DeathRecipient {
40d9f0492fSopenharmony_ci    public:
41d9f0492fSopenharmony_ci        DeathRecipient(void) = default;
42d9f0492fSopenharmony_ci        ~DeathRecipient(void) final = default;
43d9f0492fSopenharmony_ci        DISALLOW_COPY_AND_MOVE(DeathRecipient);
44d9f0492fSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
45d9f0492fSopenharmony_ci    };
46d9f0492fSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> GetDeathRecipient(void)
47d9f0492fSopenharmony_ci    {
48d9f0492fSopenharmony_ci        return deathRecipient_;
49d9f0492fSopenharmony_ci    }
50d9f0492fSopenharmony_ci
51d9f0492fSopenharmony_ci    void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock);
52d9f0492fSopenharmony_ci    sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock);
53d9f0492fSopenharmony_ci    std::mutex lock_;
54d9f0492fSopenharmony_ci    std::condition_variable deviceInfoLoadCon_;
55d9f0492fSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
56d9f0492fSopenharmony_ci    sptr<IDeviceInfo> deviceInfoService_ {};
57d9f0492fSopenharmony_ci};
58d9f0492fSopenharmony_ci} // namespace device_info
59d9f0492fSopenharmony_ci} // namespace OHOS
60d9f0492fSopenharmony_ci#endif // OHOS_SYSTEM_DEVICE_ID_KITS_S
61