serviceproviders/sapi_sysinfo/sysinfoservice/src/deviceinfo.cpp
changeset 5 989d2f495d90
child 23 50974a8b132e
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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:  class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hal.h>
       
    19 #include <SysUtil.h>
       
    20 
       
    21 #include "sysinfoservice.h"
       
    22 #include "SysInfoUtils.h"
       
    23 #include "entitykeys.h"
       
    24 #include "deviceinfo.h"
       
    25 
       
    26 _LIT(KROMInstallDir,"\\system\\install\\");
       
    27 _LIT(KS60ProductIdFile,"Series60v*.sis");
       
    28 _LIT(KProductIdentifier,"RM");
       
    29 _LIT(KProductUnknown,"Unknown");
       
    30 
       
    31 const TInt KPositionNine = 9;
       
    32 
       
    33 // --------------------------------------------------------------------
       
    34 // CDeviceInfo::CDeviceInfo()
       
    35 // C++ default constructor.
       
    36 // --------------------------------------------------------------------
       
    37 //
       
    38 CDeviceInfo::CDeviceInfo():
       
    39             iPlatformMajorVersion(0),
       
    40             iPlatformMinorVersion(0),
       
    41             iOSMajorVersion(0),
       
    42             iOSMinorVersion(0)
       
    43     {
       
    44     }
       
    45 
       
    46 // --------------------------------------------------------------------
       
    47 // CDeviceInfo::~CDeviceInfo()
       
    48 // Destructor.
       
    49 // --------------------------------------------------------------------
       
    50 //
       
    51 CDeviceInfo::~CDeviceInfo()
       
    52     {
       
    53     delete iProductType;
       
    54     }
       
    55 	
       
    56 // --------------------------------------------------------------------
       
    57 // CDeviceInfo::NewL()
       
    58 // Two-phased constructor, returns instance of this class.
       
    59 // --------------------------------------------------------------------
       
    60 //
       
    61 CDeviceInfo* CDeviceInfo::NewL()
       
    62     {
       
    63     CDeviceInfo* self;
       
    64     self = new (ELeave) CDeviceInfo();
       
    65 
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL ();
       
    68     CleanupStack::Pop(self);
       
    69 
       
    70     return self;
       
    71     }
       
    72 	
       
    73 // --------------------------------------------------------------------
       
    74 // CDeviceInfo::NewL()
       
    75 // 2nd Phase constructor to allocate required resources for this obj.
       
    76 // --------------------------------------------------------------------
       
    77 //
       
    78 void CDeviceInfo::ConstructL ()
       
    79     {
       
    80     GetDeviceInfoL();
       
    81     }
       
    82 
       
    83 // --------------------------------------------------------------------
       
    84 // CDeviceInfo::GetDeviceInfoL()
       
    85 // This function reads device information initializes member varialbes.
       
    86 // --------------------------------------------------------------------
       
    87 //
       
    88 void CDeviceInfo::GetDeviceInfoL()
       
    89     {
       
    90     //get firmware version			
       
    91     User::LeaveIfError(SysUtil::GetSWVersion(iFirmwareVersion));
       
    92 
       
    93     //get platform version			
       
    94     RFs fs;
       
    95     CDir* result;
       
    96 
       
    97     CleanupClosePushL(fs);
       
    98     User::LeaveIfError(fs.Connect());
       
    99 
       
   100     TFindFile ff(fs);
       
   101     TInt err(KErrNone);
       
   102     err = ff.FindWildByDir(KS60ProductIdFile,KROMInstallDir,result);
       
   103     if(!err)
       
   104         {
       
   105         CleanupStack::PushL(result);
       
   106         User::LeaveIfError(result->Sort(ESortByName|EDescending));
       
   107 
       
   108         if(result->Count() >= 0)
       
   109             {
       
   110             TPtrC filename = (*result)[0].iName;
       
   111             TLex parser((filename));
       
   112             parser.Inc(KPositionNine);
       
   113 
       
   114             // Get major version value
       
   115             err = parser.Val(iPlatformMajorVersion);
       
   116 
       
   117             if( parser.Get() != '.' || err )
       
   118                 {
       
   119                 iPlatformMajorVersion = 0;
       
   120                 }
       
   121             else
       
   122                 {
       
   123                 // Get minor version value
       
   124                 err = parser.Val(iPlatformMinorVersion);
       
   125                 if( err )
       
   126                     {
       
   127                     iPlatformMajorVersion = 0;
       
   128                     iPlatformMinorVersion = 0;
       
   129                     }
       
   130                 }
       
   131             }
       
   132         // clean up result
       
   133         CleanupStack::PopAndDestroy(result);
       
   134         }
       
   135     // clean up file session fs.
       
   136     CleanupStack::PopAndDestroy(&fs);	
       
   137     	
       
   138     //get machine id and symbian OS version			
       
   139     HAL::Get(HALData::EMachineUid, iMachineId);
       
   140 
       
   141     //get product type
       
   142     ProcessProductTypeL();
       
   143 
       
   144     // Session to the telephony server.
       
   145     RTelServer telserver;
       
   146     //RMobilePhone handle.	
       
   147     RMobilePhone 	mobilephone;
       
   148 
       
   149     CleanupClosePushL(telserver);
       
   150     CleanupClosePushL(mobilephone);
       
   151 
       
   152     User::LeaveIfError(RPhoneInstance::Connect( telserver,mobilephone ));
       
   153 
       
   154     //get phone manufacturer,model,IMEI		
       
   155     TRequestStatus Status = KRequestPending;
       
   156     mobilephone.GetPhoneId(Status,iPhoneIdentity);
       
   157     User::WaitForRequest(Status);
       
   158 
       
   159     //Close Phone handle.
       
   160     CleanupStack::PopAndDestroy(2,&telserver);
       
   161     }
       
   162 
       
   163 // --------------------------------------------------------------------
       
   164 // CDeviceInfo::ProcessProductType()
       
   165 // This function does lexical processing on Firmware version to read
       
   166 // product type.
       
   167 // --------------------------------------------------------------------
       
   168 //
       
   169 void CDeviceInfo::ProcessProductTypeL()
       
   170     {
       
   171     TBuf<KSysUtilVersionTextLength> versionString(KNullDesC);
       
   172     TPtrC ProductType(KNullDesC);
       
   173     const TChar KNewLine('\n');
       
   174 
       
   175     versionString.Copy(iFirmwareVersion);
       
   176 
       
   177     TInt offset = versionString.FindF(KProductIdentifier);
       
   178     if( KErrNotFound != offset)
       
   179         {
       
   180         TPtr productinfo = versionString.MidTPtr(offset);
       
   181         //search new line charecter.
       
   182         offset = productinfo.LocateF(KNewLine);
       
   183         if( KErrNotFound != offset )
       
   184             {
       
   185             ProductType.Set(productinfo.Left(offset));
       
   186             }
       
   187         }
       
   188 
       
   189     iProductType = ProductType.AllocL();	
       
   190     }
       
   191 
       
   192 // --------------------------------------------------------------------
       
   193 // CDeviceInfo::ProductType()
       
   194 // returns product type.
       
   195 // --------------------------------------------------------------------
       
   196 //
       
   197 TPtrC CDeviceInfo::ProductType() const
       
   198     {
       
   199     if( iProductType->Des() == KNullDesC )
       
   200         return TPtrC(KProductUnknown);
       
   201     else
       
   202         return TPtrC(*iProductType);
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------
       
   206 // CDeviceInfo::FirmwareVersion()
       
   207 // returns firmware version.
       
   208 // --------------------------------------------------------------------
       
   209 //
       
   210 TPtrC CDeviceInfo::FirmwareVersion() const
       
   211     {
       
   212     return TPtrC(iFirmwareVersion);
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------
       
   216 // CDeviceInfo::Manufaturer()
       
   217 // returns Manufacture name.
       
   218 // --------------------------------------------------------------------
       
   219 //
       
   220 TPtrC CDeviceInfo::Manufaturer() const
       
   221 {
       
   222 	return TPtrC(iPhoneIdentity.iManufacturer);
       
   223 }
       
   224 
       
   225 // --------------------------------------------------------------------
       
   226 // CDeviceInfo::Model()
       
   227 // returns Phone Model.
       
   228 // --------------------------------------------------------------------
       
   229 //
       
   230 TPtrC CDeviceInfo::Model() const
       
   231     {
       
   232     return TPtrC(iPhoneIdentity.iModel);
       
   233     }
       
   234 
       
   235 // --------------------------------------------------------------------
       
   236 // CDeviceInfo::IMEI()
       
   237 // returns Serial number.
       
   238 // --------------------------------------------------------------------
       
   239 //
       
   240 TPtrC CDeviceInfo::IMEI() const
       
   241     {
       
   242     return TPtrC(iPhoneIdentity.iSerialNumber);
       
   243     }
       
   244 
       
   245 // --------------------------------------------------------------------
       
   246 // CDeviceInfo::MachineId()
       
   247 // returns Machine ID.
       
   248 // --------------------------------------------------------------------
       
   249 //
       
   250 TInt CDeviceInfo::MachineId() const
       
   251     {
       
   252     return iMachineId;
       
   253     }
       
   254 
       
   255 // --------------------------------------------------------------------
       
   256 // CDeviceInfo::GetPlatformVersion()
       
   257 // returns PLATFORM VERSION NUMBER.
       
   258 // --------------------------------------------------------------------
       
   259 //
       
   260 void CDeviceInfo::GetPlatformVersion(TInt& aMajor,TInt& aMinor)
       
   261     {
       
   262     aMajor = iPlatformMajorVersion;
       
   263     aMinor = iPlatformMinorVersion;
       
   264     }
       
   265 
       
   266 // --------------------------------------------------------------------
       
   267 // CDeviceInfo::GetOSVersion()
       
   268 // returns OS VERSION NUMBER.
       
   269 // --------------------------------------------------------------------
       
   270 //
       
   271 void CDeviceInfo::GetOSVersion(TInt& aMajor,TInt& aMinor)
       
   272     {
       
   273     aMajor = iOSMajorVersion;
       
   274     aMinor = iOSMinorVersion;
       
   275     }
       
   276 
       
   277 //End of file.