Moved intent filter to LinphoneActivity to prevent launcher from showing each time + started to improve this process

This commit is contained in:
Sylvain Berfini 2019-03-05 19:30:09 +01:00
parent 50be31fdc6
commit 10f34a1979
5 changed files with 205 additions and 206 deletions

View file

@ -74,6 +74,14 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity>
<activity
android:name=".LinphoneActivity"
android:launchMode="singleTask"
android:theme="@style/LinphoneStyleLight">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.CALL" /> <action android:name="android.intent.action.CALL" />
<action android:name="android.intent.action.CALL_PRIVILEGED" /> <action android:name="android.intent.action.CALL_PRIVILEGED" />
@ -122,14 +130,6 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".LinphoneActivity"
android:launchMode="singleTask"
android:theme="@style/LinphoneStyleLight">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity <activity
android:name=".call.CallIncomingActivity" android:name=".call.CallIncomingActivity"
android:launchMode="singleTop" android:launchMode="singleTop"

View file

@ -115,6 +115,7 @@ import org.linphone.settings.AccountPreferencesFragment;
import org.linphone.settings.LinphonePreferences; import org.linphone.settings.LinphonePreferences;
import org.linphone.settings.SettingsFragment; import org.linphone.settings.SettingsFragment;
import org.linphone.utils.DeviceUtils; import org.linphone.utils.DeviceUtils;
import org.linphone.utils.IntentUtils;
import org.linphone.utils.LinphoneGenericActivity; import org.linphone.utils.LinphoneGenericActivity;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
import org.linphone.views.AddressText; import org.linphone.views.AddressText;
@ -385,6 +386,7 @@ public class LinphoneActivity extends LinphoneGenericActivity
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras) { private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras) {
if (newFragmentType == mCurrentFragment if (newFragmentType == mCurrentFragment
&& newFragmentType != FragmentsAvailable.CHAT_LIST
&& newFragmentType != FragmentsAvailable.CHAT && newFragmentType != FragmentsAvailable.CHAT
&& newFragmentType != FragmentsAvailable.GROUP_CHAT) { && newFragmentType != FragmentsAvailable.GROUP_CHAT) {
return; return;
@ -1394,6 +1396,8 @@ public class LinphoneActivity extends LinphoneGenericActivity
Log.w( Log.w(
"[Linphone Activity] Device has been restricted by user (Android 9+), push notifications won't work !"); "[Linphone Activity] Device has been restricted by user (Android 9+), push notifications won't work !");
} }
IntentUtils.handleIntent(this, getIntent());
} }
@Override @Override
@ -1457,31 +1461,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
} }
} }
} }
Intent intent = getIntent();
if (intent.getStringExtra("msgShared") != null) {
Bundle extras = new Bundle();
extras.putString("messageDraft", intent.getStringExtra("msgShared"));
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, extras);
intent.removeExtra("msgShared");
} else if (intent.getStringExtra("fileShared") != null
&& !intent.getStringExtra("fileShared").equals("")) {
Bundle extras = new Bundle();
extras.putString("fileSharedUri", intent.getStringExtra("fileShared"));
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, extras);
intent.removeExtra("fileShared");
}
mIsOnBackground = false;
if (intent != null) {
Bundle extras = intent.getExtras();
if (extras != null && extras.containsKey("SipUriOrNumber")) {
addressWaitingToBeCalled = extras.getString("SipUriOrNumber");
intent.removeExtra("SipUriOrNumber");
goToDialerFragment();
}
}
} }
@Override @Override
@ -1513,61 +1492,92 @@ public class LinphoneActivity extends LinphoneGenericActivity
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
if (getCurrentFragment() == FragmentsAvailable.SETTINGS) { if (getCurrentFragment() == FragmentsAvailable.SETTINGS) {
if (mFragment instanceof SettingsFragment) { if (mFragment instanceof SettingsFragment) {
((SettingsFragment) mFragment).closePreferenceScreen(); ((SettingsFragment) mFragment).closePreferenceScreen();
} }
} }
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if (extras != null && extras.getBoolean("GoToChat", false)) { if (extras != null) {
if (extras.getBoolean("GoToChat", false)) {
String localSipUri = extras.getString("LocalSipUri"); String localSipUri = extras.getString("LocalSipUri");
String remoteSipUri = extras.getString("ChatContactSipUri"); String remoteSipUri = extras.getString("ChatContactSipUri");
Log.i(
"[Linphone Activity] Intent asked to go to chat, local URI "
+ localSipUri
+ ", remote URI "
+ remoteSipUri);
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
if (remoteSipUri == null) { if (remoteSipUri == null) {
goToChatList(); goToChatList();
} else { } else {
goToChat(localSipUri, remoteSipUri, extras); goToChat(localSipUri, remoteSipUri, extras);
} }
} else if (extras != null && extras.getBoolean("GoToHistory", false)) { } else if (extras.getBoolean("GoToHistory", false)) {
Log.i("[Linphone Activity] Intent asked to go to call history");
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null); changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null);
} else if (extras != null && extras.getBoolean("GoToInapp", false)) { } else if (extras.getBoolean("GoToInapp", false)) {
Log.i("[Linphone Activity] Intent asked to go to inapp");
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
displayInapp(); displayInapp();
} else if (extras != null && extras.getBoolean("Notification", false)) { } else if (extras.getBoolean("Notification", false)) {
if (LinphoneManager.getLc().getCallsNb() > 0) { if (LinphoneManager.getLc().getCallsNb() > 0) {
startIncallActivity(); startIncallActivity();
} }
} else if (extras != null && extras.getBoolean("StartCall", false)) { } else if (extras.getBoolean("StartCall", false)) {
if (CallActivity.isInstanciated()) { if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity(); CallActivity.instance().startIncomingCallActivity();
} else { } else {
addressWaitingToBeCalled = extras.getString("NumberToCall"); addressWaitingToBeCalled = extras.getString("NumberToCall");
goToDialerFragment(); goToDialerFragment();
} }
} else if (extras != null && extras.getBoolean("Transfer", false)) { } else if (extras.getBoolean("Transfer", false)) {
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
} else if (extras != null && extras.getBoolean("AddCall", false)) { } else if (extras.getBoolean("AddCall", false)) {
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
} else if (intent.getStringExtra("msgShared") != null) {
String message = intent.getStringExtra("msgShared");
Log.i(
"[Linphone Activity] Intent asked to go to chat list to share message "
+ message);
extras.putString("messageDraft", message);
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, extras);
intent.removeExtra("msgShared");
} else if (intent.getStringExtra("fileShared") != null
&& !intent.getStringExtra("fileShared").equals("")) {
String file = intent.getStringExtra("fileShared");
Log.i(
"[Linphone Activity] Intent asked to go to chat list to share file(s) "
+ file);
extras.putString("fileSharedUri", file);
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, extras);
intent.removeExtra("fileShared");
} else { } else {
DialerFragment dialerFragment = DialerFragment.instance(); DialerFragment dialerFragment = DialerFragment.instance();
if (dialerFragment != null) { if (dialerFragment != null) {
if (extras != null && extras.containsKey("SipUriOrNumber")) { if (extras.containsKey("SipUriOrNumber")) {
if (getResources() if (getResources()
.getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) { .getBoolean(
R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
dialerFragment.newOutgoingCall(extras.getString("SipUriOrNumber")); dialerFragment.newOutgoingCall(extras.getString("SipUriOrNumber"));
} else { } else {
dialerFragment.displayTextInAddressBar(extras.getString("SipUriOrNumber")); dialerFragment.displayTextInAddressBar(
extras.getString("SipUriOrNumber"));
}
} }
} else { } else {
dialerFragment.newOutgoingCall(intent); if (extras.containsKey("SipUriOrNumber")) {
}
} else {
if (extras != null && extras.containsKey("SipUriOrNumber")) {
addressWaitingToBeCalled = extras.getString("SipUriOrNumber"); addressWaitingToBeCalled = extras.getString("SipUriOrNumber");
goToDialerFragment(); goToDialerFragment();
} }
} }
}
}
setIntent(intent);
if (LinphoneManager.getLc().getCalls().length > 0) { if (LinphoneManager.getLc().getCalls().length > 0) {
// If a call is ringing, start incomingcallactivity // If a call is ringing, start incomingcallactivity
Collection<Call.State> incoming = new ArrayList<>(); Collection<Call.State> incoming = new ArrayList<>();
@ -1581,8 +1591,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
} }
} }
} }
setIntent(intent);
}
public boolean isOnBackground() { public boolean isOnBackground() {
return mIsOnBackground; return mIsOnBackground;

View file

@ -24,26 +24,16 @@ import static android.content.Intent.ACTION_MAIN;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import java.util.ArrayList;
import org.linphone.assistant.RemoteProvisioningActivity; import org.linphone.assistant.RemoteProvisioningActivity;
import org.linphone.call.CallActivity;
import org.linphone.contacts.ContactsManager;
import org.linphone.settings.LinphonePreferences; import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.FileUtils;
/** Launch Linphone main activity when Service is ready. */ /** Launch Linphone main activity when Service is ready. */
public class LinphoneLauncherActivity extends Activity { public class LinphoneLauncherActivity extends Activity {
private final String ACTION_CALL_LINPHONE = "org.linphone.intent.action.CallLaunched";
private Handler mHandler; private Handler mHandler;
private ServiceWaitThread mServiceThread; private ServiceWaitThread mServiceThread;
private String mAddressToCall;
private Uri mUriToResolve;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -56,32 +46,6 @@ public class LinphoneLauncherActivity extends Activity {
mHandler = new Handler(); mHandler = new Handler();
Intent intent = getIntent();
if (intent != null) {
String action = intent.getAction();
if (Intent.ACTION_CALL.equals(action)) {
if (intent.getData() != null) {
mAddressToCall = intent.getData().toString();
mAddressToCall = mAddressToCall.replace("%40", "@");
mAddressToCall = mAddressToCall.replace("%3A", ":");
if (mAddressToCall.startsWith("sip:")) {
mAddressToCall = mAddressToCall.substring("sip:".length());
} else if (mAddressToCall.startsWith("tel:")) {
mAddressToCall = mAddressToCall.substring("tel:".length());
}
}
} else if (Intent.ACTION_VIEW.equals(action)) {
if (LinphoneService.isReady()) {
mAddressToCall =
ContactsManager.getInstance()
.getAddressOrNumberForAndroidContact(
getContentResolver(), intent.getData());
} else {
mUriToResolve = intent.getData();
}
}
}
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onServiceReady(); onServiceReady();
} else { } else {
@ -108,66 +72,8 @@ public class LinphoneLauncherActivity extends Activity {
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
Intent newIntent = new Intent(LinphoneLauncherActivity.this, classToStart); Intent intent = new Intent(LinphoneLauncherActivity.this, classToStart);
Intent intent = getIntent(); startActivity(intent);
String stringFileShared = null;
String stringUriFileShared = null;
Uri fileUri = null;
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
newIntent.setData(intent.getData());
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (("text/plain").equals(type)
&& intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
stringFileShared = intent.getStringExtra(Intent.EXTRA_TEXT);
newIntent.putExtra("msgShared", stringFileShared);
} else {
fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
stringUriFileShared =
FileUtils.getFilePath(getBaseContext(), fileUri);
newIntent.putExtra("fileShared", stringUriFileShared);
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
ArrayList<Uri> imageUris =
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
String filePaths = "";
for (Uri uri : imageUris) {
filePaths += FileUtils.getFilePath(getBaseContext(), uri);
filePaths += ":";
}
newIntent.putExtra("fileShared", filePaths);
}
} else if (ACTION_CALL_LINPHONE.equals(action)
&& (intent.getStringExtra("NumberToCall") != null)) {
String numberToCall = intent.getStringExtra("NumberToCall");
if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity();
} else {
LinphoneManager.getInstance()
.newOutgoingCall(numberToCall, null);
}
}
}
if (mUriToResolve != null) {
mAddressToCall =
ContactsManager.getInstance()
.getAddressOrNumberForAndroidContact(
getContentResolver(), mUriToResolve);
Log.i(
"LinphoneLauncher",
"Intent has uri to resolve : " + mUriToResolve.toString());
mUriToResolve = null;
}
if (mAddressToCall != null) {
newIntent.putExtra("SipUriOrNumber", mAddressToCall);
Log.i(
"LinphoneLauncher",
"Intent has address to call : " + mAddressToCall);
mAddressToCall = null;
}
startActivity(newIntent);
} }
}, },
1000); 1000);

