appinstall_plat/appmngr2runtimeapi/src/appmngr2drmutils.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Utility functions for DRM file handling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2drmutils.h"           // TAppMngr2DRMUtils
       
    20 #include "appmngr2debugutils.h"         // FLOG macros
       
    21 #include <caf/content.h>                // ContentAccess::CContent
       
    22 #include <DRMHelper.h>                  // CDRMHelper
       
    23 
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // TAppMngr2DRMUtils::IsDRMProtected()
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C TBool TAppMngr2DRMUtils::IsDRMProtected( const TDesC& aFileName )
       
    32     {
       
    33     FLOG( "TAppMngr2DRMUtils::IsDRMProtected( %S )", &aFileName );
       
    34     TInt isProtected = EFalse;
       
    35 
       
    36     ContentAccess::CContent* content = NULL;
       
    37     TRAPD( err, content = ContentAccess::CContent::NewL( aFileName ) );
       
    38     FLOG( "TAppMngr2DRMUtils::IsDRMProtected(), CAF err %d", err );
       
    39     if( err == KErrNone )
       
    40         {
       
    41         content->GetAttribute( ContentAccess::EIsProtected, isProtected );
       
    42         delete content;
       
    43         }
       
    44     
       
    45     FLOG( "TAppMngr2DRMUtils::IsDRMProtected() returns %d", isProtected );
       
    46     return isProtected;
       
    47 	}
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // TAppMngr2DRMUtils::IsDRMForwardable()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C TBool TAppMngr2DRMUtils::IsDRMForwardable( const TDesC& aFileName )
       
    54     {
       
    55     FLOG( "TAppMngr2DRMUtils::IsDRMForwardable( %S )", &aFileName );
       
    56 	TInt isForwardable = ETrue;
       
    57 
       
    58     ContentAccess::CContent* content = NULL;
       
    59     TRAPD( err, content = ContentAccess::CContent::NewL( aFileName ) );
       
    60     FLOG( "TAppMngr2DRMUtils::IsDRMForwardable(), CAF err %d", err );
       
    61     if( err == KErrNone )
       
    62         {
       
    63         content->GetAttribute( ContentAccess::EIsForwardable, isForwardable );
       
    64         delete content;
       
    65         }
       
    66 
       
    67     FLOG( "TAppMngr2DRMUtils::IsDRMForwardable() returns %d", isForwardable );
       
    68 	return isForwardable;
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // TAppMngr2DRMUtils::IsDRMRightsObjectExpiredOrMissingL()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C TBool TAppMngr2DRMUtils::IsDRMRightsObjectExpiredOrMissingL( const TDesC& aFileName )
       
    76     {
       
    77     FLOG( "TAppMngr2DRMUtils::IsDRMRightsObjectExpiredOrMissingL( %S )", &aFileName );
       
    78 	TInt err = KErrNone;
       
    79 	
       
    80     ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFileName );
       
    81   	content->GetAttribute( ContentAccess::ECanExecute, err );
       
    82     CleanupStack::PopAndDestroy( content );
       
    83 
       
    84     TBool isRightsObjectExpiredOrMissing = EFalse;
       
    85     if( err == KErrCANoRights || err == KErrCANoPermission )
       
    86         {
       
    87         isRightsObjectExpiredOrMissing = ETrue;
       
    88         }
       
    89     FLOG( "TAppMngr2DRMUtils::IsDRMRightsObjectExpiredOrMissingL() returns %d", 
       
    90             isRightsObjectExpiredOrMissing );
       
    91     return isRightsObjectExpiredOrMissing;
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // TAppMngr2DRMUtils::IsDRMRightsObjectMissingL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C TBool TAppMngr2DRMUtils::IsDRMRightsObjectMissingL( const TDesC& aFileName )
       
    99     {
       
   100     FLOG( "TAppMngr2DRMUtils::IsDRMRightsObjectMissingL( %S )", &aFileName );
       
   101     TUint32 intent = 0;
       
   102     TBool isExpired = EFalse;
       
   103     TBool isSendingAllowed = EFalse;
       
   104 
       
   105     CDRMHelperRightsConstraints* rightsPlay = NULL;
       
   106     CDRMHelperRightsConstraints* rightsDisplay = NULL; 
       
   107     CDRMHelperRightsConstraints* rightsExecute = NULL; 
       
   108     CDRMHelperRightsConstraints* rightsPrint = NULL;
       
   109 
       
   110     CDRMHelper* drm = CDRMHelper::NewLC( *CCoeEnv::Static() );
       
   111     TRAPD( err, drm->GetRightsDetailsL( aFileName, intent, isExpired, isSendingAllowed,
       
   112             rightsPlay, rightsDisplay, rightsExecute, rightsPrint ));
       
   113     FLOG( "TAppMngr2DRMUtils::IsDRMRightsObjectMissingL(), GetRightsDetailsL err %d", err );
       
   114     CleanupStack::PopAndDestroy( drm );
       
   115     
       
   116     delete rightsPlay;
       
   117     delete rightsDisplay;
       
   118     delete rightsExecute;
       
   119     delete rightsPrint;
       
   120     
       
   121     TBool isRightsObjectMissing = EFalse;
       
   122     if( err == KErrCANoRights )
       
   123         {
       
   124         isRightsObjectMissing = ETrue;
       
   125         }
       
   126     FLOG( "TAppMngr2DRMUtils::IsDRMRightsObjectMissingL() returns %d", isRightsObjectMissing );
       
   127     return isRightsObjectMissing;
       
   128     }
       
   129