From e74402bd304e8ab36cfae0fd75e8f6b47c834b67 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 6 Feb 2014 16:07:49 +0100 Subject: [PATCH] Improved way of intercepting outgoing gsm calls --- AndroidManifest.xml | 18 ++++---- res/values/non_localizable_custom.xml | 2 + src/org/linphone/AndroidCallInterceptor.java | 44 +++++++++++++++++++ src/org/linphone/BluetoothActionReceiver.java | 19 ++++++++ src/org/linphone/DialerFragment.java | 10 +++++ src/org/linphone/LinphoneActivity.java | 18 ++++++-- src/org/linphone/LinphonePreferences.java | 3 ++ 7 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 src/org/linphone/AndroidCallInterceptor.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 10cc42474..3f90022ed 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@ - + @@ -49,14 +49,6 @@ - - - - - - - - @@ -106,7 +98,13 @@ - + + + + + + + diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml index 71aebf4c6..b4c187fad 100644 --- a/res/values/non_localizable_custom.xml +++ b/res/values/non_localizable_custom.xml @@ -67,6 +67,8 @@ false true false + false + true true diff --git a/src/org/linphone/AndroidCallInterceptor.java b/src/org/linphone/AndroidCallInterceptor.java new file mode 100644 index 000000000..d1932340c --- /dev/null +++ b/src/org/linphone/AndroidCallInterceptor.java @@ -0,0 +1,44 @@ +package org.linphone; + +/* +AndroidCallInterceptor.java +Copyright (C) 2014 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class AndroidCallInterceptor extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + String phoneNumber = getResultData(); + if (phoneNumber == null) { + phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); + } + + if (context.getResources().getBoolean(R.bool.intercept_outgoing_gsm_calls) || LinphonePreferences.instance().interceptOutgoingGSMCalls()) { + setResultData(null); + Intent i = new Intent(); + i.setClass(context, LinphoneActivity.class); + i.putExtra("SipUriOrNumber", phoneNumber); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(i); + } + } +} diff --git a/src/org/linphone/BluetoothActionReceiver.java b/src/org/linphone/BluetoothActionReceiver.java index cf160aa0d..c8a141fef 100644 --- a/src/org/linphone/BluetoothActionReceiver.java +++ b/src/org/linphone/BluetoothActionReceiver.java @@ -1,5 +1,24 @@ package org.linphone; +/* +BluetoothActionReceiver.java +Copyright (C) 2014 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + import org.linphone.mediastream.Log; import android.annotation.TargetApi; diff --git a/src/org/linphone/DialerFragment.java b/src/org/linphone/DialerFragment.java index be9d5bd18..a40bc3f58 100644 --- a/src/org/linphone/DialerFragment.java +++ b/src/org/linphone/DialerFragment.java @@ -185,6 +185,16 @@ public class DialerFragment extends Fragment { mAddContact.setEnabled(LinphoneManager.getLc().getCallsNb() > 0 || !mAddress.getText().toString().equals("")); } + public void displayTextInAddressBar(String numberOrSipAddress) { + shouldEmptyAddressField = false; + mAddress.setText(numberOrSipAddress); + } + + public void newOutgoingCall(String numberOrSipAddress) { + displayTextInAddressBar(numberOrSipAddress); + LinphoneManager.getInstance().newOutgoingCall(mAddress); + } + public void newOutgoingCall(Intent intent) { if (intent != null && intent.getData() != null) { String scheme = intent.getData().getScheme(); diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index b62971984..ad50ae72d 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -282,8 +282,12 @@ public class LinphoneActivity extends FragmentActivity implements newFragment = new HistoryDetailFragment(); break; case CONTACTS: - newFragment = new ContactsFragment(); - friendStatusListenerFragment = newFragment; + if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) { + + } else { + newFragment = new ContactsFragment(); + friendStatusListenerFragment = newFragment; + } break; case CONTACT: newFragment = new ContactFragment(); @@ -1302,7 +1306,15 @@ public class LinphoneActivity extends FragmentActivity implements } } else { if (dialerFragment != null) { - ((DialerFragment) dialerFragment).newOutgoingCall(intent); + if (extras.containsKey("SipUriOrNumber")) { + if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) { + ((DialerFragment) dialerFragment).newOutgoingCall(extras.getString("SipUriOrNumber")); + } else { + ((DialerFragment) dialerFragment).displayTextInAddressBar(extras.getString("SipUriOrNumber")); + } + } else { + ((DialerFragment) dialerFragment).newOutgoingCall(intent); + } } if (LinphoneManager.getLc().getCalls().length > 0) { LinphoneCall calls[] = LinphoneManager.getLc().getCalls(); diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index 38cc5d4f0..6d2d7023b 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -810,4 +810,7 @@ public class LinphonePreferences { } // End of tunnel settings + public boolean interceptOutgoingGSMCalls() { + return getConfig().getBool("app", "intercept_outgoing_gsm_calls", false); + } }