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

Commit 7ddd226e authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

RemoteController class to expose IRemoteControlDisplay features

Wrap all the features of IRemoteControlDisplay.aidl in a
 new class, RemoteController, that implements the
 IRemoteControlDisplay interface.

The API functions to expose in the SDK are tagged with
 "CANDIDATE FOR API"

Bug 8209392

Change-Id: I597bcd503ac93e73889c9ae8b47b16c4fcb363bc
parent 9b645984
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2107,6 +2107,13 @@
        android:description="@string/permdesc_captureSecureVideoOutput"
        android:protectionLevel="signature|system" />

    <!--@hide Allows an application to know what content is playing and control its playback.
         <p>Not for use by third-party applications due to privacy of media consumption</p>  -->
    <permission android:name="android.permission.MEDIA_CONTENT_CONTROL"
        android:label="@string/permlab_mediaContentControl"
        android:description="@string/permdesc_mediaContentControl"
        android:protectionLevel="signature|system" />

    <!-- Required to be able to disable the device (very dangerous!).
    <p>Not for use by third-party applications.. -->
    <permission android:name="android.permission.BRICK"
+5 −0
Original line number Diff line number Diff line
@@ -1432,6 +1432,11 @@
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_captureSecureVideoOutput">Allows the app to capture and redirect secure video output.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_mediaContentControl">control media playback and metadata access</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_mediaContentControl">Allows the app to control media playback and access the media information (title, author...).</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_modifyAudioSettings">change your audio settings</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+60 −4
Original line number Diff line number Diff line
@@ -442,6 +442,19 @@ public class AudioManager {
        return sService;
    }

    /**
     * @hide
     * @param KeyEvent
     */
    protected void dispatchMediaKeyEvent(KeyEvent keyEvent) {
        IAudioService service = getService();
        try {
            service.dispatchMediaKeyEvent(keyEvent);
        } catch (RemoteException e) {
            Log.e(TAG, "dispatchMediaKeyEvent threw exception ", e);
        }
    }

    /**
     * @hide
     */
@@ -2233,6 +2246,49 @@ public class AudioManager {
        }
    }

    /**
     * @hide
     * CANDIDATE FOR PUBLIC API
     * @param rctlr
     * @return true if the {@link RemoteController} was successfully registered, false if an
     *     error occurred, due to an internal system error, or insufficient permissions.
     */
    public boolean registerRemoteController(RemoteController rctlr) {
        if (rctlr == null) {
            return false;
        }
        IAudioService service = getService();
        try {
            boolean reg = service.registerRemoteControlDisplay(rctlr.getRcDisplay(),
                    // passing a negative value for art work width and height
                    //   as they are still unknown at this stage
                    /*w*/-1, /*h*/ -1);
            rctlr.setIsRegistered(reg);
            return reg;
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in registerRemoteControlDisplay " + e);
            return false;
        }
    }

    /**
     * @hide
     * CANDIDATE FOR PUBLIC API
     * @param rctlr
     */
    public void unregisterRemoteController(RemoteController rctlr) {
        if (rctlr == null) {
            return;
        }
        IAudioService service = getService();
        try {
            service.unregisterRemoteControlDisplay(rctlr.getRcDisplay());
            rctlr.setIsRegistered(false);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in unregisterRemoteControlDisplay " + e);
        }
    }

    /**
     * @hide
     * Registers a remote control display that will be sent information by remote control clients.
@@ -2263,8 +2319,6 @@ public class AudioManager {
        }
        IAudioService service = getService();
        try {
            // passing a negative value for art work width and height as they are unknown at
            // this stage
            service.registerRemoteControlDisplay(rcd, w, h);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in registerRemoteControlDisplay " + e);
@@ -2357,13 +2411,15 @@ public class AudioManager {

    /**
     * @hide
     * Notify the user of a RemoteControlClient that it should update its metadata
     * Notify the user of a RemoteControlClient that it should update its metadata with the
     * new value for the given key.
     * @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) {
    public void updateRemoteControlClientMetadata(int generationId, int key,
            Rating value) {
        IAudioService service = getService();
        try {
            service.updateRemoteControlClientMetadata(generationId, key, value);
+12 −3
Original line number Diff line number Diff line
@@ -4143,8 +4143,17 @@ public class AudioService extends IAudioService.Stub {
    //==========================================================================================
    // RemoteControlDisplay / RemoteControlClient / Remote info
    //==========================================================================================
    public void registerRemoteControlDisplay(IRemoteControlDisplay rcd, int w, int h) {
    public boolean registerRemoteControlDisplay(IRemoteControlDisplay rcd, int w, int h) {
        if (PackageManager.PERMISSION_GRANTED == mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.MEDIA_CONTENT_CONTROL)) {
            mMediaFocusControl.registerRemoteControlDisplay(rcd, w, h);
            return true;
        } else {
            Log.w(TAG, "Access denied to process: " + Binder.getCallingPid() +
                    ", must have permission " + android.Manifest.permission.MEDIA_CONTENT_CONTROL +
                    " to register IRemoteControlDisplay");
            return false;
        }
    }

    public void unregisterRemoteControlDisplay(IRemoteControlDisplay rcd) {
@@ -4190,7 +4199,7 @@ public class AudioService extends IAudioService.Stub {
        mMediaFocusControl.setRemoteControlClientPlaybackPosition(generationId, timeMs);
    }

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

+5 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.IRemoteControlClient;
import android.media.IRemoteControlDisplay;
import android.media.IRemoteVolumeObserver;
import android.media.IRingtonePlayer;
import android.media.Rating;
import android.net.Uri;
import android.view.KeyEvent;

@@ -140,7 +141,7 @@ interface IAudioService {
     * @param h the maximum height of the expected bitmap. Negative or zero values indicate this
     *   display doesn't need to receive artwork.
     */
    oneway void   registerRemoteControlDisplay(in IRemoteControlDisplay rcd, int w, int h);
    boolean registerRemoteControlDisplay(in IRemoteControlDisplay rcd, int w, int h);
    /**
     * Unregister an IRemoteControlDisplay.
     * No effect if the IRemoteControlDisplay hasn't been successfully registered.
@@ -178,13 +179,14 @@ interface IAudioService {
     */
     void setRemoteControlClientPlaybackPosition(int generationId, long timeMs);
     /**
      * Notify the user of a RemoteControlClient that it should update its metadata
      * Notify the user of a RemoteControlClient that it should update its metadata with the
      * new value for the given key.
      * @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);
     void updateRemoteControlClientMetadata(int generationId, int key, in Rating value);

    /**
     * Do not use directly, use instead
Loading