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

Commit 99afec48 authored by William Escande's avatar William Escande
Browse files

AvrcpController: Move some method to static

Bug: 295237486
Test: atest AvrcpControllerServiceTest
Test: atest AvrcpControllerNativeInterfaceTest
Change-Id: Ice65ac454e5c8ccea467e725d66185d7d30ff0c4
parent 808591b3
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -753,16 +753,16 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      clazz, "handleGetPlayerItemsRsp",
      "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");

  method_createFromNativeMediaItem =
      env->GetMethodID(clazz, "createFromNativeMediaItem",
  method_createFromNativeMediaItem = env->GetStaticMethodID(
      clazz, "createFromNativeMediaItem",
      "([BJILjava/lang/String;[I[Ljava/lang/String;)Lcom/"
      "android/bluetooth/avrcpcontroller/AvrcpItem;");
  method_createFromNativeFolderItem = env->GetMethodID(
  method_createFromNativeFolderItem = env->GetStaticMethodID(
      clazz, "createFromNativeFolderItem",
      "([BJILjava/lang/String;I)Lcom/android/bluetooth/avrcpcontroller/"
      "AvrcpItem;");
  method_createFromNativePlayerItem =
      env->GetMethodID(clazz, "createFromNativePlayerItem",
  method_createFromNativePlayerItem = env->GetStaticMethodID(
      clazz, "createFromNativePlayerItem",
      "([BILjava/lang/String;[BII)Lcom/android/bluetooth/"
      "avrcpcontroller/AvrcpPlayer;");
  method_handleChangeFolderRsp =
+4 −4
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ public class AvrcpControllerNativeInterface {
    }

    // JNI Helper functions to convert native objects to java.
    AvrcpItem createFromNativeMediaItem(
    static AvrcpItem createFromNativeMediaItem(
            byte[] address, long uid, int type, String name, int[] attrIds, String[] attrVals) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (VDBG) {
@@ -281,7 +281,7 @@ public class AvrcpControllerNativeInterface {
                .build();
    }

    AvrcpItem createFromNativeFolderItem(
    static AvrcpItem createFromNativeFolderItem(
            byte[] address, long uid, int type, String name, int playable) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (VDBG) {
@@ -307,7 +307,7 @@ public class AvrcpControllerNativeInterface {
                .build();
    }

    AvrcpPlayer createFromNativePlayerItem(
    static AvrcpPlayer createFromNativePlayerItem(
            byte[] address,
            int id,
            String name,
@@ -397,7 +397,7 @@ public class AvrcpControllerNativeInterface {
    private static final byte JNI_PLAY_STATUS_FWD_SEEK = 0x03;
    private static final byte JNI_PLAY_STATUS_REV_SEEK = 0x04;

    private int toPlaybackStateFromJni(int fromJni) {
    private static int toPlaybackStateFromJni(int fromJni) {
        switch (fromJni) {
            case JNI_PLAY_STATUS_STOPPED:
                return PlaybackStateCompat.STATE_STOPPED;
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.bluetooth.avrcpcontroller;

import static com.google.common.truth.Truth.assertThat;

import android.support.v4.media.session.PlaybackStateCompat;

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@MediumTest
@RunWith(AndroidJUnit4.class)
public class AvrcpControllerNativeInterfaceTest {
    private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
    private static final byte[] REMOTE_DEVICE_ADDRESS_AS_ARRAY = new byte[] {0, 0, 0, 0, 0, 0};

    @Test
    public void createFromNativeMediaItem() {
        long uid = 1;
        int type = 2;
        int[] attrIds = new int[] {0x01}; // MEDIA_ATTRIBUTE_TITLE
        String[] attrVals = new String[] {"test_title"};

        AvrcpItem item =
                AvrcpControllerNativeInterface.createFromNativeMediaItem(
                        REMOTE_DEVICE_ADDRESS_AS_ARRAY,
                        uid,
                        type,
                        "unused_name",
                        attrIds,
                        attrVals);

        assertThat(item.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        assertThat(item.getItemType()).isEqualTo(AvrcpItem.TYPE_MEDIA);
        assertThat(item.getType()).isEqualTo(type);
        assertThat(item.getUid()).isEqualTo(uid);
        assertThat(item.getUuid()).isNotNull(); // Random uuid
        assertThat(item.getTitle()).isEqualTo(attrVals[0]);
        assertThat(item.isPlayable()).isTrue();
    }

    @Test
    public void createFromNativeFolderItem() {
        long uid = 1;
        int type = 2;
        String folderName = "test_folder_name";
        int playable = 0x01; // Playable folder

        AvrcpItem item =
                AvrcpControllerNativeInterface.createFromNativeFolderItem(
                        REMOTE_DEVICE_ADDRESS_AS_ARRAY, uid, type, folderName, playable);

        assertThat(item.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        assertThat(item.getItemType()).isEqualTo(AvrcpItem.TYPE_FOLDER);
        assertThat(item.getType()).isEqualTo(type);
        assertThat(item.getUid()).isEqualTo(uid);
        assertThat(item.getUuid()).isNotNull(); // Random uuid
        assertThat(item.getDisplayableName()).isEqualTo(folderName);
        assertThat(item.isPlayable()).isTrue();
    }

    @Test
    public void createFromNativePlayerItem() {
        int playerId = 1;
        String name = "test_name";
        byte[] transportFlags = new byte[] {1, 0, 0, 0, 0, 0, 0, 0};
        int playStatus = 0x04; // JNI_PLAY_STATUS_REV_SEEK;
        int playerType = AvrcpPlayer.TYPE_AUDIO; // No getter exists

        AvrcpPlayer player =
                AvrcpControllerNativeInterface.createFromNativePlayerItem(
                        REMOTE_DEVICE_ADDRESS_AS_ARRAY,
                        playerId,
                        name,
                        transportFlags,
                        playStatus,
                        playerType);

        assertThat(player.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        assertThat(player.getId()).isEqualTo(playerId);
        assertThat(player.supportsFeature(0)).isTrue();
        assertThat(player.getName()).isEqualTo(name);
        assertThat(player.getPlayStatus()).isEqualTo(PlaybackStateCompat.STATE_REWINDING);
    }
}
+0 −60
Original line number Diff line number Diff line
@@ -267,66 +267,6 @@ public class AvrcpControllerServiceTest {
        assertThat(result.getStatus()).isEqualTo(BrowseResult.SUCCESS);
    }

    @Test
    public void createFromNativeMediaItem() {
        // TODO This is only nativeInterfaceTest
        // long uid = 1;
        // int type = 2;
        // int[] attrIds = new int[] { 0x01 }; // MEDIA_ATTRIBUTE_TITLE}
        // String[] attrVals = new String[] {"test_title"};

        // AvrcpItem item = mService.createFromNativeMediaItem(
        //         REMOTE_DEVICE_ADDRESS_AS_ARRAY, uid, type, "unused_name", attrIds, attrVals);

        // assertThat(item.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        // assertThat(item.getItemType()).isEqualTo(AvrcpItem.TYPE_MEDIA);
        // assertThat(item.getType()).isEqualTo(type);
        // assertThat(item.getUid()).isEqualTo(uid);
        // assertThat(item.getUuid()).isNotNull(); // Random uuid
        // assertThat(item.getTitle()).isEqualTo(attrVals[0]);
        // assertThat(item.isPlayable()).isTrue();
    }

    @Test
    public void createFromNativeFolderItem() {
        // TODO This is only nativeInterfaceTest
        // long uid = 1;
        // int type = 2;
        // String folderName = "test_folder_name";
        // int playable = 0x01; // Playable folder

        // AvrcpItem item = mService.createFromNativeFolderItem(
        //         REMOTE_DEVICE_ADDRESS_AS_ARRAY, uid, type, folderName, playable);

        // assertThat(item.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        // assertThat(item.getItemType()).isEqualTo(AvrcpItem.TYPE_FOLDER);
        // assertThat(item.getType()).isEqualTo(type);
        // assertThat(item.getUid()).isEqualTo(uid);
        // assertThat(item.getUuid()).isNotNull(); // Random uuid
        // assertThat(item.getDisplayableName()).isEqualTo(folderName);
        // assertThat(item.isPlayable()).isTrue();
    }

    @Test
    public void createFromNativePlayerItem() {
        // TODO This is only nativeInterfaceTest
        // int playerId = 1;
        // String name = "test_name";
        // byte[] transportFlags = new byte[] {1, 0, 0, 0, 0, 0, 0, 0};
        // int playStatus = AvrcpControllerService.JNI_PLAY_STATUS_REV_SEEK;
        // int playerType = AvrcpPlayer.TYPE_AUDIO; // No getter exists

        // AvrcpPlayer player = mService.createFromNativePlayerItem(
        //         REMOTE_DEVICE_ADDRESS_AS_ARRAY, playerId, name, transportFlags,
        //         playStatus, playerType);

        // assertThat(player.getDevice().getAddress()).isEqualTo(REMOTE_DEVICE_ADDRESS);
        // assertThat(player.getId()).isEqualTo(playerId);
        // assertThat(player.supportsFeature(0)).isTrue();
        // assertThat(player.getName()).isEqualTo(name);
        // assertThat(player.getPlayStatus()).isEqualTo(PlaybackStateCompat.STATE_REWINDING);
    }

    @Test
    public void handleChangeFolderRsp() {
        int count = 1;