AvrcpNativeInterface.java revision 3cf7e318416748f0e57be387bd94820a34ef1185
1/*
2 * Copyright 2018 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 com.android.bluetooth.avrcp;
18
19import android.util.Log;
20
21import java.util.List;
22
23/**
24 * Native Interface to communicate with the JNI layer. This class should never be passed null
25 * data.
26 */
27public class AvrcpNativeInterface {
28    private static final String TAG = "NewAvrcpNativeInterface";
29    private static final boolean DEBUG = true;
30    private static AvrcpNativeInterface sInstance;
31
32    static {
33        classInitNative();
34    }
35
36    static AvrcpNativeInterface getInterface() {
37        if (sInstance == null) {
38            sInstance = new AvrcpNativeInterface();
39        }
40
41        return sInstance;
42    }
43
44    // TODO (apanicke): Hook into the AVRCP Service when checked in
45    void init(/* AvrcpTargetService service */) {
46        d("Init AvrcpNativeInterface");
47        initNative();
48    }
49
50    void cleanup() {
51        d("Cleanup AvrcpNativeInterface");
52        cleanupNative();
53    }
54
55    Metadata getCurrentSongInfo() {
56        d("getCurrentSongInfo");
57        // TODO (apanicke): Hook into the AVRCP Service when checked in
58        return null;
59    }
60
61    PlayStatus getPlayStatus() {
62        d("getPlayStatus");
63        // TODO (apanicke): Hook into the AVRCP Service when checked in
64        return null;
65    }
66
67    void sendMediaKeyEvent(int keyEvent, int state) {
68        d("sendMediaKeyEvent: keyEvent=" + keyEvent + " state=" + state);
69        // TODO (apanicke): Hook into the AVRCP Service when checked in
70    }
71
72    String getCurrentMediaId() {
73        d("getCurrentMediaId");
74        // TODO (apanicke): Hook into the AVRCP Service when checked in
75        return null;
76    }
77
78    List<Metadata> getNowPlayingList() {
79        d("getNowPlayingList");
80        // TODO (apanicke): Hook into the AVRCP Service when checked in
81        return null;
82    }
83
84    int getCurrentPlayerId() {
85        d("getCurrentPlayerId");
86        // TODO (apanicke): Hook into the AVRCP Service when checked in
87        return -1;
88    }
89
90    List<PlayerInfo> getMediaPlayerList() {
91        d("getMediaPlayerList");
92        // TODO (apanicke): Hook into the AVRCP Service when checked in
93        return null;
94    }
95
96    // TODO(apanicke): This shouldn't be named setBrowsedPlayer as it doesn't actually connect
97    // anything internally. It just returns the number of items in the root folder.
98    void setBrowsedPlayer(int playerId) {
99        d("setBrowsedPlayer: playerId=" + playerId);
100        // TODO (apanicke): Hook into the AVRCP Service when checked in
101    }
102
103    void getFolderItemsRequest(int playerId, String mediaId) {
104        d("getFolderItemsRequest: playerId=" + playerId + " mediaId=" + mediaId);
105        // TODO (apanicke): Hook into the AVRCP Service when checked in
106    }
107
108    void setBrowsedPlayerResponse(int playerId, boolean success, String rootId, int numItems) {
109        d("setBrowsedPlayerResponse: playerId=" + playerId
110                + " success=" + success
111                + " rootId=" + rootId
112                + " numItems=" + numItems);
113        setBrowsedPlayerResponseNative(playerId, success, rootId, numItems);
114    }
115
116    void getFolderItemsResponse(String parentId, List<ListItem> items) {
117        d("getFolderItemsResponse: parentId=" + parentId + " items.size=" + items.size());
118        getFolderItemsResponseNative(parentId, items);
119    }
120
121    void sendMediaUpdate(boolean metadata, boolean playStatus, boolean queue) {
122        d("sendMediaUpdate: metadata=" + metadata
123                + " playStatus=" + playStatus
124                + " queue=" + queue);
125        sendMediaUpdateNative(metadata, playStatus, queue);
126    }
127
128    void sendFolderUpdate(boolean availablePlayers, boolean addressedPlayers, boolean uids) {
129        d("sendFolderUpdate: availablePlayers=" + availablePlayers
130                + " addressedPlayers=" + addressedPlayers
131                + " uids=" + uids);
132        sendFolderUpdateNative(availablePlayers, addressedPlayers, uids);
133    }
134
135    void playItem(int playerId, boolean nowPlaying, String mediaId) {
136        d("playItem: playerId=" + playerId + " nowPlaying=" + nowPlaying + " mediaId" + mediaId);
137        // TODO (apanicke): Hook into the AVRCP Service when checked in
138    }
139
140    boolean connectDevice(String bdaddr) {
141        d("connectDevice: bdaddr=" + bdaddr);
142        return connectDeviceNative(bdaddr);
143    }
144
145    boolean disconnectDevice(String bdaddr) {
146        d("disconnectDevice: bdaddr=" + bdaddr);
147        return disconnectDeviceNative(bdaddr);
148    }
149
150    void setActiveDevice(String bdaddr) {
151        d("setActiveDevice: bdaddr=" + bdaddr);
152        // TODO (apanicke): Hook into the AVRCP Service when checked in
153    }
154
155    void deviceConnected(String bdaddr, boolean absoluteVolume) {
156        d("deviceConnected: bdaddr=" + bdaddr + " absoluteVolume=" + absoluteVolume);
157        // TODO (apanicke): Hook into the AVRCP Service when checked in
158    }
159
160    void deviceDisconnected(String bdaddr) {
161        d("deviceDisconnected: bdaddr=" + bdaddr);
162        // TODO (apanicke): Hook into the AVRCP Service when checked in
163    }
164
165    void sendVolumeChanged(int volume) {
166        d("sendVolumeChanged: volume=" + volume);
167        sendVolumeChangedNative(volume);
168    }
169
170    void setVolume(int volume) {
171        d("setVolume: volume=" + volume);
172        // TODO (apanicke): Hook into the AVRCP Service when checked in
173    }
174
175    private static native void classInitNative();
176    private native void initNative();
177    private native void sendMediaUpdateNative(
178            boolean trackChanged, boolean playState, boolean playPos);
179    private native void sendFolderUpdateNative(
180            boolean availablePlayers, boolean addressedPlayers, boolean uids);
181    private native void setBrowsedPlayerResponseNative(
182            int playerId, boolean success, String rootId, int numItems);
183    private native void getFolderItemsResponseNative(String parentId, List<ListItem> list);
184    private native void cleanupNative();
185    private native boolean connectDeviceNative(String bdaddr);
186    private native boolean disconnectDeviceNative(String bdaddr);
187    private native void sendVolumeChangedNative(int volume);
188
189    private static void d(String msg) {
190        if (DEBUG) {
191            Log.d(TAG, msg);
192        }
193    }
194}
195