封装CTelephoney的方法,包括获取IMEI,IMSI,品牌,型号,系统版本号,打电话功能

来源:互联网 发布:js注册事件 编辑:程序博客网 时间:2024/05/14 08:08

/***************************************

****************************************

***************************************/

 

#ifndef MYTELEPHONY_H

#define MYTELEPHONY_H

 

#include <e32base.h>

#include <Etel3rdParty.h>

#include <f32file.h>    // link against efsrv.lib

 

_LIT(KS60ProductIDFile, "Series60v*.sis");

 

_LIT(KROMInstallDir, "z://system//install//");

 

class CMyTelephony : public CActive

    {

public:

    static CMyTelephony* NewL();

    static CMyTelephony* NewLC();

    ~CMyTelephony();

 

public:

    static void GetIMSIL(TDes& aIMSI);

    static void GetIMEIL(TDes& aIMEI);

    static void GetPhoneType(TDes& aPhoneType);

    static void DialPhone(const TDesC& aPhoneId);

    static void GetS60PlatformVersionL(TUint& aMajor, TUint& aMinor );

 

 

protected:

    void DoCancel();

    void RunL();

 

private:

    CMyTelephony();

 

    void ConstructL();

 

    void GetSubscriberId();

    void GetPhoneId();

 

private:

    CTelephony* iTelephony;

    CTelephony::TCancellationRequest iRequest;

    CTelephony::TSubscriberIdV1 iSubscriberId;

    CTelephony::TSubscriberIdV1Pckg iSubscriberIdPckg;

    CTelephony::TPhoneIdV1 iPhoneId;

    CTelephony::TPhoneIdV1Pckg iPhoneIdPckg;  

    CTelephony::TCallId iCallId;

    TBuf<32> iPhoneType;

public :

    void DialNewCall(const TDesC& aTelNumber);

    };

 

#endif // MYTELEPHONY_H

/***************************************

****************************************

***************************************/

// MyTelephony.cpp

//

#include <e32svr.h>

#include "MyTelephony.h"

#include <f32file.h>

 

class CTelephony;

CMyTelephony* CMyTelephony::NewLC()

        {

        CMyTelephony* self = new (ELeave) CMyTelephony;

        CleanupStack::PushL(self);

        self->ConstructL();

        return self;

        }

 

CMyTelephony* CMyTelephony::NewL()

        {

        CMyTelephony* self = CMyTelephony::NewLC();

        CleanupStack::Pop(self);

        return self;

        }

 

void CMyTelephony::GetIMSIL(TDes& aIMSI)

        {

#ifndef __WINS__

        CMyTelephony* telephony = CMyTelephony::NewL();

        telephony->GetSubscriberId();

        aIMSI = telephony->iSubscriberId.iSubscriberId;

 

        delete telephony;

#else

        _LIT(KDebugIMSI, "000000000000000");

        aIMSI = KDebugIMSI;

#endif

        }

 

void CMyTelephony::GetIMEIL(TDes& aIMEI)

        {

#ifndef __WINS__ //真实设备 This only works on target machine

        CMyTelephony* telephony = CMyTelephony::NewL();

        telephony->GetPhoneId();

        aIMEI = telephony->iPhoneId.iSerialNumber;

 

        delete telephony;

#else //模拟器 Return a fake IMEI when working onemulator

        _LIT(KEmulatorImei, "000000000000000");

        aIMEI=KEmulatorImei;

#endif

        }

 

void CMyTelephony::GetPhoneType(TDes& aPhoneType)

        {

#ifndef __WINS__

        CMyTelephony* telephony = CMyTelephony::NewL();

        telephony->GetPhoneId();

        aPhoneType.Copy(telephony->iPhoneId.iManufacturer);

        aPhoneType.Append(telephony->iPhoneId.iModel);        

 

        delete telephony;

#else //模拟器 Return a fake IMEI when working onemulator

        _LIT(KPhoneType, "Nokia5500d");

        aPhoneType=KPhoneType;

#endif

        }

 

//获取系统版本

void CMyTelephony::GetS60PlatformVersionL( TUint& aMajor, TUint& aMinor )

 

    {

RFs aFs;

if(KErrNone == aFs.Connect())

{

TFindFile ff( aFs );

CDir* result;

User::LeaveIfError( ff.FindWildByDir( KS60ProductIDFile, KROMInstallDir, result ) );

CleanupStack::PushL( result );

User::LeaveIfError( result->Sort( ESortByName|EDescending ) );

aMajor = (*result)[0].iName[9] - '0';

aMinor = (*result)[0].iName[11] - '0';

CleanupStack::PopAndDestroy(); // result

}

aFs.Close();

 

    }

 

void CMyTelephony::DialPhone(const TDesC& aPhoneId)

        {

#ifndef __WINS__ //真实设备 This only works on target machine

        CMyTelephony* telephony = CMyTelephony::NewLC();

        telephony->DialNewCall(aPhoneId);

 

#else //模拟器 Return a fake IMEI when working onemulator

#endif

        }

void CMyTelephony::DoCancel()

        {

        iTelephony->CancelAsync(iRequest);

        iTelephony->CancelAsync(CTelephony::EDialNewCallCancel);

        }

 

void CMyTelephony::RunL()

        {

        CActiveScheduler::Stop();

        }

 

CMyTelephony::~CMyTelephony()

        {

        delete iTelephony;

        }

 

CMyTelephony::CMyTelephony() :

        CActive(CActive::EPriorityStandard), iSubscriberIdPckg(iSubscriberId),

                        iPhoneIdPckg(iPhoneId)

        {

        CActiveScheduler::Add(this);

        }

 

void CMyTelephony::ConstructL()

        {

        iTelephony = CTelephony::NewL();

        }

 

void CMyTelephony::GetSubscriberId()

        {

        Cancel();

        iRequest = CTelephony::EGetSubscriberIdCancel;

        iTelephony->GetSubscriberId(iStatus, iSubscriberIdPckg);

        SetActive();

        CActiveScheduler::Start();

        }

 

void CMyTelephony::GetPhoneId()

        {

        Cancel();

        iRequest = CTelephony::EGetPhoneIdCancel;

        iTelephony->GetPhoneId(iStatus, iPhoneIdPckg);

        SetActive();

        CActiveScheduler::Start();

        }

 

/*void CMyTelephony::GetType()

        {

        _LIT(KPath,"z://resource//versions//model.txt");

        Cancel();

 

        RFs fs;

        RFile typeFile;

        User::LeaveIfError(fs.Connect());

        TFileText myFile;

        User::LeaveIfError(typeFile.Open(fs, KPath, EFileShareReadersOnly));

 

        // Read from position 0: start of file

        myFile.Set(typeFile);

        myFile.Read(iPhoneType); // readBuf1 is now "write "

 

        fs.Close();

        SetActive();

        CActiveScheduler::Start();

        }*/

/*

 * 拨打电话

 * */

void CMyTelephony::DialNewCall(const TDesC& aTelNumber)

        {

        CTelephony::TTelNumber telNumber(aTelNumber);

        CTelephony::TCallParamsV1 callParams;

        callParams.iIdRestrict = CTelephony::ESendMyId;

        CTelephony::TCallParamsV1Pckg callParamsPckg(callParams);

        iTelephony->DialNewCall(iStatus, callParamsPckg, telNumber, iCallId);

        SetActive();

        }

原创粉丝点击