Revert "sendbug improvements on email address handling"

This reverts commit 9ebc639a313d143ade1293cb5932b446d5e623d5.
diff --git a/bugmailer/src/com/android/commands/sendbug/SendBug.java b/bugmailer/src/com/android/commands/sendbug/SendBug.java
index 1b8d669..da8788e 100644
--- a/bugmailer/src/com/android/commands/sendbug/SendBug.java
+++ b/bugmailer/src/com/android/commands/sendbug/SendBug.java
@@ -27,18 +27,15 @@
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.SystemProperties;
-import android.util.Log;
 
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.regex.Pattern;
 
 public class SendBug {
 
-    private static final String LOG_TAG = SendBug.class.getSimpleName();
-    private static final Pattern EMAIL_REGEX = Pattern.compile(
-            "^[\\w.%+-]+@[\\w.-]+\\.[a-zA-Z]{2,}$");
+    private static final String GOOGLE_ACCOUNT_TYPE = "com.google";
+    private static final String EMAIL_ACCOUNT_TYPE = "com.android.email";
     private static final String SEND_BUG_INTENT_ACTION = "android.testing.SEND_BUG";
 
     public static void main(String[] args) {
@@ -72,17 +69,12 @@
                         ? Uri.fromFile(screenShot) : null;
                 intent = getSendMailIntent(bugreportUri, screenshotUri);
             }
-            if (intent != null) {
-                final IActivityManager mAm = ActivityManagerNative.getDefault();
-                try {
-                    mAm.startActivity(null, intent, intent.getType(), null, null, 0, 0,
-                            null, null, null);
-                } catch (RemoteException e) {
-                    // ignore
-                }
-            } else {
-                Log.w(LOG_TAG, "Cannot find account to send bugreport, local path: "
-                        + bugreportPath);
+            final IActivityManager mAm = ActivityManagerNative.getDefault();
+            try {
+                mAm.startActivity(null, intent, intent.getType(), null, null, 0, 0,
+                        null, null, null);
+            } catch (RemoteException e) {
+                // ignore
             }
         }
     }
@@ -117,11 +109,11 @@
         final Intent intent = new Intent(Intent.ACTION_SEND);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.setType("application/octet-stream");
-        intent.putExtra(Intent.EXTRA_SUBJECT, bugreportUri.getLastPathSegment());
+        intent.putExtra("subject", bugreportUri.getLastPathSegment());
         final StringBuilder sb = new StringBuilder();
         sb.append(SystemProperties.get("ro.build.description"));
         sb.append("\n(Sent from BugMailer)");
-        intent.putExtra(Intent.EXTRA_TEXT, (CharSequence)sb);
+        intent.putExtra("body", sb.toString());
         if (screenshotUri != null) {
             final ArrayList<Uri> attachments = new ArrayList<Uri>();
             attachments.add(bugreportUri);
@@ -132,10 +124,9 @@
             intent.putExtra(Intent.EXTRA_STREAM, bugreportUri);
         }
         if (sendToAccount != null) {
-            intent.putExtra(Intent.EXTRA_EMAIL, new String[]{sendToAccount.name});
-            return intent;
+            intent.putExtra("to", sendToAccount.name);
         }
-        return null;
+        return intent;
     }
 
     private Account findSendToAccount() {
@@ -143,10 +134,6 @@
                 .getService(Context.ACCOUNT_SERVICE));
         Account[] accounts = null;
         Account foundAccount = null;
-        String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
-        if (!preferredDomain.startsWith("@")) {
-            preferredDomain = "@" + preferredDomain;
-        }
         try {
             accounts = accountManager.getAccounts(null);
         } catch (RemoteException e) {
@@ -154,20 +141,13 @@
         }
         if (accounts != null) {
             for (Account account : accounts) {
-                if (EMAIL_REGEX.matcher(account.name).matches()) {
-                    if (!preferredDomain.isEmpty()) {
-                        // if we have a preferred domain and it matches, return; otherwise keep
-                        // looking
-                        if (account.name.endsWith(preferredDomain)) {
-                            return account;
-                        } else {
-                            foundAccount = account;
-                        }
-                        // if we don't have a preferred domain, just return since it looks like
-                        // an email address
-                    } else {
-                        return account;
-                    }
+                if (GOOGLE_ACCOUNT_TYPE.equals(account.type)) {
+                    // return first gmail account found
+                    return account;
+                } else if (EMAIL_ACCOUNT_TYPE.equals(account.type)) {
+                    // keep regular email account for now in case there are gmail accounts
+                    // found later
+                    foundAccount = account;
                 }
             }
         }