Index: chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java b/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java |
index 7fcc2add43049f0973443225ebb51662d44bed4f..a56973dc863b8d2ca9a6fcb0c7409a4d1c22d625 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java |
@@ -8,12 +8,12 @@ |
import android.app.IntentService; |
import android.app.job.JobInfo; |
import android.content.ComponentName; |
+import android.content.Context; |
import android.content.Intent; |
import android.os.Build; |
import android.os.PersistableBundle; |
import android.support.annotation.StringDef; |
-import org.chromium.base.ContextUtils; |
import org.chromium.base.Log; |
import org.chromium.base.StreamUtil; |
import org.chromium.base.VisibleForTesting; |
@@ -87,7 +87,7 @@ |
* Schedules uploading of all pending minidumps, using the JobScheduler API. |
*/ |
@SuppressLint("NewApi") |
- public static void scheduleUploadJob() { |
+ public static void scheduleUploadJob(Context context) { |
assert shouldUseJobSchedulerForUploads(); |
CrashReportingPermissionManager permissionManager = PrivacyPreferencesManager.getInstance(); |
@@ -100,10 +100,9 @@ |
JobInfo.Builder builder = |
new JobInfo |
.Builder(TaskIds.CHROME_MINIDUMP_UPLOADING_JOB_ID, |
- new ComponentName(ContextUtils.getApplicationContext(), |
- ChromeMinidumpUploadJobService.class)) |
+ new ComponentName(context, ChromeMinidumpUploadJobService.class)) |
.setExtras(permissions); |
- MinidumpUploadJobService.scheduleUpload(builder); |
+ MinidumpUploadJobService.scheduleUpload(context, builder); |
} |
/** |
@@ -292,19 +291,19 @@ |
* Note that this method is asynchronous. All that is guaranteed is that an upload attempt will |
* be enqueued. |
* |
- * @throws SecurityException if the caller doesn't have permission to start the upload |
+ * @param context The application context, in which to initiate the crash report upload. |
+ * @throws A security excpetion if the caller doesn't have permission to start the upload |
* service. This can only happen on KitKat and below, due to a framework bug. |
*/ |
- public static void tryUploadCrashDump(File minidumpFile) throws SecurityException { |
+ public static void tryUploadCrashDump(Context context, File minidumpFile) |
+ throws SecurityException { |
assert !shouldUseJobSchedulerForUploads(); |
- CrashFileManager fileManager = |
- new CrashFileManager(ContextUtils.getApplicationContext().getCacheDir()); |
- Intent intent = |
- new Intent(ContextUtils.getApplicationContext(), MinidumpUploadService.class); |
+ CrashFileManager fileManager = new CrashFileManager(context.getCacheDir()); |
+ Intent intent = new Intent(context, MinidumpUploadService.class); |
intent.setAction(ACTION_UPLOAD); |
intent.putExtra(FILE_TO_UPLOAD_KEY, minidumpFile.getAbsolutePath()); |
intent.putExtra(UPLOAD_LOG_KEY, fileManager.getCrashUploadLogFile().getAbsolutePath()); |
- ContextUtils.getApplicationContext().startService(intent); |
+ context.startService(intent); |
} |
/** |
@@ -315,15 +314,15 @@ |
* |
* This method is safe to call from the UI thread. |
* |
- */ |
- public static void tryUploadAllCrashDumps() { |
+ * @param context Context of the application. |
+ */ |
+ public static void tryUploadAllCrashDumps(Context context) { |
assert !shouldUseJobSchedulerForUploads(); |
- CrashFileManager fileManager = |
- new CrashFileManager(ContextUtils.getApplicationContext().getCacheDir()); |
+ CrashFileManager fileManager = new CrashFileManager(context.getCacheDir()); |
File[] minidumps = fileManager.getAllMinidumpFiles(MAX_TRIES_ALLOWED); |
Log.i(TAG, "Attempting to upload accumulated crash dumps."); |
for (File minidump : minidumps) { |
- tryUploadCrashDump(minidump); |
+ tryUploadCrashDump(context, minidump); |
} |
} |
@@ -335,17 +334,17 @@ |
* |
* This method is safe to call from the UI thread. |
* |
+ * @param context the context to use for the intent. |
* @param localId The local ID of the crash report. |
*/ |
@CalledByNative |
- public static void tryUploadCrashDumpWithLocalId(String localId) { |
+ public static void tryUploadCrashDumpWithLocalId(Context context, String localId) { |
if (localId == null || localId.isEmpty()) { |
Log.w(TAG, "Cannot force crash upload since local crash id is absent."); |
return; |
} |
- CrashFileManager fileManager = |
- new CrashFileManager(ContextUtils.getApplicationContext().getCacheDir()); |
+ CrashFileManager fileManager = new CrashFileManager(context.getCacheDir()); |
File minidumpFile = fileManager.getCrashFileWithLocalId(localId); |
if (minidumpFile == null) { |
Log.w(TAG, "Could not find a crash dump with local ID " + localId); |
@@ -358,9 +357,9 @@ |
} |
if (shouldUseJobSchedulerForUploads()) { |
- scheduleUploadJob(); |
+ scheduleUploadJob(context); |
} else { |
- tryUploadCrashDump(renamedMinidumpFile); |
+ tryUploadCrashDump(context, renamedMinidumpFile); |
} |
} |
} |