summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2011-08-18 17:48:43 -0700
committerGuang Zhu <guangzhu@google.com>2011-08-18 17:48:43 -0700
commitd4cd3249e37e5689fc4a8c2858351ec9bebb467c (patch)
tree924f2bae3d7401ed34100831ddf9ca8caefc496d
parent43350373779c519e0fda89f9c5c899af1a42e8d1 (diff)
downloadextras-d4cd3249e37e5689fc4a8c2858351ec9bebb467c.tar.gz
BugReporter integration
Queries PackageManager for a predefined intent, if it's resolvable, hand the bugreport over to BugReporter. Otherwise same as before: compose an intent to send out in mail with attachment Change-Id: Ib7a5b49551ae9285ed46464277168487520d798b
-rw-r--r--bugmailer/src/com/android/commands/sendbug/SendBug.java62
1 files changed, 50 insertions, 12 deletions
diff --git a/bugmailer/src/com/android/commands/sendbug/SendBug.java b/bugmailer/src/com/android/commands/sendbug/SendBug.java
index 4fb66825..9ae2da85 100644
--- a/bugmailer/src/com/android/commands/sendbug/SendBug.java
+++ b/bugmailer/src/com/android/commands/sendbug/SendBug.java
@@ -21,17 +21,21 @@ import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.IPackageManager;
+import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import java.io.File;
+import java.util.List;
public class SendBug {
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) {
if (args.length >= 1) {
@@ -42,18 +46,10 @@ public class SendBug {
private void run(String bugreportPath) {
File bugreport = new File(bugreportPath);
if (bugreport.exists()) {
- Account sendToAccount = findSendToAccount();
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setType("application/octet-stream");
- intent.putExtra("subject", bugreport.getName());
- StringBuilder sb = new StringBuilder();
- sb.append(SystemProperties.get("ro.build.description"));
- sb.append("\n(Sent from BugMailer)");
- intent.putExtra("body", sb.toString());
- intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(bugreport));
- if (sendToAccount != null) {
- intent.putExtra("to", sendToAccount.name);
+ Uri bugreportUri = Uri.fromFile(bugreport);
+ Intent intent = tryBugReporter(bugreportUri);
+ if (intent == null) {
+ intent = getSendMailIntent(bugreportUri);
}
IActivityManager mAm = ActivityManagerNative.getDefault();
try {
@@ -64,6 +60,48 @@ public class SendBug {
}
}
+ private Intent tryBugReporter(Uri bugreportUri) {
+ Intent intent = new Intent(SEND_BUG_INTENT_ACTION);
+ intent.setData(bugreportUri);
+ IPackageManager mPm = IPackageManager.Stub.asInterface(
+ ServiceManager.getService("package"));
+ if (mPm != null) {
+ List<ResolveInfo> results = null;
+ try {
+ results = mPm.queryIntentActivities(intent, null, 0);
+ } catch (RemoteException e) {
+ return null;
+ }
+ if (results != null && results.size() > 0) {
+ ResolveInfo info = results.get(0);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClassName(info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name);
+ return intent;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ private Intent getSendMailIntent(Uri bugreportUri) {
+ Account sendToAccount = findSendToAccount();
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setType("application/octet-stream");
+ intent.putExtra("subject", bugreportUri.getLastPathSegment());
+ StringBuilder sb = new StringBuilder();
+ sb.append(SystemProperties.get("ro.build.description"));
+ sb.append("\n(Sent from BugMailer)");
+ intent.putExtra("body", sb.toString());
+ intent.putExtra(Intent.EXTRA_STREAM, bugreportUri);
+ if (sendToAccount != null) {
+ intent.putExtra("to", sendToAccount.name);
+ }
+ return intent;
+ }
+
private Account findSendToAccount() {
IAccountManager accountManager = IAccountManager.Stub.asInterface(ServiceManager
.getService(Context.ACCOUNT_SERVICE));