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.DrawableRes;
22 import android.support.annotation.MainThread;
23 import android.support.annotation.NonNull;
24 import android.support.annotation.Nullable;
25 import android.support.annotation.StringRes;
26 import android.telecom.Call;
27 import android.telecom.PhoneAccountHandle;
28 import com.google.auto.value.AutoValue;
29 import com.google.common.base.Optional;
30 import com.google.common.collect.ImmutableMap;
31 import com.google.common.util.concurrent.ListenableFuture;
32 import java.util.List;
33 
34 /** Interface for Duo video call integration. */
35 @SuppressWarnings("Guava")
36 public interface Duo {
37 
38   /** @return true if the Duo integration is enabled on this device. */
isEnabled(@onNull Context context)39   boolean isEnabled(@NonNull Context context);
40 
41   /** @return true if Duo is installed on this device. */
isInstalled(@onNull Context context)42   boolean isInstalled(@NonNull Context context);
43 
44   /**
45    * @return true if Duo is installed and the user has gone through the set-up flow confirming their
46    *     phone number.
47    */
isActivated(@onNull Context context)48   boolean isActivated(@NonNull Context context);
49 
50   /** @return true if the parameter number is reachable on Duo. */
51   @MainThread
isReachable(@onNull Context context, @Nullable String number)52   boolean isReachable(@NonNull Context context, @Nullable String number);
53 
54   /**
55    * @return true if the number supports upgrading a voice call to a Duo video call. Returns {@code
56    *     null} if result is unknown.
57    */
58   @MainThread
supportsUpgrade( @onNull Context context, @Nullable String number, @Nullable PhoneAccountHandle phoneAccountHandle)59   Optional<Boolean> supportsUpgrade(
60       @NonNull Context context,
61       @Nullable String number,
62       @Nullable PhoneAccountHandle phoneAccountHandle);
63 
64   /** Starts a task to update the reachability of the parameter numbers asynchronously. */
65   @MainThread
updateReachability( @onNull Context context, @NonNull List<String> numbers)66   ListenableFuture<ImmutableMap<String, ReachabilityData>> updateReachability(
67       @NonNull Context context, @NonNull List<String> numbers);
68 
69   /**
70    * Clears the current reachability data and starts a task to load the latest reachability data
71    * asynchronously.
72    */
73   @MainThread
reloadReachability(@onNull Context context)74   void reloadReachability(@NonNull Context context);
75 
76   /**
77    * Get the {@link PhoneAccountHandle} used by duo calls in the connection service and call log.
78    */
getPhoneAccountHandle()79   Optional<PhoneAccountHandle> getPhoneAccountHandle();
80 
isDuoAccount(PhoneAccountHandle phoneAccountHandle)81   boolean isDuoAccount(PhoneAccountHandle phoneAccountHandle);
82 
isDuoAccount(String componentName)83   boolean isDuoAccount(String componentName);
84 
85   /**
86    * @return an Intent to start a Duo video call with the parameter number. Must be started using
87    *     startActivityForResult.
88    */
89   @MainThread
getCallIntent(@onNull String number)90   Optional<Intent> getCallIntent(@NonNull String number);
91 
92   /** @return an Intent to setup duo. Must be started using startActivityForResult. */
getActivateIntent()93   Optional<Intent> getActivateIntent();
94 
95   /**
96    * @return an Intent to invite the parameter number to use duo. Must be started using
97    *     startActivityForResult.
98    */
getInviteIntent(String number)99   Optional<Intent> getInviteIntent(String number);
100 
getInstallDuoIntent()101   Optional<Intent> getInstallDuoIntent();
102 
103   /** Requests upgrading the parameter ongoing call to a Duo video call. */
104   @MainThread
requestUpgrade(@onNull Context context, Call call)105   void requestUpgrade(@NonNull Context context, Call call);
106 
107   /** Registers a listener for reachability data changes. */
108   @MainThread
registerListener(@onNull DuoListener listener)109   void registerListener(@NonNull DuoListener listener);
110 
111   /** Unregisters a listener for reachability data changes. */
112   @MainThread
unregisterListener(@onNull DuoListener listener)113   void unregisterListener(@NonNull DuoListener listener);
114 
115   /** The string resource to use for outgoing Duo call entries in call details. */
116   @StringRes
117   @MainThread
getOutgoingCallTypeText()118   int getOutgoingCallTypeText();
119 
120   /** The string resource to use for incoming Duo call entries in call details. */
121   @StringRes
122   @MainThread
getIncomingCallTypeText()123   int getIncomingCallTypeText();
124 
125   /** The ID of the drawable resource of a Duo logo. */
126   @DrawableRes
127   @MainThread
getLogo()128   int getLogo();
129 
130   /** Reachability information for a number. */
131   @AutoValue
132   abstract class ReachabilityData {
133     public enum Status {
134       UNKNOWN,
135 
136       /**
137        * The number is callable. Apps should further look up “AUDIO_CALLABLE” and “VIDEO_CALLABLE”
138        * keys for supported modes.
139        */
140       CALL,
141 
142       /** The number is not callable. Apps can send an invite to the contact via INVITE intent. */
143       INVITE,
144 
145       /**
146        * Neither Tachystick nor Duo is registered. Apps should show “setup” icon and send REGISTER
147        * intent to.
148        */
149       SETUP,
150 
151       /**
152        * Indicates that the number is callable but user needs to set up (Tachystick/Duo) before
153        * calling.
154        */
155       SETUP_AND_CALL
156     }
157 
status()158     public abstract Status status();
159 
number()160     public abstract String number();
161 
audioCallable()162     public abstract boolean audioCallable();
163 
videoCallable()164     public abstract boolean videoCallable();
165 
supportsUpgrade()166     public abstract boolean supportsUpgrade();
167 
create( Status status, String number, boolean audioCallable, boolean videoCallable, boolean supportsUpgrade)168     public static ReachabilityData create(
169         Status status,
170         String number,
171         boolean audioCallable,
172         boolean videoCallable,
173         boolean supportsUpgrade) {
174       return new AutoValue_Duo_ReachabilityData(
175           status, number, audioCallable, videoCallable, supportsUpgrade);
176     }
177   }
178 }
179