From a4ddbac290d81e6f1b9988e084a7a9bb2254c3e8 Mon Sep 17 00:00:00 2001 From: uabdullah Date: Fri, 2 Feb 2018 14:29:20 -0800 Subject: Add Support for transcription state in the AnnotatedCallLog Transcription state column is needed for voicemail transcriptions. This CL adds the support for it in the NUI so that it maybe used by the VM Tab. Bug: 72491920 Test: Unit Tests PiperOrigin-RevId: 184335015 Change-Id: I14a71890224216c957e0d6146af9dafaa1550865 --- .../database/AnnotatedCallLogDatabaseHelper.java | 3 +- .../contract/AnnotatedCallLogContract.java | 11 ++++ .../systemcalllog/SystemCallLogDataSource.java | 74 ++++++++++++++++------ .../compat/android/provider/VoicemailCompat.java | 6 +- .../voicemail/listui/VoicemailCursorLoader.java | 3 + .../dialer/voicemail/model/VoicemailEntry.java | 9 ++- 6 files changed, 80 insertions(+), 26 deletions(-) diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java index fea3e91e8..c8387377b 100644 --- a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java @@ -55,7 +55,8 @@ class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { + (AnnotatedCallLog.TRANSCRIPTION + " integer, ") + (AnnotatedCallLog.VOICEMAIL_URI + " text, ") + (AnnotatedCallLog.CALL_TYPE + " integer not null, ") - + (AnnotatedCallLog.NUMBER_ATTRIBUTES + " blob") + + (AnnotatedCallLog.NUMBER_ATTRIBUTES + " blob, ") + + (AnnotatedCallLog.TRANSCRIPTION_STATE + " integer") + ");"; /** diff --git a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java index 4fee4e558..c181d7573 100644 --- a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java +++ b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java @@ -17,7 +17,9 @@ package com.android.dialer.calllog.database.contract; import android.net.Uri; +import android.os.Build; import android.provider.BaseColumns; +import com.android.dialer.compat.android.provider.VoicemailCompat; import com.android.dialer.constants.Constants; import java.util.Arrays; @@ -199,6 +201,15 @@ public class AnnotatedCallLogContract { */ public static final String TRANSCRIPTION = "transcription"; + /** + * See {@link VoicemailCompat.TRANSCRIPTION_STATE} + * + *

Only populated in {@link Build.VERSION_CODES.O} and above + * + *

TYPE: INTEGER + */ + public static final String TRANSCRIPTION_STATE = "transcription_state"; + /** * See {@link android.provider.CallLog.Calls#VOICEMAIL_URI}. * diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java index 24410ee30..ee484d95e 100644 --- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java +++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java @@ -24,6 +24,8 @@ import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Build; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.Handler; import android.provider.CallLog; import android.provider.CallLog.Calls; @@ -32,6 +34,7 @@ import android.provider.VoicemailContract.Voicemails; import android.support.annotation.ColorInt; import android.support.annotation.MainThread; import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; import android.telecom.PhoneAccount; @@ -49,6 +52,7 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.ThreadUtil; +import com.android.dialer.compat.android.provider.VoicemailCompat; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.storage.StorageComponent; import com.android.dialer.telecom.TelecomUtil; @@ -58,6 +62,7 @@ import com.google.common.collect.Iterables; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.i18n.phonenumbers.PhoneNumberUtil; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -235,26 +240,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { .getContentResolver() .query( Calls.CONTENT_URI_WITH_VOICEMAIL, - new String[] { - Calls._ID, - Calls.DATE, - Calls.LAST_MODIFIED, // TODO(a bug): Not available in M - Calls.NUMBER, - Calls.NUMBER_PRESENTATION, - Calls.TYPE, - Calls.COUNTRY_ISO, - Calls.DURATION, - Calls.DATA_USAGE, - Calls.TRANSCRIPTION, - Calls.VOICEMAIL_URI, - Calls.IS_READ, - Calls.NEW, - Calls.GEOCODED_LOCATION, - Calls.PHONE_ACCOUNT_COMPONENT_NAME, - Calls.PHONE_ACCOUNT_ID, - Calls.FEATURES, - Calls.POST_DIAL_DIGITS // TODO(a bug): Not available in M - }, + getProjection(), // TODO(a bug): LAST_MODIFIED not available on M Calls.LAST_MODIFIED + " > ? AND " + Voicemails.DELETED + " = 0", new String[] {String.valueOf(previousTimestampProcessed)}, @@ -358,6 +344,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { contentValues.put(AnnotatedCallLog.DATA_USAGE, dataUsage); contentValues.put(AnnotatedCallLog.TRANSCRIPTION, transcription); contentValues.put(AnnotatedCallLog.VOICEMAIL_URI, voicemailUri); + setTranscriptionState(cursor, contentValues); if (existingAnnotatedCallLogIds.contains(id)) { mutations.update(id, contentValues); @@ -369,6 +356,53 @@ public class SystemCallLogDataSource implements CallLogDataSource { } } + private void setTranscriptionState(Cursor cursor, ContentValues contentValues) { + if (VERSION.SDK_INT >= VERSION_CODES.O) { + int transcriptionStateColumn = + cursor.getColumnIndexOrThrow(VoicemailCompat.TRANSCRIPTION_STATE); + int transcriptionState = cursor.getInt(transcriptionStateColumn); + contentValues.put(VoicemailCompat.TRANSCRIPTION_STATE, transcriptionState); + } + } + + private static final String[] PROJECTION_PRE_O = + new String[] { + Calls._ID, + Calls.DATE, + Calls.LAST_MODIFIED, // TODO(a bug): Not available in M + Calls.NUMBER, + Calls.NUMBER_PRESENTATION, + Calls.TYPE, + Calls.COUNTRY_ISO, + Calls.DURATION, + Calls.DATA_USAGE, + Calls.TRANSCRIPTION, + Calls.VOICEMAIL_URI, + Calls.IS_READ, + Calls.NEW, + Calls.GEOCODED_LOCATION, + Calls.PHONE_ACCOUNT_COMPONENT_NAME, + Calls.PHONE_ACCOUNT_ID, + Calls.FEATURES, + Calls.POST_DIAL_DIGITS // TODO(a bug): Not available in M + }; + + @RequiresApi(VERSION_CODES.O) + private static final String[] PROJECTION_O_AND_LATER; + + static { + List projectionList = new ArrayList<>(Arrays.asList(PROJECTION_PRE_O)); + projectionList.add(VoicemailCompat.TRANSCRIPTION_STATE); + PROJECTION_O_AND_LATER = projectionList.toArray(new String[projectionList.size()]); + } + + private String[] getProjection() { + if (VERSION.SDK_INT >= VERSION_CODES.O) { + return PROJECTION_O_AND_LATER; + } + return PROJECTION_PRE_O; + } + private void populatePhoneAccountLabelAndColor( Context appContext, ContentValues contentValues, diff --git a/java/com/android/dialer/compat/android/provider/VoicemailCompat.java b/java/com/android/dialer/compat/android/provider/VoicemailCompat.java index 02eebb32c..35e0ea58f 100644 --- a/java/com/android/dialer/compat/android/provider/VoicemailCompat.java +++ b/java/com/android/dialer/compat/android/provider/VoicemailCompat.java @@ -16,10 +16,10 @@ package com.android.dialer.compat.android.provider; /** - * Provide access to new API constants before they're publicly available + * Provide access to Voicemail Transcription API constants as they won't be publicly available. * - *

Copied from android.provider.VoicemailContract.Voicemails. These should become public in O-MR1 - * and these constants can be removed then. + *

Copied from android.provider.VoicemailContract.Voicemails. These do not plan to become public + * in O-MR1 or in the near future. */ public class VoicemailCompat { diff --git a/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java b/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java index 74d1b6162..11e788840 100644 --- a/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java +++ b/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java @@ -45,6 +45,7 @@ final class VoicemailCursorLoader extends CursorLoader { AnnotatedCallLog.VOICEMAIL_URI, AnnotatedCallLog.IS_READ, AnnotatedCallLog.NUMBER_ATTRIBUTES, + AnnotatedCallLog.TRANSCRIPTION_STATE }; // Indexes for VOICEMAIL_COLUMNS @@ -59,6 +60,7 @@ final class VoicemailCursorLoader extends CursorLoader { private static final int VOICEMAIL_URI = 8; private static final int IS_READ = 9; private static final int NUMBER_ATTRIBUTES = 10; + private static final int TRANSCRIPTION_STATE = 11; // TODO(zachh): Optimize indexes VoicemailCursorLoader(Context context) { @@ -105,6 +107,7 @@ final class VoicemailCursorLoader extends CursorLoader { .setCallType(cursor.getInt(CALL_TYPE)) .setIsRead(cursor.getInt(IS_READ)) .setNumberAttributes(numberAttributes) + .setTranscriptionState(cursor.getInt(TRANSCRIPTION_STATE)) .build(); } diff --git a/java/com/android/dialer/voicemail/model/VoicemailEntry.java b/java/com/android/dialer/voicemail/model/VoicemailEntry.java index f17a23e54..5830fb17e 100644 --- a/java/com/android/dialer/voicemail/model/VoicemailEntry.java +++ b/java/com/android/dialer/voicemail/model/VoicemailEntry.java @@ -20,6 +20,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.android.dialer.DialerPhoneNumber; import com.android.dialer.NumberAttributes; +import com.android.dialer.compat.android.provider.VoicemailCompat; import com.google.auto.value.AutoValue; /** Data class containing the contents of a voicemail entry from the AnnotatedCallLog. */ @@ -34,7 +35,8 @@ public abstract class VoicemailEntry { .setNumberAttributes(NumberAttributes.getDefaultInstance()) .setDuration(0) .setCallType(0) - .setIsRead(0); + .setIsRead(0) + .setTranscriptionState(VoicemailCompat.TRANSCRIPTION_NOT_STARTED); } public abstract int id(); @@ -44,7 +46,6 @@ public abstract class VoicemailEntry { @NonNull public abstract DialerPhoneNumber number(); - @Nullable public abstract String formattedNumber(); @@ -65,6 +66,8 @@ public abstract class VoicemailEntry { public abstract NumberAttributes numberAttributes(); + public abstract int transcriptionState(); + /** Builder for {@link VoicemailEntry}. */ @AutoValue.Builder public abstract static class Builder { @@ -91,6 +94,8 @@ public abstract class VoicemailEntry { public abstract Builder setNumberAttributes(NumberAttributes numberAttributes); + public abstract Builder setTranscriptionState(int transcriptionState); + public abstract VoicemailEntry build(); } } -- cgit v1.2.3