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     /** A prefix to use for all keys so to not clobber the global namespace. */
30     private static final String PREFIX = "telecom.";
31 
Timeouts()32     private Timeouts() {}
33 
34     /**
35      * Returns the timeout value from Settings or the default value if it hasn't been changed. This
36      * method is safe to call from any thread, including the UI thread.
37      *
38      * @param contentResolver The content resolved.
39      * @param key Settings key to retrieve.
40      * @param defaultValue Default value, in milliseconds.
41      * @return The timeout value from Settings or the default value if it hasn't been changed.
42      */
get(ContentResolver contentResolver, String key, long defaultValue)43     private static long get(ContentResolver contentResolver, String key, long defaultValue) {
44         return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue);
45     }
46 
47     /**
48      * Returns the longest period, in milliseconds, to wait for the query for direct-to-voicemail
49      * to complete. If the query goes beyond this timeout, the incoming call screen is shown to the
50      * user.
51      */
getDirectToVoicemailMillis(ContentResolver contentResolver)52     public static long getDirectToVoicemailMillis(ContentResolver contentResolver) {
53         return get(contentResolver, "direct_to_voicemail_ms", 500L);
54     }
55 
56     /**
57      * Returns the amount of time to wait before disconnecting a call that was canceled via
58      * NEW_OUTGOING_CALL broadcast. This timeout allows apps which repost the call using a gateway
59      * to reuse the existing call, preventing the call from causing a start->end->start jank in the
60      * in-call UI.
61      */
getNewOutgoingCallCancelMillis(ContentResolver contentResolver)62     public static long getNewOutgoingCallCancelMillis(ContentResolver contentResolver) {
63         return get(contentResolver, "new_outgoing_call_cancel_ms", 300L);
64     }
65 
66     /**
67      * Returns the amount of time to play each DTMF tone after post dial continue.
68      * This timeout allows the current tone to play for a certain amount of time before either being
69      * interrupted by the next tone or terminated.
70      */
getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver)71     public static long getDelayBetweenDtmfTonesMillis(ContentResolver contentResolver) {
72         return get(contentResolver, "delay_between_dtmf_tones_ms", 300L);
73     }
74 
75     /**
76      * Returns the amount of time to wait for an emergency call to be placed before routing to
77      * a different call service. A value of 0 or less means no timeout should be used.
78      */
getEmergencyCallTimeoutMillis(ContentResolver contentResolver)79     public static long getEmergencyCallTimeoutMillis(ContentResolver contentResolver) {
80         return get(contentResolver, "emergency_call_timeout_millis", 25000L /* 25 seconds */);
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. This timeout is used only when the radio is powered off (for
86      * example in airplane mode). A value of 0 or less means no timeout should be used.
87      */
getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver)88     public static long getEmergencyCallTimeoutRadioOffMillis(ContentResolver contentResolver) {
89         return get(contentResolver, "emergency_call_timeout_radio_off_millis",
90                 60000L /* 1 minute */);
91     }
92 }
93