Fix firebase. If the token is changed by the system while core is not yet instanciated, it was never saved and lost for ever.

This commit is contained in:
Simon Morlat 2018-02-21 14:58:50 +01:00
parent 5f2b1dbab3
commit 3371919087
4 changed files with 17 additions and 12 deletions

View file

@ -293,7 +293,7 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<service android:name=".firebase.FirebaseIdService"> <service android:name=".firebase.FirebaseIdService" android:exported="true">
<intent-filter> <intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter> </intent-filter>

View file

@ -802,6 +802,12 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} catch (Exception e1) { } catch (Exception e1) {
Log.i("[Push Notification] Assuming GCM jar is not provided."); Log.i("[Push Notification] Assuming GCM jar is not provided.");
} }
}else if (getString(R.string.push_type).equals("firebase")){
final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
if (refreshedToken != null) {
Log.i("[Push Notification] current token is: " + refreshedToken);
LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken);
}
} }
} }

View file

@ -1166,10 +1166,14 @@ public class LinphonePreferences {
if (regId != null && lc.getProxyConfigList().length > 0) { if (regId != null && lc.getProxyConfigList().length > 0) {
for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) { for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) {
String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1"; String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1";
String prevContactParams = lpc.getContactParameters();
if (prevContactParams == null || prevContactParams.compareTo(contactInfos)!=0) {
lpc.edit(); lpc.edit();
lpc.setContactUriParameters(contactInfos); lpc.setContactUriParameters(contactInfos);
lpc.done(); lpc.done();
Log.d("Push notif infos added to proxy config " + lpc.getAddress().asStringUriOnly()); Log.d("Push notif infos added to proxy config " + lpc.getIdentity());
}
} }
lc.refreshRegisters(); lc.refreshRegisters();
} }

View file

@ -30,15 +30,10 @@ public class FirebaseIdService extends FirebaseInstanceIdService {
@Override @Override
public void onTokenRefresh() { public void onTokenRefresh() {
// Get updated InstanceID token. // Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken(); final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
android.util.Log.i("FirebaseIdService", "[Push Notification] Refreshed token: " + refreshedToken); android.util.Log.i("FirebaseIdService", "[Push Notification] Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken); LinphoneUtils.dispatchOnUIThread(new Runnable() {
}
private void sendRegistrationToServer(final String refreshedToken) {
android.util.Log.i("FirebaseIdService", "[Push Notification] Send token to server: " + refreshedToken);
UIThreadDispatcher.dispatch(new Runnable() {
@Override @Override
public void run() { public void run() {
LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken); LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken);