Merge "Add ringer code to actually play a ringtone." into master-nova
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ba59002..02f7efb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -29,7 +29,7 @@
     <uses-sdk android:minSdkVersion="19" />
 
     <application android:name="TelecommApp"
-            android:persistent="false"
+            android:persistent="true"
             android:label="@string/telecommAppLabel"
             android:icon="@mipmap/ic_launcher_phone"
             android:supportsRtl="true">
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 7102cf4..35d744f 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -16,9 +16,14 @@
 
 package com.android.telecomm;
 
+import android.Manifest;
+import android.content.Intent;
 import android.os.Bundle;
+import android.telecomm.CallService;
 import android.telecomm.CallServiceDescriptor;
 import android.telecomm.CallState;
+import android.telecomm.ICallService;
+import android.telephony.TelephonyManager;
 import android.util.Log;
 
 import com.google.common.base.Preconditions;
@@ -330,11 +335,60 @@
                 // unexpected transition occurs.
                 call.setState(newState);
                 // TODO(santoscordon): Notify the in-call app whenever a call changes state.
+
+                broadcastState(call);
             }
         }
     }
 
     /**
+     * Send a {@link TelephonyManager#ACTION_PHONE_STATE_CHANGED} broadcast when the call state
+     * changes. TODO: Split this out into a separate class and do it properly; this is just a first
+     * pass over the functionality.
+     *
+     * @param call The {@link Call} being updated.
+     */
+    private void broadcastState(Call call) {
+        final String callState;
+        switch (call.getState()) {
+            case DIALING:
+            case ACTIVE:
+                callState = TelephonyManager.EXTRA_STATE_OFFHOOK;
+                break;
+
+            case RINGING:
+                callState = TelephonyManager.EXTRA_STATE_RINGING;
+                break;
+
+            case DISCONNECTED:
+            case ABORTED:
+                callState = TelephonyManager.EXTRA_STATE_IDLE;
+                break;
+
+            default:
+                Log.e(TAG, "Call is in an unknown state (" + call.getState() +
+                        "), not broadcasting: " + call.getId());
+                return;
+        }
+
+        Intent updateIntent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
+        updateIntent.putExtra(TelephonyManager.EXTRA_STATE, callState);
+
+        // Populate both, since the original API was needlessly complicated.
+        updateIntent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, call.getHandle());
+        // TODO: See if we can add this (the current API only sets this on NEW_OUTGOING_CALL).
+        updateIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, call.getHandle());
+
+        // TODO: Replace these with real constants once this API has been vetted.
+        CallServiceWrapper callService = call.getCallService();
+        if (callService != null) {
+            updateIntent.putExtra(CallService.class.getName(), callService.getComponentName());
+        }
+        TelecommApp.getInstance().sendBroadcast(updateIntent, Manifest.permission.READ_PHONE_STATE);
+        Log.i(TAG, "Broadcasted state change: " + callState);
+    }
+
+    /**
      * Removes the specified call from the list of unanswered incoming calls and updates the ringer
      * based on the new state of {@link #mUnansweredIncomingCalls}. Safe to call with a call ID that
      * is not present in the list of incoming calls.
diff --git a/src/com/android/telecomm/Timeouts.java b/src/com/android/telecomm/Timeouts.java
index a69319d..05c26db 100644
--- a/src/com/android/telecomm/Timeouts.java
+++ b/src/com/android/telecomm/Timeouts.java
@@ -36,7 +36,7 @@
      *     allowed to span over.
      */
     public static long getProviderLookupMs() {
-        return get("provider_lookup_ms", 100);
+        return get("provider_lookup_ms", 1000);
     }
 
     /**
@@ -44,7 +44,7 @@
      *     allowed to span over.
      */
     public static long getSelectorLookupMs() {
-        return get("selector_lookup_ms", 100);
+        return get("selector_lookup_ms", 1000);
     }
 
     /**