summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth/BluetoothAvrcpInfo.java
blob: a815d101830f937776c6cf296e16b432f55bee37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

package android.bluetooth;

import java.util.ArrayList;
import android.util.Log;

import android.os.Parcel;
import android.os.Parcelable;
import android.provider.BaseColumns;
import android.net.Uri;

/**
 * Represents the AVRCP Metadata of remote Bluetooth Device.
 *
 * {@see BluetoothAvrcpController}
 *
 * {@hide}
 */
public final class BluetoothAvrcpInfo implements Parcelable, BaseColumns{

    private byte[] supportedPlayerAttributes;// attributes supported
    private byte[] numSupportedPlayerAttribValues; // number of values of each attribute
    private String TAG = "BluetoothAvrcpInfo";
    /*
     * This would a list of values of all AttributeIds
     */
    private byte[] supportedPlayerAtribValues; // actual values lies here.

    /* Default Constructor */
    public BluetoothAvrcpInfo() {
        supportedPlayerAttributes = null;
        numSupportedPlayerAttribValues = null;
        supportedPlayerAtribValues = null;
    }
    public BluetoothAvrcpInfo(byte[] attribIds, byte[] numValueSupported, byte[] valuesSupported) {
        int numAttributes = attribIds.length;
        int zz = 0;
        supportedPlayerAttributes = new byte[numAttributes];
        numSupportedPlayerAttribValues = new byte[numAttributes];
        supportedPlayerAtribValues = new byte[valuesSupported.length];
        for (zz = 0; zz < numAttributes; zz++) {
            supportedPlayerAttributes[zz] = attribIds[zz];
            numSupportedPlayerAttribValues[zz] = numValueSupported[zz];
        }
        for (zz = 0; zz < supportedPlayerAtribValues.length; zz++)
            supportedPlayerAtribValues[zz] = valuesSupported[zz];
    }
    /*
     * Reading Structure back from Paracel
     */
    public BluetoothAvrcpInfo(Parcel source){
        ArrayList<Byte> attribs =  new ArrayList<Byte>();
        ArrayList<Byte> numAttribVal =  new ArrayList<Byte>();
        ArrayList<Byte> attribVals =  new ArrayList<Byte>();
        Byte numAttributes = source.readByte();
        /*
         * Read from Source
         */
        for(int xx = 0; xx < numAttributes ; xx++) {
            attribs.add(source.readByte());
            numAttribVal.add(source.readByte());
            for (int zz = 0; zz < numAttribVal.get(xx); zz++) {
                attribVals.add(source.readByte());
            }
        }

        /*
         * Write Back to Private Data Structures
         */
        supportedPlayerAttributes =  new byte[attribs.size()];
        for (int zz = 0; zz< attribs.size(); zz++) {
            supportedPlayerAttributes[zz] = attribs.get(zz);
        }

        numSupportedPlayerAttribValues =  new byte[numAttribVal.size()];
        for (int zz = 0; zz< numAttribVal.size(); zz++) {
            numSupportedPlayerAttribValues[zz] = numAttribVal.get(zz);
        }

        supportedPlayerAtribValues =  new byte[attribVals.size()];
        for (int zz = 0; zz< attribVals.size(); zz++) {
            supportedPlayerAtribValues[zz] = attribVals.get(zz);
        }
    }

    public int describeContents() {
        return 0;
    }

    /* While flatenning the structure we would use the follwing way
     * NumAttributes,ID, numValues, Values
     */
    public void writeToParcel(Parcel out, int flags) {
        byte numSuppAttributes = (byte)supportedPlayerAttributes.length;
        out.writeByte(numSuppAttributes);
        for (int xx = 0; xx < numSuppAttributes; xx++) {
            out.writeByte(supportedPlayerAttributes[xx]);
            out.writeByte(numSupportedPlayerAttribValues[xx]);
            for (int zz = 0; zz < numSupportedPlayerAttribValues[xx]; zz++) {
                out.writeByte(supportedPlayerAtribValues[zz]);
            }
        }
    }

    public byte[] getSupportedPlayerAttributes() {
        return supportedPlayerAttributes;
    }

    public byte getNumSupportedPlayerAttributeVal(byte playerAttributeId) {
        for (int zz = 0; zz < supportedPlayerAttributes.length; zz++) {
            if (playerAttributeId == supportedPlayerAttributes[zz]) {
                return numSupportedPlayerAttribValues[zz];
            }
        }
        return 0;
    }

