summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2012-12-21 10:27:05 +0100
committerDanny Baumann <dannybaumann@web.de>2012-12-27 12:23:55 +0100
commitb09b9292e1fa809d126541156e8c4b9b6024c58a (patch)
treeefe9d6bc880161b5992e2c8ad3700202112fdcd1 /src/java
parentc08256a14875b0e1d2e988ee3700c9dc1a5d4fd3 (diff)
downloadframeworks_opt_telephony-b09b9292e1fa809d126541156e8c4b9b6024c58a.zip
frameworks_opt_telephony-b09b9292e1fa809d126541156e8c4b9b6024c58a.tar.gz
frameworks_opt_telephony-b09b9292e1fa809d126541156e8c4b9b6024c58a.tar.bz2
Fix ringing audio focus handling.
Test case: - enable increasing ringtone starting at volume 0 - start any music player - get an incoming call Previous behaviour: When ringtone volume is increased from 0 to 1, music continues playing even though ring tone is playing as well. New behaviour: When ringtone starts, music is attenuated to make user aware of incoming call. When ringtone volume is increased to 1, music stops playing. Change-Id: Ifc32ea162d4527572be0574024116d10ee9bca66
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/android/internal/telephony/CallManager.java61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/java/com/android/internal/telephony/CallManager.java b/src/java/com/android/internal/telephony/CallManager.java
index bb237b0..f292aee 100644
--- a/src/java/com/android/internal/telephony/CallManager.java
+++ b/src/java/com/android/internal/telephony/CallManager.java
@@ -18,7 +18,10 @@ package com.android.internal.telephony;
import com.android.internal.telephony.sip.SipPhone;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.AsyncResult;
import android.os.Handler;
@@ -170,6 +173,20 @@ public final class CallManager {
protected final RegistrantList mPostDialCharacterRegistrants
= new RegistrantList();
+ private BroadcastReceiver mRingVolumeChangeReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
+ if (getState() == PhoneConstants.State.RINGING && streamType == AudioManager.STREAM_RING) {
+ int oldVolume = intent.getIntExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, -1);
+ int newVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
+ if (oldVolume == 0 || newVolume == 0) {
+ updateRingingAudioFocus(context);
+ }
+ }
+ }
+ };
+
private CallManager() {
mPhones = new ArrayList<Phone>();
mRingingCalls = new ArrayList<Call>();
@@ -378,25 +395,21 @@ public final class CallManager {
if (context == null) return;
AudioManager audioManager = (AudioManager)
context.getSystemService(Context.AUDIO_SERVICE);
+ PhoneConstants.State state = getState();
+ int lastAudioMode = audioManager.getMode();
// change the audio mode and request/abandon audio focus according to phone state,
// but only on audio mode transitions
- switch (getState()) {
+ switch (state) {
case RINGING:
- int curAudioMode = audioManager.getMode();
- if (curAudioMode != AudioManager.MODE_RINGTONE) {
- // only request audio focus if the ringtone is going to be heard
- if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) {
- if (VDBG) Log.d(LOG_TAG, "requestAudioFocus on STREAM_RING");
- audioManager.requestAudioFocusForCall(AudioManager.STREAM_RING,
- AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
- }
- if(!mSpeedUpAudioForMtCall) {
+ if (lastAudioMode != AudioManager.MODE_RINGTONE) {
+ updateRingingAudioFocus(context);
+ if (!mSpeedUpAudioForMtCall) {
audioManager.setMode(AudioManager.MODE_RINGTONE);
}
}
- if (mSpeedUpAudioForMtCall && (curAudioMode != AudioManager.MODE_IN_CALL)) {
+ if (mSpeedUpAudioForMtCall && lastAudioMode != AudioManager.MODE_IN_CALL) {
audioManager.setMode(AudioManager.MODE_IN_CALL);
}
break;
@@ -413,7 +426,7 @@ public final class CallManager {
// enable IN_COMMUNICATION audio mode instead for sipPhone
newAudioMode = AudioManager.MODE_IN_COMMUNICATION;
}
- if (audioManager.getMode() != newAudioMode || mSpeedUpAudioForMtCall) {
+ if (lastAudioMode != newAudioMode || mSpeedUpAudioForMtCall) {
// request audio focus before setting the new mode
if (VDBG) Log.d(LOG_TAG, "requestAudioFocus on STREAM_VOICE_CALL");
audioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
@@ -423,7 +436,7 @@ public final class CallManager {
mSpeedUpAudioForMtCall = false;
break;
case IDLE:
- if (audioManager.getMode() != AudioManager.MODE_NORMAL) {
+ if (lastAudioMode != AudioManager.MODE_NORMAL) {
audioManager.setMode(AudioManager.MODE_NORMAL);
if (VDBG) Log.d(LOG_TAG, "abandonAudioFocus");
// abandon audio focus after the mode has been set back to normal
@@ -432,6 +445,28 @@ public final class CallManager {
mSpeedUpAudioForMtCall = false;
break;
}
+
+ if (state == PhoneConstants.State.RINGING && lastAudioMode != AudioManager.MODE_RINGTONE) {
+ context.registerReceiver(mRingVolumeChangeReceiver,
+ new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION));
+ } else if (state != PhoneConstants.State.RINGING && lastAudioMode == AudioManager.MODE_RINGTONE) {
+ context.unregisterReceiver(mRingVolumeChangeReceiver);
+ }
+ }
+
+ private void updateRingingAudioFocus(Context context) {
+ AudioManager audioManager = (AudioManager)
+ context.getSystemService(Context.AUDIO_SERVICE);
+ int hint = audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0
+ // make user aware of an incoming call by
+ // attenuating the music he may be listening to
+ ? AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
+ // if we're going to play the ring tone, silence
+ // other sound sources
+ : AudioManager.AUDIOFOCUS_GAIN_TRANSIENT;
+
+ if (VDBG) Log.d(LOG_TAG, "requestAudioFocus on STREAM_RING");
+ audioManager.requestAudioFocusForCall(AudioManager.STREAM_RING, hint);
}
private Context getContext() {