Added logs to make it easier to debug push notifications
This commit is contained in:
parent
7b2ed48b9e
commit
5f0b241e4d
4 changed files with 14 additions and 27 deletions
|
@ -646,31 +646,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
}
|
||||
|
||||
private void initPushNotificationsService() {
|
||||
if (getString(R.string.push_type).equals("google")) {
|
||||
try {
|
||||
Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
|
||||
GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
|
||||
try {
|
||||
GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, mServiceContext);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e("[Push Notification] No receiver found", e);
|
||||
}
|
||||
final String regId = (String) GCMRegistrar.getMethod("getRegistrationId", Context.class).invoke(null, mServiceContext);
|
||||
String newPushSenderID = mServiceContext.getString(R.string.push_sender_id);
|
||||
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
|
||||
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
|
||||
GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, mServiceContext, new String[]{newPushSenderID});
|
||||
Log.i("[Push Notification] Storing current sender id = " + newPushSenderID);
|
||||
} else {
|
||||
Log.i("[Push Notification] Already registered with id = " + regId);
|
||||
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
||||
}
|
||||
} catch (java.lang.UnsupportedOperationException e) {
|
||||
Log.i("[Push Notification] Not activated");
|
||||
} catch (Exception e1) {
|
||||
Log.i("[Push Notification] Assuming GCM jar is not provided.");
|
||||
}
|
||||
} else if (getString(R.string.push_type).equals("firebase")) {
|
||||
if (getString(R.string.push_type).equals("firebase")) {
|
||||
try {
|
||||
Class<?> firebaseClass = Class.forName("com.google.firebase.iid.FirebaseInstanceId");
|
||||
Object firebaseInstance = firebaseClass.getMethod("getInstance").invoke(null);
|
||||
|
@ -678,7 +654,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
|
||||
//final String refreshedToken = com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken();
|
||||
if (refreshedToken != null) {
|
||||
Log.i("[Push Notification] current token is: " + refreshedToken);
|
||||
Log.i("[Push Notification] init push notif service token is: " + refreshedToken);
|
||||
LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1237,6 +1237,7 @@ public class LinphonePreferences {
|
|||
}
|
||||
}
|
||||
}
|
||||
Log.i("[Push Notification] Refreshing registers to ensure token is up to date" + regId);
|
||||
lc.refreshRegisters();
|
||||
}
|
||||
} else {
|
||||
|
@ -1259,6 +1260,7 @@ public class LinphonePreferences {
|
|||
|
||||
public void setPushNotificationRegistrationID(String regId) {
|
||||
if (getConfig() == null) return;
|
||||
Log.i("[Push Notification] New token received" + regId);
|
||||
getConfig().setString("app", "push_notification_regid", (regId != null) ? regId : "");
|
||||
setPushNotificationEnabled(isPushNotificationEnabled());
|
||||
}
|
||||
|
|
|
@ -311,6 +311,10 @@ public final class LinphoneService extends Service {
|
|||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
||||
if (intent.getBooleanExtra("PushNotification", false)) {
|
||||
Log.i("[Push Notification] LinphoneService started because of a push");
|
||||
}
|
||||
|
||||
if (instance != null) {
|
||||
Log.w("Attempt to start the LinphoneService but it is already running !");
|
||||
return START_REDELIVER_INTENT;
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.google.firebase.messaging.RemoteMessage;
|
|||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphoneService;
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import static android.content.Intent.ACTION_MAIN;
|
||||
|
||||
|
@ -40,11 +41,15 @@ public class FirebaseMessaging extends FirebaseMessagingService {
|
|||
|
||||
if (!LinphoneService.isReady()) {
|
||||
android.util.Log.i("FirebaseMessaging", "[Push Notification] Starting Service");
|
||||
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||
Intent intent = new Intent(ACTION_MAIN);
|
||||
intent.setClass(this, LinphoneService.class);
|
||||
intent.putExtra("PushNotification", true);
|
||||
startService(intent);
|
||||
} else if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() == 0) {
|
||||
LinphoneUtils.dispatchOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("[Push Notification] Push notification received with LinphoneManager still alive");
|
||||
if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() == 0) {
|
||||
LinphoneManager.getLc().setNetworkReachable(false);
|
||||
LinphoneManager.getLc().setNetworkReachable(true);
|
||||
|
|
Loading…
Reference in a new issue