• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 OHOS_AUTH_MANAGER_H
17 #define OHOS_AUTH_MANAGER_H
18 
19 #include <map>
20 #include <string>
21 #include <list>
22 
23 #include "nlohmann/json.hpp"
24 
25 #include "single_instance.h"
26 #include "dm_device_info.h"
27 #include "dm_app_image_info.h"
28 #include "request_session.h"
29 #include "response_session.h"
30 
31 namespace OHOS {
32 namespace DistributedHardware {
33 class AuthManager {
34     DECLARE_SINGLE_INSTANCE(AuthManager);
35 public:
36     void AuthDeviceGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo,
37         std::string &extras);
38     void OnReceiveMsg(long long channelId, std::string &message);
39     int32_t CheckAuthentication(std::string &authPara);
40     int32_t GetAuthenticationParam(DmAuthParam &authParam);
41     void OnUserOperate(int32_t action);
42     int32_t GetPincode(int64_t requestId);
43     std::string GetAuthPara();
44     int32_t GetDisplayOwner();
45     void NotifyHostOnCheckAuthResult(int64_t requestId, int errorCode);
46 
47 private:
48     void SyncDmPrivateGroup(std::string &message);
49     void AuthAppGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo,
50         std::string &extrasJson);
51     void OnReceiveMessage(long long channelId, std::string &message, int32_t msgType);
52     bool CanStartNewSession();
53     void MoveSessionToWaitScanMap();
54     int32_t CheckAuthenticationByPin(nlohmann::json &authJson);
55     void OnPinInputResult(int32_t pinCode, int32_t pinToken);
56 
57 private:
58     std::string authParam_ = "";
59     int32_t displayOwner_ = 0;
60     std::shared_ptr<RequestSession> mPendingReqSessionPtr_ {nullptr};
61     std::shared_ptr<ResponseSession> mPendingRespSessionPtr {};
62     std::map<std::string, std::shared_ptr<RequestSession>> mWaitScanReqSessionMap_ = {};
63 };
64 }
65 }
66 #endif
67