| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 19 | import android.annotation.RequiresPermission; |
| Jeff Sharkey | d7c5566 | 2021-04-20 12:30:37 -0600 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
| Jeff Sharkey | d7c5566 | 2021-04-20 12:30:37 -0600 | [diff] [blame] | 21 | import android.annotation.SdkConstant.SdkConstantType; |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 22 | import android.bluetooth.annotations.RequiresBluetoothConnectPermission; |
| 23 | import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 24 | import android.content.AttributionSource; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 26 | import android.os.IBinder; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 27 | import android.os.RemoteException; |
| 28 | import android.util.Log; |
| 29 | |
| William Escande | 5e8e153 | 2024-03-27 18:02:23 +0000 | [diff] [blame] | 30 | import java.util.Collections; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 31 | import java.util.List; |
| 32 | |
| 33 | /** |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 34 | * This class provides the public APIs to control the Bluetooth AVRCP Controller. It currently |
| 35 | * supports player information, playback support and track metadata. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 36 | * |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 37 | * <p>BluetoothAvrcpController is a proxy object for controlling the Bluetooth AVRCP Service via |
| 38 | * IPC. Use {@link BluetoothAdapter#getProfileProxy} to get the BluetoothAvrcpController proxy |
| 39 | * object. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 40 | * |
| David Duarte | 5a02bb4 | 2023-12-04 23:07:42 +0000 | [diff] [blame] | 41 | * @hide |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 42 | */ |
| 43 | public final class BluetoothAvrcpController implements BluetoothProfile { |
| 44 | private static final String TAG = "BluetoothAvrcpController"; |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 45 | private static final boolean DBG = false; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 46 | private static final boolean VDBG = false; |
| 47 | |
| 48 | /** |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 49 | * Intent used to broadcast the change in connection state of the AVRCP Controller profile. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 50 | * |
| 51 | * <p>This intent will have 3 extras: |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 52 | * |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 53 | * <ul> |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 54 | * <li>{@link #EXTRA_STATE} - The current state of the profile. |
| 55 | * <li>{@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. |
| 56 | * <li>{@link BluetoothDevice#EXTRA_DEVICE} - The remote device. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 57 | * </ul> |
| 58 | * |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 59 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of {@link |
| 60 | * #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, {@link #STATE_CONNECTED}, {@link |
| 61 | * #STATE_DISCONNECTING}. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 62 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 63 | @RequiresLegacyBluetoothPermission |
| 64 | @RequiresBluetoothConnectPermission |
| 65 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jeff Sharkey | d7c5566 | 2021-04-20 12:30:37 -0600 | [diff] [blame] | 66 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 67 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 68 | "android.bluetooth.avrcp-controller.profile.action.CONNECTION_STATE_CHANGED"; |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 71 | * Intent used to broadcast the change in player application setting state on AVRCP AG. |
| 72 | * |
| 73 | * <p>This intent will have the following extras: |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 74 | * |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 75 | * <ul> |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 76 | * <li>{@link #EXTRA_PLAYER_SETTING} - {@link BluetoothAvrcpPlayerSettings} containing the |
| 77 | * most recent player setting. |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 78 | * </ul> |
| 79 | */ |
| Jeff Sharkey | d7c5566 | 2021-04-20 12:30:37 -0600 | [diff] [blame] | 80 | @RequiresBluetoothConnectPermission |
| 81 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| 82 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 83 | public static final String ACTION_PLAYER_SETTING = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 84 | "android.bluetooth.avrcp-controller.profile.action.PLAYER_SETTING"; |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 85 | |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 86 | public static final String EXTRA_PLAYER_SETTING = |
| 87 | "android.bluetooth.avrcp-controller.profile.extra.PLAYER_SETTING"; |
| 88 | |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 89 | private final BluetoothAdapter mAdapter; |
| 90 | private final AttributionSource mAttributionSource; |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 91 | |
| 92 | private IBluetoothAvrcpController mService; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 95 | * Create a BluetoothAvrcpController proxy object for interacting with the local Bluetooth AVRCP |
| 96 | * service. |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 97 | */ |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 98 | /* package */ BluetoothAvrcpController(Context context, BluetoothAdapter adapter) { |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 99 | mAdapter = adapter; |
| 100 | mAttributionSource = adapter.getAttributionSource(); |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 101 | mService = null; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| Santiago Seifert | efe4071 | 2023-01-06 13:54:17 +0000 | [diff] [blame] | 104 | /** @hide */ |
| 105 | @Override |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 106 | public void onServiceConnected(IBinder service) { |
| 107 | mService = IBluetoothAvrcpController.Stub.asInterface(service); |
| 108 | } |
| 109 | |
| 110 | /** @hide */ |
| 111 | @Override |
| 112 | public void onServiceDisconnected() { |
| 113 | mService = null; |
| Ugo Yu | 70d7659 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 114 | } |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 115 | |
| Ugo Yu | 70d7659 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 116 | private IBluetoothAvrcpController getService() { |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 117 | return mService; |
| 118 | } |
| 119 | |
| 120 | /** @hide */ |
| 121 | @Override |
| 122 | public BluetoothAdapter getAdapter() { |
| 123 | return mAdapter; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 126 | @Override |
| David Duarte | 5a02bb4 | 2023-12-04 23:07:42 +0000 | [diff] [blame] | 127 | @SuppressWarnings("Finalize") // empty finalize for api signature |
| David Duarte | f5b3bc5 | 2023-10-17 00:55:06 +0000 | [diff] [blame] | 128 | public void finalize() {} |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 129 | |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 130 | /** {@inheritDoc} */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 131 | @Override |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 132 | @RequiresBluetoothConnectPermission |
| 133 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 134 | public List<BluetoothDevice> getConnectedDevices() { |
| 135 | if (VDBG) log("getConnectedDevices()"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 136 | final IBluetoothAvrcpController service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 137 | if (service == null) { |
| 138 | Log.w(TAG, "Proxy not attached to service"); |
| 139 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 140 | } else if (isEnabled()) { |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 141 | try { |
| Jeff Sharkey | 98f3044 | 2021-06-03 09:26:53 -0600 | [diff] [blame] | 142 | return Attributable.setAttributionSource( |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 143 | service.getConnectedDevices(mAttributionSource), mAttributionSource); |
| 144 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 145 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| William Escande | 5e8e153 | 2024-03-27 18:02:23 +0000 | [diff] [blame] | 148 | return Collections.emptyList(); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 151 | /** {@inheritDoc} */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 152 | @Override |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 153 | @RequiresBluetoothConnectPermission |
| 154 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 155 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| 156 | if (VDBG) log("getDevicesMatchingStates()"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 157 | final IBluetoothAvrcpController service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 158 | if (service == null) { |
| 159 | Log.w(TAG, "Proxy not attached to service"); |
| 160 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 161 | } else if (isEnabled()) { |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 162 | try { |
| Jeff Sharkey | 98f3044 | 2021-06-03 09:26:53 -0600 | [diff] [blame] | 163 | return Attributable.setAttributionSource( |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 164 | service.getDevicesMatchingConnectionStates(states, mAttributionSource), |
| Jeff Sharkey | 43ee69e | 2021-04-23 14:13:57 -0600 | [diff] [blame] | 165 | mAttributionSource); |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 166 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 167 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| William Escande | 5e8e153 | 2024-03-27 18:02:23 +0000 | [diff] [blame] | 170 | return Collections.emptyList(); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 173 | /** {@inheritDoc} */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 174 | @Override |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 175 | @RequiresBluetoothConnectPermission |
| 176 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 177 | public int getConnectionState(BluetoothDevice device) { |
| 178 | if (VDBG) log("getState(" + device + ")"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 179 | final IBluetoothAvrcpController service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 180 | if (service == null) { |
| 181 | Log.w(TAG, "Proxy not attached to service"); |
| 182 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 183 | } else if (isEnabled() && isValidDevice(device)) { |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 184 | try { |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 185 | return service.getConnectionState(device, mAttributionSource); |
| 186 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 187 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 190 | return BluetoothProfile.STATE_DISCONNECTED; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Gets the player application settings. |
| 195 | * |
| David Duarte | 5a02bb4 | 2023-12-04 23:07:42 +0000 | [diff] [blame] | 196 | * @return the {@link BluetoothAvrcpPlayerSettings} or {@code null} if there is an error. |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 197 | */ |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 198 | @RequiresBluetoothConnectPermission |
| 199 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 200 | public BluetoothAvrcpPlayerSettings getPlayerSettings(BluetoothDevice device) { |
| 201 | if (DBG) Log.d(TAG, "getPlayerSettings"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 202 | final IBluetoothAvrcpController service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 203 | if (service == null) { |
| 204 | Log.w(TAG, "Proxy not attached to service"); |
| 205 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 206 | } else if (isEnabled()) { |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 207 | try { |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 208 | return service.getPlayerSettings(device, mAttributionSource); |
| 209 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 210 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 213 | return null; |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 217 | * Sets the player app setting for current player. returns true in case setting is supported by |
| 218 | * remote, false otherwise |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 219 | */ |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 220 | @RequiresBluetoothConnectPermission |
| 221 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 222 | public boolean setPlayerApplicationSetting(BluetoothAvrcpPlayerSettings plAppSetting) { |
| 223 | if (DBG) Log.d(TAG, "setPlayerApplicationSetting"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 224 | final IBluetoothAvrcpController service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 225 | if (service == null) { |
| 226 | Log.w(TAG, "Proxy not attached to service"); |
| 227 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 228 | } else if (isEnabled()) { |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 229 | try { |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 230 | service.setPlayerApplicationSetting(plAppSetting, mAttributionSource); |
| 231 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 232 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 235 | return false; |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 238 | /** |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 239 | * Send Group Navigation Command to Remote. possible keycode values: next_grp, previous_grp |
| 240 | * defined above |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 241 | */ |
| Jeff Sharkey | 3614e0a | 2021-04-16 15:34:54 -0600 | [diff] [blame] | 242 | @RequiresBluetoothConnectPermission |
| 243 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 244 | public void sendGroupNavigationCmd(BluetoothDevice device, int keyCode, int keyState) { |
| David Duarte | ee52b7e | 2023-12-02 01:32:11 +0000 | [diff] [blame] | 245 | Log.d( |
| 246 | TAG, |
| 247 | "sendGroupNavigationCmd dev = " |
| 248 | + device |
| 249 | + " key " |
| 250 | + keyCode |
| 251 | + " State = " |
| 252 | + keyState); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 253 | final IBluetoothAvrcpController service = getService(); |
| 254 | if (service == null) { |
| 255 | Log.w(TAG, "Proxy not attached to service"); |
| 256 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 257 | } else if (isEnabled()) { |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 258 | try { |
| William Escande | 879a70e | 2024-03-21 21:01:41 -0700 | [diff] [blame] | 259 | service.sendGroupNavigationCmd(device, keyCode, keyState, mAttributionSource); |
| 260 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 261 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| Sanket Agarwal | 25e84d4 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 266 | private boolean isEnabled() { |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 267 | return mAdapter.getState() == BluetoothAdapter.STATE_ON; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 270 | private static boolean isValidDevice(BluetoothDevice device) { |
| 271 | return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | private static void log(String msg) { |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 275 | Log.d(TAG, msg); |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 276 | } |
| 277 | } |