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_DEVICEIDSTUB_H
17#define OHOS_SYSTEM_DEVICEIDSTUB_H
18
19#include <atomic>
20#include <mutex>
21#include "iremote_stub.h"
22#include "idevice_info.h"
23#include "system_ability.h"
24
25namespace OHOS {
26namespace device_info {
27class DeviceInfoStub : public IRemoteStub<IDeviceInfo> {
28public:
29    explicit DeviceInfoStub(bool serialInvokeFlag = true)
30        : IRemoteStub(serialInvokeFlag), serialInvokeFlag_(serialInvokeFlag) {}
31    int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
32        MessageOption &option) override;
33    bool serialInvokeFlag_ = { true };
34private:
35    bool CheckPermission(MessageParcel &data, const std::string &permission);
36};
37
38class DeviceInfoService : public SystemAbility, public DeviceInfoStub {
39public:
40    DECLARE_SYSTEM_ABILITY(DeviceInfoService);
41    DISALLOW_COPY_AND_MOVE(DeviceInfoService);
42    explicit DeviceInfoService(int32_t systemAbilityId, bool runOnCreate = true)
43        : SystemAbility(systemAbilityId, runOnCreate)
44    {
45    }
46    ~DeviceInfoService() override {}
47    int32_t GetUdid(std::string& result) override;
48    int32_t GetSerialID(std::string& result) override;
49protected:
50    void OnStart(void) override;
51    void OnStop(void) override;
52    int Dump(int fd, const std::vector<std::u16string>& args) override;
53    void ThreadForUnloadSa(void);
54    std::atomic_bool threadStarted_ { false };
55};
56} // namespace device_info
57} // namespace OHOS
58#endif // OHOS_SYSTEM_DEVICEIDSTUB_H