Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/crash/LogcatExtractionRunnable.java

Issue 2801033002: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
7 import android.os.Build; 8 import android.os.Build;
8 import android.util.Patterns; 9 import android.util.Patterns;
9 10
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
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;
112 private final File mMinidumpFile; 113 private final File mMinidumpFile;
113 114
114 /** 115 /**
116 * @param context The application context for accessing the cache directory and firing intents.
115 * @param minidump The minidump file that needs logcat output to be attached . 117 * @param minidump The minidump file that needs logcat output to be attached .
116 */ 118 */
117 public LogcatExtractionRunnable(File minidump) { 119 public LogcatExtractionRunnable(Context context, File minidump) {
120 mContext = context;
118 mMinidumpFile = minidump; 121 mMinidumpFile = minidump;
119 } 122 }
120 123
121 @Override 124 @Override
122 public void run() { 125 public void run() {
123 Log.i(TAG, "Trying to extract logcat for minidump %s.", mMinidumpFile.ge tName()); 126 Log.i(TAG, "Trying to extract logcat for minidump %s.", mMinidumpFile.ge tName());
124 CrashFileManager fileManager = 127 CrashFileManager fileManager = new CrashFileManager(mContext.getCacheDir ());
125 new CrashFileManager(ContextUtils.getApplicationContext().getCac heDir());
126 File fileToUpload = mMinidumpFile; 128 File fileToUpload = mMinidumpFile;
127 try { 129 try {
128 List<String> logcat = getElidedLogcat(); 130 List<String> logcat = getElidedLogcat();
129 fileToUpload = new MinidumpLogcatPrepender(fileManager, mMinidumpFil e, logcat).run(); 131 fileToUpload = new MinidumpLogcatPrepender(fileManager, mMinidumpFil e, logcat).run();
130 Log.i(TAG, "Succeeded extracting logcat to %s.", fileToUpload.getNam e()); 132 Log.i(TAG, "Succeeded extracting logcat to %s.", fileToUpload.getNam e());
131 } catch (IOException | InterruptedException e) { 133 } catch (IOException | InterruptedException e) {
132 Log.w(TAG, e.toString()); 134 Log.w(TAG, e.toString());
133 } 135 }
134 136
135 // Regardless of success, initiate the upload. That way, even if there a re errors augmenting 137 // Regardless of success, initiate the upload. That way, even if there a re errors augmenting
136 // the minidump with logcat data, the service can still upload the unaug mented minidump. 138 // the minidump with logcat data, the service can still upload the unaug mented minidump.
137 if (MinidumpUploadService.shouldUseJobSchedulerForUploads()) { 139 if (MinidumpUploadService.shouldUseJobSchedulerForUploads()) {
138 MinidumpUploadService.scheduleUploadJob(); 140 MinidumpUploadService.scheduleUploadJob(mContext);
139 } else { 141 } else {
140 try { 142 try {
141 MinidumpUploadService.tryUploadCrashDump(fileToUpload); 143 MinidumpUploadService.tryUploadCrashDump(mContext, fileToUpload) ;
142 } catch (SecurityException e) { 144 } catch (SecurityException e) {
143 // For KitKat and below, there was a framework bug which causes us to not be able to 145 // For KitKat and below, there was a framework bug which causes us to not be able to
144 // find our own crash uploading service. Ignore a SecurityExcept ion here on older 146 // find our own crash uploading service. Ignore a SecurityExcept ion here on older
145 // OS versions since the crash will eventually get uploaded on n ext start. 147 // OS versions since the crash will eventually get uploaded on n ext start.
146 // crbug/542533 148 // crbug/542533
147 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 149 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
148 throw e; 150 throw e;
149 } 151 }
150 } 152 }
151 } 153 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 * {@link #CONSOLE_ELISION}. 331 * {@link #CONSOLE_ELISION}.
330 * 332 *
331 * @param original String potentially containing console messages. 333 * @param original String potentially containing console messages.
332 * @return String with elided console messages. 334 * @return String with elided console messages.
333 */ 335 */
334 @VisibleForTesting 336 @VisibleForTesting
335 protected static String elideConsole(String original) { 337 protected static String elideConsole(String original) {
336 return CONSOLE_MSG.matcher(original).replaceAll(CONSOLE_ELISION); 338 return CONSOLE_MSG.matcher(original).replaceAll(CONSOLE_ELISION);
337 } 339 }
338 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698