|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <iaupdate.rsg> |
|
20 #include <StringLoader.h> |
|
21 #include <aknmessagequerydialog.h> |
|
22 #include <aknnotewrappers.h> |
|
23 #include <DevManInternalCRKeys.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include "iaupdatefwupdatehandler.h" |
|
27 #include "iaupdatefwfotamodel.h" |
|
28 #include "iaupdatefwsyncprofile.h" |
|
29 #include "iaupdatefwsyncappengine.h" |
|
30 #include "iaupdateprivatecrkeys.h" |
|
31 #include "iaupdatefwdebug.h" |
|
32 #include "iaupdatefwconst.h" //ESASyncStateDisable |
|
33 #include "iaupdatefwnsmlpskeys.h" |
|
34 #include "iaupdatefwnsmlcrkeys.h" |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CIAUpdateFWUpdateHandler::NewLC() |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CIAUpdateFWUpdateHandler* CIAUpdateFWUpdateHandler::NewLC() |
|
41 { |
|
42 CIAUpdateFWUpdateHandler* self = new(ELeave)CIAUpdateFWUpdateHandler(); |
|
43 CleanupStack::PushL( self); |
|
44 self->ConstructL(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CIAUpdateFWUpdateHandler::NewL() |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CIAUpdateFWUpdateHandler* CIAUpdateFWUpdateHandler::NewL() |
|
54 { |
|
55 CIAUpdateFWUpdateHandler* self = CIAUpdateFWUpdateHandler::NewLC(); |
|
56 CleanupStack::Pop(self); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CIAUpdateFWUpdateHandler::~CIAUpdateFWUpdateHandler() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CIAUpdateFWUpdateHandler::~CIAUpdateFWUpdateHandler() |
|
66 { |
|
67 TInt err = RProperty::Delete(KPSUidNSmlDMSyncApp,KNSmlCurrentFotaUpdateAppName); |
|
68 delete iFotaModel; |
|
69 delete iDMEngine; |
|
70 } |
|
71 |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CIAUpdateFWUpdateHandler::FirmWareUpdatewithNSU() |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C void CIAUpdateFWUpdateHandler::FirmWareUpdatewithNSU() |
|
78 { |
|
79 iRequest = ENSU; |
|
80 iStatus = KRequestPending; |
|
81 TRequestStatus* status = &iStatus; |
|
82 |
|
83 SetActive(); |
|
84 User::RequestComplete( status, KErrNone ); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CIAUpdateFWUpdateHandler::IsDMSupportAvailableL() |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C TBool CIAUpdateFWUpdateHandler::IsDMSupportAvailableL() |
|
92 { |
|
93 return iFotaModel->IsDMSupportAvailableL(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CIAUpdateFWUpdateHandler::FirmWareUpdatewithFOTA() |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C void CIAUpdateFWUpdateHandler::FirmWareUpdatewithFOTA() |
|
101 { |
|
102 iRequest = EFOTA; |
|
103 iStatus = KRequestPending; |
|
104 TRequestStatus* status = &iStatus; |
|
105 |
|
106 SetActive(); |
|
107 User::RequestComplete( status, KErrNone ); |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CIAUpdateFWUpdateHandler::CIAUpdateFWUpdateHandler() |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CIAUpdateFWUpdateHandler::CIAUpdateFWUpdateHandler():CActive( EPriorityNormal ) |
|
116 { |
|
117 CActiveScheduler::Add( this ); |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CIAUpdateFWUpdateHandler::ConstructL() |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CIAUpdateFWUpdateHandler::ConstructL() |
|
126 { |
|
127 iFotaModel = CIAUpdateFWFotaModel::NewL(); |
|
128 iDMEngine = CIAUpdateFWSyncAppEngine::NewL( iFotaModel ); |
|
129 } |
|
130 |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CIAUpdateFWUpdateHandler::RunL() |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CIAUpdateFWUpdateHandler::RunL() |
|
137 { |
|
138 switch ( iRequest ) |
|
139 { |
|
140 case ENSU: |
|
141 { |
|
142 HBufC* text1 = StringLoader::LoadLC( R_IAUPDATE_INFO_NSU_1 ); |
|
143 HBufC* text2 = StringLoader::LoadLC( R_IAUPDATE_INFO_NSU_2 ); |
|
144 |
|
145 HBufC* text = HBufC::NewLC( text1->Length() + |
|
146 text2->Length() ); |
|
147 |
|
148 text->Des() += *text1; |
|
149 text->Des() += *text2; |
|
150 |
|
151 HBufC* heading = StringLoader::LoadLC( R_IAUPDATE_NEW_SW_TITLE ); |
|
152 |
|
153 ShowDialogL( *text, *heading ); |
|
154 |
|
155 CleanupStack::PopAndDestroy( heading ); //text, heading |
|
156 CleanupStack::PopAndDestroy( text ); |
|
157 CleanupStack::PopAndDestroy( text2 ); |
|
158 CleanupStack::PopAndDestroy( text1 ); |
|
159 |
|
160 break; |
|
161 } |
|
162 case EFOTA: |
|
163 { |
|
164 //check whether FOTA engine is available at the moment |
|
165 TBool isDmActive = EFalse; |
|
166 |
|
167 TInt fotamodelstate = iFotaModel->GetCurrentFwUpdState(); |
|
168 |
|
169 FLOG_NUM( "[IAUPDATEFW] fota status = %d", fotamodelstate ); |
|
170 |
|
171 if ( fotamodelstate != RFotaEngineSession::EIdle ) |
|
172 { |
|
173 //if status is downloadcomplete or startingupdate |
|
174 //still allow user to continue |
|
175 if ( ( fotamodelstate != RFotaEngineSession::EDownloadComplete ) && ( fotamodelstate != RFotaEngineSession::EStartingUpdate ) ) |
|
176 { |
|
177 isDmActive = ETrue; |
|
178 } |
|
179 } |
|
180 |
|
181 if ( isDmActive ) |
|
182 { |
|
183 FLOG( "[IAUPDATEFW] CIAUpdateFWUpdateHandler::RunL DM is activated" ); |
|
184 return; |
|
185 } |
|
186 |
|
187 TInt profileId( KErrNotFound ); |
|
188 |
|
189 profileId = iFotaModel->DefaultFotaProfileIdL(); |
|
190 |
|
191 if (KErrNotFound != profileId) |
|
192 { |
|
193 // Define the key KNSmlCurrentFotaUpdateAppName |
|
194 TInt err = RProperty::Define( KPSUidNSmlDMSyncApp, |
|
195 KNSmlCurrentFotaUpdateAppName, |
|
196 RProperty::EInt); |
|
197 |
|
198 RProperty::Set(KPSUidNSmlDMSyncApp,KNSmlCurrentFotaUpdateAppName,1 ); |
|
199 |
|
200 iFotaModel->EnableFwUpdRequestL( profileId ); |
|
201 StartSyncL( profileId, EFalse ); |
|
202 } |
|
203 else |
|
204 { |
|
205 FLOG( "[IAUPDATEFW] CIAUpdateFWUpdateHandler::RunL no DM profile available!" ); |
|
206 } |
|
207 } |
|
208 break; |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CIAUpdateFWUpdateHandler::DoCancel() |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CIAUpdateFWUpdateHandler::DoCancel() |
|
218 { |
|
219 } |
|
220 |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CIAUpdateFWUpdateHandler::ShowDialogL() |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CIAUpdateFWUpdateHandler::ShowDialogL(TDesC& aText, TDesC& aHeading ) |
|
227 { |
|
228 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( aText ); |
|
229 |
|
230 dlg->PrepareLC( R_IAUPDATE_MESSAGE_QUERY ); |
|
231 |
|
232 CAknPopupHeadingPane* headingPane = dlg->Heading(); |
|
233 headingPane->SetTextL( aHeading ); |
|
234 |
|
235 TInt ret = dlg->RunLD(); |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CIAUpdateFWUpdateHandler::StartSyncL() |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CIAUpdateFWUpdateHandler::StartSyncL( |
|
244 const TInt aProfileId, // = KErrNotFound |
|
245 const TBool aUseFotaProgressNote ) // = EFalse |
|
246 { |
|
247 CIAUpdateFWSyncProfile* profile = |
|
248 iDMEngine->OpenProfileL( aProfileId, ESmlOpenReadWrite ); |
|
249 |
|
250 TInt connectionBearer = profile->BearerType(); |
|
251 |
|
252 TBuf<KMaxProfileNameLength> serverName; |
|
253 profile->GetName( serverName ); |
|
254 |
|
255 CRepository* centrep = NULL; |
|
256 |
|
257 // Next, we check if profile is active. If not, we change it without asking user's permission and then set it back at the end. |
|
258 if ( profile->SASyncState() == ESASyncStateDisable ) |
|
259 { |
|
260 TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) ); |
|
261 if (err == KErrNone) |
|
262 { |
|
263 centrep->Set( KNSmlFotaProfileDefaultIsActive, 0 ); |
|
264 delete centrep; centrep = NULL; |
|
265 } |
|
266 |
|
267 profile->SetSASyncStateL( ESASyncStateEnable ); |
|
268 profile->SaveL(); |
|
269 } |
|
270 |
|
271 iDMEngine->CloseProfile(); |
|
272 |
|
273 TRAPD( error, iDMEngine->SynchronizeL( serverName, |
|
274 aProfileId, |
|
275 connectionBearer, |
|
276 aUseFotaProgressNote ) ); |
|
277 |
|
278 if (error != KErrNone) |
|
279 { |
|
280 |
|
281 CAknInformationNote* queryDialog = new (ELeave) CAknInformationNote; |
|
282 |
|
283 HBufC* error = HBufC::NewL(20); |
|
284 TPtr ptrerror = error->Des(); |
|
285 ptrerror.Copy(_L("sync problem")); |
|
286 queryDialog->ExecuteLD( *error ); |
|
287 } |
|
288 } |
|
289 |
|
290 //EOF |
|
291 |