forked from mirror/monocles_chat
do not attempt endpoint renewal when account is disabled. renew on bind
(cherry picked from commit 4ee5c167bedd4e1105c4a7b52536c8ab0eb6e37d)
This commit is contained in:
parent
c3c688eba2
commit
2bd17e80b1
3 changed files with 63 additions and 42 deletions
|
@ -50,14 +50,14 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
|
|||
sqLiteDatabase.beginTransaction();
|
||||
final Optional<String> existingApplication;
|
||||
try (final Cursor cursor =
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application"},
|
||||
"instance=?",
|
||||
new String[] {instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application"},
|
||||
"instance=?",
|
||||
new String[] {instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
existingApplication = Optional.of(cursor.getString(0));
|
||||
} else {
|
||||
|
@ -84,17 +84,18 @@ 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(),
|
||||
new String[] {account, transport},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application", "instance"},
|
||||
"account <> ? OR transport <> ? OR expiration < " + expiration,
|
||||
new String[] {account, transport},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
renewalBuilder.add(
|
||||
new PushTarget(
|
||||
|
@ -109,14 +110,15 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
|
|||
final String account, final String transport, final String instance) {
|
||||
final SQLiteDatabase sqLiteDatabase = getReadableDatabase();
|
||||
try (final Cursor cursor =
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application", "endpoint"},
|
||||
"account = ? AND transport = ? AND instance = ? ",
|
||||
new String[] {account, transport, instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application", "endpoint"},
|
||||
"account = ? AND transport = ? AND instance = ? AND endpoint IS NOT NULL AND expiration >= "
|
||||
+ System.currentTimeMillis(),
|
||||
new String[] {account, transport, instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return new ApplicationEndpoint(
|
||||
cursor.getString(cursor.getColumnIndexOrThrow("application")),
|
||||
|
@ -140,14 +142,14 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
|
|||
sqLiteDatabase.beginTransaction();
|
||||
final String existingEndpoint;
|
||||
try (final Cursor cursor =
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"endpoint"},
|
||||
"instance=?",
|
||||
new String[] {instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"endpoint"},
|
||||
"instance=?",
|
||||
new String[] {instance},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
existingEndpoint = cursor.getString(0);
|
||||
} else {
|
||||
|
@ -169,14 +171,14 @@ public class UnifiedPushDatabase extends SQLiteOpenHelper {
|
|||
final ImmutableList.Builder<PushTarget> renewalBuilder = ImmutableList.builder();
|
||||
final SQLiteDatabase sqLiteDatabase = getReadableDatabase();
|
||||
try (final Cursor cursor =
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application", "instance"},
|
||||
"account = ?",
|
||||
new String[] {account},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
sqLiteDatabase.query(
|
||||
"push",
|
||||
new String[] {"application", "instance"},
|
||||
"account = ?",
|
||||
new String[] {account},
|
||||
null,
|
||||
null,
|
||||
null)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
renewalBuilder.add(
|
||||
new PushTarget(
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -419,6 +419,7 @@ public class XmppConnectionService extends Service {
|
|||
connectMultiModeConversations(account);
|
||||
syncDirtyContacts(account);
|
||||
|
||||
unifiedPushBroker.renewUnifiedPushEndpointsOnBind(account);
|
||||
}
|
||||
};
|
||||
private boolean destroyed = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue