1129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal/* 2129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * Copyright (C) 2014 The Android Open Source Project 3129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * 4129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * Licensed under the Apache License, Version 2.0 (the "License"); 5129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * you may not use this file except in compliance with the License. 6129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * You may obtain a copy of the License at 7129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * 8129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * http://www.apache.org/licenses/LICENSE-2.0 9129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * 10129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * Unless required by applicable law or agreed to in writing, software 11129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * distributed under the License is distributed on an "AS IS" BASIS, 12129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * See the License for the specific language governing permissions and 14129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal * limitations under the License. 15129f1e63c578e8beb98b87d8cd3a77cb2273dc88Sailesh Nepal */ 161063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpackage com.android.server.telecom; 181063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 1991d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunnimport android.content.ContentResolver; 201063e2854a5904e8628894e0b5f32d46087c4639Evan Charltonimport android.provider.Settings; 2121fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooleyimport java.util.concurrent.TimeUnit; 221063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 231063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton/** 241063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * A helper class which serves only to make it easier to lookup timeout values. This class should 251063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * never be instantiated, and only accessed through the {@link #get(String, long)} method. 261063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * 271063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * These methods are safe to call from any thread, including the UI thread. 281063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton */ 291063e2854a5904e8628894e0b5f32d46087c4639Evan Charltonpublic final class Timeouts { 306d4b66df3d918e3f17263ff40ca3ba0ec5a46719Hall Liu public static class Adapter { 319ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu public Adapter() { } 329ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu 339ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu public long getCallScreeningTimeoutMillis(ContentResolver cr) { 349ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu return Timeouts.getCallScreeningTimeoutMillis(cr); 359ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu } 3628b82f0fe9b55b3bd826ba3a4204329988447c57Hall Liu 3728b82f0fe9b55b3bd826ba3a4204329988447c57Hall Liu public long getCallRemoveUnbindInCallServicesDelay(ContentResolver cr) { 3828b82f0fe9b55b3bd826ba3a4204329988447c57Hall Liu return Timeouts.getCallRemoveUnbindInCallServicesDelay(cr); 3928b82f0fe9b55b3bd826ba3a4204329988447c57Hall Liu } 4020019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu 4120019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu public long getRetryBluetoothConnectAudioBackoffMillis(ContentResolver cr) { 4220019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu return Timeouts.getRetryBluetoothConnectAudioBackoffMillis(cr); 4320019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu } 4420019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu 4520019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu public long getBluetoothPendingTimeoutMillis(ContentResolver cr) { 4620019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu return Timeouts.getBluetoothPendingTimeoutMillis(cr); 4720019b6a091cab9a5d5caae8f56f3aa7f26a8178Hall Liu } 4821fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley 4921fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley public long getEmergencyCallbackWindowMillis(ContentResolver cr) { 5021fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley return Timeouts.getEmergencyCallbackWindowMillis(cr); 5121fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley } 529ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu } 539ecbb1cbae4dbb62a892c1347d8cb8691550ad1bHall Liu 541063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton /** A prefix to use for all keys so to not clobber the global namespace. */ 557cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn private static final String PREFIX = "telecom."; 561063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 571063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton private Timeouts() {} 581063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 591063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton /** 601063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * Returns the timeout value from Settings or the default value if it hasn't been changed. This 611063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * method is safe to call from any thread, including the UI thread. 621063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * 6391d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunn * @param contentResolver The content resolved. 641063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * @param key Settings key to retrieve. 651063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * @param defaultValue Default value, in milliseconds. 661063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton * @return The timeout value from Settings or the default value if it hasn't been changed. 671063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton */ 6891d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunn private static long get(ContentResolver contentResolver, String key, long defaultValue) { 6991d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunn return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue); 701063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton } 711063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton 721063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton /** 73cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon * Returns the amount of time to wait before disconnecting a call that was canceled via 74cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon * NEW_OUTGOING_CALL broadcast. This timeout allows apps which repost the call using a gateway 75cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon * to reuse the existing call, preventing the call from causing a start->end->start jank in the 76cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon * in-call UI. 77cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon */ 78cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon public static long getNewOutgoingCallCancelMillis(ContentResolver contentResolver) { 7963e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu return get(contentResolver, "new_outgoing_call_cancel_ms", 500L); 8063e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu } 8163e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu 8263e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu /** 8363e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu * Returns the maximum amount of time to wait before disconnecting a call that was canceled via 8463e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu * NEW_OUTGOING_CALL broadcast. This prevents malicious or poorly configured apps from 8563e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu * forever tying up the Telecom stack. 8663e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu */ 8763e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu public static long getMaxNewOutgoingCallCancelMillis(ContentResolver contentResolver) { 8863e690cba4c50577c6dcfc98ca1d7e5f1b1fc3c4Hall Liu return get(contentResolver, "max_new_outgoing_call_cancel_ms", 10000L); 89cf5b2918ca58b155911a66222ae5b4d21cb5b8ecSantos Cordon } 90a469f76c1710a945933910840f11f9fda0445d82Nancy Chen 91a469f76c1710a945933910840f11f9fda0445d82Nancy Chen /** 92a469f76c1710a945933910840f11f9fda0445d82Nancy Chen * Returns the amount of time to play each DTMF tone after post dial continue. 93a469f76c1710a945933910840f11f9fda0445d82Nancy Chen * This timeout allows the current tone to play for a certain amount of time before either being 94a469f76c1710a945933910840f11f9fda0445d82Nancy Chen * interrupted by the next tone or terminated. 95a469f76c1710a945933910840f11f9fda0445d82Nancy Chen */ 96a469f76c1710a945933910840f11f9fda0445d82Nancy Chen public static long getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver) { 97a469f76c1710a945933910840f11f9fda0445d82Nancy Chen return get(contentResolver, "delay_between_dtmf_tones_ms", 300L); 98a469f76c1710a945933910840f11f9fda0445d82Nancy Chen } 99a469f76c1710a945933910840f11f9fda0445d82Nancy Chen 100646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal /** 101646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal * Returns the amount of time to wait for an emergency call to be placed before routing to 102646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal * a different call service. A value of 0 or less means no timeout should be used. 103646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal */ 104646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal public static long getEmergencyCallTimeoutMillis(ContentResolver contentResolver) { 105646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal return get(contentResolver, "emergency_call_timeout_millis", 25000L /* 25 seconds */); 106646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal } 107646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal 108646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal /** 109646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal * Returns the amount of time to wait for an emergency call to be placed before routing to 110646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal * a different call service. This timeout is used only when the radio is powered off (for 111646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal * example in airplane mode). A value of 0 or less means no timeout should be used. 112646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal */ 113646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal public static long getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver) { 114646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal return get(contentResolver, "emergency_call_timeout_radio_off_millis", 115646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal 60000L /* 1 minute */); 116646fa3d6eaea71fb4c3270fde1a30eeb7c5e4288Sailesh Nepal } 1174995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius 1184995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius /** 1194995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius * Returns the amount of delay before unbinding the in-call services after all the calls 1204995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius * are removed. 1214995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius */ 1224995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius public static long getCallRemoveUnbindInCallServicesDelay(ContentResolver contentResolver) { 1234995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius return get(contentResolver, "call_remove_unbind_in_call_services_delay", 1244995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius 2000L /* 2 seconds */); 1254995e781ab0842212ef7d78cffa94bf5dcedb47eRoshan Pius } 12620ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu 12720ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu /** 12820ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu * Returns the amount of time for which bluetooth is considered connected after requesting 12920ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu * connection. This compensates for the amount of time it takes for the audio route to 13020ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu * actually change to bluetooth. 13120ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu */ 13220ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu public static long getBluetoothPendingTimeoutMillis(ContentResolver contentResolver) { 13320ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu return get(contentResolver, "bluetooth_pending_timeout_millis", 5000L); 13420ba29108f4003938c0594e4c3a82bcf7c62cc5fHall Liu } 135c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu 136c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu /** 137c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu * Returns the amount of time to wait before retrying the connectAudio call. This is 138c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu * necessary to account for the HeadsetStateMachine sometimes not being ready when we want to 139c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu * connect to bluetooth audio immediately after a device connects. 140c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu */ 141c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu public static long getRetryBluetoothConnectAudioBackoffMillis(ContentResolver contentResolver) { 142c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu return get(contentResolver, "retry_bluetooth_connect_audio_backoff_millis", 500L); 143c4e71f87351641a1f02d6c0d966bead1d8f851c4Hall Liu } 14411623a354be47205bf3bc686ed8fdfc278958983Brad Ebinger 14511623a354be47205bf3bc686ed8fdfc278958983Brad Ebinger /** 146ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal * Returns the amount of time to wait for the call screening service to allow or disallow a 147ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal * call. 148ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal */ 149ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal public static long getCallScreeningTimeoutMillis(ContentResolver contentResolver) { 150ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal return get(contentResolver, "call_screening_timeout", 5000L /* 5 seconds */); 151ae92595c2f0f88a5bef8d2601f026b9d3ae2d7ddSailesh Nepal } 15221fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley 15321fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley /** 15421fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley * Returns the amount of time after an emergency call that incoming calls should be treated 15521fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley * as potential emergency callbacks. 15621fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley */ 15721fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley public static long getEmergencyCallbackWindowMillis(ContentResolver contentResolver) { 15821fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley return get(contentResolver, "emergency_callback_window_millis", 15921fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)); 16021fb1afe2e6ba030581ae8c94e377adf7c62877dmike dooley } 1611063e2854a5904e8628894e0b5f32d46087c4639Evan Charlton} 162