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

Commit f940744f authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Pawlowski
Browse files

Add Media Control Profile constants definitions

Bug: 150670922
Tag: #feature
Test: atest BluetoothInstrumentationTests
Sponsor: jpawlowski@
Change-Id: Iea7472f3debd3fa173a4b3308f2aed8c1fcc7b33
parent bf5e3a5c
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * 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.mcp;

/**
 * Playback states definition
 */
public enum MediaState {
    INACTIVE(0x00),
    PLAYING(0x01),
    PAUSED(0x02),
    SEEKING(0x03);

    public static final MediaState STATE_MIN = INACTIVE;
    public static final MediaState STATE_MAX = SEEKING;
    private final int mValue;

    MediaState(int value) {
        mValue = value;
    }

    public int getValue() {
        return mValue;
    }
}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * 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.mcp;

/**
 * Objects IDs definition
 */
public final class ObjectIds {
    public static final int PLAYER_ICON_OBJ_ID = (int) ServiceFeature.PLAYER_ICON_OBJ_ID;
    public static final int CURRENT_TRACK_SEGMENT_OBJ_ID =
            (int) ServiceFeature.CURRENT_TRACK_SEGMENT_OBJ_ID;
    public static final int CURRENT_TRACK_OBJ_ID = (int) ServiceFeature.CURRENT_TRACK_OBJ_ID;
    public static final int NEXT_TRACK_OBJ_ID = (int) ServiceFeature.NEXT_TRACK_OBJ_ID;
    public static final int CURRENT_GROUP_OBJ_ID = (int) ServiceFeature.CURRENT_GROUP_OBJ_ID;
    public static final int PARENT_GROUP_OBJ_ID = (int) ServiceFeature.PARENT_GROUP_OBJ_ID;
    public static final int SEARCH_RESULT_OBJ_ID = (int) ServiceFeature.SEARCH_RESULT_OBJ_ID;
    private ObjectIds() {
        // not called
    }

    public static int GetMatchingServiceFeature(int objectId) {
        return objectId;
    }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * 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.mcp;

/**
 * Player state fields definition
 */
public enum PlayerStateField {
    PLAYBACK_STATE,
    PLAYBACK_SPEED,
    SEEKING_SPEED,
    PLAYING_ORDER,
    TRACK_POSITION,
    PLAYER_NAME,
    ICON_URL,
    ICON_OBJ_ID,
    PLAYING_ORDER_SUPPORTED,
    OPCODES_SUPPORTED,
    TRACK_TITLE,
    TRACK_DURATION,
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * 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.mcp;

/**
 * Playing order definition
 */
public enum PlayingOrder {
    SINGLE_ONCE(0x01),
    SINGLE_REPEAT(0x02),
    IN_ORDER_ONCE(0x03),
    IN_ORDER_REPEAT(0x04),
    OLDEST_ONCE(0x05),
    OLDEST_REPEAT(0x06),
    NEWEST_ONCE(0x07),
    NEWEST_REPEAT(0x08),
    SHUFFLE_ONCE(0x09),
    SHUFFLE_REPEAT(0x0A);

    private final int mValue;

    PlayingOrder(int value) {
        mValue = value;
    }

    public int getValue() {
        return mValue;
    }
}
+161 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com.
 *
 * 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.mcp;

import static java.util.Map.entry;

import java.util.Map;

/**
 * Media control request, from client to Media Player
 */
public final class Request {
    private final int mOpcode;
    private final Integer mIntArg;

    /**
     * Media control request constructor
     *
     * @param opcode Control request opcode
     * @param arg    Control request argument
     */
    public Request(int opcode, int arg) {
        this.mOpcode = opcode;
        this.mIntArg = arg;
    }

    /**
     * Media control results opcode getter
     *
     * @return Control request opcode
     */
    public int getOpcode() {
        return mOpcode;
    }

    /**
     * Media control results argument getter
     *
     * @return Control request argument
     */
    public int getIntArg() {
        return mIntArg;
    }

    /**
     * Media control request results definition
     */
    public enum Results {
        SUCCESS(0x01),
        OPCODE_NOT_SUPPORTED(0x02),
        MEDIA_PLAYER_INACTIVE(0x03),
        COMMAND_CANNOT_BE_COMPLETED(0x04);

        private final int mValue;

        Results(int value) {
            mValue = value;
        }

        public int getValue() {
            return mValue;
        }
    }

