From 8a90a0ac4898f5c575cbd22e8edb54f838edd9ea Mon Sep 17 00:00:00 2001 From: linyuh Date: Mon, 11 Jun 2018 16:37:22 -0700 Subject: Default column IS_VOICEMAIL_CALL to 0 in the annotated call log. Test: AnnotatedCallLogDatabaseHelperTest PiperOrigin-RevId: 200134473 Change-Id: I1d3f43630b6cd7753ef8b72a7a02d119c8ab75cc --- .../database/AnnotatedCallLogDatabaseHelper.java | 57 ++++++++++++++-------- .../android/dialer/calllog/database/Coalescer.java | 9 ++-- 2 files changed, 41 insertions(+), 25 deletions(-) (limited to 'java/com/android/dialer/calllog') diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java index 32f303fb4..8fc80a62d 100644 --- a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java @@ -20,6 +20,7 @@ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.provider.CallLog.Calls; +import android.support.annotation.VisibleForTesting; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; @@ -34,6 +35,8 @@ import javax.inject.Singleton; @Singleton public class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { + @VisibleForTesting static final int VERSION = 3; + private static final String FILENAME = "annotated_call_log.db"; private final Context appContext; @@ -45,7 +48,7 @@ public class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { @ApplicationContext Context appContext, @AnnotatedCallLogMaxRows int maxRows, @BackgroundExecutor ListeningExecutorService backgroundExecutor) { - super(appContext, FILENAME, null, 2); + super(appContext, FILENAME, null, VERSION); this.appContext = appContext; this.maxRows = maxRows; @@ -73,26 +76,12 @@ public class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { + (AnnotatedCallLog.VOICEMAIL_URI + " text, ") + (AnnotatedCallLog.CALL_TYPE + " integer not null, ") + (AnnotatedCallLog.NUMBER_ATTRIBUTES + " blob, ") - + (AnnotatedCallLog.IS_VOICEMAIL_CALL + " integer, ") + + (AnnotatedCallLog.IS_VOICEMAIL_CALL + " integer default 0, ") + (AnnotatedCallLog.VOICEMAIL_CALL_TAG + " text, ") + (AnnotatedCallLog.TRANSCRIPTION_STATE + " integer, ") + (AnnotatedCallLog.CALL_MAPPING_ID + " text") + ");"; - private static final String ALTER_TABLE_SQL_ADD_CALL_MAPPING_ID_COLUMN = - "alter table " - + AnnotatedCallLog.TABLE - + " add column " - + AnnotatedCallLog.CALL_MAPPING_ID - + " text;"; - private static final String UPDATE_CALL_MAPPING_ID_COLUMN = - "update " - + AnnotatedCallLog.TABLE - + " set " - + AnnotatedCallLog.CALL_MAPPING_ID - + " = " - + AnnotatedCallLog.TIMESTAMP; - /** * Deletes all but the first maxRows rows (by timestamp, excluding voicemails) to keep the table a * manageable size. @@ -159,12 +148,42 @@ public class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (oldVersion == 1 && newVersion == 2) { - db.execSQL(ALTER_TABLE_SQL_ADD_CALL_MAPPING_ID_COLUMN); - db.execSQL(UPDATE_CALL_MAPPING_ID_COLUMN); + if (oldVersion < 2) { + upgradeToV2(db); + } + if (oldVersion < 3) { + upgradeToV3(db); } } + private static void upgradeToV2(SQLiteDatabase db) { + db.execSQL( + "alter table " + + AnnotatedCallLog.TABLE + + " add column " + + AnnotatedCallLog.CALL_MAPPING_ID + + " text;"); + db.execSQL( + "update " + + AnnotatedCallLog.TABLE + + " set " + + AnnotatedCallLog.CALL_MAPPING_ID + + " = " + + AnnotatedCallLog.TIMESTAMP); + } + + private static void upgradeToV3(SQLiteDatabase db) { + db.execSQL( + "update " + + AnnotatedCallLog.TABLE + + " set " + + AnnotatedCallLog.IS_VOICEMAIL_CALL + + " = 0 " + + "where " + + AnnotatedCallLog.IS_VOICEMAIL_CALL + + " is null"); + } + /** Closes the database and deletes it. */ public ListenableFuture delete() { return backgroundExecutor.submit( diff --git a/java/com/android/dialer/calllog/database/Coalescer.java b/java/com/android/dialer/calllog/database/Coalescer.java index 36df87c06..903b7e26e 100644 --- a/java/com/android/dialer/calllog/database/Coalescer.java +++ b/java/com/android/dialer/calllog/database/Coalescer.java @@ -321,14 +321,11 @@ public class Coalescer { .setFeatures(coalescedContentValues.getAsInteger(CoalescedAnnotatedCallLog.FEATURES)) .setCallType(coalescedContentValues.getAsInteger(CoalescedAnnotatedCallLog.CALL_TYPE)) .setNumberAttributes(numberAttributes) + .setIsVoicemailCall( + coalescedContentValues.getAsInteger(CoalescedAnnotatedCallLog.IS_VOICEMAIL_CALL) + == 1) .setCoalescedIds(coalescedIds); - // TODO(linyuh): none of the boolean columns in the annotated call log should be null. - // This is a bug in VoicemailDataSource, but we should also fix the database constraints. - Integer isVoicemailCall = - coalescedContentValues.getAsInteger(CoalescedAnnotatedCallLog.IS_VOICEMAIL_CALL); - coalescedRowBuilder.setIsVoicemailCall(isVoicemailCall != null && isVoicemailCall == 1); - String formattedNumber = coalescedContentValues.getAsString(CoalescedAnnotatedCallLog.FORMATTED_NUMBER); if (!TextUtils.isEmpty(formattedNumber)) { -- cgit v1.2.3