1 /* 2 * Copyright (c) 2021-2025 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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_INFO_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_INFO_H 18 19 #include <set> 20 #include <map> 21 #include "account_error_no.h" 22 #include "iaccount_info.h" 23 #include "app_account_constants.h" 24 #include "parcel.h" 25 26 namespace OHOS { 27 namespace AccountSA { 28 struct OAuthTokenInfo : public Parcelable { 29 std::string authType; 30 std::string token; 31 std::set<std::string> authList; 32 bool status = true; 33 bool ReadFromParcel(Parcel &parcel); 34 bool Marshalling(Parcel &parcel) const override; 35 static OAuthTokenInfo *Unmarshalling(Parcel &parcel); 36 }; 37 38 struct AppAccountStringInfo : public Parcelable { 39 std::string name; 40 std::string owner; 41 std::string authType; 42 bool ReadFromParcel(Parcel &parcel); 43 bool Marshalling(Parcel &parcel) const override; 44 static AppAccountStringInfo *Unmarshalling(Parcel &parcel); 45 }; 46 47 struct AppAccountAuthenticatorStringInfo : public Parcelable { 48 std::string name; 49 std::string authType; 50 std::string callerBundleName; 51 explicit AppAccountAuthenticatorStringInfo( 52 std::string name, std::string authType, std::string callerBundleName); 53 AppAccountAuthenticatorStringInfo() = default; 54 bool ReadFromParcel(Parcel &parcel); 55 bool Marshalling(Parcel &parcel) const override; 56 static AppAccountAuthenticatorStringInfo *Unmarshalling(Parcel &parcel); 57 }; 58 59 class AppAccountInfo : public IAccountInfo, public Parcelable { 60 public: 61 AppAccountInfo(); 62 explicit AppAccountInfo(const std::string &name, const std::string &owner); 63 ~AppAccountInfo() override = default; 64 65 std::string GetOwner(); 66 void GetOwner(std::string &owner); 67 void SetOwner(const std::string &owner); 68 69 std::string GetName(); 70 void GetName(std::string &name) const; 71 void SetName(const std::string &name); 72 73 std::string GetAlias(); 74 75 uint32_t GetAppIndex(); 76 void SetAppIndex(const uint32_t &appIndex); 77 78 void GetExtraInfo(std::string &extraInfo) const; 79 void SetExtraInfo(const std::string &extraInfo); 80 81 ErrCode EnableAppAccess(const std::string &authorizedApp, const uint32_t apiVersion = Constants::API_VERSION7); 82 ErrCode DisableAppAccess(const std::string &authorizedApp, const uint32_t apiVersion = Constants::API_VERSION7); 83 ErrCode CheckAppAccess(const std::string &authorizedApp, bool &isAccessible); 84 85 void GetAuthorizedApps(std::set<std::string> &apps) const; 86 void SetAuthorizedApps(const std::set<std::string> &apps); 87 88 void GetSyncEnable(bool &syncEnable) const; 89 void SetSyncEnable(const bool &syncEnable); 90 91 ErrCode InitCustomData(const std::map<std::string, std::string> &data); 92 ErrCode GetAllAssociatedData(std::map<std::string, std::string> &data) const; 93 ErrCode GetAssociatedData(const std::string &key, std::string &value) const; 94 ErrCode SetAssociatedData(const std::string &key, const std::string &value); 95 96 ErrCode GetAccountCredential(const std::string &credentialType, std::string &credential) const; 97 ErrCode SetAccountCredential(const std::string &credentialType, const std::string &credential); 98 ErrCode DeleteAccountCredential(const std::string &credentialType); 99 100 ErrCode GetOAuthToken( 101 const std::string &authType, std::string &token, const uint32_t apiVersion = Constants::API_VERSION8) const; 102 ErrCode SetOAuthToken(const std::string &authType, const std::string &token); 103 ErrCode DeleteOAuthToken(const std::string &authType, const std::string &token); 104 ErrCode DeleteAuthToken(const std::string &authType, const std::string &token, bool isOwnerSelf); 105 ErrCode SetOAuthTokenVisibility(const std::string &authType, 106 const std::string &bundleName, bool isVisible, const uint32_t apiVersion = Constants::API_VERSION8); 107 ErrCode CheckOAuthTokenVisibility(const std::string &authType, 108 const std::string &bundleName, bool &isVisible, const uint32_t apiVersion = Constants::API_VERSION8) const; 109 ErrCode GetAllOAuthTokens(std::vector<OAuthTokenInfo> &tokenInfos) const; 110 ErrCode GetOAuthList(const std::string &authType, 111 std::set<std::string> &oauthList, const uint32_t apiVersion = Constants::API_VERSION8) const; 112 113 bool Marshalling(Parcel &parcel) const override; 114 static AppAccountInfo *Unmarshalling(Parcel &parcel); 115 116 std::string ToString() const override; 117 std::string GetPrimeKey() const override; 118 119 private: 120 bool ReadFromParcel(Parcel &parcel); 121 122 bool WriteStringSet(const std::set<std::string> &stringSet, Parcel &data) const; 123 bool ReadStringSet(std::set<std::string> &stringSet, Parcel &data); 124 bool WriteStringMap(const std::map<std::string, std::string> &stringSet, Parcel &data) const; 125 bool ReadStringMap(std::map<std::string, std::string> &stringMap, Parcel &data); 126 bool WriteTokenInfos(const std::map<std::string, OAuthTokenInfo> &tokenInfos, Parcel &data) const; 127 bool ReadTokenInfos(std::map<std::string, OAuthTokenInfo> &tokenInfos, Parcel &data); 128 129 public: 130 std::string owner_; 131 std::string name_; 132 std::string alias_; 133 uint32_t appIndex_; 134 std::string extraInfo_; 135 std::set<std::string> authorizedApps_; 136 bool syncEnable_ = false; 137 std::string associatedData_; 138 std::string accountCredential_; 139 std::map<std::string, OAuthTokenInfo> oauthTokens_; 140 }; 141 } // namespace AccountSA 142 } // namespace OHOS 143 144 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_INFO_H 145