|
1 /* |
|
2 * Copyright (c) 2010 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 #include "applicationsplugin.h" |
|
19 #include "harvesterserverlogger.h" |
|
20 #include <common.h> |
|
21 |
|
22 #include <ccpixindexer.h> |
|
23 #include <csearchdocument.h> |
|
24 #include <e32base.h> |
|
25 //#include <menu2internalcrkeys.h> //for KCRUidMenu |
|
26 #include <widgetpropertyvalue.h> // EBundleDisplayName |
|
27 #include <centralrepository.h> |
|
28 |
|
29 //Hidden applications |
|
30 //#define KHiddenAppRepositoryUid KCRUidMenu |
|
31 |
|
32 _LIT( KMimeTypeField, CPIX_MIMETYPE_FIELD ); |
|
33 _LIT( KMimeTypeApplication, APPLICATION_MIMETYPE); |
|
34 |
|
35 /** Field names */ |
|
36 _LIT(KApplicationFieldCaption, "Name"); |
|
37 _LIT(KApplicationFieldUid, "Uid"); |
|
38 _LIT(KApplicationFieldAbsolutePath, "Path"); |
|
39 |
|
40 // TAppInfo.Name() returns [121345678]. The below constants are used to extract '[' & ']' |
|
41 const TInt KUidStartIndex = 1; |
|
42 const TInt KUidEndIndex = 8; |
|
43 |
|
44 /** The delay between harvesting chunks. */ |
|
45 const TInt KHarvestingDelay = 1000; |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 CApplicationsPlugin* CApplicationsPlugin::NewL() |
|
49 { |
|
50 CPIXLOGSTRING("CApplicationsPlugin::NewL()"); |
|
51 CApplicationsPlugin* instance = CApplicationsPlugin::NewLC(); |
|
52 CleanupStack::Pop(instance); |
|
53 return instance; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 CApplicationsPlugin* CApplicationsPlugin::NewLC() |
|
58 { |
|
59 CApplicationsPlugin* instance = new (ELeave) CApplicationsPlugin(); |
|
60 CleanupStack::PushL(instance); |
|
61 instance->ConstructL(); |
|
62 return instance; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 CApplicationsPlugin::CApplicationsPlugin() |
|
67 { |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 CApplicationsPlugin::~CApplicationsPlugin() |
|
72 { |
|
73 if (iAsynchronizer) |
|
74 iAsynchronizer->CancelCallback(); |
|
75 iApplicationServerSession.Close(); |
|
76 iWidgetRegistry.Close(); |
|
77 //delete iHiddenApplicationsRepository; |
|
78 delete iAsynchronizer; |
|
79 delete iNotifier; |
|
80 delete iIndexer; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 void CApplicationsPlugin::ConstructL() |
|
85 { |
|
86 iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle ); |
|
87 iNotifier = CApaAppListNotifier::NewL( this, CActive::EPriorityHigh ); |
|
88 //iHiddenApplicationsRepository = CRepository::NewL( KHiddenAppRepositoryUid ); |
|
89 User::LeaveIfError( iWidgetRegistry.Connect() ); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 void CApplicationsPlugin::StartPluginL() |
|
94 { |
|
95 User::LeaveIfError( iApplicationServerSession.Connect() ); |
|
96 User::LeaveIfError(iSearchSession.DefineVolume( _L(APPLICATIONS_QBASEAPPCLASS), KNullDesC )); |
|
97 |
|
98 // Open database |
|
99 iIndexer = CCPixIndexer::NewL(iSearchSession); |
|
100 iIndexer->OpenDatabaseL( _L(APPLICATIONS_QBASEAPPCLASS) ); |
|
101 |
|
102 // Start harvester for this plugin |
|
103 iObserver->AddHarvestingQueue( this, iIndexer->GetBaseAppClass() ); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 void CApplicationsPlugin::StartHarvestingL(const TDesC& /* aQualifiedBaseAppClass */) |
|
108 { |
|
109 // Harvest items on each call |
|
110 User::LeaveIfError( iApplicationServerSession.GetAllApps() );//if not KErrNone |
|
111 iIndexer->ResetL(); |
|
112 //No need to check IsStatred() since this is the first start. |
|
113 #ifdef __PERFORMANCE_DATA |
|
114 iStartTime.UniversalTime(); |
|
115 #endif |
|
116 iAsynchronizer->Start( 0, this, KHarvestingDelay ); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 void CApplicationsPlugin::AddWidgetInfoL( CSearchDocument* aDocument, TUid aUid ) |
|
121 { |
|
122 TBuf<KMaxFileName> temp;//we can reuse this. |
|
123 |
|
124 iWidgetRegistry.GetWidgetPath( aUid, temp ); |
|
125 aDocument->AddFieldL(KApplicationFieldAbsolutePath, temp, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
126 CPIXLOGSTRING2("AddApplicationInfo(): PATH = %S ", &temp); |
|
127 |
|
128 //GetWidgetPropertyValueL returns CWidgetPropertyValue* which in turn has an operator to convert to TDesC |
|
129 aDocument->AddFieldL(KApplicationFieldCaption, *(iWidgetRegistry.GetWidgetPropertyValueL( aUid, EBundleDisplayName )), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
130 |
|
131 iWidgetRegistry.GetWidgetBundleName( aUid, temp ); |
|
132 aDocument->AddExcerptL( temp ); |
|
133 CPIXLOGSTRING2("AddApplicationInfo(): DisplayName = %S ", &temp ); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 //This need not be a member function. |
|
138 void AddApplicationInfoL( CSearchDocument* aDocument, TApaAppInfo& aAppInfo ) |
|
139 { |
|
140 TBuf<KMaxFileName> docidString = aAppInfo.iUid.Name(); //This returns stuff in the form "[UID]". So remove the brackets. |
|
141 docidString = docidString.Mid( KUidStartIndex, KUidEndIndex ); |
|
142 |
|
143 aDocument->AddFieldL(KApplicationFieldCaption, aAppInfo.iShortCaption, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
144 aDocument->AddFieldL(KApplicationFieldAbsolutePath, aAppInfo.iFullName, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
145 aDocument->AddExcerptL( aAppInfo.iCaption ); |
|
146 |
|
147 CPIXLOGSTRING3("AddApplicationInfo(): UID = %S, PATH = %S ", &docidString, &aAppInfo.iFullName ); |
|
148 CPIXLOGSTRING3("AddApplicationInfo(): Excerpt = %S, Caption = %S ", &aAppInfo.iCaption, &aAppInfo.iShortCaption ); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 TBool CApplicationsPlugin::IsAppHiddenL(TUid aUid) |
|
153 { |
|
154 //Application should not have 'hidden' capability. |
|
155 TBool ret( EFalse ); |
|
156 TApaAppCapabilityBuf cap; |
|
157 CPIXLOGSTRING2("CApplicationsPlugin::IsAppHidden(): UID = %d", aUid ); |
|
158 if ( iApplicationServerSession.GetAppCapability(cap, aUid) == KErrNone ) |
|
159 { |
|
160 CPIXLOGSTRING("CApplicationsPlugin::IsAppHidden(): GetCapability returned KErrNone"); |
|
161 ret = cap().iAppIsHidden; |
|
162 } |
|
163 |
|
164 //Application should not be listed hidden in application shell. |
|
165 // TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> uidResult; |
|
166 // if( iHiddenApplicationsRepository->Get( KMenuHideApplication, uidResult ) == KErrNone ) |
|
167 // { |
|
168 // CPIXLOGSTRING2("CApplicationsPlugin::CreateApplicationsIndexItemL(): Hidden UIDs = %S", &uidResult ); |
|
169 // TBufC16<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf(uidResult); |
|
170 // HBufC* uidString = buf.AllocLC(); |
|
171 // //If not in the list, it means it is hidden; so dont harvest |
|
172 // if( uidString->FindF( aUid.Name().Mid( KUidStartIndex, KUidEndIndex ) ) != KErrNotFound ) |
|
173 // { |
|
174 // CleanupStack::PopAndDestroy( uidString ); |
|
175 // CPIXLOGSTRING("CApplicationsPlugin::IsAppHidden(): UID in hidden app repository"); |
|
176 // return EFalse; |
|
177 // } |
|
178 // CleanupStack::PopAndDestroy( uidString ); |
|
179 // } |
|
180 |
|
181 CPIXLOGSTRING2("CApplicationsPlugin::IsAppHidden(): %d", &ret); |
|
182 return ret; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 void CApplicationsPlugin::CreateApplicationsIndexItemL( TApaAppInfo& aAppInfo, TCPixActionType /*aActionType*/ ) |
|
187 { |
|
188 //If application has 'hidden' capability, don't index. |
|
189 if( IsAppHiddenL( aAppInfo.iUid ) ) return; |
|
190 |
|
191 TBuf<KMaxFileName> docidString; |
|
192 docidString.Append( aAppInfo.iUid.Name() ); //This returns descriptor in the form "[UID]". So remove the brackets. |
|
193 docidString = docidString.Mid( KUidStartIndex, KUidEndIndex ); |
|
194 |
|
195 CSearchDocument* document = CSearchDocument::NewLC( docidString, _L(APPLICATIONS_APPCLASS) ); |
|
196 document->AddFieldL(KMimeTypeField, KMimeTypeApplication, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
197 document->AddFieldL(KApplicationFieldUid, docidString, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
198 |
|
199 if( iWidgetRegistry.IsWidget( aAppInfo.iUid ) ) |
|
200 AddWidgetInfoL( document, aAppInfo.iUid ); |
|
201 else |
|
202 AddApplicationInfoL( document, aAppInfo ); |
|
203 |
|
204 TRAPD( error, iIndexer->AddL( *document ) ); |
|
205 if( KErrNone == error ) |
|
206 { |
|
207 CPIXLOGSTRING("CApplicationsPlugin::CreateApplicationsIndexItemL(): No Error" ); |
|
208 } |
|
209 else |
|
210 { |
|
211 CPIXLOGSTRING2("CApplicationsPlugin::CreateApplicationsIndexItemL(): Error = %d", error ); |
|
212 } |
|
213 CleanupStack::PopAndDestroy( document ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 void CApplicationsPlugin::DelayedCallbackL( TInt /*aCode*/ ) |
|
218 { |
|
219 TApaAppInfo appInfo; |
|
220 const TInt error = iApplicationServerSession.GetNextApp( appInfo ); |
|
221 if( error == KErrNone ) |
|
222 { |
|
223 CreateApplicationsIndexItemL( appInfo, ECPixAddAction ); |
|
224 } |
|
225 |
|
226 if ( error != RApaLsSession::ENoMoreAppsInList ) |
|
227 { |
|
228 //No need to check IsStatred() since control reaches |
|
229 //here only on asynchornize complete. |
|
230 iAsynchronizer->Start( 0, this, KHarvestingDelay ); |
|
231 } |
|
232 else |
|
233 { |
|
234 Flush( *iIndexer ); |
|
235 #ifdef __PERFORMANCE_DATA |
|
236 UpdatePerformaceDataL(); |
|
237 #endif |
|
238 iObserver->HarvestingCompleted( this, iIndexer->GetBaseAppClass(), KErrNone ); |
|
239 } |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 void CApplicationsPlugin::DelayedError( TInt aCode ) |
|
244 { |
|
245 Flush(*iIndexer); |
|
246 iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), aCode); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 void CApplicationsPlugin::HandleAppListEvent( TInt aEvent ) |
|
251 { |
|
252 CPIXLOGSTRING2("CApplicationsPlugin::HandleAppListEvent: Start with Event = %d", aEvent ); |
|
253 if( aEvent == EAppListChanged ) |
|
254 { |
|
255 if( iAsynchronizer->CallbackPending() ) |
|
256 { |
|
257 iAsynchronizer->CancelCallback(); //first cancel any ongoing harvesting. |
|
258 } |
|
259 TRAP_IGNORE( StartHarvestingL( KNullDesC ) ); //simply reharvest |
|
260 } |
|
261 CPIXLOGSTRING("CApplicationsPlugin::HandleAppListEvent: Exit" ); |
|
262 } |
|
263 |
|
264 #ifdef __PERFORMANCE_DATA |
|
265 void CApplicationsPlugin::UpdatePerformaceDataL() |
|
266 { |
|
267 TTime now; |
|
268 |
|
269 |
|
270 iCompleteTime.UniversalTime(); |
|
271 TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime); |
|
272 |
|
273 RFs fileSession; |
|
274 RFile perfFile; |
|
275 User::LeaveIfError( fileSession.Connect () ); |
|
276 |
|
277 |
|
278 /* Open file if it exists, otherwise create it and write content in it */ |
|
279 |
|
280 if(perfFile.Open(fileSession, _L("c:\\data\\ApplicationsPerf.txt"), EFileWrite)) |
|
281 User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\ApplicationsPerf.txt"), EFileWrite)); |
|
282 |
|
283 HBufC8 *heap = HBufC8::NewL(100); |
|
284 TPtr8 ptr = heap->Des(); |
|
285 now.HomeTime(); |
|
286 TBuf<50> timeString; |
|
287 |
|
288 _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S"); |
|
289 now.FormatL(timeString,KOwnTimeFormat); |
|
290 ptr.AppendNum(now.DateTime().Day()); |
|
291 ptr.Append(_L("/")); |
|
292 ptr.AppendNum(now.DateTime().Month()); |
|
293 ptr.Append(_L("/")); |
|
294 ptr.AppendNum(now.DateTime().Year()); |
|
295 ptr.Append(_L(":")); |
|
296 ptr.Append(timeString); |
|
297 ptr.Append( _L(": Ani: Time took for Harvesting Applications is : ")); |
|
298 ptr.AppendNum(timeDiff.Int64()/1000) ; |
|
299 ptr.Append(_L(" MilliSeonds \n")); |
|
300 TInt myInt = 0; |
|
301 perfFile.Seek(ESeekEnd,myInt); |
|
302 perfFile.Write (ptr); |
|
303 perfFile.Close (); |
|
304 fileSession.Close (); |
|
305 delete heap; |
|
306 } |
|
307 #endif |
|
308 |
|
309 // End of file |