Improved time between push reception and incoming call notified to user

This commit is contained in:
Sylvain Berfini 2019-09-17 11:17:53 +02:00
parent 3fb368e961
commit 06cdd2c8cf
3 changed files with 37 additions and 26 deletions

View file

@ -19,11 +19,12 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import static android.content.Intent.ACTION_MAIN;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import org.linphone.call.CallActivity; import org.linphone.call.CallActivity;
import org.linphone.call.CallIncomingActivity; import org.linphone.call.CallIncomingActivity;
@ -47,7 +48,6 @@ public class LinphoneContext {
private static LinphoneContext sInstance = null; private static LinphoneContext sInstance = null;
private Context mContext; private Context mContext;
public final Handler handler = new Handler();
private final LoggingServiceListener mJavaLoggingService = private final LoggingServiceListener mJavaLoggingService =
new LoggingServiceListener() { new LoggingServiceListener() {
@ -74,12 +74,10 @@ public class LinphoneContext {
} }
} }
}; };
private CoreListenerStub mListener; private CoreListenerStub mListener;
private NotificationsManager mNotificationManager; private NotificationsManager mNotificationManager;
private LinphoneManager mLinphoneManager; private LinphoneManager mLinphoneManager;
private ContactsManager mContactsManager; private ContactsManager mContactsManager;
private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class; private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
public static boolean isReady() { public static boolean isReady() {
@ -130,6 +128,14 @@ public class LinphoneContext {
if (Version.sdkStrictlyBelow(Version.API24_NOUGAT_70)) { if (Version.sdkStrictlyBelow(Version.API24_NOUGAT_70)) {
if (!mLinphoneManager.getCallGsmON()) onIncomingReceived(); if (!mLinphoneManager.getCallGsmON()) onIncomingReceived();
} }
// In case of push notification Service won't be started until here
if (!LinphoneService.isReady()) {
Log.i("[Context] Service not running, starting it");
Intent intent = new Intent(ACTION_MAIN);
intent.setClass(mContext, LinphoneService.class);
mContext.startService(intent);
}
} else if (state == Call.State.OutgoingInit) { } else if (state == Call.State.OutgoingInit) {
onOutgoingStarted(); onOutgoingStarted();
} else if (state == Call.State.Connected) { } else if (state == Call.State.Connected) {
@ -160,7 +166,7 @@ public class LinphoneContext {
mNotificationManager.onCoreReady(); mNotificationManager.onCoreReady();
mContactsManager = new ContactsManager(mContext, handler); mContactsManager = new ContactsManager(mContext);
if (!Version.sdkAboveOrEqual(Version.API26_O_80) if (!Version.sdkAboveOrEqual(Version.API26_O_80)
|| (mContactsManager.hasReadContactsAccess())) { || (mContactsManager.hasReadContactsAccess())) {
mContext.getContentResolver() mContext.getContentResolver()

View file

@ -34,6 +34,7 @@ import android.database.ContentObserver;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import java.util.ArrayList; import java.util.ArrayList;
@ -67,8 +68,8 @@ public class ContactsManager extends ContentObserver implements FriendListListen
return LinphoneContext.instance().getContactsManager(); return LinphoneContext.instance().getContactsManager();
} }
public ContactsManager(Context context, Handler handler) { public ContactsManager(Context context) {
super(handler); super(new Handler(Looper.getMainLooper()));
mContext = context; mContext = context;
mContactsUpdatedListeners = new ArrayList<>(); mContactsUpdatedListeners = new ArrayList<>();
mContacts = new ArrayList<>(); mContacts = new ArrayList<>();

View file

@ -19,11 +19,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import static android.content.Intent.ACTION_MAIN;
import android.content.Intent;
import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage;
import org.linphone.LinphoneContext;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.LinphoneService; import org.linphone.LinphoneService;
import org.linphone.core.Core; import org.linphone.core.Core;
@ -32,6 +30,27 @@ import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
public class FirebaseMessaging extends FirebaseMessagingService { public class FirebaseMessaging extends FirebaseMessagingService {
private Runnable mPushReceivedRunnable =
new Runnable() {
@Override
public void run() {
if (!LinphoneService.isReady()) {
android.util.Log.i(
"FirebaseMessaging", "[Push Notification] Starting context");
new LinphoneContext(getApplicationContext());
LinphoneContext.instance().start(false);
} else {
Log.i("[Push Notification] Notifying Core");
if (LinphoneManager.getInstance() != null) {
Core core = LinphoneManager.getCore();
if (core != null) {
core.ensureRegistered();
}
}
}
}
};
public FirebaseMessaging() {} public FirebaseMessaging() {}
@Override @Override
@ -50,21 +69,6 @@ public class FirebaseMessaging extends FirebaseMessagingService {
@Override @Override
public void onMessageReceived(RemoteMessage remoteMessage) { public void onMessageReceived(RemoteMessage remoteMessage) {
android.util.Log.i("FirebaseMessaging", "[Push Notification] Received"); android.util.Log.i("FirebaseMessaging", "[Push Notification] Received");
LinphoneUtils.dispatchOnUIThread(mPushReceivedRunnable);
if (!LinphoneService.isReady()) {
android.util.Log.i("FirebaseMessaging", "[Push Notification] Starting Service");
Intent intent = new Intent(ACTION_MAIN);
intent.setClass(this, LinphoneService.class);
intent.putExtra("PushNotification", true);
startService(intent);
} else {
Log.i("[Push Notification] Notifying Core");
if (LinphoneManager.getInstance() != null) {
Core core = LinphoneManager.getCore();
if (core != null) {
core.ensureRegistered();
}
}
}
} }
} }