From 19c6c256bbb6f6a2d1c5772b6cd85f2a07d50a1c Mon Sep 17 00:00:00 2001 From: roldenburg Date: Wed, 13 Dec 2017 15:58:01 -0800 Subject: Add reloadReachabilities to Duo interface Bug: 70034799 Test: DuoImplTest, GoogleDialtactsActivityTest PiperOrigin-RevId: 178971440 Change-Id: Ib624bd340fbeac11474db198763ae77eddb03ae3 --- java/com/android/dialer/app/DialtactsActivity.java | 5 +++++ .../dialer/database/DialerDatabaseHelper.java | 15 ++++++++++---- java/com/android/dialer/duo/Duo.java | 24 +++++++++++++++++++++- java/com/android/dialer/duo/stub/DuoStub.java | 3 +++ 4 files changed, 42 insertions(+), 5 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index 48796dba3..cc3f81b3c 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -109,6 +109,7 @@ import com.android.dialer.database.DialerDatabaseHelper; import com.android.dialer.dialpadview.DialpadFragment; import com.android.dialer.dialpadview.DialpadFragment.DialpadListener; import com.android.dialer.dialpadview.DialpadFragment.LastOutgoingCallCallback; +import com.android.dialer.duo.DuoComponent; import com.android.dialer.interactions.PhoneNumberInteraction; import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorCode; import com.android.dialer.logging.DialerImpression; @@ -836,6 +837,10 @@ public class DialtactsActivity extends TransactionSafeActivity .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } + } else if (requestCode == ActivityRequestCodes.DIALTACTS_DUO) { + // We just returned from starting Duo for a task. Reload our reachability data since it + // may have changed after a user finished activating Duo. + DuoComponent.get(this).getDuo().reloadReachability(this); } super.onActivityResult(requestCode, resultCode, data); } diff --git a/java/com/android/dialer/database/DialerDatabaseHelper.java b/java/com/android/dialer/database/DialerDatabaseHelper.java index 9a2581221..113e86314 100644 --- a/java/com/android/dialer/database/DialerDatabaseHelper.java +++ b/java/com/android/dialer/database/DialerDatabaseHelper.java @@ -26,19 +26,21 @@ import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.net.Uri; -import android.os.AsyncTask; import android.provider.BaseColumns; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.Directory; +import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; import android.text.TextUtils; import com.android.contacts.common.R; import com.android.contacts.common.util.StopWatch; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import com.android.dialer.common.concurrent.DialerExecutorComponent; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.smartdial.SmartDialNameMatcher; import com.android.dialer.smartdial.SmartDialPrefix; @@ -332,7 +334,11 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { /** Starts the database upgrade process in the background. */ public void startSmartDialUpdateThread() { if (PermissionsUtil.hasContactsReadPermissions(mContext)) { - new SmartDialUpdateAsyncTask().execute(); + DialerExecutorComponent.get(mContext) + .dialerExecutorFactory() + .createNonUiTaskBuilder(new UpdateSmartDialWorker()) + .build() + .executeParallel(null); } } @@ -1228,10 +1234,11 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { } } - private class SmartDialUpdateAsyncTask extends AsyncTask { + private class UpdateSmartDialWorker implements Worker { + @Nullable @Override - protected Object doInBackground(Object... objects) { + public Void doInBackground(@Nullable Void input) throws Throwable { updateSmartDialDatabase(); return null; } diff --git a/java/com/android/dialer/duo/Duo.java b/java/com/android/dialer/duo/Duo.java index 9012dee4f..5f49e3e7e 100644 --- a/java/com/android/dialer/duo/Duo.java +++ b/java/com/android/dialer/duo/Duo.java @@ -30,6 +30,7 @@ import java.util.List; /** Interface for Duo video call integration. */ public interface Duo { + /** @return true if the Duo integration is enabled on this device. */ boolean isEnabled(@NonNull Context context); /** @@ -38,32 +39,53 @@ public interface Duo { */ boolean isActivated(@NonNull Context context); + /** @return true if the parameter number is reachable on Duo. */ @MainThread boolean isReachable(@NonNull Context context, @Nullable String number); - /** @return {@code null} if result is unknown. */ + /** + * @return true if the number supports upgrading a voice call to a Duo video call. Returns {@code + * null} if result is unknown. + */ @MainThread Optional supportsUpgrade(@NonNull Context context, @Nullable String number); + /** Starts a task to update the reachability of the parameter numbers asynchronously. */ @MainThread void updateReachability(@NonNull Context context, @NonNull List numbers); + /** + * Clears the current reachability data and starts a task to load the latest reachability data + * asynchronously. + */ + @MainThread + void reloadReachability(@NonNull Context context); + + /** + * @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); + /** Requests upgrading the parameter ongoing call to a Duo video call. */ @MainThread void requestUpgrade(@NonNull Context context, Call call); + /** Registers a listener for reachability data changes. */ @MainThread void registerListener(@NonNull DuoListener listener); + /** Unregisters a listener for reachability data changes. */ @MainThread void unregisterListener(@NonNull DuoListener listener); + /** The string resource to use for outgoing Duo call entries in call details. */ @StringRes @MainThread int getOutgoingCallTypeText(); + /** The string resource to use for incoming Duo call entries in call details. */ @StringRes @MainThread int getIncomingCallTypeText(); diff --git a/java/com/android/dialer/duo/stub/DuoStub.java b/java/com/android/dialer/duo/stub/DuoStub.java index 628d6dc27..398e99035 100644 --- a/java/com/android/dialer/duo/stub/DuoStub.java +++ b/java/com/android/dialer/duo/stub/DuoStub.java @@ -68,6 +68,9 @@ public class DuoStub implements Duo { Assert.isNotNull(numbers); } + @Override + public void reloadReachability(@NonNull Context context) {} + @MainThread @Override public Intent getIntent(@NonNull Context context, @NonNull String number) { -- cgit v1.2.3