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

Commit 430fc488 authored by RoboErik's avatar RoboErik
Browse files

Work on removing non-session media routing code

Change-Id: I73e7d22f2f8772c7b07ccf32d962161d79d5db74
parent 113af3e5
Loading
Loading
Loading
Loading
+17 −93
Original line number Diff line number Diff line
@@ -50,12 +50,6 @@ import java.util.ArrayList;
 */
public class AudioManager {

    // If we should use the new sessions APIs.
    private final static boolean USE_SESSIONS = true;
    // If we should use the legacy APIs. If both are true information will be
    // duplicated through both paths. Currently this flag isn't used.
    private final static boolean USE_LEGACY = true;

    private final Context mContext;
    private long mVolumeKeyUpTime;
    private final boolean mUseMasterVolume;
@@ -483,17 +477,8 @@ public class AudioManager {
     *     or {@link KeyEvent#KEYCODE_MEDIA_AUDIO_TRACK}.
     */
    public void dispatchMediaKeyEvent(KeyEvent keyEvent) {
        if (USE_SESSIONS) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
        helper.sendMediaButtonEvent(keyEvent, false);
        } else {
            IAudioService service = getService();
            try {
                service.dispatchMediaKeyEvent(keyEvent);
            } catch (RemoteException e) {
                Log.e(TAG, "dispatchMediaKeyEvent threw exception ", e);
            }
        }
    }

    /**
@@ -644,12 +629,8 @@ public class AudioManager {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags);
                } else {
                    service.adjustVolume(direction, flags, mContext.getOpPackageName());
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustVolume", e);
@@ -679,13 +660,8 @@ public class AudioManager {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags);
                } else {
                    service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags,
                            mContext.getOpPackageName());
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e);
@@ -2215,17 +2191,16 @@ public class AudioManager {
        }
        IAudioService service = getService();
        try {
            // pi != null
            // pi != null, this is currently still needed to support across
            // reboot launching of the last app.
            service.registerMediaButtonIntent(pi, eventReceiver,
                    eventReceiver == null ? mToken : null);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in registerMediaButtonIntent"+e);
        }
        if (USE_SESSIONS) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
        helper.addMediaButtonListener(pi, mContext);
    }
    }

    /**
     * @hide
@@ -2298,11 +2273,9 @@ public class AudioManager {
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in unregisterMediaButtonIntent"+e);
        }
        if (USE_SESSIONS) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
        helper.removeMediaButtonListener(pi);
    }
    }

    /**
     * Registers the remote control client for providing information to display on the remote
@@ -2315,21 +2288,8 @@ public class AudioManager {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
        }
        IAudioService service = getService();
        try {
            int rcseId = service.registerRemoteControlClient(
                    rcClient.getRcMediaIntent(),       /* mediaIntent   */
                    rcClient.getIRemoteControlClient(),/* rcClient      */
                    // used to match media button event receiver and audio focus
                    mContext.getPackageName());        /* packageName   */
            rcClient.setRcseId(rcseId);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in registerRemoteControlClient"+e);
        }
        if (USE_SESSIONS) {
        rcClient.registerWithSession(MediaSessionLegacyHelper.getHelper(mContext));
    }
    }

    /**
     * Unregisters the remote control client that was providing information to display on the
@@ -2341,17 +2301,8 @@ public class AudioManager {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
        }
        IAudioService service = getService();
        try {
            service.unregisterRemoteControlClient(rcClient.getRcMediaIntent(), /* mediaIntent   */
                    rcClient.getIRemoteControlClient());                       /* rcClient      */
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in unregisterRemoteControlClient"+e);
        }
        if (USE_SESSIONS) {
        rcClient.unregisterWithSession(MediaSessionLegacyHelper.getHelper(mContext));
    }
    }

    /**
     * Registers a {@link RemoteController} instance for it to receive media metadata updates
@@ -2368,25 +2319,8 @@ public class AudioManager {
        if (rctlr == null) {
            return false;
        }
        if (USE_SESSIONS) {
        rctlr.startListeningToSessions();
        return true;
        } else {
            IAudioService service = getService();
            final RemoteController.OnClientUpdateListener l = rctlr.getUpdateListener();
            final ComponentName listenerComponent = new ComponentName(mContext, l.getClass());
            try {
                int[] artworkDimensions = rctlr.getArtworkSize();
                boolean reg = service.registerRemoteController(rctlr.getRcDisplay(),
                        artworkDimensions[0]/* w */, artworkDimensions[1]/* h */,
                        listenerComponent);
                rctlr.setIsRegistered(reg);
                return reg;
            } catch (RemoteException e) {
                Log.e(TAG, "Dead object in registerRemoteController " + e);
                return false;
            }
        }
    }

    /**
@@ -2398,17 +2332,7 @@ public class AudioManager {
        if (rctlr == null) {
            return;
        }
        if (USE_SESSIONS) {
        rctlr.stopListeningToSessions();
        } else {
            IAudioService service = getService();
            try {
                service.unregisterRemoteControlDisplay(rctlr.getRcDisplay());
                rctlr.setIsRegistered(false);
            } catch (RemoteException e) {
                Log.e(TAG, "Dead object in unregisterRemoteControlDisplay " + e);
            }
        }
    }

    /**
+9 −18
Original line number Diff line number Diff line
@@ -108,8 +108,7 @@ public class AudioService extends IAudioService.Stub {
    /** Debug volumes */
    protected static final boolean DEBUG_VOL = false;

    /** Reroute calls to media session apis */
    private static final boolean USE_SESSIONS = true;
    /** debug calls to media session apis */
    private static final boolean DEBUG_SESSIONS = true;

    /** Allow volume changes to set ringer mode to silent? */
