diff options
6 files changed, 60 insertions, 12 deletions
@@ -348,6 +348,7 @@ LOCAL_SRC_FILES += \ media/java/android/media/IRingtonePlayer.aidl \ media/java/android/media/IVolumeController.aidl \ media/java/android/media/audiopolicy/IAudioPolicyCallback.aidl \ + media/java/android/media/midi/IBluetoothMidiService.aidl \ media/java/android/media/midi/IMidiDeviceListener.aidl \ media/java/android/media/midi/IMidiDeviceOpenCallback.aidl \ media/java/android/media/midi/IMidiDeviceServer.aidl \ diff --git a/media/java/android/media/midi/IBluetoothMidiService.aidl b/media/java/android/media/midi/IBluetoothMidiService.aidl new file mode 100644 index 0000000..fe5566d --- /dev/null +++ b/media/java/android/media/midi/IBluetoothMidiService.aidl @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.midi; + +import android.bluetooth.BluetoothDevice; +import android.os.IBinder; + +/** @hide */ +interface IBluetoothMidiService +{ + IBinder addBluetoothDevice(in BluetoothDevice bluetoothDevice); +} diff --git a/media/packages/BluetoothMidiService/Android.mk b/media/packages/BluetoothMidiService/Android.mk index 2c9c3c5..0565925 100644 --- a/media/packages/BluetoothMidiService/Android.mk +++ b/media/packages/BluetoothMidiService/Android.mk @@ -3,7 +3,8 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := $(call all-subdir-java-files) +LOCAL_SRC_FILES += \ + $(call all-java-files-under,src) LOCAL_PACKAGE_NAME := BluetoothMidiService LOCAL_CERTIFICATE := platform diff --git a/media/packages/BluetoothMidiService/AndroidManifest.xml b/media/packages/BluetoothMidiService/AndroidManifest.xml index b0b389a..1cfd55d 100644 --- a/media/packages/BluetoothMidiService/AndroidManifest.xml +++ b/media/packages/BluetoothMidiService/AndroidManifest.xml @@ -8,7 +8,7 @@ <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" /> diff --git a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java index 1f81a05..5541f9f 100644 --- a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java +++ b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java @@ -19,6 +19,7 @@ package com.android.bluetoothmidiservice; import android.app.Service; import android.bluetooth.BluetoothDevice; import android.content.Intent; +import android.media.midi.IBluetoothMidiService; import android.media.midi.MidiManager; import android.os.IBinder; import android.util.Log; @@ -34,25 +35,31 @@ public class BluetoothMidiService extends Service { @Override public IBinder onBind(Intent intent) { - if (MidiManager.BLUETOOTH_MIDI_SERVICE_INTENT.equals(intent.getAction())) { - BluetoothDevice bluetoothDevice = (BluetoothDevice)intent.getParcelableExtra("device"); + // Return the interface + return mBinder; + } + + + private final IBluetoothMidiService.Stub mBinder = new IBluetoothMidiService.Stub() { + + public IBinder addBluetoothDevice(BluetoothDevice bluetoothDevice) { + BluetoothMidiDevice device; if (bluetoothDevice == null) { - Log.e(TAG, "no BluetoothDevice in onBind intent"); + Log.e(TAG, "no BluetoothDevice in addBluetoothDevice()"); return null; } - - BluetoothMidiDevice device; synchronized (mDeviceServerMap) { device = mDeviceServerMap.get(bluetoothDevice); if (device == null) { - device = new BluetoothMidiDevice(this, bluetoothDevice, this); + device = new BluetoothMidiDevice(BluetoothMidiService.this, + bluetoothDevice, BluetoothMidiService.this); mDeviceServerMap.put(bluetoothDevice, device); } } return device.getBinder(); } - return null; - } + + }; void deviceClosed(BluetoothDevice device) { synchronized (mDeviceServerMap) { diff --git a/services/midi/java/com/android/server/midi/MidiService.java b/services/midi/java/com/android/server/midi/MidiService.java index 701e07f..c6d5a7e 100644 --- a/services/midi/java/com/android/server/midi/MidiService.java +++ b/services/midi/java/com/android/server/midi/MidiService.java @@ -27,6 +27,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.XmlResourceParser; +import android.media.midi.IBluetoothMidiService; import android.media.midi.IMidiDeviceListener; import android.media.midi.IMidiDeviceOpenCallback; import android.media.midi.IMidiDeviceServer; @@ -394,7 +395,20 @@ public class MidiService extends IMidiManager.Stub { mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { - IMidiDeviceServer server = IMidiDeviceServer.Stub.asInterface(service); + IMidiDeviceServer server = null; + if (mBluetoothDevice != null) { + IBluetoothMidiService mBluetoothMidiService = IBluetoothMidiService.Stub.asInterface(service); + try { + // We need to explicitly add the device in a separate method + // because onBind() is only called once. + IBinder deviceBinder = mBluetoothMidiService.addBluetoothDevice(mBluetoothDevice); + server = IMidiDeviceServer.Stub.asInterface(deviceBinder); + } catch(RemoteException e) { + Log.e(TAG, "Could not call addBluetoothDevice()", e); + } + } else { + server = IMidiDeviceServer.Stub.asInterface(service); + } setDeviceServer(server); } @@ -411,7 +425,6 @@ public class MidiService extends IMidiManager.Stub { intent.setComponent(new ComponentName( MidiManager.BLUETOOTH_MIDI_SERVICE_PACKAGE, MidiManager.BLUETOOTH_MIDI_SERVICE_CLASS)); - intent.putExtra("device", mBluetoothDevice); } else { intent = new Intent(MidiDeviceService.SERVICE_INTERFACE); intent.setComponent( |