• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "auth_response_state.h"
17 
18 #include "dm_auth_manager.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
Leave()24 int32_t AuthResponseState::Leave()
25 {
26     return DM_OK;
27 }
28 
SetAuthContext(std::shared_ptr<DmAuthResponseContext> context)29 int32_t AuthResponseState::SetAuthContext(std::shared_ptr<DmAuthResponseContext> context)
30 {
31     context_ = std::move(context);
32     return DM_OK;
33 }
34 
GetAuthContext()35 std::shared_ptr<DmAuthResponseContext> AuthResponseState::GetAuthContext()
36 {
37     return context_;
38 }
39 
SetAuthManager(std::shared_ptr<DmAuthManager> authManager)40 int32_t AuthResponseState::SetAuthManager(std::shared_ptr<DmAuthManager> authManager)
41 {
42     authManager_ = std::move(authManager);
43     return DM_OK;
44 }
45 
TransitionTo(std::shared_ptr<AuthResponseState> state)46 int32_t AuthResponseState::TransitionTo(std::shared_ptr<AuthResponseState> state)
47 {
48     LOGI("AuthRequestState::TransitionTo");
49     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
50     if (stateAuthManager == nullptr) {
51         LOGE("AuthRequestState::authManager_ null");
52         return ERR_DM_FAILED;
53     }
54     state->SetAuthManager(stateAuthManager);
55     stateAuthManager->SetAuthResponseState(state);
56     state->SetAuthContext(context_);
57     this->Leave();
58     state->Enter();
59     return DM_OK;
60 }
61 
GetStateType()62 int32_t AuthResponseInitState::GetStateType()
63 {
64     return AuthState::AUTH_RESPONSE_INIT;
65 }
66 
Enter()67 int32_t AuthResponseInitState::Enter()
68 {
69     LOGI("AuthResponse::AuthResponseInitState Enter");
70     return DM_OK;
71 }
72 
GetStateType()73 int32_t AuthResponseNegotiateState::GetStateType()
74 {
75     return AuthState::AUTH_RESPONSE_NEGOTIATE;
76 }
77 
Enter()78 int32_t AuthResponseNegotiateState::Enter()
79 {
80     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
81     if (stateAuthManager == nullptr) {
82         LOGE("AuthRequestState::authManager_ null");
83         return ERR_DM_FAILED;
84     }
85     stateAuthManager->RespNegotiate(context_->sessionId);
86     return DM_OK;
87 }
88 
GetStateType()89 int32_t AuthResponseConfirmState::GetStateType()
90 {
91     return AuthState::AUTH_RESPONSE_CONFIRM;
92 }
93 
Enter()94 int32_t AuthResponseConfirmState::Enter()
95 {
96     LOGI("AuthResponse::AuthResponseConfirmState Enter");
97     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
98     if (stateAuthManager == nullptr) {
99         LOGE("AuthRequestState::authManager_ null");
100         return ERR_DM_FAILED;
101     }
102     stateAuthManager->ShowConfigDialog();
103     return DM_OK;
104 }
105 
GetStateType()106 int32_t AuthResponseGroupState::GetStateType()
107 {
108     return AuthState::AUTH_RESPONSE_GROUP;
109 }
110 
Enter()111 int32_t AuthResponseGroupState::Enter()
112 {
113     LOGI("AuthResponse::AuthResponseGroupState Enter");
114     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
115     if (stateAuthManager == nullptr) {
116         LOGE("AuthRequestState::authManager_ null");
117         return ERR_DM_FAILED;
118     }
119     stateAuthManager->CreateGroup();
120     return DM_OK;
121 }
122 
GetStateType()123 int32_t AuthResponseShowState::GetStateType()
124 {
125     return AuthState::AUTH_RESPONSE_SHOW;
126 }
127 
Enter()128 int32_t AuthResponseShowState::Enter()
129 {
130     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
131     if (stateAuthManager == nullptr) {
132         LOGE("AuthRequestState::authManager_ null");
133         return ERR_DM_FAILED;
134     }
135     stateAuthManager->ShowAuthInfoDialog();
136     return DM_OK;
137 }
138 
GetStateType()139 int32_t AuthResponseFinishState::GetStateType()
140 {
141     return AuthState::AUTH_RESPONSE_FINISH;
142 }
143 
Enter()144 int32_t AuthResponseFinishState::Enter()
145 {
146     std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
147     if (stateAuthManager == nullptr) {
148         LOGE("AuthRequestState::authManager_ null");
149         return ERR_DM_FAILED;
150     }
151     stateAuthManager->AuthenticateFinish();
152     return DM_OK;
153 }
154 } // namespace DistributedHardware
155 } // namespace OHOS
156