[Android] factorize call detection & don' t crash if the device has no telephony features

Sébastien Toque git at videolan.org
Mon Oct 1 20:40:16 CEST 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Oct  1 20:37:11 2012 +0200| [c070d33ca9e8e8b3c99c270ffa7a8483c7494d5f] | committer: Sébastien Toque

factorize call detection & don't crash if the device has no telephony features

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c070d33ca9e8e8b3c99c270ffa7a8483c7494d5f
---

 vlc-android/src/org/videolan/vlc/AudioService.java |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 1976dad..d6ebe3e 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -239,8 +239,6 @@ public class AudioService extends Service {
                 return;
             }
 
-            TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-
             /*
              * widget events
              */
@@ -265,12 +263,17 @@ public class AudioService extends Service {
                 next();
             }
 
+            // skip all headsets events if there is a call
+            TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+            if (telManager != null && telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
+                return;
+
             /*
              * headset controller events
              */
             else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {
                 KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
-                if (event == null || telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
+                if (event == null)
                     return;
 
                 if (mCurrentMedia == null) {
@@ -337,7 +340,7 @@ public class AudioService extends Service {
             /*
              * headset plug events
              */
-            if (mDetectHeadset && telManager.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
+            if (mDetectHeadset) {
                 if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
                     Log.i(TAG, "Headset Removed.");
                     if (mLibVLC.isPlaying() && mCurrentMedia != null)



More information about the Android mailing list