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 22 /** 23 * A helper class which serves only to make it easier to lookup timeout values. This class should 24 * never be instantiated, and only accessed through the {@link #get(String, long)} method. 25 * 26 * These methods are safe to call from any thread, including the UI thread. 27 */ 28 public final class Timeouts { 29 public static class Adapter { 30 public Adapter() { } 31 32 public long getCallScreeningTimeoutMillis(ContentResolver cr) { 33 return Timeouts.getCallScreeningTimeoutMillis(cr); 34 } 35 } 36 37 /** A prefix to use for all keys so to not clobber the global namespace. */ 38 private static final String PREFIX = "telecom."; 39 40 private Timeouts() {} 41 42 /** 43 * Returns the timeout value from Settings or the default value if it hasn't been changed. This 44 * method is safe to call from any thread, including the UI thread. 45 * 46 * @param contentResolver The content resolved. 47 * @param key Settings key to retrieve. 48 * @param defaultValue Default value, in milliseconds. 49 * @return The timeout value from Settings or the default value if it hasn't been changed. 50 */ 51 private static long get(ContentResolver contentResolver, String key, long defaultValue) { 52 return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue); 53 } 54 55 /** 56 * Returns the longest period, in milliseconds, to wait for the query for direct-to-voicemail 57 * to complete. If the query goes beyond this timeout, the incoming call screen is shown to the 58 * user. 59 */ 60 public static long getDirectToVoicemailMillis(ContentResolver contentResolver) { 61 return get(contentResolver, "direct_to_voicemail_ms", 500L); 62 } 63 64 /** 65 * Returns the amount of time to wait before disconnecting a call that was canceled via 66 * NEW_OUTGOING_CALL broadcast. This timeout allows apps which repost the call using a gateway 67 * to reuse the existing call, preventing the call from causing a start->end->start jank in the 68 * in-call UI. 69 */ 70 public static long getNewOutgoingCallCancelMillis(ContentResolver contentResolver) { 71 return get(contentResolver, "new_outgoing_call_cancel_ms", 400L); 72 } 73 74 /** 75 * Returns the amount of time to play each DTMF tone after post dial continue. 76 * This timeout allows the current tone to play for a certain amount of time before either being 77 * interrupted by the next tone or terminated. 78 */ 79 public static long getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver) { 80 return get(contentResolver, "delay_between_dtmf_tones_ms", 300L); 81 } 82 83 /** 84 * Returns the amount of time to wait for an emergency call to be placed before routing to 85 * a different call service. A value of 0 or less means no timeout should be used. 86 */ 87 public static long getEmergencyCallTimeoutMillis(ContentResolver contentResolver) { 88 return get(contentResolver, "emergency_call_timeout_millis", 25000L /* 25 seconds */); 89 } 90 91 /** 92 * Returns the amount of time to wait for an emergency call to be placed before routing to 93 * a different call service. This timeout is used only when the radio is powered off (for 94 * example in airplane mode). A value of 0 or less means no timeout should be used. 95 */ 96 public static long getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver) { 97 return get(contentResolver, "emergency_call_timeout_radio_off_millis", 98 60000L /* 1 minute */); 99 } 100 101 /** 102 * Returns the amount of delay before unbinding the in-call services after all the calls 103 * are removed. 104 */ 105 public static long getCallRemoveUnbindInCallServicesDelay(ContentResolver contentResolver) { 106 return get(contentResolver, "call_remove_unbind_in_call_services_delay", 107 2000L /* 2 seconds */); 108 } 109 110 /** 111 * Returns the amount of time for which bluetooth is considered connected after requesting 112 * connection. This compensates for the amount of time it takes for the audio route to 113 * actually change to bluetooth. 114 */ 115 public static long getBluetoothPendingTimeoutMillis(ContentResolver contentResolver) { 116 return get(contentResolver, "bluetooth_pending_timeout_millis", 5000L); 117 } 118 119 /** 120 * Returns the amount of time to wait before retrying the connectAudio call. This is 121 * necessary to account for the HeadsetStateMachine sometimes not being ready when we want to 122 * connect to bluetooth audio immediately after a device connects. 123 */ 124 public static long getRetryBluetoothConnectAudioBackoffMillis(ContentResolver contentResolver) { 125 return get(contentResolver, "retry_bluetooth_connect_audio_backoff_millis", 500L); 126 } 127 128 /** 129 * Returns the amount of time after a Logging session has been started that Telecom is set to 130 * perform a sweep to check and make sure that the session is still not incomplete (stale). 131 */ 132 public static long getStaleSessionCleanupTimeoutMillis(ContentResolver contentResolver) { 133 return get(contentResolver, "stale_session_cleanup_timeout_millis", 134 Log.DEFAULT_SESSION_TIMEOUT_MS); 135 } 136 137 /** 138 * Returns the amount of time to wait for the call screening service to allow or disallow a 139 * call. 140 */ 141 public static long getCallScreeningTimeoutMillis(ContentResolver contentResolver) { 142 return get(contentResolver, "call_screening_timeout", 5000L /* 5 seconds */); 143 } 144 145 /** 146 * Returns the amount of time to wait for the block checker to allow or disallow a call. 147 */ 148 public static long getBlockCheckTimeoutMillis(ContentResolver contentResolver) { 149 return get(contentResolver, "block_check_timeout_millis", 500L); 150 } 151 } 152