|
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: AlwaysOnline server Central Repository controller |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <centralrepository.h> |
|
22 #include <cenrepnotifyhandler.h> |
|
23 #include <CoreApplicationUIsSDKCRKeys.h> // Offline key |
|
24 |
|
25 #include "AOCenRepControl.h" |
|
26 #include "AOInternalCRKeys.h" |
|
27 #include "AlwaysOnlineManagerLogging.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // CONSTANTS |
|
32 const TUint32 KDisabledPluginsBaseKey = 0x00000100; |
|
33 const TUint32 KDisabledPluginsLastKey = 0x000001FF; |
|
34 const TUint32 KCoreAppUiRepository = 0x101F876C; |
|
35 |
|
36 #ifdef _DEBUG // Just to make compiler happy! |
|
37 _LIT( KAOSetPanic, "AO cenrep set" ); |
|
38 _LIT( KAOGetPanic, "AO cenrep get" ); |
|
39 _LIT( KAODelPanic, "AO cenrep del" ); |
|
40 #endif |
|
41 |
|
42 // MACROS |
|
43 // LOCAL CONSTANTS AND MACROS |
|
44 // MODULE DATA STRUCTURES |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 // FORWARD DECLARATIONS |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CAOCenRepControl::CAOCenRepControl() |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 CAOCenRepControl::CAOCenRepControl( CAlwaysOnlineManager& aCallBack ) : |
|
55 iCallBack( aCallBack ) |
|
56 { |
|
57 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::CAOCenRepControl()"); |
|
58 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::CAOCenRepControl()"); |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CAOCenRepControl::~CAOCenRepControl() |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CAOCenRepControl::~CAOCenRepControl() |
|
66 { |
|
67 if ( iCoreAppUiCenRepNotifier ) |
|
68 { |
|
69 iCoreAppUiCenRepNotifier->StopListening(); |
|
70 } |
|
71 |
|
72 delete iCoreAppUiCenRepNotifier; |
|
73 iCoreAppUiCenRepNotifier = NULL; |
|
74 |
|
75 delete iCoreAppUiCenRepSession; |
|
76 iCoreAppUiCenRepSession = NULL; |
|
77 |
|
78 delete iAoServerCenRepSession; |
|
79 iAoServerCenRepSession = NULL; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CAOCenRepControl::ConstructL() |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 void CAOCenRepControl::ConstructL() |
|
87 { |
|
88 // Create Core App Ui Central Repository session and notifier |
|
89 CreateCoreAppUiCenRepSessionL(); |
|
90 |
|
91 // Create AoServer Central Repository session |
|
92 CreateAoServerCenRepSessionL(); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CAOCenRepControl::NewL() |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 CAOCenRepControl* CAOCenRepControl::NewL( CAlwaysOnlineManager& aCallBack ) |
|
100 { |
|
101 CAOCenRepControl* self = NewLC( aCallBack ); |
|
102 CleanupStack::Pop( self ); |
|
103 |
|
104 return self; |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CAOCenRepControl::NewLC() |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 CAOCenRepControl* CAOCenRepControl::NewLC( CAlwaysOnlineManager& aCallBack ) |
|
112 { |
|
113 CAOCenRepControl* self = new ( ELeave ) CAOCenRepControl( aCallBack ); |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL(); |
|
116 |
|
117 return self; |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // CAOCenRepControl::CreateAoServerCenRepSessionL() |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 void CAOCenRepControl::CreateAoServerCenRepSessionL() |
|
125 { |
|
126 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::CreateAoServerCenRepSessionL()"); |
|
127 |
|
128 // Create the session if not yet exist. |
|
129 if ( !iAoServerCenRepSession ) |
|
130 { |
|
131 iAoServerCenRepSession = CRepository::NewL( KCRUidAOSettings ); |
|
132 } |
|
133 |
|
134 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::CreateAoServerCenRepSessionL()"); |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CAOCenRepControl::SetCenRepKey() |
|
139 // ---------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CAOCenRepControl::SetCenRepKey( |
|
142 const TUid& aRepository, const TUint32 aKeyId, TInt aValue ) |
|
143 { |
|
144 TInt result = KErrNotFound; |
|
145 |
|
146 switch ( aRepository.iUid ) |
|
147 { |
|
148 case KCRAOSettings: |
|
149 result = iAoServerCenRepSession->Set( aKeyId, aValue ); |
|
150 break; |
|
151 case KCoreAppUiRepository: |
|
152 result = iCoreAppUiCenRepSession->Set( aKeyId, aValue ); |
|
153 break; |
|
154 default: |
|
155 __ASSERT_DEBUG( EFalse, User::Panic( KAOSetPanic, KErrNotSupported ) ); |
|
156 break; |
|
157 } |
|
158 |
|
159 return result; |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------------------------------- |
|
163 // CAOCenRepControl::GetCenRepKey() |
|
164 // ---------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CAOCenRepControl::GetCenRepKey( |
|
167 const TUid& aRepository, const TUint32 aKeyId, TInt& aValue ) |
|
168 { |
|
169 TInt result = KErrNotFound; |
|
170 |
|
171 switch ( aRepository.iUid ) |
|
172 { |
|
173 case KCRAOSettings: |
|
174 result = iAoServerCenRepSession->Get( aKeyId, aValue ); |
|
175 break; |
|
176 case KCoreAppUiRepository: |
|
177 result = iCoreAppUiCenRepSession->Get( aKeyId, aValue ); |
|
178 break; |
|
179 default: |
|
180 __ASSERT_DEBUG( EFalse, User::Panic( KAOGetPanic, KErrNotSupported ) ); |
|
181 break; |
|
182 } |
|
183 |
|
184 return result; |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CAOCenRepControl::DelCenRepKey() |
|
189 // ---------------------------------------------------------------------------- |
|
190 // |
|
191 TInt CAOCenRepControl::DelCenRepKey( |
|
192 const TUid& aRepository, |
|
193 const TUint32 aKeyId ) |
|
194 { |
|
195 TInt result = KErrNotFound; |
|
196 |
|
197 switch ( aRepository.iUid ) |
|
198 { |
|
199 case KCRAOSettings: |
|
200 result = iAoServerCenRepSession->Delete( aKeyId ); |
|
201 break; |
|
202 case KCoreAppUiRepository: |
|
203 result = iCoreAppUiCenRepSession->Delete( aKeyId ); |
|
204 break; |
|
205 default: |
|
206 __ASSERT_DEBUG( EFalse, User::Panic( KAODelPanic, KErrNotSupported ) ); |
|
207 break; |
|
208 } |
|
209 |
|
210 return result; |
|
211 } |
|
212 |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // CAOCenRepControl::CreateCoreAppUiCenRepSessionL() |
|
216 // ---------------------------------------------------------------------------- |
|
217 // |
|
218 void CAOCenRepControl::CreateCoreAppUiCenRepSessionL() |
|
219 { |
|
220 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::CreateCoreAppUiCenRepSessionL()"); |
|
221 // Create the session |
|
222 iCoreAppUiCenRepSession = CRepository::NewL( KCRUidCoreApplicationUIs ); |
|
223 |
|
224 // Create the notifer |
|
225 iCoreAppUiCenRepNotifier = |
|
226 CCenRepNotifyHandler::NewL( |
|
227 iCallBack, *iCoreAppUiCenRepSession, CCenRepNotifyHandler::EIntKey, |
|
228 KCoreAppUIsNetworkConnectionAllowed ); |
|
229 |
|
230 // Start listening |
|
231 iCoreAppUiCenRepNotifier->StartListeningL(); |
|
232 |
|
233 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::CreateCoreAppUiCenRepSessionL()"); |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // CAOCenRepControl::ReCreateCoreAppUiCenRepSessionL() |
|
238 // ---------------------------------------------------------------------------- |
|
239 // |
|
240 void CAOCenRepControl::ReCreateCoreAppUiCenRepSessionL() |
|
241 { |
|
242 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::ReCreateCoreAppUiCenRepSessionL()"); |
|
243 // Remove session and notifier |
|
244 if ( iCoreAppUiCenRepNotifier ) |
|
245 { |
|
246 iCoreAppUiCenRepNotifier->StopListening(); |
|
247 } |
|
248 |
|
249 delete iCoreAppUiCenRepNotifier; |
|
250 iCoreAppUiCenRepNotifier = NULL; |
|
251 |
|
252 delete iCoreAppUiCenRepSession; |
|
253 iCoreAppUiCenRepSession = NULL; |
|
254 |
|
255 // Create new session |
|
256 CreateCoreAppUiCenRepSessionL(); |
|
257 |
|
258 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::ReCreateCoreAppUiCenRepSessionL()"); |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------------------------- |
|
262 // CAOCenRepControl::UpdateDisabledPluginsUids() |
|
263 // ---------------------------------------------------------------------------- |
|
264 // |
|
265 void CAOCenRepControl::UpdateDisabledPluginsUids( |
|
266 CArrayFixFlat<TUid>& aDisabledPluginUidsArray ) |
|
267 { |
|
268 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::UpdateDisabledPluginsUids()"); |
|
269 // Reset to original state |
|
270 aDisabledPluginUidsArray.Reset(); |
|
271 |
|
272 // Key #1 indicates the number of disabled plugin |
|
273 TInt count = 0; |
|
274 TInt result = GetCenRepKey( |
|
275 KCRUidAOSettings, |
|
276 KAODisabledPluginsCount, |
|
277 count ); |
|
278 |
|
279 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::UpdateDisabledPluginsUids() Disabled plugins count: %d", count); |
|
280 |
|
281 // Is there any disabled plugins? |
|
282 if ( count > 0 ) |
|
283 { |
|
284 TInt value = 0; |
|
285 TInt error = KErrNone; |
|
286 TUint32 key = KDisabledPluginsBaseKey; |
|
287 |
|
288 for ( ; key <= KDisabledPluginsLastKey; key++ ) |
|
289 { |
|
290 error = GetCenRepKey( |
|
291 KCRUidAOSettings, |
|
292 key, |
|
293 value ); |
|
294 |
|
295 // If no errors, then index have an UID and it can be appended |
|
296 // to disabled plugins array. |
|
297 if ( error == KErrNone && value != KErrNotFound ) |
|
298 { |
|
299 TRAPD( err, aDisabledPluginUidsArray.AppendL( TUid::Uid( value ) ) ) |
|
300 // If AppendL returns error (most propably memory full) then we |
|
301 // don't set plugin as disabled. Delete the key from cenrep. |
|
302 if ( err != KErrNone ) |
|
303 { |
|
304 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::UpdateDisabledPluginsUids() AppendL failed, err = %d", err); |
|
305 // Enable plugin |
|
306 SetPluginStatus( TUid::Uid( value ), EFalse ); |
|
307 } |
|
308 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::UpdateDisabledPluginsUids() found disabled plugin, UID: 0x%x", TUid::Uid( value )); |
|
309 } |
|
310 // Have we found all the disabled plugins? |
|
311 if ( aDisabledPluginUidsArray.Count() == count ) |
|
312 { |
|
313 // We already found all the UIDs of the disabled plugins, |
|
314 // so we can jump out from the loop. |
|
315 break; |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::UpdateDisabledPluginsUids()"); |
|
321 } |
|
322 |
|
323 // ---------------------------------------------------------------------------- |
|
324 // CAOCenRepControl::SetPluginStatus() |
|
325 // ---------------------------------------------------------------------------- |
|
326 // |
|
327 void CAOCenRepControl::SetPluginStatus( const TUid& aPlugin, TBool aDisable ) |
|
328 { |
|
329 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::SetPluginStatus()"); |
|
330 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::SetPluginStatus() aPlugin: 0x%x", aPlugin); |
|
331 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::SetPluginStatus() aDisable: %d", aDisable); |
|
332 |
|
333 TInt result = KErrNone; |
|
334 TUint32 key; |
|
335 |
|
336 if ( aDisable ) |
|
337 { |
|
338 // Get first free key for disabled plugins UIDs |
|
339 if ( GetFirstFreeKey( key ) ) |
|
340 { |
|
341 // Set aPlugin to first free key |
|
342 result = SetCenRepKey( KCRUidAOSettings, key, aPlugin.iUid ); |
|
343 } |
|
344 |
|
345 // Update disabled plugins count |
|
346 if ( result == KErrNone ) |
|
347 { |
|
348 UpdateDisabledPluginsCount( ETrue ); |
|
349 } |
|
350 } |
|
351 else |
|
352 { |
|
353 // Find correct cenrep key, which have value aPlugin as a value. |
|
354 if ( GetKeyWithValue( aPlugin, key ) ) |
|
355 { |
|
356 // Delete the found cenrep key |
|
357 result = DelCenRepKey( KCRUidAOSettings, key ); |
|
358 } |
|
359 |
|
360 // Update disabled plugins count |
|
361 if ( result == KErrNone ) |
|
362 { |
|
363 UpdateDisabledPluginsCount( EFalse ); |
|
364 } |
|
365 } |
|
366 |
|
367 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::SetPluginStatus()"); |
|
368 } |
|
369 |
|
370 // ---------------------------------------------------------------------------- |
|
371 // CAOCenRepControl::GetFirstFreeKey() |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 TBool CAOCenRepControl::GetFirstFreeKey( TUint32& aFreeKey ) |
|
375 { |
|
376 TInt error = KErrNone; |
|
377 TInt value = 0; |
|
378 TBool found = EFalse; |
|
379 TInt key = KDisabledPluginsBaseKey; |
|
380 |
|
381 while( !found && key <= KDisabledPluginsLastKey ) |
|
382 { |
|
383 error = GetCenRepKey( |
|
384 KCRUidAOSettings, |
|
385 key, |
|
386 value ); |
|
387 |
|
388 if ( error == KErrNotFound ) |
|
389 { |
|
390 aFreeKey = key; |
|
391 found = ETrue; |
|
392 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::GetFirstFreeKey() aFreeKey: 0x%x", aFreeKey); |
|
393 } |
|
394 |
|
395 key++; |
|
396 } |
|
397 |
|
398 return found; |
|
399 } |
|
400 |
|
401 // ---------------------------------------------------------------------------- |
|
402 // CAOCenRepControl::GetKeyWithValue() |
|
403 // ---------------------------------------------------------------------------- |
|
404 // |
|
405 TBool CAOCenRepControl::GetKeyWithValue( |
|
406 const TUid& aValue, |
|
407 TUint32& aKey ) |
|
408 { |
|
409 TInt error = KErrNone; |
|
410 TInt value = 0; |
|
411 TBool found = EFalse; |
|
412 TInt loopKey = KDisabledPluginsBaseKey; |
|
413 |
|
414 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::GetKeyWithValue() Searching value: 0x%x", aValue); |
|
415 |
|
416 while ( !found && loopKey <= KDisabledPluginsLastKey ) |
|
417 { |
|
418 error = GetCenRepKey( |
|
419 KCRUidAOSettings, |
|
420 loopKey, |
|
421 value ); |
|
422 |
|
423 if ( error == KErrNone && aValue.iUid == value ) |
|
424 { |
|
425 aKey = loopKey; |
|
426 found = ETrue; |
|
427 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::GetKeyWithValue() Found in key: 0x%x", aKey); |
|
428 } |
|
429 loopKey++; |
|
430 value = 0; |
|
431 } |
|
432 |
|
433 return found; |
|
434 } |
|
435 |
|
436 // ---------------------------------------------------------------------------- |
|
437 // CAOCenRepControl::UpdateDisabledPluginsCount() |
|
438 // ---------------------------------------------------------------------------- |
|
439 // |
|
440 TInt CAOCenRepControl::UpdateDisabledPluginsCount( TBool aIncrease ) |
|
441 { |
|
442 KAOMANAGER_LOGGER_FN1("CAOCenRepControl::UpdateDisabledPluginsCount()"); |
|
443 TInt count = 0; |
|
444 TInt result = GetCenRepKey( |
|
445 KCRUidAOSettings, |
|
446 KAODisabledPluginsCount, |
|
447 count ); |
|
448 |
|
449 if ( result == KErrNone ) |
|
450 { |
|
451 aIncrease ? count++ : count--; |
|
452 |
|
453 result = SetCenRepKey( |
|
454 KCRUidAOSettings, |
|
455 KAODisabledPluginsCount, |
|
456 count ); |
|
457 |
|
458 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOCenRepControl::UpdateDisabledPluginsCount() count: %d", count); |
|
459 } |
|
460 |
|
461 KAOMANAGER_LOGGER_FN2("CAOCenRepControl::UpdateDisabledPluginsCount()"); |
|
462 |
|
463 return result; |
|
464 } |
|
465 // End of File |