1 /* 2 * Copyright (C) 2014 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 17 package com.android.server.telecom; 18 19 import android.content.ContentResolver; 20 import android.provider.Settings; 21 import android.telecom.CallRedirectionService; 22 import java.util.concurrent.TimeUnit; 23 24 /** 25 * A helper class which serves only to make it easier to lookup timeout values. This class should 26 * never be instantiated, and only accessed through the {@link #get(String, long)} method. 27 * 28 * These methods are safe to call from any thread, including the UI thread. 29 */ 30 public final class Timeouts { 31 public static class Adapter { Adapter()32 public Adapter() { } 33 getCallScreeningTimeoutMillis(ContentResolver cr)34 public long getCallScreeningTimeoutMillis(ContentResolver cr) { 35 return Timeouts.getCallScreeningTimeoutMillis(cr); 36 } 37 getCallRemoveUnbindInCallServicesDelay(ContentResolver cr)38 public long getCallRemoveUnbindInCallServicesDelay(ContentResolver cr) { 39 return Timeouts.getCallRemoveUnbindInCallServicesDelay(cr); 40 } 41 getRetryBluetoothConnectAudioBackoffMillis(ContentResolver cr)42 public long getRetryBluetoothConnectAudioBackoffMillis(ContentResolver cr) { 43 return Timeouts.getRetryBluetoothConnectAudioBackoffMillis(cr); 44 } 45 getBluetoothPendingTimeoutMillis(ContentResolver cr)46 public long getBluetoothPendingTimeoutMillis(ContentResolver cr) { 47 return Timeouts.getBluetoothPendingTimeoutMillis(cr); 48 } 49 getEmergencyCallbackWindowMillis(ContentResolver cr)50 public long getEmergencyCallbackWindowMillis(ContentResolver cr) { 51 return Timeouts.getEmergencyCallbackWindowMillis(cr); 52 } 53 getUserDefinedCallRedirectionTimeoutMillis(ContentResolver cr)54 public long getUserDefinedCallRedirectionTimeoutMillis(ContentResolver cr) { 55 return Timeouts.getUserDefinedCallRedirectionTimeoutMillis(cr); 56 } 57 getCarrierCallRedirectionTimeoutMillis(ContentResolver cr)58 public long getCarrierCallRedirectionTimeoutMillis(ContentResolver cr) { 59 return Timeouts.getCarrierCallRedirectionTimeoutMillis(cr); 60 } 61 getPhoneAccountSuggestionServiceTimeout(ContentResolver cr)62 public long getPhoneAccountSuggestionServiceTimeout(ContentResolver cr) { 63 return Timeouts.getPhoneAccountSuggestionServiceTimeout(cr); 64 } 65 } 66 67 /** A prefix to use for all keys so to not clobber the global namespace. */ 68 private static final String PREFIX = "telecom."; 69 Timeouts()70 private Timeouts() {} 71 72 /** 73 * Returns the timeout value from Settings or the default value if it hasn't been changed. This 74 * method is safe to call from any thread, including the UI thread. 75 * 76 * @param contentResolver The content resolved. 77 * @param key Settings key to retrieve. 78 * @param defaultValue Default value, in milliseconds. 79 * @return The timeout value from Settings or the default value if it hasn't been changed. 80 */ get(ContentResolver contentResolver, String key, long defaultValue)81 private static long get(ContentResolver contentResolver, String key, long defaultValue) { 82 return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue); 83 } 84 85 /** 86 * Returns the amount of time to wait before disconnecting a call that was canceled via 87 * NEW_OUTGOING_CALL broadcast. This timeout allows apps which repost the call using a gateway 88 * to reuse the existing call, preventing the call from causing a start->end->start jank in the 89 * in-call UI. 90 */ getNewOutgoingCallCancelMillis(ContentResolver contentResolver)91 public static long getNewOutgoingCallCancelMillis(ContentResolver contentResolver) { 92 return get(contentResolver, "new_outgoing_call_cancel_ms", 500L); 93 } 94 95 /** 96 * Returns the maximum amount of time to wait before disconnecting a call that was canceled via 97 * NEW_OUTGOING_CALL broadcast. This prevents malicious or poorly configured apps from 98 * forever tying up the Telecom stack. 99 */ getMaxNewOutgoingCallCancelMillis(ContentResolver contentResolver)100 public static long getMaxNewOutgoingCallCancelMillis(ContentResolver contentResolver) { 101 return get(contentResolver, "max_new_outgoing_call_cancel_ms", 10000L); 102 } 103 104 /** 105 * Returns the amount of time to play each DTMF tone after post dial continue. 106 * This timeout allows the current tone to play for a certain amount of time before either being 107 * interrupted by the next tone or terminated. 108 */ getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver)109 public static long getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver) { 110 return get(contentResolver, "delay_between_dtmf_tones_ms", 300L); 111 } 112 113 /** 114 * Returns the amount of time to wait for an emergency call to be placed before routing to 115 * a different call service. A value of 0 or less means no timeout should be used. 116 */ getEmergencyCallTimeoutMillis(ContentResolver contentResolver)117 public static long getEmergencyCallTimeoutMillis(ContentResolver contentResolver) { 118 return get(contentResolver, "emergency_call_timeout_millis", 25000L /* 25 seconds */); 119 } 120 121 /** 122 * Returns the amount of time to wait for an emergency call to be placed before routing to 123 * a different call service. This timeout is used only when the radio is powered off (for 124 * example in airplane mode). A value of 0 or less means no timeout should be used. 125 */ getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver)126 public static long getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver) { 127 return get(contentResolver, "emergency_call_timeout_radio_off_millis", 128 60000L /* 1 minute */); 129 } 130 131 /** 132 * Returns the amount of delay before unbinding the in-call services after all the calls 133 * are removed. 134 */ getCallRemoveUnbindInCallServicesDelay(ContentResolver contentResolver)135 public static long getCallRemoveUnbindInCallServicesDelay(ContentResolver contentResolver) { 136 return get(contentResolver, "call_remove_unbind_in_call_services_delay", 137 2000L /* 2 seconds */); 138 } 139 140 /** 141 * Returns the amount of time for which bluetooth is considered connected after requesting 142 * connection. This compensates for the amount of time it takes for the audio route to 143 * actually change to bluetooth. 144 */ getBluetoothPendingTimeoutMillis(ContentResolver contentResolver)145 public static long getBluetoothPendingTimeoutMillis(ContentResolver contentResolver) { 146 return get(contentResolver, "bluetooth_pending_timeout_millis", 5000L); 147 } 148 149 /** 150 * Returns the amount of time to wait before retrying the connectAudio call. This is 151 * necessary to account for the HeadsetStateMachine sometimes not being ready when we want to 152 * connect to bluetooth audio immediately after a device connects. 153 */ getRetryBluetoothConnectAudioBackoffMillis(ContentResolver contentResolver)154 public static long getRetryBluetoothConnectAudioBackoffMillis(ContentResolver contentResolver) { 155 return get(contentResolver, "retry_bluetooth_connect_audio_backoff_millis", 500L); 156 } 157 158 /** 159 * Returns the amount of time to wait for the phone account suggestion service to reply. 160 */ getPhoneAccountSuggestionServiceTimeout(ContentResolver contentResolver)161 public static long getPhoneAccountSuggestionServiceTimeout(ContentResolver contentResolver) { 162 return get(contentResolver, "phone_account_suggestion_service_timeout", 163 5000L /* 5 seconds */); 164 } 165 166 /** 167 * Returns the amount of time to wait for the call screening service to allow or disallow a 168 * call. 169 */ getCallScreeningTimeoutMillis(ContentResolver contentResolver)170 public static long getCallScreeningTimeoutMillis(ContentResolver contentResolver) { 171 return get(contentResolver, "call_screening_timeout", 5000L /* 5 seconds */); 172 } 173 174 /** 175 * Returns the amount of time after an emergency call that incoming calls should be treated 176 * as potential emergency callbacks. 177 */ getEmergencyCallbackWindowMillis(ContentResolver contentResolver)178 public static long getEmergencyCallbackWindowMillis(ContentResolver contentResolver) { 179 return get(contentResolver, "emergency_callback_window_millis", 180 TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)); 181 } 182 183 /** 184 * Returns the amount of time for an user-defined {@link CallRedirectionService}. 185 * 186 * @param contentResolver The content resolved. 187 */ getUserDefinedCallRedirectionTimeoutMillis(ContentResolver contentResolver)188 public static long getUserDefinedCallRedirectionTimeoutMillis(ContentResolver contentResolver) { 189 return get(contentResolver, "user_defined_call_redirection_timeout", 190 5000L /* 5 seconds */); 191 } 192 193 /** 194 * Returns the amount of time for a carrier {@link CallRedirectionService}. 195 * 196 * @param contentResolver The content resolved. 197 */ getCarrierCallRedirectionTimeoutMillis(ContentResolver contentResolver)198 public static long getCarrierCallRedirectionTimeoutMillis(ContentResolver contentResolver) { 199 return get(contentResolver, "carrier_call_redirection_timeout", 5000L /* 5 seconds */); 200 } 201 } 202