• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.internal.telephony.d2d;
18 
19 import android.content.ContentResolver;
20 import android.provider.Settings;
21 
22 /**
23  * Timeouts and configuration parameters related to the device-to-device communication code.
24  */
25 public final class Timeouts {
26 
27     public static class Adapter {
28         private final ContentResolver mContentResolver;
29 
Adapter(ContentResolver cr)30         public Adapter(ContentResolver cr) {
31             mContentResolver = cr;
32         }
33 
getRtpMessageAckDurationMillis()34         public long getRtpMessageAckDurationMillis()  {
35             return Timeouts.getRtpMessageAckDurationMillis(mContentResolver);
36         }
37 
38         /**
39          * The minimum interval between DTMF digits.
40          * @return minimum interval in millis.
41          */
getDtmfMinimumIntervalMillis()42         public long getDtmfMinimumIntervalMillis() {
43             return Timeouts.getDtmfMinimumIntervalMillis(mContentResolver);
44         }
45 
getMaxDurationOfDtmfMessageMillis()46         public long getMaxDurationOfDtmfMessageMillis() {
47             return Timeouts.getMaxDurationOfDtmfMessageMillis(mContentResolver);
48         }
49 
getDtmfDurationFuzzMillis()50         public long getDtmfDurationFuzzMillis() {
51             return Timeouts.getDtmfDurationFuzzMillis(mContentResolver);
52         }
53 
getDtmfNegotiationTimeoutMillis()54         public long getDtmfNegotiationTimeoutMillis() {
55             return Timeouts.getDtmfNegotiationTimeoutMillis(mContentResolver);
56         }
57     }
58 
59     /** A prefix to use for all keys so to not clobber the global namespace. */
60     private static final String PREFIX = "telephony.d2d.";
61 
62     /**
63      * Returns the timeout value from Settings or the default value if it hasn't been changed. This
64      * method is safe to call from any thread, including the UI thread.
65      *
66      * @param contentResolver The content resolved.
67      * @param key             Settings key to retrieve.
68      * @param defaultValue    Default value, in milliseconds.
69      * @return The timeout value from Settings or the default value if it hasn't been changed.
70      */
get(ContentResolver contentResolver, String key, long defaultValue)71     private static long get(ContentResolver contentResolver, String key, long defaultValue) {
72         return Settings.Secure.getLong(contentResolver, PREFIX + key, defaultValue);
73     }
74 
75     /**
76      * Determines the length of time to wait for acknowledgement of an RTP header extension before
77      * retrying a message send.
78      * @param cr
79      * @return
80      */
getRtpMessageAckDurationMillis(ContentResolver cr)81     public static long getRtpMessageAckDurationMillis(ContentResolver cr) {
82         return get(cr, "rtp_message_ack_duration_millis", 1000L);
83     }
84 
85     /**
86      * Determines the minimum duration between DTMF digits.  Digits are sent with this much spacing
87      * between them.
88      * @param cr
89      * @return
90      */
getDtmfMinimumIntervalMillis(ContentResolver cr)91     public static long getDtmfMinimumIntervalMillis(ContentResolver cr) {
92         return get(cr, "dtmf_minimum_interval_millis", 100L);
93     }
94 
95     /**
96      * Determines the maximum amount of time to wait for a single DTMF sequence.
97      * @param cr
98      * @return
99      */
getMaxDurationOfDtmfMessageMillis(ContentResolver cr)100     public static long getMaxDurationOfDtmfMessageMillis(ContentResolver cr) {
101         return get(cr, "dtmf_max_message_duration_millis", 1000L);
102     }
103 
104     /**
105      * Determines the maximum amount of time to wait for negotiation of the DTMF protocol.
106      * @param cr
107      * @return
108      */
getDtmfNegotiationTimeoutMillis(ContentResolver cr)109     public static long getDtmfNegotiationTimeoutMillis(ContentResolver cr) {
110         return get(cr, "dtmf_negotiation_timeout_millis", 3000L);
111     }
112 
113     /**
114      * A random amount of time up to this amount will be added to
115      * {@link #getMaxDurationOfDtmfMessageMillis(ContentResolver)} when determining how long to
116      * wait before sending a DTMF message.  This fuzz factor is used to account for timing
117      * discrepancies between devices.
118      * @param cr
119      * @return
120      */
getDtmfDurationFuzzMillis(ContentResolver cr)121     public static long getDtmfDurationFuzzMillis(ContentResolver cr) {
122         return get(cr, "dtmf_duration_fuzz_millis", 10L);
123     }
124 
125 }
126