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
17package com.android.dialer.duo;
18
19import android.content.Context;
20import android.content.Intent;
21import android.support.annotation.MainThread;
22import android.support.annotation.NonNull;
23import android.support.annotation.Nullable;
24import android.support.annotation.StringRes;
25import android.telecom.Call;
26import android.telecom.PhoneAccountHandle;
27import com.google.auto.value.AutoValue;
28import com.google.common.base.Optional;
29import java.util.List;
30
31/** Interface for Duo video call integration. */
32public interface Duo {
33
34  /** @return true if the Duo integration is enabled on this device. */
35  boolean isEnabled(@NonNull Context context);
36
37  /** @return true if Duo is installed on this device. */
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   */
44  boolean isActivated(@NonNull Context context);
45
46  /** @return true if the parameter number is reachable on Duo. */
47  @MainThread
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
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
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
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
76  Intent getIntent(@NonNull Context context, @NonNull String number);
77
78  /** Requests upgrading the parameter ongoing call to a Duo video call. */
79  @MainThread
80  void requestUpgrade(@NonNull Context context, Call call);
81
82  /** Registers a listener for reachability data changes. */
83  @MainThread
84  void registerListener(@NonNull DuoListener listener);
85
86  /** Unregisters a listener for reachability data changes. */
87  @MainThread
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
93  int getOutgoingCallTypeText();
94
95  /** The string resource to use for incoming Duo call entries in call details. */
96  @StringRes
97  @MainThread
98  int getIncomingCallTypeText();
99
100  /** Reachability information for a number. */
101  @AutoValue
102  abstract class ReachabilityData {
103    public abstract String number();
104
105    public abstract boolean videoCallable();
106
107    public abstract boolean supportsUpgrade();
108
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