summaryrefslogtreecommitdiffstats
path: root/services/midi/java
diff options
context:
space:
mode:
authorPhil Burk <philburk@google.com>2015-08-05 23:32:54 -0700
committerPhil Burk <philburk@google.com>2015-10-12 20:59:57 +0000
commite39def480fd2d1bcc3a89751dd492d4634c38194 (patch)
treecbe9cf6a2e94de0985bd8217b015c7efe1c36af0 /services/midi/java
parentc83a6121d214631c0a52be5b2c5c8ce2f6470ed0 (diff)
downloadframeworks_base-e39def480fd2d1bcc3a89751dd492d4634c38194.zip
frameworks_base-e39def480fd2d1bcc3a89751dd492d4634c38194.tar.gz
frameworks_base-e39def480fd2d1bcc3a89751dd492d4634c38194.tar.bz2
MidiService: update listener with current status when registered
This will give an app an opportunity to learn whether an input port is busy before the user tries to connect and then fails. Bug: 22825043 Change-Id: Ifede60f166dfe66ea15453044fce06f4a8452b18 Signed-off-by: Phil Burk <philburk@google.com> (cherry picked from commit b2355940e3e697deeecd1b6511cd5094f9dc553a)
Diffstat (limited to 'services/midi/java')
-rw-r--r--services/midi/java/com/android/server/midi/MidiService.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/services/midi/java/com/android/server/midi/MidiService.java b/services/midi/java/com/android/server/midi/MidiService.java
index 3ecfd55..701e07f 100644
--- a/services/midi/java/com/android/server/midi/MidiService.java
+++ b/services/midi/java/com/android/server/midi/MidiService.java
@@ -575,6 +575,8 @@ public class MidiService extends IMidiManager.Stub {
Client client = getClient(token);
if (client == null) return;
client.addListener(listener);
+ // Let listener know whether any ports are already busy.
+ updateStickyDeviceStatus(client.mUid, listener);
}
@Override
@@ -584,6 +586,25 @@ public class MidiService extends IMidiManager.Stub {
client.removeListener(listener);
}
+ // Inform listener of the status of all known devices.
+ private void updateStickyDeviceStatus(int uid, IMidiDeviceListener listener) {
+ synchronized (mDevicesByInfo) {
+ for (Device device : mDevicesByInfo.values()) {
+ // ignore private devices that our client cannot access
+ if (device.isUidAllowed(uid)) {
+ try {
+ MidiDeviceStatus status = device.getDeviceStatus();
+ if (status != null) {
+ listener.onDeviceStatusChanged(status);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception", e);
+ }
+ }
+ }
+ }
+ }
+
private static final MidiDeviceInfo[] EMPTY_DEVICE_INFO_ARRAY = new MidiDeviceInfo[0];
public MidiDeviceInfo[] getDevices() {