mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Add NotInCallConstraint, restrict auto-download of media and documents when on an active voice or video call.
This commit is contained in:
committed by
Greyson Parrelli
parent
ef95479157
commit
8724d904b7
@@ -0,0 +1,43 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.impl;
|
||||
|
||||
import android.app.job.JobInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.thoughtcrime.securesms.events.WebRtcViewModel;
|
||||
import org.thoughtcrime.securesms.jobmanager.Constraint;
|
||||
|
||||
/**
|
||||
* Constraint met when the user is not in an active, connected call.
|
||||
*/
|
||||
public final class NotInCallConstraint implements Constraint {
|
||||
|
||||
public static final String KEY = "NotInCallConstraint";
|
||||
|
||||
@Override
|
||||
public boolean isMet() {
|
||||
return isNotInConnectedCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
public static boolean isNotInConnectedCall() {
|
||||
WebRtcViewModel viewModel = EventBus.getDefault().getStickyEvent(WebRtcViewModel.class);
|
||||
return viewModel == null || viewModel.getState() != WebRtcViewModel.State.CALL_CONNECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToJobInfo(@NonNull JobInfo.Builder jobInfoBuilder) {
|
||||
}
|
||||
|
||||
public static class Factory implements Constraint.Factory<NotInCallConstraint> {
|
||||
@Override
|
||||
public NotInCallConstraint create() {
|
||||
return new NotInCallConstraint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.thoughtcrime.securesms.events.WebRtcViewModel;
|
||||
import org.thoughtcrime.securesms.jobmanager.ConstraintObserver;
|
||||
|
||||
public final class NotInCallConstraintObserver implements ConstraintObserver {
|
||||
|
||||
private static final String REASON = NotInCallConstraintObserver.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void register(@NonNull Notifier notifier) {
|
||||
EventBus.getDefault().register(new EventBusListener(notifier));
|
||||
}
|
||||
|
||||
private static final class EventBusListener {
|
||||
|
||||
private final Notifier notifier;
|
||||
|
||||
private EventBusListener(@NonNull Notifier notifier) {
|
||||
this.notifier = notifier;
|
||||
}
|
||||
|
||||
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
|
||||
public void consume(@NonNull WebRtcViewModel viewModel) {
|
||||
NotInCallConstraint constraint = new NotInCallConstraint.Factory().create();
|
||||
|
||||
if (constraint.isMet()) {
|
||||
notifier.onConstraintMet(REASON);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user