1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Extended functinality for policy provision process. |
|
15 * |
|
16 */ |
|
17 #include <cmmanagerext.h> |
|
18 #include <cmconnectionmethodext.h> |
|
19 #include <cmdestinationext.h> |
|
20 #include <cmconnectionmethoddef.h> |
|
21 #include <centralrepository.h> |
|
22 |
|
23 #include "sit.h" |
|
24 #include "extender.h" |
|
25 #include "log.h" |
|
26 #include "vpnconnstarter.h" |
|
27 #include "extenderhelper.h" |
|
28 |
|
29 |
|
30 CExtender* CExtender::NewL() |
|
31 { |
|
32 LOG(Log::Printf(_L("CExtender::NewL - begin\n"))); |
|
33 CExtender* self = new (ELeave) CExtender(); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(); // self |
|
37 LOG(Log::Printf(_L("CExtender::NewL - end\n"))); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CExtender::~CExtender() |
|
42 { |
|
43 LOG(Log::Printf(_L("CExtender::~CExtender\n"))); |
|
44 Cancel(); |
|
45 |
|
46 iVpnExtServ.Close(); |
|
47 iNotifier.Close(); |
|
48 delete iExtenderHelper; |
|
49 } |
|
50 |
|
51 CExtender::CExtender() : CActive(EPriorityNormal) |
|
52 { |
|
53 |
|
54 } |
|
55 |
|
56 void CExtender::ConstructL() |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 User::LeaveIfError(iVpnExtServ.Connect()); |
|
60 User::LeaveIfError(iNotifier.Connect()); |
|
61 } |
|
62 |
|
63 void CExtender::DoCancel() |
|
64 { |
|
65 CancelOngoingOperation(); |
|
66 } |
|
67 |
|
68 void CExtender::RunL() |
|
69 { |
|
70 ChangeStateL(); |
|
71 } |
|
72 |
|
73 void CExtender::GotoState(TInt aState) |
|
74 { |
|
75 SetNextState(aState); |
|
76 SetActive(); |
|
77 TRequestStatus* status = &iStatus; |
|
78 User::RequestComplete(status, KErrNone); |
|
79 } |
|
80 |
|
81 void CExtender::SetCurrState(TInt aState) |
|
82 { |
|
83 iCurrState = aState; |
|
84 } |
|
85 |
|
86 void CExtender::SetNextState(TInt aState) |
|
87 { |
|
88 iNextState = aState; |
|
89 } |
|
90 |
|
91 TInt CExtender::CurrState() |
|
92 { |
|
93 return iCurrState; |
|
94 } |
|
95 |
|
96 TInt CExtender::NextState() |
|
97 { |
|
98 return iNextState; |
|
99 } |
|
100 |
|
101 TInt CExtender::RunError(TInt aError) |
|
102 { |
|
103 LOG(Log::Printf(_L("CExtender::RunError - error = %d\n"), aError)); |
|
104 ProcessComplete(aError); |
|
105 return KErrNone; |
|
106 } |
|
107 |
|
108 void CExtender::ChangeStateL() |
|
109 { |
|
110 switch (NextState()) |
|
111 { |
|
112 case KStateCheckPolicyUpdateAvailability: |
|
113 StateCheckPolicyUpdateAvailabilityL(); |
|
114 break; |
|
115 |
|
116 case KStateAfterAskUpdateConfirmation: |
|
117 StateAfterAskUpdateConfirmationL(); |
|
118 break; |
|
119 |
|
120 case KStateUpdatePolicy: |
|
121 StateUpdatePolicyL(); |
|
122 break; |
|
123 |
|
124 case KStateAfterUpdatePolicy: |
|
125 StateAfterUpdatePolicyL(); |
|
126 break; |
|
127 |
|
128 case KStateShowUpdateCompleteNote: |
|
129 StateShowUpdateCompleteNote(); |
|
130 break; |
|
131 |
|
132 case KStateAfterShowUpdateCompleteNote: |
|
133 StateAfterShowUpdateCompleteNote(); |
|
134 break; |
|
135 |
|
136 case KStateShowApActFailureNote: |
|
137 StateShowApActFailureNote(); |
|
138 break; |
|
139 |
|
140 case KStateAfterShowApActFailureNote: |
|
141 StateAfterShowApActFailureNote(); |
|
142 break; |
|
143 |
|
144 default: |
|
145 User::Panic(KSitName, EPanicInvalidTaskHandlerState); |
|
146 } |
|
147 } |
|
148 |
|
149 void CExtender::CancelOngoingOperation() |
|
150 { |
|
151 switch (CurrState()) |
|
152 { |
|
153 case KStateShowApActFailureNote: |
|
154 case KStateAskUpdateConfirmation: |
|
155 case KStateShowUpdateCompleteNote: |
|
156 LOG(Log::Printf(_L("CExtender::CancelOngoingOperation - cancelling notifier\n"))); |
|
157 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
158 break; |
|
159 |
|
160 case KStateCheckPolicyUpdateAvailability: |
|
161 case KStateUpdatePolicy: |
|
162 case KStateAfterUpdatePolicy: |
|
163 LOG(Log::Printf(_L("CExtender::CancelOngoingOperation - cancelling Policy Provision operation\n"))); |
|
164 iVpnExtServ.CancelPolicyProvision(); |
|
165 iExtenderHelper->Cancel(); |
|
166 break; |
|
167 |
|
168 case KStateAfterShowApActFailureNote: |
|
169 case KStateAfterAskUpdateConfirmation: |
|
170 case KStateAfterCheckPolicyUpdateAvailability: |
|
171 case KStateAfterShowUpdateCompleteNote: |
|
172 LOG(Log::Printf(_L("CExtender::CancelOngoingOperation - cancelling nothing\n"))); |
|
173 // Nothing to cancel |
|
174 break; |
|
175 |
|
176 default: |
|
177 User::Panic(KSitName, EPanicInvalidTaskHandlerState); |
|
178 } |
|
179 } |
|
180 |
|
181 void CExtender::OnVpnApActStart(CVpnConnStarter* aVpnConnStarter) |
|
182 { |
|
183 LOG(Log::Printf(_L("CExtender::OnVpnApActStart\n"))); |
|
184 iVpnConnStarter = aVpnConnStarter; |
|
185 |
|
186 // Prevent the deletion of the iVpnConnStarter task |
|
187 // handler (that owns us) as long as we are running |
|
188 iVpnConnStarter->SetDelayedTaskEnd(ETrue); |
|
189 } |
|
190 |
|
191 void CExtender::OnVpnApActCancel() |
|
192 { |
|
193 LOG(Log::Printf(_L("CExtender::OnVpnApActCancel\n"))); |
|
194 |
|
195 // Allow the deletion of the iVpnConnStarter task handler |
|
196 // (the activation has been cancelled in which case |
|
197 // automatic policy updating process will not be |
|
198 // performed and thus the task handler can be deleted |
|
199 // right away after cancel) |
|
200 iVpnConnStarter->SetDelayedTaskEnd(EFalse); |
|
201 } |
|
202 |
|
203 void CExtender::OnVpnApActEnd(const TVpnPolicyId* aPolicyId, TInt aStatus, TUint32 aRealIapId) |
|
204 { |
|
205 LOG(Log::Printf(_L("CExtender::OnVpnApActEnd\n"))); |
|
206 iPolicyId.Copy(*aPolicyId); |
|
207 iRealIapId = aRealIapId; |
|
208 |
|
209 iVpnActStatus = aStatus; |
|
210 |
|
211 if (iVpnActStatus != KErrNone && iVpnActStatus != KErrCancel) |
|
212 { |
|
213 // Report the failure to the system |
|
214 // (management session runner if such is present) |
|
215 // First show a VPN connection activation failure note |
|
216 GotoState(KStateShowApActFailureNote); |
|
217 } |
|
218 else if (iVpnActStatus == KErrCancel) |
|
219 { |
|
220 // The user has cancelled the VPN connection activation, |
|
221 // in that case the automatic policy update operation is |
|
222 // not performed |
|
223 EndTask(); |
|
224 } |
|
225 else |
|
226 { |
|
227 // Begin the combined policy update and |
|
228 // certificate enrollment process right away |
|
229 //GotoState(KStateCheckPolicyUpdateAvailability); |
|
230 EndTask(); |
|
231 } |
|
232 } |
|
233 |
|
234 void CExtender::StateShowApActFailureNote() |
|
235 { |
|
236 LOG(Log::Printf(_L("CExtender::StateShowApActFailureNote\n"))); |
|
237 SetCurrState(KStateShowApActFailureNote); |
|
238 iStatus = KRequestPending; |
|
239 SetActive(); |
|
240 |
|
241 TRequestStatus* ownStatus = &iStatus; |
|
242 User::RequestComplete(ownStatus, KErrNone); |
|
243 |
|
244 SetNextState(KStateAfterShowApActFailureNote); |
|
245 } |
|
246 |
|
247 void CExtender::StateAfterShowApActFailureNote() |
|
248 { |
|
249 LOG(Log::Printf(_L("CExtender::StateAfterShowApActFailureNote\n"))); |
|
250 SetCurrState(KStateAfterShowApActFailureNote); |
|
251 |
|
252 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
253 |
|
254 // Begin the combined policy update |
|
255 // and certificate enrollment process |
|
256 GotoState(KStateCheckPolicyUpdateAvailability); |
|
257 } |
|
258 |
|
259 |
|
260 void CExtender::StateCheckPolicyUpdateAvailabilityL() |
|
261 { |
|
262 LOG(Log::Printf(_L("CExtender::StateCheckPolicyUpdateAvailabilityL\n"))); |
|
263 SetCurrState(KStateCheckPolicyUpdateAvailability); |
|
264 |
|
265 LOG(Log::Printf(_L(" Doing the policy update.\n"))); |
|
266 |
|
267 |
|
268 TAgileProvisionPolicy vpnPolicyName; |
|
269 User::LeaveIfError(iVpnExtServ.GetPolicyName(vpnPolicyName)); |
|
270 |
|
271 if ( iPolicyId.Compare(vpnPolicyName.iPolicyName) == 0 ) |
|
272 { |
|
273 SetCurrState(KStateAskUpdateConfirmation); |
|
274 |
|
275 TVpnDialogInfo dialogInfo(TVpnDialog::EPolicyUpdateConfirmation, 0); |
|
276 iDialogInfoDes() = dialogInfo; |
|
277 |
|
278 iNotifier.StartNotifierAndGetResponse(iStatus, KUidVpnDialogNotifier, |
|
279 iDialogInfoDes, iDialogResponseDes); |
|
280 |
|
281 SetActive(); |
|
282 SetNextState(KStateAfterAskUpdateConfirmation); |
|
283 } |
|
284 else |
|
285 { |
|
286 EndTask(); |
|
287 } |
|
288 } |
|
289 |
|
290 |
|
291 void CExtender::StateAfterAskUpdateConfirmationL() |
|
292 { |
|
293 LOG(Log::Printf(_L("CExtender::StateAfterAskUpdateConfirmationL\n"))); |
|
294 SetCurrState(KStateAfterAskUpdateConfirmation); |
|
295 |
|
296 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
297 |
|
298 // If the user pressed Cancel or an |
|
299 // error occurred, we stop here |
|
300 User::LeaveIfError(iStatus.Int()); |
|
301 |
|
302 iShowCompletionNote = ETrue; |
|
303 GotoState(KStateUpdatePolicy); |
|
304 } |
|
305 |
|
306 void CExtender::StateUpdatePolicyL() |
|
307 { |
|
308 LOG(Log::Printf(_L("CExtender::StateUpdatePolicy\n"))); |
|
309 SetCurrState(KStateUpdatePolicy); |
|
310 |
|
311 if ( iExtenderHelper == NULL) |
|
312 iExtenderHelper=CExtenderHelper::NewL(); |
|
313 |
|
314 iExtenderHelper->StartNotifierL(this); |
|
315 |
|
316 |
|
317 iVpnExtServ.SynchronizePolicyServer(iStatus); |
|
318 |
|
319 SetActive(); |
|
320 SetNextState(KStateAfterUpdatePolicy); |
|
321 } |
|
322 |
|
323 void CExtender::StateAfterUpdatePolicyL() |
|
324 { |
|
325 LOG(Log::Printf(_L("CExtender::StateAfterUpdatePolicyL\n"))); |
|
326 |
|
327 |
|
328 if (iStatus != KErrNone) |
|
329 { |
|
330 User::Leave(iStatus.Int()); |
|
331 } |
|
332 |
|
333 ProcessComplete(KErrNone); |
|
334 } |
|
335 |
|
336 void CExtender::ProcessComplete(TInt aStatus) |
|
337 { |
|
338 LOG(Log::Printf(_L("CExtender::ProcessComplete - status = %d\n"), aStatus)); |
|
339 iFinalStatus = aStatus; |
|
340 GotoState(KStateShowUpdateCompleteNote); |
|
341 } |
|
342 |
|
343 void CExtender::StateShowUpdateCompleteNote() |
|
344 { |
|
345 LOG(Log::Printf(_L("CExtender::StateShowUpdateCompleteNote\n"))); |
|
346 SetCurrState(KStateShowUpdateCompleteNote); |
|
347 |
|
348 if (!iShowCompletionNote || iFinalStatus == KErrCancel) |
|
349 { |
|
350 EndTask(); |
|
351 } |
|
352 else if ( iFinalStatus == KErrNone ) |
|
353 { |
|
354 |
|
355 TVpnDialogInfo dialogInfo(TNoteDialog::EInfo, TVpnNoteDialog::EPolicyUpdateSucceeded); |
|
356 iDialogInfoDes() = dialogInfo; |
|
357 |
|
358 iNotifier.StartNotifierAndGetResponse(iStatus, KUidVpnDialogNotifier, |
|
359 iDialogInfoDes, iDialogResponseDes); |
|
360 |
|
361 SetActive(); |
|
362 SetNextState(KStateAfterShowUpdateCompleteNote); |
|
363 |
|
364 } |
|
365 else |
|
366 { |
|
367 TVpnDialogInfo dialogInfo(TNoteDialog::EInfo, TVpnNoteDialog::EPolicyUpdateFailed); |
|
368 iDialogInfoDes() = dialogInfo; |
|
369 |
|
370 iNotifier.StartNotifierAndGetResponse(iStatus, KUidVpnDialogNotifier, |
|
371 iDialogInfoDes, iDialogResponseDes); |
|
372 |
|
373 SetActive(); |
|
374 SetNextState(KStateAfterShowUpdateCompleteNote); |
|
375 } |
|
376 |
|
377 |
|
378 } |
|
379 |
|
380 void CExtender::StateAfterShowUpdateCompleteNote() |
|
381 { |
|
382 LOG(Log::Printf(_L("CExtender::StateAfterShowUpdateCompleteNote\n"))); |
|
383 SetCurrState(KStateAfterShowUpdateCompleteNote); |
|
384 |
|
385 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
386 |
|
387 EndTask(); |
|
388 } |
|
389 |
|
390 TCmSettingSelection CExtender::GetPolicyServerSelectionL() |
|
391 { |
|
392 |
|
393 // Get policy server details |
|
394 // from the Policy Provision server configuration |
|
395 TAgileProvisionApiServerSettings vpnPolicyServerDetails; |
|
396 User::LeaveIfError(iVpnExtServ.ServerDetails(vpnPolicyServerDetails)); |
|
397 |
|
398 |
|
399 // Return the server selection |
|
400 return vpnPolicyServerDetails.iSelection; |
|
401 } |
|
402 |
|
403 void CExtender::EndTask() |
|
404 { |
|
405 LOG(Log::Printf(_L("CExtender::EndTask\n"))); |
|
406 // Allow the deletion of the CVpnConStarter task handler |
|
407 iVpnConnStarter->SetDelayedTaskEnd(EFalse); |
|
408 |
|
409 // We're done and the enclosing connection starter |
|
410 // object is now free to go (causing the deletion |
|
411 // of this extender object as well) |
|
412 iVpnConnStarter->TaskDone(); |
|
413 } |
|