|
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: CJavaFile |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "logger.h" |
|
19 #include "mjavafile.h" |
|
20 #include "javafile.h" |
|
21 |
|
22 using namespace javaruntime; |
|
23 |
|
24 //***************************************************************************** |
|
25 MJavaFile* CJavaFile::NewL() |
|
26 { |
|
27 JELOG2(EJVM); |
|
28 CJavaFile* self = new(ELeave) CJavaFile(); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 //***************************************************************************** |
|
36 CJavaFile::CJavaFile(): iJavaFileMode(EJavaFileClosed) |
|
37 { |
|
38 JELOG2(EJVM); |
|
39 } |
|
40 |
|
41 //***************************************************************************** |
|
42 void CJavaFile::ConstructL() |
|
43 { |
|
44 JELOG2(EJVM); |
|
45 } |
|
46 |
|
47 //***************************************************************************** |
|
48 CJavaFile::~CJavaFile() |
|
49 { |
|
50 JELOG2(EJVM); |
|
51 Close(); |
|
52 } |
|
53 |
|
54 //***************************************************************************** |
|
55 void CJavaFile::OpenCafL(const TDesC& aFileName) |
|
56 { |
|
57 JELOG2(EJVM); |
|
58 if (NULL == iCafContent) |
|
59 { |
|
60 iCafContent = ContentAccess::CContent::NewL(aFileName); |
|
61 } |
|
62 iCafData = iCafContent->OpenContentL(ContentAccess::EPeek); |
|
63 User::LeaveIfError(iCafData->ExecuteIntent(ContentAccess::EPeek)); |
|
64 } |
|
65 |
|
66 //***************************************************************************** |
|
67 TInt CJavaFile::Open(RFs& aFs,const TDesC& aFileName, TUint aFileMode) |
|
68 { |
|
69 JELOG2(EJVM); |
|
70 if (iJavaFileMode != EJavaFileClosed) |
|
71 { |
|
72 // Not allowed if some file is already opened and not properly closed. |
|
73 return KErrInUse; |
|
74 } |
|
75 mFileName.assign((wchar_t*)aFileName.Ptr(), aFileName.Length()); |
|
76 TInt status; |
|
77 if (isDrmFile(aFileName)) |
|
78 { |
|
79 LOG1(EJVM, EInfo,"Opening file %S using CAF", mFileName.c_str()); |
|
80 iJavaFileMode = EJavaFileOpenForCaf; //This is set before opening |
|
81 //in order to allow proper |
|
82 //cleanup if something fails. |
|
83 TRAP(status, OpenCafL(aFileName)); |
|
84 if (status != KErrNone) |
|
85 { |
|
86 // Clean up and set the class ready for opening another file. |
|
87 Close(); |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 // Using RFile |
|
93 LOG1(EJVM, EInfo,"Opening file %S using RFile", mFileName.c_str()); |
|
94 status = iNormalFile.Open(aFs, aFileName, aFileMode); |
|
95 if (status == KErrNone) |
|
96 { |
|
97 iJavaFileMode = EJavaFileOpenForNormalFile; |
|
98 } |
|
99 // No need for cleaning. |
|
100 } |
|
101 return status; |
|
102 } |
|
103 |
|
104 //***************************************************************************** |
|
105 void CJavaFile::Close() |
|
106 { |
|
107 JELOG2(EJVM); |
|
108 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
109 { |
|
110 LOG1(EJVM, EInfo,"Closing file %S using CAF", mFileName.c_str()); |
|
111 delete iCafData; |
|
112 iCafData = NULL; |
|
113 delete iCafContent; |
|
114 iCafContent = NULL; |
|
115 } |
|
116 if (iJavaFileMode == EJavaFileOpenForNormalFile) |
|
117 { |
|
118 LOG1(EJVM, EInfo,"Closing file %S using RFile", mFileName.c_str()); |
|
119 iNormalFile.Close(); |
|
120 } |
|
121 iJavaFileMode = EJavaFileClosed; |
|
122 } |
|
123 |
|
124 //***************************************************************************** |
|
125 TInt CJavaFile::Size(TInt& aSize) const |
|
126 { |
|
127 JELOG2(EJVM); |
|
128 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
129 { |
|
130 //Using CAF |
|
131 TInt status = KErrNone; |
|
132 TRAP(status, iCafData->DataSizeL(aSize)); |
|
133 return status; |
|
134 } |
|
135 else |
|
136 { |
|
137 //Using RFile |
|
138 return iNormalFile.Size(aSize); |
|
139 } |
|
140 } |
|
141 |
|
142 //***************************************************************************** |
|
143 TInt CJavaFile::SetSize(TInt aSize) |
|
144 { |
|
145 JELOG2(EJVM); |
|
146 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
147 { |
|
148 //Not supported for files accessed via CAF. |
|
149 return KErrNotSupported; |
|
150 } |
|
151 else |
|
152 { |
|
153 //Using RFile |
|
154 return iNormalFile.SetSize(aSize); |
|
155 } |
|
156 } |
|
157 |
|
158 //***************************************************************************** |
|
159 TInt CJavaFile::Create(RFs& aFs,const TDesC& aName,TUint aFileMode) |
|
160 { |
|
161 JELOG2(EJVM); |
|
162 if (iJavaFileMode != EJavaFileClosed) |
|
163 { |
|
164 //Not allowed if some file is already opened and not properly closed. |
|
165 return KErrInUse; |
|
166 } |
|
167 //Using RFile |
|
168 TInt status = iNormalFile.Create(aFs, aName, aFileMode); |
|
169 if (status == KErrNone) |
|
170 { |
|
171 iJavaFileMode = EJavaFileOpenForNormalFile; |
|
172 } |
|
173 return status; |
|
174 } |
|
175 |
|
176 //***************************************************************************** |
|
177 TInt CJavaFile::Read(TDes8& aDes) const |
|
178 { |
|
179 //JELOG4(EJVM, EEntry & EInfoHeavyLoad); |
|
180 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
181 { |
|
182 //Using CAF |
|
183 return iCafData->Read(aDes); |
|
184 } |
|
185 else |
|
186 { |
|
187 //Using RFile |
|
188 return iNormalFile.Read(aDes); |
|
189 } |
|
190 } |
|
191 |
|
192 //***************************************************************************** |
|
193 TInt CJavaFile::Read(TDes8& aDes, TInt aLength) const |
|
194 { |
|
195 //JELOG4(EJVM, EEntry & EInfoHeavyLoad); |
|
196 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
197 { |
|
198 //Using CAF |
|
199 return iCafData->Read(aDes, aLength); |
|
200 } |
|
201 else |
|
202 { |
|
203 //Using RFile |
|
204 return iNormalFile.Read(aDes, aLength); |
|
205 } |
|
206 } |
|
207 |
|
208 //***************************************************************************** |
|
209 TInt CJavaFile::Replace(RFs& aFs,const TDesC& aName,TUint aFileMode) |
|
210 { |
|
211 JELOG2(EJVM); |
|
212 //Using RFile |
|
213 TInt status = iNormalFile.Replace(aFs, aName, aFileMode); |
|
214 if (status == KErrNone) |
|
215 { |
|
216 iJavaFileMode = EJavaFileOpenForNormalFile; |
|
217 } |
|
218 else |
|
219 { |
|
220 //Clean the environment just in case. |
|
221 Close(); |
|
222 } |
|
223 return status; |
|
224 } |
|
225 |
|
226 |
|
227 |
|
228 //***************************************************************************** |
|
229 TInt CJavaFile::Write(const TDesC8& aDes) |
|
230 { |
|
231 JELOG2(EJVM); |
|
232 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
233 { |
|
234 //Not supported for files accessed via CAF. |
|
235 return KErrNotSupported; |
|
236 } |
|
237 else |
|
238 { |
|
239 //Using RFile |
|
240 return iNormalFile.Write(aDes); |
|
241 } |
|
242 } |
|
243 |
|
244 //***************************************************************************** |
|
245 TInt CJavaFile::Write(const TDesC8& aDes,TInt aLength) |
|
246 { |
|
247 JELOG2(EJVM); |
|
248 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
249 { |
|
250 //Not supported for files accessed via CAF. |
|
251 return KErrNotSupported; |
|
252 } |
|
253 else |
|
254 { |
|
255 //Using RFile |
|
256 return iNormalFile.Write(aDes, aLength); |
|
257 } |
|
258 } |
|
259 |
|
260 //***************************************************************************** |
|
261 TInt CJavaFile::Write(TInt aPos,const TDesC8& aDes) |
|
262 { |
|
263 JELOG2(EJVM); |
|
264 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
265 { |
|
266 //Not supported for files accessed via CAF. |
|
267 return KErrNotSupported; |
|
268 } |
|
269 else |
|
270 { |
|
271 //Using RFile |
|
272 return iNormalFile.Write(aPos, aDes); |
|
273 } |
|
274 } |
|
275 |
|
276 //***************************************************************************** |
|
277 TInt CJavaFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) |
|
278 { |
|
279 JELOG2(EJVM); |
|
280 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
281 { |
|
282 //Not supported for files accessed via CAF. |
|
283 return KErrNotSupported; |
|
284 } |
|
285 else |
|
286 { |
|
287 //Using RFile |
|
288 return iNormalFile.Write(aPos, aDes, aLength); |
|
289 } |
|
290 } |
|
291 |
|
292 //***************************************************************************** |
|
293 TInt CJavaFile::Lock(TInt aPos, TInt aLength) const |
|
294 { |
|
295 JELOG2(EJVM); |
|
296 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
297 { |
|
298 //Not supported for files accessed via CAF. |
|
299 return KErrNotSupported; |
|
300 } |
|
301 else |
|
302 { |
|
303 //Using RFile |
|
304 return iNormalFile.Lock(aPos, aLength); |
|
305 } |
|
306 } |
|
307 |
|
308 //***************************************************************************** |
|
309 TInt CJavaFile::UnLock(TInt aPos, TInt aLength) const |
|
310 { |
|
311 JELOG2(EJVM); |
|
312 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
313 { |
|
314 //Not supported for files accessed via CAF. |
|
315 return KErrNotSupported; |
|
316 } |
|
317 else |
|
318 { |
|
319 //Using RFile |
|
320 return iNormalFile.UnLock(aPos, aLength); |
|
321 } |
|
322 } |
|
323 |
|
324 //***************************************************************************** |
|
325 TInt CJavaFile::Seek(TSeek aMode,TInt& aPos) const |
|
326 { |
|
327 // JELOG4(EJVM, EEntry & EInfoHeavyLoad); |
|
328 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
329 { |
|
330 //Using CAF |
|
331 return iCafData->Seek(aMode, aPos); |
|
332 } |
|
333 else |
|
334 { |
|
335 //Using RFile |
|
336 return iNormalFile.Seek(aMode, aPos); |
|
337 } |
|
338 } |
|
339 |
|
340 //***************************************************************************** |
|
341 TInt CJavaFile::Flush() |
|
342 { |
|
343 JELOG2(EJVM); |
|
344 if (iJavaFileMode == EJavaFileOpenForCaf) |
|
345 { |
|
346 //Not supported for files accessed via CAF. |
|
347 return KErrNotSupported; |
|
348 } |
|
349 else |
|
350 { |
|
351 //Using RFile |
|
352 return iNormalFile.Flush(); |
|
353 } |
|
354 } |
|
355 |
|
356 //***************************************************************************** |
|
357 TBool CJavaFile::isDrmFile(const TDesC& aFileName) |
|
358 { |
|
359 TParse filename; |
|
360 filename.Set(aFileName, NULL, NULL); |
|
361 TPtrC filenameExt = filename.Ext(); |
|
362 |
|
363 if (filenameExt.CompareF(_L(".dm")) == 0 || |
|
364 filenameExt.CompareF(_L(".dcf")) == 0) |
|
365 { |
|
366 // Filename extension indicates this is a DRM protected file. |
|
367 return ETrue; |
|
368 } |
|
369 |
|
370 if (filenameExt.CompareF(_L(".jar")) != 0) |
|
371 { |
|
372 // Filename extension indicates this is not a jar file, |
|
373 // assume it is not DRM protected. |
|
374 return EFalse; |
|
375 } |
|
376 |
|
377 RProcess thisProcess; |
|
378 TName thisProcessName = thisProcess.Name(); |
|
379 if (KErrNotFound == thisProcessName.FindF(_L("Installer"))) |
|
380 { |
|
381 // We are not running in JavaInstaller process, |
|
382 // do not check if file is DRM protected from CAF |
|
383 // but assume that file is not DRM protected. |
|
384 return EFalse; |
|
385 } |
|
386 |
|
387 // Check from CAF if file is DRM protected. |
|
388 TBool drmFile = EFalse; |
|
389 if (NULL == iCafContent) |
|
390 { |
|
391 TRAP_IGNORE(iCafContent = ContentAccess::CContent::NewL(aFileName)); |
|
392 if (NULL != iCafContent) |
|
393 { |
|
394 TInt value = 0; |
|
395 TInt err = iCafContent->GetAttribute( |
|
396 ContentAccess::EIsProtected, value); |
|
397 if (KErrNone == err && value) |
|
398 { |
|
399 // This is a DRM file. |
|
400 drmFile = ETrue; |
|
401 } |
|
402 else |
|
403 { |
|
404 // Not a DRM file, delete iCafContent instance. |
|
405 delete iCafContent; |
|
406 iCafContent = NULL; |
|
407 } |
|
408 } |
|
409 } |
|
410 return drmFile; |
|
411 } |
|
412 |
|
413 |
|
414 EXPORT_C void Dummy1() {} |
|
415 EXPORT_C void Dummy2() {} |
|
416 EXPORT_C void Dummy3() {} |
|
417 EXPORT_C void Dummy4() {} |
|
418 EXPORT_C void Dummy5() {} |
|
419 EXPORT_C void Dummy6() {} |
|
420 EXPORT_C void Dummy7() {} |
|
421 EXPORT_C void Dummy8() {} |
|
422 EXPORT_C void Dummy9() {} |