1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bluetooth.avrcp; 18 19 import android.os.SystemProperties; 20 21 /** A class to represent an AVRCP version */ 22 final class AvrcpVersion { 23 public static final AvrcpVersion AVRCP_VERSION_1_3 = new AvrcpVersion(1, 3); 24 public static final AvrcpVersion AVRCP_VERSION_1_4 = new AvrcpVersion(1, 4); 25 public static final AvrcpVersion AVRCP_VERSION_1_5 = new AvrcpVersion(1, 5); 26 public static final AvrcpVersion AVRCP_VERSION_1_6 = new AvrcpVersion(1, 6); 27 28 // System settings version strings 29 private static final String AVRCP_VERSION_PROPERTY = "persist.bluetooth.avrcpversion"; 30 private static final String AVRCP_VERSION_1_3_STRING = "avrcp13"; 31 private static final String AVRCP_VERSION_1_4_STRING = "avrcp14"; 32 private static final String AVRCP_VERSION_1_5_STRING = "avrcp15"; 33 private static final String AVRCP_VERSION_1_6_STRING = "avrcp16"; 34 35 public int major; 36 public int minor; 37 getCurrentSystemPropertiesValue()38 public static AvrcpVersion getCurrentSystemPropertiesValue() { 39 // Make sure this default version agrees with avrc_api.h's "AVRC_DEFAULT_VERSION" 40 String version = SystemProperties.get(AVRCP_VERSION_PROPERTY, AVRCP_VERSION_1_5_STRING); 41 switch (version) { 42 case AVRCP_VERSION_1_3_STRING: 43 return AVRCP_VERSION_1_3; 44 case AVRCP_VERSION_1_4_STRING: 45 return AVRCP_VERSION_1_4; 46 case AVRCP_VERSION_1_5_STRING: 47 return AVRCP_VERSION_1_5; 48 case AVRCP_VERSION_1_6_STRING: 49 return AVRCP_VERSION_1_6; 50 default: 51 return new AvrcpVersion(-1, -1); 52 } 53 } 54 isAtleastVersion(AvrcpVersion version)55 public boolean isAtleastVersion(AvrcpVersion version) { 56 if (version == null) return true; 57 if (major < version.major) return false; 58 if (major > version.major) return true; 59 if (minor < version.minor) return false; 60 if (minor > version.minor) return true; 61 return true; 62 } 63 AvrcpVersion(int majorVersion, int minorVersion)64 AvrcpVersion(int majorVersion, int minorVersion) { 65 major = majorVersion; 66 minor = minorVersion; 67 } 68 toString()69 public String toString() { 70 if (major < 0 || minor < 0) return "Invalid"; 71 return major + "." + minor; 72 } 73 } 74