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

Commit 8ab8c2d0 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Cache RemoteController artwork bitmap size, use it in registration

Allow an app to set the artwork configuration at any point
  regardless of the registration state, and cache the width/height
  values.
If the RemoteController is already registered, apply them.
If the RemoteController is not registered, use the cached value
  when the object gets registered.

Bug 10862527

Change-Id: If633e2b9383e7d59690288d2271113e98b195cd8
parent 33ed738d
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2281,10 +2281,9 @@ public class AudioManager {
        }
        IAudioService service = getService();
        try {
            int[] artworkDimensions = rctlr.getArtworkSize();
            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);
                    artworkDimensions[0]/*w*/, artworkDimensions[1]/*h*/);
            rctlr.setIsRegistered(reg);
            return reg;
        } catch (RemoteException e) {
+33 −17
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ public final class RemoteController
    private OnClientUpdateListener mOnClientUpdateListener;
    private PlaybackInfo mLastPlaybackInfo;
    private int mLastTransportControlFlags = TRANSPORT_UNKNOWN;
    private int mArtworkWidth = -1;
    private int mArtworkHeight = -1;

    /**
     * Class constructor.
@@ -290,7 +292,6 @@ public final class RemoteController

    /**
     * @hide
     * must be called on a registered RemoteController
     * @param wantBitmap
     * @param width
     * @param height
@@ -298,22 +299,26 @@ public final class RemoteController
     */
    public int setArtworkConfiguration(boolean wantBitmap, int width, int height) {
        synchronized (mInfoLock) {
            if (!mIsRegistered) {
                Log.e(TAG, "Cannot specify bitmap configuration on unregistered RemoteController");
                return ERROR;
            }
        }
            if (wantBitmap) {
                if ((width > 0) && (height > 0)) {
                    if (width > MAX_BITMAP_DIMENSION) { width = MAX_BITMAP_DIMENSION; }
                    if (height > MAX_BITMAP_DIMENSION) { height = MAX_BITMAP_DIMENSION; }
                mAudioManager.remoteControlDisplayUsesBitmapSize(mRcd, width, height);
                    mArtworkWidth = width;
                    mArtworkHeight = height;
                } else {
                    Log.e(TAG, "Invalid dimensions");
                    return ERROR_BAD_VALUE;
                }
            } else {
            mAudioManager.remoteControlDisplayUsesBitmapSize(mRcd, -1, -1);
                mArtworkWidth = -1;
                mArtworkHeight = -1;
            }
            if (mIsRegistered) {
                mAudioManager.remoteControlDisplayUsesBitmapSize(mRcd,
                        mArtworkWidth, mArtworkHeight);
            } // else new values have been stored, and will be read by AudioManager with
              //    RemoteController.getArtworkSize() when AudioManager.registerRemoteController()
              //    is called.
        }
        return SUCCESS;
    }
@@ -321,7 +326,6 @@ public final class RemoteController
    /**
     * Set the maximum artwork image dimensions to be received in the metadata.
     * No bitmaps will be received unless this has been specified.
     * This method can only be called on a registered RemoteController.
     * @param width the maximum width in pixels
     * @param height  the maximum height in pixels
     * @return {@link #SUCCESS}, {@link #ERROR} or {@link #ERROR_BAD_VALUE}
@@ -332,7 +336,6 @@ public final class RemoteController

    /**
     * Prevents this RemoteController from receiving artwork images.
     * This method can only be called on a registered RemoteController.
     * @return {@link #SUCCESS}, {@link #ERROR}
     */
    public int clearArtworkConfiguration() {
@@ -767,4 +770,17 @@ public final class RemoteController
    protected RcDisplay getRcDisplay() {
        return mRcd;
    }

    /**
     * @hide
     * Used by AudioManager to read the current artwork dimension
     * @return array containing width (index 0) and height (index 1) of currently set artwork size
     */
    protected int[] getArtworkSize() {
        synchronized (mInfoLock) {
            int[] size = { mArtworkWidth, mArtworkHeight };
            return size;
        }
    }

}