114
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 <mcsmenuutils.h>
|
|
19 |
#include <javaregistry.h>
|
|
20 |
#include <javaregistryentry.h>
|
|
21 |
#include <drmrightsinfo.h>
|
|
22 |
|
|
23 |
#include "menusrvengutils.h"
|
|
24 |
#include "mcsdef.h"
|
|
25 |
#include "mcssathandler.h"
|
|
26 |
|
|
27 |
// ================= MEMBER FUNCTIONS =======================
|
|
28 |
|
|
29 |
// ---------------------------------------------------------
|
|
30 |
// CMenuSrvEngUtils::~CMenuSrvEngUtils
|
|
31 |
// ---------------------------------------------------------
|
|
32 |
//
|
|
33 |
CMenuSrvEngUtils::~CMenuSrvEngUtils()
|
|
34 |
{
|
|
35 |
delete iSatHandler;
|
|
36 |
iApaLsSession.Close();
|
|
37 |
iWidgetSession.Close();
|
|
38 |
iWsSession.Close();
|
|
39 |
iAppAttributes.ResetAndDestroy();
|
|
40 |
}
|
|
41 |
|
|
42 |
// ---------------------------------------------------------
|
|
43 |
// CMenuSrvEngUtils::NewL
|
|
44 |
// ---------------------------------------------------------
|
|
45 |
//
|
|
46 |
CMenuSrvEngUtils* CMenuSrvEngUtils::NewL( CMenuEng& aEng )
|
|
47 |
{
|
|
48 |
CMenuSrvEngUtils* utils = new (ELeave) CMenuSrvEngUtils( aEng );
|
|
49 |
CleanupStack::PushL( utils );
|
|
50 |
utils->ConstructL();
|
|
51 |
CleanupStack::Pop( utils );
|
|
52 |
return utils;
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------
|
|
56 |
// CMenuSrvEngUtils::CMenuSrvEngUtils
|
|
57 |
// ---------------------------------------------------------
|
|
58 |
//
|
|
59 |
CMenuSrvEngUtils::CMenuSrvEngUtils( CMenuEng& aEng )
|
|
60 |
: iEng( aEng )
|
|
61 |
{
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------
|
|
65 |
// CMenuSrvEngUtils::ConstructL
|
|
66 |
// ---------------------------------------------------------
|
|
67 |
//
|
|
68 |
void CMenuSrvEngUtils::ConstructL()
|
|
69 |
{
|
|
70 |
User::LeaveIfError( iApaLsSession.Connect() );
|
|
71 |
User::LeaveIfError( iWidgetSession.Connect() );
|
|
72 |
User::LeaveIfError( iWsSession.Connect() );
|
|
73 |
iSatHandler = CMcsSatHandler::NewL();
|
|
74 |
}
|
|
75 |
|
|
76 |
// ---------------------------------------------------------
|
|
77 |
// CMenuSrvEngUtils::GetAppInfo
|
|
78 |
// ---------------------------------------------------------
|
|
79 |
//
|
|
80 |
TInt CMenuSrvEngUtils::GetAppInfoL( const CMenuEngObject& aEngObj, TApaAppInfo& aAppInfo ) const
|
|
81 |
{
|
|
82 |
TUid appUid;
|
|
83 |
TInt err = GetAppUid( aEngObj, appUid );
|
|
84 |
if ( !err )
|
|
85 |
{
|
|
86 |
if( appUid == KSatUid )
|
|
87 |
{
|
|
88 |
err = GetSatAppInfo( aAppInfo );
|
|
89 |
}
|
|
90 |
else
|
|
91 |
{
|
|
92 |
aAppInfo.iUid = appUid;
|
|
93 |
err = GetAppInfoFromArrayL( aAppInfo );
|
|
94 |
if( err )
|
|
95 |
{
|
|
96 |
err = iApaLsSession.GetAppInfo( aAppInfo, appUid );
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
return err;
|
|
101 |
}
|
|
102 |
|
|
103 |
// ---------------------------------------------------------
|
|
104 |
// CMenuSrvEngUtils::IsNativeL
|
|
105 |
// ---------------------------------------------------------
|
|
106 |
//
|
|
107 |
|
|
108 |
TInt CMenuSrvEngUtils::IsNativeL( TUid aAppUid, TBool& aIsNative )
|
|
109 |
{
|
|
110 |
TInt error( KErrNotFound );
|
|
111 |
CMenuEngObject::TAppType aType;
|
|
112 |
error = GetAppTypeFromArrayL( aAppUid, aType );
|
|
113 |
if ( error == KErrNone && aType == CMenuEngObject::ENativeApp )
|
|
114 |
{
|
|
115 |
aIsNative = ETrue;
|
|
116 |
}
|
|
117 |
else if( error != KErrNone )
|
|
118 |
{
|
|
119 |
TApaAppInfo appInfo;
|
|
120 |
error = iApaLsSession.GetAppInfo( appInfo, aAppUid );
|
|
121 |
if( error == KErrNone )
|
|
122 |
{
|
|
123 |
error = iApaLsSession.IsProgram( appInfo.iFullName, aIsNative );
|
|
124 |
}
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
|
128 |
aIsNative = EFalse;
|
|
129 |
}
|
|
130 |
return error;
|
|
131 |
}
|
|
132 |
|
|
133 |
// ---------------------------------------------------------
|
|
134 |
// CMenuSrvEngUtils::GetDrmProtectionByContentIdL
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
//
|
|
137 |
TInt CMenuSrvEngUtils::GetDrmProtectionByContentIdL(const TDesC& aContentId,
|
|
138 |
TDRMProtectionInfo& aProtectionInfo) const
|
|
139 |
{
|
|
140 |
TInt err( KErrNone );
|
|
141 |
DRM::CDrmRightsInfo* drmInfo = DRM::CDrmRightsInfo::NewL();
|
|
142 |
CleanupStack::PushL( drmInfo );
|
|
143 |
|
|
144 |
{
|
|
145 |
DRM::TDrmRightsInfo drmRightInfo;
|
|
146 |
TRAP( err, drmInfo->CheckRightsL( aContentId,
|
|
147 |
ContentAccess::EExecute,
|
|
148 |
drmRightInfo ); )
|
|
149 |
if( err == KErrNone )
|
|
150 |
{
|
|
151 |
switch (drmRightInfo)
|
|
152 |
{
|
|
153 |
case (DRM::EURightsInfoValid)://1
|
|
154 |
aProtectionInfo = EDRMProtected;
|
|
155 |
break;
|
|
156 |
|
|
157 |
case (DRM::EURightsInfoExpired)://2
|
|
158 |
aProtectionInfo = EDRMRightsExpired;
|
|
159 |
break;
|
|
160 |
|
|
161 |
case (DRM::EURightsInfoMissing)://3
|
|
162 |
aProtectionInfo = EDRMRightsExpired;
|
|
163 |
break;
|
|
164 |
case (DRM::EURightsInfoFuture)://4
|
|
165 |
|
|
166 |
default:
|
|
167 |
aProtectionInfo = EDRMUnknownProtection;
|
|
168 |
break;
|
|
169 |
}
|
|
170 |
}
|
|
171 |
}
|
|
172 |
CleanupStack::PopAndDestroy( drmInfo );
|
|
173 |
return err;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
// ---------------------------------------------------------
|
|
178 |
// CMenuSrvEngUtils::GetDrmProtection
|
|
179 |
// ---------------------------------------------------------
|
|
180 |
//
|
|
181 |
TInt CMenuSrvEngUtils::GetDrmProtectionL(
|
|
182 |
const TUid aAppUid, TDRMProtectionInfo& aProtectionInfo ) const
|
|
183 |
{
|
|
184 |
TInt err( KErrNone );
|
|
185 |
|
|
186 |
TApaAppInfo info;
|
|
187 |
|
|
188 |
aProtectionInfo = EDRMUnknownProtection;
|
|
189 |
CMenuEngObject::TAppType aType;
|
|
190 |
err = GetAppTypeFromArrayL( aAppUid, aType );
|
|
191 |
if( ( !err && aType == CMenuEngObject::EJavaApp )
|
|
192 |
|| ( err && IsMiddlet( aAppUid ) ) )
|
|
193 |
{
|
|
194 |
TBuf<KMaxFileName> contentId;
|
|
195 |
GetJavaContentIdL( aAppUid, contentId );
|
|
196 |
if ( contentId != KNullDesC )
|
|
197 |
{
|
|
198 |
GetDrmProtectionByContentIdL( contentId, aProtectionInfo );
|
|
199 |
}
|
|
200 |
}
|
|
201 |
return err;
|
|
202 |
}
|
|
203 |
|
|
204 |
// ---------------------------------------------------------
|
|
205 |
// CMenuSrvEngUtils::GetDrmProtection
|
|
206 |
// ---------------------------------------------------------
|
|
207 |
//
|
|
208 |
TInt CMenuSrvEngUtils::GetDrmProtectionL(
|
|
209 |
const CMenuEngObject& aEngObj,
|
|
210 |
TDRMProtectionInfo& aProtectionInfo ) const
|
|
211 |
{
|
|
212 |
TInt err( KErrNone );
|
|
213 |
|
|
214 |
if ( aEngObj.Type().CompareF( KMenuTypeApp ) == 0 )
|
|
215 |
{
|
|
216 |
TUid uid;
|
|
217 |
err = CMenuSrvEngUtils::GetAppUid( aEngObj, uid );
|
|
218 |
if ( err == KErrNone )
|
|
219 |
{
|
|
220 |
err = GetDrmProtectionL( uid, aProtectionInfo );
|
|
221 |
}
|
|
222 |
}
|
|
223 |
else
|
|
224 |
{
|
|
225 |
err = KErrNone;
|
|
226 |
aProtectionInfo = EDRMUnknownProtection;
|
|
227 |
}
|
|
228 |
|
|
229 |
return err;
|
|
230 |
}
|
|
231 |
|
|
232 |
// ---------------------------------------------------------
|
|
233 |
// CMenuSrvEngUtils::GetDrmProtection
|
|
234 |
// ---------------------------------------------------------
|
|
235 |
//
|
|
236 |
TInt CMenuSrvEngUtils::GetDrmProtectionL(TInt aItemId,
|
|
237 |
TDRMProtectionInfo& aProtectionInfo) const
|
|
238 |
{
|
|
239 |
TInt err( 0 );
|
|
240 |
const CMenuEngObject& obj = iEng.ObjectL( aItemId );
|
|
241 |
err = GetDrmProtectionL( obj, aProtectionInfo );
|
|
242 |
return err;
|
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------
|
|
246 |
// CMenuSrvEngUtils::GetSatAppInfo
|
|
247 |
// ---------------------------------------------------------
|
|
248 |
//
|
|
249 |
TInt CMenuSrvEngUtils::GetSatAppInfo( TApaAppInfo& aAppInfo ) const
|
|
250 |
{
|
|
251 |
TBuf<KApaMaxAppCaption> aBuf;
|
|
252 |
TInt err = iSatHandler->GetName( aBuf );
|
|
253 |
if( err == KErrNone )
|
|
254 |
{
|
|
255 |
aAppInfo.iShortCaption = aBuf;
|
|
256 |
aAppInfo.iCaption = aBuf;
|
|
257 |
}
|
|
258 |
return err;
|
|
259 |
}
|
|
260 |
|
|
261 |
// ---------------------------------------------------------
|
|
262 |
// CMenuSrvEngUtils::IsMiddlet
|
|
263 |
// ---------------------------------------------------------
|
|
264 |
//
|
|
265 |
TBool CMenuSrvEngUtils::IsMiddlet( const TUid aAppUid ) const
|
|
266 |
{
|
|
267 |
const TUid KMidletType = { 0x10210E26 };
|
|
268 |
TUid typeuid = KNullUid;
|
|
269 |
|
|
270 |
if ( KErrNone == iApaLsSession.GetAppType( typeuid, aAppUid ) )
|
|
271 |
{
|
|
272 |
if ( typeuid == KMidletType )
|
|
273 |
{
|
|
274 |
return ETrue;
|
|
275 |
}
|
|
276 |
}
|
|
277 |
return EFalse;
|
|
278 |
}
|
|
279 |
|
|
280 |
// ---------------------------------------------------------
|
|
281 |
// GetAppUid
|
|
282 |
// ---------------------------------------------------------
|
|
283 |
//
|
|
284 |
TInt CMenuSrvEngUtils::GetAppUid( const CMenuEngObject& aEngObj, TUid& aAppUid )
|
|
285 |
{
|
|
286 |
TInt err( 0 );
|
|
287 |
TPtrC attrVal;
|
|
288 |
TBool attrExists( EFalse );
|
|
289 |
TBool localized( EFalse );//
|
|
290 |
attrExists = aEngObj.FindAttribute( KMenuAttrUid, attrVal, localized );
|
|
291 |
if ( !attrExists )
|
|
292 |
{
|
|
293 |
err = KErrNotFound;
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
TUint appUid;
|
|
298 |
err = MenuUtils::GetTUint( attrVal, appUid );
|
|
299 |
if ( !err )
|
|
300 |
{
|
|
301 |
aAppUid = TUid::Uid( appUid );
|
|
302 |
}
|
|
303 |
}
|
|
304 |
return err;
|
|
305 |
}
|
|
306 |
|
|
307 |
// ---------------------------------------------------------
|
|
308 |
// CMenuSrvEngUtils::GetJavaContentIdL
|
|
309 |
// ---------------------------------------------------------
|
|
310 |
//
|
|
311 |
void CMenuSrvEngUtils::GetJavaContentIdL( TUid aUid, TDes& aContentId ) const
|
|
312 |
{
|
|
313 |
Java::CJavaRegistry* javaRegistry;
|
|
314 |
Java::CJavaRegistryEntry* regEntry = NULL;
|
|
315 |
|
|
316 |
javaRegistry = Java::CJavaRegistry::NewL();
|
|
317 |
CleanupStack::PushL( javaRegistry );
|
|
318 |
|
|
319 |
//regEntry will be NULL if there is no Java application
|
|
320 |
//corresponding to the specified aUid
|
|
321 |
regEntry = javaRegistry->RegistryEntryL( aUid );
|
|
322 |
|
|
323 |
//DrmContentId() will return reference to NULL when
|
|
324 |
//Java application is not DRM protected
|
|
325 |
if( regEntry && ( ®Entry->DrmContentId() ) )
|
|
326 |
{
|
|
327 |
aContentId.Copy( regEntry->DrmContentId() );
|
|
328 |
}
|
|
329 |
else
|
|
330 |
{
|
|
331 |
aContentId.Copy( KNullDesC );
|
|
332 |
}
|
|
333 |
|
|
334 |
delete regEntry;
|
|
335 |
CleanupStack::PopAndDestroy( javaRegistry );
|
|
336 |
}
|
|
337 |
|
|
338 |
// ---------------------------------------------------------
|
|
339 |
// CMenuSrvAppScanner::GetApaItemsL
|
|
340 |
// ---------------------------------------------------------
|
|
341 |
//
|
|
342 |
void CMenuSrvEngUtils::ReloadApaItemsL()
|
|
343 |
{
|
|
344 |
iAppAttributes.ResetAndDestroy();
|
|
345 |
TApaAppInfo appInfo;
|
|
346 |
TApaAppCapabilityBuf appCap;
|
|
347 |
|
|
348 |
User::LeaveIfError( iApaLsSession.GetAllApps( 0 ) );
|
|
349 |
// for every application get uid, hidden and missing attribute
|
|
350 |
// and add to aArray.
|
|
351 |
while ( KErrNone == iApaLsSession.GetNextApp( appInfo ) )
|
|
352 |
{
|
|
353 |
User::LeaveIfError(
|
|
354 |
iApaLsSession.GetAppCapability( appCap, appInfo.iUid ) );
|
|
355 |
// "Hidden" status according to AppArc.
|
|
356 |
TBool appHidden = appCap().iAppIsHidden;
|
|
357 |
|
|
358 |
CMenuSrvAppAttributes* appAtributes = CMenuSrvAppAttributes::NewLC( appCap, appInfo );
|
|
359 |
if( IsMiddlet( appInfo.iUid ) )
|
|
360 |
{
|
|
361 |
appAtributes->SetAppType( CMenuEngObject::EJavaApp );
|
|
362 |
}
|
|
363 |
else if( iWidgetSession.IsWidget( appInfo.iUid ) )
|
|
364 |
{
|
|
365 |
appAtributes->SetAppType( CMenuEngObject::EWidgetApp );
|
|
366 |
}
|
|
367 |
else
|
|
368 |
{
|
|
369 |
//TODO: it is really necessary?
|
|
370 |
TBool isNative( EFalse );
|
|
371 |
iApaLsSession.IsProgram( appInfo.iFullName, isNative );
|
|
372 |
if( isNative )
|
|
373 |
{
|
|
374 |
appAtributes->SetAppType( CMenuEngObject::ENativeApp );
|
|
375 |
}
|
|
376 |
}
|
|
377 |
|
|
378 |
iAppAttributes.AppendL( appAtributes );
|
|
379 |
CleanupStack::Pop( appAtributes );
|
|
380 |
}
|
|
381 |
}
|
|
382 |
|
|
383 |
// ---------------------------------------------------------
|
|
384 |
//
|
|
385 |
// ---------------------------------------------------------
|
|
386 |
//
|
|
387 |
TInt CMenuSrvEngUtils::GetAppInfoFromArrayL( TApaAppInfo& aAppInfo ) const
|
|
388 |
{
|
|
389 |
TApaAppCapabilityBuf capability;
|
|
390 |
CMenuSrvAppAttributes* attribute = CMenuSrvAppAttributes::NewLC( capability, aAppInfo );
|
|
391 |
TInt index = iAppAttributes.Find( attribute,
|
|
392 |
TIdentityRelation<CMenuSrvAppAttributes>( CMenuSrvAppAttributes::MatchItems ) );
|
|
393 |
if( index >= 0 )
|
|
394 |
{
|
|
395 |
aAppInfo.iCaption = iAppAttributes[index]->GetCaption();
|
|
396 |
aAppInfo.iFullName = iAppAttributes[index]->GetFullName();
|
|
397 |
aAppInfo.iShortCaption = iAppAttributes[index]->GetShortCaption();
|
|
398 |
index = KErrNone;
|
|
399 |
}
|
|
400 |
CleanupStack::PopAndDestroy( attribute );
|
|
401 |
return index;
|
|
402 |
}
|
|
403 |
|
|
404 |
// ---------------------------------------------------------
|
|
405 |
//
|
|
406 |
// ---------------------------------------------------------
|
|
407 |
//
|
|
408 |
TInt CMenuSrvEngUtils::GetAppTypeFromArrayL( const TUid& aAppUid,
|
|
409 |
CMenuEngObject::TAppType& aType ) const
|
|
410 |
{
|
|
411 |
TApaAppCapabilityBuf capability;
|
|
412 |
TApaAppInfo appInfo;
|
|
413 |
appInfo.iUid = aAppUid;
|
|
414 |
CMenuSrvAppAttributes* attribute = CMenuSrvAppAttributes::NewLC( capability, appInfo );
|
|
415 |
TInt index = iAppAttributes.Find( attribute,
|
|
416 |
TIdentityRelation<CMenuSrvAppAttributes>( CMenuSrvAppAttributes::MatchItems ) );
|
|
417 |
if( index >= 0 )
|
|
418 |
{
|
|
419 |
aType = iAppAttributes[index]->GetAppType();
|
|
420 |
index = KErrNone;
|
|
421 |
}
|
|
422 |
|
|
423 |
CleanupStack::PopAndDestroy( attribute );
|
|
424 |
return index;
|
|
425 |
}
|
|
426 |
|
|
427 |
// ---------------------------------------------------------
|
|
428 |
//
|
|
429 |
// ---------------------------------------------------------
|
|
430 |
//
|
|
431 |
RPointerArray<CMenuSrvAppAttributes>& CMenuSrvEngUtils::GetAppItemsL()
|
|
432 |
{
|
|
433 |
return iAppAttributes;
|
|
434 |
}
|
|
435 |
|
|
436 |
// ---------------------------------------------------------
|
|
437 |
// MenuSrvUtil::UidToStringL
|
|
438 |
// ---------------------------------------------------------
|
|
439 |
//
|
|
440 |
void MenuSrvUtil::UidToStringL( TUint aUid, TDes& aResult,
|
|
441 |
TBool aLegacy, TRadix aRadix )
|
|
442 |
{
|
|
443 |
aResult.Zero();
|
|
444 |
|
|
445 |
TBuf<KUidChars> number;
|
|
446 |
if( !aLegacy )
|
|
447 |
{
|
|
448 |
if (aRadix == EHex)
|
|
449 |
{
|
|
450 |
aResult.Append( KHex );
|
|
451 |
}
|
|
452 |
}
|
|
453 |
number.AppendNum( aUid, aRadix );
|
|
454 |
number.UpperCase();
|
|
455 |
|
|
456 |
aResult.Append( number );
|
|
457 |
}
|