FP2-1177: Contact name can not display on calling screen

Resolve content URI while read the contact.

Change-Id: I74871eba7a4c2c7e1247ceaebf1f4272e1a82bd7
diff --git a/src/com/android/voicedialer/CommandRecognizerEngine.java b/src/com/android/voicedialer/CommandRecognizerEngine.java
index 91b37e1..bb35b15 100644
--- a/src/com/android/voicedialer/CommandRecognizerEngine.java
+++ b/src/com/android/voicedialer/CommandRecognizerEngine.java
@@ -26,6 +26,10 @@
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.speech.srec.Recognizer;
 import android.util.Log;
+import android.database.Cursor;
+import android.content.ContentResolver;
+import android.provider.ContactsContract.CommonDataKinds;
+import android.net.Uri;
 
 import java.io.File;
 import java.io.FileFilter;
@@ -997,6 +1001,33 @@
 
                 int count = 0;
 
+                String ContactIdString =Long.toString(contactId);
+                String homeNumber ="";
+                String mobileNumber ="";
+                String workNumber="";
+                String otherNumber="";
+
+                ContentResolver cr = mActivity.getContentResolver();
+                Cursor PhoneCur = cr.query(Phone.CONTENT_URI,
+                    null,
+                    Phone.RAW_CONTACT_ID +" =?",
+                    new String[]{ContactIdString}, null);
+                while (PhoneCur.moveToNext())
+                {
+                    String number = PhoneCur.getString(PhoneCur.getColumnIndex(Phone.NUMBER));
+                    String numberType = PhoneCur.getString(PhoneCur.getColumnIndex(Phone.TYPE));
+                    if (Integer.parseInt(numberType) == Phone.TYPE_HOME){
+                        homeNumber = number;
+                    }else if (Integer.parseInt(numberType) == Phone.TYPE_MOBILE){
+                        mobileNumber = number;
+                    }else if (Integer.parseInt(numberType) == Phone.TYPE_WORK){
+                        workNumber = number;
+                    }else {
+                        otherNumber = number;
+                    }
+                }
+                Log.d(TAG, "commands.length= " +commands.length +" contactId" +contactId );
+
                 //
                 // generate the best entry corresponding to what was said
                 //
@@ -1011,11 +1042,21 @@
                             "W".equalsIgnoreCase(spokenPhoneIdCommand) ? workId :
                             "O".equalsIgnoreCase(spokenPhoneIdCommand) ? otherId :
                              VoiceContact.ID_UNDEFINED;
-                    if (spokenPhoneId != VoiceContact.ID_UNDEFINED) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
+                    String spokenNumber =
+                            "H".equalsIgnoreCase(spokenPhoneIdCommand) ? homeNumber :
+                            "M".equalsIgnoreCase(spokenPhoneIdCommand) ? mobileNumber :
+                            "W".equalsIgnoreCase(spokenPhoneIdCommand) ? workNumber :
+                            "O".equalsIgnoreCase(spokenPhoneIdCommand) ? otherNumber :
+                            "";
+
+                       if (spokenPhoneId != VoiceContact.ID_UNDEFINED) {
+                        /*addCallIntent(intents, ContentUris.withAppendedId(
                                 Phone.CONTENT_URI, spokenPhoneId),
-                                literal, spokenPhoneIdCommand, 0);
+                                literal, spokenPhoneIdCommand, 0);*/
+                        addCallIntent(intents, Uri.parse("tel:" + spokenNumber),
+                            literal, spokenPhoneIdCommand, 0);
                         count++;
+                        Log.d(TAG, "spokenNumber");
                     }
                 }
 
@@ -1039,10 +1080,19 @@
                         phoneType = "O";
                         phoneIdMsg = res.getText(R.string.at_other);
                     }
+
+                    String spokenNumber =
+                        "H".equalsIgnoreCase(phoneType) ? homeNumber :
+                        "M".equalsIgnoreCase(phoneType) ? mobileNumber :
+                        "W".equalsIgnoreCase(phoneType) ? workNumber :
+                        "O".equalsIgnoreCase(phoneType) ? otherNumber :
+                        "";
                     if (phoneIdMsg != null) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
+                        /*addCallIntent(intents, ContentUris.withAppendedId(
                                 Phone.CONTENT_URI, primaryId),
-                                literal + phoneIdMsg, phoneType, 0);
+                                literal + phoneIdMsg, phoneType, 0);*/
+                        addCallIntent(intents,Uri.parse("tel:" + spokenNumber),
+                             literal + phoneIdMsg, phoneType, 0);
                         count++;
                     }
                 }
@@ -1068,32 +1118,28 @@
 
                     //  add 'CALL JACK JONES at home' using phoneId
                     if (homeId != VoiceContact.ID_UNDEFINED) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
-                                Phone.CONTENT_URI, homeId),
+                        addCallIntent(intents, Uri.parse("tel:" + homeNumber),
                                 lit + res.getText(R.string.at_home), "H",  0);
                         count++;
                     }
 
                     //  add 'CALL JACK JONES on mobile' using mobileId
                     if (mobileId != VoiceContact.ID_UNDEFINED) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
-                                Phone.CONTENT_URI, mobileId),
+                        addCallIntent(intents, Uri.parse("tel:" + mobileNumber),
                                 lit + res.getText(R.string.on_mobile), "M", 0);
                         count++;
                     }
 
                     //  add 'CALL JACK JONES at work' using workId
                     if (workId != VoiceContact.ID_UNDEFINED) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
-                                Phone.CONTENT_URI, workId),
+                        addCallIntent(intents, Uri.parse("tel:" + workNumber),
                                 lit + res.getText(R.string.at_work), "W", 0);
                         count++;
                     }
 
                     //  add 'CALL JACK JONES at other' using otherId
                     if (otherId != VoiceContact.ID_UNDEFINED) {
-                        addCallIntent(intents, ContentUris.withAppendedId(
-                                Phone.CONTENT_URI, otherId),
+                        addCallIntent(intents, Uri.parse("tel:" + otherNumber),
                                 lit + res.getText(R.string.at_other), "O", 0);
                         count++;
                     }