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

Commit 198bc229 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "Ratings for RemoteControl" into klp-dev

parents f4e8eb83 f823fc4d
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -2359,6 +2359,24 @@ public class AudioManager {
        }
    }

    /**
     * @hide
     * Notify the user of a RemoteControlClient that it should update its metadata
     * @param generationId the RemoteControlClient generation counter for which this request is
     *         issued. Requests for an older generation than current one will be ignored.
     * @param key the metadata key for which a new value exists
     * @param value the new metadata value
     */
    public void updateRemoteControlClientMetadata(int generationId, int key, long value) {
        IAudioService service = getService();
        try {
            service.updateRemoteControlClientMetadata(generationId, key, value);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in updateRemoteControlClientMetadata("+ generationId + ", "
                    + key +", " + value + ")", e);
        }
    }

    /**
     *  @hide
     *  Reload audio settings. This method is called by Settings backup
+5 −1
Original line number Diff line number Diff line
@@ -4189,6 +4189,10 @@ public class AudioService extends IAudioService.Stub {
        mMediaFocusControl.setRemoteControlClientPlaybackPosition(generationId, timeMs);
    }

    public void updateRemoteControlClientMetadata(int generationId, int key, long value) {
        mMediaFocusControl.updateRemoteControlClientMetadata(generationId, key, value);
    }

    public void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) {
        mMediaFocusControl.registerRemoteVolumeObserverForRcc(rccId, rvo);
    }
+8 −0
Original line number Diff line number Diff line
@@ -179,6 +179,14 @@ interface IAudioService {
     * @param timeMs the time in ms to seek to, must be positive.
     */
     void setRemoteControlClientPlaybackPosition(int generationId, long timeMs);
     /**
      * Notify the user of a RemoteControlClient that it should update its metadata
      * @param generationId the RemoteControlClient generation counter for which this request is
      *         issued. Requests for an older generation than current one will be ignored.
      * @param key the metadata key for which a new value exists
      * @param value the new metadata value
      */
     void updateRemoteControlClientMetadata(int generationId, int key, long value);

    /**
     * Do not use directly, use instead
+1 −0
Original line number Diff line number Diff line
@@ -49,4 +49,5 @@ oneway interface IRemoteControlClient
    void setBitmapSizeForDisplay(IRemoteControlDisplay rcd, int w, int h);
    void setWantsSyncForDisplay(IRemoteControlDisplay rcd, boolean wantsSync);
    void seekTo(int clientGeneration, long timeMs);
    void updateMetadata(int clientGeneration, int key, long value);
}
 No newline at end of file
+40 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public class MediaFocusControl implements OnFinished {
    private static final int MSG_PROMOTE_RCC = 6;
    private static final int MSG_RCC_NEW_PLAYBACK_STATE = 7;
    private static final int MSG_RCC_SEEK_REQUEST = 8;
    private static final int MSG_RCC_UPDATE_METADATA_LONG = 9;

    // sendMsg() flags
    /** If the msg is already queued, replace it with this one. */
@@ -188,18 +189,27 @@ public class MediaFocusControl implements OnFinished {
                    onNewPlaybackInfoForRcc(msg.arg1 /* rccId */, msg.arg2 /* key */,
                            ((Integer)msg.obj).intValue() /* value */);
                    break;

                case MSG_RCC_NEW_VOLUME_OBS:
                    onRegisterVolumeObserverForRcc(msg.arg1 /* rccId */,
                            (IRemoteVolumeObserver)msg.obj /* rvo */);
                    break;

                case MSG_RCC_NEW_PLAYBACK_STATE:
                    onNewPlaybackStateForRcc(msg.arg1 /* rccId */,
                            msg.arg2 /* state */,
                            (RccPlaybackState)msg.obj /* newState */);
                    break;

                case MSG_RCC_SEEK_REQUEST:
                    onSetRemoteControlClientPlaybackPosition(
                            msg.arg1 /* generationId */, ((Long)msg.obj).longValue() /* timeMs */);
                    break;

                case MSG_RCC_UPDATE_METADATA_LONG:
                    onUpdateRemoteControlClientMetadataLong(msg.arg1 /*genId*/, msg.arg2 /*key*/,
                            ((Long)msg.obj).longValue() /* value */);
                    break;

                case MSG_PROMOTE_RCC:
                    onPromoteRcc(msg.arg1);
@@ -2070,6 +2080,36 @@ public class MediaFocusControl implements OnFinished {
        }
    }

    protected void updateRemoteControlClientMetadata(int genId, int key, long value) {
        sendMsg(mEventHandler, MSG_RCC_UPDATE_METADATA_LONG, SENDMSG_QUEUE,
                genId /* arg1 */, key /* arg2 */, Long.valueOf(value) /* obj */, 0 /* delay */);
    }

    private void onUpdateRemoteControlClientMetadataLong(int genId, int key, long value) {
        if(DEBUG_RC) Log.d(TAG, "onUpdateRemoteControlClientMetadataLong(genId=" + genId +
                ", what=" + key + ",val=" + value + ")");
        synchronized(mRCStack) {
            synchronized(mCurrentRcLock) {
                if ((mCurrentRcClient != null) && (mCurrentRcClientGen == genId)) {
                    try {
                        switch (key) {
                            case RemoteControlClient.MetadataEditor.LONG_KEY_RATING_BY_USER:
                                mCurrentRcClient.updateMetadata(genId, key, value);
                                break;
                            default:
                                Log.e(TAG, "unhandled metadata key " + key + " update for RCC "
                                        + genId);
                                break;
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG, "Current valid remote client is dead", e);
                        mCurrentRcClient = null;
                    }
                }
            }
        }
    }

    protected void setPlaybackInfoForRcc(int rccId, int what, int value) {
        sendMsg(mEventHandler, MSG_RCC_NEW_PLAYBACK_INFO, SENDMSG_QUEUE,
                rccId /* arg1 */, what /* arg2 */, Integer.valueOf(value) /* obj */, 0 /* delay */);
Loading