|
1 /* |
|
2 * Copyright (c) 2006,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: Implementation of CCommsDatStartup class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <e32def.h> |
|
24 #include <e32base.h> |
|
25 #include <s32strm.h> |
|
26 #include <s32file.h> |
|
27 #include <etelpckt.h> |
|
28 |
|
29 #include <centralrepository.h> |
|
30 #include "cdccommsdatcreatorcrkeys.h" |
|
31 |
|
32 #include "cdccommsdatstartup.h" |
|
33 #include "cdccommsdatcreator.h" |
|
34 #include "cdcerrors.h" |
|
35 #include "cdclogger.h" |
|
36 |
|
37 |
|
38 // CONSTANTS |
|
39 const TUid KCRUidCommsDb = { 0xcccccc00 }; |
|
40 |
|
41 //------------------------------------------------ |
|
42 // CCdcCommsDatStartup::DoStartL |
|
43 //------------------------------------------------ |
|
44 // |
|
45 void CCdcCommsDatStartup::DoStartL() |
|
46 { |
|
47 CLOG_WRITE( "-----------------------------" ); |
|
48 CLOG_WRITE( "CCdcCommsDatStartup::DoStartL" ); |
|
49 CLOG_WRITE( "-----------------------------" ); |
|
50 |
|
51 CheckCreatorUIdL(); |
|
52 |
|
53 CreateRepositoryL(); |
|
54 |
|
55 // Set status to not initialised |
|
56 SetStartupStatusL( ECommsDatInitialisationFailed ); |
|
57 |
|
58 CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL()" ); |
|
59 // In all RFS cases CommsDat must be reset |
|
60 ResetCommsDatToDefaultL(); |
|
61 |
|
62 // Reset EAP settings databases |
|
63 ResetEAPSettingsL(); |
|
64 |
|
65 CLOG_WRITE( "CCdcCommsDatStartup::CCdcCommsDatCreator::NewLC()" ); |
|
66 |
|
67 CCdcCommsDatCreator* cdc = CCdcCommsDatCreator::NewLC(); |
|
68 |
|
69 CLOG_WRITE( "CCdcCommsDatStartup::CreateTablesL" ); |
|
70 |
|
71 // In all RFS cases CommsDat tables must be checked/created |
|
72 cdc->CreateTablesL(); |
|
73 |
|
74 TFileName fileName; |
|
75 GetInputFileNameL( fileName ); |
|
76 |
|
77 // CommsDatCreator feature is supported if input file name |
|
78 // lenght is not 0. However file name lenght at least 5. (x.xml) |
|
79 if( fileName.Length() > 0 ) |
|
80 { |
|
81 CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation enabled" ); |
|
82 |
|
83 TFileName path( _L("Z:\\private\\10281BC3\\" ) ); |
|
84 path.Append( fileName ); |
|
85 |
|
86 CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL begin" ); |
|
87 |
|
88 TRAPD(err, cdc->CreateCommsDatL( path ) ); |
|
89 if(err != KErrNone ) |
|
90 { |
|
91 // CommsDat creation leaved so something must be wrong. |
|
92 // Reset CommsDat and EAP settings. |
|
93 ResetCommsDatToDefaultL(); |
|
94 ResetEAPSettingsL(); |
|
95 cdc->CreateTablesL(); |
|
96 User::Leave( err ); |
|
97 } |
|
98 |
|
99 CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL end" ); |
|
100 } |
|
101 else |
|
102 { |
|
103 CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation disabled" ); |
|
104 } |
|
105 |
|
106 // If nothing has leaved then everything is okay (both in disabled and |
|
107 // enabled cases. |
|
108 SetStartupStatusL( ECommsDatInitialised ); |
|
109 |
|
110 CleanupStack::PopAndDestroy( cdc ); |
|
111 CLOG_WRITE( "CCdcCommsDatStartup::DoStartL end" ); |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CCdcCommsDatStartup::CreateRepositoryL() |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 void CCdcCommsDatStartup::CreateRepositoryL() |
|
119 { |
|
120 CLOG_WRITE( "CCdcCommsDatStartup::CreateRepositoryL()" ); |
|
121 |
|
122 TRAPD( err, iRepository = CRepository::NewL( KCRUidCommsDatCreator ) ); |
|
123 |
|
124 // Log is important now, because repository cannot contain the |
|
125 // error value if it cannot be used |
|
126 if( err != KErrNone ) |
|
127 { |
|
128 CLOG_WRITE_FORMAT( "Repository could not created err : %d", err ); |
|
129 User::Leave( err ); |
|
130 } |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // CCdcCommsDatStartup::SetStartupStatusL() |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 void CCdcCommsDatStartup::SetStartupStatusL( TInt aResult ) |
|
138 { |
|
139 CLOG_WRITE_FORMAT( "CCdcCommsDatStartup::SetStartupStatusL() %d", aResult ); |
|
140 |
|
141 TInt err = iRepository->Set( KCommsDatCreatorStartupStatus, aResult ); |
|
142 if( err != KErrNone ) |
|
143 { |
|
144 CLOG_WRITE_FORMAT( |
|
145 "Value could not write to repository err : %d", err ); |
|
146 User::Leave( err ); |
|
147 } |
|
148 |
|
149 CLOG_WRITE_FORMAT( "CCdcCommsDatStartup::SetStartupStatusL() %d", aResult ); |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------------------------- |
|
153 // CCdcCommsDatStartup::GetInputFileNameL() |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 void CCdcCommsDatStartup::GetInputFileNameL( TFileName &aFileName ) |
|
157 { |
|
158 CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL()" ); |
|
159 |
|
160 TInt err = iRepository->Get( KCommsDatCreatorInputFileName, aFileName ); |
|
161 if( err != KErrNone ) |
|
162 { |
|
163 CLOG_WRITE_FORMAT( |
|
164 "Value could not red from repository err : %d", err ); |
|
165 User::Leave( err ); |
|
166 } |
|
167 |
|
168 CLOG_WRITE( "Input filename red" ); |
|
169 |
|
170 HBufC *fileName = aFileName.AllocLC(); |
|
171 |
|
172 CLOG_WRITE_FORMAT( "Input filename value : %S", fileName ); |
|
173 |
|
174 CleanupStack::PopAndDestroy( fileName ); |
|
175 |
|
176 // Check if file exists. If it doesn't reset filename. |
|
177 RFs fs; |
|
178 err = fs.Connect();//check |
|
179 |
|
180 if( err == KErrNone ) |
|
181 { |
|
182 RFile file; |
|
183 |
|
184 TFileName path( _L("Z:\\private\\10281BC3\\" ) ); |
|
185 path.Append( aFileName ); |
|
186 |
|
187 err = file.Open(fs, path, EFileRead); |
|
188 if( err != KErrNone ) |
|
189 { |
|
190 CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL() File does not exist"); |
|
191 aFileName.Zero(); |
|
192 } |
|
193 else |
|
194 { |
|
195 file.Close(); |
|
196 } |
|
197 fs.Close(); |
|
198 } |
|
199 |
|
200 CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL()" ); |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // CCdcCommsDatStartup::CheckCreatorUIdL() |
|
205 // ---------------------------------------------------------------------------- |
|
206 // |
|
207 void CCdcCommsDatStartup::CheckCreatorUIdL() |
|
208 { |
|
209 // UID of MainRfs |
|
210 const TUid KCreatorUid = { 0x102073EA }; |
|
211 |
|
212 CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" ); |
|
213 |
|
214 TUid creatorId = User::CreatorIdentity(); |
|
215 |
|
216 CLOG_WRITE_FORMAT( "CreatorId : %x", creatorId ); |
|
217 |
|
218 if( KCreatorUid != creatorId ) |
|
219 { |
|
220 User::Leave( KErrPermissionDenied ); |
|
221 } |
|
222 |
|
223 CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" ); |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CCdcCommsDatStartup::~CCdcCommsDatStartup() |
|
228 // ---------------------------------------------------------------------------- |
|
229 // |
|
230 CCdcCommsDatStartup::~CCdcCommsDatStartup() |
|
231 { |
|
232 if( iRepository ) |
|
233 { |
|
234 delete iRepository; |
|
235 } |
|
236 } |
|
237 |
|
238 // ---------------------------------------------------------------------------- |
|
239 // CCdcCommsDatCreatorRfsPlugin::ResetCommsDatToDefaultL() |
|
240 // ---------------------------------------------------------------------------- |
|
241 // |
|
242 void CCdcCommsDatStartup::ResetCommsDatToDefaultL() |
|
243 { |
|
244 CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL" ); |
|
245 |
|
246 CRepository* repository( NULL ); |
|
247 |
|
248 repository = CRepository::NewL( KCRUidCommsDb ); |
|
249 CleanupStack::PushL( repository ); |
|
250 |
|
251 CLOG_WRITE("Reset CommsDat CenRep"); |
|
252 |
|
253 User::LeaveIfError( repository->Reset() ); |
|
254 |
|
255 CleanupStack::PopAndDestroy( repository ); |
|
256 |
|
257 CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL end" ); |
|
258 } |
|
259 |
|
260 // ---------------------------------------------------------------------------- |
|
261 // CCdcCommsDatCreatorRfsPlugin::ResetEAPSettingsL() |
|
262 // ---------------------------------------------------------------------------- |
|
263 // |
|
264 void CCdcCommsDatStartup::ResetEAPSettingsL() |
|
265 { |
|
266 CLOG_WRITE( "CCdcCommsDatStartup::ResetEAPSettingsL" ); |
|
267 RFs fs; |
|
268 User::LeaveIfError( fs.Connect() ); |
|
269 CleanupClosePushL( fs ); |
|
270 |
|
271 CFileMan *fileMan = CFileMan::NewL( fs ); |
|
272 CleanupStack::PushL( fileMan ); |
|
273 |
|
274 _LIT( KEapWildcard, "c:\\private\\100012a5\\DBS_102072E9_eap*" ); |
|
275 |
|
276 TInt err = fileMan->Delete( KEapWildcard ); |
|
277 |
|
278 if ( err != KErrNone |
|
279 && err != KErrNotFound |
|
280 && err != KErrPathNotFound ) |
|
281 { |
|
282 User::Leave( err ); |
|
283 } |
|
284 |
|
285 CleanupStack::PopAndDestroy( fileMan ); |
|
286 CleanupStack::PopAndDestroy(); // fs |
|
287 CLOG_WRITE( "CCdcCommsDatStartup::ResetEAPSettingsL end" ); |
|
288 } |
|
289 |
|
290 // End of File. |