• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     uint32_t GetAppIndex();
50     void SetAppIndex(const uint32_t &appIndex);
51 
52     void GetExtraInfo(std::string &extraInfo) const;
53     void SetExtraInfo(const std::string &extraInfo);
54 
55     ErrCode EnableAppAccess(const std::string &authorizedApp, const uint32_t apiVersion = Constants::API_VERSION7);
56     ErrCode DisableAppAccess(const std::string &authorizedApp, const uint32_t apiVersion = Constants::API_VERSION7);
57     ErrCode CheckAppAccess(const std::string &authorizedApp, bool &isAccessible);
58 
59     void GetAuthorizedApps(std::set<std::string> &apps) const;
60     void SetAuthorizedApps(const std::set<std::string> &apps);
61 
62     void GetSyncEnable(bool &syncEnable) const;
63     void SetSyncEnable(const bool &syncEnable);
64 
65     ErrCode InitCustomData(const std::map<std::string, std::string> &data);
66     ErrCode GetAllAssociatedData(std::map<std::string, std::string> &data) const;
67     ErrCode GetAssociatedData(const std::string &key, std::string &value) const;
68     ErrCode SetAssociatedData(const std::string &key, const std::string &value);
69 
70     ErrCode GetAccountCredential(const std::string &credentialType, std::string &credential) const;
71     ErrCode SetAccountCredential(
72         const std::string &credentialType, const std::string &credential, bool isDelete = false);
73 
74     ErrCode GetOAuthToken(
75         const std::string &authType, std::string &token, const uint32_t apiVersion = Constants::API_VERSION8) const;
76     ErrCode SetOAuthToken(const std::string &authType, const std::string &token);
77     ErrCode DeleteOAuthToken(const std::string &authType, const std::string &token);
78     ErrCode DeleteAuthToken(const std::string &authType, const std::string &token, bool isOwnerSelf);
79     ErrCode SetOAuthTokenVisibility(const std::string &authType,
80         const std::string &bundleName, bool isVisible, const uint32_t apiVersion = Constants::API_VERSION8);
81     ErrCode CheckOAuthTokenVisibility(const std::string &authType,
82         const std::string &bundleName, bool &isVisible, const uint32_t apiVersion = Constants::API_VERSION8) const;
83     ErrCode GetAllOAuthTokens(std::vector<OAuthTokenInfo> &tokenInfos) const;
84     ErrCode GetOAuthList(const std::string &authType,
85         std::set<std::string> &oauthList, const uint32_t apiVersion = Constants::API_VERSION8) const;
86 
87     bool Marshalling(Parcel &parcel) const override;
88     static AppAccountInfo *Unmarshalling(Parcel &parcel);
89 
90     Json ToJson() const override;
91     void FromJson(const Json &jsonObject) override;
92     std::string ToString() const override;
93     std::string GetPrimeKey() const override;
94 
95 private:
96     void ParseTokenInfosFromJson(const Json &jsonObject);
97     bool ReadFromParcel(Parcel &parcel);
98 
99     bool WriteStringSet(const std::set<std::string> &stringSet, Parcel &data) const;
100     bool ReadStringSet(std::set<std::string> &stringSet, Parcel &data);
101     bool WriteStringMap(const std::map<std::string, std::string> &stringSet, Parcel &data) const;
102     bool ReadStringMap(std::map<std::string, std::string> &stringMap, Parcel &data);
103     bool WriteTokenInfos(const std::map<std::string, OAuthTokenInfo> &tokenInfos, Parcel &data) const;
104     bool ReadTokenInfos(std::map<std::string, OAuthTokenInfo> &tokenInfos, Parcel &data);
105 
106 private:
107     std::string owner_;
108     std::string name_;
109     uint32_t appIndex_;
110     std::string extraInfo_;
111     std::set<std::string> authorizedApps_;
112     bool syncEnable_ = false;
113     std::string associatedData_;
114     std::string accountCredential_;
115     std::map<std::string, OAuthTokenInfo> oauthTokens_;
116 };
117 }  // namespace AccountSA
118 }  // namespace OHOS
119 
120 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_INFO_H
121