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 /** 22 * A class to represent an AVRCP version 23 */ 24 final class AvrcpVersion { 25 public static final AvrcpVersion AVRCP_VERSION_1_3 = new AvrcpVersion(1, 3); 26 public static final AvrcpVersion AVRCP_VERSION_1_4 = new AvrcpVersion(1, 4); 27 public static final AvrcpVersion AVRCP_VERSION_1_5 = new AvrcpVersion(1, 5); 28 public static final AvrcpVersion AVRCP_VERSION_1_6 = new AvrcpVersion(1, 6); 29 30 // System settings version strings 31 private static final String AVRCP_VERSION_PROPERTY = "persist.bluetooth.avrcpversion"; 32 private static final String AVRCP_VERSION_1_3_STRING = "avrcp13"; 33 private static final String AVRCP_VERSION_1_4_STRING = "avrcp14"; 34 private static final String AVRCP_VERSION_1_5_STRING = "avrcp15"; 35 private static final String AVRCP_VERSION_1_6_STRING = "avrcp16"; 36 37 public int major; 38 public int minor; 39 getCurrentSystemPropertiesValue()40 public static AvrcpVersion getCurrentSystemPropertiesValue() { 41 String version = SystemProperties.get(AVRCP_VERSION_PROPERTY); 42 switch (version) { 43 case AVRCP_VERSION_1_3_STRING: 44 return AVRCP_VERSION_1_3; 45 case AVRCP_VERSION_1_4_STRING: 46 return AVRCP_VERSION_1_4; 47 case AVRCP_VERSION_1_5_STRING: 48 return AVRCP_VERSION_1_5; 49 case AVRCP_VERSION_1_6_STRING: 50 return AVRCP_VERSION_1_6; 51 default: 52 return new AvrcpVersion(-1, -1); 53 } 54 } 55 isAtleastVersion(AvrcpVersion version)56 public boolean isAtleastVersion(AvrcpVersion version) { 57 if (version == null) return true; 58 if (major < version.major) return false; 59 if (major > version.major) return true; 60 if (minor < version.minor) return false; 61 if (minor > version.minor) return true; 62 return true; 63 } 64 AvrcpVersion(int majorVersion, int minorVersion)65 AvrcpVersion(int majorVersion, int minorVersion) { 66 major = majorVersion; 67 minor = minorVersion; 68 } 69 toString()70 public String toString() { 71 if (major < 0 || minor < 0) return "Invalid"; 72 return major + "." + minor; 73 } 74 } 75