diff options
author | Mike Lockwood <lockwood@google.com> | 2015-06-04 13:43:56 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2015-06-04 19:16:23 -0700 |
commit | e0a6ca64fac5bd4f10139321604031816e90adb4 (patch) | |
tree | af84954409f063e07e3845c5b8a8fe703106da7a /media/packages | |
parent | ec7100d0114d50f12c4ad95eaeac61e93a6d5a96 (diff) | |
download | frameworks_base-e0a6ca64fac5bd4f10139321604031816e90adb4.zip frameworks_base-e0a6ca64fac5bd4f10139321604031816e90adb4.tar.gz frameworks_base-e0a6ca64fac5bd4f10139321604031816e90adb4.tar.bz2 |
MidiManager: proxy all requests to open devices through MidiService
Previously when a MidiManager client opened a virtual or Bluetooth device,
the client bound directly to the virtual device's MidiDeviceService
or BluetoothMidiDevice's IMidiDeviceServer for the given BluetoothDevice.
Only USB devices were opened in MidiService.
Now opening any type of MIDI device is done via IMidiManager.openDevice() or
IMidiManager.openBluetoothDevice(). MidiService tracks all connnections between
clients and devices.
Services that implement virtual devices must now require android.permission.BIND_MIDI_DEVICE_SERVICE
so only MidiService can bind to these services.
Bug: 21044677
Change-Id: I7172f7b1e0cbfe4a2a87dff376c32dc9b41aa563
Diffstat (limited to 'media/packages')
-rw-r--r-- | media/packages/BluetoothMidiService/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java | 26 |
2 files changed, 22 insertions, 7 deletions
diff --git a/media/packages/BluetoothMidiService/AndroidManifest.xml b/media/packages/BluetoothMidiService/AndroidManifest.xml index 15aa581..b0b389a 100644 --- a/media/packages/BluetoothMidiService/AndroidManifest.xml +++ b/media/packages/BluetoothMidiService/AndroidManifest.xml @@ -8,7 +8,8 @@ <application android:label="@string/app_name"> - <service android:name="BluetoothMidiService"> + <service android:name="BluetoothMidiService" + android:permission="android.permission.BIND_MIDI_DEVICE_SERVICE"> <intent-filter> <action android:name="android.media.midi.BluetoothMidiService" /> </intent-filter> diff --git a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java index 60c6570..e6d59e4 100644 --- a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java +++ b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java @@ -24,10 +24,11 @@ import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothProfile; import android.content.Context; -import android.media.midi.MidiReceiver; -import android.media.midi.MidiManager; -import android.media.midi.MidiDeviceServer; import android.media.midi.MidiDeviceInfo; +import android.media.midi.MidiDeviceServer; +import android.media.midi.MidiDeviceStatus; +import android.media.midi.MidiManager; +import android.media.midi.MidiReceiver; import android.os.Bundle; import android.os.IBinder; import android.util.Log; @@ -81,6 +82,18 @@ public final class BluetoothMidiDevice { private final BluetoothPacketDecoder mPacketDecoder = new BluetoothPacketDecoder(MAX_PACKET_SIZE); + private final MidiDeviceServer.Callback mDeviceServerCallback + = new MidiDeviceServer.Callback() { + @Override + public void onDeviceStatusChanged(MidiDeviceServer server, MidiDeviceStatus status) { + } + + @Override + public void onClose() { + close(); + } + }; + private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, @@ -213,7 +226,7 @@ public final class BluetoothMidiDevice { inputPortReceivers[0] = mEventScheduler.getReceiver(); mDeviceServer = mMidiManager.createDeviceServer(inputPortReceivers, 1, - null, null, properties, MidiDeviceInfo.TYPE_BLUETOOTH, null); + null, null, properties, MidiDeviceInfo.TYPE_BLUETOOTH, mDeviceServerCallback); mOutputReceiver = mDeviceServer.getOutputPortReceivers()[0]; @@ -248,11 +261,12 @@ public final class BluetoothMidiDevice { private void close() { synchronized (mBluetoothDevice) { - mEventScheduler.close(); + mEventScheduler.close(); + mService.deviceClosed(mBluetoothDevice); + if (mDeviceServer != null) { IoUtils.closeQuietly(mDeviceServer); mDeviceServer = null; - mService.deviceClosed(mBluetoothDevice); } if (mBluetoothGatt != null) { mBluetoothGatt.close(); |