Dynamically respond to notificationsV2 feature flag.

We were only reading it once, possibly before the flags were
initialized. This lets us be more responsive to the flag changing within
an application cycle.
fork-5.53.8
Greyson Parrelli 2021-04-14 18:49:31 -04:00
rodzic 2547db2a8e
commit cdddfd37d2
3 zmienionych plików z 31 dodań i 25 usunięć

Wyświetl plik

@ -142,6 +142,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
} }
}) })
.addBlocking("blob-provider", this::initializeBlobProvider) .addBlocking("blob-provider", this::initializeBlobProvider)
.addBlocking("feature-flags", FeatureFlags::init)
.addNonBlocking(this::initializeRevealableMessageManager) .addNonBlocking(this::initializeRevealableMessageManager)
.addNonBlocking(this::initializeGcmCheck) .addNonBlocking(this::initializeGcmCheck)
.addNonBlocking(this::initializeSignedPreKeyCheck) .addNonBlocking(this::initializeSignedPreKeyCheck)
@ -150,7 +151,6 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
.addNonBlocking(this::initializePendingMessages) .addNonBlocking(this::initializePendingMessages)
.addNonBlocking(this::initializeCleanup) .addNonBlocking(this::initializeCleanup)
.addNonBlocking(this::initializeGlideCodecs) .addNonBlocking(this::initializeGlideCodecs)
.addNonBlocking(FeatureFlags::init)
.addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary) .addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary)
.addNonBlocking(StorageSyncHelper::scheduleRoutineSync) .addNonBlocking(StorageSyncHelper::scheduleRoutineSync)
.addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop()) .addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop())

Wyświetl plik

@ -186,14 +186,7 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
@Override @Override
public @NonNull MessageNotifier provideMessageNotifier() { public @NonNull MessageNotifier provideMessageNotifier() {
MessageNotifier inner; return new OptimizedMessageNotifier();
if (FeatureFlags.useNewNotificationSystem()) {
inner = new MessageNotifierV2();
} else {
inner = new DefaultMessageNotifier();
}
return new OptimizedMessageNotifier(inner);
} }
@Override @Override

Wyświetl plik

@ -7,8 +7,10 @@ import androidx.annotation.MainThread;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.signal.core.util.concurrent.SignalExecutors; import org.signal.core.util.concurrent.SignalExecutors;
import org.thoughtcrime.securesms.notifications.v2.MessageNotifierV2;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.BubbleUtil; import org.thoughtcrime.securesms.util.BubbleUtil;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.LeakyBucketLimiter; import org.thoughtcrime.securesms.util.LeakyBucketLimiter;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
@ -17,73 +19,76 @@ import org.thoughtcrime.securesms.util.Util;
*/ */
public class OptimizedMessageNotifier implements MessageNotifier { public class OptimizedMessageNotifier implements MessageNotifier {
private final MessageNotifier wrapped;
private final LeakyBucketLimiter limiter; private final LeakyBucketLimiter limiter;
private final DefaultMessageNotifier messageNotifierV1;
private final MessageNotifierV2 messageNotifierV2;
@MainThread @MainThread
public OptimizedMessageNotifier(@NonNull MessageNotifier wrapped) { public OptimizedMessageNotifier() {
this.wrapped = wrapped;
this.limiter = new LeakyBucketLimiter(5, 1000, new Handler(SignalExecutors.getAndStartHandlerThread("signal-notifier").getLooper())); this.limiter = new LeakyBucketLimiter(5, 1000, new Handler(SignalExecutors.getAndStartHandlerThread("signal-notifier").getLooper()));
this.messageNotifierV1 = new DefaultMessageNotifier();
this.messageNotifierV2 = new MessageNotifierV2();
} }
@Override @Override
public void setVisibleThread(long threadId) { public void setVisibleThread(long threadId) {
wrapped.setVisibleThread(threadId); getNotifier().setVisibleThread(threadId);
} }
@Override @Override
public long getVisibleThread() { public long getVisibleThread() {
return wrapped.getVisibleThread(); return getNotifier().getVisibleThread();
} }
@Override @Override
public void clearVisibleThread() { public void clearVisibleThread() {
wrapped.clearVisibleThread(); getNotifier().clearVisibleThread();
} }
@Override @Override
public void setLastDesktopActivityTimestamp(long timestamp) { public void setLastDesktopActivityTimestamp(long timestamp) {
wrapped.setLastDesktopActivityTimestamp(timestamp); getNotifier().setLastDesktopActivityTimestamp(timestamp);
} }
@Override @Override
public void notifyMessageDeliveryFailed(Context context, Recipient recipient, long threadId) { public void notifyMessageDeliveryFailed(Context context, Recipient recipient, long threadId) {
wrapped.notifyMessageDeliveryFailed(context, recipient, threadId); getNotifier().notifyMessageDeliveryFailed(context, recipient, threadId);
} }
@Override @Override
public void cancelDelayedNotifications() { public void cancelDelayedNotifications() {
wrapped.cancelDelayedNotifications(); getNotifier().cancelDelayedNotifications();
} }
@Override @Override
public void updateNotification(@NonNull Context context) { public void updateNotification(@NonNull Context context) {
runOnLimiter(() -> wrapped.updateNotification(context)); runOnLimiter(() -> getNotifier().updateNotification(context));
} }
@Override @Override
public void updateNotification(@NonNull Context context, long threadId) { public void updateNotification(@NonNull Context context, long threadId) {
runOnLimiter(() -> wrapped.updateNotification(context, threadId)); runOnLimiter(() -> getNotifier().updateNotification(context, threadId));
} }
@Override @Override
public void updateNotification(@NonNull Context context, long threadId, @NonNull BubbleUtil.BubbleState defaultBubbleState) { public void updateNotification(@NonNull Context context, long threadId, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
runOnLimiter(() -> wrapped.updateNotification(context, threadId, defaultBubbleState)); runOnLimiter(() -> getNotifier().updateNotification(context, threadId, defaultBubbleState));
} }
@Override @Override
public void updateNotification(@NonNull Context context, long threadId, boolean signal) { public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
runOnLimiter(() -> wrapped.updateNotification(context, threadId, signal)); runOnLimiter(() -> getNotifier().updateNotification(context, threadId, signal));
} }
@Override @Override
public void updateNotification(@NonNull Context context, long threadId, boolean signal, int reminderCount, @NonNull BubbleUtil.BubbleState defaultBubbleState) { public void updateNotification(@NonNull Context context, long threadId, boolean signal, int reminderCount, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
runOnLimiter(() -> wrapped.updateNotification(context, threadId, signal, reminderCount, defaultBubbleState)); runOnLimiter(() -> getNotifier().updateNotification(context, threadId, signal, reminderCount, defaultBubbleState));
} }
@Override @Override
public void clearReminder(@NonNull Context context) { public void clearReminder(@NonNull Context context) {
wrapped.clearReminder(context); getNotifier().clearReminder(context);
} }
private void runOnLimiter(@NonNull Runnable runnable) { private void runOnLimiter(@NonNull Runnable runnable) {
@ -96,4 +101,12 @@ public class OptimizedMessageNotifier implements MessageNotifier {
} }
}); });
} }
private MessageNotifier getNotifier() {
if (FeatureFlags.useNewNotificationSystem()) {
return messageNotifierV2;
} else {
return messageNotifierV1;
}
}
} }