javaruntimes/midp/runtime/src.s60/platformimpl.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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:  Platform dependent implementations.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <DRMHelper.h>
       
    20 #include <drmrightsinfo.h>
       
    21 
       
    22 #include "logger.h"
       
    23 #include "platformimpl.h"
       
    24 #include "javacommonutils.h"
       
    25 
       
    26 void consumeRigthsImplL(const std::wstring& uri, std::string& status,
       
    27                         const CDRMHelper::TDRMHelperConsumeAction action,
       
    28                         int& handle)
       
    29 {
       
    30     JELOG2(EJavaRuntime);
       
    31     LOG1(EJavaRuntime, EInfo, "consumeRigthsImplL. URI: %S", uri.c_str());
       
    32 
       
    33 
       
    34     // Convert wstring to 16 bit descriptor.
       
    35     TPtrC ptr((const TUint16 *)uri.c_str(), uri.length());
       
    36 
       
    37     CDRMHelper* drmHelper = reinterpret_cast<CDRMHelper*>(handle);
       
    38 
       
    39     // In case of start we need to create instance of CDRMHelper.
       
    40     if (action == CDRMHelper::EStart)
       
    41     {
       
    42         drmHelper = CDRMHelper::NewLC();
       
    43         handle = reinterpret_cast<int>(drmHelper);
       
    44     }
       
    45 
       
    46     int err = -1;
       
    47     if (drmHelper)
       
    48     {
       
    49         err = drmHelper->ConsumeFile2(ptr, ContentAccess::EExecute, action);
       
    50     }
       
    51     if (action == CDRMHelper::EFinish)
       
    52     {
       
    53         delete drmHelper;
       
    54         drmHelper = NULL;
       
    55     }
       
    56     else
       
    57     {
       
    58         CleanupStack::Pop(drmHelper);
       
    59     }
       
    60     if (err != KErrNone)
       
    61     {
       
    62         delete drmHelper;
       
    63         handle = 0;
       
    64     }
       
    65 
       
    66     switch (err)
       
    67     {
       
    68     case KErrNone:
       
    69         status.clear();
       
    70         break;
       
    71 
       
    72     case KErrCANoPermission:
       
    73         status = "Rights exist but the execute intent is not permitted";
       
    74         break;
       
    75 
       
    76     case KErrCAPendingRights:
       
    77         status = "Rights have not yet arrived but are expected soon";
       
    78         break;
       
    79 
       
    80     case KErrPermissionDenied:
       
    81         status = "Client is not allowed to use this content object";
       
    82         break;
       
    83 
       
    84     default:
       
    85         ELOG1(EJavaRuntime, "CDRMHelper::ConsumeFile2 failed: %d", err);
       
    86         User::Leave(err);
       
    87         break;
       
    88 
       
    89     }
       
    90 }
       
    91 
       
    92 bool checkRigthsL(const std::wstring& drmContentId, std::string& status)
       
    93 {
       
    94     JELOG2(EJavaRuntime);
       
    95     LOG1(EJavaRuntime, EInfo, "checkRigthsL. drmContentId: %S",
       
    96          drmContentId.c_str());
       
    97 
       
    98     // Convert wstring to 16 bit descriptor.
       
    99     TPtrC ptr((const TUint16 *)drmContentId.c_str(), drmContentId.length());
       
   100 
       
   101     DRM::CDrmRightsInfo* ri(DRM::CDrmRightsInfo::NewLC());
       
   102     DRM::TDrmRightsInfo rightsInfo(DRM::EURightsInfoValid);
       
   103 
       
   104     // Check if there are still valid rigths.
       
   105     TRAPD(err, ri->CheckRightsL(ptr,
       
   106                                 ContentAccess::EExecute,
       
   107                                 rightsInfo)) ;
       
   108 
       
   109     CleanupStack::PopAndDestroy(ri);
       
   110     // If leave happened consider it fatal.
       
   111     if (err != KErrNone)
       
   112     {
       
   113         ELOG1(EJavaRuntime, "CheckRightsL failed: %d", err);
       
   114         User::Leave(err);
       
   115     }
       
   116 
       
   117     LOG1(EJavaRuntime, EInfo, "checkRigthsL, rightsInfo: %d", rightsInfo);
       
   118 
       
   119 
       
   120     if (rightsInfo == DRM::EURightsInfoValid)
       
   121     {
       
   122         return true;
       
   123     }
       
   124 
       
   125     WLOG1(EJavaRuntime, "No more rights to start MIDlet: rightsInfo = %d",
       
   126           rightsInfo);
       
   127     status = "No more rights to start MIDlet";
       
   128     return false;
       
   129 }
       
   130 
       
   131 void consumeRigthsImpl(const std::wstring& uri,
       
   132                        const std::wstring& drmContentId,
       
   133                        std::string& status,
       
   134                        bool startPhase,
       
   135                        int& handle)
       
   136 {
       
   137     JELOG2(EJavaRuntime);
       
   138 
       
   139     bool rightsOk = true;
       
   140 
       
   141     int err = KErrNone;
       
   142     // Need to check only when starting the MIDlet.
       
   143     if (startPhase)
       
   144     {
       
   145         // Check if there are still valid rights.
       
   146         TRAP(err, rightsOk = checkRigthsL(drmContentId, status););
       
   147     }
       
   148 
       
   149     if (err == KErrNone && rightsOk)
       
   150     {
       
   151         // Rigths where still valid, so lets consume rights.
       
   152         const CDRMHelper::TDRMHelperConsumeAction action =
       
   153             startPhase ? CDRMHelper::EStart : CDRMHelper::EFinish;
       
   154         TRAP(err, consumeRigthsImplL(uri, status, action, handle););
       
   155     }
       
   156     if (err != KErrNone)
       
   157     {
       
   158         ELOG1(EJavaRuntime, "ERROR!!! consumeRigthsImpl() %d", err);
       
   159         status = "General OS error code: ";
       
   160         status += java::util::JavaCommonUtils::intToString(err);
       
   161     }
       
   162 }