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 com.android.bluetooth.avrcp;
18 
19 import android.util.Log;
20 
21 import com.android.bluetooth.Utils;
22 
23 import java.nio.ByteBuffer;
24 import java.nio.charset.Charset;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 
30 /**
31  * Provides Bluetooth AVRCP Controller profile, as a service in the Bluetooth application.
32  * TODO(sanketa): Rip out this feature as this is part of 1.6.
33  * @hide
34  */
35 public class NowPlaying {
36     private static final boolean DBG = true;
37     private static final String TAG = "NowPlaying";
38 
39     RemoteDevice mDevice;
40     private TrackInfo mCurrTrack;
41 
42     private ArrayList<TrackInfo> mNowPlayingList;
43 
NowPlaying(RemoteDevice mRemoteDevice)44     public NowPlaying(RemoteDevice mRemoteDevice) {
45         mDevice = mRemoteDevice;
46         mNowPlayingList = new ArrayList<TrackInfo>();
47         mCurrTrack = null;
48     }
49 
cleanup()50     public void cleanup() {
51         mDevice = null;
52         if(mNowPlayingList != null) {
53             mNowPlayingList.clear();
54         }
55         mCurrTrack = null;
56     }
57 
getDeviceRecords()58     public RemoteDevice getDeviceRecords() {
59         return mDevice;
60     }
61 
addTrack(TrackInfo mTrack)62     public void addTrack (TrackInfo mTrack) {
63         if(mNowPlayingList != null) {
64             mNowPlayingList.add(mTrack);
65         }
66     }
67 
setCurrTrack(TrackInfo mTrack)68     public void setCurrTrack (TrackInfo mTrack) {
69         mCurrTrack = mTrack;
70     }
71 
getCurrentTrack()72     public TrackInfo getCurrentTrack() {
73         return mCurrTrack;
74     }
75 
updateCurrentTrack(TrackInfo mTrack)76     public void updateCurrentTrack(TrackInfo mTrack) {
77         mCurrTrack.mAlbumTitle = mTrack.mAlbumTitle;
78         mCurrTrack.mArtistName = mTrack.mArtistName;
79         mCurrTrack.mGenre = mTrack.mGenre;
80         mCurrTrack.mTotalTracks = mTrack.mTotalTracks;
81         mCurrTrack.mTrackLen = mTrack.mTrackLen;
82         mCurrTrack.mTrackTitle = mTrack.mTrackTitle;
83         mCurrTrack.mTrackNum = mTrack.mTrackNum;
84     }
85 
getTrackFromId(int mTrackId)86     public TrackInfo getTrackFromId(int mTrackId) {
87         if(mTrackId == 0)
88             return getCurrentTrack();
89         else {
90             for(TrackInfo mTrackInfo: mNowPlayingList) {
91                 if(mTrackInfo.mItemUid == mTrackId)
92                     return mTrackInfo;
93             }
94             return null;
95         }
96     }
97 }
98