From 7e1a0d155eecc8a407e11f91605db135911c8eb6 Mon Sep 17 00:00:00 2001 From: mdooley Date: Fri, 17 Nov 2017 11:02:48 -0800 Subject: Refactoring and adding TOS check before transcribing This cl just adds a check before starting a transcription job to verify that the user has accepted the appropriate TOS. Its a rather big cl just because it had to expose some TOS acceptance details that were previously encapsulated in the VoicemailTosMessageCreator. Bug: 69267260 Test: manual and unit tests PiperOrigin-RevId: 176132370 Change-Id: Ic28fb197a07f9df7a9b5f1729c84566cba0890fc --- .../impl/transcribe/TranscriptionService.java | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'java/com/android/voicemail/impl/transcribe') diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java index 33c9676a4..a19ab6208 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java @@ -69,15 +69,7 @@ public class TranscriptionService extends JobService { public static boolean scheduleNewVoicemailTranscriptionJob( Context context, Uri voicemailUri, PhoneAccountHandle account, boolean highPriority) { Assert.isMainThread(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - LogUtil.i( - "TranscriptionService.scheduleNewVoicemailTranscriptionJob", "not supported by sdk"); - return false; - } - if (!carrierAllowsOttTranscription(context, account)) { - LogUtil.i( - "TranscriptionService.scheduleNewVoicemailTranscriptionJob", - "carrier doesn't allow transcription"); + if (!canTranscribeVoicemail(context, account)) { return false; } @@ -101,12 +93,24 @@ public class TranscriptionService extends JobService { return scheduler.enqueue(builder.build(), workItem) == JobScheduler.RESULT_SUCCESS; } - private static boolean carrierAllowsOttTranscription( - Context context, PhoneAccountHandle account) { + private static boolean canTranscribeVoicemail(Context context, PhoneAccountHandle account) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + LogUtil.i("TranscriptionService.canTranscribeVoicemail", "not supported by sdk"); + return false; + } VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient(); - return Boolean.parseBoolean( + if (!client.hasAcceptedTos(context, account)) { + LogUtil.i("TranscriptionService.canTranscribeVoicemail", "hasn't accepted TOS"); + return false; + } + if (!Boolean.parseBoolean( client.getCarrierConfigString( - context, account, CarrierConfigKeys.VVM_CARRIER_ALLOWS_OTT_TRANSCRIPTION_STRING)); + context, account, CarrierConfigKeys.VVM_CARRIER_ALLOWS_OTT_TRANSCRIPTION_STRING))) { + LogUtil.i( + "TranscriptionService.canTranscribeVoicemail", "carrier doesn't allow transcription"); + return false; + } + return true; } // Cancel all transcription tasks -- cgit v1.2.3