1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <apgcli.h> |
|
21 #include <DRMHelper.h> |
|
22 #include <bldvariant.hrh> |
|
23 #include <pathinfo.h> |
|
24 #include <ProfileEngineDomainCRKeys.h> |
|
25 #include "cphoneringingtone.h" |
|
26 #include "cphonecenrepproxy.h" |
|
27 #include "phonelogger.h" |
|
28 #include "phoneconstants.h" |
|
29 #include "phonelogger.h" |
|
30 |
|
31 // CONSTANTS |
|
32 // Rich audio file MIME types |
|
33 _LIT(KAac, "audio/aac"); |
|
34 _LIT(KMp3, "audio/mp3"); |
|
35 _LIT(KMpeg, "audio/mpeg"); |
|
36 _LIT(K3gpp, "audio/3gpp"); |
|
37 _LIT(KMp4, "audio/mp4"); |
|
38 _LIT(KAmrWb, "audio/amr-wb"); |
|
39 _LIT(KWavX, "audio/x-wav"); |
|
40 _LIT(KWav, "audio/wav"); |
|
41 |
|
42 // Rich video file MIME types |
|
43 _LIT(KV3gpp, "video/3gpp"); |
|
44 _LIT(KVMp4, "video/mp4"); |
|
45 _LIT(KV3gpp2, "video/3gpp2"); |
|
46 |
|
47 // MACROS |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CPhoneRingingTone::CPhoneRingingTone |
|
53 // C++ default constructor can NOT contain any code, that |
|
54 // might leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CPhoneRingingTone::CPhoneRingingTone( TBool aDrmInPlayback ) : |
|
58 iDrmInPlayback( aDrmInPlayback ) |
|
59 { |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CPhoneRingingTone::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CPhoneRingingTone::ConstructL( const TDesC& aFileName ) |
|
68 { |
|
69 iFileName = aFileName.AllocL(); |
|
70 |
|
71 GetMaxToneFileSize(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CPhoneRingingTone::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CPhoneRingingTone* CPhoneRingingTone::NewL( |
|
80 const TDesC& aFileName, |
|
81 TBool aDrmInPlayback ) |
|
82 { |
|
83 CPhoneRingingTone* self = new( ELeave ) CPhoneRingingTone( |
|
84 aDrmInPlayback ); |
|
85 |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL( aFileName ); |
|
88 CleanupStack::Pop( self ); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 // Destructor |
|
94 CPhoneRingingTone::~CPhoneRingingTone() |
|
95 { |
|
96 delete iFileName; |
|
97 delete iMimeType; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CPhoneRingingTone::SetFileName |
|
102 // (other items were commented in a header). |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CPhoneRingingTone::SetFileName( const TDesC& aFileName ) |
|
106 { |
|
107 delete iFileName; |
|
108 iFileName = NULL; |
|
109 iFileName = aFileName.Alloc(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CPhoneRingingTone::SetVolume |
|
114 // (other items were commented in a header). |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CPhoneRingingTone::SetVolume( const TInt aVolume ) |
|
118 { |
|
119 iVolume = aVolume; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CPhoneRingingTone::SetRingingType |
|
124 // (other items were commented in a header). |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CPhoneRingingTone::SetRingingType( TProfileRingingType aRingingType) |
|
128 { |
|
129 iRingingType = aRingingType; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CPhoneRingingTone::Volume |
|
134 // (other items were commented in a header). |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CPhoneRingingTone::Volume() const |
|
138 { |
|
139 return iVolume; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CPhoneRingingTone::RingingType |
|
144 // (other items were commented in a header). |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TProfileRingingType CPhoneRingingTone::RingingType() const |
|
148 { |
|
149 return iRingingType; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CPhoneRingingTone::FileName |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 const TDesC& CPhoneRingingTone::FileName() const |
|
158 { |
|
159 // iFileName is never NULL |
|
160 return *iFileName; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CPhoneRingingTone::SetTtsToneToBePlayed |
|
165 // (other items were commented in a header). |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CPhoneRingingTone::SetTtsToneToBePlayed( TBool aTtsToneToBePlayed ) |
|
169 { |
|
170 iTtsToneToBePlayed = aTtsToneToBePlayed; |
|
171 } |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CPhoneRingingTone::TtsToneToBePlayed |
|
174 // (other items were commented in a header). |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CPhoneRingingTone::TtsToneToBePlayed() const |
|
178 { |
|
179 |
|
180 return iTtsToneToBePlayed; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CPhoneRingingTone::MimeType |
|
185 // (other items were commented in a header). |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 const TDesC& CPhoneRingingTone::MimeType() const |
|
189 { |
|
190 if ( iMimeType ) |
|
191 { |
|
192 return *iMimeType; |
|
193 } |
|
194 else |
|
195 { |
|
196 return KNullDesC; |
|
197 } |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CPhoneRingingTone::IsVideoRingingTone |
|
202 // (other items were commented in a header). |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CPhoneRingingTone::IsVideoRingingTone() |
|
206 { |
|
207 #ifdef RD_VIDEO_AS_RINGING_TONE |
|
208 if ( RefreshMime() != KErrNone ) |
|
209 { |
|
210 // try to handle as audio |
|
211 return EFalse; |
|
212 } |
|
213 |
|
214 TBool isVideo( EFalse ); |
|
215 |
|
216 if ( iMimeType && iMimeType->MatchF( KPhoneRingingToneVideoMime ) != |
|
217 KErrNotFound ) |
|
218 { |
|
219 isVideo = ETrue; |
|
220 } |
|
221 else if ( iMimeType && iMimeType->MatchF( KPhoneRingingToneRealVideoMime ) != |
|
222 KErrNotFound ) |
|
223 { |
|
224 isVideo = ETrue; |
|
225 } |
|
226 |
|
227 if ( isVideo ) |
|
228 { |
|
229 if ( IsFileInRom() && !IsFileInVideoDirectory() ) |
|
230 { |
|
231 // For ROM files check also location, because |
|
232 // MIME check is not fully reliable. |
|
233 isVideo = EFalse; |
|
234 } |
|
235 } |
|
236 |
|
237 return isVideo; |
|
238 #else |
|
239 // if extended security -> refresh MIME |
|
240 if ( iDrmInPlayback ) |
|
241 { |
|
242 RefreshMime(); |
|
243 } |
|
244 |
|
245 return EFalse; |
|
246 #endif |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CPhoneRingingTone::IsFileDrmProtected |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 TBool CPhoneRingingTone::IsFileDrmProtected() const |
|
255 { |
|
256 const TDesC& type = MimeType(); |
|
257 |
|
258 if ( type == KAac || type == KMp3 || type == KMpeg || |
|
259 type == K3gpp || type == KMp4 || type == KAmrWb || |
|
260 type == KWavX || type == KWav || type == KV3gpp || |
|
261 type == KVMp4 || type == KV3gpp2 ) |
|
262 { |
|
263 ContentAccess::CContent* content = NULL; |
|
264 TRAPD( err, content = ContentAccess::CContent::NewL( *iFileName ) ); |
|
265 if ( err == KErrNone && content ) |
|
266 { |
|
267 TInt drmProtected( 0 ); |
|
268 content->GetAttribute( ContentAccess::EIsProtected, drmProtected ); |
|
269 delete content; |
|
270 return drmProtected; |
|
271 } |
|
272 } |
|
273 |
|
274 return ETrue; // Other MIMEs can be played without DRM check. |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CPhoneRingingTone::IsFileInRom |
|
279 // (other items were commented in a header). |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 TBool CPhoneRingingTone::IsFileInRom() const |
|
283 { |
|
284 TParsePtrC parsedName( *iFileName ); |
|
285 |
|
286 // Files on rom are not DRM checked |
|
287 if ( parsedName.Drive().CompareF( KPhoneRingingToneDriveZ ) == 0 ) |
|
288 { |
|
289 return ETrue; |
|
290 } |
|
291 else |
|
292 { |
|
293 return EFalse; |
|
294 } |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CPhoneRingingTone::IsFileInVideoDirectory |
|
299 // (other items were commented in a header). |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TBool CPhoneRingingTone::IsFileInVideoDirectory() const |
|
303 { |
|
304 TParsePtrC parsedName( *iFileName ); |
|
305 |
|
306 if ( PathInfo::PathType( parsedName.DriveAndPath() ) == |
|
307 PathInfo::EVideosPath ) |
|
308 { |
|
309 return ETrue; |
|
310 } |
|
311 else |
|
312 { |
|
313 return EFalse; |
|
314 } |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CPhoneRingingTone::RefreshMime |
|
319 // (other items were commented in a header). |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 TInt CPhoneRingingTone::RefreshMime() |
|
323 { |
|
324 TRAPD( err, RefreshMimeL() ); |
|
325 return err; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CPhoneRingingTone::RefreshMimeL |
|
330 // (other items were commented in a header). |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CPhoneRingingTone::RefreshMimeL() |
|
334 { |
|
335 RApaLsSession apaLsSession; |
|
336 User::LeaveIfError( apaLsSession.Connect() ); |
|
337 CleanupClosePushL( apaLsSession ); |
|
338 |
|
339 TUid dummyUid = { 0 }; |
|
340 TDataType dataType( dummyUid ); |
|
341 |
|
342 User::LeaveIfError( |
|
343 apaLsSession.AppForDocument( *iFileName, dummyUid, dataType ) ); |
|
344 |
|
345 CleanupStack::PopAndDestroy(); // CleanupClosePushL |
|
346 |
|
347 delete iMimeType; |
|
348 iMimeType = NULL; |
|
349 iMimeType = dataType.Des().AllocL(); |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 TBool CPhoneRingingTone::CheckAndHandleToneSizeLimit() |
|
357 { |
|
358 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtone::CheckAndHandleToneSizeLimit()" ); |
|
359 |
|
360 TBool bValidSize = ETrue; |
|
361 |
|
362 // If user has somehow managed to get a too large file as ringing tone, |
|
363 // play default tone instead. |
|
364 if ( iToneFileSizeLimitKB ) |
|
365 { |
|
366 if ( CheckToneFileSize( FileName(), iToneFileSizeLimitKB) != KErrNone ) |
|
367 { |
|
368 bValidSize = EFalse; |
|
369 } |
|
370 } |
|
371 __PHONELOG1( |
|
372 EBasic, |
|
373 EPhoneControl, |
|
374 "CPhoneRingingtone::CheckAndHandleToneSizeLimit - bValidSize(%d)", |
|
375 bValidSize); |
|
376 |
|
377 return bValidSize; |
|
378 } |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 TInt CPhoneRingingTone::CheckToneFileSize( const TDesC& aFile, |
|
384 TInt aSizeLimitKB ) |
|
385 { |
|
386 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtone::CheckToneFileSize()" ); |
|
387 //return KErrNone; |
|
388 |
|
389 // Get file size |
|
390 TInt size = 0; |
|
391 |
|
392 RFs fs; |
|
393 TInt error = fs.Connect(); |
|
394 TEntry entry; |
|
395 if ( KErrNone == error ) |
|
396 { |
|
397 if (KErrNone == fs.Entry( aFile, entry )) |
|
398 { |
|
399 size = entry.iSize; |
|
400 } |
|
401 |
|
402 // Check |
|
403 aSizeLimitKB *= Kkilo; |
|
404 if ( aSizeLimitKB && size > aSizeLimitKB ) |
|
405 { |
|
406 error = KErrTooBig; |
|
407 } |
|
408 } |
|
409 |
|
410 fs.Close(); |
|
411 __PHONELOG1( |
|
412 EBasic, |
|
413 EPhoneControl, |
|
414 "CPhoneRingingtonePlayer::CheckToneFileSize - size (%d)", |
|
415 size ); |
|
416 return error; |
|
417 |
|
418 } |
|
419 |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CPhoneRingingTone::GetMaxToneFileSize() |
|
426 { |
|
427 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtone::GetMaxToneFileSize()" ); |
|
428 |
|
429 TInt error(KErrNone); |
|
430 iToneFileSizeLimitKB = 5000; |
|
431 |
|
432 if ( error != KErrNone ) |
|
433 { |
|
434 iToneFileSizeLimitKB = 0; |
|
435 } |
|
436 if ( iToneFileSizeLimitKB < 0 ) |
|
437 { |
|
438 iToneFileSizeLimitKB = 0; |
|
439 } |
|
440 |
|
441 __PHONELOG2( |
|
442 EBasic, |
|
443 EPhoneControl, |
|
444 "CPhoneRingingtonePlayer::GetMaxToneFileSize - error (%d), aMaxSizeKB(%d)", |
|
445 error, |
|
446 iToneFileSizeLimitKB ); |
|
447 } |
|
448 |
|
449 // End of File |
|