summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2013-06-12 01:02:50 -0700
committerMartijn Coenen <maco@google.com>2013-06-12 01:12:33 -0700
commit825f3b96bd360f42158a25e5d6b09fc6f046ab10 (patch)
tree21d66762c971fee330247a0fd5ec662f7b4a905b
parent2b4dc11f4508cdb662a8069cccf9f2273004a4c8 (diff)
downloadandroid_packages_apps_Nfc-825f3b96bd360f42158a25e5d6b09fc6f046ab10.tar.gz
android_packages_apps_Nfc-825f3b96bd360f42158a25e5d6b09fc6f046ab10.tar.bz2
android_packages_apps_Nfc-825f3b96bd360f42158a25e5d6b09fc6f046ab10.zip
Properly dispatch "play key" into the system.
When pairing a Bluetooth headset, directly dispatch Play KeyEvents to AudioService, to ensure that the current active stack of registered MediaButtonReceivers is honored. Bug: 9389201 Change-Id: Idce1d28d684134cd8f69e2fb2304747c7b6b8fe8
-rw-r--r--src/com/android/nfc/handover/BluetoothHeadsetHandover.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/com/android/nfc/handover/BluetoothHeadsetHandover.java b/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
index c845f89e..f46757c8 100644
--- a/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
+++ b/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
@@ -25,9 +25,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.media.IAudioService;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
@@ -359,13 +362,20 @@ public class BluetoothHeadsetHandover implements BluetoothProfile.ServiceListene
}
void startTheMusic() {
- Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
- intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_MEDIA_PLAY));
- mContext.sendOrderedBroadcast(intent, null);
- intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
- KeyEvent.KEYCODE_MEDIA_PLAY));
- mContext.sendOrderedBroadcast(intent, null);
+ IAudioService audioService = IAudioService.Stub.asInterface(
+ ServiceManager.checkService(Context.AUDIO_SERVICE));
+ if (audioService != null) {
+ try {
+ KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
+ audioService.dispatchMediaKeyEvent(keyEvent);
+ keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY);
+ audioService.dispatchMediaKeyEvent(keyEvent);
+ } catch (RemoteException e) {
+ Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
+ }
+ } else {
+ Log.w(TAG, "Unable to find IAudioService for media key event");
+ }
}
void requestPairConfirmation() {