Duo.java revision efe91971cbb687f72e4914530bd7abe96e8f6f8b
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 com.google.auto.value.AutoValue;
27import com.google.common.base.Optional;
28import java.util.List;
29
30/** Interface for Duo video call integration. */
31public interface Duo {
32
33  /** @return true if the Duo integration is enabled on this device. */
34  boolean isEnabled(@NonNull Context context);
35
36  /** @return true if Duo is installed on this device. */
37  boolean isInstalled(@NonNull Context context);
38
39  /**
40   * @return true if Duo is installed and the user has gone through the set-up flow confirming their
41   *     phone number.
42   */
43  boolean isActivated(@NonNull Context context);
44
45  /** @return true if the parameter number is reachable on Duo. */
46  @MainThread
47  boolean isReachable(@NonNull Context context, @Nullable String number);
48
49  /**
50   * @return true if the number supports upgrading a voice call to a Duo video call. Returns {@code
51   *     null} if result is unknown.
52   */
53  @MainThread
54  Optional<Boolean> supportsUpgrade(@NonNull Context context, @Nullable String number);
55
56  /** Starts a task to update the reachability of the parameter numbers asynchronously. */
57  @MainThread
58  void updateReachability(@NonNull Context context, @NonNull List<String> numbers);
59
60  /**
61   * Clears the current reachability data and starts a task to load the latest reachability data
62   * asynchronously.
63   */
64  @MainThread
65  void reloadReachability(@NonNull Context context);
66
67  /**
68   * @return an Intent to start a Duo video call with the parameter number. Must be started using
69   *     startActivityForResult.
70   */
71  @MainThread
72  Intent getIntent(@NonNull Context context, @NonNull String number);
73
74  /** Requests upgrading the parameter ongoing call to a Duo video call. */
75  @MainThread
76  void requestUpgrade(@NonNull Context context, Call call);
77
78  /** Registers a listener for reachability data changes. */
79  @MainThread
80  void registerListener(@NonNull DuoListener listener);
81
82  /** Unregisters a listener for reachability data changes. */
83  @MainThread
84  void unregisterListener(@NonNull DuoListener listener);
85
86  /** The string resource to use for outgoing Duo call entries in call details. */
87  @StringRes
88  @MainThread
89  int getOutgoingCallTypeText();
90
91  /** The string resource to use for incoming Duo call entries in call details. */
92  @StringRes
93  @MainThread
94  int getIncomingCallTypeText();
95
96  /** Reachability information for a number. */
97  @AutoValue
98  abstract class ReachabilityData {
99    public abstract String number();
100
101    public abstract boolean videoCallable();
102
103    public abstract boolean supportsUpgrade();
104
105    public static ReachabilityData create(
106        String number, boolean videoCallable, boolean supportsUpgrade) {
107      return new AutoValue_Duo_ReachabilityData(number, videoCallable, supportsUpgrade);
108    }
109  }
110}
111