|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Network selection dialog controller |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <networkhandlingproxy.h> |
|
20 #include <cnwsession.h> |
|
21 #include <centralrepository.h> |
|
22 #include <e32property.h> |
|
23 |
|
24 #include <ProfileEngineSDKCRKeys.h> |
|
25 #include <BTSapDomainPSKeys.h> |
|
26 |
|
27 #include "ainwsdlgcontroller.h" |
|
28 #include "debug.h" |
|
29 |
|
30 |
|
31 // 1-minute timeout before showing soft notification |
|
32 const TInt KPhoneNetworkLostTimeout = 60*1000000; |
|
33 |
|
34 // Offline profile, from ProfileEngineSDKCRKeys.h |
|
35 const TInt KOfflineProfileId = 5; |
|
36 |
|
37 |
|
38 CAiNwSDlgController* CAiNwSDlgController::NewL() |
|
39 { |
|
40 CAiNwSDlgController* self = new(ELeave) CAiNwSDlgController(); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(); // self |
|
44 return self; |
|
45 } |
|
46 |
|
47 CAiNwSDlgController::CAiNwSDlgController() |
|
48 { |
|
49 iRegistered = ETrue; |
|
50 } |
|
51 |
|
52 void CAiNwSDlgController::ConstructL() |
|
53 { |
|
54 __PRINTS( "XAI: CAiNwSDlgController is initializing" ); |
|
55 |
|
56 iSoftNotifier = CAknSoftNotifier::NewL(); |
|
57 iSession = CreateL( *this, iInfo ); |
|
58 iProfileApi = CRepository::NewL( KCRUidProfileEngine ); |
|
59 iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
60 |
|
61 HandleStateChange(); |
|
62 |
|
63 __PRINTS( "XAI: CAiNwSDlgController initialized succesfully" ); |
|
64 } |
|
65 |
|
66 CAiNwSDlgController::~CAiNwSDlgController() |
|
67 { |
|
68 delete iPeriodic; |
|
69 delete iProfileApi; |
|
70 delete iSession; |
|
71 delete iSoftNotifier; |
|
72 } |
|
73 |
|
74 void CAiNwSDlgController::HandleStateChange() |
|
75 { |
|
76 switch( iInfo.iRegistrationStatus ) |
|
77 { |
|
78 case ENWNotRegisteredNoService: |
|
79 // Fall-through |
|
80 case ENWNotRegisteredEmergencyOnly: |
|
81 // Fall-through |
|
82 case ENWNotRegisteredSearching: |
|
83 // Fall-through |
|
84 case ENWRegistrationDenied: |
|
85 HandleNetworkLost(); |
|
86 break; |
|
87 |
|
88 case ENWRegisteredBusy: |
|
89 // Fall-through |
|
90 case ENWRegisteredOnHomeNetwork: |
|
91 // Fall-through |
|
92 case ENWRegisteredRoaming: |
|
93 HandleNetworkFound(); |
|
94 break; |
|
95 |
|
96 case ENWRegistrationUnknown: |
|
97 // Take no action |
|
98 default: |
|
99 break; |
|
100 } |
|
101 } |
|
102 |
|
103 void CAiNwSDlgController::HandleNetworkFound() |
|
104 { |
|
105 __PRINTS( "XAI: Network found" ); |
|
106 iRegistered = ETrue; |
|
107 iPeriodic->Cancel(); |
|
108 CancelDialog(); |
|
109 } |
|
110 |
|
111 void CAiNwSDlgController::HandleNetworkLost() |
|
112 { |
|
113 if( iInfo.iSelectionSetting == ENWNetworkSelectionManual ) |
|
114 { |
|
115 // See if we were registered before |
|
116 if( iRegistered ) |
|
117 { |
|
118 iRegistered = EFalse; |
|
119 |
|
120 if(!IsOffLineMode() && !IsBluetoothSAPConnected()) |
|
121 { |
|
122 __PRINTS( "XAI: Network lost, show dialog in 1 minute" ); |
|
123 iPeriodic->Start( KPhoneNetworkLostTimeout, |
|
124 KPhoneNetworkLostTimeout, TCallBack( DelayCallBack, this )); |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 void CAiNwSDlgController::LaunchDialog() |
|
131 { |
|
132 iPeriodic->Cancel(); |
|
133 TRAP_IGNORE( iSoftNotifier->AddNotificationL( ESelectNetworkNotification, 1 ); ); |
|
134 } |
|
135 |
|
136 void CAiNwSDlgController::CancelDialog() |
|
137 { |
|
138 TRAP_IGNORE( iSoftNotifier->CancelSoftNotificationL( ESelectNetworkNotification ); ); |
|
139 } |
|
140 |
|
141 TInt CAiNwSDlgController::DelayCallBack(TAny* aParam) |
|
142 { |
|
143 CAiNwSDlgController* self = (CAiNwSDlgController*) aParam; |
|
144 self->LaunchDialog(); |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 void CAiNwSDlgController::HandleNetworkMessage( const TNWMessages aMessage ) |
|
149 { |
|
150 switch(aMessage) |
|
151 { |
|
152 case ENWMessageNetworkRegistrationStatusChange: |
|
153 HandleStateChange(); |
|
154 break; |
|
155 |
|
156 default: |
|
157 break; |
|
158 } |
|
159 } |
|
160 |
|
161 void CAiNwSDlgController::HandleNetworkError( const TNWOperation /*aOperation*/, |
|
162 TInt /*aErrorCode*/ ) |
|
163 { |
|
164 // Take no action. |
|
165 } |
|
166 |
|
167 TBool CAiNwSDlgController::IsOffLineMode() const |
|
168 { |
|
169 TInt profileId; |
|
170 TInt err = iProfileApi->Get( KProEngActiveProfile, profileId ); |
|
171 return profileId == KOfflineProfileId && err == KErrNone; |
|
172 } |
|
173 |
|
174 TBool CAiNwSDlgController::IsBluetoothSAPConnected() const |
|
175 { |
|
176 TInt btSapState( EBTSapNotConnected ); |
|
177 TInt err = RProperty::Get( KPSUidBluetoothSapConnectionState, |
|
178 KBTSapConnectionState, |
|
179 btSapState ); |
|
180 return btSapState != EBTSapNotConnected && err == KErrNone; |
|
181 } |
|
182 |
|
183 // End of file. |