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

Commit 623e1939 authored by William Escande's avatar William Escande
Browse files

ErrorProne: AudioUtil

remove unused code + implement a few hasCode for
(MediaData|MediaController|Metadata|Image)

MediaPlayerList:
```
734: warning: Conversion from long to float may lose precision;
  use an explicit cast to float if this was intentional
                    .setState(PlaybackState.STATE_STOPPED, 0L, 0L);
                                                               ^
842: warning: MediaSession.Token is final and does not override Object.toString,
                                + token);
                                  ^
```

MediaPlayerWrapper:
```
xxx: warning: This access should be guarded by 'this.mCallbackLock', which is not currently held
        mControllerCallbacks = new MediaControllerListener(mMediaController, mLooper);
        ^
309: warning: Comparison using reference equality instead of value equality
        if (newController == mMediaController) return;
                          ^
456: warning: Calling equals on incompatible types MediaMetadata and Metadata
            if (Objects.equals(metadata, mCurrentData.metadata)) {
                              ^
```

BTAudioEventLogger.java:
```
32: warning: Inner class is non-static but does not reference enclosing class
    private class Event {
            ^
```
BrowsedPlayerWrapper:
42: warning: Log tag too long, cannot exceed 23 characters.
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
                                                        ^
```
AvrcpPassthrough:
```
120: warning: Switch case has 'fall through' comment, but execution cannot fall through from the previous case
            case BluetoothAvrcp.PASSTHROUGH_ID_SELECT:
            ^
