• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ConfigProviderBindings;
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         && ConfigProviderBindings.get(context)
34             .getBoolean("voicemail_transcription_available", false);
35   }
36 
getServerAddress()37   public String getServerAddress() {
38     // Private voicemail transcription service
39     return ConfigProviderBindings.get(context)
40         .getString(
41             "voicemail_transcription_server_address", "voicemailtranscription-pa.googleapis.com");
42   }
43 
getApiKey()44   public String getApiKey() {
45     // Android API key restricted to com.google.android.dialer
46     return ConfigProviderBindings.get(context)
47         .getString(
48             "voicemail_transcription_client_api_key", "AIzaSyAXdDnif6B7sBYxU8hzw9qAp3pRPVHs060");
49   }
50 
getAuthToken()51   public String getAuthToken() {
52     return null;
53   }
54 
shouldUsePlaintext()55   public boolean shouldUsePlaintext() {
56     return ConfigProviderBindings.get(context)
57         .getBoolean("voicemail_transcription_server_use_plaintext", false);
58   }
59 
shouldUseSyncApi()60   public boolean shouldUseSyncApi() {
61     return ConfigProviderBindings.get(context)
62         .getBoolean("voicemail_transcription_server_use_sync_api", false);
63   }
64 
getMaxTranscriptionRetries()65   public long getMaxTranscriptionRetries() {
66     return ConfigProviderBindings.get(context)
67         .getLong("voicemail_transcription_max_transcription_retries", 2L);
68   }
69 
getMaxGetTranscriptPolls()70   public int getMaxGetTranscriptPolls() {
71     return (int)
72         ConfigProviderBindings.get(context)
73             .getLong("voicemail_transcription_max_get_transcript_polls", 20L);
74   }
75 
getInitialGetTranscriptPollDelayMillis()76   public long getInitialGetTranscriptPollDelayMillis() {
77     return ConfigProviderBindings.get(context)
78         .getLong(
79             "voicemail_transcription_get_initial_transcript_poll_delay_millis",
80             TimeUnit.SECONDS.toMillis(1));
81   }
82 
getMaxGetTranscriptPollTimeMillis()83   public long getMaxGetTranscriptPollTimeMillis() {
84     return ConfigProviderBindings.get(context)
85         .getLong(
86             "voicemail_transcription_get_max_transcript_poll_time_millis",
87             TimeUnit.MINUTES.toMillis(20));
88   }
89 
isVoicemailDonationAvailable()90   public boolean isVoicemailDonationAvailable() {
91     return ConfigProviderBindings.get(context)
92         .getBoolean("voicemail_transcription_donation_available", false);
93   }
94 
useClientGeneratedVoicemailIds()95   public boolean useClientGeneratedVoicemailIds() {
96     return ConfigProviderBindings.get(context)
97         .getBoolean("voicemail_transcription_client_generated_voicemail_ids", false);
98   }
99 
100   @Override
toString()101   public String toString() {
102     return String.format(
103         "{ address: %s, api key: %s, auth token: %s, plaintext: %b, sync: %b, retries: %d, polls:"
104             + " %d, poll ms: %d }",
105         getServerAddress(),
106         getApiKey(),
107         getAuthToken(),
108         shouldUsePlaintext(),
109         shouldUseSyncApi(),
110         getMaxTranscriptionRetries(),
111         getMaxGetTranscriptPolls(),
112         getMaxGetTranscriptPollTimeMillis());
113   }
114 }
115