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

Commit 23a3c648 authored by William Escande's avatar William Escande
Browse files

Properly inject mediaPlayerList in test

Fix a staticFieldLeak

Bug: 289445022
Test: m Bluetooth
Flag: Exempt lint
Change-Id: Ic065b351c4dd0fcb0c6c3b69391b6fa4e2641c79
parent e590aafa
Loading
Loading
Loading
Loading
+23 −34
Original line number Diff line number Diff line
@@ -17042,7 +17042,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17058,7 +17058,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17074,7 +17074,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17090,7 +17090,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17106,7 +17106,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17122,7 +17122,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17138,7 +17138,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17154,7 +17154,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17170,7 +17170,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17186,7 +17186,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17202,7 +17202,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17218,7 +17218,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17234,7 +17234,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17250,7 +17250,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17266,7 +17266,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17282,7 +17282,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17298,7 +17298,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17314,7 +17314,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17330,7 +17330,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17346,7 +17346,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17362,7 +17362,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17378,7 +17378,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17394,7 +17394,7 @@
            column="5"/>
        <location
            file="packages/modules/Bluetooth/android/app/res/values/strings.xml"
            line="103"
            line="104"
            column="5"
            message="Conflicting number of arguments (0) here"/>
    </issue>
@@ -17641,17 +17641,6 @@
            column="13"/>
    </issue>
    <issue
        id="StaticFieldLeak"
        message="Do not place Android context classes in static fields (static reference to `MediaPlayerList` which has field `mContext` pointing to `Context`); this is a memory leak"
        errorLine1="    static MediaPlayerList sMediaPlayerListForTesting = null;"
        errorLine2="    ~~~~~~">
        <location
            file="packages/modules/Bluetooth/android/app/src/com/android/bluetooth/mcp/MediaControlProfile.java"
            line="90"
            column="5"/>
    </issue>
    <issue
        id="StaticFieldLeak"
        message="Do not place Android context classes in static fields (static reference to `MediaPlayerWrapper` which has field `mContext` pointing to `Context`); this is a memory leak"
+5 −11
Original line number Diff line number Diff line
@@ -87,12 +87,6 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {

    private MediaPlayerWrapper mLastActivePlayer = null;

    static MediaPlayerList sMediaPlayerListForTesting = null;

    static void setsMediaPlayerListForTesting(MediaPlayerList mediaPlayerList) {
        sMediaPlayerListForTesting = mediaPlayerList;
    }

    // Same base feature set as the player item features defined in `avrcp/get_foder_items.cc`
    private static final long BASE_PLAYER_ACTION_SET =
            PlaybackState.ACTION_PLAY
@@ -281,16 +275,16 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
    }

    public MediaControlProfile(@NonNull McpService mcpService) {
        this(mcpService, new MediaPlayerList(Looper.myLooper(), mcpService));
    }

    public MediaControlProfile(@NonNull McpService mcpService, MediaPlayerList mediaPlayerList) {
        Log.v(TAG, "Creating Generic Media Control Service");

        mMcpService = requireNonNull(mcpService);
        mContext = mcpService;

        if (sMediaPlayerListForTesting != null) {
            mMediaPlayerList = sMediaPlayerListForTesting;
        } else {
            mMediaPlayerList = new MediaPlayerList(Looper.myLooper(), mContext);
        }
        mMediaPlayerList = requireNonNull(mediaPlayerList);
    }

    @Override
+1 −2
Original line number Diff line number Diff line
@@ -112,8 +112,7 @@ public class MediaControlProfileTest {
                .when(mMockPackageManager)
                .getApplicationInfo(anyString(), anyInt());

        MediaControlProfile.setsMediaPlayerListForTesting(mMockMediaPlayerList);
        mMediaControlProfile = new MediaControlProfile(mMockMcpService);
        mMediaControlProfile = new MediaControlProfile(mMockMcpService, mMockMediaPlayerList);

        // this is equivalent of what usually happens inside init class
        mMediaControlProfile.injectGattServiceForTesting(packageName, mMockGMcsService);