1 /* |
|
2 * Copyright (c) 2008 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: Service Activation this feature provided if service |
|
15 * to be enabled from PNPMS application |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <PnpProvUtil.h> |
|
21 #include "PnpServiceActivation.h" |
|
22 #include <apacmdln.h> |
|
23 #include <apgcli.h> |
|
24 #include <w32std.h> |
|
25 #include <apgtask.h> |
|
26 #include <w32std.h> |
|
27 #include <StringLoader.h> |
|
28 #include <PnpProvisioning.rsg> |
|
29 #include <AknGlobalNote.h> |
|
30 #include <centralrepository.h> |
|
31 |
|
32 #include <e32svr.h> |
|
33 #include <centralrepository.h> |
|
34 #include "PnpLogger.h" |
|
35 |
|
36 |
|
37 const TUid KCRUidPnPProvisioning = {0x10204338}; |
|
38 // Browser UID |
|
39 const TUid KWAPBrowserUID = { 0x10008d39 }; |
|
40 const TInt KMaxLength = 255; |
|
41 // POP3 and IMAP4 provisioning settings application ID |
|
42 |
|
43 // Literal constants |
|
44 |
|
45 const TUint32 KServiceAct1 = 0x00000100; |
|
46 |
|
47 // INCLUDE FILES |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CPnpServiceActivation::CPnpServiceActivation |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CPnpServiceActivation::CPnpServiceActivation() |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CPnpProvUtil::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPnpServiceActivation::ConstructL() |
|
64 { |
|
65 //No values to assign |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPnpProvUtil::NewL |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CPnpServiceActivation* CPnpServiceActivation::NewL() |
|
74 { |
|
75 CPnpServiceActivation* self = NewLC(); |
|
76 CleanupStack::Pop(); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CPnpServiceActivation::NewLC |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CPnpServiceActivation* CPnpServiceActivation::NewLC() |
|
86 { |
|
87 CPnpServiceActivation* self = new( ELeave ) CPnpServiceActivation; |
|
88 |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // Destructor |
|
97 // ----------------------------------------------------------------------------- |
|
98 CPnpServiceActivation::~CPnpServiceActivation() |
|
99 { |
|
100 } |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CPnpServiceActivation::LaunchApplicationL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CPnpServiceActivation::LaunchApplicationL() |
|
106 { |
|
107 |
|
108 // For email service activation Messaging launcher is activated |
|
109 TBool validApp = ValidateAppUidWithProvappIDL(); |
|
110 |
|
111 if(validApp) |
|
112 { |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 RApaLsSession appArcSession; |
|
118 |
|
119 User::LeaveIfError( appArcSession.Connect() ); |
|
120 CleanupClosePushL( appArcSession ); |
|
121 TApaAppInfo appInfo; |
|
122 User::LeaveIfError(appArcSession.GetAppInfo( appInfo, TUid::Uid( iLaunchUid) ) ); |
|
123 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
124 cmdLine->SetCommandL( EApaCommandRun ); |
|
125 cmdLine->SetExecutableNameL( appInfo.iFullName ); |
|
126 User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); |
|
127 CleanupStack::PopAndDestroy( 2 ); // cmdLine, appArcSession |
|
128 } |
|
129 |
|
130 } |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CPnpServiceActivation::ValidateAppUidWithProvappIDL() |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TBool CPnpServiceActivation::ValidateAppUidWithProvappIDL() |
|
138 { |
|
139 |
|
140 // Get application ID and Provisioning settings application |
|
141 // ID and validate the application launcher |
|
142 |
|
143 RPointerArray<HBufC> appID; |
|
144 TBuf<16> pLaunchUid; |
|
145 TBool returnFlag (EFalse); |
|
146 TBool FoundUid(EFalse); |
|
147 TBool FoundAppid(EFalse); |
|
148 |
|
149 CPnpProvUtil *provutil = CPnpProvUtil::NewLC(); |
|
150 |
|
151 iLaunchUid = provutil->GetApplicationUidL(); |
|
152 |
|
153 provutil->GetProvAdapterAppIdsL(appID); |
|
154 pLaunchUid.Num(iLaunchUid); |
|
155 |
|
156 FoundUid = isPresent(pLaunchUid); |
|
157 TUint32 secondPosition = iPosition+200; |
|
158 if(FoundUid) |
|
159 { |
|
160 for(TInt i=0; i<appID.Count(); i++) |
|
161 { |
|
162 TPtrC ptr(*appID[i]); |
|
163 FoundAppid = isFound(ptr,secondPosition); |
|
164 if(FoundAppid) |
|
165 { |
|
166 if(iPosition == KServiceAct1){ |
|
167 DisplayAppSpecNoteL(); |
|
168 } |
|
169 returnFlag = ETrue; |
|
170 } |
|
171 } |
|
172 } |
|
173 |
|
174 |
|
175 CleanupStack::PopAndDestroy(); |
|
176 |
|
177 appID.ResetAndDestroy(); |
|
178 appID.Close(); |
|
179 return returnFlag; |
|
180 } |
|
181 |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CPnpServiceActivation::KillBrowserL() |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CPnpServiceActivation::KillBrowserL() |
|
188 { |
|
189 |
|
190 // Get the correct application data |
|
191 RWsSession ws; |
|
192 User::LeaveIfError(ws.Connect()); |
|
193 CleanupClosePushL(ws); |
|
194 |
|
195 // Find the task with uid of browser. If task exists then |
|
196 // kill browser |
|
197 TApaTaskList taskList(ws); |
|
198 TApaTask task = taskList.FindApp( KWAPBrowserUID ); |
|
199 if(task.Exists()) |
|
200 task.EndTask(); |
|
201 |
|
202 CleanupStack::PopAndDestroy(); // ws, lsSession |
|
203 |
|
204 |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CPnpServiceActivation::DisplayAppSpecNote() |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 |
|
212 void CPnpServiceActivation::DisplayAppSpecNoteL() |
|
213 { |
|
214 HBufC* text = StringLoader::LoadLC(R_TEXT_EMAIL_SERVICE_NOTE); |
|
215 |
|
216 CAknGlobalNote* globalNote = CAknGlobalNote::NewL(); |
|
217 CleanupStack::PushL( globalNote ); |
|
218 globalNote->ShowNoteL( EAknGlobalInformationNote , *text ); |
|
219 CleanupStack::PopAndDestroy( 2 ); |
|
220 } |
|
221 |
|
222 TBool CPnpServiceActivation::isPresent(TDesC& p) |
|
223 { |
|
224 TBool flag(EFalse); |
|
225 TUint32 position = KServiceAct1; |
|
226 for(TInt i=0;i<=299;i++) |
|
227 { |
|
228 TBool val = isFound(p,position); |
|
229 if(val) |
|
230 { |
|
231 iPosition = position; |
|
232 flag = ETrue; |
|
233 break; |
|
234 } |
|
235 position++; |
|
236 } |
|
237 return flag; |
|
238 } |
|
239 TBool CPnpServiceActivation::isFound(TDesC& p,TUint32 position) |
|
240 { |
|
241 TBool val(EFalse); |
|
242 TBuf16<KMaxLength> keys; |
|
243 HBufC* heapBuf = HBufC::NewLC(20); |
|
244 TPtr ptr(heapBuf->Des()); |
|
245 ptr = keys; |
|
246 RPointerArray<HBufC> array; |
|
247 TRAPD( errVal,GetCenrepValueL(KCRUidPnPProvisioning,position,keys)); |
|
248 // End of File |
|
249 if(errVal != KErrNone) |
|
250 { |
|
251 CleanupStack::PopAndDestroy(); |
|
252 return val; |
|
253 } |
|
254 ParseValues(array, keys); |
|
255 val = Search(array,p); |
|
256 CleanupStack::PopAndDestroy(heapBuf); |
|
257 array.ResetAndDestroy(); |
|
258 array.Close(); |
|
259 return val; |
|
260 } |
|
261 |
|
262 TBool CPnpServiceActivation::Search(RPointerArray<HBufC>& array,TDesC& p) |
|
263 { |
|
264 TBool flag(EFalse); |
|
265 for(TInt j=0; j<array.Count(); j++) |
|
266 { |
|
267 TPtrC ptr(*array[j]); |
|
268 if(!ptr.Compare(p)) |
|
269 { |
|
270 flag = ETrue; |
|
271 } |
|
272 } |
|
273 return flag; |
|
274 } |
|
275 void CPnpServiceActivation::ParseValues(RPointerArray<HBufC>& array, TDesC& aValue) |
|
276 { |
|
277 TLex aLex(aValue); |
|
278 while(aLex.Peek() != '\x00') |
|
279 { |
|
280 aLex.Mark(); |
|
281 while(aLex.Peek()!=',' && aLex.Peek()!='\x00') |
|
282 aLex.Inc(); |
|
283 TPtrC aPtr = aLex.MarkedToken(); |
|
284 HBufC *buf18 = aPtr.AllocL(); |
|
285 array.Append(buf18); |
|
286 if(aLex.Peek()=='\x00') // end of string |
|
287 break; |
|
288 aLex.Inc(); |
|
289 } |
|
290 } |
|
291 void CPnpServiceActivation::GetCenrepValueL(const TUid aRepositoryUid,TUint32 aKey, TDes16& aValue) |
|
292 { |
|
293 CRepository * rep = NULL; |
|
294 TInt errorStatus = KErrNone; |
|
295 TRAPD( errVal, rep = CRepository::NewL(aRepositoryUid)); |
|
296 if(errVal == KErrNone) |
|
297 { |
|
298 errorStatus = rep->Get( aKey , aValue ); |
|
299 } |
|
300 else |
|
301 { |
|
302 errorStatus = errVal; |
|
303 } |
|
304 |
|
305 if(rep) |
|
306 { |
|
307 delete rep; |
|
308 } |
|
309 if(errorStatus != KErrNone ) |
|
310 { |
|
311 User::Leave(errorStatus); |
|
312 } |
|
313 } |
|