Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [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 | |
Mike Lockwood | b673770 | 2015-02-20 08:28:47 -0800 | [diff] [blame] | 17 | package android.media.midi; |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 18 | |
| 19 | import android.os.Bundle; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
Mikhail Naganov | 33603ae | 2016-09-27 10:42:53 -0700 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 25 | /** |
| 26 | * This class contains information to describe a MIDI device. |
| 27 | * For now we only have information that can be retrieved easily for USB devices, |
| 28 | * but we will probably expand this in the future. |
| 29 | * |
| 30 | * This class is just an immutable object to encapsulate the MIDI device description. |
| 31 | * Use the MidiDevice class to actually communicate with devices. |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 32 | */ |
Mike Lockwood | be215dd | 2015-03-07 11:04:59 -0800 | [diff] [blame] | 33 | public final class MidiDeviceInfo implements Parcelable { |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 34 | |
| 35 | private static final String TAG = "MidiDeviceInfo"; |
| 36 | |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 37 | /* |
| 38 | * Please note that constants and (un)marshalling code need to be kept in sync |
| 39 | * with the native implementation (MidiDeviceInfo.h|cpp) |
| 40 | */ |
| 41 | |
Mike Lockwood | 78beecf | 2014-12-11 09:15:23 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Constant representing USB MIDI devices for {@link #getType} |
| 44 | */ |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 45 | public static final int TYPE_USB = 1; |
Mike Lockwood | 78beecf | 2014-12-11 09:15:23 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Constant representing virtual (software based) MIDI devices for {@link #getType} |
| 49 | */ |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 50 | public static final int TYPE_VIRTUAL = 2; |
| 51 | |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 52 | /** |
Mike Lockwood | 3f5acc6 | 2015-03-17 13:21:03 -0700 | [diff] [blame] | 53 | * Constant representing Bluetooth MIDI devices for {@link #getType} |
| 54 | */ |
| 55 | public static final int TYPE_BLUETOOTH = 3; |
| 56 | |
| 57 | /** |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 58 | * Bundle key for the device's user visible name property. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 59 | * The value for this property is of type {@link java.lang.String}. |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 60 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties}. |
| 61 | * For USB devices, this is a concatenation of the manufacturer and product names. |
| 62 | */ |
| 63 | public static final String PROPERTY_NAME = "name"; |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 64 | |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Bundle key for the device's manufacturer name property. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 67 | * The value for this property is of type {@link java.lang.String}. |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 68 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties}. |
| 69 | * Matches the USB device manufacturer name string for USB MIDI devices. |
| 70 | */ |
| 71 | public static final String PROPERTY_MANUFACTURER = "manufacturer"; |
| 72 | |
| 73 | /** |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 74 | * Bundle key for the device's product name property. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 75 | * The value for this property is of type {@link java.lang.String}. |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 76 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 77 | * Matches the USB device product name string for USB MIDI devices. |
| 78 | */ |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 79 | public static final String PROPERTY_PRODUCT = "product"; |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Mike Lockwood | 02868b1 | 2015-04-29 13:44:34 -0700 | [diff] [blame] | 82 | * Bundle key for the device's version property. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 83 | * The value for this property is of type {@link java.lang.String}. |
Mike Lockwood | 02868b1 | 2015-04-29 13:44:34 -0700 | [diff] [blame] | 84 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 85 | * Matches the USB device version number for USB MIDI devices. |
| 86 | */ |
| 87 | public static final String PROPERTY_VERSION = "version"; |
| 88 | |
| 89 | /** |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 90 | * Bundle key for the device's serial number property. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 91 | * The value for this property is of type {@link java.lang.String}. |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 92 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 93 | * Matches the USB device serial number for USB MIDI devices. |
| 94 | */ |
| 95 | public static final String PROPERTY_SERIAL_NUMBER = "serial_number"; |
| 96 | |
| 97 | /** |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 98 | * Bundle key for the device's corresponding USB device. |
| 99 | * The value for this property is of type {@link android.hardware.usb.UsbDevice}. |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 100 | * Only set for USB MIDI devices. |
| 101 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 102 | */ |
| 103 | public static final String PROPERTY_USB_DEVICE = "usb_device"; |
| 104 | |
| 105 | /** |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 106 | * Bundle key for the device's corresponding Bluetooth device. |
| 107 | * The value for this property is of type {@link android.bluetooth.BluetoothDevice}. |
Mike Lockwood | 3f5acc6 | 2015-03-17 13:21:03 -0700 | [diff] [blame] | 108 | * Only set for Bluetooth MIDI devices. |
| 109 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 110 | */ |
| 111 | public static final String PROPERTY_BLUETOOTH_DEVICE = "bluetooth_device"; |
| 112 | |
| 113 | /** |
Mike Lockwood | 10024b3 | 2014-12-11 13:44:20 -0800 | [diff] [blame] | 114 | * Bundle key for the device's ALSA card number. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 115 | * The value for this property is an integer. |
Mike Lockwood | 10024b3 | 2014-12-11 13:44:20 -0800 | [diff] [blame] | 116 | * Only set for USB MIDI devices. |
| 117 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 118 | * |
| 119 | * @hide |
Mike Lockwood | 10024b3 | 2014-12-11 13:44:20 -0800 | [diff] [blame] | 120 | */ |
| 121 | public static final String PROPERTY_ALSA_CARD = "alsa_card"; |
| 122 | |
| 123 | /** |
| 124 | * Bundle key for the device's ALSA device number. |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 125 | * The value for this property is an integer. |
Mike Lockwood | 10024b3 | 2014-12-11 13:44:20 -0800 | [diff] [blame] | 126 | * Only set for USB MIDI devices. |
| 127 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 128 | * |
| 129 | * @hide |
Mike Lockwood | 10024b3 | 2014-12-11 13:44:20 -0800 | [diff] [blame] | 130 | */ |
| 131 | public static final String PROPERTY_ALSA_DEVICE = "alsa_device"; |
| 132 | |
| 133 | /** |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 134 | * ServiceInfo for the service hosting the device implementation. |
| 135 | * The value for this property is of type {@link android.content.pm.ServiceInfo}. |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 136 | * Only set for Virtual MIDI devices. |
| 137 | * Used with the {@link android.os.Bundle} returned by {@link #getProperties} |
| 138 | * |
| 139 | * @hide |
| 140 | */ |
| 141 | public static final String PROPERTY_SERVICE_INFO = "service_info"; |
| 142 | |
| 143 | /** |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 144 | * Contains information about an input or output port. |
| 145 | */ |
| 146 | public static final class PortInfo { |
| 147 | /** |
| 148 | * Port type for input ports |
| 149 | */ |
| 150 | public static final int TYPE_INPUT = 1; |
| 151 | |
| 152 | /** |
| 153 | * Port type for output ports |
| 154 | */ |
| 155 | public static final int TYPE_OUTPUT = 2; |
| 156 | |
| 157 | private final int mPortType; |
| 158 | private final int mPortNumber; |
| 159 | private final String mName; |
| 160 | |
| 161 | PortInfo(int type, int portNumber, String name) { |
| 162 | mPortType = type; |
| 163 | mPortNumber = portNumber; |
| 164 | mName = (name == null ? "" : name); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the port type of the port (either {@link #TYPE_INPUT} or {@link #TYPE_OUTPUT}) |
| 169 | * @return the port type |
| 170 | */ |
| 171 | public int getType() { |
| 172 | return mPortType; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Returns the port number of the port |
| 177 | * @return the port number |
| 178 | */ |
| 179 | public int getPortNumber() { |
| 180 | return mPortNumber; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Returns the name of the port, or empty string if the port has no name |
| 185 | * @return the port name |
| 186 | */ |
| 187 | public String getName() { |
| 188 | return mName; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | private final int mType; // USB or virtual |
Paul McLean | 8a3e33b | 2017-03-14 15:20:51 -0700 | [diff] [blame] | 193 | private final int mId; // unique ID generated by MidiService. Accessed from native code. |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 194 | private final int mInputPortCount; |
| 195 | private final int mOutputPortCount; |
| 196 | private final String[] mInputPortNames; |
| 197 | private final String[] mOutputPortNames; |
| 198 | private final Bundle mProperties; |
| 199 | private final boolean mIsPrivate; |
| 200 | |
| 201 | /** |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 202 | * MidiDeviceInfo should only be instantiated by MidiService implementation |
| 203 | * @hide |
| 204 | */ |
Mike Lockwood | b6b9a91 | 2014-12-08 11:19:04 -0800 | [diff] [blame] | 205 | public MidiDeviceInfo(int type, int id, int numInputPorts, int numOutputPorts, |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 206 | String[] inputPortNames, String[] outputPortNames, Bundle properties, |
| 207 | boolean isPrivate) { |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 208 | mType = type; |
| 209 | mId = id; |
Mike Lockwood | b6b9a91 | 2014-12-08 11:19:04 -0800 | [diff] [blame] | 210 | mInputPortCount = numInputPorts; |
| 211 | mOutputPortCount = numOutputPorts; |
Mike Lockwood | 0caf689 | 2015-03-16 16:03:17 -0700 | [diff] [blame] | 212 | if (inputPortNames == null) { |
| 213 | mInputPortNames = new String[numInputPorts]; |
| 214 | } else { |
| 215 | mInputPortNames = inputPortNames; |
| 216 | } |
| 217 | if (outputPortNames == null) { |
| 218 | mOutputPortNames = new String[numOutputPorts]; |
| 219 | } else { |
| 220 | mOutputPortNames = outputPortNames; |
| 221 | } |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 222 | mProperties = properties; |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 223 | mIsPrivate = isPrivate; |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Returns the type of the device. |
| 228 | * |
| 229 | * @return the device's type |
| 230 | */ |
| 231 | public int getType() { |
| 232 | return mType; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Returns the ID of the device. |
| 237 | * This ID is generated by the MIDI service and is not persistent across device unplugs. |
| 238 | * |
| 239 | * @return the device's ID |
| 240 | */ |
| 241 | public int getId() { |
| 242 | return mId; |
| 243 | } |
| 244 | |
| 245 | /** |
Mike Lockwood | b6b9a91 | 2014-12-08 11:19:04 -0800 | [diff] [blame] | 246 | * Returns the device's number of input ports. |
| 247 | * |
| 248 | * @return the number of input ports |
| 249 | */ |
| 250 | public int getInputPortCount() { |
| 251 | return mInputPortCount; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Returns the device's number of output ports. |
| 256 | * |
| 257 | * @return the number of output ports |
| 258 | */ |
| 259 | public int getOutputPortCount() { |
| 260 | return mOutputPortCount; |
| 261 | } |
| 262 | |
| 263 | /** |
Mike Lockwood | 9189f5f | 2015-04-09 17:51:32 -0700 | [diff] [blame] | 264 | * Returns information about the device's ports. |
| 265 | * The ports are in unspecified order. |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 266 | * |
Mike Lockwood | 9189f5f | 2015-04-09 17:51:32 -0700 | [diff] [blame] | 267 | * @return array of {@link PortInfo} |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 268 | */ |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 269 | public PortInfo[] getPorts() { |
| 270 | PortInfo[] ports = new PortInfo[mInputPortCount + mOutputPortCount]; |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 271 | |
Mike Lockwood | 9189f5f | 2015-04-09 17:51:32 -0700 | [diff] [blame] | 272 | int index = 0; |
| 273 | for (int i = 0; i < mInputPortCount; i++) { |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 274 | ports[index++] = new PortInfo(PortInfo.TYPE_INPUT, i, mInputPortNames[i]); |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 275 | } |
Mike Lockwood | 9189f5f | 2015-04-09 17:51:32 -0700 | [diff] [blame] | 276 | for (int i = 0; i < mOutputPortCount; i++) { |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 277 | ports[index++] = new PortInfo(PortInfo.TYPE_OUTPUT, i, mOutputPortNames[i]); |
Mike Lockwood | 9189f5f | 2015-04-09 17:51:32 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Mike Lockwood | 7eb441c | 2015-05-12 13:32:16 -0700 | [diff] [blame] | 280 | return ports; |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 284 | * Returns the {@link android.os.Bundle} containing the device's properties. |
| 285 | * |
| 286 | * @return the device's properties |
| 287 | */ |
| 288 | public Bundle getProperties() { |
| 289 | return mProperties; |
| 290 | } |
| 291 | |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Returns true if the device is private. Private devices are only visible and accessible |
| 294 | * to clients with the same UID as the application that is hosting the device. |
| 295 | * |
| 296 | * @return true if the device is private |
| 297 | */ |
| 298 | public boolean isPrivate() { |
| 299 | return mIsPrivate; |
| 300 | } |
| 301 | |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 302 | @Override |
| 303 | public boolean equals(Object o) { |
| 304 | if (o instanceof MidiDeviceInfo) { |
| 305 | return (((MidiDeviceInfo)o).mId == mId); |
| 306 | } else { |
| 307 | return false; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public int hashCode() { |
| 313 | return mId; |
| 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public String toString() { |
Mike Lockwood | fd5637f | 2015-05-07 13:02:01 -0700 | [diff] [blame] | 318 | // This is a hack to force the mProperties Bundle to unparcel so we can |
| 319 | // print all the names and values. |
| 320 | mProperties.getString(PROPERTY_NAME); |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 321 | return ("MidiDeviceInfo[mType=" + mType + |
Mike Lockwood | b6b9a91 | 2014-12-08 11:19:04 -0800 | [diff] [blame] | 322 | ",mInputPortCount=" + mInputPortCount + |
| 323 | ",mOutputPortCount=" + mOutputPortCount + |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 324 | ",mProperties=" + mProperties + |
| 325 | ",mIsPrivate=" + mIsPrivate); |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 328 | public static final @android.annotation.NonNull Parcelable.Creator<MidiDeviceInfo> CREATOR = |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 329 | new Parcelable.Creator<MidiDeviceInfo>() { |
| 330 | public MidiDeviceInfo createFromParcel(Parcel in) { |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 331 | // Needs to be kept in sync with code in MidiDeviceInfo.cpp |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 332 | int type = in.readInt(); |
| 333 | int id = in.readInt(); |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 334 | int inputPortCount = in.readInt(); |
| 335 | int outputPortCount = in.readInt(); |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 336 | String[] inputPortNames = in.createStringArray(); |
| 337 | String[] outputPortNames = in.createStringArray(); |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 338 | boolean isPrivate = (in.readInt() == 1); |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 339 | Bundle basicPropertiesIgnored = in.readBundle(); |
| 340 | Bundle properties = in.readBundle(); |
| 341 | return new MidiDeviceInfo(type, id, inputPortCount, outputPortCount, |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 342 | inputPortNames, outputPortNames, properties, isPrivate); |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | public MidiDeviceInfo[] newArray(int size) { |
| 346 | return new MidiDeviceInfo[size]; |
| 347 | } |
| 348 | }; |
| 349 | |
| 350 | public int describeContents() { |
| 351 | return 0; |
| 352 | } |
| 353 | |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 354 | private Bundle getBasicProperties(String[] keys) { |
| 355 | Bundle basicProperties = new Bundle(); |
| 356 | for (String key : keys) { |
Mikhail Naganov | 33603ae | 2016-09-27 10:42:53 -0700 | [diff] [blame] | 357 | Object val = mProperties.get(key); |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 358 | if (val != null) { |
Mikhail Naganov | 33603ae | 2016-09-27 10:42:53 -0700 | [diff] [blame] | 359 | if (val instanceof String) { |
| 360 | basicProperties.putString(key, (String) val); |
| 361 | } else if (val instanceof Integer) { |
| 362 | basicProperties.putInt(key, (Integer) val); |
| 363 | } else { |
| 364 | Log.w(TAG, "Unsupported property type: " + val.getClass().getName()); |
| 365 | } |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | return basicProperties; |
| 369 | } |
| 370 | |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 371 | public void writeToParcel(Parcel parcel, int flags) { |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 372 | // Needs to be kept in sync with code in MidiDeviceInfo.cpp |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 373 | parcel.writeInt(mType); |
| 374 | parcel.writeInt(mId); |
Mike Lockwood | b6b9a91 | 2014-12-08 11:19:04 -0800 | [diff] [blame] | 375 | parcel.writeInt(mInputPortCount); |
| 376 | parcel.writeInt(mOutputPortCount); |
Mike Lockwood | f2cd802 | 2015-03-11 08:50:41 -0700 | [diff] [blame] | 377 | parcel.writeStringArray(mInputPortNames); |
| 378 | parcel.writeStringArray(mOutputPortNames); |
Mike Lockwood | 11fd96d | 2015-03-02 12:07:49 -0800 | [diff] [blame] | 379 | parcel.writeInt(mIsPrivate ? 1 : 0); |
Mikhail Naganov | 84b6740 | 2016-09-15 11:00:57 -0700 | [diff] [blame] | 380 | // "Basic" properties only contain properties of primitive types |
| 381 | // and thus can be read back by native code. "Extra" properties is |
| 382 | // a superset that contains all properties. |
| 383 | parcel.writeBundle(getBasicProperties(new String[] { |
| 384 | PROPERTY_NAME, PROPERTY_MANUFACTURER, PROPERTY_PRODUCT, PROPERTY_VERSION, |
| 385 | PROPERTY_SERIAL_NUMBER, PROPERTY_ALSA_CARD, PROPERTY_ALSA_DEVICE |
| 386 | })); |
| 387 | // Must be serialized last so native code can safely ignore it. |
| 388 | parcel.writeBundle(mProperties); |
Mike Lockwood | 67f8e8b | 2014-12-01 13:54:59 -0800 | [diff] [blame] | 389 | } |
| 390 | } |