|
1 /* |
|
2 * Copyright (c) 2007 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: Software Installer plug-in usb handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "chswiusbhandler.h" |
|
22 #include "chswiplugin.h" |
|
23 #include "chswimassmodeobserver.h" |
|
24 #include <driveinfo.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KCallBackDelay = 5000000; |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // CCHSwiUsbHandler::NewL() |
|
31 // two-phase constructor |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 CCHSwiUsbHandler* CCHSwiUsbHandler::NewL( |
|
35 MCHSwiMassModeObserver* aMassModeObserver, |
|
36 RFs& aFs ) |
|
37 { |
|
38 CCHSwiUsbHandler* self = |
|
39 new(ELeave) CCHSwiUsbHandler( aMassModeObserver, aFs ); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CCHSwiUsbHandler::CCHSwiUsbHandler() |
|
48 // C++ default constructor |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 CCHSwiUsbHandler::CCHSwiUsbHandler( MCHSwiMassModeObserver* aMassModeObserver, |
|
52 RFs& aFs ) |
|
53 : CActive( CActive::EPriorityUserInput ), |
|
54 iLastDriveScanError( KErrNone ), |
|
55 iMassModeObserver( aMassModeObserver ), |
|
56 iFs( aFs ), |
|
57 iDriveFlags( 0 ) |
|
58 { |
|
59 CActiveScheduler::Add( this ); |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // CCHSwiUsbHandler::ConstructL() |
|
64 // Symbian default constructor |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 void CCHSwiUsbHandler::ConstructL() |
|
68 { |
|
69 User::LeaveIfError( iTimer.CreateLocal() ); |
|
70 |
|
71 iLastDriveScanError = ScanDrivesAndUpdateFlag( EFalse ); |
|
72 |
|
73 if ( iLastDriveScanError != KErrNone ) |
|
74 { |
|
75 HandleDriveError(); |
|
76 } |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // CCHSwiUsbHandler::~CCHSwiUsbHandler() |
|
81 // destructor |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 CCHSwiUsbHandler::~CCHSwiUsbHandler() |
|
85 { |
|
86 Cancel(); |
|
87 iTimer.Close(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // CCHSwiUsbHandler::SynchronousDriveScan() |
|
92 // Performs synchronous drive scan. Checks whether Mass Drive is available |
|
93 // and updates the flag in observer. |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 void CCHSwiUsbHandler::SynchronousDriveScan() |
|
97 { |
|
98 iLastDriveScanError = ScanDrivesAndUpdateFlag( iLastDriveScanError == KErrNone ); |
|
99 |
|
100 if ( iLastDriveScanError != KErrNone ) |
|
101 { |
|
102 HandleDriveError(); |
|
103 } |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CCHSwiUsbHandler::PostponedDriveScan() |
|
108 // Starts postponed drive scan. |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 void CCHSwiUsbHandler::PostponedDriveScan() |
|
112 { |
|
113 Cancel(); |
|
114 iTimer.After( iStatus, KCallBackDelay ); |
|
115 SetActive(); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // CCHSwiUsbHandler::RunL() |
|
120 // Handles postponed drive scan. |
|
121 // Executed either after call to PostponedDriveScan or in case of drive reading |
|
122 // errors in SynchronousDriveScan or ConstructL. |
|
123 // ---------------------------------------------------------------------------- |
|
124 // |
|
125 void CCHSwiUsbHandler::RunL() |
|
126 { |
|
127 TBool massModeBeforeScan = iMassModeObserver->IsMassStorageMode(); |
|
128 TInt errorBeforeScan = iLastDriveScanError; |
|
129 |
|
130 SynchronousDriveScan(); |
|
131 |
|
132 if ( iLastDriveScanError == KErrNone ) |
|
133 { |
|
134 iMassModeObserver->HandleSuccessfulAsynchDriveScan(); |
|
135 |
|
136 // CCHSwiUsbObserver can't detect app uninstall when app had been installed on removable |
|
137 // memory card, the memory card was removed during mass mode, and then mass |
|
138 // mode was deactivated. |
|
139 // Additionaly, we need to update widgets when recovering from error. |
|
140 if ( !iMassModeObserver->IsMassStorageMode() && |
|
141 ( massModeBeforeScan || errorBeforeScan != KErrNone ) ) |
|
142 { |
|
143 iMassModeObserver->HandleMassStorageModeEndEvent(); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------------------------------- |
|
149 // CCHSwiUsbHandler::HandleDriveError() |
|
150 // Handles drive access errors by launching new postponed scan. |
|
151 // ---------------------------------------------------------------------------- |
|
152 void CCHSwiUsbHandler::HandleDriveError() |
|
153 { |
|
154 Cancel(); |
|
155 iMassModeObserver->SetMassStorageMode( ETrue ); |
|
156 |
|
157 iTimer.After( iStatus, KCallBackDelay ); |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CCHSwiUsbHandler::ScanDrivesAndUpdateFlag() |
|
163 // Scans drives and updates Mass Mode flag in the observer. |
|
164 // ---------------------------------------------------------------------------- |
|
165 TInt CCHSwiUsbHandler::ScanDrivesAndUpdateFlag( TBool aFlagsValid ) |
|
166 { |
|
167 TInt error( KErrNone ); |
|
168 |
|
169 if( aFlagsValid ) |
|
170 { |
|
171 // iDriveFlags is valid, we can use deltaDriveFlags to avoid |
|
172 // unnecessary calls to DriveInfo::GetDriveStatus |
|
173 TInt driveFlags = 0; |
|
174 TInt deltaDriveFlags = 0; |
|
175 |
|
176 error = ScanDrives( driveFlags ); |
|
177 |
|
178 if ( error == KErrNone ) |
|
179 { |
|
180 deltaDriveFlags = iDriveFlags ^ driveFlags; |
|
181 iDriveFlags = driveFlags; |
|
182 } |
|
183 |
|
184 if ( deltaDriveFlags ) |
|
185 { |
|
186 error = UpdateMassModeFlag(); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 error = ScanDrives( iDriveFlags ); |
|
192 |
|
193 if ( error == KErrNone ) |
|
194 { |
|
195 error = UpdateMassModeFlag(); |
|
196 } |
|
197 } |
|
198 |
|
199 return error; |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // CCHSwiUsbHandler::UpdateMassModeFlag() |
|
204 // Updates Mass Mode flag in the observer. |
|
205 // ---------------------------------------------------------------------------- |
|
206 TInt CCHSwiUsbHandler::UpdateMassModeFlag() |
|
207 { |
|
208 TInt flags = iDriveFlags; |
|
209 TBool massMemoryPresent = EFalse; |
|
210 |
|
211 for( TInt DriveNo = EDriveA + 1 ; DriveNo <= EDriveY; DriveNo++ ) |
|
212 { |
|
213 flags = flags >> 1; |
|
214 if( flags & 01 ) |
|
215 { |
|
216 TUint status( 0 ); |
|
217 TInt error = DriveInfo::GetDriveStatus( iFs, DriveNo, status ); |
|
218 |
|
219 if( error != KErrNone ) |
|
220 { |
|
221 return error; |
|
222 } |
|
223 |
|
224 if( ( status & DriveInfo::EDriveExternallyMountable ) |
|
225 && ( status & DriveInfo::EDriveInternal ) ) |
|
226 { |
|
227 // Internal Memory |
|
228 massMemoryPresent = ETrue; |
|
229 break; |
|
230 } |
|
231 } |
|
232 } |
|
233 |
|
234 iMassModeObserver->SetMassStorageMode( !massMemoryPresent ); |
|
235 return KErrNone; |
|
236 } |
|
237 |
|
238 // ---------------------------------------------------------------------------- |
|
239 // CCHSwiUsbHandler::RunError() |
|
240 // Ignore errors from RunL. |
|
241 // ---------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CCHSwiUsbHandler::RunError( TInt /* aError */ ) |
|
244 { |
|
245 return KErrNone; // indicates error was handled |
|
246 } |
|
247 |
|
248 // ---------------------------------------------------------------------------- |
|
249 // CCHSwiUsbHandler::DoCancel() |
|
250 // Cancel the MMC event handler |
|
251 // ---------------------------------------------------------------------------- |
|
252 void CCHSwiUsbHandler::DoCancel() |
|
253 { |
|
254 iTimer.Cancel(); |
|
255 } |
|
256 |
|
257 // ---------------------------------------------------------------------------- |
|
258 // CCHSwiUsbHandler::ScanDrives( TInt& aDriveFlags ) |
|
259 // Scans drives and records a bit flag for those that exist and are |
|
260 // suitable for installing widgets to. |
|
261 // ---------------------------------------------------------------------------- |
|
262 // |
|
263 TInt CCHSwiUsbHandler::ScanDrives( TInt& aDriveFlags ) |
|
264 { |
|
265 // List all drives in the system |
|
266 TDriveList driveList; |
|
267 TInt error = iFs.DriveList( driveList ); |
|
268 |
|
269 if ( KErrNone == error ) |
|
270 { |
|
271 for ( TInt driveNumber = EDriveY; |
|
272 driveNumber >= EDriveA; |
|
273 driveNumber-- ) |
|
274 { |
|
275 // The drives that will be filtered out are the same ones that |
|
276 // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL() |
|
277 if ( (EDriveD == driveNumber) |
|
278 || !driveList[driveNumber] ) |
|
279 { |
|
280 // EDriveD is a temporary drive usually a RAM disk |
|
281 continue; |
|
282 } |
|
283 |
|
284 TVolumeInfo volInfo; |
|
285 if ( iFs.Volume( volInfo, driveNumber ) != KErrNone ) |
|
286 { |
|
287 // volume is not usable (e.g. no media card inserted) |
|
288 continue; |
|
289 } |
|
290 if ( (volInfo.iDrive.iType == EMediaNotPresent) || |
|
291 (volInfo.iDrive.iType == EMediaRom) || |
|
292 (volInfo.iDrive.iType == EMediaRemote) || |
|
293 (volInfo.iDrive.iDriveAtt & KDriveAttRom) || |
|
294 (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) ) |
|
295 { |
|
296 // not a suitable widget install drive |
|
297 continue; |
|
298 } |
|
299 |
|
300 // found a usable drive |
|
301 aDriveFlags |= (1 << driveNumber); |
|
302 } |
|
303 } |
|
304 |
|
305 return error; |
|
306 } |
|
307 |