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