fixed workaround that allowed us to expire devices

This commit is contained in:
Daniel Gultsch 2017-12-07 14:47:21 +01:00
parent a4b44ee730
commit 328c6dea0f
2 changed files with 9 additions and 9 deletions

View File

@ -80,8 +80,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
private final SerialSingleThreadExecutor executor; private final SerialSingleThreadExecutor executor;
private int numPublishTriesOnEmptyPep = 0; private int numPublishTriesOnEmptyPep = 0;
private boolean pepBroken = false; private boolean pepBroken = false;
private int lastDeviceListNotificationHash = 0;
private AtomicBoolean ownPushPending = new AtomicBoolean(false);
private AtomicBoolean changeAccessMode = new AtomicBoolean(false); private AtomicBoolean changeAccessMode = new AtomicBoolean(false);
@Override @Override
@ -350,7 +350,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
public void resetBrokenness() { public void resetBrokenness() {
this.pepBroken = false; this.pepBroken = false;
numPublishTriesOnEmptyPep = 0; this.numPublishTriesOnEmptyPep = 0;
this.lastDeviceListNotificationHash = 0;
} }
public void clearErrorsInFetchStatusMap(Jid jid) { public void clearErrorsInFetchStatusMap(Jid jid) {
@ -388,11 +389,13 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) { public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
boolean me = jid.toBareJid().equals(account.getJid().toBareJid()); final int hash = deviceIds.hashCode();
if (me && ownPushPending.getAndSet(false)) { final boolean me = jid.toBareJid().equals(account.getJid().toBareJid());
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": ignoring own device update because of pending push"); if (me && hash == this.lastDeviceListNotificationHash) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": ignoring duplicate own device id list");
return; return;
} }
this.lastDeviceListNotificationHash = hash;
boolean needsPublishing = me && !deviceIds.contains(getOwnDeviceId()); boolean needsPublishing = me && !deviceIds.contains(getOwnDeviceId());
if (me) { if (me) {
deviceIds.remove(getOwnDeviceId()); deviceIds.remove(getOwnDeviceId());
@ -527,7 +530,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
private void publishDeviceIdsAndRefineAccessModel(final Set<Integer> ids, final boolean firstAttempt) { private void publishDeviceIdsAndRefineAccessModel(final Set<Integer> ids, final boolean firstAttempt) {
final Bundle publishOptions = account.getXmppConnection().getFeatures().pepPublishOptions() ? PublishOptions.openAccess() : null; final Bundle publishOptions = account.getXmppConnection().getFeatures().pepPublishOptions() ? PublishOptions.openAccess() : null;
IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(ids, publishOptions); IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(ids, publishOptions);
ownPushPending.set(true);
mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
@ -551,7 +553,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE,false); account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE,false);
mXmppConnectionService.databaseBackend.updateAccount(account); mXmppConnectionService.databaseBackend.updateAccount(account);
} }
ownPushPending.set(false);
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.ERROR) {
pepBroken = true; pepBroken = true;
Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error")); Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error"));

View File

@ -293,10 +293,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.updateAccountUi(); mXmppConnectionService.updateAccountUi();
} }
} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) { } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
Element item = items.findChild("item"); Element item = items.findChild("item");
Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list (" + deviceIds + ") update from " + from + ", processing..."); Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list " + deviceIds + " update from " + from + ", processing... ");
AxolotlService axolotlService = account.getAxolotlService(); AxolotlService axolotlService = account.getAxolotlService();
axolotlService.registerDevices(from, deviceIds); axolotlService.registerDevices(from, deviceIds);
mXmppConnectionService.updateAccountUi(); mXmppConnectionService.updateAccountUi();