View file

@ -20,11 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager;
import android.app.Application; import android.app.Application;
import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
@ -32,7 +29,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.SystemClock;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.view.WindowManager; import android.view.WindowManager;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,7 +48,6 @@ import org.linphone.core.tools.Log;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import org.linphone.notifications.NotificationsManager; import org.linphone.notifications.NotificationsManager;
import org.linphone.receivers.BluetoothManager; import org.linphone.receivers.BluetoothManager;
import org.linphone.receivers.KeepAliveReceiver;
import org.linphone.settings.LinphonePreferences; import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
import org.linphone.views.LinphoneGL2JNIViewOverlay; import org.linphone.views.LinphoneGL2JNIViewOverlay;
@ -175,7 +170,7 @@ public final class LinphoneService extends Service {
if (sInstance != null) { if (sInstance != null) {
Log.w("[Service] Attempt to start the LinphoneService but it is already running !"); Log.w("[Service] Attempt to start the LinphoneService but it is already running !");
return START_REDELIVER_INTENT; return START_STICKY;
} }
LinphoneManager.createAndStart(this, isPush); LinphoneManager.createAndStart(this, isPush);
@ -263,25 +258,9 @@ public final class LinphoneService extends Service {
5000); 5000);
} }
// make sure the application will at least wakes up every 10 mn
if (LinphonePreferences.instance().isBackgroundModeEnabled()
&& (!LinphonePreferences.instance().isPushNotificationEnabled()
|| !LinphoneManager.getInstance().hasLinphoneAccount())) {
Intent keepAliveIntent = new Intent(this, KeepAliveReceiver.class);
PendingIntent keepAlivePendingIntent =
PendingIntent.getBroadcast(
this, 0, keepAliveIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager =
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE));
alarmManager.setExact(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + 600000,
keepAlivePendingIntent);
}
BluetoothManager.getInstance().initBluetooth(); BluetoothManager.getInstance().initBluetooth();
return START_REDELIVER_INTENT; return START_STICKY;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -0,0 +1,106 @@
package org.linphone.utils;
/*
IntentUtils.java
Copyright (C) 2018 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.util.ArrayList;
import org.linphone.LinphoneActivity;
import org.linphone.LinphoneManager;
import org.linphone.call.CallActivity;
import org.linphone.contacts.ContactsManager;
import org.linphone.core.tools.Log;
public class IntentUtils {
private static final String ACTION_CALL_LINPHONE = "org.linphone.intent.action.CallLaunched";
public static void handleIntent(Context context, Intent intent) {
if (intent == null) return;
Intent newIntent = new Intent(context, LinphoneActivity.class);
String stringFileShared;
String stringUriFileShared;
Uri fileUri;
String addressToCall;
String action = intent.getAction();
String type = intent.getType();
newIntent.setData(intent.getData());
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (("text/plain").equals(type) && intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
stringFileShared = intent.getStringExtra(Intent.EXTRA_TEXT);
newIntent.putExtra("msgShared", stringFileShared);
Log.i("[Intent Utils] ACTION_SEND with text/plain data: " + stringFileShared);
} else {
fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
stringUriFileShared = FileUtils.getFilePath(context, fileUri);
newIntent.putExtra("fileShared", stringUriFileShared);
Log.i("[Intent Utils] ACTION_SEND with file: " + stringUriFileShared);
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
String filePaths = "";
for (Uri uri : imageUris) {
filePaths += FileUtils.getFilePath(context, uri);
filePaths += ":";
}
newIntent.putExtra("fileShared", filePaths);
Log.i("[Intent Utils] ACTION_SEND_MULTIPLE with files: " + filePaths);
}
} else if (ACTION_CALL_LINPHONE.equals(action)
&& (intent.getStringExtra("NumberToCall") != null)) {
String numberToCall = intent.getStringExtra("NumberToCall");
Log.i("[Intent Utils] ACTION_CALL_LINPHONE with number: " + numberToCall);
if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity();
} else {
LinphoneManager.getInstance().newOutgoingCall(numberToCall, null);
}
} else if (Intent.ACTION_CALL.equals(action)) {
if (intent.getData() != null) {
addressToCall = intent.getData().toString();
addressToCall = addressToCall.replace("%40", "@");
addressToCall = addressToCall.replace("%3A", ":");
if (addressToCall.startsWith("sip:")) {
addressToCall = addressToCall.substring("sip:".length());
} else if (addressToCall.startsWith("tel:")) {
addressToCall = addressToCall.substring("tel:".length());
}
Log.i("[Intent Utils] ACTION_CALL with number: " + addressToCall);
newIntent.putExtra("SipUriOrNumber", addressToCall);
}
} else if (Intent.ACTION_VIEW.equals(action)) {
addressToCall =
ContactsManager.getInstance()
.getAddressOrNumberForAndroidContact(
context.getContentResolver(), intent.getData());
newIntent.putExtra("SipUriOrNumber", addressToCall);
Log.i("[Intent Utils] ACTION_VIEW with number: " + addressToCall);
} else {
Log.i("[Intent Utils] Unknown action [" + action + "], skipping");
return;
}
context.startActivity(newIntent);
}
}