blob: 3d3d80e2b4dd6dcdeac63bda88400e9ee5ef22d0 [file] [log] [blame]
Sanket Agarwal1bec6a52015-10-21 18:23:27 -07001/*
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
17package android.bluetooth;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Log;
22
23import java.util.HashMap;
24import java.util.Map;
25
26/**
27 * Class used to identify settings associated with the player on AG.
28 *
29 * {@hide}
30 */
31public final class BluetoothAvrcpPlayerSettings implements Parcelable {
32 public static final String TAG = "BluetoothAvrcpPlayerSettings";
33
34 /**
35 * Equalizer setting.
36 */
Jack Hea355e5e2017-08-22 16:06:54 -070037 public static final int SETTING_EQUALIZER = 0x01;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070038
39 /**
40 * Repeat setting.
41 */
Jack Hea355e5e2017-08-22 16:06:54 -070042 public static final int SETTING_REPEAT = 0x02;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070043
44 /**
45 * Shuffle setting.
46 */
Jack Hea355e5e2017-08-22 16:06:54 -070047 public static final int SETTING_SHUFFLE = 0x04;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070048
49 /**
50 * Scan mode setting.
51 */
Jack Hea355e5e2017-08-22 16:06:54 -070052 public static final int SETTING_SCAN = 0x08;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070053
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 *
Jack He2992cd02017-08-22 21:21:23 -070085 * Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}.
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070086 */
Jack Hea355e5e2017-08-22 16:06:54 -070087 public static final int STATE_ALL_TRACK = 0x03;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070088
89 /**
90 * Group repeat/shuffle.
91 *
Jack He2992cd02017-08-22 21:21:23 -070092 * Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}.
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070093 */
Jack Hea355e5e2017-08-22 16:06:54 -070094 public static final int STATE_GROUP = 0x04;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070095
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
Jack He2992cd02017-08-22 21:21:23 -0700106 @Override
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700107 public int describeContents() {
108 return 0;
109 }
110
Jack He2992cd02017-08-22 21:21:23 -0700111 @Override
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700112 public void writeToParcel(Parcel out, int flags) {
113 out.writeInt(mSettings);
114 out.writeInt(mSettingsValue.size());
115 for (int k : mSettingsValue.keySet()) {
116 out.writeInt(k);
117 out.writeInt(mSettingsValue.get(k));
118 }
119 }
120
Jack He2992cd02017-08-22 21:21:23 -0700121 public static final Parcelable.Creator<BluetoothAvrcpPlayerSettings> CREATOR =
122 new Parcelable.Creator<BluetoothAvrcpPlayerSettings>() {
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700123 public BluetoothAvrcpPlayerSettings createFromParcel(Parcel in) {
124 return new BluetoothAvrcpPlayerSettings(in);
125 }
126
127 public BluetoothAvrcpPlayerSettings[] newArray(int size) {
128 return new BluetoothAvrcpPlayerSettings[size];
129 }
130 };
131
132 private BluetoothAvrcpPlayerSettings(Parcel in) {
133 mSettings = in.readInt();
134 int numSettings = in.readInt();
135 for (int i = 0; i < numSettings; i++) {
136 mSettingsValue.put(in.readInt(), in.readInt());
137 }
138 }
139
140 /**
141 * Create a new player settings object.
142 *
143 * @param settings a ORed value of SETTINGS_* defined above.
144 */
145 public BluetoothAvrcpPlayerSettings(int settings) {
146 mSettings = settings;
147 }
148
149 /**
150 * Get the supported settings.
151 *
152 * @return int ORed value of supported settings.
153 */
154 public int getSettings() {
155 return mSettings;
156 }
157
158 /**
159 * Add a setting value.
160 *
161 * The setting must be part of possible settings in {@link getSettings()}.
Jack Hea355e5e2017-08-22 16:06:54 -0700162 *
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700163 * @param setting setting config.
164 * @param value value for the setting.
165 * @throws IllegalStateException if the setting is not supported.
166 */
167 public void addSettingValue(int setting, int value) {
168 if ((setting & mSettings) == 0) {
169 Log.e(TAG, "Setting not supported: " + setting + " " + mSettings);
170 throw new IllegalStateException("Setting not supported: " + setting);
171 }
172 mSettingsValue.put(setting, value);
173 }
174
175 /**
176 * Get a setting value.
177 *
178 * The setting must be part of possible settings in {@link getSettings()}.
Jack Hea355e5e2017-08-22 16:06:54 -0700179 *
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700180 * @param setting setting config.
181 * @return value value for the setting.
182 * @throws IllegalStateException if the setting is not supported.
183 */
184 public int getSettingValue(int setting) {
185 if ((setting & mSettings) == 0) {
186 Log.e(TAG, "Setting not supported: " + setting + " " + mSettings);
187 throw new IllegalStateException("Setting not supported: " + setting);
188 }
189 Integer i = mSettingsValue.get(setting);
190 if (i == null) return -1;
191 return i;
192 }
193}