Basic wiring to hook up the call activity logic with calls manager.

Change-Id: I3bbd1401b933b353578d66168ce1bdf914b6f762
diff --git a/src/com/android/telecomm/CallActivity.java b/src/com/android/telecomm/CallActivity.java
index 1d48962..54424e4 100644
--- a/src/com/android/telecomm/CallActivity.java
+++ b/src/com/android/telecomm/CallActivity.java
@@ -23,15 +23,23 @@
 import android.util.Log;
 import android.widget.Toast;
 
+import com.android.telecomm.exceptions.CallServiceUnavailableException;
+import com.android.telecomm.exceptions.RestrictedCallException;
+
 /**
  * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
  * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
  * TODO(santoscordon): Connect with CallsManager.
  */
 public class CallActivity extends Activity {
+    /** Used to identify log entries by this class. */
     private static final String TAG = CallActivity.class.getSimpleName();
+
+    /** Indicates whether or not debug-level entries should be logged. */
     private static boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
+    private CallsManager mCallsManager = CallsManager.getInstance();
+
     /**
      * {@inheritDoc}
      *
@@ -60,7 +68,7 @@
         // TODO(santoscordon): Figure out if there is something to restore from bundle.
         // See OutgoingCallBroadcaster in services/Telephony for more.
 
-        processIntent(intent);
+        processOutgoingCallIntent(intent);
 
         // TODO(santoscordon): Remove this finish() once this app does more than just show a toast.
         finish();
@@ -75,10 +83,24 @@
      *
      * @param intent Call intent containing data about the handle to call.
      */
-    private void processIntent(Intent intent) {
-        // TODO(santoscordon): Pass intent data through to CallsManager. At the moment, we just
-        // display a toast of the data.
+    private void processOutgoingCallIntent(Intent intent) {
+        // TODO(santoscordon): Remove the toast.
         String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
         Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
+
+        // TODO(gilad): Pull the scheme etc. from the data string as well as any relevant extras
+        // from the intent into structured data and invoke the corresponding CallsManager APIs
+        // based on that.  May want to add a static utility to perform that in case the logic is
+        // non-trivial/voluminous.
+        String handle = intent.getDataString();
+        ContactInfo contactInfo = null;
+        try {
+          mCallsManager.processOutgoingCallIntent(handle, contactInfo);
+        } catch (RestrictedCallException e) {
+          // TODO(gilad): Handle or explicitly state to be ignored.
+        } catch (CallServiceUnavailableException e) {
+          // TODO(gilad): Handle or explicitly state to be ignored. If both should be ignored, consider
+          // extending from the same base class and simplify the handling code to a single catch clause.
+        }
     }
 }
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 99b68bd..a5fdcf7 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -6,11 +6,22 @@
 import java.util.ArrayList;
 import java.util.List;
 
-/** Singleton */
+/**
+ * Singleton.
+ *
+ * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
+ * access from other packages specifically refraining from passing the CallsManager instance
+ * beyond the com.android.telecomm package boundary.
+ */
 public class CallsManager {
 
   private static final CallsManager INSTANCE = new CallsManager();
 
+  /**
+   * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set
+   * of CallsManager APIs that need to be exposed to the dialer (or any application firing call
+   * intents) may be empty.
+   */
   private DialerAdapter dialerAdapter;
 
   private InCallAdapter inCallAdapter;
@@ -34,12 +45,10 @@
     voicemailManager = new VoicemailManager();  // As necessary etc.
   }
 
-  /** Package private */
   static CallsManager getInstance() {
     return INSTANCE;
   }
 
-  /** Package private */
   // TODO(gilad): Circle back to how we'd want to do this.
   void addCallService(CallService callService) {
     if (callService != null) {
@@ -48,15 +57,20 @@
     }
   }
 
-  /** Package private */
-  void connectTo(String userInput, ContactInfo contactInfo)
+  /**
+   * Attempts to issue/connect the specified call.  From an (arbitrary) application standpoint,
+   * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
+   * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
+   * this method.
+   */
+  void processOutgoingCallIntent(String handle, ContactInfo contactInfo)
       throws RestrictedCallException, CallServiceUnavailableException {
 
     for (OutgoingCallFilter policy : outgoingCallFilters) {
-      policy.validate(userInput, contactInfo);
+      policy.validate(handle, contactInfo);
     }
 
     // No objection to issue the call, proceed with trying to put it through.
-    switchboard.placeOutgoingCall(userInput, contactInfo);
+    switchboard.placeOutgoingCall(handle, contactInfo);
   }
 }
diff --git a/src/com/android/telecomm/DialerAdapter.java b/src/com/android/telecomm/DialerAdapter.java
index fef3d9f..927663b 100644
--- a/src/com/android/telecomm/DialerAdapter.java
+++ b/src/com/android/telecomm/DialerAdapter.java
@@ -1,10 +1,14 @@
 package com.android.telecomm;
 
-/** Only exposes the CallsManager APIs that the Dialer should have access to. */
+/**
+ * Only exposes the CallsManager APIs that the Dialer should have access to.
+ *
+ * NOTE(gilad): may be unnecessary, see the comment in CallsManager.
+ */
+
 public class DialerAdapter {
   private CallsManager callsManager;
 
-  /** Package private */
   DialerAdapter(CallsManager callsManager) {
     this.callsManager = callsManager;
   }
diff --git a/src/com/android/telecomm/TelecommReceiver.java b/src/com/android/telecomm/TelecommReceiver.java
index 12afe16..9ed0fa7 100644
--- a/src/com/android/telecomm/TelecommReceiver.java
+++ b/src/com/android/telecomm/TelecommReceiver.java
@@ -26,6 +26,8 @@
  * Receiver for public intents relating to Telecomm.
  */
 public class TelecommReceiver extends BroadcastReceiver {
+
+    /** Used to identify log entries by this class. */
     private static final String TAG = TelecommReceiver.class.getSimpleName();
 
     /**
@@ -42,15 +44,17 @@
     /**
      * The package name of the {@link ICallServiceProvider} used to get the {@link CallService}.
      */
-    /* package */ static final String EXTRA_PACKAGE_NAME = "com.android.telecomm.PACKAGE_NAME";
+    static final String EXTRA_PACKAGE_NAME = "com.android.telecomm.PACKAGE_NAME";
 
     /**
      * The CallService ID used to identify the {@link CallService} via {@link ICallServiceProvider}.
      * IDs are only required to be unique within the scope of an {@link ICallServiceProvider}.
      */
-    /* package */ static final String EXTRA_CALL_SERVICE_ID =
+    static final String EXTRA_CALL_SERVICE_ID =
             "com.android.telecomm.CALL_SERVICE_ID";
 
+    private CallsManager mCallsManager = CallsManager.getInstance();
+
     /** {@inheritDoc} */
     @Override
     public void onReceive(Context context, Intent intent) {
@@ -62,9 +66,9 @@
 
     /**
      * Tells CallsManager to connect to the {@link #CallService} identified by the package name
-     * and call service ID in the extras of the intent parameter.
+     * and call-service ID in the extras of the intent parameter.
      *
-     * @param intent The intent containing the package name and call service ID as extras.
+     * @param intent The intent containing the package name and call-service ID as extras.
      */
     private void connectToCallService(Intent intent) {
         String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);