Improved time between push reception and incoming call notified to user
This commit is contained in:
parent
3fb368e961
commit
06cdd2c8cf
3 changed files with 37 additions and 26 deletions
|
@ -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.
|
||||
*/
|
||||
|
||||
import static android.content.Intent.ACTION_MAIN;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import org.linphone.call.CallActivity;
|
||||
import org.linphone.call.CallIncomingActivity;
|
||||
|
@ -47,7 +48,6 @@ public class LinphoneContext {
|
|||
private static LinphoneContext sInstance = null;
|
||||
|
||||
private Context mContext;
|
||||
public final Handler handler = new Handler();
|
||||
|
||||
private final LoggingServiceListener mJavaLoggingService =
|
||||
new LoggingServiceListener() {
|
||||
|
@ -74,12 +74,10 @@ public class LinphoneContext {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
private CoreListenerStub mListener;
|
||||
private NotificationsManager mNotificationManager;
|
||||
private LinphoneManager mLinphoneManager;
|
||||
private ContactsManager mContactsManager;
|
||||
|
||||
private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
|
||||
|
||||
public static boolean isReady() {
|
||||
|
@ -130,6 +128,14 @@ public class LinphoneContext {
|
|||
if (Version.sdkStrictlyBelow(Version.API24_NOUGAT_70)) {
|
||||
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) {
|
||||
onOutgoingStarted();
|
||||
} else if (state == Call.State.Connected) {
|
||||
|
@ -160,7 +166,7 @@ public class LinphoneContext {
|
|||
|
||||
mNotificationManager.onCoreReady();
|
||||
|
||||
mContactsManager = new ContactsManager(mContext, handler);
|
||||
mContactsManager = new ContactsManager(mContext);
|
||||
if (!Version.sdkAboveOrEqual(Version.API26_O_80)
|
||||
|| (mContactsManager.hasReadContactsAccess())) {
|
||||
mContext.getContentResolver()
|
||||
|
|
|
@ -34,6 +34,7 @@ import android.database.ContentObserver;
|
|||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.ContactsContract;
|
||||
import java.util.ArrayList;
|
||||
|
@ -67,8 +68,8 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
return LinphoneContext.instance().getContactsManager();
|
||||
}
|
||||
|
||||
public ContactsManager(Context context, Handler handler) {
|
||||
super(handler);
|
||||
public ContactsManager(Context context) {
|
||||
super(new Handler(Looper.getMainLooper()));
|
||||
mContext = context;
|
||||
mContactsUpdatedListeners = new ArrayList<>();
|
||||
mContacts = new ArrayList<>();
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
||||
import static android.content.Intent.ACTION_MAIN;
|
||||
|
||||
import android.content.Intent;
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
import org.linphone.LinphoneContext;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphoneService;
|
||||
import org.linphone.core.Core;
|
||||
|
@ -32,6 +30,27 @@ import org.linphone.settings.LinphonePreferences;
|
|||
import org.linphone.utils.LinphoneUtils;
|
||||
|
||||
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() {}
|
||||
|
||||
@Override
|
||||
|
@ -50,21 +69,6 @@ public class FirebaseMessaging extends FirebaseMessagingService {
|
|||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
android.util.Log.i("FirebaseMessaging", "[Push Notification] Received");
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
LinphoneUtils.dispatchOnUIThread(mPushReceivedRunnable);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue