diff options
author | zachh <zachh@google.com> | 2018-03-20 17:08:52 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-20 17:09:39 -0700 |
commit | 2482c0fc58034e01efb7ce7e67408e248f028c95 (patch) | |
tree | 64e3aa663d2a36568df7a3d35d5322d24398e706 /java/com/android/dialer/calllog/database | |
parent | 6f067c91169ab9d4c24e43c039ef902700a7087f (diff) |
Added "clearData" to CallLogDataSource and PhoneLookup interfaces.
This is necessary to disable the call log framework via flags.
This isn't yet called anywhere.
Bug: 74821995
Test: unit
PiperOrigin-RevId: 189838957
Change-Id: I926c02c41151528eabc208c874acbfe7897a2f93
Diffstat (limited to 'java/com/android/dialer/calllog/database')
5 files changed, 94 insertions, 10 deletions
diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java index 69722731e..9a80af2f7 100644 --- a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java @@ -45,12 +45,7 @@ import java.util.Arrays; /** {@link ContentProvider} for the annotated call log. */ public class AnnotatedCallLogContentProvider extends ContentProvider { - /** - * We sometimes run queries where we potentially pass every ID into a where clause using the - * (?,?,?,...) syntax. The maximum number of host parameters is 999, so that's the maximum size - * this table can be. See https://www.sqlite.org/limits.html for more details. - */ - private static final int MAX_ROWS = 999; + private static final int ANNOTATED_CALL_LOG_TABLE_CODE = 1; private static final int ANNOTATED_CALL_LOG_TABLE_ID_CODE = 2; @@ -87,7 +82,7 @@ public class AnnotatedCallLogContentProvider extends ContentProvider { @Override public boolean onCreate() { - databaseHelper = new AnnotatedCallLogDatabaseHelper(getContext(), MAX_ROWS); + databaseHelper = CallLogDatabaseComponent.get(getContext()).annotatedCallLogDatabaseHelper(); // Note: As this method is called before Application#onCreate, we must *not* initialize objects // that require preparation work done in Application#onCreate. diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java index 3b67ff2d7..7df83b3d1 100644 --- a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java @@ -22,15 +22,34 @@ import android.database.sqlite.SQLiteOpenHelper; import android.provider.CallLog.Calls; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; +import com.android.dialer.inject.ApplicationContext; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; import java.util.Locale; +import javax.inject.Inject; +import javax.inject.Singleton; /** {@link SQLiteOpenHelper} for the AnnotatedCallLog database. */ -class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { +@Singleton +public class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { + + private static final String FILENAME = "annotated_call_log.db"; + + private final Context appContext; private final int maxRows; + private final ListeningExecutorService backgroundExecutor; + + @Inject + public AnnotatedCallLogDatabaseHelper( + @ApplicationContext Context appContext, + @AnnotatedCallLogMaxRows int maxRows, + @BackgroundExecutor ListeningExecutorService backgroundExecutor) { + super(appContext, FILENAME, null, 1); - AnnotatedCallLogDatabaseHelper(Context appContext, int maxRows) { - super(appContext, "annotated_call_log.db", null, 1); + this.appContext = appContext; this.maxRows = maxRows; + this.backgroundExecutor = backgroundExecutor; } private static final String CREATE_TABLE_SQL = @@ -127,4 +146,14 @@ class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {} + + /** Closes the database and deletes it. */ + public ListenableFuture<Void> delete() { + return backgroundExecutor.submit( + () -> { + close(); + appContext.deleteDatabase(FILENAME); + return null; + }); + } } diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogMaxRows.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogMaxRows.java new file mode 100644 index 000000000..5542d661f --- /dev/null +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogMaxRows.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2018 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.calllog.database; + +import javax.inject.Qualifier; + +/** Annotation for the max number of rows in the AnnotatedCallLog. */ +@Qualifier +public @interface AnnotatedCallLogMaxRows {} diff --git a/java/com/android/dialer/calllog/database/CallLogDatabaseComponent.java b/java/com/android/dialer/calllog/database/CallLogDatabaseComponent.java index 991237449..09e291eb0 100644 --- a/java/com/android/dialer/calllog/database/CallLogDatabaseComponent.java +++ b/java/com/android/dialer/calllog/database/CallLogDatabaseComponent.java @@ -25,6 +25,8 @@ public abstract class CallLogDatabaseComponent { public abstract Coalescer coalescer(); + public abstract AnnotatedCallLogDatabaseHelper annotatedCallLogDatabaseHelper(); + public static CallLogDatabaseComponent get(Context context) { return ((CallLogDatabaseComponent.HasComponent) ((HasRootComponent) context.getApplicationContext()).component()) diff --git a/java/com/android/dialer/calllog/database/CallLogDatabaseModule.java b/java/com/android/dialer/calllog/database/CallLogDatabaseModule.java new file mode 100644 index 000000000..eef3fb54e --- /dev/null +++ b/java/com/android/dialer/calllog/database/CallLogDatabaseModule.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 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.calllog.database; + +import dagger.Module; +import dagger.Provides; + +/** Binds database dependencies. */ +@Module +public class CallLogDatabaseModule { + + @Provides + @AnnotatedCallLogMaxRows + static int provideMaxRows() { + /* + * We sometimes run queries where we potentially pass every ID into a where clause using the + * (?,?,?,...) syntax. The maximum number of host parameters is 999, so that's the maximum size + * this table can be. See https://www.sqlite.org/limits.html for more details. + */ + return 999; + } +} |