From 34b1662b7532343341bbee22227e8ed82575864f Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 1 May 2018 14:53:14 -0700 Subject: Replace DuoConstants with interface. They are not constant across different Duo implementations. TEST=TAP Bug: 76430187,78783816 Test: TAP PiperOrigin-RevId: 195001650 Change-Id: I4356d04c9eeac50fefd41e1142f3123591e93bc0 --- java/com/android/dialer/duo/Duo.java | 36 ++++++++++++++++- java/com/android/dialer/duo/DuoConstants.java | 45 ---------------------- .../android/dialer/duo/PlaceDuoCallReceiver.java | 2 +- java/com/android/dialer/duo/stub/DuoStub.java | 38 +++++++++++++++++- 4 files changed, 72 insertions(+), 49 deletions(-) delete mode 100644 java/com/android/dialer/duo/DuoConstants.java (limited to 'java/com/android/dialer/duo') diff --git a/java/com/android/dialer/duo/Duo.java b/java/com/android/dialer/duo/Duo.java index e020c80e6..06a3db063 100644 --- a/java/com/android/dialer/duo/Duo.java +++ b/java/com/android/dialer/duo/Duo.java @@ -30,6 +30,7 @@ import com.google.common.base.Optional; import java.util.List; /** Interface for Duo video call integration. */ +@SuppressWarnings("Guava") public interface Duo { /** @return true if the Duo integration is enabled on this device. */ @@ -69,12 +70,45 @@ public interface Duo { @MainThread void reloadReachability(@NonNull Context context); + /** + * Get the {@link PhoneAccountHandle} used by duo calls in the connection service and call log. + */ + Optional getPhoneAccountHandle(); + + boolean isDuoAccount(PhoneAccountHandle phoneAccountHandle); + + boolean isDuoAccount(String componentName); + /** * @return an Intent to start a Duo video call with the parameter number. Must be started using * startActivityForResult. */ @MainThread - Intent getIntent(@NonNull Context context, @NonNull String number); + Optional getCallIntent(@NonNull String number); + + /** @return an Intent to setup duo. Must be started using startActivityForResult. */ + Optional getActivateIntent(); + + /** + * @return an Intent to invite the parameter number to use duo. Must be started using + * startActivityForResult. + */ + Optional getInviteIntent(String number); + + /** Return value of {@link #getIntentType(Intent)} */ + enum IntentType { + /** The intent is returned by {@link #getCallIntent(String)} */ + CALL, + /** The intent is returned by {@link #getActivateIntent()} */ + ACTIVATE, + /** The intent is returned by {@link #getInviteIntent(String)} */ + INVITE + } + + /** Classifies a Duo intent. Absent if the intent is not a Duo intent. */ + Optional getIntentType(Intent intent); + + Optional getInstallDuoIntent(); /** Requests upgrading the parameter ongoing call to a Duo video call. */ @MainThread diff --git a/java/com/android/dialer/duo/DuoConstants.java b/java/com/android/dialer/duo/DuoConstants.java deleted file mode 100644 index 6eb660de0..000000000 --- a/java/com/android/dialer/duo/DuoConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.duo; - -import android.content.ComponentName; -import android.telecom.PhoneAccountHandle; - -/** Constants to reference the Duo application. */ -public final class DuoConstants { - public static final String PACKAGE_NAME = "com.google.android.apps.tachyon"; - - public static final String CONNECTION_SERVICE = - "com.google.android.apps.tachyon.telecom.TachyonTelecomConnectionService"; - - public static final String PHONE_ACCOUNT_ID = "0"; - - public static final ComponentName PHONE_ACCOUNT_COMPONENT_NAME = - new ComponentName(PACKAGE_NAME, CONNECTION_SERVICE); - - public static final PhoneAccountHandle PHONE_ACCOUNT_HANDLE = - new PhoneAccountHandle(PHONE_ACCOUNT_COMPONENT_NAME, PHONE_ACCOUNT_ID); - - public static final String DUO_ACTIVATE_ACTION = - "com.google.android.apps.tachyon.action.REGISTER"; - - public static final String DUO_INVITE_ACTION = "com.google.android.apps.tachyon.action.INVITE"; - - public static final String DUO_CALL_ACTION = "com.google.android.apps.tachyon.action.CALL"; - - private DuoConstants() {} -} diff --git a/java/com/android/dialer/duo/PlaceDuoCallReceiver.java b/java/com/android/dialer/duo/PlaceDuoCallReceiver.java index 913132c88..f504aef57 100644 --- a/java/com/android/dialer/duo/PlaceDuoCallReceiver.java +++ b/java/com/android/dialer/duo/PlaceDuoCallReceiver.java @@ -72,6 +72,6 @@ public final class PlaceDuoCallReceiver extends BroadcastReceiver { Duo duo = DuoComponent.get(context).getDuo(); activity.startActivityForResult( - duo.getIntent(context, phoneNumber), ActivityRequestCodes.DIALTACTS_DUO); + duo.getCallIntent(phoneNumber).orNull(), ActivityRequestCodes.DIALTACTS_DUO); } } diff --git a/java/com/android/dialer/duo/stub/DuoStub.java b/java/com/android/dialer/duo/stub/DuoStub.java index ef78f8b90..b0867148f 100644 --- a/java/com/android/dialer/duo/stub/DuoStub.java +++ b/java/com/android/dialer/duo/stub/DuoStub.java @@ -81,12 +81,46 @@ public class DuoStub implements Duo { @Override public void reloadReachability(@NonNull Context context) {} + @Override + public Optional getPhoneAccountHandle() { + return Optional.absent(); + } + + @Override + public boolean isDuoAccount(PhoneAccountHandle phoneAccountHandle) { + return false; + } + + @Override + public boolean isDuoAccount(String componentName) { + return false; + } + @MainThread @Override - public Intent getIntent(@NonNull Context context, @NonNull String number) { + public Optional getCallIntent(@NonNull String number) { Assert.isMainThread(); - Assert.isNotNull(context); Assert.isNotNull(number); + return Optional.absent(); + } + + @Override + public Optional getActivateIntent() { + return Optional.absent(); + } + + @Override + public Optional getInviteIntent(String number) { + return Optional.absent(); + } + + @Override + public Optional getIntentType(Intent intent) { + return Optional.absent(); + } + + @Override + public Optional getInstallDuoIntent() { return null; } -- cgit v1.2.3