Merge "Fixing NPE in contact photo loader" into froyo
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 94fedf1..1e9b525 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -318,7 +318,7 @@
             <intent-filter>
                 <action android:name="android.intent.action.CREATE_SHORTCUT" />
                 <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.CAR_DOCK" />
+                <category android:name="android.intent.category.CAR_MODE" />
             </intent-filter>
 
         </activity-alias>
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 6fd03f7..aeb4014 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -452,6 +452,7 @@
     private boolean mShowNumberOfContacts;
 
     private boolean mShowSearchSnippets;
+    private boolean mSearchInitiated;
 
     private String mInitialFilter;
 
@@ -1058,6 +1059,7 @@
             startQuery();
         }
         mJustCreated = false;
+        mSearchInitiated = false;
     }
 
     /**
@@ -1651,9 +1653,10 @@
      * bringing up the search UI first.
      */
     public boolean onKey(View v, int keyCode, KeyEvent event) {
-        if (!mSearchMode && (mMode & MODE_MASK_NO_FILTER) == 0) {
+        if (!mSearchMode && (mMode & MODE_MASK_NO_FILTER) == 0 && !mSearchInitiated) {
             int unicodeChar = event.getUnicodeChar();
             if (unicodeChar != 0) {
+                mSearchInitiated = true;
                 startSearch(new String(new int[]{unicodeChar}, 0, 1), false, null, false);
                 return true;
             }
diff --git a/src/com/android/contacts/model/GoogleSource.java b/src/com/android/contacts/model/GoogleSource.java
index 274d65a..90abc92 100644
--- a/src/com/android/contacts/model/GoogleSource.java
+++ b/src/com/android/contacts/model/GoogleSource.java
@@ -42,6 +42,10 @@
 
 public class GoogleSource extends FallbackSource {
     public static final String ACCOUNT_TYPE = "com.google";
+
+    private static final String SELECTION_GROUPS_BY_TITLE_AND_ACCOUNT =
+            Groups.TITLE + "=? AND " + Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=?";
+
     public GoogleSource(String resPackageName) {
         this.accountType = ACCOUNT_TYPE;
         this.resPackageName = null;
@@ -156,7 +160,7 @@
     // TODO: this should come from resource in the future
     // Note that frameworks/base/core/java/android/pim/vcard/VCardEntry.java also wants
     // this String.
-    private static final String GOOGLE_MY_CONTACTS_GROUP = "My Contacts";
+    private static final String GOOGLE_MY_CONTACTS_GROUP = "System Group: My Contacts";
 
     public static final void attemptMyContactsMembership(EntityDelta state, Context context) {
         final ValuesDelta stateValues = state.getValues();
@@ -223,11 +227,10 @@
 
                 operations.add(ContentProviderOperation
                         .newAssertQuery(Groups.CONTENT_URI)
-                        .withSelection(Groups.TITLE + "=?",
-                                new String[] { GOOGLE_MY_CONTACTS_GROUP })
+                        .withSelection(SELECTION_GROUPS_BY_TITLE_AND_ACCOUNT,
+                                new String[] {GOOGLE_MY_CONTACTS_GROUP, accountName, accountType})
                         .withExpectedCount(0).build());
                 operations.add(ContentProviderOperation
-
                         .newInsert(Groups.CONTENT_URI)
                         .withValues(newGroup)
                         .build());
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 593d6cc..7af1a54 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -31,6 +31,11 @@
         android:targetPackage="com.android.contacts"
         android:label="Contacts launch performance">
     </instrumentation>
-    
+
+
+    <instrumentation android:name="com.android.contacts.DialerLaunchPerformance"
+        android:targetPackage="com.android.contacts"
+        android:label="Dialer launch performance">
+    </instrumentation>
 
 </manifest> 
diff --git a/tests/src/com/android/contacts/ContactsLaunchPerformance.java b/tests/src/com/android/contacts/ContactsLaunchPerformance.java
index bd60e70..9177457 100644
--- a/tests/src/com/android/contacts/ContactsLaunchPerformance.java
+++ b/tests/src/com/android/contacts/ContactsLaunchPerformance.java
@@ -17,25 +17,22 @@
 package com.android.contacts;
 
 import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
 import android.test.LaunchPerformanceBase;
 import android.os.Bundle;
 
-import java.util.Map;
-
 /**
  * Instrumentation class for Address Book launch performance testing.
  */
 public class ContactsLaunchPerformance extends LaunchPerformanceBase {
 
-    public static final String LOG_TAG = "ContactsLaunchPerformance";
-
-    public ContactsLaunchPerformance() {
-        super();
-    }
-
     @Override
     public void onCreate(Bundle arguments) {
-        mIntent.setClassName(getTargetContext(), "com.android.contacts.ContactsListActivity");
+        mIntent.setAction(Intent.ACTION_MAIN);
+        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+        mIntent.setComponent(new ComponentName("com.android.contacts",
+                "com.android.contacts.DialtactsContactsEntryActivity"));
 
         start();
     }
diff --git a/tests/src/com/android/contacts/DialerLaunchPerformance.java b/tests/src/com/android/contacts/DialerLaunchPerformance.java
new file mode 100644
index 0000000..ae78082
--- /dev/null
+++ b/tests/src/com/android/contacts/DialerLaunchPerformance.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+import android.test.LaunchPerformanceBase;
+
+/**
+ * Instrumentation class for Address Book launch performance testing.
+ */
+public class DialerLaunchPerformance extends LaunchPerformanceBase {
+
+    @Override
+    public void onCreate(Bundle arguments) {
+        mIntent.setAction(Intent.ACTION_MAIN);
+        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+        mIntent.setComponent(new ComponentName("com.android.contacts",
+                "com.android.contacts.DialtactsActivity"));
+
+        start();
+    }
+
+    /**
+     * Calls LaunchApp and finish.
+     */
+    @Override
+    public void onStart() {
+        super.onStart();
+        LaunchApp();
+        finish(Activity.RESULT_OK, mResults);
+    }
+}