15c735df2Sopenharmony_ci/* 25c735df2Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License. 55c735df2Sopenharmony_ci * You may obtain a copy of the License at 65c735df2Sopenharmony_ci * 75c735df2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85c735df2Sopenharmony_ci * 95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and 135c735df2Sopenharmony_ci * limitations under the License. 145c735df2Sopenharmony_ci */ 155c735df2Sopenharmony_ci 165c735df2Sopenharmony_ci#ifndef APP_IDENTITY_H 175c735df2Sopenharmony_ci#define APP_IDENTITY_H 185c735df2Sopenharmony_ci 195c735df2Sopenharmony_ci#include <string> 205c735df2Sopenharmony_ci#include <parcel.h> 215c735df2Sopenharmony_ci 225c735df2Sopenharmony_cinamespace OHOS { 235c735df2Sopenharmony_cinamespace Location { 245c735df2Sopenharmony_ciclass AppIdentity : public Parcelable { 255c735df2Sopenharmony_cipublic: 265c735df2Sopenharmony_ci AppIdentity(); 275c735df2Sopenharmony_ci explicit AppIdentity(pid_t uid, pid_t pid, uint32_t tokenId, uint64_t tokenIdEx, uint32_t firstTokenId); 285c735df2Sopenharmony_ci virtual ~AppIdentity() = default; 295c735df2Sopenharmony_ci 305c735df2Sopenharmony_ci inline pid_t GetPid() const 315c735df2Sopenharmony_ci { 325c735df2Sopenharmony_ci return pid_; 335c735df2Sopenharmony_ci } 345c735df2Sopenharmony_ci 355c735df2Sopenharmony_ci inline void SetPid(pid_t pid) 365c735df2Sopenharmony_ci { 375c735df2Sopenharmony_ci pid_ = pid; 385c735df2Sopenharmony_ci } 395c735df2Sopenharmony_ci 405c735df2Sopenharmony_ci inline pid_t GetUid() const 415c735df2Sopenharmony_ci { 425c735df2Sopenharmony_ci return uid_; 435c735df2Sopenharmony_ci } 445c735df2Sopenharmony_ci 455c735df2Sopenharmony_ci inline void SetUid(pid_t uid) 465c735df2Sopenharmony_ci { 475c735df2Sopenharmony_ci uid_ = uid; 485c735df2Sopenharmony_ci } 495c735df2Sopenharmony_ci 505c735df2Sopenharmony_ci inline uint32_t GetTokenId() const 515c735df2Sopenharmony_ci { 525c735df2Sopenharmony_ci return tokenId_; 535c735df2Sopenharmony_ci } 545c735df2Sopenharmony_ci 555c735df2Sopenharmony_ci inline void SetTokenId(uint32_t tokenId) 565c735df2Sopenharmony_ci { 575c735df2Sopenharmony_ci tokenId_ = tokenId; 585c735df2Sopenharmony_ci } 595c735df2Sopenharmony_ci 605c735df2Sopenharmony_ci inline uint64_t GetTokenIdEx() const 615c735df2Sopenharmony_ci { 625c735df2Sopenharmony_ci return tokenIdEx_; 635c735df2Sopenharmony_ci } 645c735df2Sopenharmony_ci 655c735df2Sopenharmony_ci inline void SetTokenIdEx(uint64_t tokenIdEx) 665c735df2Sopenharmony_ci { 675c735df2Sopenharmony_ci tokenIdEx_ = tokenIdEx; 685c735df2Sopenharmony_ci } 695c735df2Sopenharmony_ci 705c735df2Sopenharmony_ci inline uint32_t GetFirstTokenId() const 715c735df2Sopenharmony_ci { 725c735df2Sopenharmony_ci return firstTokenId_; 735c735df2Sopenharmony_ci } 745c735df2Sopenharmony_ci 755c735df2Sopenharmony_ci inline void SetFirstTokenId(uint32_t firstTokenId) 765c735df2Sopenharmony_ci { 775c735df2Sopenharmony_ci firstTokenId_ = firstTokenId; 785c735df2Sopenharmony_ci } 795c735df2Sopenharmony_ci 805c735df2Sopenharmony_ci inline std::string GetBundleName() const 815c735df2Sopenharmony_ci { 825c735df2Sopenharmony_ci return bundleName_; 835c735df2Sopenharmony_ci } 845c735df2Sopenharmony_ci 855c735df2Sopenharmony_ci inline void SetBundleName(std::string bundleName) 865c735df2Sopenharmony_ci { 875c735df2Sopenharmony_ci bundleName_ = bundleName; 885c735df2Sopenharmony_ci } 895c735df2Sopenharmony_ci void ReadFromParcel(Parcel& parcel) 905c735df2Sopenharmony_ci { 915c735df2Sopenharmony_ci uid_ = parcel.ReadInt32(); 925c735df2Sopenharmony_ci pid_ = parcel.ReadInt32(); 935c735df2Sopenharmony_ci tokenId_ = static_cast<uint32_t>(parcel.ReadInt32()); 945c735df2Sopenharmony_ci tokenIdEx_ = parcel.ReadInt64(); 955c735df2Sopenharmony_ci firstTokenId_ = static_cast<uint32_t>(parcel.ReadInt32()); 965c735df2Sopenharmony_ci bundleName_ = parcel.ReadString(); 975c735df2Sopenharmony_ci } 985c735df2Sopenharmony_ci 995c735df2Sopenharmony_ci bool Marshalling(Parcel& parcel) const 1005c735df2Sopenharmony_ci { 1015c735df2Sopenharmony_ci return parcel.WriteInt32(uid_) && 1025c735df2Sopenharmony_ci parcel.WriteInt32(pid_) && 1035c735df2Sopenharmony_ci parcel.WriteInt32(tokenId_) && 1045c735df2Sopenharmony_ci parcel.WriteInt64(tokenIdEx_) && 1055c735df2Sopenharmony_ci parcel.WriteInt32(firstTokenId_) && 1065c735df2Sopenharmony_ci parcel.WriteString(bundleName_); 1075c735df2Sopenharmony_ci } 1085c735df2Sopenharmony_ci 1095c735df2Sopenharmony_ci static std::shared_ptr<AppIdentity> Unmarshalling(Parcel& parcel) 1105c735df2Sopenharmony_ci { 1115c735df2Sopenharmony_ci auto identity = std::make_shared<AppIdentity>(); 1125c735df2Sopenharmony_ci identity->ReadFromParcel(parcel); 1135c735df2Sopenharmony_ci return identity; 1145c735df2Sopenharmony_ci } 1155c735df2Sopenharmony_ci 1165c735df2Sopenharmony_ci std::string ToString() const; 1175c735df2Sopenharmony_ciprivate: 1185c735df2Sopenharmony_ci pid_t uid_; 1195c735df2Sopenharmony_ci pid_t pid_; 1205c735df2Sopenharmony_ci uint32_t tokenId_; 1215c735df2Sopenharmony_ci uint64_t tokenIdEx_; 1225c735df2Sopenharmony_ci uint32_t firstTokenId_; 1235c735df2Sopenharmony_ci std::string bundleName_; 1245c735df2Sopenharmony_ci}; 1255c735df2Sopenharmony_ci} // namespace Location 1265c735df2Sopenharmony_ci} // namespace OHOS 1275c735df2Sopenharmony_ci#endif // APP_IDENTITY_H