summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2015-03-04 16:05:17 -0800
committerMike Lockwood <lockwood@google.com>2015-03-04 20:38:42 -0800
commit35110d1ed72ee7fe687125831b4dd91b87b515ee (patch)
treeb7251e8d4a4c1ff47d3b0081f245f7062a0c8835 /media
parent3b7664589be22ddad34b72e11ced937d48660ebb (diff)
downloadframeworks_base-35110d1ed72ee7fe687125831b4dd91b87b515ee.zip
frameworks_base-35110d1ed72ee7fe687125831b4dd91b87b515ee.tar.gz
frameworks_base-35110d1ed72ee7fe687125831b4dd91b87b515ee.tar.bz2
Add MidiDevice.close() method so we can clean up our ServiceConnection
Change-Id: I65cd4cfd940b02709daeffef6dab814305b8a6b0
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/midi/MidiDevice.java34
-rw-r--r--media/java/android/media/midi/MidiManager.java2
2 files changed, 29 insertions, 7 deletions
diff --git a/media/java/android/media/midi/MidiDevice.java b/media/java/android/media/midi/MidiDevice.java
index 87af362..a273915 100644
--- a/media/java/android/media/midi/MidiDevice.java
+++ b/media/java/android/media/midi/MidiDevice.java
@@ -16,10 +16,15 @@
package android.media.midi;
+import android.content.Context;
+import android.content.ServiceConnection;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log;
+import java.io.Closeable;
+import java.io.IOException;
+
/**
* This class is used for sending and receiving data to and from an MIDI device
* Instances of this class are created by {@link MidiManager#openDevice}.
@@ -27,19 +32,27 @@ import android.util.Log;
* CANDIDATE FOR PUBLIC API
* @hide
*/
-public final class MidiDevice {
+public final class MidiDevice implements Closeable {
private static final String TAG = "MidiDevice";
private final MidiDeviceInfo mDeviceInfo;
private final IMidiDeviceServer mServer;
+ private Context mContext;
+ private ServiceConnection mServiceConnection;
- /**
- * MidiDevice should only be instantiated by MidiManager
- * @hide
- */
- public MidiDevice(MidiDeviceInfo deviceInfo, IMidiDeviceServer server) {
+ /* package */ MidiDevice(MidiDeviceInfo deviceInfo, IMidiDeviceServer server) {
+ mDeviceInfo = deviceInfo;
+ mServer = server;
+ mContext = null;
+ mServiceConnection = null;
+ }
+
+ /* package */ MidiDevice(MidiDeviceInfo deviceInfo, IMidiDeviceServer server,
+ Context context, ServiceConnection serviceConnection) {
mDeviceInfo = deviceInfo;
mServer = server;
+ mContext = context;
+ mServiceConnection = serviceConnection;
}
/**
@@ -90,6 +103,15 @@ public final class MidiDevice {
}
@Override
+ public void close() throws IOException {
+ if (mContext != null && mServiceConnection != null) {
+ mContext.unbindService(mServiceConnection);
+ mContext = null;
+ mServiceConnection = null;
+ }
+ }
+
+ @Override
public String toString() {
return ("MidiDevice: " + mDeviceInfo.toString());
}
diff --git a/media/java/android/media/midi/MidiManager.java b/media/java/android/media/midi/MidiManager.java
index ca7d3c2..08ac25a 100644
--- a/media/java/android/media/midi/MidiManager.java
+++ b/media/java/android/media/midi/MidiManager.java
@@ -223,7 +223,7 @@ public class MidiManager {
public void onServiceConnected(ComponentName name, IBinder binder) {
IMidiDeviceServer server =
IMidiDeviceServer.Stub.asInterface(binder);
- MidiDevice device = new MidiDevice(deviceInfoF, server);
+ MidiDevice device = new MidiDevice(deviceInfoF, server, mContext, this);
sendOpenDeviceResponse(deviceInfoF, device, callbackF, handlerF);
}