24
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// CPhoneApp.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "CPhoneId.h"
|
|
19 |
|
|
20 |
/**
|
|
21 |
TODO These Literals would be read from some file which the application would
|
|
22 |
check the result of GetPhoneId() against each time the App was run to make sure
|
|
23 |
it was registered.
|
|
24 |
*/
|
|
25 |
_LIT(KRegisteredManufacturer, "Generic");
|
|
26 |
_LIT(KRegisteredModel, "123");
|
|
27 |
_LIT(KRegisteredSerialNumber, "1234567890");
|
|
28 |
|
|
29 |
/**
|
|
30 |
Factory constructor.
|
|
31 |
|
|
32 |
@param aController Pointer to MExecAsync object passed to constructor of
|
|
33 |
CISVAPIBase
|
|
34 |
@return Instance of CPhoneId class
|
|
35 |
*/
|
|
36 |
CPhoneId* CPhoneId::NewL(MExecAsync* aController)
|
|
37 |
{
|
|
38 |
CPhoneId* self = new(ELeave) CPhoneId(aController);
|
|
39 |
CleanupStack::PushL(self);
|
|
40 |
self->ConstructL();
|
|
41 |
CleanupStack::Pop(self);
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
/**
|
|
46 |
Destructor.
|
|
47 |
Cancels outstanding requests.
|
|
48 |
*/
|
|
49 |
CPhoneId::~CPhoneId()
|
|
50 |
{
|
|
51 |
Cancel();
|
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
Gets the phone ID by calling 3rd party API function CTelephony::GetPhoneId().
|
|
56 |
*/
|
|
57 |
void CPhoneId::DoStartRequestL()
|
|
58 |
{
|
|
59 |
// Retrieves the model information and unique identification of the mobile device.
|
|
60 |
iTelephony->GetPhoneId(iStatus, iPhoneIdV1Pckg);
|
|
61 |
SetActive();
|
|
62 |
}
|
|
63 |
|
|
64 |
/**
|
|
65 |
Constructor.
|
|
66 |
|
|
67 |
@param aController Pointer to MExecAsync object passed to constructor of
|
|
68 |
CISVAPIBase
|
|
69 |
*/
|
|
70 |
CPhoneId::CPhoneId(MExecAsync* aController)
|
|
71 |
: CISVAPIAsync(aController, KPhoneId),
|
|
72 |
iPhoneIdV1Pckg(iPhoneIdV1)
|
|
73 |
{
|
|
74 |
// Empty method
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
Second phase constructor.
|
|
79 |
*/
|
|
80 |
void CPhoneId::ConstructL()
|
|
81 |
{
|
|
82 |
// Empty method
|
|
83 |
}
|
|
84 |
|
|
85 |
/**
|
|
86 |
Checks the status of the active object and whether the application is registered to
|
|
87 |
the mobile phone and displays output to the console.
|
|
88 |
*/
|
|
89 |
void CPhoneId::RunL()
|
|
90 |
{
|
|
91 |
// Print Phone Info
|
|
92 |
if(iStatus != KErrNone)
|
|
93 |
{
|
|
94 |
iConsole->Printf(KError);
|
|
95 |
|
|
96 |
// Print the error status code
|
|
97 |
iConsole->Printf(_L("%d\n"), iStatus.Int());
|
|
98 |
}
|
|
99 |
else
|
|
100 |
{
|
|
101 |
if (AppRegistered())
|
|
102 |
{
|
|
103 |
TBuf<CTelephony::KPhoneManufacturerIdSize> manufacturer = iPhoneIdV1.iManufacturer;
|
|
104 |
TBuf<CTelephony::KPhoneModelIdSize> model = iPhoneIdV1.iModel;
|
|
105 |
TBuf<CTelephony::KPhoneSerialNumberSize> serialNumber = iPhoneIdV1.iSerialNumber;
|
|
106 |
iConsole->Printf(KPhoneIdMsg);
|
|
107 |
|
|
108 |
// Print phone manufacturer
|
|
109 |
iConsole->Printf(manufacturer);
|
|
110 |
iConsole->Printf(KNewLine);
|
|
111 |
|
|
112 |
// Print phone model
|
|
113 |
iConsole->Printf(model);
|
|
114 |
iConsole->Printf(KNewLine);
|
|
115 |
|
|
116 |
// Print the IMEI or ESN serial number
|
|
117 |
iConsole->Printf(serialNumber);
|
|
118 |
iConsole->Printf(KNewLine);
|
|
119 |
|
|
120 |
ExampleComplete();
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
// Application isn't registered!
|
|
125 |
|
|
126 |
// Sim Tsy Config doesn't match Lits defined in CPhoneId
|
|
127 |
// Could end Application here by calling Terminate().
|
|
128 |
// Wait for 5 seconds then continue by calling ExampleComplete().
|
|
129 |
iConsole->Printf(_L("Application not registered to phone!\n"));
|
|
130 |
iConsole->Printf(_L("Recify this to remove this delay\n"));
|
|
131 |
User::After(5000000);
|
|
132 |
ExampleComplete();
|
|
133 |
}
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
Cancels asynchronous request to CTelephony::GetPhoneId().
|
|
139 |
*/
|
|
140 |
void CPhoneId::DoCancel()
|
|
141 |
{
|
|
142 |
// Cancels an outstanding asynchronous request.
|
|
143 |
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
147 |
Compares data retrieved from phone with registered values to check the application is
|
|
148 |
registered.
|
|
149 |
|
|
150 |
@return Returns ETrue if phone data matches registered values otherwise EFalse.
|
|
151 |
*/
|
|
152 |
TBool CPhoneId::AppRegistered()
|
|
153 |
{
|
|
154 |
// Values on phone
|
|
155 |
TBuf<CTelephony::KPhoneManufacturerIdSize> manufacturer = iPhoneIdV1.iManufacturer;
|
|
156 |
TBuf<CTelephony::KPhoneModelIdSize> model = iPhoneIdV1.iModel;
|
|
157 |
TBuf<CTelephony::KPhoneSerialNumberSize> serialNumber = iPhoneIdV1.iSerialNumber;
|
|
158 |
|
|
159 |
// Registered values
|
|
160 |
TBuf<CTelephony::KPhoneModelIdSize> registeredModel(KRegisteredModel);
|
|
161 |
TBuf<CTelephony::KPhoneSerialNumberSize> registeredSerialNumber(KRegisteredSerialNumber);
|
|
162 |
TBuf<CTelephony::KPhoneManufacturerIdSize> registeredManufacturer(KRegisteredManufacturer);
|
|
163 |
|
|
164 |
return registeredModel == model &&
|
|
165 |
registeredManufacturer == manufacturer &&
|
|
166 |
registeredSerialNumber == serialNumber ;
|
|
167 |
}
|