summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2011-07-19 18:44:41 -0700
committerGuang Zhu <guangzhu@google.com>2011-07-19 18:58:50 -0700
commit8c658e058446ad69fb056b2160340d708582b9ee (patch)
tree4e1ebf03ed0d45cd6bf02c01e96f5c08a2fa381a
parente9eeec84408d01bf56b9297125a2ebc2638344c8 (diff)
downloadextras-8c658e058446ad69fb056b2160340d708582b9ee.tar.gz
additional scripts for emailing bugreports after capture
First script calls dumpsys to generate the bugreport, second script launches a cmd line tool that queries account manager for possible accounts to set as "to:" field and launches an intent to mail the bugreport out This is done in 2 steps because it's more convenient to look up account for emailing with a framework context, but to make sure bugreport is captured, using dumpsys from shell script is more reliable in case Dalvik VM crashes. Change-Id: Ibb54ac793bbd59f016db9fe98118155168c9371e
-rw-r--r--bugmailer/Android.mk9
-rwxr-xr-xbugmailer/bugmailer.sh11
-rwxr-xr-xbugmailer/send_bug5
-rw-r--r--bugmailer/src/com/android/commands/sendbug/SendBug.java90
4 files changed, 107 insertions, 8 deletions
diff --git a/bugmailer/Android.mk b/bugmailer/Android.mk
new file mode 100644
index 00000000..9ae4fd8e
--- /dev/null
+++ b/bugmailer/Android.mk
@@ -0,0 +1,9 @@
+# Copyright 2011 The Android Open Source Project
+#
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_MODULE := send_bug
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_JAVA_LIBRARY)
diff --git a/bugmailer/bugmailer.sh b/bugmailer/bugmailer.sh
index c8da909e..9fdc0d1f 100755
--- a/bugmailer/bugmailer.sh
+++ b/bugmailer/bugmailer.sh
@@ -3,8 +3,6 @@
timestamp=`date +'%Y-%m-%d-%H-%M-%S'`
storagePath="$EXTERNAL_STORAGE/bugreports"
bugreport=$storagePath/bugreport-$timestamp
-buildDesc="`/system/bin/getprop ro.build.description`
-(Sent from BugMailer)"
# run bugreport
/system/bin/dumpstate -o $bugreport $@
@@ -13,9 +11,6 @@ buildDesc="`/system/bin/getprop ro.build.description`
# make files readable
chown root.sdcard_rw $bugreport.txt
-# send intent to mail it
-/system/bin/am start -a android.intent.action.SEND \
- -t "application/octet-stream" \
- -e "subject" "bugreport-$timestamp" \
- -e "body" "$buildDesc" \
- --eu "android.intent.extra.STREAM" "file://$bugreport.txt"
+# invoke send_bug to look up email accounts and fire intents
+# make it convenient to send bugreport to oneself
+/system/bin/send_bug $bugreport.txt
diff --git a/bugmailer/send_bug b/bugmailer/send_bug
new file mode 100755
index 00000000..db58b326
--- /dev/null
+++ b/bugmailer/send_bug
@@ -0,0 +1,5 @@
+# Script to start "send_bug" on the device
+#
+base=/system
+export CLASSPATH=$base/framework/send_bug.jar
+exec app_process $base/bin com.android.commands.sendbug.SendBug "$@"
diff --git a/bugmailer/src/com/android/commands/sendbug/SendBug.java b/bugmailer/src/com/android/commands/sendbug/SendBug.java
new file mode 100644
index 00000000..d2a555d2
--- /dev/null
+++ b/bugmailer/src/com/android/commands/sendbug/SendBug.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011 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.commands.sendbug;
+
+import android.accounts.Account;
+import android.accounts.IAccountManager;
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+
+import java.io.File;
+
+public class SendBug {
+
+ private static final String GOOGLE_ACCOUNT_TYPE = "com.google";
+ private static final String EMAIL_ACCOUNT_TYPE = "com.android.email";
+
+ public static void main(String[] args) {
+ if (args.length >= 1) {
+ new SendBug().run(args[0]);
+ }
+ }
+
+ 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);
+ }
+ IActivityManager mAm = ActivityManagerNative.getDefault();
+ try {
+ mAm.startActivity(null, intent, intent.getType(), null, 0, null, null, 0, false,
+ false);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+
+ private Account findSendToAccount() {
+ IAccountManager accountManager = IAccountManager.Stub.asInterface(ServiceManager
+ .getService(Context.ACCOUNT_SERVICE));
+ Account[] accounts = null;
+ Account foundAccount = null;
+ try {
+ accounts = accountManager.getAccounts(null);
+ } catch (RemoteException e) {
+ }
+ if (accounts != null) {
+ for (Account account : accounts) {
+ 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;
+ }
+ }
+ }
+ return foundAccount;
+ }
+}