do not attempt endpoint renewal when account is disabled. renew on bind

This commit is contained in:
Daniel Gultsch 2023-01-04 20:59:08 +01:00
parent b1f95d2e39
commit 4ee5c167be
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 25 additions and 4 deletions

View file

@ -84,13 +84,14 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
public List<PushTarget> getRenewals(final String account, final String transport) {
final ImmutableList.Builder<PushTarget> renewalBuilder = ImmutableList.builder();
// TODO use a date somewhat in the future to account for period renewal triggers
final long expiration = System.currentTimeMillis();
final SQLiteDatabase sqLiteDatabase = getReadableDatabase();
try (final Cursor cursor =
sqLiteDatabase.query(
"push",
new String[] {"application", "instance"},
"account <> ? OR transport <> ? OR expiration < "
+ System.currentTimeMillis(),
"account <> ? OR transport <> ? OR expiration < " + expiration,
new String[] {account, transport},
null,
null,
@ -112,7 +113,8 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
sqLiteDatabase.query(
"push",
new String[] {"application", "endpoint"},
"account = ? AND transport = ? AND instance = ? ",
"account = ? AND transport = ? AND instance = ? AND endpoint IS NOT NULL AND expiration >= "
+ System.currentTimeMillis(),
new String[] {account, transport, instance},
null,
null,

View file

@ -34,10 +34,28 @@ public class UnifiedPushBroker {
this.service = xmppConnectionService;
}
public void renewUnifiedPushEndpointsOnBind(final Account account) {
final Optional<Transport> transport = getTransport();
if (transport.isPresent()) {
final Account transportAccount = transport.get().account;
if (transportAccount != null && transportAccount.getUuid().equals(account.getUuid())) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid() + ": trigger endpoint renewal on bind");
renewUnifiedEndpoint(transport.get());
}
}
}
public Optional<Transport> renewUnifiedPushEndpoints() {
final Optional<Transport> transportOptional = getTransport();
if (transportOptional.isPresent()) {
renewUnifiedEndpoint(transportOptional.get());
final Transport transport = transportOptional.get();
if (transport.account.isEnabled()) {
renewUnifiedEndpoint(transportOptional.get());
} else {
Log.d(Config.LOGTAG, "skipping UnifiedPush endpoint renewal. Account is disabled");
}
} else {
Log.d(Config.LOGTAG, "skipping UnifiedPush endpoint renewal. No transport selected");
}

View file

@ -381,6 +381,7 @@ public class XmppConnectionService extends Service {
connectMultiModeConversations(account);
syncDirtyContacts(account);
unifiedPushBroker.renewUnifiedPushEndpointsOnBind(account);
}
};
private final AtomicLong mLastExpiryRun = new AtomicLong(0);