    public byte[] getSupportedPlayerAttributeVlaues (byte playerAttributeId) {
        int index = 0;
        int zz = 0;
        boolean attributeFound = false;
        for (zz = 0; zz < supportedPlayerAttributes.length; zz++) {
            if (playerAttributeId == supportedPlayerAttributes[zz]) {
                attributeFound = true;
                break;
            }
            else
               index = index + numSupportedPlayerAttribValues[zz];
        }
        if (attributeFound) {
            byte[] supportedValues =  new byte[numSupportedPlayerAttribValues[zz]];
            for (int xx = 0; xx < numSupportedPlayerAttribValues[zz]; xx++)
                supportedValues[xx] = supportedPlayerAtribValues[xx + index];
            return supportedValues;
        }
        else
            return new byte[0];
    }
    public void putPlayerSettingAttributes(byte[] attribIds, byte[] numValueSupported, byte[] valuesSupported) {
        int numAttributes = attribIds.length;
        int zz = 0;
        supportedPlayerAttributes = new byte[numAttributes];
        numSupportedPlayerAttribValues = new byte[numAttributes];
        supportedPlayerAtribValues = new byte[valuesSupported.length];
        for (zz = 0; zz < numAttributes; zz++) {
            supportedPlayerAttributes[zz] = attribIds[zz];
            numSupportedPlayerAttribValues[zz] = numValueSupported[zz];
        }
        for (zz = 0; zz < supportedPlayerAtribValues.length; zz++)
            supportedPlayerAtribValues[zz] = valuesSupported[zz];
   }
    public static final Parcelable.Creator<BluetoothAvrcpInfo> CREATOR =
        new Parcelable.Creator<BluetoothAvrcpInfo>() {
            public BluetoothAvrcpInfo createFromParcel(Parcel in) {
                return new BluetoothAvrcpInfo(in);
            }
            public BluetoothAvrcpInfo[] newArray(int size) {
                return new BluetoothAvrcpInfo[size];
            }
    };

    public static final String PERMISSION_ACCESS = "android.permission.ACCESS_BLUETOOTH_AVRCP_CT_DATA";
    public static final Uri CONTENT_URI = Uri.parse("content://com.android.bluetooth.avrcp/btavrcp_ct");

    /*
     * BaseColumns already has _ID and COUNT values
     * Below mentioned strings are used to implement different columns
     * of AVRCP MetaData table.
     * TRACK_NUM       : Ineteger value containing the order number of
     *                   the audio-file on its original recording.
     *                   Numeric ASCII string converted to Integer
     * TITLE           : Text field representing the title, song name
     * ARTIST_NAME     : Text field representing artist(s), performer(s)
     * ALBUM_NAME      : Text field representing the title of the recording
     *                   (source) from which the audio in the file is taken.
     * TOTAL_TRACKS    : Integet value containing the total number of tracks
     *                   or elements on the original recording.
     * GENRE           : Text field representing the category of the composition
     *                   characterized by a particular style.
     * PLAYING_TIME    : Integer containing the length of the audio file in
     *                   milliseconds for eg 02:30 = 150000
     * PLAY_STATUS     : Text feild showing current state of track. Possible
     *                   values would be Playing, Stopped, Paused, Forward_Seek
     *                   REV_SEEK
     * REPEAT_STATUS   : String describing Repeat mode status on remote Media Player
     *                   Posible values "NOT SUPPORTED", "OFF" "Single Track Repeat"
     *                   "All Track Repeat" "Group Repeat"
     * SHUFFLE_STATUS  : String describing Shuffle mode status on remote Media Player
     *                   Posible values "NOT SUPPORTED", "OFF" "All Track Shuffle"
     *                   "Group Shuffle"
     * SCAN_STAUS      : String describing SCAN mode status on remote Media Player
     *                   Possible values "NOT SUPPORTED", "OFF","ALL Tracks Scan"
     *                   "Group Scan"
     *
     * EQUALIZER_STATUS: String describing EQUALIZER mode status on remote Media Player
     *                   Possible values "NOT SUPPORTED", "OFF","ON"
     */
    public static final String TRACK_NUM = "track_num";
    public static final String TITLE = "title";
    public static final String ARTIST_NAME = "artist_name";
    public static final String ALBUM_NAME = "album_name";
    public static final String TOTAL_TRACKS = "total_tracks";
    public static final String GENRE = "genre";
    public static final String PLAYING_TIME = "playing_time";
    public static final String TOTAL_TRACK_TIME = "total_track_time";
    public static final String PLAY_STATUS = "play_status";
    public static final String REPEAT_STATUS = "repeat_status";
    public static final String SHUFFLE_STATUS = "shuffle_status";
    public static final String SCAN_STATUS = "scan_status";
    public static final String EQUALIZER_STATUS = "equalizer_status";

