• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 FIRST_USE_DIALOG_H
16 #define FIRST_USE_DIALOG_H
17 
18 #include <map>
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include "access_token.h"
23 #include "iremote_object.h"
24 #include "nlohmann/json.hpp"
25 #include "sec_comp_err.h"
26 #include "sec_comp_info.h"
27 #include "sec_event_handler.h"
28 
29 namespace OHOS {
30 namespace Security {
31 namespace SecurityComponent {
32 class FirstUseDialog final {
33 public:
34     FirstUseDialog() = default;
35     ~FirstUseDialog() = default;
36     bool NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type, sptr<IRemoteObject> callerToken);
37     void Init(std::shared_ptr<SecEventHandler> secHandler);
38 
39 private:
40     bool IsCfgDirExist(void);
41     bool IsCfgFileExist(void);
42     bool IsCfgFileValid(void);
43     bool ReadCfgContent(std::string& content);
44     void WriteCfgContent(const std::string& content);
45     bool ParseRecord(nlohmann::json& jsonRes,
46         AccessToken::AccessTokenID& id, uint64_t& type);
47     void ParseRecords(nlohmann::json& jsonRes);
48     void LoadFirstUseRecord(void);
49     void SaveFirstUseRecord(void);
50     void StartDialogAbility(SecCompType type, sptr<IRemoteObject> callerToken);
51     void SendSaveEventHandler(void);
52 
53     std::mutex useMapMutex_;
54     std::unordered_map<AccessToken::AccessTokenID, uint64_t> firstUseMap_;
55     std::shared_ptr<SecEventHandler> secHandler_;
56 };
57 }  // namespace SecurityComponentEnhance
58 }  // namespace Security
59 }  // namespace OHOS
60 #endif  // FIRST_USE_DIALOG_H
61