1 #!/system/bin/sh 2 3 # TODO: restructure this to keep bugreports entirely on internal storage 4 5 # Do not allow bugreports on user builds unless USB debugging 6 # is enabled. 7 if [ "x$(getprop ro.build.type)" = "xuser" -a \ 8 "x$(getprop init.svc.adbd)" != "xrunning" ]; then 9 exit 0 10 fi 11 12 # Build emulated storage paths when appropriate 13 # See storage config details at http://source.android.com/tech/storage/ 14 if [ -n "$EMULATED_STORAGE_SOURCE" ]; then 15 writePath="$EMULATED_STORAGE_SOURCE/0" 16 readPath="$EMULATED_STORAGE_TARGET/0" 17 else 18 writePath="$EXTERNAL_STORAGE" 19 readPath="$EXTERNAL_STORAGE" 20 fi 21 22 tmpPath="/data/local/tmp" 23 bugreportPath="bugreports" 24 screenshotPath="Pictures/Screenshots" 25 26 # Create directories if needed 27 if [ ! -e "$writePath/$bugreportPath" ]; then 28 mkdir "$writePath/$bugreportPath" 29 fi 30 if [ ! -e "$writePath/$screenshotPath" ]; then 31 mkdir "$writePath/$screenshotPath" 32 fi 33 34 timestamp=`date +'%Y-%m-%d-%H-%M-%S'` 35 36 # take screen shot 37 # we run this as a bg job in case screencap is stuck 38 /system/bin/screencap -p "$writePath/$screenshotPath/Screenshot_$timestamp.png" & 39 40 # run bugreport 41 /system/bin/dumpstate -o "$tmpPath/bugreport-$timestamp" $@ 42 43 # copy finished bugreport into place for sending 44 cp "$tmpPath/bugreport-$timestamp.txt" "$writePath/$bugreportPath/bugreport-$timestamp.txt" 45 # clean up any remaining files 46 rm $tmpPath/bugreport* 47 48 # invoke send_bug to look up email accounts and fire intents 49 # make it convenient to send bugreport to oneself 50 /system/bin/send_bug "$readPath/$bugreportPath/bugreport-$timestamp.txt" "$readPath/$screenshotPath/Screenshot_$timestamp.png" 51