    /*
     * Default values for each of the items
    */
    public static final int TRACK_NUM_INVALID = 0xFF;
    public static final String TITLE_INVALID = "NOT_SUPPORTED";
    public static final String ARTIST_NAME_INVALID = "NOT_SUPPORTED";
    public static final String ALBUM_NAME_INVALID = "NOT_SUPPORTED";
    public static final int TOTAL_TRACKS_INVALID = 0xFF;
    public static final String GENRE_INVALID = "NOT_SUPPORTED";
    public static final int PLAYING_TIME_INVALID = 0xFF;
    public static final int TOTAL_TRACK_TIME_INVALID = 0xFF;
    public static final String PLAY_STATUS_INVALID = "NOT_SUPPORTED";
    public static final String REPEAT_STATUS_INVALID = "NOT_SUPPORTED";
    public static final String SHUFFLE_STATUS_INVALID = "NOT_SUPPORTED";
    public static final String SCAN_STATUS_INVALID = "NOT_SUPPORTED";
    public static final String EQUALIZER_STATUS_INVALID = "NOT_SUPPORTED";

    /*
     *Element Id Values for GetMetaData
    */
    public static final int MEDIA_ATTRIBUTE_ALL = 0x00;
    public static final int MEDIA_ATTRIBUTE_TITLE = 0x01;
    public static final int MEDIA_ATTRIBUTE_ARTIST_NAME = 0x02;
    public static final int MEDIA_ATTRIBUTE_ALBUM_NAME = 0x03;
    public static final int MEDIA_ATTRIBUTE_TRACK_NUMBER = 0x04;
    public static final int MEDIA_ATTRIBUTE_TOTAL_TRACK_NUMBER = 0x05;
    public static final int MEDIA_ATTRIBUTE_GENRE = 0x06;
    public static final int MEDIA_ATTRIBUTE_PLAYING_TIME = 0x07;

    /*
     *PlayStatusId Values for GetPlayStatus
    */
    public static final int MEDIA_PLAYSTATUS_ALL = 0x08;
    public static final int MEDIA_PLAYSTATUS_SONG_TOTAL_LEN = 0x09;
    public static final int MEDIA_PLAYSTATUS_SONG_CUR_POS = 0x0a;
    public static final int MEDIA_PLAYSTATUS_SONG_PLAY_STATUS = 0x0b;

    /*
     * Values for SetPlayerApplicationSettings
    */
    public static final byte ATTRIB_EQUALIZER_STATUS = 0x01;
    public static final byte ATTRIB_REPEAT_STATUS = 0x02;
    public static final byte ATTRIB_SHUFFLE_STATUS = 0x03;
    public static final byte ATTRIB_SCAN_STATUS = 0x04;

    public static final byte EQUALIZER_STATUS_OFF = 0x01;
    public static final byte EQUALIZER_STATUS_ON = 0x02;

    public static final byte REPEAT_STATUS_OFF = 0x01;
    public static final byte REPEAT_STATUS_SINGLE_TRACK_REPEAT = 0x02;
    public static final byte REPEAT_STATUS_ALL_TRACK_REPEAT = 0x03;
    public static final byte REPEAT_STATUS_GROUP_REPEAT = 0x04;

    public static final byte SHUFFLE_STATUS_OFF = 0x01;
    public static final byte SHUFFLE_STATUS_ALL_TRACK_SHUFFLE = 0x02;
    public static final byte SHUFFLE_STATUS_GROUP_SHUFFLE = 0x03;

    public static final byte SCAN_STATUS_OFF = 0x01;
    public static final byte SCAN_STATUS_ALL_TRACK_SCAN = 0x02;
    public static final byte SCAN_STATUS_GROUP_SCAN = 0x03;

    public static final int BTRC_FEAT_METADATA = 0x01;
    public static final int BTRC_FEAT_ABSOLUTE_VOLUME = 0x02;
    public static final int BTRC_FEAT_BROWSE = 0x04;

}