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