diff options
3 files changed, 48 insertions, 7 deletions
diff --git a/java/com/android/dialer/lightbringer/Lightbringer.java b/java/com/android/dialer/lightbringer/Lightbringer.java index fa57b0166..2318ef5fd 100644 --- a/java/com/android/dialer/lightbringer/Lightbringer.java +++ b/java/com/android/dialer/lightbringer/Lightbringer.java @@ -25,6 +25,9 @@ import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.telecom.Call; import android.telecom.PhoneAccountHandle; +import com.google.auto.value.AutoValue; +import com.google.common.base.Optional; +import java.util.List; public interface Lightbringer { @@ -33,8 +36,12 @@ public interface Lightbringer { @MainThread boolean isReachable(@NonNull Context context, @Nullable String number); + /** @return {@code null} if result is unknown. */ @MainThread - boolean supportsUpgrade(@NonNull Context context, @Nullable String number); + Optional<Boolean> supportsUpgrade(@NonNull Context context, @Nullable String number); + + @MainThread + void updateReachability(@NonNull Context context, @NonNull List<String> numbers); @MainThread Intent getIntent(@NonNull Context context, @NonNull String number); @@ -67,4 +74,19 @@ public interface Lightbringer { @StringRes @MainThread int getIncomingCallTypeText(); + + /** Reachability information for a number. */ + @AutoValue + abstract class ReachabilityData { + public abstract String number(); + + public abstract boolean videoCallable(); + + public abstract boolean supportsUpgrade(); + + public static ReachabilityData create( + String number, boolean videoCallable, boolean supportsUpgrade) { + return new AutoValue_Lightbringer_ReachabilityData(number, videoCallable, supportsUpgrade); + } + } } diff --git a/java/com/android/dialer/lightbringer/stub/LightbringerStub.java b/java/com/android/dialer/lightbringer/stub/LightbringerStub.java index a0309220a..e66739113 100644 --- a/java/com/android/dialer/lightbringer/stub/LightbringerStub.java +++ b/java/com/android/dialer/lightbringer/stub/LightbringerStub.java @@ -28,6 +28,8 @@ import android.telecom.PhoneAccountHandle; import com.android.dialer.common.Assert; import com.android.dialer.lightbringer.Lightbringer; import com.android.dialer.lightbringer.LightbringerListener; +import com.google.common.base.Optional; +import java.util.List; import javax.inject.Inject; public class LightbringerStub implements Lightbringer { @@ -50,10 +52,17 @@ public class LightbringerStub implements Lightbringer { @MainThread @Override - public boolean supportsUpgrade(@NonNull Context context, @Nullable String number) { + public Optional<Boolean> supportsUpgrade(@NonNull Context context, @Nullable String number) { Assert.isMainThread(); Assert.isNotNull(context); - return false; + return Optional.of(false); + } + + @Override + public void updateReachability(@NonNull Context context, @NonNull List<String> numbers) { + Assert.isMainThread(); + Assert.isNotNull(context); + Assert.isNotNull(numbers); } @MainThread diff --git a/java/com/android/incallui/videotech/lightbringer/LightbringerTech.java b/java/com/android/incallui/videotech/lightbringer/LightbringerTech.java index a807759db..4b6f5ec5a 100644 --- a/java/com/android/incallui/videotech/lightbringer/LightbringerTech.java +++ b/java/com/android/incallui/videotech/lightbringer/LightbringerTech.java @@ -31,6 +31,8 @@ import com.android.incallui.video.protocol.VideoCallScreen; import com.android.incallui.video.protocol.VideoCallScreenDelegate; import com.android.incallui.videotech.VideoTech; import com.android.incallui.videotech.utils.SessionModificationState; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; public class LightbringerTech implements VideoTech, LightbringerListener { private final Lightbringer lightbringer; @@ -38,6 +40,7 @@ public class LightbringerTech implements VideoTech, LightbringerListener { private final Call call; private final String callingNumber; private int callState = Call.STATE_NEW; + private boolean isRemoteUpgradeAvailabilityQueried; public LightbringerTech( @NonNull Lightbringer lightbringer, @@ -69,13 +72,20 @@ public class LightbringerTech implements VideoTech, LightbringerListener { LogUtil.v("LightbringerTech.isAvailable", "upgrade unavailable, call must be active"); return false; } + Optional<Boolean> localResult = lightbringer.supportsUpgrade(context, callingNumber); + if (localResult.isPresent()) { + LogUtil.v( + "LightbringerTech.isAvailable", "upgrade supported in local cache: " + localResult.get()); + return localResult.get(); + } - if (!lightbringer.supportsUpgrade(context, callingNumber)) { - LogUtil.v("LightbringerTech.isAvailable", "upgrade unavailable, number does not support it"); - return false; + if (!isRemoteUpgradeAvailabilityQueried) { + LogUtil.v("LightbringerTech.isAvailable", "reachability unknown, starting remote query"); + isRemoteUpgradeAvailabilityQueried = true; + lightbringer.updateReachability(context, ImmutableList.of(callingNumber)); } - return true; + return false; } @Override |