```

Bug: 236759221
Test: m RUN_ERROR_PRONE=true Bluetooth
Change-Id: Ie5c4c37cc16508028f9519bda42da30135b04078
parent c01e1876
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class BTAudioEventLogger {
    private final EvictingQueue<Event> mEvents;

    // Event class contain timestamp and log context.
    private class Event {
    private static class Event {
        private final String mTimeStamp;
        private final String mMsg;

+7 −5
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ public class BrowsablePlayerConnector {

    private static BrowsablePlayerConnector sInjectConnector;
    private Handler mHandler;
    private Context mContext;
    private PlayerListCallback mCallback;

    private List<BrowsedPlayerWrapper> mResults = new ArrayList<BrowsedPlayerWrapper>();
@@ -62,7 +61,11 @@ public class BrowsablePlayerConnector {
        void run(List<BrowsedPlayerWrapper> result);
    }

    private static void setInstanceForTesting(BrowsablePlayerConnector connector) {
    /**
     * @hide
     */
    @VisibleForTesting
    static void setInstanceForTesting(BrowsablePlayerConnector connector) {
        Utils.enforceInstrumentationTestMode();
        sInjectConnector = connector;
    }
@@ -80,7 +83,7 @@ public class BrowsablePlayerConnector {
            return null;
        }

        BrowsablePlayerConnector newWrapper = new BrowsablePlayerConnector(context, looper, cb);
        BrowsablePlayerConnector newWrapper = new BrowsablePlayerConnector(looper, cb);

        // Try to start connecting all the browsed player wrappers
        for (ResolveInfo info : players) {
@@ -109,8 +112,7 @@ public class BrowsablePlayerConnector {
        return newWrapper;
    }

    private BrowsablePlayerConnector(Context context, Looper looper, PlayerListCallback cb) {
        mContext = context;
    private BrowsablePlayerConnector(Looper looper, PlayerListCallback cb) {
        mCallback = cb;
        mHandler = new Handler(looper) {
            public void handleMessage(Message msg) {
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import java.util.Map;
 * Right now this is ok because the BrowsablePlayerConnector will handle timeouts.
 */
class BrowsedPlayerWrapper {
    private static final String TAG = "AvrcpBrowsedPlayerWrapper";
    private static final String TAG = "BrowsedPlayerWrapper";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    enum ConnectionState {
+2 −4
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ public class MediaPlayerList {

    private Context mContext;
    private Looper mLooper; // Thread all media player callbacks and timeouts happen on
    private PackageManager mPackageManager;
    private MediaSessionManager mMediaSessionManager;
    private MediaData mCurrMediaData = null;
    private final AudioManager mAudioManager;
@@ -731,7 +730,7 @@ public class MediaPlayerList {
        if (getActivePlayer() == null) {
            Log.d(TAG, "updateMediaForAudioPlayback: no active player");
            PlaybackState.Builder builder = new PlaybackState.Builder()
                    .setState(PlaybackState.STATE_STOPPED, 0L, 0L);
                    .setState(PlaybackState.STATE_STOPPED, 0L, 0f);
            List<Metadata> queue = new ArrayList<Metadata>();
            queue.add(Util.empty_data());
            currMediaData = new MediaData(
@@ -838,8 +837,7 @@ public class MediaPlayerList {
                        MediaSession.Token token) {
                    if (mMediaSessionManager == null) {
                        Log.w(TAG, "onMediaKeyEventSessionChanged(): Unexpected callback "
                                + "from the MediaSessionManager, pkg" + packageName + ", token="
                                + token);
                                + "from the MediaSessionManager, pkg" + packageName);
                        return;
                    }
                    if (TextUtils.isEmpty(packageName)) {
+24 −20
Original line number Diff line number Diff line
@@ -288,8 +288,10 @@ public class MediaPlayerWrapper {
                getPlaybackState(),
                Util.toMetadataList(mContext, getQueue()));

        synchronized (mCallbackLock) {
            mControllerCallbacks = new MediaControllerListener(mMediaController, mLooper);
        }
    }

    /**
     * Unregisters from updates. Note, this doesn't require the looper to be shut down.
@@ -298,15 +300,14 @@ public class MediaPlayerWrapper {
        // Prevent a race condition where a callback could be called while shutting down
        synchronized (mCallbackLock) {
            mRegisteredCallback = null;
        }

            if (mControllerCallbacks == null) return;
            mControllerCallbacks.cleanup();
            mControllerCallbacks = null;
        }
    }

    void updateMediaController(MediaController newController) {
        if (newController == mMediaController) return;
        if (Objects.equals(newController, mMediaController)) return;

        mMediaController = newController;

@@ -315,17 +316,18 @@ public class MediaPlayerWrapper {
                d("Controller for " + mPackageName + " maybe is not activated.");
                return;
            }
        }

            mControllerCallbacks.cleanup();

        // Update the current data since it could be different on the new controller for the player
            // Update the current data since it could be different on the new controller for the
            // player
            mCurrentData = new MediaData(
                    Util.toMetadata(mContext, getMetadata()),
                    getPlaybackState(),
                    Util.toMetadataList(mContext, getQueue()));

            mControllerCallbacks = new MediaControllerListener(mMediaController, mLooper);
        }
        d("Controller for " + mPackageName + " was updated.");
    }

@@ -429,7 +431,7 @@ public class MediaPlayerWrapper {
        }

        @Override
        public void onMetadataChanged(@Nullable MediaMetadata metadata) {
        public void onMetadataChanged(@Nullable MediaMetadata mediaMetadata) {
            if (!isMetadataReady()) {
                Log.v(TAG, "onMetadataChanged(): " + mPackageName
                        + " tried to update with no queue");
@@ -438,10 +440,10 @@ public class MediaPlayerWrapper {

            if (DEBUG) {
                Log.v(TAG, "onMetadataChanged(): " + mPackageName + " : "
                        + Util.toMetadata(mContext, metadata));
                        + Util.toMetadata(mContext, mediaMetadata));
            }

            if (!Objects.equals(metadata, getMetadata())) {
            if (!Objects.equals(mediaMetadata, getMetadata())) {
                e("The callback metadata doesn't match controller metadata");
            }

@@ -453,7 +455,7 @@ public class MediaPlayerWrapper {
            // TODO: Spotify needs a metadata update debouncer as it sometimes updates the metadata
            // twice in a row with the only difference being that the song duration is rounded to
            // the nearest second.
            if (Objects.equals(metadata, mCurrentData.metadata)) {
            if (Objects.equals(Util.toMetadata(mContext, mediaMetadata), mCurrentData.metadata)) {
                Log.w(TAG, "onMetadataChanged(): " + mPackageName
                        + " tried to update with no new data");
                return;
@@ -570,9 +572,11 @@ public class MediaPlayerWrapper {

    @VisibleForTesting
    Handler getTimeoutHandler() {
        synchronized (mCallbackLock) {
            if (mControllerCallbacks == null) return null;
            return mControllerCallbacks.getTimeoutHandler();
        }
    }

    @Override
    public String toString() {
Loading