devicediagnostics/diagplugins/diagpdptestengine/src/diagpdptestengine.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007 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:  This is the class module for the PDP Test Engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <DiagFrameworkDebug.h>                 // debug macros
       
    21 #include "diagpdptestengine.h"
       
    22 #include <cmpluginpacketdatadef.h>
       
    23 //#include <AknLists.h>
       
    24 //#include <BADESCA.H >
       
    25 //#include <aknPopup.h> 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES
       
    29 
       
    30 // CONSTANTS
       
    31 //const TInt KConnArrayGranularity = ( 3 );
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ==============================
       
    44 
       
    45 // ========================= MEMBER FUNCTIONS ================================
       
    46   
       
    47  
       
    48 // ----------------------------------------------------------------------------
       
    49 // CDiagPDPTestEngine::CDiagPDPTestEngine()
       
    50 //
       
    51 // C++ default constructor
       
    52 // ----------------------------------------------------------------------------    
       
    53 CDiagPDPTestEngine::CDiagPDPTestEngine() 
       
    54     : CActive(CActive::EPriorityUserInput)
       
    55     {
       
    56     // no implementation needed 
       
    57     }
       
    58    
       
    59 // ----------------------------------------------------------------------------
       
    60 // CDiagPDPTestEngine::~CDiagPDPTestEngine()
       
    61 //
       
    62 // C++ default destructor
       
    63 // ----------------------------------------------------------------------------    
       
    64 CDiagPDPTestEngine::~CDiagPDPTestEngine()
       
    65     {
       
    66     // no implementation needed
       
    67     }   
       
    68    
       
    69 // ----------------------------------------------------------------------------
       
    70 // CDiagPDPTestEngine::RunL()
       
    71 //
       
    72 // Handle asynchronous requests
       
    73 // ----------------------------------------------------------------------------     
       
    74 void CDiagPDPTestEngine::RunL()
       
    75     {
       
    76     // no implementation needed 
       
    77     } 
       
    78     
       
    79     
       
    80 // ----------------------------------------------------------------------------
       
    81 // CDiagPDPTestEngine::DoCancel()
       
    82 //
       
    83 // Handle cancellation of asynchronous requests
       
    84 // ----------------------------------------------------------------------------    
       
    85 void CDiagPDPTestEngine::DoCancel()
       
    86     {
       
    87     // no implementation needed 
       
    88     }
       
    89     
       
    90 // ----------------------------------------------------------------------------
       
    91 // CDiagPDPTestEngine::CheckAPNsInConnectionManagerL()
       
    92 //
       
    93 // 
       
    94 // ----------------------------------------------------------------------------    
       
    95 TBool CDiagPDPTestEngine::CheckAPNsInConnectionManagerL()
       
    96     {
       
    97     LOGSTRING( "CDiagPDPTestEngine::CheckAPNsInConnectionManagerL()" );
       
    98     /*RArray<TUint32> idArray;
       
    99     CleanupClosePushL( idArray );
       
   100 
       
   101     CDesCArrayFlat* nameArray = new (ELeave) CDesCArrayFlat(16);
       
   102     CleanupStack::PushL( nameArray );
       
   103     
       
   104     // Get IAP names and ids from the database
       
   105     CCommsDatabase* TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   106     CleanupStack::PushL( TheDb );
       
   107 
       
   108     TheDb->ShowHiddenRecords();
       
   109 
       
   110     CCommsDbTableView* view = TheDb->OpenTableLC( TPtrC(IAP) );
       
   111 
       
   112     TBuf<40> name;
       
   113     TUint32 id,aId;
       
   114     TInt res = view->GotoFirstRecord();
       
   115     while( res == KErrNone )
       
   116     {
       
   117         view->ReadTextL( TPtrC(COMMDB_NAME), name );
       
   118         view->ReadUintL( TPtrC(COMMDB_ID), id );
       
   119         
       
   120         idArray.Insert( id, 0 );
       
   121         nameArray->InsertL( 0, name );
       
   122 
       
   123         res = view->GotoNextRecord();
       
   124         RDebug::Print(_L("IAP name, id: %S, %d"), &name, id);
       
   125     }
       
   126     
       
   127     CleanupStack::PopAndDestroy( view ); // view
       
   128     CleanupStack::PopAndDestroy( TheDb ); // TheDb
       
   129     
       
   130     // Create listbox and PUSH it.
       
   131     CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox;
       
   132     CleanupStack::PushL( list );
       
   133     
       
   134     // Create popup list and PUSH it.
       
   135     CAknPopupList* popupList = CAknPopupList::NewL(
       
   136         list, R_AVKON_SOFTKEYS_OK_CANCEL,
       
   137         AknPopupLayouts::EMenuWindow);
       
   138     CleanupStack::PushL( popupList );
       
   139     
       
   140     // initialize listbox.
       
   141     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
       
   142     list->CreateScrollBarFrameL( ETrue );
       
   143     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   144         CEikScrollBarFrame::EOff,
       
   145         CEikScrollBarFrame::EAuto );
       
   146     
       
   147     // Set listitems.
       
   148     CTextListBoxModel* model = list->Model();
       
   149     model->SetItemTextArray( nameArray );
       
   150     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   151     
       
   152     // Set title
       
   153     popupList->SetTitleL( _L("Select IAP:") );
       
   154     
       
   155     // Show popup list.
       
   156     TInt popupOk = popupList->ExecuteLD();
       
   157     CleanupStack::Pop( popupList ); // popupList
       
   158     if ( popupOk )
       
   159         {
       
   160         TInt index = list->CurrentItemIndex();
       
   161         aId = idArray[index];
       
   162         }
       
   163     
       
   164     CleanupStack::PopAndDestroy( 3, &idArray );  // list, nameArray, idArray
       
   165     
       
   166     if(popupOk != EFalse)
       
   167 					{
       
   168 					iIAPiddefault = aId;
       
   169 					}
       
   170 		return popupOk;*/
       
   171 		
       
   172 		
       
   173        /*CCommsDatabase* cdb = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   174        CleanupStack::PushL(cdb);
       
   175        LOGSTRING("CCommsDatabase::NewL");
       
   176        CApDataHandler* apDataHandler = CApDataHandler::NewLC(*cdb);
       
   177        LOGSTRING("CApDataHandler::NewLC");
       
   178        iIAPiddefault = apDataHandler->DefaultL(EFalse);
       
   179        LOGSTRING2( "CApDataHandler->Default %d",iIAPiddefault );
       
   180        CleanupStack::PopAndDestroy(2);
       
   181        LOGSTRING( "pop/destroy 2");
       
   182        return ETrue;*/
       
   183 /*    LOGSTRING( "CDiagPDPTestEngine::CheckAPNsInConnectionManagerL()" )
       
   184 
       
   185     // Reset the arrays to hold valid IAP Ids
       
   186     iPrimaryAPNIapIdArray.Reset();;
       
   187     iSecondaryAPNIapIdArray.Reset();    
       
   188     
       
   189     // Opens a session with the connection manager
       
   190     RCmManager connManager; 
       
   191     connManager.OpenLC();
       
   192     LOGSTRING( "CDiagPDPTestEngine session with connection manager opened." )
       
   193 
       
   194     // create a conneciton array to hold the Ids of connections    
       
   195     RArray< TUint32 > connArray = RArray< TUint32 >( KConnArrayGranularity );
       
   196     CleanupClosePushL( connArray );
       
   197     
       
   198     // Get a list of all the destinations
       
   199     LOGSTRING( "CDiagPDPTestEngine Get a list of all the destinations." )
       
   200     connManager.AllDestinationsL( connArray );    
       
   201     TInt numberOfDestinations = connArray.Count();    
       
   202     LOGSTRING2( "CDiagPDPTestEngine number of destinations = %d", numberOfDestinations )
       
   203     
       
   204       
       
   205     // Look through all the destinations' connection methods and see if any of
       
   206     // them match the CenRep data.
       
   207     for ( TInt i = 0; i < numberOfDestinations; i++ )
       
   208         {
       
   209         RCmDestination destination = connManager.DestinationL( connArray[ i ] );
       
   210         CleanupClosePushL( destination );
       
   211 
       
   212         // Don't use any hidden destinations, because they are not visible to
       
   213         // the user.
       
   214         if ( destination.IsHidden() )
       
   215             {
       
   216             LOGSTRING2( "CDiagPDPTestEngine: Destination number %d is hidden, hence ignoring it", i)
       
   217             CleanupStack::PopAndDestroy(); // destination
       
   218             continue;
       
   219             }
       
   220 
       
   221         // get the number of connection methods with this destination
       
   222         TInt numberOfConnectionMethods = destination.ConnectionMethodCount();
       
   223         LOGSTRING3( "CDiagPDPTestEngine For destination %d, number of connection methods are %d", i, numberOfConnectionMethods )
       
   224         
       
   225         for ( TInt j = 0; j < numberOfConnectionMethods; j++ )
       
   226             {
       
   227             RCmConnectionMethod method = destination.ConnectionMethodL( j );
       
   228             CleanupClosePushL( method );
       
   229             
       
   230             // This call is trapped because not all connection methods support
       
   231             // the data we're querying, and the leave should not be propagated
       
   232             // up because that would not be a reason for test failure.
       
   233             TRAP_IGNORE( CheckConnectionMatchL( method ) )
       
   234             CleanupStack::PopAndDestroy(); // method
       
   235             }
       
   236 
       
   237         CleanupStack::PopAndDestroy(); // destination
       
   238         }        
       
   239 
       
   240 
       
   241     // Get a list of all the uncategorized connection methods.
       
   242     LOGSTRING( "CDiagPDPTestEngine : Get a list of all the uncategorized connection methods." )
       
   243     connArray.Reset();
       
   244     connManager.ConnectionMethodL( connArray );
       
   245     
       
   246     TInt numberOfUncategorizedConnectionMethods = connArray.Count();    
       
   247     LOGSTRING2( "CDiagPDPTestEngine : number of uncategorized connection methods = %d", numberOfUncategorizedConnectionMethods)
       
   248 
       
   249     // Look through all the uncategorized connection methods and see if any
       
   250     // of them match match the CenRep data.
       
   251     for ( TInt i = 0; i < numberOfUncategorizedConnectionMethods; i++ )
       
   252         {
       
   253         RCmConnectionMethod method = connManager.ConnectionMethodL( connArray[ i ] );
       
   254         CleanupClosePushL( method );
       
   255 
       
   256         // This call is trapped because not all connection methods support
       
   257         // the data we're querying, and the leave should not be propagated
       
   258         // up because that would not be a reason for test failure.
       
   259         TRAP_IGNORE( CheckConnectionMatchL( method) )
       
   260         CleanupStack::PopAndDestroy(); // method
       
   261         }
       
   262 
       
   263     CleanupStack::PopAndDestroy(); // connArray
       
   264     CleanupStack::PopAndDestroy(); // connManager
       
   265     
       
   266     // check if atleast one occurrence each of the primary APN or the secondary APN was found in CommsDB
       
   267     if( (iPrimaryAPNIapIdArray.Count() > 0) || (iSecondaryAPNIapIdArray.Count() > 0) )
       
   268         {
       
   269         return ETrue;
       
   270         }
       
   271     else
       
   272         {
       
   273         return EFalse;
       
   274         }
       
   275     */
       
   276     return ETrue; //compiler warning
       
   277     }
       
   278 
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CDiagPDPTestEngine::CheckConnectionMatchL()
       
   282 //
       
   283 //
       
   284 // ----------------------------------------------------------------------------  
       
   285 
       
   286 void CDiagPDPTestEngine::CheckConnectionMatchL(const RCmConnectionMethod& aMethod)
       
   287     {
       
   288     LOGSTRING( "CDiagBrowserPluginModel::CheckConnectionMatchL()" )
       
   289 
       
   290     HBufC* name = aMethod.GetStringAttributeL(
       
   291         CMManager::ECmName );
       
   292     CleanupStack::PushL( name );
       
   293 
       
   294     HBufC* apn = aMethod.GetStringAttributeL(
       
   295         CMManager::EPacketDataAPName );
       
   296 
       
   297     CleanupStack::PushL( apn );
       
   298 
       
   299     TInt type = aMethod.GetIntAttributeL(
       
   300         CMManager::ECmBearerType );
       
   301 
       
   302     TBool hidden = aMethod.GetBoolAttributeL(
       
   303         CMManager::ECmHidden );
       
   304 
       
   305     TUint32 apId = aMethod.GetIntAttributeL(
       
   306         CMManager::ECmIapId );   
       
   307 
       
   308     LOGSTRING5(
       
   309         "CDiagBrowserPluginModel::CheckConnectionMatchL() "
       
   310         L" Name '%S', APN '%S' ,Type '0x%08x', Hidden '%d'", name, apn, type, hidden )
       
   311 
       
   312 
       
   313     if ( ( apn->Compare( iCenrepPrimaryAPN ) == 0 ) && 
       
   314          type == KUidPacketDataBearerType &&
       
   315          !hidden )
       
   316         {
       
   317         LOGSTRING( "CDiagBrowserPluginModel connection matches primary APN, adding to primary IAP array" )
       
   318         iPrimaryAPNIapIdArray.Append(apId);
       
   319         }
       
   320         
       
   321     if ( ( apn->Compare( iCenrepSecondaryAPN ) == 0 ) && 
       
   322          type == KUidPacketDataBearerType &&
       
   323          !hidden )
       
   324         {
       
   325         LOGSTRING( "CDiagBrowserPluginModel connection matches secondary APN, adding to secondary IAP array" )
       
   326         iSecondaryAPNIapIdArray.Append(apId);
       
   327         }        
       
   328 
       
   329     CleanupStack::PopAndDestroy( apn );
       
   330     CleanupStack::PopAndDestroy( name );
       
   331     }
       
   332 
       
   333     
       
   334 // ----------------------------------------------------------------------------
       
   335 // CDiagPDPTestEngine::FindActiveConnectionsL()
       
   336 //
       
   337 // this function returns ETrue if an already active connection is found using 
       
   338 // the IAP ids which match with the specified APNs, else it returns EFalse
       
   339 // ----------------------------------------------------------------------------       
       
   340 TBool CDiagPDPTestEngine::FindActiveConnectionsL() 
       
   341     {
       
   342     LOGSTRING( "CDiagPDPTestEngine::FindActiveConnectionsL");
       
   343     TBool result = EFalse;   
       
   344     TUint connectionCount = 0;
       
   345     TPckgBuf<TConnectionInfo> connectionInfo;
       
   346     User::LeaveIfError(
       
   347         iConnection.EnumerateConnections(connectionCount));
       
   348     LOGSTRING("iConnection.EnumerateConnections");
       
   349     if(connectionCount > 0)
       
   350         {
       
   351         // there is atleast one active connection
       
   352 
       
   353         // iterate through each active connection
       
   354         for(TUint count = 1 ; count <= connectionCount; count++)
       
   355             {
       
   356             User::LeaveIfError(
       
   357                 iConnection.GetConnectionInfo(count, connectionInfo));               
       
   358             
       
   359             // test if the IAP Id of this active connection matches with one of the IAP ids in 
       
   360             // primary array or secondary array
       
   361             /*if( ((iPrimaryAPNIapIdArray.Find( connectionInfo().iIapId)) != KErrNotFound ) || 
       
   362                 ((iSecondaryAPNIapIdArray.Find( connectionInfo().iIapId)) != KErrNotFound ) )*/
       
   363 	        if (iIAPiddefault == connectionInfo().iIapId)
       
   364                 {
       
   365                 // the IAP ID of the current active connection has matched with the one of the IAPs in primary array or secondary array
       
   366                 // data connection has PASSED
       
   367                 LOGSTRING("IAP ID of the current active connection has matched");
       
   368                 result = ETrue;
       
   369                 break; //break from the for loop
       
   370                 }
       
   371                 else
       
   372                 {
       
   373                 // do nothing, look for next active connection
       
   374                 }
       
   375             }
       
   376         }
       
   377     else
       
   378         {
       
   379         // no active connection found
       
   380         result = EFalse;        
       
   381         }
       
   382 
       
   383     return result;
       
   384     }
       
   385     
       
   386     
       
   387 
       
   388 // End of File