Retrieving IMEI, IMSI, Network Info (Cell Id, Location Code) 3rd Edition.
In the 2nd edition there are many ways to retrieve the IMEI and IMSI. The one popularly used is the 3rd party “MobInfo Dll”. In Series 60 3rd edition there is no such third party Dll. Instead “CTelephony” needs to be used.
I’ve seen lots of threads for 2nd edition, but did not get good pointers for retrieving these parameters for 3rd edition.
Following is my contribution on how to retrieve IMEI and IMSI. Along with that you can also use this code to retrieve network info (Cell Id, Location code) It can further be extended to retrieve other network info.
#include <Etel3rdParty.h>
class CystemManager : public CActive
{
public:
typedef enum {EHandsetIMEI, EHandsetIMSI, EHandsetNetworkInfo } InfoType;
public:
static CystemManager* NewL();
// Destructor
~CSystemManager();
public:
// New functions
void StartL(); // Request
const TPtrC GetIMEI();
const TPtrC GetIMSI();
void GetNetworkInfoL(TUint& aLocation, TUint& aCellId);
private:
// C++ constructor
CSystemManager();
// Second-phase constructor
void ConstructL();
// From CActive
void RunL();
// Cancel
void DoCancel();
private:
enum TGetInfoState
{
EStart = 1,
EGetPhoneInfo,
EDone
};
private:
InfoType iPhoneInfoType;
TInt iState; // State of the active object
CTelephony* iTelephony;
CTelephony::TPhoneIdV1 iPhoneId;
CTelephony::TSubscriberIdV1 iSubscriberId;
CTelephony::TNetworkInfoV1 iNetworkInfo;
CActiveSchedulerWait iActiveSchedulerWait;
TBuf<CTelephony::KPhoneSerialNumberSize>iIMEI;
TBuf<CTelephony::KIMSISize> iIMSI;
TUint iCellId;
TUint iLocationAreaCode;
};
#endif // __SYSTEM_MANAGER_H__
Source File
// System includes
#include <badesca.h>
#include <e32std.h>
#include <eikenv.h>
#include <eikappui.h>
#include <eikapp.h>
#include <etelbgsm.h>
//User includes
#include "SystemManager.h"
CSystemManager* CSystemManager::NewL()
{
CSystemManager* self = new (ELeave) CSystemManager();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
CSystemManager::CSystemManager() : CActive(EPriorityHigh), // HIGH priority
iPhoneInfoType(EHandsetIMEI),
iState(EStart),
iTelephony(NULL),
iIMEI(0),
iIMSI(0),
iCellId(0),
iLocationAreaCode(0)
{
}
void CSystemManager::ConstructL()
{
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this); // Add to scheduler
}
CSystemManager::~CSystemManager()
{
Cancel(); // Cancel any request, if outstanding
// Delete instance variables if any
delete iTelephony;
}
void CSystemManager::DoCancel()
{
switch(iPhoneInfoType)
{
case EHandsetIMEI:
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
break;
case EHandsetIMSI:
iTelephony->CancelAsync(CTelephony::EGetSubscriberIdCancel);
break;
default:
iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
break;
}
}
void CSystemManager::StartL()
{
Cancel(); // Cancel any request, just to be sure
iState = EGetPhoneInfo;
switch(iPhoneInfoType)
{
case EHandsetIMEI:
{
CTelephony::TPhoneIdV1Pckg phoneIdPckg( iPhoneId );
iTelephony->GetPhoneId(iStatus, phoneIdPckg);
}
break;
case EHandsetIMSI:
{
CTelephony::TSubscriberIdV1Pckg subscriberIdPckg( iSubscriberId );
iTelephony->GetSubscriberId(iStatus, subscriberIdPckg);
}
break;
case EHandsetNetworkInfo:
{
CTelephony::TNetworkInfoV1Pckg networkInfoPckg( iNetworkInfo );
iTelephony->GetCurrentNetworkInfo(iStatus, networkInfoPckg);
}
break;
}
SetActive(); // Tell scheduler a request is active
iActiveSchedulerWait.Start();
}
void CSystemManager::RunL()
{
iState = EDone;
if ( iActiveSchedulerWait.IsStarted() )
{
iActiveSchedulerWait.AsyncStop();
if(iStatus == KErrNone)
{
switch(iPhoneInfoType)
{
case EHandsetIMEI:
iIMEI.Append(iPhoneId.iSerialNumber );
break;
case EHandsetIMSI:
iIMSI.Append(iSubscriberId.iSubscriberId );
break;
case EHandsetNetworkInfo:
iCellId = iNetworkInfo.iCellId;
iLocationAreaCode = iNetworkInfo.iLocationAreaCode;
break;
}
}
else
{
// ***********Handle Error here ************
}
}
}
const TPtrC CSystemManager::GetIMEI()
{
iPhoneInfoType = EHandsetIMEI;
iIMEI.Zero();
StartL();
TPtrC ptr(iIMEI.Ptr());
return ptr;
}
const TPtrC CSystemManager::GetIMSI()
{
iPhoneInfoType = EHandsetIMSI;
iIMSI.Zero();
StartL();
TPtrC ptr(iIMSI.Ptr());
return ptr;
}
void CSystemManager::GetNetworkInfoL(TUint& aLocationCode, TUint& aCellId)
{
iPhoneInfoType = EHandsetNetworkInfo;
StartL();
aCellId = iCellId;
aLocationCode = iLocationAreaCode;
return;
}
Note: This piece of code requires "ReadDeviceData" Capability.
You can further extend the above code for retrieving other network information.