1/*
2 * Copyright (C) 2022 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 APP_IDENTITY_H
17#define APP_IDENTITY_H
18
19#include <string>
20#include <parcel.h>
21
22namespace OHOS {
23namespace Location {
24class AppIdentity : public Parcelable {
25public:
26    AppIdentity();
27    explicit AppIdentity(pid_t uid, pid_t pid, uint32_t tokenId, uint64_t tokenIdEx, uint32_t firstTokenId);
28    virtual ~AppIdentity() = default;
29
30    inline pid_t GetPid() const
31    {
32        return pid_;
33    }
34
35    inline void SetPid(pid_t pid)
36    {
37        pid_ = pid;
38    }
39
40    inline pid_t GetUid() const
41    {
42        return uid_;
43    }
44
45    inline void SetUid(pid_t uid)
46    {
47        uid_ = uid;
48    }
49
50    inline uint32_t GetTokenId() const
51    {
52        return tokenId_;
53    }
54
55    inline void SetTokenId(uint32_t tokenId)
56    {
57        tokenId_ = tokenId;
58    }
59
60    inline uint64_t GetTokenIdEx() const
61    {
62        return tokenIdEx_;
63    }
64
65    inline void SetTokenIdEx(uint64_t tokenIdEx)
66    {
67        tokenIdEx_ = tokenIdEx;
68    }
69
70    inline uint32_t GetFirstTokenId() const
71    {
72        return firstTokenId_;
73    }
74
75    inline void SetFirstTokenId(uint32_t firstTokenId)
76    {
77        firstTokenId_ = firstTokenId;
78    }
79
80    inline std::string GetBundleName() const
81    {
82        return bundleName_;
83    }
84
85    inline void SetBundleName(std::string bundleName)
86    {
87        bundleName_ = bundleName;
88    }
89    void ReadFromParcel(Parcel& parcel)
90    {
91        uid_ = parcel.ReadInt32();
92        pid_ = parcel.ReadInt32();
93        tokenId_ = static_cast<uint32_t>(parcel.ReadInt32());
94        tokenIdEx_ = parcel.ReadInt64();
95        firstTokenId_ = static_cast<uint32_t>(parcel.ReadInt32());
96        bundleName_ = parcel.ReadString();
97    }
98
99    bool Marshalling(Parcel& parcel) const
100    {
101        return parcel.WriteInt32(uid_) &&
102           parcel.WriteInt32(pid_) &&
103           parcel.WriteInt32(tokenId_) &&
104           parcel.WriteInt64(tokenIdEx_) &&
105           parcel.WriteInt32(firstTokenId_) &&
106           parcel.WriteString(bundleName_);
107    }
108
109    static std::shared_ptr<AppIdentity> Unmarshalling(Parcel& parcel)
110    {
111        auto identity = std::make_shared<AppIdentity>();
112        identity->ReadFromParcel(parcel);
113        return identity;
114    }
115
116    std::string ToString() const;
117private:
118    pid_t uid_;
119    pid_t pid_;
120    uint32_t tokenId_;
121    uint64_t tokenIdEx_;
122    uint32_t firstTokenId_;
123    std::string bundleName_;
124};
125} // namespace Location
126} // namespace OHOS
127#endif // APP_IDENTITY_H