From 9b0f8be225e43b513df188d9dd40380a34698752 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 4 Jul 2012 14:50:54 +0200 Subject: [PATCH] update volume management to Handle ICS behavior --- res/xml/preferences.xml | 2 -- src/org/linphone/DialerActivity.java | 2 +- src/org/linphone/IncallActivity.java | 2 +- src/org/linphone/LinphoneManager.java | 21 +++++++++++++-------- src/org/linphone/LinphoneUtils.java | 9 +++++---- src/org/linphone/VideoCallActivity.java | 2 +- submodules/linphone | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 53f16a8bf..3e7a9948e 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -160,8 +160,6 @@ - 0; if (keyCode == KeyEvent.KEYCODE_BACK && isInCall) { diff --git a/src/org/linphone/IncallActivity.java b/src/org/linphone/IncallActivity.java index f18a81b3e..4cea2330f 100644 --- a/src/org/linphone/IncallActivity.java +++ b/src/org/linphone/IncallActivity.java @@ -812,7 +812,7 @@ public class IncallActivity extends AbstractCalleesActivity implements @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if (LinphoneUtils.onKeyVolumeSoftAdjust(keyCode)) return true; + if (LinphoneUtils.onKeyVolumeAdjust(keyCode)) return true; if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true; return super.onKeyDown(keyCode, event); } diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index a6ebb5315..55f87d596 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -93,6 +93,7 @@ import android.media.AudioManager; import android.media.MediaPlayer; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Build; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.Vibrator; @@ -990,7 +991,7 @@ public final class LinphoneManager implements LinphoneCoreListener { if (state == State.Connected) { if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) { - adjustSoftwareVolume(0); // Synchronize + adjustVolume(0); // Synchronize } } @@ -1225,15 +1226,19 @@ public final class LinphoneManager implements LinphoneCoreListener { return r.getString(R.string.unknown_incoming_call_name); } - public void adjustSoftwareVolume(int i) { - int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM); - int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM); + public void adjustVolume(int i) { + if (Build.VERSION.SDK_INT<15) { + int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM); + int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM); - int nextVolume = oldVolume +i; - if (nextVolume > maxVolume) nextVolume = maxVolume; - if (nextVolume < 0) nextVolume = 0; + int nextVolume = oldVolume +i; + if (nextVolume > maxVolume) nextVolume = maxVolume; + if (nextVolume < 0) nextVolume = 0; - mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep); + mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep); + } else + // starting from ICS, volume must be adjusted by the application, at least for STREAM_VOICE_CALL volume stream + mAudioManager.adjustStreamVolume(LINPHONE_VOLUME_STREAM, i<0?AudioManager.ADJUST_LOWER:AudioManager.ADJUST_RAISE, 0); } public static Boolean isProximitySensorNearby(final SensorEvent event) { diff --git a/src/org/linphone/LinphoneUtils.java b/src/org/linphone/LinphoneUtils.java index cd9c7d4b2..9722e2400 100644 --- a/src/org/linphone/LinphoneUtils.java +++ b/src/org/linphone/LinphoneUtils.java @@ -47,6 +47,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.Build; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; @@ -74,9 +75,9 @@ public final class LinphoneUtils { return true; } - public static boolean onKeyVolumeSoftAdjust(int keyCode) { + public static boolean onKeyVolumeAdjust(int keyCode) { if (!((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) - && Hacks.needSoftvolume())) { + && (Hacks.needSoftvolume())|| Build.VERSION.SDK_INT>=15)) { return false; // continue } @@ -84,9 +85,9 @@ public final class LinphoneUtils { Log.i("Couldn't change softvolume has service is not running"); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { - LinphoneManager.getInstance().adjustSoftwareVolume(1); + LinphoneManager.getInstance().adjustVolume(1); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { - LinphoneManager.getInstance().adjustSoftwareVolume(-1); + LinphoneManager.getInstance().adjustVolume(-1); } return preventVolumeBarToDisplay; } diff --git a/src/org/linphone/VideoCallActivity.java b/src/org/linphone/VideoCallActivity.java index 7551bc229..ed1a56119 100755 --- a/src/org/linphone/VideoCallActivity.java +++ b/src/org/linphone/VideoCallActivity.java @@ -374,7 +374,7 @@ public class VideoCallActivity extends Activity implements } public boolean onKeyDown(int keyCode, KeyEvent event) { - if (LinphoneUtils.onKeyVolumeSoftAdjust(keyCode)) + if (LinphoneUtils.onKeyVolumeAdjust(keyCode)) return true; if (Version.isXLargeScreen(this) && LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) { return true; diff --git a/submodules/linphone b/submodules/linphone index 9f02a12f4..9496394c8 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 9f02a12f4641989a225ee77bf6f403cd1c57d9e6 +Subproject commit 9496394c88dbdf6e6dd120b5657a2846b603d612