Timeouts.java revision 8cb83ea9b12793863638a1834278d4957e51bedd
131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/*
231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Copyright (C) 2014 The Android Open Source Project
331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * you may not use this file except in compliance with the License.
631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * You may obtain a copy of the License at
731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
1031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * See the License for the specific language governing permissions and
1431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * limitations under the License.
1531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */
1631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
17325dc23624160689e59fbac708cf6f222b20d025Daniel Sandlerpackage com.android.server.telecom;
1831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
19df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.content.ContentResolver;
20df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.provider.Settings;
21c4fe9ea11e82fe16d60525323464fd50cf391378Adam Cohen
22df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen/**
23df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen * A helper class which serves only to make it easier to lookup timeout values. This class should
247066003b2032a49ae5e59dab9b706259bdeb7e6eSunny Goyal * never be instantiated, and only accessed through the {@link #get(String, long)} method.
25c46bfef5dfd8c6867641bdc32c27b03e2f183726Sunny Goyal *
2631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * These methods are safe to call from any thread, including the UI thread.
2776fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen */
28b745afbdd75157c73d581b345118cdaff99e912dWinson Chungpublic final class Timeouts {
29043f2af567178b82b0b41f12d379e7dd12da2936Winson Chung    /** A prefix to use for all keys so to not clobber the global namespace. */
30fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guy    private static final String PREFIX = "telecom.";
31c46bfef5dfd8c6867641bdc32c27b03e2f183726Sunny Goyal
328f1eff7b6cc8621888ee46605c32e601f80a890bWinson Chung    private Timeouts() {}
337a14d0bddea652ddca855af0c413e47a6c1360b2Adam Cohen
34e601a43345224e3e386abc68bbea8b08b2df9570Adam Cohen    /**
35e601a43345224e3e386abc68bbea8b08b2df9570Adam Cohen     * Returns the timeout value from Settings or the default value if it hasn't been changed. This
3631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * method is safe to call from any thread, including the UI thread.
373bf84d3250bf45f2a5b041245e9bd327e03e22c0Adam Cohen     *
3876fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * @param contentResolver The content resolved.
3976fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * @param key Settings key to retrieve.
4076fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * @param defaultValue Default value, in milliseconds.
4176fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * @return The timeout value from Settings or the default value if it hasn't been changed.
420c872ba544ecfd9b106bb66137da8680927590deAdam Cohen     */
4331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    private static long get(ContentResolver contentResolver, String key, long defaultValue) {
44c4918358049914a4700bc8f2eb91167eb4a67becSunny Goyal        return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue);
453371da0159cc54ff8ae1b1b26effb96445f208d5Adam Cohen    }
463371da0159cc54ff8ae1b1b26effb96445f208d5Adam Cohen
47c4fe9ea11e82fe16d60525323464fd50cf391378Adam Cohen    /**
48c1cd23b4a7744105c124c4d9f642134b5f49694fSunny Goyal     * Returns the longest period, in milliseconds, to wait for the query for direct-to-voicemail
4976fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * to complete. If the query goes beyond this timeout, the incoming call screen is shown to the
5076fc085d28178a5d4fb3787ede956281a2cc3179Adam Cohen     * user.
5131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
52df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public static long getDirectToVoicemailMillis(ContentResolver contentResolver) {
5383a8f042adda926489494dff217c15ab696139b4Sunny Goyal        return get(contentResolver, "direct_to_voicemail_ms", 500L);
54e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal    }
55f406615354a92367481a60966b6b873cae37fe4cSunny Goyal
56325dc23624160689e59fbac708cf6f222b20d025Daniel Sandler    /**
57fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal     * Returns the amount of time to wait before disconnecting a call that was canceled via
58bc753359f8b08e0813016eebc8392b83a4d2bd6eSunny Goyal     * NEW_OUTGOING_CALL broadcast. This timeout allows apps which repost the call using a gateway
5983a8f042adda926489494dff217c15ab696139b4Sunny Goyal     * to reuse the existing call, preventing the call from causing a start->end->start jank in the
60091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen     * in-call UI.
6183a8f042adda926489494dff217c15ab696139b4Sunny Goyal     */
62c0dcf597084d00e4c23a7fea5fd0738f6c095a6bAdam Cohen    public static long getNewOutgoingCallCancelMillis(ContentResolver contentResolver) {
633bf84d3250bf45f2a5b041245e9bd327e03e22c0Adam Cohen        return get(contentResolver, "new_outgoing_call_cancel_ms", 400L);
64c0dcf597084d00e4c23a7fea5fd0738f6c095a6bAdam Cohen    }
6531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
6631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
6731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * Returns the amount of time to play each DTMF tone after post dial continue.
688dfcba4af7a7ece09e8c7d96053e54f3a383e905Adam Cohen     * This timeout allows the current tone to play for a certain amount of time before either being
69ea0818d475df26d498ce08105bc2bc5582fce5a9Adam Cohen     * interrupted by the next tone or terminated.
708f1eff7b6cc8621888ee46605c32e601f80a890bWinson Chung     */
718f1eff7b6cc8621888ee46605c32e601f80a890bWinson Chung    public static long getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver) {
724eac29a80b9a73465c8de54f1caec2a8098a73c6Adam Cohen        return get(contentResolver, "delay_between_dtmf_tones_ms", 300L);
73df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
74c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal
75c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    /**
76c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * Returns the amount of time to wait for an emergency call to be placed before routing to
77c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * a different call service. A value of 0 or less means no timeout should be used.
78c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     */
7931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public static long getEmergencyCallTimeoutMillis(ContentResolver contentResolver) {
80df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        return get(contentResolver, "emergency_call_timeout_millis", 25000L /* 25 seconds */);
81df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
82df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
83df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    /**
84df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * Returns the amount of time to wait for an emergency call to be placed before routing to
854846193300245c8c0a1f9bde3175f273df044309Sunny Goyal     * a different call service. This timeout is used only when the radio is powered off (for
864846193300245c8c0a1f9bde3175f273df044309Sunny Goyal     * example in airplane mode). A value of 0 or less means no timeout should be used.
874846193300245c8c0a1f9bde3175f273df044309Sunny Goyal     */
884846193300245c8c0a1f9bde3175f273df044309Sunny Goyal    public static long getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver) {
894846193300245c8c0a1f9bde3175f273df044309Sunny Goyal        return get(contentResolver, "emergency_call_timeout_radio_off_millis",
904846193300245c8c0a1f9bde3175f273df044309Sunny Goyal                60000L /* 1 minute */);
914846193300245c8c0a1f9bde3175f273df044309Sunny Goyal    }
924846193300245c8c0a1f9bde3175f273df044309Sunny Goyal
934846193300245c8c0a1f9bde3175f273df044309Sunny Goyal    /**
944846193300245c8c0a1f9bde3175f273df044309Sunny Goyal     * Returns the amount of delay before unbinding the in-call services after all the calls
95a07c2f5c80908e8a612f4681314a7068b92baa9fSunny Goyal     * are removed.
96b7e15adc7b67cb1d70ca72014b200dd6cbbf166aSunny Goyal     */
97f0f4eda31841f41d892bf18847c1acdc45d2cd64Adam Cohen    public static long getCallRemoveUnbindInCallServicesDelay(ContentResolver contentResolver) {
985d518fa77c56a65104f02f40269ad8e43f3431b2Adam Cohen        return get(contentResolver, "call_remove_unbind_in_call_services_delay",
99c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal                2000L /* 2 seconds */);
100c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    }
101c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal
102c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    /**
103c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * Returns the amount of time for which bluetooth is considered connected after requesting
104c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * connection. This compensates for the amount of time it takes for the audio route to
105c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * actually change to bluetooth.
106b863415c17aaaf6012647df5ed14803f89f94bcbSunny Goyal     */
107b863415c17aaaf6012647df5ed14803f89f94bcbSunny Goyal    public static long getBluetoothPendingTimeoutMillis(ContentResolver contentResolver) {
108c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal        return get(contentResolver, "bluetooth_pending_timeout_millis", 5000L);
109091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen    }
110c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal
111c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    /**
112c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * Returns the amount of time after a Logging session has been started that Telecom is set to
113c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * perform a sweep to check and make sure that the session is still not incomplete (stale).
114c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     */
115c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    public static long getStaleSessionCleanupTimeoutMillis(ContentResolver contentResolver) {
116c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal        return get(contentResolver, "stale_session_cleanup_timeout_millis",
117c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal                Log.DEFAULT_SESSION_TIMEOUT_MS);
118c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    }
119c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal
120c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    /**
121091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen     * Returns the amount of time to wait for the call screening service to allow or disallow a
122c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * call.
123b863415c17aaaf6012647df5ed14803f89f94bcbSunny Goyal     */
124091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen    public static long getCallScreeningTimeoutMillis(ContentResolver contentResolver) {
125c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal        return get(contentResolver, "call_screening_timeout", 5000L /* 5 seconds */);
126c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal    }
127290800b5b7d575fd709f244f54a5fa5b63b58876Sunny Goyal
128290800b5b7d575fd709f244f54a5fa5b63b58876Sunny Goyal    /**
129c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     * Returns the amount of time to wait for the block checker to allow or disallow a call.
130c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal     */
131091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen    public static long getBlockCheckTimeoutMillis(ContentResolver contentResolver) {
132c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal        return get(contentResolver, "block_check_timeout_millis", 500L);
133091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen    }
134c3a609f950a713d995f1968574d8ed7b4449f415Sunny Goyal}
1357c6932140dcbd2db88d7a809ba72ee04abb5bf26Adam Cohen