1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.duo; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.support.annotation.MainThread; 22 import android.support.annotation.NonNull; 23 import android.support.annotation.Nullable; 24 import android.support.annotation.StringRes; 25 import android.telecom.Call; 26 import android.telecom.PhoneAccountHandle; 27 import com.google.auto.value.AutoValue; 28 import com.google.common.base.Optional; 29 import java.util.List; 30 31 /** Interface for Duo video call integration. */ 32 public interface Duo { 33 34 /** @return true if the Duo integration is enabled on this device. */ isEnabled(@onNull Context context)35 boolean isEnabled(@NonNull Context context); 36 37 /** @return true if Duo is installed on this device. */ isInstalled(@onNull Context context)38 boolean isInstalled(@NonNull Context context); 39 40 /** 41 * @return true if Duo is installed and the user has gone through the set-up flow confirming their 42 * phone number. 43 */ isActivated(@onNull Context context)44 boolean isActivated(@NonNull Context context); 45 46 /** @return true if the parameter number is reachable on Duo. */ 47 @MainThread isReachable(@onNull Context context, @Nullable String number)48 boolean isReachable(@NonNull Context context, @Nullable String number); 49 50 /** 51 * @return true if the number supports upgrading a voice call to a Duo video call. Returns {@code 52 * null} if result is unknown. 53 */ 54 @MainThread supportsUpgrade( @onNull Context context, @Nullable String number, @Nullable PhoneAccountHandle phoneAccountHandle)55 Optional<Boolean> supportsUpgrade( 56 @NonNull Context context, 57 @Nullable String number, 58 @Nullable PhoneAccountHandle phoneAccountHandle); 59 60 /** Starts a task to update the reachability of the parameter numbers asynchronously. */ 61 @MainThread updateReachability(@onNull Context context, @NonNull List<String> numbers)62 void updateReachability(@NonNull Context context, @NonNull List<String> numbers); 63 64 /** 65 * Clears the current reachability data and starts a task to load the latest reachability data 66 * asynchronously. 67 */ 68 @MainThread reloadReachability(@onNull Context context)69 void reloadReachability(@NonNull Context context); 70 71 /** 72 * @return an Intent to start a Duo video call with the parameter number. Must be started using 73 * startActivityForResult. 74 */ 75 @MainThread getIntent(@onNull Context context, @NonNull String number)76 Intent getIntent(@NonNull Context context, @NonNull String number); 77 78 /** Requests upgrading the parameter ongoing call to a Duo video call. */ 79 @MainThread requestUpgrade(@onNull Context context, Call call)80 void requestUpgrade(@NonNull Context context, Call call); 81 82 /** Registers a listener for reachability data changes. */ 83 @MainThread registerListener(@onNull DuoListener listener)84 void registerListener(@NonNull DuoListener listener); 85 86 /** Unregisters a listener for reachability data changes. */ 87 @MainThread unregisterListener(@onNull DuoListener listener)88 void unregisterListener(@NonNull DuoListener listener); 89 90 /** The string resource to use for outgoing Duo call entries in call details. */ 91 @StringRes 92 @MainThread getOutgoingCallTypeText()93 int getOutgoingCallTypeText(); 94 95 /** The string resource to use for incoming Duo call entries in call details. */ 96 @StringRes 97 @MainThread getIncomingCallTypeText()98 int getIncomingCallTypeText(); 99 100 /** Reachability information for a number. */ 101 @AutoValue 102 abstract class ReachabilityData { number()103 public abstract String number(); 104 videoCallable()105 public abstract boolean videoCallable(); 106 supportsUpgrade()107 public abstract boolean supportsUpgrade(); 108 create( String number, boolean videoCallable, boolean supportsUpgrade)109 public static ReachabilityData create( 110 String number, boolean videoCallable, boolean supportsUpgrade) { 111 return new AutoValue_Duo_ReachabilityData(number, videoCallable, supportsUpgrade); 112 } 113 } 114 } 115