    /**
     * Media control request supported opcodes definition
     */
    public final static class SupportedOpcodes {
        public static final int NONE = 0x00;
        public static final int PLAY = 0x01;
        public static final int PAUSE = 0x02;
        public static final int FAST_REWIND = 0x04;
        public static final int FAST_FORWARD = 0x08;
        public static final int STOP = 0x10;
        public static final int MOVE_RELATIVE = 0x20;
        public static final int PREVIOUS_SEGMENT = 0x40;
        public static final int NEXT_SEGMENT = 0x80;
        public static final int FIRST_SEGMENT = 0x0100;
        public static final int LAST_SEGMENT = 0x0200;
        public static final int GOTO_SEGMENT = 0x0400;
        public static final int PREVIOUS_TRACK = 0x0800;
        public static final int NEXT_TRACK = 0x1000;
        public static final int FIRST_TRACK = 0x2000;
        public static final int LAST_TRACK = 0x4000;
        public static final int GOTO_TRACK = 0x8000;
        public static final int PREVIOUS_GROUP = 0x010000;
        public static final int NEXT_GROUP = 0x020000;
        public static final int FIRST_GROUP = 0x040000;
        public static final int LAST_GROUP = 0x080000;
        public static final int GOTO_GROUP = 0x100000;
    }

    /**
     * Media control request opcodes definition
     */
    public final static class Opcodes {
        public static final int PLAY = 0x01;
        public static final int PAUSE = 0x02;
        public static final int FAST_REWIND = 0x03;
        public static final int FAST_FORWARD = 0x04;
        public static final int STOP = 0x05;
        public static final int MOVE_RELATIVE = 0x10;
        public static final int PREVIOUS_SEGMENT = 0x20;
        public static final int NEXT_SEGMENT = 0x21;
        public static final int FIRST_SEGMENT = 0x22;
        public static final int LAST_SEGMENT = 0x23;
        public static final int GOTO_SEGMENT = 0x24;
        public static final int PREVIOUS_TRACK = 0x30;
        public static final int NEXT_TRACK = 0x31;
        public static final int FIRST_TRACK = 0x32;
        public static final int LAST_TRACK = 0x33;
        public static final int GOTO_TRACK = 0x34;
        public static final int PREVIOUS_GROUP = 0x40;
        public static final int NEXT_GROUP = 0x41;
        public static final int FIRST_GROUP = 0x42;
        public static final int LAST_GROUP = 0x43;
        public static final int GOTO_GROUP = 0x44;
    }

    /* Map opcodes which are written to 'Media Control Point' characteristics to their corresponding
     * feature bit masks used in 'Media Control Point Opcodes Supported' characteristic.
     */
    public final static Map<Integer, Integer> OpcodeToOpcodeSupport = Map.ofEntries(
            entry(Opcodes.PLAY, SupportedOpcodes.PLAY),
            entry(Opcodes.PAUSE, SupportedOpcodes.PAUSE),
            entry(Opcodes.FAST_REWIND, SupportedOpcodes.FAST_REWIND),
            entry(Opcodes.FAST_FORWARD, SupportedOpcodes.FAST_FORWARD),
            entry(Opcodes.STOP, SupportedOpcodes.STOP),
            entry(Opcodes.MOVE_RELATIVE, SupportedOpcodes.MOVE_RELATIVE),
            entry(Opcodes.PREVIOUS_SEGMENT, SupportedOpcodes.PREVIOUS_SEGMENT),
            entry(Opcodes.NEXT_SEGMENT, SupportedOpcodes.NEXT_SEGMENT),
            entry(Opcodes.FIRST_SEGMENT, SupportedOpcodes.FIRST_SEGMENT),
            entry(Opcodes.LAST_SEGMENT, SupportedOpcodes.LAST_SEGMENT),
            entry(Opcodes.GOTO_SEGMENT, SupportedOpcodes.GOTO_SEGMENT),
            entry(Opcodes.PREVIOUS_TRACK, SupportedOpcodes.PREVIOUS_TRACK),
            entry(Opcodes.NEXT_TRACK, SupportedOpcodes.NEXT_TRACK),
            entry(Opcodes.FIRST_TRACK, SupportedOpcodes.FIRST_TRACK),
            entry(Opcodes.LAST_TRACK, SupportedOpcodes.LAST_TRACK),
            entry(Opcodes.GOTO_TRACK, SupportedOpcodes.GOTO_TRACK),
            entry(Opcodes.PREVIOUS_GROUP, SupportedOpcodes.PREVIOUS_GROUP),
            entry(Opcodes.NEXT_GROUP, SupportedOpcodes.NEXT_GROUP),
            entry(Opcodes.FIRST_GROUP, SupportedOpcodes.FIRST_GROUP),
            entry(Opcodes.LAST_GROUP, SupportedOpcodes.LAST_GROUP),
            entry(Opcodes.GOTO_GROUP, SupportedOpcodes.GOTO_GROUP));

}
Loading