Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f9d814d authored by Oscar Azucena's avatar Oscar Azucena
Browse files

Fixed device info reporting for media player

Fixed issue relating to audio device information reporting to audio
playback configuration. The self routing listener is registered during
play start and temporarily remove during stop. Also fixed issue where
removing the last audio routing change listener would stop the media
player from further reporting device changes to audio playback
configuration monitor.

Test: atest AudioPlaybackConfigurationTest --rerun-until-failure 100
Bug: 179218630
Change-Id: Iec60b0a2baa6c90aa1e250a66f00675fe9fc6d9d
parent 39ceb7f3
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -3526,8 +3526,9 @@ public class AudioTrack extends PlayerBase
                native_enableDeviceCallback();
                return true;
            } catch (IllegalStateException e) {
                // Fail silently as track state could have changed in between start
                // and enabling routing callback, return false to indicate not enabled
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "testEnableNativeRoutingCallbacks failed", e);
                }
            }
        }
        return false;
@@ -3577,7 +3578,7 @@ public class AudioTrack extends PlayerBase
            Handler handler) {
        synchronized (mRoutingChangeListeners) {
            if (listener != null && !mRoutingChangeListeners.containsKey(listener)) {
                testEnableNativeRoutingCallbacksLocked();
                mEnableSelfRoutingMonitor = testEnableNativeRoutingCallbacksLocked();
                mRoutingChangeListeners.put(
                        listener, new NativeRoutingEventHandlerDelegate(this, listener,
                                handler != null ? handler : new Handler(mInitializationLooper)));
+6 −15
Original line number Diff line number Diff line
@@ -1358,6 +1358,7 @@ public class MediaPlayer extends PlayerBase
    private void startImpl() {
        baseStart(0); // unknown device at this point
        stayAwake(true);
        tryToEnableNativeRoutingCallback();
        _start();
    }

@@ -1383,6 +1384,7 @@ public class MediaPlayer extends PlayerBase
        stayAwake(false);
        _stop();
        baseStop();
        tryToDisableNativeRoutingCallback();
    }

    private native void _stop() throws IllegalStateException;
@@ -1524,8 +1526,9 @@ public class MediaPlayer extends PlayerBase
                native_enableDeviceCallback(true);
                return true;
            } catch (IllegalStateException e) {
                // Fail silently as media player state could have changed in between start
                // and enabling routing callback, return false to indicate not enabled
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "testEnableNativeRoutingCallbacks failed", e);
                }
            }
        }
        return false;
@@ -1588,7 +1591,7 @@ public class MediaPlayer extends PlayerBase
            Handler handler) {
        synchronized (mRoutingChangeListeners) {
            if (listener != null && !mRoutingChangeListeners.containsKey(listener)) {
                testEnableNativeRoutingCallbacksLocked();
                mEnableSelfRoutingMonitor = testEnableNativeRoutingCallbacksLocked();
                mRoutingChangeListeners.put(
                        listener, new NativeRoutingEventHandlerDelegate(this, listener,
                                handler != null ? handler : mEventHandler));
@@ -3481,9 +3484,6 @@ public class MediaPlayer extends PlayerBase

            case MEDIA_STOPPED:
                {
                    tryToDisableNativeRoutingCallback();
                    // FIXME see b/179218630
                    //baseStop();
                    TimeProvider timeProvider = mTimeProvider;
                    if (timeProvider != null) {
                        timeProvider.onStopped();
@@ -3492,18 +3492,9 @@ public class MediaPlayer extends PlayerBase
                break;

            case MEDIA_STARTED:
                {
                    // FIXME see b/179218630
                    //baseStart(native_getRoutedDeviceId());
                    tryToEnableNativeRoutingCallback();
                }
                // fall through
            case MEDIA_PAUSED:
                {
                    // FIXME see b/179218630
                    //if (msg.what == MEDIA_PAUSED) {
                    //    basePause();
                    //}
                    TimeProvider timeProvider = mTimeProvider;
                    if (timeProvider != null) {
                        timeProvider.onPaused(msg.what == MEDIA_PAUSED);