diff options
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe')
-rw-r--r-- | java/com/android/voicemail/impl/transcribe/TranscriptionBackfillService.java | 9 | ||||
-rw-r--r-- | java/com/android/voicemail/impl/transcribe/TranscriptionService.java | 66 |
2 files changed, 46 insertions, 29 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionBackfillService.java b/java/com/android/voicemail/impl/transcribe/TranscriptionBackfillService.java index f7f643932..8161e71f7 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionBackfillService.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionBackfillService.java @@ -25,6 +25,7 @@ import android.net.Uri; import android.support.annotation.WorkerThread; import android.support.v4.app.JobIntentService; import android.support.v4.os.BuildCompat; +import android.telecom.PhoneAccountHandle; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.ThreadUtil; import com.android.dialer.constants.ScheduledJobIds; @@ -38,7 +39,7 @@ import java.util.List; public class TranscriptionBackfillService extends JobIntentService { /** Schedule a task to scan the database for untranscribed voicemails */ - public static boolean scheduleTask(Context context) { + public static boolean scheduleTask(Context context, PhoneAccountHandle account) { if (BuildCompat.isAtLeastO()) { LogUtil.enterBlock("TranscriptionBackfillService.transcribeOldVoicemails"); ComponentName componentName = new ComponentName(context, TranscriptionBackfillService.class); @@ -46,15 +47,17 @@ public class TranscriptionBackfillService extends JobIntentService { new JobInfo.Builder(ScheduledJobIds.VVM_TRANSCRIPTION_BACKFILL_JOB, componentName) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); JobScheduler scheduler = context.getSystemService(JobScheduler.class); - return scheduler.enqueue(builder.build(), makeWorkItem()) == JobScheduler.RESULT_SUCCESS; + return scheduler.enqueue(builder.build(), makeWorkItem(account)) + == JobScheduler.RESULT_SUCCESS; } else { LogUtil.i("TranscriptionBackfillService.transcribeOldVoicemails", "not supported"); return false; } } - private static JobWorkItem makeWorkItem() { + private static JobWorkItem makeWorkItem(PhoneAccountHandle account) { Intent intent = new Intent(); + intent.putExtra(TranscriptionService.EXTRA_ACCOUNT_HANDLE, account); return new JobWorkItem(intent); } diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java index 79e1a017c..33c9676a4 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java @@ -24,10 +24,9 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.support.annotation.MainThread; -import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; -import android.support.v4.os.BuildCompat; import android.telecom.PhoneAccountHandle; import android.text.TextUtils; import com.android.dialer.common.Assert; @@ -35,6 +34,9 @@ import com.android.dialer.common.LogUtil; import com.android.dialer.constants.ScheduledJobIds; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.voicemail.CarrierConfigKeys; +import com.android.voicemail.VoicemailClient; +import com.android.voicemail.VoicemailComponent; import com.android.voicemail.impl.transcribe.grpc.TranscriptionClientFactory; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -65,34 +67,46 @@ public class TranscriptionService extends JobService { // donation. @MainThread public static boolean scheduleNewVoicemailTranscriptionJob( - Context context, - Uri voicemailUri, - @Nullable PhoneAccountHandle account, - boolean highPriority) { + Context context, Uri voicemailUri, PhoneAccountHandle account, boolean highPriority) { Assert.isMainThread(); - if (BuildCompat.isAtLeastO()) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { LogUtil.i( - "TranscriptionService.scheduleNewVoicemailTranscriptionJob", "scheduling transcription"); - Logger.get(context).logImpression(DialerImpression.Type.VVM_TRANSCRIPTION_VOICEMAIL_RECEIVED); - - ComponentName componentName = new ComponentName(context, TranscriptionService.class); - JobInfo.Builder builder = - new JobInfo.Builder(ScheduledJobIds.VVM_TRANSCRIPTION_JOB, componentName); - if (highPriority) { - builder - .setMinimumLatency(0) - .setOverrideDeadline(0) - .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); - } else { - builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); - } - JobScheduler scheduler = context.getSystemService(JobScheduler.class); - JobWorkItem workItem = makeWorkItem(voicemailUri, account); - return scheduler.enqueue(builder.build(), workItem) == JobScheduler.RESULT_SUCCESS; - } else { - LogUtil.i("TranscriptionService.scheduleNewVoicemailTranscriptionJob", "not supported"); + "TranscriptionService.scheduleNewVoicemailTranscriptionJob", "not supported by sdk"); return false; } + if (!carrierAllowsOttTranscription(context, account)) { + LogUtil.i( + "TranscriptionService.scheduleNewVoicemailTranscriptionJob", + "carrier doesn't allow transcription"); + return false; + } + + LogUtil.i( + "TranscriptionService.scheduleNewVoicemailTranscriptionJob", "scheduling transcription"); + Logger.get(context).logImpression(DialerImpression.Type.VVM_TRANSCRIPTION_VOICEMAIL_RECEIVED); + + ComponentName componentName = new ComponentName(context, TranscriptionService.class); + JobInfo.Builder builder = + new JobInfo.Builder(ScheduledJobIds.VVM_TRANSCRIPTION_JOB, componentName); + if (highPriority) { + builder + .setMinimumLatency(0) + .setOverrideDeadline(0) + .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); + } else { + builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); + } + JobScheduler scheduler = context.getSystemService(JobScheduler.class); + JobWorkItem workItem = makeWorkItem(voicemailUri, account); + return scheduler.enqueue(builder.build(), workItem) == JobScheduler.RESULT_SUCCESS; + } + + private static boolean carrierAllowsOttTranscription( + Context context, PhoneAccountHandle account) { + VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient(); + return Boolean.parseBoolean( + client.getCarrierConfigString( + context, account, CarrierConfigKeys.VVM_CARRIER_ALLOWS_OTT_TRANSCRIPTION_STRING)); } // Cancel all transcription tasks |