usbengines/usbwatcher/src/cusbdevicelock.cpp
changeset 35 9d8b04ca6939
parent 0 1e05558e2206
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Implements device lock feature in case of USB
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <featmgr.h>
       
    20 #include <bldvariant.hrh>
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32property.h>
       
    24 #include <coreapplicationuisdomainpskeys.h>
       
    25 #include <e32property.h>
       
    26 
       
    27 #include "debug.h"
       
    28 #include "cusbdevicelock.h"
       
    29 #include "cusbwatcher.h"
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // C++ constructor
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 CUsbDeviceLock::CUsbDeviceLock( CUsbWatcher& aOwner )
       
    38     : CActive( EPriorityNormal )
       
    39     , iOwner( aOwner )
       
    40     {
       
    41     LOG_FUNC
       
    42 
       
    43     CActiveScheduler::Add(this);
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // Destructor
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CUsbDeviceLock::~CUsbDeviceLock()
       
    51     {
       
    52     LOG_FUNC
       
    53 
       
    54     if( FeatureManager::FeatureSupported( KFeatureIdUsbDeviceLock ) )
       
    55         {
       
    56         Cancel();
       
    57         iProperty.Close();
       
    58         }
       
    59 
       
    60     FeatureManager::UnInitializeLib();
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // Two-phased constructor.
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CUsbDeviceLock* CUsbDeviceLock::NewL( CUsbWatcher& aOwner )
       
    68     {
       
    69     LOG_FUNC
       
    70 
       
    71     CUsbDeviceLock* self = new ( ELeave ) CUsbDeviceLock( aOwner );
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop(); // pop self
       
    75     return self;
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 void CUsbDeviceLock::ConstructL()
       
    83     {
       
    84     LOG_FUNC
       
    85 
       
    86     FeatureManager::InitializeLibL();
       
    87 
       
    88     if( FeatureManager::FeatureSupported( KFeatureIdUsbDeviceLock ) )
       
    89         {
       
    90         LEAVEIFERROR( iProperty.Attach( KPSUidCoreApplicationUIs,
       
    91             KCoreAppUIsAutolockStatus ) );
       
    92         }
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // Subscribes to P&S property.
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 void CUsbDeviceLock::Subscribe()
       
   100     {
       
   101     LOG_FUNC
       
   102 
       
   103     if( FeatureManager::FeatureSupported( KFeatureIdUsbDeviceLock ) )
       
   104         {
       
   105         if ( !IsActive() )
       
   106             {
       
   107             iProperty.Subscribe( iStatus );
       
   108             SetActive();
       
   109             }
       
   110         else
       
   111             {
       
   112             LOG( "ERROR: request exists" );
       
   113             }
       
   114         }
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // Get device lock state.
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 TBool CUsbDeviceLock::Locked()
       
   122     {
       
   123     LOG_FUNC
       
   124 
       
   125     TInt command;
       
   126     if( FeatureManager::FeatureSupported( KFeatureIdUsbDeviceLock ) )
       
   127         {
       
   128         TInt err = iProperty.Get( command );
       
   129         if(  KErrNone == err )
       
   130             {
       
   131             LOG1( "Autolock status = %d", command );
       
   132             if( EAutolockOff == command )
       
   133                 {
       
   134                 LOG("Device UNLOCKED" );
       
   135                 return EFalse;
       
   136                 }
       
   137             else
       
   138                 {
       
   139                 LOG( "Device LOCKED"  );
       
   140                 }
       
   141             }
       
   142         else
       
   143             {
       
   144             LOG1( "ERROR: RProperty::Get = %d", err );
       
   145             }
       
   146 
       
   147         return ETrue;
       
   148         }
       
   149 
       
   150     return EFalse;
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // Standard active object error function.
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CUsbDeviceLock::RunError( TInt /*aError*/ )
       
   158     {
       
   159     LOG_FUNC
       
   160 
       
   161     return KErrNone;
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // When device lock state changes this method is executed.
       
   166 // ----------------------------------------------------------------------------
       
   167 //
       
   168 void CUsbDeviceLock::RunL()
       
   169     {
       
   170     LOG_FUNC
       
   171     LOG1( "iStatus: %d", iStatus.Int() );
       
   172     Subscribe();
       
   173     TInt command = EAutolockStatusUninitialized;
       
   174     TInt err = iProperty.Get( command );
       
   175     if ( err == KErrNone )
       
   176         {
       
   177         LOG1( "Autolock status: %d", command );
       
   178         switch ( command )
       
   179             {
       
   180             case EAutolockOff:
       
   181                 iOwner.Unlock();
       
   182                 break;
       
   183             case ERemoteLocked:
       
   184                 iOwner.Lock();
       
   185                 break;
       
   186             default:
       
   187                 LOG1( "Unhandled state: %d",  command );
       
   188                 break;
       
   189             }
       
   190         }
       
   191     else
       
   192         {
       
   193         LOG1( "RProperty::Get ERROR %d", err );
       
   194         }
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CUsbMediaWatcher::CUsbDeviceLock::DoCancel
       
   199 // Basic DoCancel.
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 void CUsbDeviceLock::DoCancel()
       
   203     {
       
   204     LOG_FUNC
       
   205 
       
   206     if( FeatureManager::FeatureSupported( KFeatureIdUsbDeviceLock ) )
       
   207         {
       
   208         iProperty.Cancel();
       
   209         }
       
   210     }
       
   211 
       
   212 // End if file