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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java

Issue 2737263006: [Android Crash Reporting] Allow uploading minidumps via the JobScheduler (Closed)
Patch Set: Use shared prefs Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.android_webview.crash; 5 package org.chromium.android_webview.crash;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.app.Service; 8 import android.app.Service;
9 import android.app.job.JobInfo; 9 import android.app.job.JobInfo;
10 import android.app.job.JobScheduler;
11 import android.content.ComponentName;
12 import android.content.Context; 10 import android.content.Context;
13 import android.content.Intent; 11 import android.content.Intent;
14 import android.os.Binder; 12 import android.os.Binder;
15 import android.os.Build; 13 import android.os.Build;
16 import android.os.IBinder; 14 import android.os.IBinder;
17 import android.os.ParcelFileDescriptor; 15 import android.os.ParcelFileDescriptor;
18 16
19 import org.chromium.base.Log; 17 import org.chromium.base.Log;
20 import org.chromium.base.VisibleForTesting; 18 import org.chromium.base.VisibleForTesting;
21 import org.chromium.components.minidump_uploader.CrashFileManager; 19 import org.chromium.components.minidump_uploader.CrashFileManager;
20 import org.chromium.components.minidump_uploader.MinidumpUploadJobService;
22 21
23 import java.io.File; 22 import java.io.File;
24 import java.io.IOException; 23 import java.io.IOException;
25 24
26 /** 25 /**
27 * Service that is responsible for receiving crash dumps from an application, fo r upload. 26 * Service that is responsible for receiving crash dumps from an application, fo r upload.
28 */ 27 */
29 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 28 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
30 public class CrashReceiverService extends Service { 29 public class CrashReceiverService extends Service {
31 private static final String TAG = "CrashReceiverService"; 30 private static final String TAG = "CrashReceiverService";
32 31
33 private static final String WEBVIEW_CRASH_DIR = "WebView_Crashes"; 32 private static final String WEBVIEW_CRASH_DIR = "WebView_Crashes";
34 private static final String WEBVIEW_TMP_CRASH_DIR = "WebView_Crashes_Tmp"; 33 private static final String WEBVIEW_TMP_CRASH_DIR = "WebView_Crashes_Tmp";
35 34
35 /**
36 * The job id for uploading minidumps. For more info on this constant, see
37 * https://developer.android.com/reference/android/app/job/JobInfo.Builder.h tml#JobInfo.Builder(int,%20android.content.ComponentName)
38 */
gsennton 2017/03/14 18:17:28 Maybe add a comment about this having to be differ
Ilya Sherman 2017/03/15 02:13:34 Acknowledged.
36 private static final int MINIDUMP_UPLOADING_JOB_ID = 42; 39 private static final int MINIDUMP_UPLOADING_JOB_ID = 42;
37 // Initial back-off time for upload-job, this is set to a fairly high number (30 minutes) to
38 // increase the chance of performing uploads in batches if the initial uploa d fails.
39 private static final int JOB_BACKOFF_TIME_IN_MS = 1000 * 60 * 30;
40 // Back-off policy for upload-job.
41 private static final int JOB_BACKOFF_POLICY = JobInfo.BACKOFF_POLICY_EXPONEN TIAL;
42 40
43 private Object mCopyingLock = new Object(); 41 private Object mCopyingLock = new Object();
44 private boolean mIsCopying = false; 42 private boolean mIsCopying = false;
45 43
46 @Override 44 @Override
47 public void onCreate() { 45 public void onCreate() {
48 super.onCreate(); 46 super.onCreate();
49 } 47 }
50 48
51 private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService .Stub() { 49 private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService .Stub() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Log.e(TAG, "Was interrupted when waiting to copy minidumps", e); 96 Log.e(TAG, "Was interrupted when waiting to copy minidumps", e);
99 return false; 97 return false;
100 } 98 }
101 } 99 }
102 mIsCopying = true; 100 mIsCopying = true;
103 return true; 101 return true;
104 } 102 }
105 } 103 }
106 104
107 private void scheduleNewJob() { 105 private void scheduleNewJob() {
108 JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_ SCHEDULER_SERVICE); 106 JobInfo.Builder builder =
109 JobInfo newJob = new JobInfo 107 new JobInfo
110 .Builder(MINIDUMP_UPLOADING_JOB_ID /* jobId */, 108 .Builder(MINIDUMP_UPLOADING_JOB_ID,
111 new ComponentName(this, AwMinidumpUploa dJobService.class)) 109 new ComponentName(this, AwMinidumpUploadJobServi ce.class))
112 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UN METERED) 110 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
113 // Minimum delay when a job is retried (a retry will happen when 111 MinidumpUploadJobService.scheduleUpload(this, builder);
114 // there are minidumps left after trying to upl oad all minidumps -
115 // this could e.g. happen if we add more minidu mps at the same time
116 // as uploading old ones).
117 .setBackoffCriteria(JOB_BACKOFF_TIME_IN_MS, JOB _BACKOFF_POLICY)
118 .build();
119 if (jobScheduler.schedule(newJob) == JobScheduler.RESULT_FAILURE) {
120 throw new RuntimeException("couldn't schedule " + newJob);
121 }
122 } 112 }
123 113
124 /** 114 /**
125 * Copy minidumps from the {@param fileDescriptors} to the directory where W ebView stores its 115 * Copy minidumps from the {@param fileDescriptors} to the directory where W ebView stores its
126 * minidump files. {@param context} is used to look up the directory in whic h the files will be 116 * minidump files. {@param context} is used to look up the directory in whic h the files will be
127 * saved. 117 * saved.
128 * @return whether any minidump was copied. 118 * @return whether any minidump was copied.
129 */ 119 */
130 @VisibleForTesting 120 @VisibleForTesting
131 public static boolean copyMinidumps( 121 public static boolean copyMinidumps(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 @VisibleForTesting 201 @VisibleForTesting
212 public static File getWebViewTmpCrashDir(Context context) { 202 public static File getWebViewTmpCrashDir(Context context) {
213 return new File(context.getCacheDir(), WEBVIEW_TMP_CRASH_DIR); 203 return new File(context.getCacheDir(), WEBVIEW_TMP_CRASH_DIR);
214 } 204 }
215 205
216 @Override 206 @Override
217 public IBinder onBind(Intent intent) { 207 public IBinder onBind(Intent intent) {
218 return mBinder; 208 return mBinder;
219 } 209 }
220 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698