1 /* |
|
2 * Copyright (c) 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: Handle notifications of MMC events. |
|
15 * |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "WidgetMMCHandler.h" |
|
21 #include "WidgetRegistry.h" |
|
22 |
|
23 // CONSTANTS |
|
24 LOG_NAMES( "widreg", "widrmmc.txt" ) |
|
25 |
|
26 // ============================================================================ |
|
27 // CWidgetMMCHandler::NewL() |
|
28 // two-phase constructor |
|
29 // |
|
30 // @since 3.1 |
|
31 // @param aRegistry - Widget registry for callback. |
|
32 // @param aFs - file session |
|
33 // @return pointer to CWidgetMMCHandler |
|
34 // ============================================================================ |
|
35 // |
|
36 CWidgetMMCHandler* CWidgetMMCHandler::NewL( |
|
37 CWidgetRegistry& aRegistry, |
|
38 RFs& aFs ) |
|
39 { |
|
40 CWidgetMMCHandler* self = |
|
41 new(ELeave) CWidgetMMCHandler( aRegistry , aFs ); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ============================================================================ |
|
49 // CWidgetMMCHandler::CWidgetMMCHandler() |
|
50 // C++ default constructor |
|
51 // |
|
52 // @since 3.1 |
|
53 // ============================================================================ |
|
54 // |
|
55 CWidgetMMCHandler::CWidgetMMCHandler( CWidgetRegistry& aRegistry, |
|
56 RFs& aFs ) |
|
57 : CActive( CActive::EPriorityStandard ), |
|
58 iRegistry( &aRegistry ), |
|
59 iFs( aFs ), |
|
60 iDriveFlags( 0 ) |
|
61 { |
|
62 CActiveScheduler::Add( this ); |
|
63 } |
|
64 |
|
65 // ============================================================================ |
|
66 // CWidgetMMCHandler::ConstructL() |
|
67 // Symbian default constructor |
|
68 // |
|
69 // @since 3.1 |
|
70 // ============================================================================ |
|
71 // |
|
72 void CWidgetMMCHandler::ConstructL() |
|
73 { |
|
74 LOG_CONSTRUCTL; |
|
75 if ( KErrNone != ScanDrives( iDriveFlags ) ) |
|
76 { |
|
77 iDriveFlags = 0; |
|
78 } |
|
79 iDeltaDriveFlags = 0; |
|
80 iApaAppListNotifier = CApaAppListNotifier::NewL(this,CActive::EPriorityStandard); |
|
81 } |
|
82 |
|
83 // ============================================================================ |
|
84 // CWidgetMMCHandler::~CWidgetMMCHandler() |
|
85 // destructor |
|
86 // |
|
87 // @since 3.1 |
|
88 // ============================================================================ |
|
89 CWidgetMMCHandler::~CWidgetMMCHandler() |
|
90 { |
|
91 Cancel(); |
|
92 LOG_DESTRUCT; |
|
93 } |
|
94 |
|
95 // ============================================================================ |
|
96 // CWidgetMMCHandler::Start() |
|
97 // Start monitoring. |
|
98 // |
|
99 // @since 5.0 |
|
100 // ============================================================================ |
|
101 void CWidgetMMCHandler::Start() |
|
102 { |
|
103 iFs.NotifyChange( ENotifyDisk, iStatus ); |
|
104 SetActive(); |
|
105 } |
|
106 |
|
107 // ============================================================================ |
|
108 // CWidgetMMCHandler::RunL() |
|
109 // Handle notifications of MMC events. |
|
110 // |
|
111 // @since 3.1 |
|
112 // ============================================================================ |
|
113 void CWidgetMMCHandler::RunL() |
|
114 { |
|
115 LOG_OPEN; |
|
116 LOG1( "MMC notification status %d", iStatus.Int() ); |
|
117 |
|
118 TInt status = iStatus.Int(); |
|
119 |
|
120 // Request the notification before scanning |
|
121 iFs.NotifyChange( ENotifyDisk, iStatus ); |
|
122 SetActive(); |
|
123 |
|
124 if ( status == KErrNone ) |
|
125 { |
|
126 TInt driveFlags = 0; |
|
127 TInt deltaDriveFlags = 0; |
|
128 if ( KErrNone == ScanDrives( driveFlags ) ) |
|
129 { |
|
130 LOG1( " iDriveFlags 0x%x", iDriveFlags ); |
|
131 LOG1( " driveFlags 0x%x", driveFlags ); |
|
132 deltaDriveFlags = iDriveFlags ^ driveFlags; |
|
133 iDeltaDriveFlags |= deltaDriveFlags; |
|
134 LOG1( " deltaDriveFlags 0x%x", deltaDriveFlags ); |
|
135 iDriveFlags = driveFlags; |
|
136 } |
|
137 } |
|
138 LOG( "MMC notification done" ); |
|
139 LOG_CLOSE; |
|
140 } |
|
141 |
|
142 // ============================================================================ |
|
143 // CWidgetMMCHandler::RunError() |
|
144 // Ignore errors from RunL. |
|
145 // |
|
146 // @since 5.0 |
|
147 // ============================================================================ |
|
148 TInt CWidgetMMCHandler::RunError( TInt /* aError */ ) |
|
149 { |
|
150 LOG_CLOSE; |
|
151 return KErrNone; // indicates error was handled |
|
152 } |
|
153 |
|
154 // ============================================================================ |
|
155 // CWidgetMMCHandler::DoCancel() |
|
156 // Cancel the MMC event handler |
|
157 // |
|
158 // @since 3.1 |
|
159 // ============================================================================ |
|
160 void CWidgetMMCHandler::DoCancel() |
|
161 { |
|
162 LOG_CLOSE; |
|
163 iFs.NotifyChangeCancel(); |
|
164 } |
|
165 |
|
166 /* Scans drives and records a bit flag for those that exist and are |
|
167 * suitable for installing widgets to. |
|
168 */ |
|
169 TInt CWidgetMMCHandler::ScanDrives( TInt& aDriveFlags ) |
|
170 { |
|
171 LOG_OPEN; |
|
172 LOG( "ScanDrives" ); |
|
173 // List all drives in the system |
|
174 TDriveList driveList; |
|
175 TInt error = iFs.DriveList( driveList ); |
|
176 if ( KErrNone == error ) |
|
177 { |
|
178 for ( TInt driveNumber = EDriveY; |
|
179 driveNumber >= EDriveA; |
|
180 driveNumber-- ) |
|
181 { |
|
182 // The drives that will be filtered out are the same ones that |
|
183 // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL() |
|
184 if ( (EDriveD == driveNumber) |
|
185 || !driveList[driveNumber] ) |
|
186 { |
|
187 // EDriveD is a temporary drive usually a RAM disk |
|
188 continue; |
|
189 } |
|
190 |
|
191 TVolumeInfo volInfo; |
|
192 if ( iFs.Volume( volInfo, driveNumber ) != KErrNone ) |
|
193 { |
|
194 // volume is not usable (e.g. no media card inserted) |
|
195 continue; |
|
196 } |
|
197 if ( (volInfo.iDrive.iType == EMediaNotPresent) || |
|
198 (volInfo.iDrive.iType == EMediaRom) || |
|
199 (volInfo.iDrive.iType == EMediaRemote) || |
|
200 (volInfo.iDrive.iDriveAtt & KDriveAttRom) || |
|
201 (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) ) |
|
202 { |
|
203 // not a suitable widget install drive |
|
204 continue; |
|
205 } |
|
206 |
|
207 // found a usable drive |
|
208 aDriveFlags |= (1 << driveNumber); |
|
209 LOG2( " drive %d, flags 0x%x", driveNumber, aDriveFlags ); |
|
210 } |
|
211 } |
|
212 LOG1( "ScanDrives done, error %d", error ); |
|
213 LOG_CLOSE; |
|
214 return error; |
|
215 } |
|
216 |
|
217 void CWidgetMMCHandler::HandleAppListEvent(TInt aEvent) |
|
218 { |
|
219 TBool dirtyFlag = EFalse; |
|
220 TInt parseError = KErrNone; |
|
221 |
|
222 if ( iDeltaDriveFlags ) |
|
223 { |
|
224 // Assume usual case and things are consistent |
|
225 // and the registry entry file can be parsed and used. |
|
226 TRAPD( error, iRegistry->InternalizeL( ETrue, |
|
227 ETrue, |
|
228 dirtyFlag, |
|
229 parseError ) ); |
|
230 if ( KErrNone == error ) |
|
231 { |
|
232 // internalize consistency enforcement may have altered registry |
|
233 if ( dirtyFlag ) |
|
234 { |
|
235 TRAP_IGNORE( iRegistry->ExternalizeL(); ); |
|
236 } |
|
237 } |
|
238 iDeltaDriveFlags = 0; |
|
239 |
|
240 CWidgetRegistry::NotifyWidgetAltered(); |
|
241 } |
|
242 } |
|