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