Remove SMACK rule file(.rule) according three domain model
[apps/core/preloaded/video-player.git] / src / mp-video-service-ctrl.c
1 /*
2  * Copyright (c) [2012] Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <app.h>
19 #include <aul.h>
20 #include <glib.h>
21
22 #include "mp-util.h"
23 #include "mp-video-log.h"
24 #include "mp-video-service-ctrl.h"
25
26
27 #define MP_VIDEO_LAUNCHED_BY_APP_KEY            "launching_application"
28 #define MP_VIDEO_SORT_TYPE_KEY                          "order_type"
29 #define MP_VIDEO_LIST_TYPE_KEY                          "video_list_type"
30 #define MP_VIDEO_TAG_NAME_KEY                           "tag_name"
31 #define MP_VIDEO_EDIT_MODE_KEY                          "edit_mode"
32 #define MP_VIDEO_START_POS_TIME_KEY                     "start_pos_time"
33 #define MP_VIDEO_URI_PATH                                       "path"
34 #define MP_VIDEO_COOKIE                                         "cookie"
35 #define MP_VIDEO_MULTI_WIN_TYPE_KEY                     "is_multi_win_type"
36 #define MP_VIDEO_LAUNCH_TYPE                            "launch-type"
37 #define MP_VIDEO_SHORTCUT_VIDEO                         "shortcut-videoplayer"
38
39 static service_h pAppSvcHandle = NULL;
40 static int nPlayerType = MP_NONE_VIEW_TYPE;
41 static int nPrevPlayerType = MP_NONE_VIEW_TYPE;
42 static int nGalleryLatestTime = 0;
43 static char *g_szStreamingCookie = NULL;
44 static bool bIsShortcutType = FALSE;
45
46
47 /////////////////////////////////////////////////////////////////////////////
48 // Internal Function
49
50 bool MpVideoServiceCtrlCheckMime(service_h pVideoServiceHandle, char **szMediaUri)
51 {
52         VideoLogInfo("");
53
54         if(!pVideoServiceHandle)
55         {
56                 VideoLogInfo("[ERR] No Exist Service handle.");
57                 return FALSE;
58         }
59
60         bool bRet = TRUE;
61         char *szMimeContent = NULL;
62
63         if(service_get_extra_data(pVideoServiceHandle, AUL_K_MIME_CONTENT, &szMimeContent) != SERVICE_ERROR_NONE)
64         {
65                 VideoLogInfo("No exist mime type.");
66                 bRet = FALSE;
67         }
68
69         if(szMimeContent)
70         {
71                 *szMediaUri = (char*)malloc(strlen(szMimeContent) + 1);
72                 memset(*szMediaUri, 0, strlen(szMimeContent) + 1);
73                 strncpy(*szMediaUri, szMimeContent, strlen(szMimeContent));
74                 VideoLogInfo("Mime content : %s", *szMediaUri);
75                 free(szMimeContent);
76                 bRet = TRUE;
77         }
78         else
79         {
80                 VideoLogInfo("No exist MIME type.");
81                 bRet = FALSE;
82         }
83
84         return bRet;
85 }
86
87 bool MpVideoServiceCtrlCheckBundle(service_h pVideoServiceHandle, char **szMediaUri)
88 {
89         if(!pVideoServiceHandle)
90         {
91                 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
92                 return FALSE;
93         }
94
95         bool bRet = TRUE;
96         char *szStrVideoURI = NULL;
97
98         if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_URI_PATH, &szStrVideoURI) != SERVICE_ERROR_NONE)
99         {
100                 VideoLogInfo("No exist KEY of video/streaming URI.");
101                 bRet = FALSE;
102                 return bRet;
103         }
104
105         if(szStrVideoURI)
106         {
107                 *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
108                 memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
109                 strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
110                 VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
111                 free(szStrVideoURI);
112                 szStrVideoURI = NULL;
113                 bRet = TRUE;
114         }
115         else
116         {
117                 VideoLogInfo("No exist video/streaming URI.");
118                 bRet = FALSE;
119         }
120
121         return bRet;
122 }
123
124 bool MpVideoServiceCtrlCheckAUL(service_h pVideoServiceHandle, char **szMediaUri)
125 {
126         if(!pVideoServiceHandle)
127         {
128                 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
129                 return FALSE;
130         }
131
132
133         char *pGetOperation = NULL;
134
135         service_get_operation(pVideoServiceHandle, &pGetOperation);
136
137         if(pGetOperation == NULL)
138         {
139                 return FALSE;
140         }
141
142         if(!strcmp(SERVICE_OPERATION_VIEW , pGetOperation))
143         {
144                 char *szStrVideoURI = NULL;
145
146                 service_get_uri(pVideoServiceHandle, &szStrVideoURI);
147
148                 if(szStrVideoURI)
149                 {
150                         *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
151                         memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
152                         strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
153                         VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
154                         free(szStrVideoURI);
155                         szStrVideoURI = NULL;
156                 }
157                 else
158                 {
159                         VideoLogInfo("[ERR] No exist video/streaming URI.");
160
161                         if(pGetOperation)
162                         {
163                                 free(pGetOperation);
164                                 pGetOperation = NULL;
165                         }
166
167                         return FALSE;
168                 }
169         }
170         else
171         {
172                 VideoLogInfo("No exist Operation.");
173
174                 if(pGetOperation)
175                 {
176                         free(pGetOperation);
177                         pGetOperation = NULL;
178                 }
179
180                 return FALSE;
181         }
182
183         VideoLogInfo("Video/Streaming URI path pAppData->szMediaUri : %s", *szMediaUri);
184
185         if(pGetOperation)
186         {
187         free(pGetOperation);
188                 pGetOperation = NULL;
189         }
190
191         return TRUE;
192 }
193
194
195 bool MpVideoServiceCtrlParseUri(service_h pVideoServiceHandle, char** szMediaUri)
196 {
197         VideoLogInfo("");
198
199         if(!MpVideoServiceCtrlCheckMime(pVideoServiceHandle, szMediaUri))
200         {
201                 if(!MpVideoServiceCtrlCheckBundle(pVideoServiceHandle, szMediaUri))
202                 {
203                         if(!MpVideoServiceCtrlCheckAUL(pVideoServiceHandle, szMediaUri))
204                         {
205                                 VideoLogInfo("No exist URI path.");
206                                 return FALSE;
207                         }
208                 }
209         }
210
211         VideoLogInfo("szMediaUri : %s", *szMediaUri);
212
213         return TRUE;
214 }
215
216 int MpVideoServiceCtrlCheckUriType(char* szMediaUri)
217 {
218         if(!szMediaUri)
219         {
220                 VideoLogInfo("[ERR] No exist media uri.");
221                 return MP_ERROR_PLAYER_TYPE;
222         }
223
224         VideoLogInfo("");
225
226         int nRet = 0;
227
228         if(MpUtilCheckUriType(szMediaUri))
229                 {
230                         VideoLogInfo("MP_STREAMING_PLAYER");
231                         nRet = MP_STREAMING_PLAYER;
232                 }
233                 else
234                 {
235                         VideoLogInfo("MP_VIDEO_PLAYER");
236                         nRet = MP_VIDEO_PLAYER;
237                 }
238
239         return nRet;
240 }
241
242 bool MpVideoServiceCtrlCheckCookieForStreaming(service_h pVideoServiceHandle)
243 {
244         if(!pVideoServiceHandle)
245         {
246                 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
247                 return FALSE;
248         }
249
250         bool bRet = TRUE;
251         char *pStrVideoCookie = NULL;
252
253         if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_COOKIE, &pStrVideoCookie) != SERVICE_ERROR_NONE)
254         {
255                 VideoLogInfo("[ERR] No exist KEY of streaming COOKIE.");
256                 bRet = FALSE;
257         }
258
259         if(pStrVideoCookie)
260         {
261                 g_szStreamingCookie = (char*)malloc(strlen(pStrVideoCookie) + 1);
262                 memset(g_szStreamingCookie, 0, strlen(pStrVideoCookie) + 1);
263                 strncpy(g_szStreamingCookie, pStrVideoCookie, strlen(pStrVideoCookie));
264                 VideoLogInfo("Video/Streaming URI path Cookie : %s", g_szStreamingCookie);
265                 free(pStrVideoCookie);
266         }
267         else
268         {
269                 VideoLogInfo("[ERR] No exist video/streaming URI.");
270                 bRet = FALSE;
271         }
272
273         return TRUE;
274 }
275
276 int MpVideoServiceCtrlCheckStartPositionTime(service_h pVideoServiceHandle, char *szBundleKey)
277 {
278         VideoLogInfo("");
279
280         if(!pVideoServiceHandle)
281         {
282                 VideoLogInfo("No exist Service handle data.");
283                 return 0;
284         }
285
286         int nStartPositionTime = 0;
287         char *szStartPosTime = NULL;
288
289         if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szStartPosTime) != SERVICE_ERROR_NONE)
290         {
291                 VideoLogInfo("No exist mime type.");
292                 return 0;
293         }
294
295         if(!szStartPosTime)
296         {
297                 VideoLogInfo("No exist pointer of position time.");
298                 return 0;
299         }
300
301         nStartPositionTime = atoi(szStartPosTime);
302
303         VideoLogInfo("Start position time : %d", nStartPositionTime);
304
305         free(szStartPosTime);
306
307         if(nStartPositionTime < 0)
308         {
309                 nStartPositionTime = 0;
310         }
311
312         return nStartPositionTime;
313 }
314
315 bool MpVideoServiceCtrlGetTagNameOfGallery(service_h pVideoServiceHandle, char *szBundleKey, char *szTagName)
316 {
317         VideoLogInfo("");
318
319         if(!pVideoServiceHandle)
320         {
321                 VideoLogInfo("No exist Service handle.");
322                 return FALSE;
323         }
324
325         if(!szBundleKey)
326         {
327                 VideoLogInfo("No exist Service handle kay.");
328                 return FALSE;
329         }
330
331         if(!szTagName)
332         {
333                 VideoLogInfo("No exist pAppData.");
334                 return FALSE;
335         }
336
337         bool nRet = TRUE;
338         char *szVideoTagName = NULL;
339
340         if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szVideoTagName) != SERVICE_ERROR_NONE)
341         {
342                 VideoLogInfo("No exist mime type.");
343                 nRet = FALSE;
344         }
345
346         if(szVideoTagName)
347         {
348                 strncpy(szTagName, szVideoTagName, STR_LEN_MAX - 1);
349                 VideoLogInfo("szTagName : %s", szTagName);
350                 free(szVideoTagName);
351                 nRet = TRUE;
352         }
353         else
354         {
355                 VideoLogInfo("No exist pointer of szVideoTagName.");
356                 nRet = FALSE;
357         }
358
359         return nRet;
360 }
361
362 int MpVideoServiceCtrlCheckLauncher(service_h pVideoServiceHandle)
363 {
364         VideoLogInfo("");
365
366         if(!pVideoServiceHandle)
367         {
368                 VideoLogInfo("No exist Service handle data.");
369                 return MP_VIDEO_PLAYER_SIMPLE;
370         }
371
372         char *szLaunchingByOtherApp = NULL;
373
374         if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCHED_BY_APP_KEY, &szLaunchingByOtherApp) != SERVICE_ERROR_NONE)
375         {
376                 VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
377                 return MP_VIDEO_PLAYER_SIMPLE;
378         }
379
380         if(!szLaunchingByOtherApp)
381         {
382                 VideoLogInfo("No exist pointer of szLaunchingByOtherApp");
383                 return MP_VIDEO_PLAYER_SIMPLE;
384         }
385
386         MpPlayerViewType nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
387
388         if(!strcmp(szLaunchingByOtherApp, "gallery"))
389         {
390                 nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
391
392                 nGalleryLatestTime = MpVideoServiceCtrlCheckStartPositionTime(pVideoServiceHandle, MP_VIDEO_START_POS_TIME_KEY);
393         }
394         else if(!strcmp(szLaunchingByOtherApp, "image_viewer"))
395         {
396                         nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
397                 }
398         else if(!strcmp(szLaunchingByOtherApp, "email"))
399         {
400                 nTmpLaunchingAppType = MP_VIDEO_PLAYER_EMAIL;
401         }
402         else if(!strcmp(szLaunchingByOtherApp, "message"))
403         {
404                 nTmpLaunchingAppType = MP_VIDEO_PLAYER_MMS;
405         }
406         else if(!strcmp(szLaunchingByOtherApp, "light_play_view"))
407         {
408                 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
409         }
410         else
411         {
412                 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
413         }
414
415         VideoLogInfo("Start position time : %d", nTmpLaunchingAppType);
416
417         free(szLaunchingByOtherApp);
418
419         return (int)nTmpLaunchingAppType;
420 }
421
422 bool MpVideoServiceCtrlCheckShortcut(service_h pVideoServiceHandle)
423 {
424         if(!pVideoServiceHandle)
425         {
426                 VideoLogInfo("No exist Service handle.");
427                 return FALSE;
428         }
429
430         VideoLogInfo("");
431
432         char *pGetOperation = NULL;
433
434         service_get_operation(pVideoServiceHandle, &pGetOperation);
435
436         if(pGetOperation == NULL)
437         {
438                 bIsShortcutType = FALSE;
439                 return bIsShortcutType;
440         }
441
442         if(!strcmp(pGetOperation, SERVICE_OPERATION_DEFAULT))
443         {
444                 char *szOperationType = NULL;
445
446                 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCH_TYPE, &szOperationType) != SERVICE_ERROR_NONE)
447                 {
448                         VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
449                         bIsShortcutType = FALSE;
450                 }
451
452                 if(!szOperationType)
453                 {
454                         VideoLogInfo("No exist pointer of szOperationType");
455                         bIsShortcutType = FALSE;
456                 }
457                 else
458                 {
459                         if(!strcmp(szOperationType, MP_VIDEO_SHORTCUT_VIDEO))
460                         {
461                                 bIsShortcutType = TRUE;
462                         }
463                         else
464                         {
465                                 bIsShortcutType = FALSE;
466                         }
467
468                         if(szOperationType)
469                         {
470                                 free(szOperationType);
471                                 szOperationType = NULL;
472                         }
473                 }
474         }
475
476         return bIsShortcutType;
477 }
478
479
480
481 /////////////////////////////////////////////////////////////////////////////
482 // External Function
483
484 void MpVideoServiceCtrlReset(void)
485 {
486         VideoLogInfo("");
487
488         pAppSvcHandle = NULL;
489
490         nGalleryLatestTime = 0;
491
492         if(g_szStreamingCookie)
493         {
494                 free(g_szStreamingCookie);
495                 g_szStreamingCookie = NULL;
496         }
497 }
498
499 int MpVideoServiceCtrlInitServiceParser(void* pAppServiceHandle, char** szMediaUri)
500 {
501         if(!pAppServiceHandle)
502         {
503                 VideoLogInfo("");
504                 return MP_ERROR_PLAYER_TYPE;
505         }
506
507         VideoLogInfo("");
508
509         MpVideoServiceCtrlReset();
510
511         pAppSvcHandle = (service_h)pAppServiceHandle;
512         nPlayerType = MP_NONE_VIEW_TYPE;
513
514         if(!MpVideoServiceCtrlParseUri(pAppSvcHandle, szMediaUri))
515         {
516                 VideoLogInfo("MP_VIDEO_PLAYER_LIST");
517                 nPlayerType = MP_VIDEO_PLAYER;
518         }
519
520         if(!*szMediaUri)
521                 {
522                         return nPlayerType;
523                 }
524         else
525         {
526                 VideoLogInfo("szMediaUri : %s", *szMediaUri);
527         }
528
529         int nUriType = 0;
530
531         nUriType = MpVideoServiceCtrlCheckUriType(*szMediaUri);
532
533         if(nUriType == MP_VIDEO_PLAYER)
534                 {
535                         nPlayerType = MpVideoServiceCtrlCheckLauncher(pAppSvcHandle);
536                 }
537
538         if(nUriType == MP_STREAMING_PLAYER)
539                 {
540                         nPlayerType = MP_STREAMING_PLAYER;
541                 MpVideoServiceCtrlCheckCookieForStreaming(pAppSvcHandle);
542                 }
543
544         return nPlayerType;
545                 }
546
547 int MpVideoServiceCtrlGetLatestTime(void)
548 {
549         VideoLogInfo("");
550
551         if(nGalleryLatestTime < 0)
552         {
553                 nGalleryLatestTime = 0;
554         }
555
556         return nGalleryLatestTime;
557 }
558
559 int MpVideoServiceCtrlGetPlayerTypeWithoutLog(void)
560 {
561         if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
562         {
563                 nPlayerType = MP_ERROR_PLAYER_TYPE;
564         }
565
566         return nPlayerType;
567 }
568
569 int MpVideoServiceCtrlGetPlayerType(void)
570 {
571         VideoLogInfo("");
572
573         if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
574         {
575                 nPlayerType = MP_ERROR_PLAYER_TYPE;
576         }
577
578         VideoLogInfo("nPlayerType : %d", nPlayerType);
579
580         return nPlayerType;
581 }
582
583 void MpVideoServiceCtrlSetPlayerType(int nSetPlayerType)
584 {
585         VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
586
587         if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
588         {
589                 MpVideoServiceCtrlSetPrevPlayerType(nPlayerType);
590                 nPlayerType = nSetPlayerType;
591         }
592 }
593
594 int MpVideoServiceCtrlGetPrevPlayerType(void)
595 {
596         VideoLogInfo("");
597
598         if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
599         {
600                 nPrevPlayerType = MP_ERROR_PLAYER_TYPE;
601         }
602
603         VideoLogInfo("nPrevPlayerType : %d", nPrevPlayerType);
604
605         return nPrevPlayerType;
606 }
607
608 void MpVideoServiceCtrlSetPrevPlayerType(int nSetPlayerType)
609 {
610         VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
611
612         if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
613         {
614                 nPrevPlayerType = nSetPlayerType;
615         }
616 }
617
618 char* MpVideoServiceCtrlGetCookieForStreaming(void)
619 {
620         VideoLogInfo("");
621
622         if(!g_szStreamingCookie)
623         {
624                 VideoLogInfo("No exist streaming cookie.");
625                 return NULL;
626         }
627
628         return g_szStreamingCookie;
629 }