connectionmonitoring/connectionmonitorui/src/ConnectionInfoBase.cpp
branchRCL_3
changeset 69 cf1b3ddbe9a1
parent 58 83ca720e2b9a
equal deleted inserted replaced
65:14754bf06654 69:cf1b3ddbe9a1
    32 
    32 
    33 // CONSTANTS
    33 // CONSTANTS
    34 
    34 
    35 const TUint KUpArrowChar = 0x2191; ///< ASCII code of UpArrow
    35 const TUint KUpArrowChar = 0x2191; ///< ASCII code of UpArrow
    36 const TUint KDownArrowChar = 0x2193; ///< ASCII code of DownArrow
    36 const TUint KDownArrowChar = 0x2193; ///< ASCII code of DownArrow
    37 
    37 const TUint KBannedServerUID = 0x101fd9c5; // Banned DHCP server UID
    38 #ifndef _DEBUG
       
    39 const TUint KHiddenDhcpServerUid = 0x101fd9c5; ///< Hidden DHCP server UID (dhcpserv.exe)
       
    40 const TUint KHiddenDnsServerUid = 0x10000882; ///< Hidden DNS server UID (dnd.exe)
       
    41 #endif
       
    42 
    38 
    43 const TInt KFeedsServerUid         = 0x1020728E;
    39 const TInt KFeedsServerUid         = 0x1020728E;
    44 const TInt KDownloadMgrServerUid   = 0x10008D60;
    40 const TInt KDownloadMgrServerUid   = 0x10008D60;
    45 const TInt KMessagingServerUid     = 0x1000484b;
    41 const TInt KMessagingServerUid     = 0x1000484b;
    46 const TInt KJavaVMUid              = 0x102033E6;
    42 const TInt KJavaVMUid              = 0x102033E6;
    84     {
    80     {
    85     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - start " );
    81     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - start " );
    86     iConnectionStatus = EConnectionUninitialized;
    82     iConnectionStatus = EConnectionUninitialized;
    87     iConnectionId = aConnectionId;
    83     iConnectionId = aConnectionId;
    88     iConnectionBearerType = aConnectionBearerType;
    84     iConnectionBearerType = aConnectionBearerType;
    89     iClientBuf().iCount = 0;
       
    90     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - end " );
    85     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - end " );
    91     }
    86     }
    92 
    87 
    93 
    88 
    94 // ---------------------------------------------------------
    89 // ---------------------------------------------------------
   495 // ---------------------------------------------------------
   490 // ---------------------------------------------------------
   496 //
   491 //
   497 TInt CConnectionInfoBase::RefreshAppNamesL()
   492 TInt CConnectionInfoBase::RefreshAppNamesL()
   498     {
   493     {
   499     CMUILOGGER_ENTERFN( "CConnectionInfoBase::RefreshAppNamesL" );
   494     CMUILOGGER_ENTERFN( "CConnectionInfoBase::RefreshAppNamesL" );
   500 
   495     
   501     TInt sharings( 0 );
   496     TInt sharings( 0 );
   502 
   497     
   503     if ( IsAlive() )
   498 if ( IsAlive() )
   504         {
   499     {
   505         if ( iAppNames )
   500     if ( iAppNames )
   506             {
   501         {
   507             // Check whether it is an internal or external (modem) connection
   502         iAppNames->Reset();
   508             // External (modem) connections does not need application name
   503         HBufC* actAppName = NULL;
   509             if ( iConnectionBearerType >= EBearerExternalCSD )
   504         // Check whether it is an internal or external (modem) connection
       
   505         // External (modem) connections does not need application name
       
   506         if ( iConnectionBearerType < EBearerExternalCSD )
       
   507             {
       
   508             TInt count( 0 );
       
   509             TConnMonClientEnumBuf clientBuf;
       
   510             iActiveWrapper->StartGetConnSharings( iConnectionId,
       
   511                                                   iConnectionMonitor,
       
   512                                                   clientBuf );
       
   513             
       
   514             TInt err( iActiveWrapper->iStatus.Int() );
       
   515             CMUILOGGER_WRITE_F( "RefreshSharings status: %d", err );
       
   516             
       
   517             if ( !err )
   510                 {
   518                 {
   511                 CMUILOGGER_WRITE( "External (modem) connections does not need application name" );
   519                 count = clientBuf().iCount;
   512                 return sharings;
       
   513                 }
   520                 }
   514             else
   521                 
       
   522             CMUILOGGER_WRITE_F( "clientBuf().iCount: %d", count );
       
   523                 
       
   524 #ifndef __WINS__ // Appl. uid is always zero in emulator
       
   525 
       
   526             RApaLsSession appSess;
       
   527             TApaAppInfo appInfo;
       
   528 
       
   529             // The connection could be shared by several applications
       
   530             User::LeaveIfError( appSess.Connect() );
       
   531                     
       
   532             TUint i;
       
   533             for ( i = 0; i < count; i++ )
   515                 {
   534                 {
   516                 TInt count( 0 );
   535                 actAppName = NULL;
   517                 TConnMonClientEnumBuf clientBuf;
   536                 appInfo.iCaption.Zero();
   518                 iActiveWrapper->StartGetConnSharings( iConnectionId,
   537 
   519                                                       iConnectionMonitor,
   538                 TInt result = appSess.GetAppInfo( appInfo, 
   520                                                       clientBuf );
   539                                                   clientBuf().iUid[i] );
   521 
   540 
   522                 TInt err( iActiveWrapper->iStatus.Int() );
   541                 //================================
   523                 CMUILOGGER_WRITE_F( "RefreshSharings status: %d", err );
   542                 CMUILOGGER_WRITE_F( "result: %d", result ); 
   524 
   543                 CMUILOGGER_WRITE_F( "iClientInfo.iUid[i].iUid: %x", 
   525                 if ( !err )
   544                                     clientBuf().iUid[i].iUid );
       
   545                 
       
   546                 if ( result != KErrNone )
   526                     {
   547                     {
   527                     count = clientBuf().iCount;
   548                     TInt resId = 0;
   528                     }
   549                     switch ( clientBuf().iUid[i].iUid )
   529                 CMUILOGGER_WRITE_F( "clientBuf().iCount: %d", count );
   550                         {
   530 
   551                         case KMessagingServerUid: // Messaging
   531                 if ( IsTheSameUids( clientBuf ) )
   552                             {
   532                     {
   553                             resId = R_QTN_CMON_SHARING_APP_MSG_SERVER;
   533                     // Same client list, use cached application names.
   554                             break;
   534                     CMUILOGGER_WRITE( "Client list unchanged, use cached names" );
   555                             }
   535                     CMUILOGGER_WRITE_F( "sharings: %d", iAppNames->Count() );
   556                         case KDownloadMgrServerUid: // Downloads
   536                     return iAppNames->Count();
   557                             {
       
   558                             resId = R_QTN_CMON_SHARING_APP_DL_MG;
       
   559                             break;
       
   560                             }
       
   561                         case KFeedsServerUid: // Web Feeds
       
   562                             {
       
   563                             resId = R_QTN_CMON_SHARING_APP_RSS_SERVER;
       
   564                             break;
       
   565                             }
       
   566                         case KJavaVMUid: // Application
       
   567                             {
       
   568                             resId = R_QTN_CMON_SHARING_APP_JAVA_MIDLET;
       
   569                             break;
       
   570                             }
       
   571                         case KBannedServerUID:
       
   572                             {   // Forget about DHCP server!
       
   573                             break;
       
   574                             }
       
   575                         case KSUPLServerUid:
       
   576                             {
       
   577                             resId = R_QTN_CMON_SHARING_APP_SUPL;
       
   578                             break;
       
   579                             }
       
   580                         default: // (unknown)
       
   581                             {
       
   582                             resId = R_QTN_CMON_SHARING_APP_UNKNOWN;
       
   583                             break;
       
   584                             }
       
   585                         }
       
   586 
       
   587                     if ( resId )
       
   588                         {
       
   589                         actAppName = StringLoader::LoadL( resId );
       
   590                         }
   537                     }
   591                     }
   538                 else
   592                 else
   539                     {
   593                     {
   540                     CMUILOGGER_WRITE( "Client list changed, update names" );
   594                     actAppName =  HBufC::NewL( appInfo.iCaption.Length() );
   541                     CopyUidsToBuf ( clientBuf );
   595                     TPtr actAppNameBuf = actAppName->Des();
       
   596                     actAppNameBuf.Append( appInfo.iCaption );
   542                     }
   597                     }
   543 
   598 
   544                 iAppNames->Reset();
   599                 if ( actAppName )
   545                 HBufC* actAppName = NULL;
       
   546 
       
   547 #ifndef __WINS__ // Appl. uid is always zero in emulator
       
   548 
       
   549                 RApaLsSession appSess;
       
   550                 TApaAppInfo appInfo;
       
   551 
       
   552                 // The connection could be shared by several applications
       
   553                 User::LeaveIfError( appSess.Connect() );
       
   554 
       
   555                 TUint i;
       
   556                 for ( i = 0; i < count; i++ )
       
   557                     {
   600                     {
   558                     actAppName = NULL;
   601                     iAppNames->AppendL( actAppName->Des() );        
   559                     appInfo.iCaption.Zero();
   602                     delete actAppName;
   560 
       
   561                     TInt result = appSess.GetAppInfo( appInfo,
       
   562                             clientBuf().iUid[i] );
       
   563 
       
   564                     //================================
       
   565                     CMUILOGGER_WRITE_F( "result: %d", result );
       
   566                     CMUILOGGER_WRITE_F( "iClientInfo.iUid[i].iUid: %x",
       
   567                             clientBuf().iUid[i].iUid );
       
   568 
       
   569                     if ( result != KErrNone )
       
   570                         {
       
   571                         TInt resId = 0;
       
   572                         switch ( clientBuf().iUid[i].iUid )
       
   573                             {
       
   574                             case KMessagingServerUid: // Messaging
       
   575                                 {
       
   576                                 resId = R_QTN_CMON_SHARING_APP_MSG_SERVER;
       
   577                                 break;
       
   578                                 }
       
   579                             case KDownloadMgrServerUid: // Downloads
       
   580                                 {
       
   581                                 resId = R_QTN_CMON_SHARING_APP_DL_MG;
       
   582                                 break;
       
   583                                 }
       
   584                             case KFeedsServerUid: // Web Feeds
       
   585                                 {
       
   586                                 resId = R_QTN_CMON_SHARING_APP_RSS_SERVER;
       
   587                                 break;
       
   588                                 }
       
   589                             case KJavaVMUid: // Application
       
   590                                 {
       
   591                                 resId = R_QTN_CMON_SHARING_APP_JAVA_MIDLET;
       
   592                                 break;
       
   593                                 }
       
   594 #ifndef _DEBUG
       
   595                             // Hide DHCP & DNS from UI in release build.
       
   596                             case KHiddenDhcpServerUid:
       
   597                             case KHiddenDnsServerUid:
       
   598                                 {
       
   599                                 break;
       
   600                                 }
       
   601 #endif
       
   602                             case KSUPLServerUid:
       
   603                                 {
       
   604                                 resId = R_QTN_CMON_SHARING_APP_SUPL;
       
   605                                 break;
       
   606                                 }
       
   607                             default: // (unknown)
       
   608                                 {
       
   609                                 resId = R_QTN_CMON_SHARING_APP_UNKNOWN;
       
   610                                 break;
       
   611                                 }
       
   612                             }
       
   613 
       
   614                         if ( resId && resId != R_QTN_CMON_SHARING_APP_UNKNOWN  )
       
   615                             {
       
   616                             actAppName = StringLoader::LoadL( resId );
       
   617                             }
       
   618                         else if ( resId ) // Try to find application process name from system.
       
   619                             {
       
   620                             TFileName name;
       
   621                             TFindProcess find;
       
   622                             TBool name_solved( EFalse );
       
   623                             while ( find.Next( name ) == KErrNone )
       
   624                                 {
       
   625                                 RProcess ph;
       
   626                                 TInt err2( KErrNone );
       
   627                                 err2 = ph.Open( name );
       
   628 
       
   629                                 if ( err2 )
       
   630                                     {
       
   631                                     ph.Close();
       
   632                                     }
       
   633                                 else
       
   634                                     {
       
   635                                     TUidType procUid = ph.Type();
       
   636                                     ph.Close();
       
   637 
       
   638                                     // There are three UIDs in procUid. The last one is the second
       
   639                                     // UID defined in MMP file and clientBuf().iUid[i].iUid is also
       
   640                                     // the same kind of UID. So, we only need to compare them to
       
   641                                     // find application name.
       
   642                                     if ( procUid[2].iUid == clientBuf().iUid[i].iUid )
       
   643                                         {
       
   644                                         // Name is in format "app_name[uid]001", so cut rest of
       
   645                                         // string starting from "[".
       
   646                                         TInt index = name.LocateReverse('[');
       
   647                                         if ( index >= 1 )
       
   648                                             {
       
   649                                             name.SetLength( index );
       
   650                                             }
       
   651 
       
   652                                         actAppName = HBufC::NewL( name.Length() );
       
   653                                         TPtr actAppNameBuf = actAppName->Des();
       
   654                                         actAppNameBuf.Append( name );
       
   655 
       
   656 #ifdef _DEBUG
       
   657                                         CMUILOGGER_WRITE( "--------------------" );
       
   658                                         CMUILOGGER_WRITE( " Application is Found:" );
       
   659                                         CMUILOGGER_WRITE_F( "Client Uid: %x", clientBuf().iUid[i].iUid );
       
   660                                         CMUILOGGER_WRITE_F( "Proc Uid: %x", procUid[2].iUid );
       
   661                                         CMUILOGGER_WRITE_F( "App Name: %S", &name);
       
   662                                         CMUILOGGER_WRITE( "--------------------" );
       
   663 #endif
       
   664 
       
   665                                         name_solved = ETrue;
       
   666                                         break;
       
   667                                         }
       
   668                                     }
       
   669                                 }
       
   670 
       
   671                             if ( !name_solved )
       
   672                                 {
       
   673                                 actAppName = StringLoader::LoadL( R_QTN_CMON_SHARING_APP_UNKNOWN );
       
   674                                 }
       
   675                             }
       
   676                         }
       
   677                     else
       
   678                         {
       
   679                         actAppName = HBufC::NewL( appInfo.iCaption.Length() );
       
   680                         TPtr actAppNameBuf = actAppName->Des();
       
   681                         actAppNameBuf.Append( appInfo.iCaption );
       
   682                         }
       
   683 
       
   684                     if ( actAppName )
       
   685                         {
       
   686                         iAppNames->AppendL( actAppName->Des() );
       
   687                         delete actAppName;
       
   688                         }
       
   689                     }
   603                     }
       
   604                 }
   690 
   605 
   691                 iAppNames->Sort();
   606                 iAppNames->Sort();
   692                 appSess.Close();
   607                 appSess.Close();
   693 #else
   608 #else
   694                 TInt countBan( 0 );
   609             TInt countBan( 0 );
   695 
   610 
   696 #ifndef _DEBUG
   611             if ( !err )
   697                 if ( !err )
   612                 {
       
   613                 // remove the DHCP server is not actually 
       
   614                 // an owner of the connection
       
   615                 for ( TUint tmp = 0; tmp < count; ++tmp )
   698                     {
   616                     {
   699                     // Remove DHCP and DNS from the client list. 
   617                     TUid uid = clientBuf().iUid[tmp];
   700                     for ( TUint tmp = 0; tmp < count; tmp++ )
   618             
       
   619                     if ( uid.iUid == KBannedServerUID )
   701                         {
   620                         {
   702                         TUid uid = clientBuf().iUid[tmp];
   621                         ++countBan;
   703 
       
   704                         if ( uid.iUid == KHiddenDhcpServerUid || uid.iUid == KHiddenDnsServerUid )
       
   705                             {
       
   706                             countBan++;
       
   707                             }
       
   708                         }
   622                         }
   709                     }
   623                     } // end
   710 #endif
   624                 }
   711 
   625 
   712                 _LIT( KStrApplication, "Application" );
   626             _LIT( KStrApplication, "Application" );
   713                 // Give a dummy name for all applications.
   627             // Give a dummy name of the application
   714                 for ( TInt i = 0; i < ( count - countBan ); i++ )
   628             for ( TInt i = 0; i < ( count - countBan ); i++ )
   715                     {
   629                 {
   716                     iAppNames->AppendL( KStrApplication );
   630                 iAppNames->AppendL( KStrApplication );
   717                     }
   631                 }
   718 
   632 
   719 #endif // __WINS__
   633 #endif // __WINS__
   720                 } // End of else in if ( iConnectionBearerType > EBearerExternalCSD )
   634 
   721             sharings = iAppNames->Count();
   635             }
   722             CMUILOGGER_WRITE_F( "sharings: %d", sharings );
   636         /* modem connections does not need application name
   723             } // End of if ( iAppNames )
   637         else 
   724         } // End of if ( IsAlive() )
   638             {
   725 
   639             }
       
   640         */
       
   641         sharings = iAppNames->Count();
       
   642         }
       
   643     }
       
   644         
   726     CMUILOGGER_LEAVEFN( "CConnectionInfoBase::RefreshAppNamesL" );
   645     CMUILOGGER_LEAVEFN( "CConnectionInfoBase::RefreshAppNamesL" );
   727     return sharings;
   646     return sharings;
   728     }
   647     }
   729 
   648 
   730 // ---------------------------------------------------------
       
   731 // CConnectionInfoBase::IsTheSameUids
       
   732 // ---------------------------------------------------------
       
   733 //
       
   734 TBool CConnectionInfoBase::IsTheSameUids( TConnMonClientEnumBuf& aClients )
       
   735     {
       
   736     TBool ret( EFalse );
       
   737 
       
   738     if ( iClientBuf().iCount != aClients().iCount )
       
   739         {
       
   740         return ret;
       
   741         }
       
   742     else
       
   743         {
       
   744         TInt count = aClients().iCount;
       
   745         for ( TInt i = 0; i < count; i++ )
       
   746             {
       
   747             // Is the current value inside aClients found from iClientBuf.
       
   748             TBool found( EFalse );
       
   749             for ( TInt j = 0; j < count; j++ )
       
   750                 {
       
   751                 if ( aClients().iUid[i].iUid == iClientBuf().iUid[j].iUid )
       
   752                     {
       
   753                     found = ETrue;
       
   754                     break;
       
   755                     }
       
   756                 }
       
   757 
       
   758             if ( !found )
       
   759                 {
       
   760                 return ret;
       
   761                 }
       
   762             }
       
   763 
       
   764         // If we reach this point, aClients contents are identical with iClientBuf.
       
   765         ret = ETrue;
       
   766         }
       
   767 
       
   768     return ret;
       
   769     }
       
   770 
       
   771 // ---------------------------------------------------------
       
   772 // CConnectionInfoBase::CopyUidsToBuf
       
   773 // ---------------------------------------------------------
       
   774 //
       
   775 void CConnectionInfoBase::CopyUidsToBuf( TConnMonClientEnumBuf& aClients )
       
   776     {
       
   777     TInt count = aClients().iCount;
       
   778 
       
   779     for ( TInt i = 0; i < count; i++ )
       
   780         {
       
   781         iClientBuf().iUid[i].iUid = aClients().iUid[i].iUid;
       
   782         }
       
   783     iClientBuf().iCount = count;
       
   784     }
       
   785 
   649 
   786 // ---------------------------------------------------------
   650 // ---------------------------------------------------------
   787 // CConnectionInfoBase::ToDetailsListBoxItemTextL
   651 // CConnectionInfoBase::ToDetailsListBoxItemTextL
   788 // ---------------------------------------------------------
   652 // ---------------------------------------------------------
   789 //
   653 //