summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnne Rong <annerong@google.com>2015-09-18 12:28:46 -0700
committerAnne Rong <annerong@google.com>2015-09-18 17:15:11 -0700
commit1b4545d7b500e4e18a0f5be43a8052fce2112ae0 (patch)
tree052357afa8a1cc543cbd4e3804f56d0b0ba1aa5d
parentfbb709bc08fb999760b94adfa1bcbc956532a4e2 (diff)
Update time last blocked + times blocked fields on blocking a number.
Bug: 24134609 Change-Id: I57db367f77a7e4e901f10ea419cc5214524b02c1
-rw-r--r--src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java22
-rw-r--r--src/com/android/dialer/database/FilteredNumberContract.java11
-rw-r--r--src/com/android/dialer/database/FilteredNumberProvider.java25
3 files changed, 45 insertions, 13 deletions
diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
index 0f33aa21c..9da9cc15b 100644
--- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
+++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
@@ -80,22 +80,30 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- ((Listener) cookie).onQueryComplete(token, cookie, cursor);
+ if (cookie != null) {
+ ((Listener) cookie).onQueryComplete(token, cookie, cursor);
+ }
}
@Override
protected void onInsertComplete(int token, Object cookie, Uri uri) {
- ((Listener) cookie).onInsertComplete(token, cookie, uri);
+ if (cookie != null) {
+ ((Listener) cookie).onInsertComplete(token, cookie, uri);
+ }
}
@Override
protected void onUpdateComplete(int token, Object cookie, int result) {
- ((Listener) cookie).onUpdateComplete(token, cookie, result);
+ if (cookie != null) {
+ ((Listener) cookie).onUpdateComplete(token, cookie, result);
+ }
}
@Override
protected void onDeleteComplete(int token, Object cookie, int result) {
- ((Listener) cookie).onDeleteComplete(token, cookie, result);
+ if (cookie != null) {
+ ((Listener) cookie).onDeleteComplete(token, cookie, result);
+ }
}
private static Uri getContentUri(Integer id) {
@@ -106,6 +114,12 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
return uri;
}
+ public final void incrementFilteredCount(Integer id) {
+ startUpdate(NO_TOKEN, null,
+ ContentUris.withAppendedId(FilteredNumber.CONTENT_URI_INCREMENT_FILTERED_COUNT, id),
+ null, null, null);
+ }
+
/**
* Check if the number + country iso given has been blocked.
* This method normalizes the number for the lookup if normalizedNumber is null.
diff --git a/src/com/android/dialer/database/FilteredNumberContract.java b/src/com/android/dialer/database/FilteredNumberContract.java
index 38c49dc9d..f3966816c 100644
--- a/src/com/android/dialer/database/FilteredNumberContract.java
+++ b/src/com/android/dialer/database/FilteredNumberContract.java
@@ -16,13 +16,8 @@
package com.android.dialer.database;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
-import android.telephony.PhoneNumberUtils;
import com.android.dialerbind.ObjectFactory;
@@ -137,11 +132,17 @@ public final class FilteredNumberContract {
public static class FilteredNumber implements BaseColumns {
public static final String FILTERED_NUMBERS_TABLE = "filtered_numbers_table";
+ public static final String FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT =
+ "filtered_numbers_increment_filtered_count";
public static final Uri CONTENT_URI = Uri.withAppendedPath(
AUTHORITY_URI,
FILTERED_NUMBERS_TABLE);
+ public static final Uri CONTENT_URI_INCREMENT_FILTERED_COUNT = Uri.withAppendedPath(
+ AUTHORITY_URI,
+ FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT);
+
/**
* This utility class cannot be instantiated.
*/
diff --git a/src/com/android/dialer/database/FilteredNumberProvider.java b/src/com/android/dialer/database/FilteredNumberProvider.java
index 2bea7cae1..acb5e7f67 100644
--- a/src/com/android/dialer/database/FilteredNumberProvider.java
+++ b/src/com/android/dialer/database/FilteredNumberProvider.java
@@ -22,12 +22,12 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
+import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Binder;
import android.text.TextUtils;
-import android.text.format.Time;
import android.util.Log;
import com.android.contacts.common.GeoUtil;
@@ -49,6 +49,7 @@ public class FilteredNumberProvider extends ContentProvider {
private static final int FILTERED_NUMBERS_TABLE = 1;
private static final int FILTERED_NUMBERS_TABLE_ID = 2;
+ private static final int FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT = 3;
private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
@@ -64,6 +65,10 @@ public class FilteredNumberProvider extends ContentProvider {
sUriMatcher.addURI(ObjectFactory.getFilteredNumberProviderAuthority(),
FilteredNumberContract.FilteredNumber.FILTERED_NUMBERS_TABLE + "/#",
FILTERED_NUMBERS_TABLE_ID);
+ sUriMatcher.addURI(ObjectFactory.getFilteredNumberProviderAuthority(),
+ FilteredNumberContract.FilteredNumber.FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT
+ + "/#",
+ FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT);
return true;
}
@@ -121,9 +126,7 @@ public class FilteredNumberProvider extends ContentProvider {
@VisibleForTesting
protected long getCurrentTimeMs() {
- Time timeNow = new Time();
- timeNow.setToNow();
- return timeNow.toMillis(false);
+ return System.currentTimeMillis();
}
private void setDefaultValues(ContentValues values) {
@@ -171,6 +174,20 @@ public class FilteredNumberProvider extends ContentProvider {
case FILTERED_NUMBERS_TABLE_ID:
selection = getSelectionWithId(selection, ContentUris.parseId(uri));
break;
+ case FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT:
+ final long id = ContentUris.parseId(uri);
+ try {
+ db.execSQL(" UPDATE " + DialerDatabaseHelper.Tables.FILTERED_NUMBER_TABLE
+ + " SET" + FilteredNumberColumns.TIMES_FILTERED + "="
+ + FilteredNumberColumns.TIMES_FILTERED + "+1,"
+ + FilteredNumberColumns.LAST_TIME_FILTERED + "="
+ + getCurrentTimeMs()
+ + " WHERE " + FilteredNumberColumns._ID + "=" + id);
+ } catch (SQLException e) {
+ Log.d(TAG, "Could not update blocked statistics for " + id);
+ return 0;
+ }
+ return 1;
default:
throw new IllegalArgumentException("Unknown uri: " + uri);
}