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