javacommons/security/src.s60/telutils.cpp
branchRCL_3
changeset 19 04becd199f91
child 46 4376525cdefb
child 56 abc41079b313
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2007-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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "telutils.h"
       
    20 
       
    21 using namespace java::security;
       
    22 
       
    23 TelUtils* TelUtils::createInstance()
       
    24 {
       
    25     TelUtils* self = NULL;
       
    26     TRAPD(err,
       
    27           self = new(ELeave) TelUtils();
       
    28           CleanupStack::PushL(self);
       
    29           self->ConstructL();
       
    30           CleanupStack::Pop(self);
       
    31          );
       
    32     if (err == KErrNone)
       
    33     {
       
    34         return self;
       
    35     }
       
    36     else
       
    37     {
       
    38         return NULL;
       
    39     }
       
    40 }
       
    41 
       
    42 void TelUtils::getNetworkCodes(std::string& mcc, std::string& mnc)
       
    43 {
       
    44     //JELOG2(EUtils);
       
    45     mnc += "000";
       
    46     mcc += "000";
       
    47     if (iMnc)
       
    48     {
       
    49         descToStr(iMnc, mnc);
       
    50     }
       
    51     if (iMcc)
       
    52     {
       
    53         descToStr(iMcc, mcc);
       
    54     }
       
    55 }
       
    56 
       
    57 void TelUtils::getImei(std::string& imei)
       
    58 {
       
    59     //JELOG2(EUtils);
       
    60     if (iImei)
       
    61     {
       
    62         descToStr(iImei, imei);
       
    63     }
       
    64 }
       
    65 
       
    66 
       
    67 void TelUtils::ConstructL()
       
    68 {
       
    69     RMobilePhone::TMobilePhoneIdentityV1        phoneId;
       
    70     RTelServer::TPhoneInfo                      phoneInfo;
       
    71     User::LeaveIfError(iServer.Connect());
       
    72     User::LeaveIfError(iServer.LoadPhoneModule(KMmTsyModuleName));
       
    73     User::LeaveIfError(iServer.GetPhoneInfo(0, phoneInfo));
       
    74     User::LeaveIfError(iPhone.Open(iServer, phoneInfo.iName));
       
    75 
       
    76     TUint32 idCaps;
       
    77     TInt result = iPhone.GetIdentityCaps(idCaps);
       
    78     if (KErrNone == result && idCaps&RMobilePhone::KCapsGetSerialNumber)
       
    79     {
       
    80         TRequestStatus  status;
       
    81         iPhone.GetPhoneId(status, phoneId);
       
    82         User::WaitForRequest(status);
       
    83         User::LeaveIfError(status.Int());
       
    84         iImei = phoneId.iSerialNumber.Alloc();
       
    85     }
       
    86 
       
    87     TUint32 networkCaps;
       
    88     result = iPhone.GetNetworkCaps(networkCaps);
       
    89     if (KErrNone == result && networkCaps & RMobilePhone::KCapsGetCurrentNetwork)
       
    90     {
       
    91         TRequestStatus  status;
       
    92         RMobilePhone::TMobilePhoneOPlmnV3   networkInfo;
       
    93         RMobilePhone::TMobilePhoneOPlmnV3Pckg pckgNetworkInfo(networkInfo);
       
    94         RMobilePhone::TMobilePhoneNetworkNameV3 networkName;
       
    95         RMobilePhone::TMobilePhoneNetworkNameV3Pckg pckgNetworkName(networkName);
       
    96         iPhone.GetCurrentNetworkName(status, pckgNetworkName, pckgNetworkInfo);
       
    97         User::WaitForRequest(status);
       
    98         User::LeaveIfError(status.Int());
       
    99         iMnc = (networkInfo.iNetworkId).Alloc();
       
   100         iMcc = (networkInfo.iCountryCode).Alloc();
       
   101     }
       
   102 
       
   103     if (iServer.Handle())
       
   104     {
       
   105         iPhone.Close();
       
   106         iServer.UnloadPhoneModule(KMmTsyModuleName);
       
   107         iServer.Close();
       
   108     }
       
   109 }
       
   110 
       
   111 TelUtils::TelUtils()
       
   112         : iImei(NULL), iMnc(NULL), iMcc(NULL)
       
   113 {
       
   114 }
       
   115 
       
   116 TelUtils::~TelUtils()
       
   117 {
       
   118     if (iServer.Handle())
       
   119     {
       
   120         iPhone.Close();
       
   121         iServer.UnloadPhoneModule(KMmTsyModuleName);
       
   122         iServer.Close();
       
   123     }
       
   124     if (iImei)
       
   125     {
       
   126         delete iImei;
       
   127         iImei = NULL;
       
   128     }
       
   129     if (iMnc)
       
   130     {
       
   131         delete iMnc;
       
   132         iMnc = NULL;
       
   133     }
       
   134     if (iMcc)
       
   135     {
       
   136         delete iMcc;
       
   137         iMcc = NULL;
       
   138     }
       
   139 }
       
   140 
       
   141 void TelUtils::descToStr(HBufC * desc, std::string& str)
       
   142 {
       
   143     if (desc->Length() > 0)
       
   144     {
       
   145         str.clear();
       
   146         const char * tmp = (const char *)desc->Ptr();
       
   147         for (int i=0; i < desc->Length(); i++)
       
   148         {
       
   149             str += tmp;
       
   150             tmp += 2;
       
   151         }
       
   152     }
       
   153 }
       
   154