From 26c348520f12d32de3ab0557208b04467146aea1 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Tue, 18 Feb 2025 12:48:34 -0600 Subject: [PATCH] Revert "Add a 2-notification ttl=0 push notification experiment" This reverts commit 4908a0aa9e0584367549281031b9645c110639ab. --- .../textsecuregcm/WhisperServerService.java | 23 ---- .../ZeroTtlPushNotificationExperiment.java | 51 --------- .../textsecuregcm/push/FcmSender.java | 21 +--- .../textsecuregcm/push/PushNotification.java | 9 +- .../push/PushNotificationManager.java | 18 +-- .../push/PushNotificationScheduler.java | 5 +- .../push/ZeroTtlNotificationScheduler.java | 103 ------------------ ...xperimentNotificationSchedulerFactory.java | 26 ----- ...oTtlPushNotificationExperimentFactory.java | 36 ------ .../textsecuregcm/push/APNSenderTest.java | 12 +- .../textsecuregcm/push/FcmSenderTest.java | 8 +- .../push/PushNotificationManagerTest.java | 20 ++-- 12 files changed, 28 insertions(+), 304 deletions(-) delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/experiment/ZeroTtlPushNotificationExperiment.java delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/push/ZeroTtlNotificationScheduler.java delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlExperimentNotificationSchedulerFactory.java delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlPushNotificationExperimentFactory.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index ddf691585..c2b0bd986 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -268,8 +268,6 @@ import org.whispersystems.textsecuregcm.workers.BackupMetricsCommand; import org.whispersystems.textsecuregcm.workers.CertificateCommand; import org.whispersystems.textsecuregcm.workers.CheckDynamicConfigurationCommand; import org.whispersystems.textsecuregcm.workers.DeleteUserCommand; -import org.whispersystems.textsecuregcm.workers.DiscardPushNotificationExperimentSamplesCommand; -import org.whispersystems.textsecuregcm.workers.FinishPushNotificationExperimentCommand; import org.whispersystems.textsecuregcm.workers.IdleDeviceNotificationSchedulerFactory; import org.whispersystems.textsecuregcm.workers.MessagePersisterServiceCommand; import org.whispersystems.textsecuregcm.workers.NotifyIdleDevicesCommand; @@ -282,10 +280,7 @@ import org.whispersystems.textsecuregcm.workers.ScheduledApnPushNotificationSend import org.whispersystems.textsecuregcm.workers.ServerVersionCommand; import org.whispersystems.textsecuregcm.workers.SetRequestLoggingEnabledTask; import org.whispersystems.textsecuregcm.workers.SetUserDiscoverabilityCommand; -import org.whispersystems.textsecuregcm.workers.StartPushNotificationExperimentCommand; import org.whispersystems.textsecuregcm.workers.UnlinkDeviceCommand; -import org.whispersystems.textsecuregcm.workers.ZeroTtlExperimentNotificationSchedulerFactory; -import org.whispersystems.textsecuregcm.workers.ZeroTtlPushNotificationExperimentFactory; import org.whispersystems.textsecuregcm.workers.ZkParamsCommand; import org.whispersystems.websocket.WebSocketResourceProviderFactory; import org.whispersystems.websocket.setup.WebSocketEnvironment; @@ -340,24 +335,6 @@ public class WhisperServerService extends Application("start-zero-ttl-push-notification-experiment", - "Start an experiment to send push notifications with ttl=0 to idle android devices", - new ZeroTtlPushNotificationExperimentFactory())); - - bootstrap.addCommand( - new FinishPushNotificationExperimentCommand<>("finish-zero-ttl-push-notification-experiment", - "Finish an experiment to send push notifications with ttl=0 to idle android devices", - new ZeroTtlPushNotificationExperimentFactory())); - - bootstrap.addCommand( - new DiscardPushNotificationExperimentSamplesCommand("discard-zero-ttl-push-notification-experiment", - "Discard samples from the \"zero TTL push notification\" experiment", - new ZeroTtlPushNotificationExperimentFactory())); - - bootstrap.addCommand(new ProcessScheduledJobsServiceCommand("process-zero-ttl-notification-jobs", - "Processes scheduled jobs to send zero-ttl experiment notifications to idle devices", - new ZeroTtlExperimentNotificationSchedulerFactory())); - bootstrap.addCommand(new ProcessScheduledJobsServiceCommand("process-idle-device-notification-jobs", "Processes scheduled jobs to send notifications to idle devices", new IdleDeviceNotificationSchedulerFactory())); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ZeroTtlPushNotificationExperiment.java b/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ZeroTtlPushNotificationExperiment.java deleted file mode 100644 index 2ca4168ea..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ZeroTtlPushNotificationExperiment.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2025 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.experiment; - -import org.whispersystems.textsecuregcm.push.ZeroTtlNotificationScheduler; -import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.workers.IdleWakeupEligibilityChecker; -import java.time.LocalTime; -import java.util.concurrent.CompletableFuture; - -public class ZeroTtlPushNotificationExperiment extends IdleDevicePushNotificationExperiment { - private static final LocalTime PREFERRED_NOTIFICATION_TIME = LocalTime.of(14, 0); - - private final ZeroTtlNotificationScheduler zeroTtlNotificationScheduler; - - public ZeroTtlPushNotificationExperiment( - final IdleWakeupEligibilityChecker idleWakeupEligibilityChecker, - final ZeroTtlNotificationScheduler zeroTtlNotificationScheduler) { - super(idleWakeupEligibilityChecker); - this.zeroTtlNotificationScheduler = zeroTtlNotificationScheduler; - } - - @Override - boolean isIdleDeviceEligible(final Account account, final Device idleDevice, final DeviceLastSeenState state) { - return state.pushTokenType() == DeviceLastSeenState.PushTokenType.FCM; - } - - @Override - public String getExperimentName() { - return "zero-ttl-notification"; - } - - @Override - public Class getStateClass() { - return DeviceLastSeenState.class; - } - - @Override - public CompletableFuture applyExperimentTreatment(final Account account, final Device device) { - return zeroTtlNotificationScheduler.scheduleNotification(account, device, PREFERRED_NOTIFICATION_TIME, true); - } - - @Override - public CompletableFuture applyControlTreatment(final Account account, final Device device) { - return zeroTtlNotificationScheduler.scheduleNotification(account, device, PREFERRED_NOTIFICATION_TIME, false); - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/FcmSender.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/FcmSender.java index 8bbadafa7..ad38ae334 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/FcmSender.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/FcmSender.java @@ -14,7 +14,6 @@ import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.ThreadManager; import com.google.firebase.messaging.AndroidConfig; -import com.google.firebase.messaging.AndroidNotification; import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.FirebaseMessagingException; import com.google.firebase.messaging.Message; @@ -25,7 +24,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Optional; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; @@ -80,24 +78,11 @@ public class FcmSender implements PushNotificationSender { @Override public CompletableFuture sendNotification(PushNotification pushNotification) { - final AndroidConfig.Builder androidConfig = AndroidConfig.builder() - .setPriority(pushNotification.urgent() ? AndroidConfig.Priority.HIGH : AndroidConfig.Priority.NORMAL); - - // This experiment compares the effect of two standard push notifications to one standard + one with a TTL=0 - switch (pushNotification.experimentalNotificationType().orElse(null)) { - case ZERO_TTL -> { - androidConfig.setTtl(0); - androidConfig.setCollapseKey("ttl0"); - } - case NON_COLLAPSIBLE -> - // We still want to make sure we don't collapse notifications in the control group - androidConfig.setCollapseKey("ttl0"); - case null -> {} - } - Message.Builder builder = Message.builder() .setToken(pushNotification.deviceToken()) - .setAndroidConfig(androidConfig.build()); + .setAndroidConfig(AndroidConfig.builder() + .setPriority(pushNotification.urgent() ? AndroidConfig.Priority.HIGH : AndroidConfig.Priority.NORMAL) + .build()); final String key = switch (pushNotification.notificationType()) { case NOTIFICATION -> "newMessageAlert"; diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotification.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotification.java index 129698e6b..3f3738de5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotification.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotification.java @@ -8,7 +8,6 @@ package org.whispersystems.textsecuregcm.push; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.Device; import javax.annotation.Nullable; -import java.util.Optional; public record PushNotification(String deviceToken, TokenType tokenType, @@ -16,8 +15,7 @@ public record PushNotification(String deviceToken, @Nullable String data, @Nullable Account destination, @Nullable Device destinationDevice, - boolean urgent, - Optional experimentalNotificationType) { + boolean urgent) { public enum NotificationType { NOTIFICATION, @@ -30,9 +28,4 @@ public record PushNotification(String deviceToken, FCM, APN } - - public enum ExperimentalNotificationType { - ZERO_TTL, - NON_COLLAPSIBLE - } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java index 04f953205..2780d78a0 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java @@ -51,21 +51,11 @@ public class PushNotificationManager { final Pair tokenAndType = getToken(device); return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), - PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent, Optional.empty())); - } - - public CompletableFuture> sendExperimentMessageNotification( - final Account destination, final byte destinationDeviceId, final boolean urgent, PushNotification.ExperimentalNotificationType experimentalNotificationType) throws NotPushRegisteredException { - final Device device = destination.getDevice(destinationDeviceId).orElseThrow(NotPushRegisteredException::new); - final Pair tokenAndType = getToken(device); - - return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), - PushNotification.NotificationType.NOTIFICATION, - null, destination, device, urgent, Optional.of(experimentalNotificationType))); + PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent)); } public CompletableFuture sendRegistrationChallengeNotification(final String deviceToken, final PushNotification.TokenType tokenType, final String challengeToken) { - return sendNotification(new PushNotification(deviceToken, tokenType, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true, Optional.empty())) + return sendNotification(new PushNotification(deviceToken, tokenType, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true)) .thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications"))); } @@ -76,7 +66,7 @@ public class PushNotificationManager { final Pair tokenAndType = getToken(device); return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), - PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, destination, device, true, Optional.empty())) + PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, destination, device, true)) .thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications"))); } @@ -86,7 +76,7 @@ public class PushNotificationManager { return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY, - context, destination, device, true, Optional.empty())) + context, destination, device, true)) .thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications"))); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationScheduler.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationScheduler.java index 329c11514..5596cba81 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationScheduler.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationScheduler.java @@ -286,7 +286,7 @@ public class PushNotificationScheduler implements Managed { return pushSchedulingCluster.withCluster(connection -> connection.async().set( getLastBackgroundApnsNotificationTimestampKey(account, device), String.valueOf(clock.millis()), new SetArgs().ex(BACKGROUND_NOTIFICATION_PERIOD))) - .thenCompose(ignored -> apnSender.sendNotification(new PushNotification(device.getApnId(), PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, false, Optional.empty()))) + .thenCompose(ignored -> apnSender.sendNotification(new PushNotification(device.getApnId(), PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, false))) .thenAccept(response -> Metrics.counter(BACKGROUND_NOTIFICATION_SENT_COUNTER_NAME, ACCEPTED_TAG, String.valueOf(response.accepted())) .increment()) @@ -308,8 +308,7 @@ public class PushNotificationScheduler implements Managed { null, account, device, - true, - Optional.empty()); + true); final PushNotificationSender pushNotificationSender = isApnsDevice ? apnSender : fcmSender; diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/ZeroTtlNotificationScheduler.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/ZeroTtlNotificationScheduler.java deleted file mode 100644 index 296bdf380..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/ZeroTtlNotificationScheduler.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.whispersystems.textsecuregcm.push; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.annotations.VisibleForTesting; -import java.io.IOException; -import java.time.Clock; -import java.time.Duration; -import java.time.Instant; -import java.time.LocalTime; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; -import org.whispersystems.textsecuregcm.identity.IdentityType; -import org.whispersystems.textsecuregcm.scheduler.JobScheduler; -import org.whispersystems.textsecuregcm.scheduler.SchedulingUtil; -import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.AccountsManager; -import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.util.SystemMapper; -import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; - -public class ZeroTtlNotificationScheduler extends JobScheduler { - - private final AccountsManager accountsManager; - private final PushNotificationManager pushNotificationManager; - private final Clock clock; - - @VisibleForTesting - record JobDescriptor(UUID accountIdentifier, byte deviceId, long lastSeen, boolean zeroTtl) {} - - public ZeroTtlNotificationScheduler( - final AccountsManager accountsManager, - final PushNotificationManager pushNotificationManager, - final DynamoDbAsyncClient dynamoDbAsyncClient, - final String tableName, - final Duration jobExpiration, - final Clock clock) { - - super(dynamoDbAsyncClient, tableName, jobExpiration, clock); - - this.accountsManager = accountsManager; - this.pushNotificationManager = pushNotificationManager; - this.clock = clock; - } - - @Override - public String getSchedulerName() { - return "ZeroTtlNotification"; - } - - @Override - protected CompletableFuture processJob(@Nullable final byte[] jobData) { - final JobDescriptor jobDescriptor; - - try { - jobDescriptor = SystemMapper.jsonMapper().readValue(jobData, JobDescriptor.class); - } catch (final IOException e) { - return CompletableFuture.failedFuture(e); - } - - return accountsManager.getByAccountIdentifierAsync(jobDescriptor.accountIdentifier()) - .thenCompose(maybeAccount -> maybeAccount.map(account -> - account.getDevice(jobDescriptor.deviceId()).map(device -> { - if (jobDescriptor.lastSeen() != device.getLastSeen()) { - return CompletableFuture.completedFuture("deviceSeenRecently"); - } - - try { - return sendNotification(account, jobDescriptor).thenApply(ignored -> "sent"); - } catch (final NotPushRegisteredException e) { - return CompletableFuture.completedFuture("deviceTokenDeleted"); - } - }) - .orElse(CompletableFuture.completedFuture("deviceDeleted"))) - .orElse(CompletableFuture.completedFuture("accountDeleted"))); - } - - private CompletableFuture sendNotification(final Account account, - final JobDescriptor jobDescriptor) throws NotPushRegisteredException { - final CompletableFuture> standardNotification = pushNotificationManager.sendNewMessageNotification( - account, jobDescriptor.deviceId(), true); - final CompletableFuture> experimentNotification = pushNotificationManager.sendExperimentMessageNotification( - account, jobDescriptor.deviceId(), true, jobDescriptor.zeroTtl() - ? PushNotification.ExperimentalNotificationType.ZERO_TTL - : PushNotification.ExperimentalNotificationType.NON_COLLAPSIBLE); - - return standardNotification.thenCombine(experimentNotification, (ignored1, ignored2) -> null); - } - - public CompletableFuture scheduleNotification(final Account account, final Device device, - final LocalTime preferredDeliveryTime, boolean zeroTtl) { - final Instant runAt = SchedulingUtil.getNextRecommendedNotificationTime(account, preferredDeliveryTime, clock); - - try { - return scheduleJob(runAt, SystemMapper.jsonMapper().writeValueAsBytes( - new JobDescriptor(account.getIdentifier(IdentityType.ACI), device.getId(), device.getLastSeen(), zeroTtl))); - } catch (final JsonProcessingException e) { - // This should never happen when serializing an `AccountAndDeviceIdentifier` - throw new AssertionError(e); - } - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlExperimentNotificationSchedulerFactory.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlExperimentNotificationSchedulerFactory.java deleted file mode 100644 index 6439374b6..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlExperimentNotificationSchedulerFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.whispersystems.textsecuregcm.workers; - -import java.time.Clock; -import org.whispersystems.textsecuregcm.WhisperServerConfiguration; -import org.whispersystems.textsecuregcm.configuration.DynamoDbTables; -import org.whispersystems.textsecuregcm.push.ZeroTtlNotificationScheduler; -import org.whispersystems.textsecuregcm.scheduler.JobScheduler; - -public class ZeroTtlExperimentNotificationSchedulerFactory implements JobSchedulerFactory { - - @Override - public JobScheduler buildJobScheduler(final CommandDependencies commandDependencies, - final WhisperServerConfiguration configuration) { - final DynamoDbTables.TableWithExpiration tableConfiguration = configuration.getDynamoDbTables().getScheduledJobs(); - - final Clock clock = Clock.systemUTC(); - - return new ZeroTtlNotificationScheduler( - commandDependencies.accountsManager(), - commandDependencies.pushNotificationManager(), - commandDependencies.dynamoDbAsyncClient(), - tableConfiguration.getTableName(), - tableConfiguration.getExpiration(), - clock); - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlPushNotificationExperimentFactory.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlPushNotificationExperimentFactory.java deleted file mode 100644 index 1134203d0..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ZeroTtlPushNotificationExperimentFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2025 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.workers; - -import org.whispersystems.textsecuregcm.WhisperServerConfiguration; -import org.whispersystems.textsecuregcm.configuration.DynamoDbTables; -import org.whispersystems.textsecuregcm.experiment.DeviceLastSeenState; -import org.whispersystems.textsecuregcm.experiment.PushNotificationExperiment; -import org.whispersystems.textsecuregcm.experiment.ZeroTtlPushNotificationExperiment; -import org.whispersystems.textsecuregcm.push.ZeroTtlNotificationScheduler; -import java.time.Clock; - -public class ZeroTtlPushNotificationExperimentFactory implements PushNotificationExperimentFactory { - - @Override - public PushNotificationExperiment buildExperiment(final CommandDependencies commandDependencies, - final WhisperServerConfiguration configuration) { - - final DynamoDbTables.TableWithExpiration tableConfiguration = configuration.getDynamoDbTables().getScheduledJobs(); - - final Clock clock = Clock.systemUTC(); - - return new ZeroTtlPushNotificationExperiment( - new IdleWakeupEligibilityChecker(clock, commandDependencies.messagesManager()), - new ZeroTtlNotificationScheduler( - commandDependencies.accountsManager(), - commandDependencies.pushNotificationManager(), - commandDependencies.dynamoDbAsyncClient(), - tableConfiguration.getTableName(), - tableConfiguration.getExpiration(), - clock)); - } -} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/push/APNSenderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/push/APNSenderTest.java index 05c634875..250ff3285 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/push/APNSenderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/push/APNSenderTest.java @@ -69,8 +69,7 @@ class APNSenderTest { (Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response)); PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN, - PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, urgent, - Optional.empty()); + PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, urgent); final SendPushNotificationResult result = apnSender.sendNotification(pushNotification).join(); @@ -114,8 +113,7 @@ class APNSenderTest { (Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response)); PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN, - PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true, - Optional.empty()); + PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true); when(destinationDevice.getApnId()).thenReturn(DESTINATION_DEVICE_TOKEN); when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11)); @@ -146,8 +144,7 @@ class APNSenderTest { (Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response)); PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN, - PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true, - Optional.empty()); + PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true); final SendPushNotificationResult result = apnSender.sendNotification(pushNotification).join(); @@ -174,8 +171,7 @@ class APNSenderTest { new IOException("lost connection"))); PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN, - PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true, - Optional.empty()); + PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true); assertThatThrownBy(() -> apnSender.sendNotification(pushNotification).join()) .isInstanceOf(CompletionException.class) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/push/FcmSenderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/push/FcmSenderTest.java index 8244b7488..c6b5088c9 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/push/FcmSenderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/push/FcmSenderTest.java @@ -54,7 +54,7 @@ class FcmSenderTest { @Test void testSendMessage() { - final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true, Optional.empty()); + final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true); final SettableApiFuture sendFuture = SettableApiFuture.create(); sendFuture.set("message-id"); @@ -71,7 +71,7 @@ class FcmSenderTest { @Test void testSendMessageRejected() { - final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true, Optional.empty()); + final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true); final FirebaseMessagingException invalidArgumentException = mock(FirebaseMessagingException.class); when(invalidArgumentException.getMessagingErrorCode()).thenReturn(MessagingErrorCode.INVALID_ARGUMENT); @@ -91,7 +91,7 @@ class FcmSenderTest { @Test void testSendMessageUnregistered() { - final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true, Optional.empty()); + final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true); final FirebaseMessagingException unregisteredException = mock(FirebaseMessagingException.class); when(unregisteredException.getMessagingErrorCode()).thenReturn(MessagingErrorCode.UNREGISTERED); @@ -111,7 +111,7 @@ class FcmSenderTest { @Test void testSendMessageException() { - final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true, Optional.empty()); + final PushNotification pushNotification = new PushNotification("foo", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, null, null, true); final SettableApiFuture sendFuture = SettableApiFuture.create(); sendFuture.setException(new IOException()); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java index b955dd498..c1153d6e4 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java @@ -66,7 +66,7 @@ class PushNotificationManagerTest { .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))); pushNotificationManager.sendNewMessageNotification(account, Device.PRIMARY_ID, urgent); - verify(fcmSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent, Optional.empty())); + verify(fcmSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent)); } @Test @@ -78,7 +78,7 @@ class PushNotificationManagerTest { .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))); pushNotificationManager.sendRegistrationChallengeNotification(deviceToken, PushNotification.TokenType.APN, challengeToken); - verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true, Optional.empty())); + verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true)); } @Test @@ -97,7 +97,7 @@ class PushNotificationManagerTest { .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))); pushNotificationManager.sendRateLimitChallengeNotification(account, challengeToken); - verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, account, device, true, Optional.empty())); + verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, account, device, true)); } @ParameterizedTest @@ -124,10 +124,10 @@ class PushNotificationManagerTest { if (isApn){ verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, - PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY, "someContext", account, device, true, Optional.empty())); + PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY, "someContext", account, device, true)); } else { verify(fcmSender, times(1)).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.FCM, - PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY, "someContext", account, device, true, Optional.empty())); + PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY, "someContext", account, device, true)); } } @@ -141,7 +141,7 @@ class PushNotificationManagerTest { when(account.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(device)); final PushNotification pushNotification = new PushNotification( - "token", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent, Optional.empty()); + "token", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent); when(fcmSender.sendNotification(pushNotification)) .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))); @@ -165,7 +165,7 @@ class PushNotificationManagerTest { when(account.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(device)); final PushNotification pushNotification = new PushNotification( - "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent, Optional.empty()); + "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent); when(apnSender.sendNotification(pushNotification)) .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))); @@ -200,7 +200,7 @@ class PushNotificationManagerTest { when(accountsManager.getByAccountIdentifier(aci)).thenReturn(Optional.of(account)); final PushNotification pushNotification = new PushNotification( - "token", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, true, Optional.empty()); + "token", PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, true); when(fcmSender.sendNotification(pushNotification)) .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(false, Optional.empty(), true, Optional.empty()))); @@ -225,7 +225,7 @@ class PushNotificationManagerTest { when(accountsManager.getByAccountIdentifier(aci)).thenReturn(Optional.of(account)); final PushNotification pushNotification = new PushNotification( - "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true, Optional.empty()); + "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true); when(apnSender.sendNotification(pushNotification)) .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(false, Optional.empty(), true, Optional.empty()))); @@ -256,7 +256,7 @@ class PushNotificationManagerTest { when(accountsManager.getByAccountIdentifier(aci)).thenReturn(Optional.of(account)); final PushNotification pushNotification = new PushNotification( - "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true, Optional.empty()); + "token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true); when(apnSender.sendNotification(pushNotification)) .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(false, Optional.empty(), true, Optional.of(tokenTimestamp.minusSeconds(60)))));