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

Commit 63b91a56 authored by Sal Savage's avatar Sal Savage
Browse files

Get the AVRCP Version that the user has requested

This change will grab the user selected AVRCP version number at start up
of the service. This value is a system property and will match the value
the native layer uses in our SDP record. It will allow us to make
decisions on which features to support since some features are not valid
in older versions. Cover art is one such example.

Tag: #feature
Bug: 153076316
Test: atest BluetoothInstrumentationTests
Test: build, flash, make sure proper version appears in dumpsys
bluetooth_manager

Change-Id: I5df51028c47cccc54c1891f5bef259618f254be6
parent d9cda67f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class AvrcpTargetService extends ProfileService {
    private final BTAudioEventLogger mMediaKeyEventLogger = new BTAudioEventLogger(
            MEDIA_KEY_EVENT_LOGGER_SIZE, MEDIA_KEY_EVENT_LOGGER_TITLE);

    private AvrcpVersion mAvrcpVersion;
    private MediaPlayerList mMediaPlayerList;
    private AudioManager mAudioManager;
    private AvrcpBroadcastReceiver mReceiver;
@@ -195,6 +196,8 @@ public class AvrcpTargetService extends ProfileService {
        mNativeInterface = AvrcpNativeInterface.getInterface();
        mNativeInterface.init(AvrcpTargetService.this);

        mAvrcpVersion = AvrcpVersion.getCurrentSystemPropertiesValue();

        mVolumeManager = new AvrcpVolumeManager(this, mAudioManager, mNativeInterface);

        UserManager userManager = UserManager.get(getApplicationContext());
@@ -402,6 +405,8 @@ public class AvrcpTargetService extends ProfileService {
        }

        StringBuilder tempBuilder = new StringBuilder();
        tempBuilder.append("AVRCP version: " + mAvrcpVersion + "\n");

        if (mMediaPlayerList != null) {
            mMediaPlayerList.dump(tempBuilder);
        } else {
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.avrcp;

import android.os.SystemProperties;

/**
 * A class to represent an AVRCP version
 */
final class AvrcpVersion {
    public static final AvrcpVersion AVRCP_VERSION_1_3 = new AvrcpVersion(1, 3);
    public static final AvrcpVersion AVRCP_VERSION_1_4 = new AvrcpVersion(1, 4);
    public static final AvrcpVersion AVRCP_VERSION_1_5 = new AvrcpVersion(1, 5);
    public static final AvrcpVersion AVRCP_VERSION_1_6 = new AvrcpVersion(1, 6);

    // System settings version strings
    private static final String AVRCP_VERSION_PROPERTY = "persist.bluetooth.avrcpversion";
    private static final String AVRCP_VERSION_1_3_STRING = "avrcp13";
    private static final String AVRCP_VERSION_1_4_STRING = "avrcp14";
    private static final String AVRCP_VERSION_1_5_STRING = "avrcp15";
    private static final String AVRCP_VERSION_1_6_STRING = "avrcp16";

    public int major;
    public int minor;

    public static AvrcpVersion getCurrentSystemPropertiesValue() {
        String version = SystemProperties.get(AVRCP_VERSION_PROPERTY);
        switch (version) {
            case AVRCP_VERSION_1_3_STRING:
                return AVRCP_VERSION_1_3;
            case AVRCP_VERSION_1_4_STRING:
                return AVRCP_VERSION_1_4;
            case AVRCP_VERSION_1_5_STRING:
                return AVRCP_VERSION_1_5;
            case AVRCP_VERSION_1_6_STRING:
                return AVRCP_VERSION_1_6;
            default:
                return new AvrcpVersion(-1, -1);
        }
    }

    public boolean isAtleastVersion(AvrcpVersion version) {
        if (version == null) return true;
        if (major < version.major) return false;
        if (major > version.major) return true;
        if (minor < version.minor) return false;
        if (minor > version.minor) return true;
        return true;
    }

    AvrcpVersion(int majorVersion, int minorVersion) {
        major = majorVersion;
        minor = minorVersion;
    }

    public String toString() {
        if (major < 0 || minor < 0) return "Invalid";
        return major + "." + minor;
    }
}