summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-08-16 10:32:14 -0700
committerJeff Sharkey <jsharkey@android.com>2012-08-16 11:48:42 -0700
commit6186a9cb55dae698f048616bb82887565d5779df (patch)
tree5b7269c674ec83fa42f52007284562af970fb0bb
parent9ebc639a313d143ade1293cb5932b446d5e623d5 (diff)
downloadextras-6186a9cb55dae698f048616bb82887565d5779df.tar.gz
Support custom path when saving bugreports.
When running on multi-user devices, we need to save bugreport data to a write path, and launch intents using a different read path. Bug: 6925012 Change-Id: I32773b733e8a4dd75a30f5b9b05424c4238243af
-rwxr-xr-xbugmailer/bugmailer.sh49
-rw-r--r--bugmailer/src/com/android/commands/sendbug/SendBug.java42
2 files changed, 51 insertions, 40 deletions
diff --git a/bugmailer/bugmailer.sh b/bugmailer/bugmailer.sh
index 93d1c8a4..225b18d2 100755
--- a/bugmailer/bugmailer.sh
+++ b/bugmailer/bugmailer.sh
@@ -1,5 +1,7 @@
#!/system/bin/sh
+# TODO: restructure this to keep bugreports entirely on internal storage
+
# Do not allow bugreports on user builds unless USB debugging
# is enabled.
if [ "x$(getprop ro.build.type)" = "xuser" -a \
@@ -7,29 +9,44 @@ if [ "x$(getprop ro.build.type)" = "xuser" -a \
exit 0
fi
-timestamp=`date +'%Y-%m-%d-%H-%M-%S'`
-storagePath="$EXTERNAL_STORAGE/bugreports"
-bugreport=$storagePath/bugreport-$timestamp
-screenshotPath="$EXTERNAL_STORAGE/Pictures/Screenshots"
-screenshot=$screenshotPath/Screenshot_$timestamp.png
-
-# check screen shot folder
-if [ ! -e $screenshotPath ]; then
- mkdir $screenshotPath
+# Use bugreport-specific paths if defined
+if [ -n "$BUGREPORT_WRITE_PATH" ]; then
+ writePath="$BUGREPORT_WRITE_PATH"
+else
+ writePath="$EXTERNAL_STORAGE"
+fi
+if [ -n "$BUGREPORT_READ_PATH" ]; then
+ readPath="$BUGREPORT_READ_PATH"
+else
+ readPath="$EXTERNAL_STORAGE"
+fi
+
+tmpPath="/data/local/tmp"
+bugreportPath="bugreports"
+screenshotPath="Pictures/Screenshots"
+
+# Create directories if needed
+if [ ! -e "$writePath/$bugreportPath" ]; then
+ mkdir "$writePath/$bugreportPath"
+fi
+if [ ! -e "$writePath/$screenshotPath" ]; then
+ mkdir "$writePath/$screenshotPath"
fi
+timestamp=`date +'%Y-%m-%d-%H-%M-%S'`
+
# take screen shot
# we run this as a bg job in case screencap is stuck
-/system/bin/screencap -p $screenshot &
+/system/bin/screencap -p "$writePath/$screenshotPath/Screenshot_$timestamp.png" &
# run bugreport
-/system/bin/dumpstate -o $bugreport $@
-
+/system/bin/dumpstate -o "$tmpPath/bugreport-$timestamp" $@
-# make files readable
-chown root.sdcard_rw $bugreport.txt
-chown root.sdcard_rw $screenshot
+# copy finished bugreport into place for sending
+cp "$tmpPath/bugreport-$timestamp.txt" "$writePath/$bugreportPath/bugreport-$timestamp.txt"
+# clean up any remaining files
+rm $tmpPath/bugreport*
# 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 $screenshot
+/system/bin/send_bug "$readPath/$bugreportPath/bugreport-$timestamp.txt" "$readPath/$screenshotPath/Screenshot_$timestamp.png"
diff --git a/bugmailer/src/com/android/commands/sendbug/SendBug.java b/bugmailer/src/com/android/commands/sendbug/SendBug.java
index 1b8d669c..f6d0db73 100644
--- a/bugmailer/src/com/android/commands/sendbug/SendBug.java
+++ b/bugmailer/src/com/android/commands/sendbug/SendBug.java
@@ -58,32 +58,26 @@ public class SendBug {
File screenShot = null;
if (screenShotPath != null) {
screenShot = new File(screenShotPath);
- if (!screenShot.exists()) {
- // screen shot probably failed
- screenShot = null;
- }
}
- if (bugreport.exists()) {
- final Uri bugreportUri = Uri.fromFile(bugreport);
- // todo (aalbert): investigate adding a screenshot to BugReporter
- Intent intent = tryBugReporter(bugreportUri);
- if (intent == null) {
- final Uri screenshotUri = screenShot != null
- ? 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 Uri bugreportUri = Uri.fromFile(bugreport);
+ // todo (aalbert): investigate adding a screenshot to BugReporter
+ Intent intent = tryBugReporter(bugreportUri);
+ if (intent == null) {
+ final Uri screenshotUri = screenShot != null
+ ? 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);
}
}