1 /* 2 * Copyright (C) 2015 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 android.bluetooth; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.Log; 23 24 import java.util.HashMap; 25 import java.util.Map; 26 27 /** 28 * Class used to identify settings associated with the player on AG. 29 * 30 * @hide 31 */ 32 public final class BluetoothAvrcpPlayerSettings implements Parcelable { 33 public static final String TAG = "BluetoothAvrcpPlayerSettings"; 34 35 /** Equalizer setting. */ 36 public static final int SETTING_EQUALIZER = 0x01; 37 38 /** Repeat setting. */ 39 public static final int SETTING_REPEAT = 0x02; 40 41 /** Shuffle setting. */ 42 public static final int SETTING_SHUFFLE = 0x04; 43 44 /** Scan mode setting. */ 45 public static final int SETTING_SCAN = 0x08; 46 47 /** 48 * Invalid state. 49 * 50 * <p>Used for returning error codes. 51 */ 52 public static final int STATE_INVALID = -1; 53 54 /** 55 * OFF state. 56 * 57 * <p>Denotes a general OFF state. Applies to all settings. 58 */ 59 public static final int STATE_OFF = 0x00; 60 61 /** 62 * ON state. 63 * 64 * <p>Applies to {@link SETTING_EQUALIZER}. 65 */ 66 public static final int STATE_ON = 0x01; 67 68 /** 69 * Single track repeat. 70 * 71 * <p>Applies only to {@link SETTING_REPEAT}. 72 */ 73 public static final int STATE_SINGLE_TRACK = 0x02; 74 75 /** 76 * All track repeat/shuffle. 77 * 78 * <p>Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}. 79 */ 80 public static final int STATE_ALL_TRACK = 0x03; 81 82 /** 83 * Group repeat/shuffle. 84 * 85 * <p>Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}. 86 */ 87 public static final int STATE_GROUP = 0x04; 88 89 /** List of supported settings ORed. */ 90 private int mSettings; 91 92 /** Hash map of current capability values. */ 93 private Map<Integer, Integer> mSettingsValue = new HashMap<Integer, Integer>(); 94 95 @Override describeContents()96 public int describeContents() { 97 return 0; 98 } 99 100 @Override writeToParcel(Parcel out, int flags)101 public void writeToParcel(Parcel out, int flags) { 102 out.writeInt(mSettings); 103 out.writeInt(mSettingsValue.size()); 104 for (int k : mSettingsValue.keySet()) { 105 out.writeInt(k); 106 out.writeInt(mSettingsValue.get(k)); 107 } 108 } 109 110 public static final @NonNull Creator<BluetoothAvrcpPlayerSettings> CREATOR = 111 new Creator<>() { 112 public BluetoothAvrcpPlayerSettings createFromParcel(Parcel in) { 113 return new BluetoothAvrcpPlayerSettings(in); 114 } 115 116 public BluetoothAvrcpPlayerSettings[] newArray(int size) { 117 return new BluetoothAvrcpPlayerSettings[size]; 118 } 119 }; 120 BluetoothAvrcpPlayerSettings(Parcel in)121 private BluetoothAvrcpPlayerSettings(Parcel in) { 122 mSettings = in.readInt(); 123 int numSettings = in.readInt(); 124 for (int i = 0; i < numSettings; i++) { 125 mSettingsValue.put(in.readInt(), in.readInt()); 126 } 127 } 128 129 /** 130 * Create a new player settings object. 131 * 132 * @param settings a ORed value of SETTINGS_* defined above. 133 */ BluetoothAvrcpPlayerSettings(int settings)134 public BluetoothAvrcpPlayerSettings(int settings) { 135 mSettings = settings; 136 } 137 138 /** 139 * Get the supported settings. 140 * 141 * @return int ORed value of supported settings. 142 */ getSettings()143 public int getSettings() { 144 return mSettings; 145 } 146 147 /** 148 * Add a setting value. 149 * 150 * <p>The setting must be part of possible settings in {@link getSettings()}. 151 * 152 * @param setting setting config. 153 * @param value value for the setting. 154 * @throws IllegalStateException if the setting is not supported. 155 */ addSettingValue(int setting, int value)156 public void addSettingValue(int setting, int value) { 157 if ((setting & mSettings) == 0) { 158 Log.e(TAG, "Setting not supported: " + setting + " " + mSettings); 159 throw new IllegalStateException("Setting not supported: " + setting); 160 } 161 mSettingsValue.put(setting, value); 162 } 163 164 /** 165 * Get a setting value. 166 * 167 * <p>The setting must be part of possible settings in {@link getSettings()}. 168 * 169 * @param setting setting config. 170 * @return value value for the setting. 171 * @throws IllegalStateException if the setting is not supported. 172 */ getSettingValue(int setting)173 public int getSettingValue(int setting) { 174 if ((setting & mSettings) == 0) { 175 Log.e(TAG, "Setting not supported: " + setting + " " + mSettings); 176 throw new IllegalStateException("Setting not supported: " + setting); 177 } 178 Integer i = mSettingsValue.get(setting); 179 if (i == null) return -1; 180 return i; 181 } 182 } 183