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
703934a221
commit
64131854ab
4 changed files with 17 additions and 12 deletions
|
@ -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>
|
||||||
|
|
|
@ -72,6 +72,8 @@ import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.firebase.iid.FirebaseInstanceId;
|
||||||
|
|
||||||
import org.linphone.call.CallActivity;
|
import org.linphone.call.CallActivity;
|
||||||
import org.linphone.call.CallIncomingActivity;
|
import org.linphone.call.CallIncomingActivity;
|
||||||
import org.linphone.activities.LinphoneActivity;
|
import org.linphone.activities.LinphoneActivity;
|
||||||
|
@ -676,6 +678,12 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1143,11 +1143,14 @@ public class LinphonePreferences {
|
||||||
if (regId != null && lc.getProxyConfigList().length > 0) {
|
if (regId != null && lc.getProxyConfigList().length > 0) {
|
||||||
for (ProxyConfig lpc : lc.getProxyConfigList()) {
|
for (ProxyConfig 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.getIdentityAddress().asStringUriOnly());
|
Log.d("Push notif infos added to proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lc.refreshRegisters();
|
lc.refreshRegisters();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,14 +30,8 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendRegistrationToServer(final String refreshedToken) {
|
|
||||||
android.util.Log.i("FirebaseIdService", "[Push Notification] Send token to server: " + refreshedToken);
|
|
||||||
LinphoneUtils.dispatchOnUIThread(new Runnable() {
|
LinphoneUtils.dispatchOnUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Reference in a new issue