[0.6.46] Apply blocking policy 20/127720/4
authorEunhae Choi <eunhae1.choi@samsung.com>
Fri, 28 Apr 2017 10:36:39 +0000 (19:36 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Mon, 8 May 2017 08:26:37 +0000 (17:26 +0900)
If application uses media session with MIX_WITH_OTHERS option and other process
has already acquired a focus which has more higher priority than media, an error
will be returned from this function.

Change-Id: I6816fd19ef0c328942cf79e2076b4bb67875b1e9

packaging/libmm-player.spec
src/mm_player_sound_focus.c

index 6a6e06d..ee9f29d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.45
+Version:    0.6.46
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 5088a76..bdba869 100644 (file)
@@ -117,6 +117,25 @@ __mmplayer_sound_get_stream_type(gint type)
        return "media";
 }
 
+static bool
+__mmplayer_check_need_block(const char *focus_acquired_by)
+{
+    if (!focus_acquired_by)
+        return false;
+
+    if (!strcmp(focus_acquired_by, "alarm") ||
+        !strcmp(focus_acquired_by, "ringtone-voip") ||
+        !strcmp(focus_acquired_by, "ringtone-call") ||
+        !strcmp(focus_acquired_by, "voip") ||
+        !strcmp(focus_acquired_by, "call-voice") ||
+        !strcmp(focus_acquired_by, "call-video")) {
+        LOGW("Blocked by session policy, focus_acquired_by[%s]", focus_acquired_by);
+        return true;
+    }
+
+    return false;
+}
+
 int
 _mmplayer_sound_acquire_focus(MMPlayerSoundFocus* sound_focus)
 {
@@ -134,7 +153,7 @@ _mmplayer_sound_acquire_focus(MMPlayerSoundFocus* sound_focus)
 
                ret = mm_sound_acquire_focus(sound_focus->focus_id, FOCUS_FOR_BOTH, "mm-player acquire focus");
                if (ret != MM_ERROR_NONE) {
-                       LOGE("failed to acquire sound focus\n");
+                       LOGE("failed to acquire sound focus [0x%X]", ret);
                        return ret;
                }
 
@@ -142,7 +161,29 @@ _mmplayer_sound_acquire_focus(MMPlayerSoundFocus* sound_focus)
 
                ret = mm_sound_update_focus_status(sound_focus->focus_id, 1);
                if (ret != MM_ERROR_NONE)
-                       LOGE("failed to update focus status\n");
+                       LOGE("failed to update focus status [0x%X]", ret);
+       } else {
+               if (sound_focus->watch_id > 0) {
+                       char *stream_type = NULL;
+                       char *ext_info = NULL;
+                       int option = 0;
+
+                       ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info);
+                       if (ret == MM_ERROR_NONE) {
+                               LOGD("Focus is acquired by stream_type[%s], option[%d], ext_info[%s]", stream_type, option, ext_info);
+                               if (__mmplayer_check_need_block((const char*)stream_type)) {
+                                       LOGE("Blocked by an acquired focus[%s]", stream_type);
+                                       ret = MM_ERROR_POLICY_INTERNAL;
+                               }
+                       } else {
+                               LOGW("failed to get stream type of acquired focus [0x%X]", ret);
+                               if (ret == MM_ERROR_SOUND_NO_DATA) /* there is no acquired focus, it is normal case */
+                                       ret = MM_ERROR_NONE;
+                       }
+
+                       if (stream_type) free(stream_type);
+                       if (ext_info) free(ext_info);
+               }
        }
 
        MMPLAYER_FLEAVE();