|
1 /* |
|
2 * Copyright (c) 2004-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: Observes terminals roaming status. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "mpmroamingwatcher.h" |
|
21 #include "mpmlogger.h" |
|
22 |
|
23 // EXTERNAL DATA STRUCTURES |
|
24 // None. |
|
25 |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 // None. |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 // MACROS |
|
32 // None. |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 // None. |
|
36 |
|
37 // MODULE DATA STRUCTURES |
|
38 // None. |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 // None. |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 // None. |
|
45 |
|
46 // ============================= LOCAL FUNCTIONS =============================== |
|
47 // None. |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CMPMRoamingWatcher::CMPMRoamingWatcher |
|
53 // C++ default constructor can NOT contain any code, that might leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CMPMRoamingWatcher::CMPMRoamingWatcher( RMobilePhone& aMobilePhone ) |
|
57 : CActive( CActive::EPriorityStandard ), |
|
58 iMobilePhone( aMobilePhone ), |
|
59 iRegistrationStatus( RMobilePhone::ERegistrationUnknown ), |
|
60 iRoamingStatus( EMPMRoamingStatusUnknown ), |
|
61 iCurrentCountryCode( 0 ), |
|
62 iAskCellularDataUsageAbroad( true ) |
|
63 { |
|
64 MPMLOGSTRING( "CMPMRoamingWatcher::CMPMRoamingWatcher" ) |
|
65 CActiveScheduler::Add( this ); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMPMRoamingWatcher::ConstructL |
|
70 // Symbian 2nd phase constructor can leave. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CMPMRoamingWatcher::ConstructL() |
|
74 { |
|
75 MPMLOGSTRING( "CMPMRoamingWatcher::ConstructL" ) |
|
76 // Retrieve current status |
|
77 TRequestStatus status( KErrNone ); |
|
78 RMobilePhone::TMobilePhoneRegistrationStatus registrationStatus ( RMobilePhone::ERegistrationUnknown ); |
|
79 iMobilePhone.GetNetworkRegistrationStatus( status, registrationStatus ); |
|
80 User::WaitForRequest( status ); |
|
81 |
|
82 if( status.Int() == KErrNone ) |
|
83 { |
|
84 iRoamingStatus = MapRegistrationStatus( registrationStatus ); |
|
85 MPMLOGSTRING2( "CMPMRoamingWatcher::ConstructL iRoamingStatus: %d", iRoamingStatus ) |
|
86 } |
|
87 |
|
88 //Start waiting notification |
|
89 iMobilePhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegistrationStatus ); |
|
90 SetActive(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CMPMRoamingWatcher::NewL |
|
95 // Two-phased constructor. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMPMRoamingWatcher* CMPMRoamingWatcher::NewL( RMobilePhone& aMobilePhone ) |
|
99 { |
|
100 MPMLOGSTRING( "CMPMRoamingWatcher::NewL" ) |
|
101 CMPMRoamingWatcher* self = new( ELeave ) CMPMRoamingWatcher( aMobilePhone ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CMPMRoamingWatcher::~CIpdcRoamingObserver |
|
110 // Destructor. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CMPMRoamingWatcher::~CMPMRoamingWatcher() |
|
114 { |
|
115 MPMLOGSTRING( "CMPMRoamingWatcher::~CMPMRoamingWatcher" ) |
|
116 Cancel(); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CMPMRoamingWatcher::RunL |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CMPMRoamingWatcher::RunL() |
|
125 { |
|
126 MPMLOGSTRING( "CMPMRoamingWatcher::RunL" ) |
|
127 |
|
128 TMPMRoamingStatus roamingStatus = EMPMRoamingStatusUnknown; |
|
129 RMobilePhone::TMobilePhoneRegistrationStatus registrationStatus = RMobilePhone::ERegistrationUnknown; |
|
130 |
|
131 TInt status = iStatus.Int(); |
|
132 |
|
133 //store current value if there was no error |
|
134 if( status == KErrNone ) |
|
135 { |
|
136 registrationStatus = iRegistrationStatus; |
|
137 } |
|
138 |
|
139 //Start listening next status change |
|
140 iMobilePhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegistrationStatus ); |
|
141 SetActive(); |
|
142 |
|
143 //Map current value |
|
144 roamingStatus = MapRegistrationStatus( registrationStatus ); |
|
145 |
|
146 if( roamingStatus != iRoamingStatus ) |
|
147 { |
|
148 iRoamingStatus = roamingStatus; |
|
149 MPMLOGSTRING2( "CMPMRoamingWatcher::RunL iRoamingStatus: %d", iRoamingStatus ) |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CMPMRoamingWatcher::RunError |
|
156 // |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CMPMRoamingWatcher::RunError( TInt /*aError*/ ) |
|
160 { |
|
161 MPMLOGSTRING( "CMPMRoamingWatcher::RunError" ) |
|
162 return KErrNone; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CMPMRoamingWatcher::DoCancel |
|
167 // |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CMPMRoamingWatcher::DoCancel() |
|
171 { |
|
172 MPMLOGSTRING( "CMPMRoamingWatcher::DoCancel" ) |
|
173 iMobilePhone.CancelAsyncRequest( EMobilePhoneNotifyNetworkRegistrationStatusChange ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CMPMRoamingWatcher::MapRegistrationStatus |
|
178 // |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 TMPMRoamingStatus CMPMRoamingWatcher::MapRegistrationStatus( RMobilePhone::TMobilePhoneRegistrationStatus aStatus ) |
|
182 { |
|
183 MPMLOGSTRING( "CMPMRoamingWatcher::MapRegistrationStatus" ) |
|
184 TMPMRoamingStatus roamingStatus = EMPMRoamingStatusUnknown; |
|
185 |
|
186 switch (aStatus) |
|
187 { |
|
188 case RMobilePhone::ERegisteredOnHomeNetwork: |
|
189 { |
|
190 roamingStatus = EMPMHomenetwork; |
|
191 iAskCellularDataUsageAbroad = false; |
|
192 break; |
|
193 } |
|
194 |
|
195 case RMobilePhone::ERegisteredRoaming: |
|
196 { |
|
197 RMobilePhone::TMobilePhoneNetworkInfoV1 network; |
|
198 RMobilePhone::TMobilePhoneNetworkInfoV1Pckg networkPckg( network ); |
|
199 |
|
200 RMobilePhone::TMobilePhoneNetworkInfoV1 homeNetwork; |
|
201 RMobilePhone::TMobilePhoneNetworkInfoV1Pckg homeNetworkPckg( homeNetwork ); |
|
202 |
|
203 TRequestStatus status( KErrNone ); |
|
204 |
|
205 iMobilePhone.GetCurrentNetwork(status, networkPckg); |
|
206 User::WaitForRequest( status ); |
|
207 |
|
208 if(status.Int() == KErrNone) |
|
209 { |
|
210 iMobilePhone.GetHomeNetwork(status, homeNetworkPckg); |
|
211 User::WaitForRequest( status ); |
|
212 |
|
213 if(status.Int() == KErrNone) |
|
214 { |
|
215 RMobilePhone::TMobilePhoneNetworkCountryCode countryCode = network.iCountryCode; |
|
216 |
|
217 if(countryCode.Compare(homeNetwork.iCountryCode) == 0) |
|
218 { |
|
219 roamingStatus = EMPMNationalRoaming; |
|
220 } |
|
221 else |
|
222 { |
|
223 roamingStatus = EMPMInternationalRoaming; |
|
224 // |
|
225 if ( iCurrentCountryCode != countryCode ) |
|
226 { |
|
227 iAskCellularDataUsageAbroad = ETrue; |
|
228 } |
|
229 } |
|
230 iCurrentCountryCode = countryCode; |
|
231 } |
|
232 } |
|
233 break; |
|
234 } |
|
235 |
|
236 default: |
|
237 { |
|
238 roamingStatus = EMPMRoamingStatusUnknown; |
|
239 break; |
|
240 } |
|
241 } |
|
242 MPMLOGSTRING2( "CMPMRoamingWatcher::MapRegistrationStatus roamingStatus: %d", roamingStatus ) |
|
243 |
|
244 return roamingStatus; |
|
245 } |
|
246 |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CMPMRoamingWatcher::RoamingStatus |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TMPMRoamingStatus CMPMRoamingWatcher::RoamingStatus() const |
|
254 { |
|
255 MPMLOGSTRING2( "CMPMRoamingWatcher::RoamingStatus iRoamingStatus: %d", iRoamingStatus ) |
|
256 return iRoamingStatus; |
|
257 } |
|
258 |
|
259 |
|
260 TBool CMPMRoamingWatcher::AskCellularDataUsageAbroad() const |
|
261 { |
|
262 MPMLOGSTRING2( "CMPMRoamingWatcher::AskCellularDataUsageAbroad iAskCellularDataUsageAbroad: %d", iAskCellularDataUsageAbroad ) |
|
263 return iAskCellularDataUsageAbroad; |
|
264 } |
|
265 |
|
266 void CMPMRoamingWatcher::SetAskCellularDataUsageAbroad(TBool aAskUsage) |
|
267 { |
|
268 iAskCellularDataUsageAbroad = aAskUsage; |
|
269 MPMLOGSTRING2( "CMPMRoamingWatcher::SetAskCellularDataUsageAbroad iAskCellularDataUsageAbroad: %d", iAskCellularDataUsageAbroad ) |
|
270 } |
|
271 |
|
272 |
|
273 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
274 // None. |
|
275 |
|
276 // End of File |