Allow timeouts to be configurable
Read the various timeouts from Settings so that they can be configured
and tuned at runtime (instead of baking them into the source code).
Bug: 13329970
Change-Id: I0113d171b5f5098305dff89e86eee8ad11939c27
diff --git a/src/com/android/telecomm/Timeouts.java b/src/com/android/telecomm/Timeouts.java
new file mode 100644
index 0000000..a69319d
--- /dev/null
+++ b/src/com/android/telecomm/Timeouts.java
@@ -0,0 +1,67 @@
+// Copyright 2014 Google Inc. All Rights Reserved.
+
+package com.android.telecomm;
+
+import android.provider.Settings;
+import android.telecomm.CallServiceProvider;
+import android.telecomm.CallServiceSelector;
+
+/**
+ * A helper class which serves only to make it easier to lookup timeout values. This class should
+ * never be instantiated, and only accessed through the {@link #get(String, long)} method.
+ *
+ * These methods are safe to call from any thread, including the UI thread.
+ */
+public final class Timeouts {
+ /** A prefix to use for all keys so to not clobber the global namespace. */
+ private static final String PREFIX = "telecomm.";
+
+ private Timeouts() {}
+
+ /**
+ * Returns the timeout value from Settings or the default value if it hasn't been changed. This
+ * method is safe to call from any thread, including the UI thread.
+ *
+ * @param key Settings key to retrieve.
+ * @param defaultValue Default value, in milliseconds.
+ * @return The timeout value from Settings or the default value if it hasn't been changed.
+ */
+ private static long get(String key, long defaultValue) {
+ return Settings.Secure.getLong(
+ TelecommApp.getInstance().getContentResolver(), PREFIX + key, defaultValue);
+ }
+
+ /**
+ * @return The longest period in milliseconds each {@link CallServiceProvider} lookup cycle is
+ * allowed to span over.
+ */
+ public static long getProviderLookupMs() {
+ return get("provider_lookup_ms", 100);
+ }
+
+ /**
+ * @return The longest period in milliseconds each {@link CallServiceSelector} lookup cycle is
+ * allowed to span over.
+ */
+ public static long getSelectorLookupMs() {
+ return get("selector_lookup_ms", 100);
+ }
+
+ /**
+ * @return How frequently, in milliseconds, to run {@link Switchboard}'s clean-up "tick" cycle.
+ */
+ public static long getTickMs() {
+ return get("tick_ms", 250);
+ }
+
+ /**
+ * Returns the longest period, in milliseconds, each new outgoing call is allowed to wait before
+ * being established. If the call does not connect before this time, abort the call.
+ *
+ * @return The longest period, in milliseconds, each new call is allowed to wait before being
+ * established.
+ */
+ public static long getNewOutgoingCallMs() {
+ return get("new_outgoing_call_ms", 5000);
+ }
+}