|
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: Implements simcontrol key sequence handling. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <qsysteminfo.h> |
|
19 #include <qmobilityglobal.h> |
|
20 #include <secui.h> |
|
21 #include <secuimanualsecuritysettings.h> |
|
22 #include "keysequencerecognitionservicedefs.h" |
|
23 #include "keysequencerecognitionservicelog.h" |
|
24 #include "simcontrolkeysequencehandler.h" |
|
25 |
|
26 |
|
27 //QTM_USE_NAMESPACE |
|
28 |
|
29 /*! |
|
30 SimControlKeySequenceHandler::SimControlKeySequenceHandler. |
|
31 */ |
|
32 SimControlKeySequenceHandler::SimControlKeySequenceHandler( |
|
33 QObject* parent) |
|
34 : |
|
35 KeySequenceHandler(parent), |
|
36 m_securityModel(0) |
|
37 { |
|
38 DPRINT_METHODENTRYEXIT; |
|
39 |
|
40 setKeySequenceValidator(KCodeChangePin1 + "|" + |
|
41 KCodeChangePin2 + "|" + |
|
42 KCodeUnblockPin1 + "|" + |
|
43 KCodeUnblockPin2); |
|
44 |
|
45 QT_TRAP_THROWING(TSecUi::InitializeLibL()); |
|
46 QT_TRAP_THROWING( m_securityModel = CManualSecuritySettings::NewL() ); |
|
47 } |
|
48 |
|
49 |
|
50 /*! |
|
51 SimControlKeySequenceHandler::~SimControlKeySequenceHandler. |
|
52 */ |
|
53 SimControlKeySequenceHandler::~SimControlKeySequenceHandler() |
|
54 { |
|
55 DPRINT_METHODENTRYEXIT; |
|
56 |
|
57 delete m_securityModel; |
|
58 TSecUi::UnInitializeLib(); |
|
59 } |
|
60 |
|
61 |
|
62 /*! |
|
63 SimControlKeySequenceHandler::executeKeySequence. |
|
64 */ |
|
65 bool SimControlKeySequenceHandler::executeKeySequence( |
|
66 const QString &keySequence) |
|
67 { |
|
68 DPRINT_METHODENTRYEXIT; |
|
69 |
|
70 bool handled = parseString( keySequence ); |
|
71 |
|
72 return handled; |
|
73 } |
|
74 |
|
75 |
|
76 |
|
77 bool SimControlKeySequenceHandler::parseString(const QString &keySequence) |
|
78 { |
|
79 DPRINT_METHODENTRYEXIT; |
|
80 |
|
81 const QString KChangePin1("**04*"); |
|
82 const QString KChangePin2("**042"); |
|
83 const QString KUnblockPin1("**05*"); |
|
84 const QString KUnblockPin2("**052"); |
|
85 |
|
86 QString oldPin; |
|
87 QString newPin; |
|
88 QString verifyNewPin; |
|
89 QString puk; |
|
90 |
|
91 SimOperation operation; |
|
92 bool handled = false; |
|
93 |
|
94 QString keySequencePrefix (keySequence); |
|
95 |
|
96 //Get first 5 chars from keysequence string |
|
97 keySequencePrefix.chop(keySequencePrefix.length()-5); |
|
98 QRegExp expression(QRegExp::escape(keySequencePrefix)); |
|
99 |
|
100 QString parsedKeySequence(keySequence); |
|
101 |
|
102 //remove '#' from end |
|
103 parsedKeySequence.chop(1); |
|
104 |
|
105 QStringList pins; |
|
106 |
|
107 if (expression.exactMatch(KChangePin1) || expression.exactMatch(KChangePin2)) |
|
108 { |
|
109 if (expression.exactMatch(KChangePin1)) |
|
110 { |
|
111 parsedKeySequence.remove(0, 5); |
|
112 operation = Pin1; |
|
113 } |
|
114 |
|
115 if (expression.exactMatch(KChangePin2)) |
|
116 { |
|
117 parsedKeySequence.remove(0, 6); |
|
118 operation = Pin2; |
|
119 } |
|
120 pins = parsedKeySequence.split("*"); |
|
121 oldPin= pins.value(0); |
|
122 newPin = pins.value(1); |
|
123 verifyNewPin = pins.value(2); |
|
124 handled = true; |
|
125 processChangePin(operation, oldPin, newPin, verifyNewPin); |
|
126 } |
|
127 |
|
128 if (expression.exactMatch(KUnblockPin1) || expression.exactMatch(KUnblockPin2)) |
|
129 { |
|
130 if ( expression.exactMatch(KUnblockPin1)) |
|
131 { |
|
132 parsedKeySequence.remove(0, 5); |
|
133 operation = Pin1; |
|
134 } |
|
135 |
|
136 if (expression.exactMatch(KUnblockPin2)) |
|
137 { |
|
138 parsedKeySequence.remove(0, 6); |
|
139 operation = Pin2; |
|
140 } |
|
141 |
|
142 pins = parsedKeySequence.split("*"); |
|
143 puk = pins.value(0); |
|
144 newPin = pins.value(1); |
|
145 verifyNewPin = pins.value(2); |
|
146 handled = true; |
|
147 processUnblockPin(operation, puk, newPin, verifyNewPin); |
|
148 } |
|
149 |
|
150 return handled; |
|
151 } |
|
152 |
|
153 void SimControlKeySequenceHandler::processChangePin(SimOperation operation, QString oldPin, |
|
154 QString newPin, QString verifyNew) |
|
155 { |
|
156 CManualSecuritySettings::TPin pin; |
|
157 |
|
158 if(operation == Pin1) |
|
159 { |
|
160 pin = CManualSecuritySettings::EPin1; |
|
161 } |
|
162 else |
|
163 { |
|
164 pin = CManualSecuritySettings::EPin2; |
|
165 } |
|
166 |
|
167 TBuf<200> oldPinBuf(oldPin.utf16()); |
|
168 TBuf<200> newPinBuf(newPin.utf16()); |
|
169 TBuf<200> verifyNewBuf(verifyNew.utf16()); |
|
170 |
|
171 QT_TRAP_THROWING(m_securityModel->ChangePinL(pin, oldPinBuf, newPinBuf, verifyNewBuf)); |
|
172 } |
|
173 |
|
174 |
|
175 void SimControlKeySequenceHandler::processUnblockPin(SimOperation operation, QString puk, QString newPin, |
|
176 QString verifyNew) |
|
177 { |
|
178 CManualSecuritySettings::TPin pin; |
|
179 |
|
180 if(operation == Pin1) |
|
181 { |
|
182 pin = CManualSecuritySettings::EPin1; |
|
183 } |
|
184 else |
|
185 { |
|
186 pin= CManualSecuritySettings::EPin2; |
|
187 } |
|
188 |
|
189 TBuf<200> pukBuf(puk.utf16()); |
|
190 TBuf<200> newPinBuf(newPin.utf16()); |
|
191 TBuf<200> verifyNewBuf(verifyNew.utf16()); |
|
192 |
|
193 |
|
194 QT_TRAP_THROWING(m_securityModel->UnblockPinL(pin, pukBuf, newPinBuf, verifyNewBuf)); |
|
195 } |