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

Commit 55a3218f authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Subclassing AudioTrack considered harmful

This class was not really designed for subclassing to be meaningful,
and some uses could be downright dangerous, for example setState().

Change-Id: I36029e94546c53a47926918e7f667d9e83bd02fe
parent 0ada5d65
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -11008,7 +11008,7 @@ package android.media {
    method public static float getMaxVolume();
    method public static int getMinBufferSize(int, int, int);
    method public static float getMinVolume();
    method protected int getNativeFrameCount();
    method protected deprecated int getNativeFrameCount();
    method public static int getNativeOutputSampleRate(int);
    method public int getNotificationMarkerPosition();
    method public int getPlayState();
@@ -11030,7 +11030,7 @@ package android.media {
    method public void setPlaybackPositionUpdateListener(android.media.AudioTrack.OnPlaybackPositionUpdateListener, android.os.Handler);
    method public int setPlaybackRate(int);
    method public int setPositionNotificationPeriod(int);
    method protected void setState(int);
    method protected deprecated void setState(int);
    method public int setStereoVolume(float, float);
    method public void stop() throws java.lang.IllegalStateException;
    method public int write(byte[], int, int);
+11 −2
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ import android.util.Log;
 * be played from it.<br>
 * For the streaming mode, data will be written to the hardware in chunks of
 * sizes less than or equal to the total buffer size.
 *
 * AudioTrack is not final and thus permits subclasses, but such use is not recommended.
 */
public class AudioTrack
{
@@ -601,7 +603,11 @@ public class AudioTrack

    /**
     *  Returns the native frame count used by the hardware.
     *  @deprecated Only accessible by subclasses, which are not recommended for AudioTrack.
     *  See {@link AudioManager#getProperty(String)} for key
     *  {@link AudioManager#PROPERTY_OUTPUT_FRAMES_PER_BUFFER}.
     */
    @Deprecated
    protected int getNativeFrameCount() {
        return native_get_native_frame_count();
    }
@@ -865,10 +871,13 @@ public class AudioTrack
    }

    /**
     * Sets the initialization state of the instance. To be used in an AudioTrack subclass
     * constructor to set a subclass-specific post-initialization state.
     * Sets the initialization state of the instance. This method was originally intended to be used
     * in an AudioTrack subclass constructor to set a subclass-specific post-initialization state.
     * However, subclasses of AudioTrack are no longer recommended, so this method is obsolete.
     * @param state the state of the AudioTrack instance
     * @deprecated Only accessible by subclasses, which are not recommended for AudioTrack.
     */
    @Deprecated
    protected void setState(int state) {
        mState = state;
    }