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:
parent
5f2b1dbab3
commit
3371919087
4 changed files with 17 additions and 12 deletions
|
@ -293,7 +293,7 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name=".firebase.FirebaseIdService">
|
||||
<service android:name=".firebase.FirebaseIdService" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
|
||||
</intent-filter>
|
||||
|
|
|
@ -802,6 +802,12 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
} catch (Exception e1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1166,10 +1166,14 @@ public class LinphonePreferences {
|
|||
if (regId != null && lc.getProxyConfigList().length > 0) {
|
||||
for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) {
|
||||
String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1";
|
||||
lpc.edit();
|
||||
lpc.setContactUriParameters(contactInfos);
|
||||
lpc.done();
|
||||
Log.d("Push notif infos added to proxy config " + lpc.getAddress().asStringUriOnly());
|
||||
|
||||
String prevContactParams = lpc.getContactParameters();
|
||||
if (prevContactParams == null || prevContactParams.compareTo(contactInfos)!=0) {
|
||||
lpc.edit();
|
||||
lpc.setContactUriParameters(contactInfos);
|
||||
lpc.done();
|
||||
Log.d("Push notif infos added to proxy config " + lpc.getIdentity());
|
||||
}
|
||||
}
|
||||
lc.refreshRegisters();
|
||||
}
|
||||
|
|
|
@ -30,15 +30,10 @@ public class FirebaseIdService extends FirebaseInstanceIdService {
|
|||
@Override
|
||||
public void onTokenRefresh() {
|
||||
// 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);
|
||||
|
||||
sendRegistrationToServer(refreshedToken);
|
||||
}
|
||||
|
||||
private void sendRegistrationToServer(final String refreshedToken) {
|
||||
android.util.Log.i("FirebaseIdService", "[Push Notification] Send token to server: " + refreshedToken);
|
||||
UIThreadDispatcher.dispatch(new Runnable() {
|
||||
LinphoneUtils.dispatchOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken);
|
||||
|
|
Loading…
Reference in a new issue