| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.crash; | 5 package org.chromium.chrome.browser.crash; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.os.Build; | 7 import android.os.Build; |
| 9 import android.util.Patterns; | 8 import android.util.Patterns; |
| 10 | 9 |
| 10 import org.chromium.base.ContextUtils; |
| 11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
| 12 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
| 13 import org.chromium.components.minidump_uploader.CrashFileManager; | 13 import org.chromium.components.minidump_uploader.CrashFileManager; |
| 14 | 14 |
| 15 import java.io.BufferedReader; | 15 import java.io.BufferedReader; |
| 16 import java.io.File; | 16 import java.io.File; |
| 17 import java.io.IOException; | 17 import java.io.IOException; |
| 18 import java.io.InputStreamReader; | 18 import java.io.InputStreamReader; |
| 19 import java.util.ArrayList; | 19 import java.util.ArrayList; |
| 20 import java.util.Collections; | 20 import java.util.Collections; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 "android.hardware", "android.inputmethodservice", "android.location"
, "android.media", | 102 "android.hardware", "android.inputmethodservice", "android.location"
, "android.media", |
| 103 "android.mtp", "android.net", "android.nfc", "android.opengl", "andr
oid.os", | 103 "android.mtp", "android.net", "android.nfc", "android.opengl", "andr
oid.os", |
| 104 "android.preference", "android.print", "android.printservice", "andr
oid.provider", | 104 "android.preference", "android.print", "android.printservice", "andr
oid.provider", |
| 105 "android.renderscript", "android.sax", "android.security", "android.
service", | 105 "android.renderscript", "android.sax", "android.security", "android.
service", |
| 106 "android.speech", "android.support", "android.system", "android.tele
com", | 106 "android.speech", "android.support", "android.system", "android.tele
com", |
| 107 "android.telephony", "android.test", "android.text", "android.transi
tion", | 107 "android.telephony", "android.test", "android.text", "android.transi
tion", |
| 108 "android.util", "android.view", "android.webkit", "android.widget",
"com.android.", | 108 "android.util", "android.view", "android.webkit", "android.widget",
"com.android.", |
| 109 "dalvik.", "java.", "javax.", "org.apache.", "org.json.", "org.w3c.d
om.", "org.xml.", | 109 "dalvik.", "java.", "javax.", "org.apache.", "org.json.", "org.w3c.d
om.", "org.xml.", |
| 110 "org.xmlpull."}; | 110 "org.xmlpull."}; |
| 111 | 111 |
| 112 private final Context mContext; | |
| 113 private final File mMinidumpFile; | 112 private final File mMinidumpFile; |
| 114 | 113 |
| 115 /** | 114 /** |
| 116 * @param context The application context for accessing the cache directory
and firing intents. | |
| 117 * @param minidump The minidump file that needs logcat output to be attached
. | 115 * @param minidump The minidump file that needs logcat output to be attached
. |
| 118 */ | 116 */ |
| 119 public LogcatExtractionRunnable(Context context, File minidump) { | 117 public LogcatExtractionRunnable(File minidump) { |
| 120 mContext = context; | |
| 121 mMinidumpFile = minidump; | 118 mMinidumpFile = minidump; |
| 122 } | 119 } |
| 123 | 120 |
| 124 @Override | 121 @Override |
| 125 public void run() { | 122 public void run() { |
| 126 Log.i(TAG, "Trying to extract logcat for minidump %s.", mMinidumpFile.ge
tName()); | 123 Log.i(TAG, "Trying to extract logcat for minidump %s.", mMinidumpFile.ge
tName()); |
| 127 CrashFileManager fileManager = new CrashFileManager(mContext.getCacheDir
()); | 124 CrashFileManager fileManager = |
| 125 new CrashFileManager(ContextUtils.getApplicationContext().getCac
heDir()); |
| 128 File fileToUpload = mMinidumpFile; | 126 File fileToUpload = mMinidumpFile; |
| 129 try { | 127 try { |
| 130 List<String> logcat = getElidedLogcat(); | 128 List<String> logcat = getElidedLogcat(); |
| 131 fileToUpload = new MinidumpLogcatPrepender(fileManager, mMinidumpFil
e, logcat).run(); | 129 fileToUpload = new MinidumpLogcatPrepender(fileManager, mMinidumpFil
e, logcat).run(); |
| 132 Log.i(TAG, "Succeeded extracting logcat to %s.", fileToUpload.getNam
e()); | 130 Log.i(TAG, "Succeeded extracting logcat to %s.", fileToUpload.getNam
e()); |
| 133 } catch (IOException | InterruptedException e) { | 131 } catch (IOException | InterruptedException e) { |
| 134 Log.w(TAG, e.toString()); | 132 Log.w(TAG, e.toString()); |
| 135 } | 133 } |
| 136 | 134 |
| 137 // Regardless of success, initiate the upload. That way, even if there a
re errors augmenting | 135 // Regardless of success, initiate the upload. That way, even if there a
re errors augmenting |
| 138 // the minidump with logcat data, the service can still upload the unaug
mented minidump. | 136 // the minidump with logcat data, the service can still upload the unaug
mented minidump. |
| 139 if (MinidumpUploadService.shouldUseJobSchedulerForUploads()) { | 137 if (MinidumpUploadService.shouldUseJobSchedulerForUploads()) { |
| 140 MinidumpUploadService.scheduleUploadJob(mContext); | 138 MinidumpUploadService.scheduleUploadJob(); |
| 141 } else { | 139 } else { |
| 142 try { | 140 try { |
| 143 MinidumpUploadService.tryUploadCrashDump(mContext, fileToUpload)
; | 141 MinidumpUploadService.tryUploadCrashDump(fileToUpload); |
| 144 } catch (SecurityException e) { | 142 } catch (SecurityException e) { |
| 145 // For KitKat and below, there was a framework bug which causes
us to not be able to | 143 // For KitKat and below, there was a framework bug which causes
us to not be able to |
| 146 // find our own crash uploading service. Ignore a SecurityExcept
ion here on older | 144 // find our own crash uploading service. Ignore a SecurityExcept
ion here on older |
| 147 // OS versions since the crash will eventually get uploaded on n
ext start. | 145 // OS versions since the crash will eventually get uploaded on n
ext start. |
| 148 // crbug/542533 | 146 // crbug/542533 |
| 149 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 147 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 150 throw e; | 148 throw e; |
| 151 } | 149 } |
| 152 } | 150 } |
| 153 } | 151 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 * {@link #CONSOLE_ELISION}. | 329 * {@link #CONSOLE_ELISION}. |
| 332 * | 330 * |
| 333 * @param original String potentially containing console messages. | 331 * @param original String potentially containing console messages. |
| 334 * @return String with elided console messages. | 332 * @return String with elided console messages. |
| 335 */ | 333 */ |
| 336 @VisibleForTesting | 334 @VisibleForTesting |
| 337 protected static String elideConsole(String original) { | 335 protected static String elideConsole(String original) { |
| 338 return CONSOLE_MSG.matcher(original).replaceAll(CONSOLE_ELISION); | 336 return CONSOLE_MSG.matcher(original).replaceAll(CONSOLE_ELISION); |
| 339 } | 337 } |
| 340 } | 338 } |
| OLD | NEW |