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