1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 package com.android.voicemail.impl.transcribe; 17 18 import android.content.Context; 19 import android.os.Build; 20 import com.android.dialer.configprovider.ConfigProviderComponent; 21 import java.util.concurrent.TimeUnit; 22 23 /** Provides configuration values needed to connect to the transcription server. */ 24 public class TranscriptionConfigProvider { 25 private final Context context; 26 TranscriptionConfigProvider(Context context)27 public TranscriptionConfigProvider(Context context) { 28 this.context = context; 29 } 30 isVoicemailTranscriptionAvailable()31 public boolean isVoicemailTranscriptionAvailable() { 32 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O 33 && ConfigProviderComponent.get(context) 34 .getConfigProvider() 35 .getBoolean("voicemail_transcription_available", false); 36 } 37 getServerAddress()38 public String getServerAddress() { 39 // Private voicemail transcription service 40 return ConfigProviderComponent.get(context) 41 .getConfigProvider() 42 .getString( 43 "voicemail_transcription_server_address", "voicemailtranscription-pa.googleapis.com"); 44 } 45 getApiKey()46 public String getApiKey() { 47 // Android API key restricted to com.google.android.dialer 48 return ConfigProviderComponent.get(context) 49 .getConfigProvider() 50 .getString( 51 "voicemail_transcription_client_api_key", "AIzaSyAXdDnif6B7sBYxU8hzw9qAp3pRPVHs060"); 52 } 53 getAuthToken()54 public String getAuthToken() { 55 return null; 56 } 57 shouldUsePlaintext()58 public boolean shouldUsePlaintext() { 59 return ConfigProviderComponent.get(context) 60 .getConfigProvider() 61 .getBoolean("voicemail_transcription_server_use_plaintext", false); 62 } 63 shouldUseSyncApi()64 public boolean shouldUseSyncApi() { 65 return ConfigProviderComponent.get(context) 66 .getConfigProvider() 67 .getBoolean("voicemail_transcription_server_use_sync_api", false); 68 } 69 getMaxTranscriptionRetries()70 public long getMaxTranscriptionRetries() { 71 return ConfigProviderComponent.get(context) 72 .getConfigProvider() 73 .getLong("voicemail_transcription_max_transcription_retries", 2L); 74 } 75 getMaxGetTranscriptPolls()76 public int getMaxGetTranscriptPolls() { 77 return (int) 78 ConfigProviderComponent.get(context) 79 .getConfigProvider() 80 .getLong("voicemail_transcription_max_get_transcript_polls", 20L); 81 } 82 getInitialGetTranscriptPollDelayMillis()83 public long getInitialGetTranscriptPollDelayMillis() { 84 return ConfigProviderComponent.get(context) 85 .getConfigProvider() 86 .getLong( 87 "voicemail_transcription_get_initial_transcript_poll_delay_millis", 88 TimeUnit.SECONDS.toMillis(1)); 89 } 90 getMaxGetTranscriptPollTimeMillis()91 public long getMaxGetTranscriptPollTimeMillis() { 92 return ConfigProviderComponent.get(context) 93 .getConfigProvider() 94 .getLong( 95 "voicemail_transcription_get_max_transcript_poll_time_millis", 96 TimeUnit.MINUTES.toMillis(20)); 97 } 98 isVoicemailDonationAvailable()99 public boolean isVoicemailDonationAvailable() { 100 return ConfigProviderComponent.get(context) 101 .getConfigProvider() 102 .getBoolean("voicemail_transcription_donation_available", false); 103 } 104 useClientGeneratedVoicemailIds()105 public boolean useClientGeneratedVoicemailIds() { 106 return ConfigProviderComponent.get(context) 107 .getConfigProvider() 108 .getBoolean("voicemail_transcription_client_generated_voicemail_ids", false); 109 } 110 111 @Override toString()112 public String toString() { 113 return String.format( 114 "{ address: %s, api key: %s, auth token: %s, plaintext: %b, sync: %b, retries: %d, polls:" 115 + " %d, poll ms: %d }", 116 getServerAddress(), 117 getApiKey(), 118 getAuthToken(), 119 shouldUsePlaintext(), 120 shouldUseSyncApi(), 121 getMaxTranscriptionRetries(), 122 getMaxGetTranscriptPolls(), 123 getMaxGetTranscriptPollTimeMillis()); 124 } 125 } 126