|
1 /* |
|
2 * Copyright (c) 2004-2008 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: This is the handler for the SIM Application Toolkit to detect |
|
15 * the SIM card subscriber ID. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <e32svr.h> |
|
22 #include "msatmultimodeapi.h" |
|
23 #include "MSatUtils.h" |
|
24 #include "CSatSSimSubscriberId.h" |
|
25 #include "TSatEventMediator.h" |
|
26 #include "csatsactivewrapper.h" |
|
27 #include "SatLog.h" |
|
28 |
|
29 // MCC and MNC values can be found from numbering plans |
|
30 const TInt KMinImsiLength( 5 ); // MNC + MNC consists of five numbers |
|
31 const TInt KTimeBeforeRetry( 500000 ); // 0.5 seconds. |
|
32 const TInt KMaxRetry( 20 ); |
|
33 |
|
34 // Special IMSI |
|
35 _LIT( KCmccImsiIdentity1, "46000" ); |
|
36 _LIT( KCmccImsiIdentity2, "46002" ); |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CSatSSimSubscriberId::CSatSSimSubscriberId |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CSatSSimSubscriberId::CSatSSimSubscriberId( |
|
47 MSatMultiModeApi& aPhone, |
|
48 TSatEventMediator& aEventMediator ) : |
|
49 CActive( EPriorityStandard ), |
|
50 iPhone( aPhone ), |
|
51 iEventMediator( aEventMediator ), |
|
52 iSubscriberIdValid( EFalse ), |
|
53 iRetryCounter( 0 ) |
|
54 { |
|
55 LOG( SIMPLE, |
|
56 "SATENGINE: CSatSSimSubscriberId::CSatSSimSubscriberId calling" ) |
|
57 |
|
58 // Add to active scheduler. |
|
59 CActiveScheduler::Add( this ); |
|
60 |
|
61 LOG( SIMPLE, |
|
62 "SATENGINE: CSatSSimSubscriberId::CSatSSimSubscriberId exiting" ) |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSatSSimSubscriberId::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CSatSSimSubscriberId::ConstructL() |
|
71 { |
|
72 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::ConstructL calling" ) |
|
73 |
|
74 // Used to suspends the current thread until a 0.5 seconds |
|
75 // interval has expired. |
|
76 iWrapper = new ( ELeave ) CSatSActiveWrapper(); |
|
77 |
|
78 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::ConstructL exiting" ) |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSatSSimSubscriberId::NewL |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CSatSSimSubscriberId* CSatSSimSubscriberId::NewL( |
|
87 MSatMultiModeApi& aPhone, |
|
88 TSatEventMediator& aEventMediator ) |
|
89 { |
|
90 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::NewL calling" ) |
|
91 |
|
92 // Perform construction. |
|
93 CSatSSimSubscriberId* self = new ( ELeave ) CSatSSimSubscriberId( |
|
94 aPhone, |
|
95 aEventMediator ); |
|
96 |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL(); |
|
99 CleanupStack::Pop( self ); |
|
100 |
|
101 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::NewL exiting" ) |
|
102 return self; |
|
103 } |
|
104 |
|
105 |
|
106 // Destructor |
|
107 CSatSSimSubscriberId::~CSatSSimSubscriberId() |
|
108 { |
|
109 LOG( SIMPLE, |
|
110 "SATENGINE: CSatSSimSubscriberId::~CSatSSimSubscriberId calling" ) |
|
111 |
|
112 if ( iWrapper ) |
|
113 { |
|
114 iWrapper->CancelWrapper(); |
|
115 delete iWrapper; |
|
116 iWrapper = NULL; |
|
117 } |
|
118 |
|
119 // Cancel any outstanding requests. |
|
120 Cancel(); |
|
121 |
|
122 LOG( SIMPLE, |
|
123 "SATENGINE: CSatSSimSubscriberId::~CSatSSimSubscriberId exiting" ) |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CSatSSimSubscriberId::Start |
|
128 // Starts the handler initially. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CSatSSimSubscriberId::Start() |
|
132 { |
|
133 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::Start calling" ) |
|
134 |
|
135 iRetryCounter = KMaxRetry; |
|
136 DoStart(); |
|
137 |
|
138 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::Start exiting" ) |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CSatSSimSubscriberId::DoStart |
|
143 // Starts the handler. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CSatSSimSubscriberId::DoStart() |
|
147 { |
|
148 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::DoStart calling" ) |
|
149 |
|
150 if ( !IsActive() ) |
|
151 { |
|
152 iSubscriberIdValid = EFalse; |
|
153 iPhone.GetSubscriberId( iStatus, iSubscriberId ); |
|
154 LOG( SIMPLE, "SATENGINE: GetSubscriberId called" ) |
|
155 SetActive(); |
|
156 } |
|
157 |
|
158 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::DoStart exiting" ) |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CSatSSimSubscriberId::RunL |
|
163 // Handles the command. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CSatSSimSubscriberId::RunL() |
|
167 { |
|
168 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::RunL calling" ) |
|
169 |
|
170 // Check the status of the asnychronous operation. |
|
171 TInt status( iStatus.Int() ); |
|
172 if ( KErrNone == status ) |
|
173 { |
|
174 // Indicate id successfully read. |
|
175 iSubscriberIdValid = ETrue; |
|
176 |
|
177 // Handle special SIM. |
|
178 if ( IsCmccSIM() ) |
|
179 { |
|
180 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::RunL Cmcc SIM" ) |
|
181 // Activate SetUpMenuHandler for special SIM. |
|
182 iEventMediator.Notify( MSatUtils::ECmccSimDetected ); |
|
183 } |
|
184 } |
|
185 else if ( ( KErrServerBusy == status ) || |
|
186 ( KErrNotFound == status ) ) |
|
187 { |
|
188 LOG2( SIMPLE, |
|
189 "SATENGINE: CSatSSimSubscriberId::RunL Server busy (%d)", status ) |
|
190 |
|
191 if ( iRetryCounter > 0 ) |
|
192 { |
|
193 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::RunL \ |
|
194 iRetryCounter > 0" ) |
|
195 iRetryCounter--; |
|
196 |
|
197 // Restart subscriber ID reading after short period of time. |
|
198 if ( iWrapper ) |
|
199 { |
|
200 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::RunL \ |
|
201 iWrapper true" ) |
|
202 iWrapper->After( KTimeBeforeRetry ); |
|
203 } |
|
204 |
|
205 DoStart(); |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 LOG2( SIMPLE, |
|
211 "SATENGINE: CSatSSimSubscriberId::RunL error: %d", status ) |
|
212 } |
|
213 |
|
214 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::RunL exiting" ) |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CSatSSimSubscriberId::DoCancel |
|
219 // Cancels the pending request. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CSatSSimSubscriberId::DoCancel() |
|
223 { |
|
224 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::DoCancel calling" ) |
|
225 |
|
226 // Cancel an outstanding request. |
|
227 iPhone.CancelAsyncRequest( EMobilePhoneGetSubscriberId ); |
|
228 |
|
229 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::DoCancel exiting" ) |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CSatSSimSubscriberId::IsCmccSIM |
|
234 // Check if the used SIM card is special SIM |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CSatSSimSubscriberId::IsCmccSIM() const |
|
238 { |
|
239 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::IsCmccSIM calling" ) |
|
240 TBool isCmcc( EFalse ); |
|
241 |
|
242 // Check validity. |
|
243 if ( iSubscriberIdValid ) |
|
244 { |
|
245 if ( iSubscriberId.Length() >= KMinImsiLength ) |
|
246 { |
|
247 LOG( SIMPLE, "SATENGINE: \ |
|
248 CSatSSimSubscriberId::IsCmccSIM length valid" ) |
|
249 isCmcc = ( |
|
250 ( iSubscriberId.Left( KMinImsiLength ). |
|
251 Compare( KCmccImsiIdentity1 ) == KErrNone ) || |
|
252 ( iSubscriberId.Left( KMinImsiLength ). |
|
253 Compare( KCmccImsiIdentity2 ) == KErrNone ) ); |
|
254 } |
|
255 } |
|
256 |
|
257 else |
|
258 { |
|
259 LOG( SIMPLE, "SATENGINE: CSatSSimSubscriberId::IsCmccSIM Not valid" ) |
|
260 } |
|
261 |
|
262 LOG2( |
|
263 SIMPLE, |
|
264 "SATENGINE: CSatSSimSubscriberId::IsCmccSIM exiting: %i", |
|
265 isCmcc ) |
|
266 |
|
267 return isCmcc; |
|
268 } |