@@ -4484,27 +4483,19 @@ public class AudioService extends IAudioService.Stub {
    }

    public void dispatchMediaKeyEvent(KeyEvent keyEvent) {
        if (USE_SESSIONS) {
        if (DEBUG_SESSIONS) {
            int pid = getCallingPid();
            Log.w(TAG, "Call to dispatchMediaKeyEvent from " + pid);
        }
        MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false);
        } else {
            mMediaFocusControl.dispatchMediaKeyEvent(keyEvent);
        }
    }

    public void dispatchMediaKeyEventUnderWakelock(KeyEvent keyEvent) {
        if (USE_SESSIONS) {
        if (DEBUG_SESSIONS) {
            int pid = getCallingPid();
            Log.w(TAG, "Call to dispatchMediaKeyEventUnderWakelock from " + pid);
        }
        MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, true);
        } else {
            mMediaFocusControl.dispatchMediaKeyEventUnderWakelock(keyEvent);
        }
    }

    //==========================================================================================
+7 −59
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class MediaRouter {
    private static final String TAG = "MediaRouter";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean USE_SESSIONS = true;

    static class Static implements DisplayManager.DisplayListener {
        final Context mAppContext;
@@ -2104,11 +2103,7 @@ public class MediaRouter {
        public void setPlaybackType(int type) {
            if (mPlaybackType != type) {
                mPlaybackType = type;
                if (USE_SESSIONS) {
                configureSessionVolume();
                } else {
                    setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE, type);
                }
            }
        }

@@ -2121,12 +2116,7 @@ public class MediaRouter {
        public void setVolumeHandling(int volumeHandling) {
            if (mVolumeHandling != volumeHandling) {
                mVolumeHandling = volumeHandling;
                if (USE_SESSIONS) {
                configureSessionVolume();
                } else {
                    setPlaybackInfoOnRcc(
                            RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING, volumeHandling);
                }
            }
        }

@@ -2139,13 +2129,9 @@ public class MediaRouter {
            volume = Math.max(0, Math.min(volume, getVolumeMax()));
            if (mVolume != volume) {
                mVolume = volume;
                if (USE_SESSIONS) {
                if (mSvp != null) {
                    mSvp.notifyVolumeChanged();
                }
                } else {
                    setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_VOLUME, volume);
                }
                dispatchRouteVolumeChanged(this);
                if (mGroup != null) {
                    mGroup.memberVolumeChanged(this);
@@ -2184,11 +2170,7 @@ public class MediaRouter {
        public void setVolumeMax(int volumeMax) {
            if (mVolumeMax != volumeMax) {
                mVolumeMax = volumeMax;
                if (USE_SESSIONS) {
                configureSessionVolume();
                } else {
                    setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_VOLUME_MAX, volumeMax);
                }
            }
        }

@@ -2199,40 +2181,12 @@ public class MediaRouter {
        public void setPlaybackStream(int stream) {
            if (mPlaybackStream != stream) {
                mPlaybackStream = stream;
                if (USE_SESSIONS) {
                configureSessionVolume();
                } else {
                    setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_USES_STREAM, stream);
                }
            }
        }

        private void updatePlaybackInfoOnRcc() {
            if (USE_SESSIONS) {
            configureSessionVolume();
            } else {
                if ((mRcc != null)
                        && (mRcc.getRcseId() != RemoteControlClient.RCSE_ID_UNREGISTERED)) {
                    mRcc.setPlaybackInformation(
                            RemoteControlClient.PLAYBACKINFO_VOLUME_MAX, mVolumeMax);
                    mRcc.setPlaybackInformation(
                            RemoteControlClient.PLAYBACKINFO_VOLUME, mVolume);
                    mRcc.setPlaybackInformation(
                            RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING, mVolumeHandling);
                    mRcc.setPlaybackInformation(
                            RemoteControlClient.PLAYBACKINFO_USES_STREAM, mPlaybackStream);
                    mRcc.setPlaybackInformation(
                            RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE, mPlaybackType);
                    // let AudioService know whom to call when remote volume
                    // needs to be updated
                    try {
                        sStatic.mAudioService.registerRemoteVolumeObserverForRcc(
                                mRcc.getRcseId() /* rccId */, mRemoteVolObserver /* rvo */);
                    } catch (RemoteException e) {
                        Log.e(TAG, "Error registering remote volume observer", e);
                    }
                }
            }
        }

        private void configureSessionVolume() {
@@ -2272,12 +2226,6 @@ public class MediaRouter {
            }
        }

        private void setPlaybackInfoOnRcc(int what, int value) {
            if (mRcc != null) {
                mRcc.setPlaybackInformation(what, value);
            }
        }

        class SessionVolumeProvider extends RemoteVolumeProvider {

            public SessionVolumeProvider(int volumeControl, int maxVolume) {
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class PlayerRecord implements DeathRecipient {
     */
    final private ComponentName mReceiverComponent;

    private int mRccId = RemoteControlClient.RCSE_ID_UNREGISTERED;
    private int mRccId = -1;

    /**
     * A non-null token implies this record tracks a "live" player whose death is being monitored.
+4 −798

File changed.

Preview size limit exceeded, changes collapsed.

Loading