• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /**
36      * Equalizer setting.
37      */
38     public static final int SETTING_EQUALIZER = 0x01;
39 
40     /**
41      * Repeat setting.
42      */
43     public static final int SETTING_REPEAT = 0x02;
44 
45     /**
46      * Shuffle setting.
47      */
48     public static final int SETTING_SHUFFLE = 0x04;
49 
50     /**
51      * Scan mode setting.
52      */
53     public static final int SETTING_SCAN = 0x08;
54 
55     /**
56      * Invalid state.
57      *
58      * Used for returning error codes.
59      */
60     public static final int STATE_INVALID = -1;
61 
62     /**
63      * OFF state.
64      *
65      * Denotes a general OFF state. Applies to all settings.
66      */
67     public static final int STATE_OFF = 0x00;
68 
69     /**
70      * ON state.
71      *
72      * Applies to {@link SETTING_EQUALIZER}.
73      */
74     public static final int STATE_ON = 0x01;
75 
76     /**
77      * Single track repeat.
78      *
79      * Applies only to {@link SETTING_REPEAT}.
80      */
81     public static final int STATE_SINGLE_TRACK = 0x02;
82 
83     /**
84      * All track repeat/shuffle.
85      *
86      * Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}.
87      */
88     public static final int STATE_ALL_TRACK = 0x03;
89 
90     /**
91      * Group repeat/shuffle.
92      *
93      * Applies to {@link #SETTING_REPEAT}, {@link #SETTING_SHUFFLE} and {@link #SETTING_SCAN}.
94      */
95     public static final int STATE_GROUP = 0x04;
96 
97     /**
98      * List of supported settings ORed.
99      */
100     private int mSettings;
101 
102     /**
103      * Hash map of current capability values.
104      */
105     private Map<Integer, Integer> mSettingsValue = new HashMap<Integer, Integer>();
106 
107     @Override
describeContents()108     public int describeContents() {
109         return 0;
110     }
111 
112     @Override
writeToParcel(Parcel out, int flags)113     public void writeToParcel(Parcel out, int flags) {
114         out.writeInt(mSettings);
115         out.writeInt(mSettingsValue.size());
116         for (int k : mSettingsValue.keySet()) {
117             out.writeInt(k);
118             out.writeInt(mSettingsValue.get(k));
119         }
120     }
121 
122     public static final @NonNull Creator<BluetoothAvrcpPlayerSettings> CREATOR = new Creator<>() {
123         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 
BluetoothAvrcpPlayerSettings(Parcel in)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      */
BluetoothAvrcpPlayerSettings(int settings)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      */
getSettings()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()}.
162      *
163      * @param setting setting config.
164      * @param value value for the setting.
165      * @throws IllegalStateException if the setting is not supported.
166      */
addSettingValue(int setting, int value)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()}.
179      *
180      * @param setting setting config.
181      * @return value value for the setting.
182      * @throws IllegalStateException if the setting is not supported.
183      */
getSettingValue(int setting)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 }
194