• 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_OHOS_ACCOUNT_DATA_DEAL_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OHOS_ACCOUNT_DATA_DEAL_H
18 
19 #include <string>
20 #include <mutex>
21 #include <nlohmann/json.hpp>
22 #include "account_error_no.h"
23 #include "account_info.h"
24 
25 namespace OHOS {
26 namespace AccountSA {
27 using json = nlohmann::json;
28 
29 class OhosAccountDataDeal {
30 public:
31     explicit OhosAccountDataDeal(const std::string &configFileDir);
32     ErrCode Init(std::int32_t userId);
33 
34     ErrCode AccountInfoFromJson(AccountInfo &accountInfo, int32_t userId);
35     ErrCode AccountInfoToJson(const AccountInfo &accountInfo) const;
~OhosAccountDataDeal()36     ~OhosAccountDataDeal() {}
37 
38 private:
39     bool initOk_;
40     std::string configFileDir_;
41     std::mutex mutex_;
42     nlohmann::json jsonData_;
43     void BuildJsonFileFromScratch(int32_t userId) const;
44     ErrCode SaveAccountInfo(const AccountInfo &accountInfo) const;
45     ErrCode GetAccountInfo(AccountInfo &accountInfo, int32_t userId);
46     ErrCode ParseJsonFromFile(const std::string &filePath, nlohmann::json &jsonData, int32_t userId);
47 };
48 }  // namespace AccountSA
49 }  // namespace OHOS
50 
51 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OHOS_ACCOUNT_DATA_DEAL_H
52