connectionmonitoring/connectionmonitorui/src/ConnectionInfoBase.cpp
branchRCL_3
changeset 55 fc7b30ed2058
parent 12 ea6e024ea6f9
equal deleted inserted replaced
54:984e13af52c4 55:fc7b30ed2058
    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 const TUint KBannedServerUID = 0x101fd9c5; // Banned DHCP server UID
    37 
       
    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
    38 
    42 
    39 const TInt KFeedsServerUid         = 0x1020728E;
    43 const TInt KFeedsServerUid         = 0x1020728E;
    40 const TInt KDownloadMgrServerUid   = 0x10008D60;
    44 const TInt KDownloadMgrServerUid   = 0x10008D60;
    41 const TInt KMessagingServerUid     = 0x1000484b;
    45 const TInt KMessagingServerUid     = 0x1000484b;
    42 const TInt KJavaVMUid              = 0x102033E6;
    46 const TInt KJavaVMUid              = 0x102033E6;
    80     {
    84     {
    81     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - start " );
    85     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - start " );
    82     iConnectionStatus = EConnectionUninitialized;
    86     iConnectionStatus = EConnectionUninitialized;
    83     iConnectionId = aConnectionId;
    87     iConnectionId = aConnectionId;
    84     iConnectionBearerType = aConnectionBearerType;
    88     iConnectionBearerType = aConnectionBearerType;
       
    89     iClientBuf().iCount = 0;
    85     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - end " );
    90     CMUILOGGER_WRITE( "CConnectionInfoBase constuctor - end " );
    86     }
    91     }
    87 
    92 
    88 
    93 
    89 // ---------------------------------------------------------
    94 // ---------------------------------------------------------
   490 // ---------------------------------------------------------
   495 // ---------------------------------------------------------
   491 //
   496 //
   492 TInt CConnectionInfoBase::RefreshAppNamesL()
   497 TInt CConnectionInfoBase::RefreshAppNamesL()
   493     {
   498     {
   494     CMUILOGGER_ENTERFN( "CConnectionInfoBase::RefreshAppNamesL" );
   499     CMUILOGGER_ENTERFN( "CConnectionInfoBase::RefreshAppNamesL" );
   495     
   500 
   496     TInt sharings( 0 );
   501     TInt sharings( 0 );
   497     
   502 
   498 if ( IsAlive() )
   503     if ( IsAlive() )
   499     {
   504         {
   500     if ( iAppNames )
   505         if ( iAppNames )
   501         {
   506             {
   502         iAppNames->Reset();
   507             // Check whether it is an internal or external (modem) connection
   503         HBufC* actAppName = NULL;
   508             // External (modem) connections does not need application name
   504         // Check whether it is an internal or external (modem) connection
   509             if ( iConnectionBearerType >= EBearerExternalCSD )
   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 )
       
   518                 {
   510                 {
   519                 count = clientBuf().iCount;
   511                 CMUILOGGER_WRITE( "External (modem) connections does not need application name" );
       
   512                 return sharings;
   520                 }
   513                 }
   521                 
   514             else
   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++ )
       
   534                 {
   515                 {
   535                 actAppName = NULL;
   516                 TInt count( 0 );
   536                 appInfo.iCaption.Zero();
   517                 TConnMonClientEnumBuf clientBuf;
   537 
   518                 iActiveWrapper->StartGetConnSharings( iConnectionId,
   538                 TInt result = appSess.GetAppInfo( appInfo, 
   519                                                       iConnectionMonitor,
   539                                                   clientBuf().iUid[i] );
   520                                                       clientBuf );
   540 
   521 
   541                 //================================
   522                 TInt err( iActiveWrapper->iStatus.Int() );
   542                 CMUILOGGER_WRITE_F( "result: %d", result ); 
   523                 CMUILOGGER_WRITE_F( "RefreshSharings status: %d", err );
   543                 CMUILOGGER_WRITE_F( "iClientInfo.iUid[i].iUid: %x", 
   524 
   544                                     clientBuf().iUid[i].iUid );
   525                 if ( !err )
   545                 
       
   546                 if ( result != KErrNone )
       
   547                     {
   526                     {
   548                     TInt resId = 0;
   527                     count = clientBuf().iCount;
   549                     switch ( clientBuf().iUid[i].iUid )
   528                     }
   550                         {
   529                 CMUILOGGER_WRITE_F( "clientBuf().iCount: %d", count );
   551                         case KMessagingServerUid: // Messaging
   530 
   552                             {
   531                 if ( IsTheSameUids( clientBuf ) )
   553                             resId = R_QTN_CMON_SHARING_APP_MSG_SERVER;
   532                     {
   554                             break;
   533                     // Same client list, use cached application names.
   555                             }
   534                     CMUILOGGER_WRITE( "Client list unchanged, use cached names" );
   556                         case KDownloadMgrServerUid: // Downloads
   535                     CMUILOGGER_WRITE_F( "sharings: %d", iAppNames->Count() );
   557                             {
   536                     return iAppNames->Count();
   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                         }
       
   591                     }
   537                     }
   592                 else
   538                 else
   593                     {
   539                     {
   594                     actAppName =  HBufC::NewL( appInfo.iCaption.Length() );
   540                     CMUILOGGER_WRITE( "Client list changed, update names" );
   595                     TPtr actAppNameBuf = actAppName->Des();
   541                     CopyUidsToBuf ( clientBuf );
   596                     actAppNameBuf.Append( appInfo.iCaption );
       
   597                     }
   542                     }
   598 
   543 
   599                 if ( actAppName )
   544                 iAppNames->Reset();
       
   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++ )
   600                     {
   557                     {
   601                     iAppNames->AppendL( actAppName->Des() );        
   558                     actAppName = NULL;
   602                     delete actAppName;
   559                     appInfo.iCaption.Zero();
       
   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                         }
   603                     }
   689                     }
   604                 }
       
   605 
   690 
   606                 iAppNames->Sort();
   691                 iAppNames->Sort();
   607                 appSess.Close();
   692                 appSess.Close();
   608 #else
   693 #else
   609             TInt countBan( 0 );
   694                 TInt countBan( 0 );
   610 
   695 
   611             if ( !err )
   696 #ifndef _DEBUG
   612                 {
   697                 if ( !err )
   613                 // remove the DHCP server is not actually 
       
   614                 // an owner of the connection
       
   615                 for ( TUint tmp = 0; tmp < count; ++tmp )
       
   616                     {
   698                     {
   617                     TUid uid = clientBuf().iUid[tmp];
   699                     // Remove DHCP and DNS from the client list. 
   618             
   700                     for ( TUint tmp = 0; tmp < count; tmp++ )
   619                     if ( uid.iUid == KBannedServerUID )
       
   620                         {
   701                         {
   621                         ++countBan;
   702                         TUid uid = clientBuf().iUid[tmp];
       
   703 
       
   704                         if ( uid.iUid == KHiddenDhcpServerUid || uid.iUid == KHiddenDnsServerUid )
       
   705                             {
       
   706                             countBan++;
       
   707                             }
   622                         }
   708                         }
   623                     } // end
   709                     }
   624                 }
   710 #endif
   625 
   711 
   626             _LIT( KStrApplication, "Application" );
   712                 _LIT( KStrApplication, "Application" );
   627             // Give a dummy name of the application
   713                 // Give a dummy name for all applications.
   628             for ( TInt i = 0; i < ( count - countBan ); i++ )
   714                 for ( TInt i = 0; i < ( count - countBan ); i++ )
   629                 {
   715                     {
   630                 iAppNames->AppendL( KStrApplication );
   716                     iAppNames->AppendL( KStrApplication );
   631                 }
   717                     }
   632 
   718 
   633 #endif // __WINS__
   719 #endif // __WINS__
   634 
   720                 } // End of else in if ( iConnectionBearerType > EBearerExternalCSD )
   635             }
   721             sharings = iAppNames->Count();
   636         /* modem connections does not need application name
   722             CMUILOGGER_WRITE_F( "sharings: %d", sharings );
   637         else 
   723             } // End of if ( iAppNames )
   638             {
   724         } // End of if ( IsAlive() )
   639             }
   725 
   640         */
       
   641         sharings = iAppNames->Count();
       
   642         }
       
   643     }
       
   644         
       
   645     CMUILOGGER_LEAVEFN( "CConnectionInfoBase::RefreshAppNamesL" );
   726     CMUILOGGER_LEAVEFN( "CConnectionInfoBase::RefreshAppNamesL" );
   646     return sharings;
   727     return sharings;
   647     }
   728     }
   648 
   729 
       
   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     }
   649 
   785 
   650 // ---------------------------------------------------------
   786 // ---------------------------------------------------------
   651 // CConnectionInfoBase::ToDetailsListBoxItemTextL
   787 // CConnectionInfoBase::ToDetailsListBoxItemTextL
   652 // ---------------------------------------------------------
   788 // ---------------------------------------------------------
   653 //
   789 //