From aaab2ddc86bd610330c90c6f0ad0805bd696cd96 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 11 Dec 2012 11:21:03 +0100 Subject: [PATCH] Use edge optimization if needed --- src/org/linphone/CallManager.java | 7 ++- src/org/linphone/IncomingCallActivity.java | 9 +++- src/org/linphone/LinphoneManager.java | 6 ++- src/org/linphone/LinphoneUtils.java | 53 ++++++++++++++++++++++ submodules/linphone | 2 +- 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/org/linphone/CallManager.java b/src/org/linphone/CallManager.java index 8b2cf7a0c..d46b9408f 100644 --- a/src/org/linphone/CallManager.java +++ b/src/org/linphone/CallManager.java @@ -49,7 +49,7 @@ public class CallManager { - void inviteAddress(LinphoneAddress lAddress, boolean videoEnabled) throws LinphoneCoreException { + void inviteAddress(LinphoneAddress lAddress, boolean videoEnabled, boolean lowBandwidth) throws LinphoneCoreException { LinphoneCore lc = LinphoneManager.getLc(); LinphoneCallParams params = lc.createDefaultCallParameters(); @@ -60,6 +60,11 @@ public class CallManager { } else { params.setVideoEnabled(false); } + + if (lowBandwidth) { + params.enableLowBandwidth(true); + Log.d("Low bandwidth enabled in call params"); + } lc.inviteAddressWithParams(lAddress, params); } diff --git a/src/org/linphone/IncomingCallActivity.java b/src/org/linphone/IncomingCallActivity.java index 6242ca4cf..8dfbaaf4e 100644 --- a/src/org/linphone/IncomingCallActivity.java +++ b/src/org/linphone/IncomingCallActivity.java @@ -162,6 +162,12 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat params.setVideoEnabled(false); } + boolean isLowBandwidthConnection = !LinphoneUtils.isHightBandwidthConnection(this); + if (isLowBandwidthConnection) { + params.enableLowBandwidth(true); + Log.d("Low bandwidth enabled in call params"); + } + if (!LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) { // the above method takes care of Samsung Galaxy S Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show(); @@ -170,8 +176,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat return; } final LinphoneCallParams remoteParams = mCall.getRemoteParams(); - if (remoteParams != null && remoteParams.getVideoEnabled() - && LinphoneManager.getInstance().isAutoAcceptCamera()) { + if (remoteParams != null && remoteParams.getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) { LinphoneActivity.instance().startVideoActivity(mCall); } else { LinphoneActivity.instance().startIncallActivity(mCall); diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index ed9394269..267a352ed 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -274,14 +274,16 @@ public final class LinphoneManager implements LinphoneCoreListener { } lAddress.setDisplayName(address.getDisplayedName()); + boolean isLowBandwidthConnection = !LinphoneUtils.isHightBandwidthConnection(LinphoneService.instance().getApplicationContext()); + try { if (Version.isVideoCapable()) { boolean prefVideoEnable = isVideoEnabled(); int key = R.string.pref_video_initiate_call_with_video_key; boolean prefInitiateWithVideo = getPrefBoolean(key, false); - CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo); + CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo, isLowBandwidthConnection); } else { - CallManager.getInstance().inviteAddress(lAddress, false); + CallManager.getInstance().inviteAddress(lAddress, false, isLowBandwidthConnection); } diff --git a/src/org/linphone/LinphoneUtils.java b/src/org/linphone/LinphoneUtils.java index e969de7fd..dd1a5846a 100644 --- a/src/org/linphone/LinphoneUtils.java +++ b/src/org/linphone/LinphoneUtils.java @@ -47,8 +47,11 @@ import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; +import android.telephony.TelephonyManager; import android.util.TypedValue; import android.view.KeyEvent; import android.view.View; @@ -277,5 +280,55 @@ public final class LinphoneUtils { state == LinphoneCall.State.PausedByRemote || state == LinphoneCall.State.Pausing; } + + public static boolean isHightBandwidthConnection(Context context){ + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo info = cm.getActiveNetworkInfo(); + return (info != null && info.isConnected() && isConnectionFast(info.getType(),info.getSubtype())); + } + + private static boolean isConnectionFast(int type, int subType){ + if (type == ConnectivityManager.TYPE_WIFI) { + return true; + } else if (type == ConnectivityManager.TYPE_MOBILE) { + switch (subType) { + case TelephonyManager.NETWORK_TYPE_1xRTT: + return false; // ~ 50-100 kbps + case TelephonyManager.NETWORK_TYPE_CDMA: + return false; // ~ 14-64 kbps + case TelephonyManager.NETWORK_TYPE_EDGE: + return false; // ~ 50-100 kbps + case TelephonyManager.NETWORK_TYPE_GPRS: + return false; // ~ 100 kbps + case TelephonyManager.NETWORK_TYPE_EVDO_0: + return false; // ~25 kbps + case TelephonyManager.NETWORK_TYPE_LTE: + return true; // ~ 400-1000 kbps + case TelephonyManager.NETWORK_TYPE_EVDO_A: + return true; // ~ 600-1400 kbps + case TelephonyManager.NETWORK_TYPE_HSDPA: + return true; // ~ 2-14 Mbps + case TelephonyManager.NETWORK_TYPE_HSPA: + return true; // ~ 700-1700 kbps + case TelephonyManager.NETWORK_TYPE_HSUPA: + return true; // ~ 1-23 Mbps + case TelephonyManager.NETWORK_TYPE_UMTS: + return true; // ~ 400-7000 kbps + case TelephonyManager.NETWORK_TYPE_EHRPD: + return true; // ~ 1-2 Mbps + case TelephonyManager.NETWORK_TYPE_EVDO_B: + return true; // ~ 5 Mbps + case TelephonyManager.NETWORK_TYPE_HSPAP: + return true; // ~ 10-20 Mbps + case TelephonyManager.NETWORK_TYPE_IDEN: + return true; // ~ 10+ Mbps + case TelephonyManager.NETWORK_TYPE_UNKNOWN: + default: + return false; + } + } else { + return false; + } + } } diff --git a/submodules/linphone b/submodules/linphone index 7d07ca75e..1e75dc402 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 7d07ca75e745d5fc29e3f5687b5eed17a2e54135 +Subproject commit 1e75dc40229e1f8e6e5c6c121957722f11c03a3e