|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <etelmm.h> |
|
19 #include <commsdattypesv1_1.h> |
|
20 |
|
21 #include "cradionetworkinfolistener.h" |
|
22 #include "mradiosettingssetter.h" |
|
23 #include "cradioenginelogger.h" |
|
24 |
|
25 using namespace CommsDat; |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CRadioNetworkInfoListener* CRadioNetworkInfoListener::NewL( MRadioSettingsSetter& aSetter, |
|
35 MRadioNetworkChangeObserver* aObserver ) |
|
36 { |
|
37 CRadioNetworkInfoListener* self = new ( ELeave ) CRadioNetworkInfoListener( aSetter, aObserver ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CRadioNetworkInfoListener::CRadioNetworkInfoListener( MRadioSettingsSetter& aSetter, |
|
49 MRadioNetworkChangeObserver* aObserver ) |
|
50 : CActive( CActive::EPriorityHigh ) |
|
51 , iSetter( aSetter ) |
|
52 , iObserver( aObserver ) |
|
53 , iSubscriberIdPckg( iSubscriberId ) |
|
54 , iNetworkInfoPckg( iNetworkInfo ) |
|
55 { |
|
56 CActiveScheduler::Add( this ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CRadioNetworkInfoListener::ConstructL() |
|
64 { |
|
65 LOG_METHOD_AUTO; |
|
66 #ifndef __WINS__ |
|
67 iTelephony = CTelephony::NewL(); |
|
68 |
|
69 // Initialize the default network id and country code directly from CommsDat, as CTelephony cannot be used in synchronous mode |
|
70 // and using it in async mode will cause problems in core initialisation, and too much complexity! |
|
71 |
|
72 // Get default TSY from database. |
|
73 |
|
74 CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion()); |
|
75 CleanupStack::PushL( db ); |
|
76 |
|
77 CMDBRecordSet<CCDModemBearerRecord>* set = new ( ELeave ) CMDBRecordSet<CCDModemBearerRecord>( KCDTIdModemBearerRecord ); |
|
78 CleanupStack::PushL( set ); |
|
79 |
|
80 set->LoadL( *db ); |
|
81 |
|
82 TInt index = 0; |
|
83 CCDModemBearerRecord* record = static_cast<CCDModemBearerRecord*>( set->iRecords[index++]); |
|
84 |
|
85 if ( record->iTsyName.IsNull() && set->iRecords.Count() > index ) // the first item is normally only a template |
|
86 { |
|
87 record = static_cast<CCDModemBearerRecord*>( set->iRecords[index++]); |
|
88 } |
|
89 |
|
90 TPtrC name( static_cast<const TDesC&>( record->iTsyName )); |
|
91 TBuf<50> tsyName; |
|
92 tsyName.Copy( name ); |
|
93 |
|
94 LOG_FORMAT( "CRadioNetworkInfoListener::ConstructL, TSY name: %S", &tsyName ); |
|
95 CleanupStack::PopAndDestroy( set ); |
|
96 CleanupStack::PopAndDestroy( db ); |
|
97 |
|
98 RTelServer telServer; |
|
99 CleanupClosePushL( telServer ); |
|
100 RMobilePhone mobilePhone; |
|
101 CleanupClosePushL( mobilePhone ); |
|
102 |
|
103 // Open phone |
|
104 User::LeaveIfError( telServer.Connect()); |
|
105 |
|
106 // TSY module gets automatically unloaded when tel.Close() is called ( and tel is is CU-stack ), |
|
107 // so loaded TSY is also leave-safe |
|
108 User::LeaveIfError( telServer.LoadPhoneModule( tsyName )); |
|
109 |
|
110 // Get number of phones. |
|
111 TInt phones( 0 ); |
|
112 User::LeaveIfError( telServer.EnumeratePhones( phones )); |
|
113 LOG_FORMAT( "CRadioNetworkInfoListener::ConstructL, Number of phones=%d", phones ); |
|
114 |
|
115 // Get phone info of first legal phone. |
|
116 TInt legalPhoneIndex = KErrNotFound; |
|
117 RTelServer::TPhoneInfo phoneInfo; |
|
118 for ( TInt i=0; i<phones && legalPhoneIndex == KErrNotFound; i++) |
|
119 { |
|
120 if ( telServer.GetPhoneInfo( i, phoneInfo ) == KErrNone ) |
|
121 { |
|
122 if ( phoneInfo.iNetworkType == RTelServer::ENetworkTypeMobileDigital ) |
|
123 { |
|
124 legalPhoneIndex = i; |
|
125 } |
|
126 } |
|
127 } |
|
128 User::LeaveIfError( legalPhoneIndex ); |
|
129 |
|
130 // Open legal phone. |
|
131 User::LeaveIfError( mobilePhone.Open( telServer, phoneInfo.iName )); |
|
132 |
|
133 TUint32 networkCaps; |
|
134 User::LeaveIfError( mobilePhone.GetNetworkCaps( networkCaps )); |
|
135 TUint32 identityCaps; |
|
136 User::LeaveIfError( mobilePhone.GetIdentityCaps( identityCaps )); |
|
137 // Check if we are allowed to get network info. |
|
138 if ( networkCaps & RMobilePhone::KCapsGetCurrentNetwork ) |
|
139 { |
|
140 // Gather initial information synchronically. |
|
141 RMobilePhone::TMobilePhoneLocationAreaV1 location; |
|
142 |
|
143 RMobilePhone::TMobilePhoneNetworkInfoV1 networkInfo; |
|
144 RMobilePhone::TMobilePhoneNetworkInfoV1Pckg networkInfoPckg( networkInfo ); |
|
145 |
|
146 mobilePhone.GetCurrentNetwork( iStatus, networkInfoPckg, location ); |
|
147 User::WaitForRequest( iStatus ); |
|
148 |
|
149 CTelephony::TNetworkInfoV1 telephonyNetworkInfo; |
|
150 if ( iStatus == KErrNone ) |
|
151 { |
|
152 telephonyNetworkInfo.iMode = static_cast<CTelephony::TNetworkMode>( networkInfo.iMode ); |
|
153 telephonyNetworkInfo.iCountryCode = networkInfo.iCountryCode; |
|
154 telephonyNetworkInfo.iCdmaSID = networkInfo.iCdmaSID; |
|
155 telephonyNetworkInfo.iNetworkId = networkInfo.iNetworkId; |
|
156 } |
|
157 else |
|
158 { |
|
159 telephonyNetworkInfo.iCountryCode = iSetter.CountryCode(); |
|
160 telephonyNetworkInfo.iNetworkId = iSetter.NetworkId(); |
|
161 } |
|
162 iNetworkInfoPckg() = telephonyNetworkInfo; |
|
163 } |
|
164 else |
|
165 { |
|
166 // Leave if we are not allowed to get network info. |
|
167 // Other action could also be considered!!!! |
|
168 User::Leave( KErrNotSupported ); |
|
169 } |
|
170 |
|
171 if ( identityCaps & RMobilePhone::KCapsGetSubscriberId ) |
|
172 { |
|
173 TRequestStatus stat; |
|
174 RMobilePhone::TMobilePhoneSubscriberId subscriberId; |
|
175 mobilePhone.GetSubscriberId( stat, subscriberId ); |
|
176 User::WaitForRequest( stat ); |
|
177 |
|
178 CTelephony::TSubscriberIdV1 telephonySubscriberId; |
|
179 |
|
180 if ( stat == KErrNone ) |
|
181 { |
|
182 telephonySubscriberId.iSubscriberId = subscriberId; |
|
183 } |
|
184 else |
|
185 { |
|
186 telephonySubscriberId.iSubscriberId = iSetter.SubscriberId(); |
|
187 } |
|
188 |
|
189 iSubscriberIdPckg() = telephonySubscriberId; |
|
190 } |
|
191 |
|
192 CleanupStack::PopAndDestroy( 2, &telServer ); |
|
193 #endif |
|
194 // At the end, update the local variables by simulating the "netid changed" event. |
|
195 RunL(); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 CRadioNetworkInfoListener::~CRadioNetworkInfoListener() |
|
203 { |
|
204 Cancel(); |
|
205 |
|
206 #ifndef __WINS__ |
|
207 delete iTelephony; |
|
208 #endif |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 TInt CRadioNetworkInfoListener::CompoundNetworkId() const |
|
216 { |
|
217 LOG_FORMAT( "CRadioNetworkInfoListener::CompoundNetworkId() - %d", iCompoundNetworkId ); |
|
218 return iCompoundNetworkId; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 TPtrC CRadioNetworkInfoListener::SubscriberId() const |
|
226 { |
|
227 TPtrC id = iSubscriberId.iSubscriberId; |
|
228 LOG_FORMAT( "CRadioNetworkInfoListener::SubscriberId() - %S", &id ); |
|
229 return id; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TPtrC CRadioNetworkInfoListener::CountryCode() const |
|
237 { |
|
238 TPtrC countryCode = iSetter.CountryCode(); |
|
239 LOG_FORMAT( "CRadioNetworkInfoListener::CountryCode() - %S", &countryCode ); |
|
240 return countryCode; |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CRadioNetworkInfoListener::SaveNetworkInfoL() |
|
248 { |
|
249 #ifdef __WINS__ |
|
250 iNetworkInfo.iCountryCode.Copy( _L("244") ); |
|
251 iNetworkInfo.iNetworkId.Zero(); |
|
252 #endif |
|
253 |
|
254 LOG_FORMAT( "CRadioNetworkInfoListener::SaveNetworkInfoL() - iNetworkInfo.iCountryCode = %S", |
|
255 &iNetworkInfo.iCountryCode ); |
|
256 |
|
257 User::LeaveIfError( iSetter.SetCountryCode( iNetworkInfo.iCountryCode ) ); |
|
258 |
|
259 // The compound network identifier is composed of the current network identifier and country code. |
|
260 TBuf<KDefaultRealWidth> compoundNetworkId; |
|
261 compoundNetworkId.Append( iSetter.CountryCode() ); |
|
262 if ( iNetworkInfo.iNetworkId.Length() < 2 ) |
|
263 { |
|
264 // Network identifier has only one digit, in which case it must be prepended with a zero. |
|
265 compoundNetworkId.AppendNum( 0 ); |
|
266 } |
|
267 |
|
268 compoundNetworkId.Append( iNetworkInfo.iNetworkId ); |
|
269 |
|
270 TLex lex( compoundNetworkId ); |
|
271 User::LeaveIfError( lex.Val( iCompoundNetworkId ) ); |
|
272 |
|
273 if ( iCompoundNetworkId != 0 && iPreviousCompoundNetworkId != iCompoundNetworkId ) |
|
274 { |
|
275 if ( iPreviousCompoundNetworkId != 0 && iObserver ) |
|
276 { |
|
277 iObserver->NetworkIdChanged(); |
|
278 } |
|
279 iPreviousCompoundNetworkId = iCompoundNetworkId; |
|
280 } |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CRadioNetworkInfoListener::DoCancel() |
|
288 { |
|
289 #ifndef __WINS__ |
|
290 iTelephony->CancelAsync( CTelephony::ECurrentNetworkInfoChangeCancel ); |
|
291 #endif |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 void CRadioNetworkInfoListener::RunL() |
|
299 { |
|
300 LOG_FORMAT( "CRadioNetworkInfoListener::RunL() - iStatus.Int() = %d", iStatus.Int() ); |
|
301 #ifndef __WINS__ |
|
302 iTelephony->NotifyChange( iStatus, CTelephony::ECurrentNetworkInfoChange, iNetworkInfoPckg ); |
|
303 SetActive(); |
|
304 #endif |
|
305 SaveNetworkInfoL(); |
|
306 } |