diff options
author | mdooley <mdooley@google.com> | 2018-01-14 09:31:50 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-14 09:34:53 -0800 |
commit | 9fbb81d83f24d6f7ad9832bc16c3a41065eb9337 (patch) | |
tree | e50dd75250358ee2cf1a86eecbbbef2e40daab79 /java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java | |
parent | 25f24a79a24334e23706c2a8d69903820c622edb (diff) |
Make sure that voicemail transcriptions are processed serially
Since we are now using the AlarmManager to decide when to poll
for voicemail transcriptions, we need to ensure that we don't
start transcribing a voicemail until polling for the previous
one ends.
This cl postpones a voicemail transcription task if there is an alarm
set to poll for a transcription result. After a transcription result
is received (or we give up) the db is scanned for any pending transcriptions
and the next one is started.
Bug: 70242961
Test: manual and updated unit tests
PiperOrigin-RevId: 181899975
Change-Id: I7b8fb696164980cf710aa58a79418c6954e2b4d2
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java')
-rw-r--r-- | java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java b/java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java index a9a37225b..24c07cc37 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionDbHelper.java @@ -22,11 +22,10 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.net.Uri; -import android.os.Build.VERSION_CODES; +import android.os.Build; import android.provider.VoicemailContract.Voicemails; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; -import android.support.v4.os.BuildCompat; import android.util.Pair; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; @@ -35,7 +34,7 @@ import java.util.ArrayList; import java.util.List; /** Helper class for reading and writing transcription data in the database */ -@TargetApi(VERSION_CODES.O) +@TargetApi(Build.VERSION_CODES.O) public class TranscriptionDbHelper { @VisibleForTesting static final String[] PROJECTION = @@ -63,9 +62,8 @@ public class TranscriptionDbHelper { } @WorkerThread - @TargetApi(VERSION_CODES.M) // used for try with resources Pair<String, Integer> getTranscriptionAndState() { - Assert.checkState(BuildCompat.isAtLeastO()); + Assert.checkState(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); Assert.isWorkerThread(); try (Cursor cursor = contentResolver.query(uri, PROJECTION, null, null, null)) { if (cursor == null) { @@ -84,9 +82,8 @@ public class TranscriptionDbHelper { } @WorkerThread - @TargetApi(VERSION_CODES.M) // used for try with resources List<Uri> getUntranscribedVoicemails() { - Assert.checkArgument(BuildCompat.isAtLeastO()); + Assert.checkState(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); Assert.isWorkerThread(); List<Uri> untranscribed = new ArrayList<>(); String whereClause = @@ -105,6 +102,25 @@ public class TranscriptionDbHelper { } @WorkerThread + List<Uri> getTranscribingVoicemails() { + Assert.checkState(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); + Assert.isWorkerThread(); + List<Uri> inProgress = new ArrayList<>(); + String whereClause = VoicemailCompat.TRANSCRIPTION_STATE + "=?"; + String[] whereArgs = {String.valueOf(VoicemailCompat.TRANSCRIPTION_IN_PROGRESS)}; + try (Cursor cursor = contentResolver.query(uri, PROJECTION, whereClause, whereArgs, null)) { + if (cursor == null) { + LogUtil.e("TranscriptionDbHelper.getTranscribingVoicemails", "query failed."); + } else { + while (cursor.moveToNext()) { + inProgress.add(ContentUris.withAppendedId(uri, cursor.getLong(ID))); + } + } + } + return inProgress; + } + + @WorkerThread void setTranscriptionState(int transcriptionState) { Assert.isWorkerThread(); LogUtil.i( |