Bug 1090919 - Fix audio problem when mediaserver is restarted. r=mwu
authorDaniel Bonnevier <daniel.bonnevier@sonymobile.com>
Fri, 14 Nov 2014 06:12:00 +0100
changeset 216886 48a024873cbca590c16e325bf45edc64a912471b
parent 216885 2513d21bbff2bfdca66e7fd6eab236e5aba25445
child 216887 aa46b3ca0f9f507db37215265d9a8d10dfacb003
push id10102
push userkwierso@gmail.com
push dateSat, 22 Nov 2014 00:56:43 +0000
treeherderfx-team@9bc239136a6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs1090919
milestone36.0a1
Bug 1090919 - Fix audio problem when mediaserver is restarted. r=mwu When mediaserver is restarted AudioPolicyService needs to be recreated when mediasrever is fully started.
dom/system/gonk/AudioManager.cpp
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -10,16 +10,17 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 #include <android/log.h>
 #include <cutils/properties.h>
+#include <binder/IServiceManager.h>
 
 #include "AudioChannelService.h"
 #include "AudioManager.h"
 
 #include "nsIObserverService.h"
 #ifdef MOZ_B2G_RIL
 #include "nsIRadioInterfaceLayer.h"
 #endif
@@ -54,16 +55,17 @@ using namespace mozilla::dom::bluetooth;
 
 #define HEADPHONES_STATUS_HEADSET     MOZ_UTF16("headset")
 #define HEADPHONES_STATUS_HEADPHONE   MOZ_UTF16("headphone")
 #define HEADPHONES_STATUS_OFF         MOZ_UTF16("off")
 #define HEADPHONES_STATUS_UNKNOWN     MOZ_UTF16("unknown")
 #define HEADPHONES_STATUS_CHANGED     "headphones-status-changed"
 #define MOZ_SETTINGS_CHANGE_ID        "mozsettings-changed"
 #define AUDIO_CHANNEL_PROCESS_CHANGED "audio-channel-process-changed"
+#define AUDIO_POLICY_SERVICE_NAME     "media.audio_policy"
 
 static void BinderDeadCallback(status_t aErr);
 static void InternalSetAudioRoutes(SwitchState aState);
 // Refer AudioService.java from Android
 static int sMaxStreamVolumeTbl[AUDIO_STREAM_CNT] = {
   5,   // voice call
   15,  // system
   15,  // ring
@@ -89,16 +91,29 @@ namespace gonk {
 class RecoverTask : public nsRunnable
 {
 public:
   RecoverTask() {}
   NS_IMETHODIMP Run() {
     nsCOMPtr<nsIAudioManager> amService = do_GetService(NS_AUDIOMANAGER_CONTRACTID);
     NS_ENSURE_TRUE(amService, NS_OK);
     AudioManager *am = static_cast<AudioManager *>(amService.get());
+
+    int attempt;
+    for (attempt = 0; attempt < 50; attempt++) {
+      if (defaultServiceManager()->checkService(String16(AUDIO_POLICY_SERVICE_NAME)) != 0) {
+        break;
+      }
+
+      LOG("AudioPolicyService is dead! attempt=%d", attempt);
+      usleep(1000 * 200);
+    }
+
+    MOZ_RELEASE_ASSERT(attempt < 50);
+
     for (int loop = 0; loop < AUDIO_STREAM_CNT; loop++) {
       AudioSystem::initStreamVolume(static_cast<audio_stream_type_t>(loop), 0,
                                    sMaxStreamVolumeTbl[loop]);
       int32_t index;
       am->GetStreamVolumeIndex(loop, &index);
       am->SetStreamVolumeIndex(loop, index);
     }