• 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 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_CONTROL_FILE_MANAGER_H
16 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_CONTROL_FILE_MANAGER_H
17 #include <memory>
18 #include <mutex>
19 #include "ios_account_control.h"
20 #include "os_account_database_operator.h"
21 #include "os_account_file_operator.h"
22 #include "os_account_photo_operator.h"
23 namespace OHOS {
24 namespace AccountSA {
25 class OsAccountControlFileManager : public IOsAccountControl {
26 public:
27     OsAccountControlFileManager();
28     virtual ~OsAccountControlFileManager();
29     void Init() override;
30     ErrCode GetOsAccountList(std::vector<OsAccountInfo> &osAccountList) override;
31     ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo) override;
32     ErrCode GetConstraintsByType(const OsAccountType type, std::vector<std::string> &constratins) override;
33     ErrCode InsertOsAccount(OsAccountInfo &osAccountInfo) override;
34     ErrCode DelOsAccount(const int id) override;
35     ErrCode UpdateOsAccount(OsAccountInfo &osAccountInfo) override;
36     ErrCode GetMaxCreatedOsAccountNum(int &maxCreatedOsAccountNum) override;
37     ErrCode GetSerialNumber(int64_t &serialNumber) override;
38     ErrCode GetAllowCreateId(int &id) override;
39     ErrCode IsOsAccountExists(const int id, bool &isExists) override;
40     ErrCode GetPhotoById(const int id, std::string &photo) override;
41     ErrCode SetPhotoById(const int id, const std::string &photo) override;
42     ErrCode GetIsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override;
43     ErrCode IsConstrarionsInTypeList(const std::vector<std::string> &constrains, bool &isExists) override;
44     ErrCode IsAllowedCreateAdmin(bool &isAllowedCreateAdmin) override;
45 
46     ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID,
47         int &createdOsAccountNum) override;
48     ErrCode GetSerialNumberFromDatabase(const std::string& storeID,
49         int64_t &serialNumber) override;
50     ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override;
51     ErrCode GetOsAccountFromDatabase(const std::string& storeID,
52         const int id, OsAccountInfo& osAccountInfo) override;
53     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
54         std::vector<OsAccountInfo>& osAccountList) override;
55 
56 private:
57     ErrCode UpdateAccountList(const std::string& idStr, bool isAdd);
58     ErrCode GetAccountListFromFile(Json& accountListJson);
59     ErrCode SaveAccountListToFile(const Json& accountListJson);
60     ErrCode SaveAccountListToFileAndDataBase(const Json& accountListJson);
61     void BuildAndSaveAccountListJsonFile(const std::vector<std::string>& accounts);
62     void RecoverAccountListJsonFile();
63 
64 private:
65     std::shared_ptr<AccountFileOperator> accountFileOperator_;
66     std::shared_ptr<OsAccountDatabaseOperator> osAccountDataBaseOperator_;
67     std::shared_ptr<OsAccountFileOperator> osAccountFileOperator_;
68     std::shared_ptr<OsAccountPhotoOperator> osAccountPhotoOperator_;
69     std::mutex accountListFileLock_;
70 };
71 }  // namespace AccountSA
72 }  // namespace OHOS
73 #endif /* OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_CONTROL_FILE_MANAGER_H */