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.annotation.SuppressLint; | |
7 import android.app.IntentService; | 8 import android.app.IntentService; |
9 import android.app.job.JobInfo; | |
8 import android.content.Context; | 10 import android.content.Context; |
9 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.os.Build; | |
13 import android.os.PersistableBundle; | |
10 import android.support.annotation.StringDef; | 14 import android.support.annotation.StringDef; |
11 | 15 |
12 import org.chromium.base.Log; | 16 import org.chromium.base.Log; |
13 import org.chromium.base.StreamUtil; | 17 import org.chromium.base.StreamUtil; |
14 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
15 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
16 import org.chromium.base.metrics.RecordHistogram; | 20 import org.chromium.base.metrics.RecordHistogram; |
21 import org.chromium.chrome.browser.ChromeFeatureList; | |
17 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 22 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
18 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ; | 23 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ; |
19 import org.chromium.components.minidump_uploader.CrashFileManager; | 24 import org.chromium.components.minidump_uploader.CrashFileManager; |
20 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; | 25 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; |
26 import org.chromium.components.minidump_uploader.MinidumpUploadJobService; | |
21 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager; | 27 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager; |
22 | 28 |
23 import java.io.BufferedReader; | 29 import java.io.BufferedReader; |
24 import java.io.File; | 30 import java.io.File; |
25 import java.io.FileReader; | 31 import java.io.FileReader; |
26 import java.io.IOException; | 32 import java.io.IOException; |
27 | 33 |
28 /** | 34 /** |
29 * Service that is responsible for uploading crash minidumps to the Google crash server. | 35 * Service that is responsible for uploading crash minidumps to the Google crash server. |
30 */ | 36 */ |
(...skipping 30 matching lines...) Expand all Loading... | |
61 static final String OTHER = "Other"; | 67 static final String OTHER = "Other"; |
62 | 68 |
63 static final String[] TYPES = {BROWSER, RENDERER, GPU, OTHER}; | 69 static final String[] TYPES = {BROWSER, RENDERER, GPU, OTHER}; |
64 | 70 |
65 public MinidumpUploadService() { | 71 public MinidumpUploadService() { |
66 super(TAG); | 72 super(TAG); |
67 setIntentRedelivery(true); | 73 setIntentRedelivery(true); |
68 } | 74 } |
69 | 75 |
70 /** | 76 /** |
77 * @return Whether to use the JobSchduler API to upload crash reports, rathe r than directly | |
78 * creating a service for uploading. | |
79 */ | |
80 public static boolean shouldUseJobSchedulerForUploads() { | |
81 // The JobScheduler API is only available as of Android L. | |
82 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
83 return false; | |
84 } | |
85 | |
86 return ChromeFeatureList.isEnabled( | |
87 ChromeFeatureList.UPLOAD_CRASH_REPORTS_USING_JOB_SCHEDULER); | |
88 } | |
89 | |
90 /** | |
91 * Schedules uploading of all pending minidumps, using the JobScheduler API. | |
92 */ | |
93 @SuppressLint("NewApi") | |
94 public static void scheduleUploadJob(Context context) { | |
95 assert MinidumpUploadService.shouldUseJobSchedulerForUploads(); | |
96 CrashReportingPermissionManager permissionManager = PrivacyPreferencesMa nager.getInstance(); | |
97 PersistableBundle permissions = new PersistableBundle(); | |
98 // Note: putBoolean is only available in API level 22, so massage the da ta into ints | |
99 // instead. | |
100 permissions.putInt(ChromeMinidumpUploaderDelegate.IS_CLIENT_IN_METRICS_S AMPLE, | |
101 permissionManager.isClientInMetricsSample() ? 1 : 0); | |
102 permissions.putInt(ChromeMinidumpUploaderDelegate.IS_CRASH_UPLOAD_DISABL ED_BY_COMMAND_LINE, | |
103 permissionManager.isCrashUploadDisabledByCommandLine() ? 1 : 0); | |
104 permissions.putInt( | |
105 ChromeMinidumpUploaderDelegate.IS_USAGE_AND_CRASH_REPORTING_PERM ITTED_BY_USER, | |
106 permissionManager.isUsageAndCrashReportingPermittedByUser() ? 1 : 0); | |
107 permissions.putInt(ChromeMinidumpUploaderDelegate.IS_UPLOAD_ENABLED_FOR_ TESTS, | |
108 permissionManager.isUploadEnabledForTests() ? 1 : 0); | |
109 MinidumpUploadJobService.scheduleUpload(context, ChromeMinidumpUploadJob Service.class, | |
110 JobInfo.NETWORK_TYPE_ANY, permissions); | |
gsennton
2017/03/13 17:57:17
Not sure I like the mismatch between the network t
Ilya Sherman
2017/03/14 02:18:55
I believe that matches what we currently do in Chr
gsennton
2017/03/14 18:17:28
Right, because updating to only using unmetered ne
Ilya Sherman
2017/03/15 02:13:34
Affirmative =)
| |
111 } | |
112 | |
113 /** | |
71 * Stores the successes and failures from uploading crash to UMA, | 114 * Stores the successes and failures from uploading crash to UMA, |
72 */ | 115 */ |
73 public static void storeBreakpadUploadStatsInUma(ChromePreferenceManager pre f) { | 116 public static void storeBreakpadUploadStatsInUma(ChromePreferenceManager pre f) { |
74 for (String type : TYPES) { | 117 for (String type : TYPES) { |
75 for (int success = pref.getCrashSuccessUploadCount(type); success > 0; success--) { | 118 for (int success = pref.getCrashSuccessUploadCount(type); success > 0; success--) { |
76 RecordHistogram.recordEnumeratedHistogram( | 119 RecordHistogram.recordEnumeratedHistogram( |
77 HISTOGRAM_NAME_PREFIX + type, SUCCESS, HISTOGRAM_MAX); | 120 HISTOGRAM_NAME_PREFIX + type, SUCCESS, HISTOGRAM_MAX); |
78 } | 121 } |
79 for (int fail = pref.getCrashFailureUploadCount(type); fail > 0; fai l--) { | 122 for (int fail = pref.getCrashFailureUploadCount(type); fail > 0; fai l--) { |
80 RecordHistogram.recordEnumeratedHistogram( | 123 RecordHistogram.recordEnumeratedHistogram( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 * | 285 * |
243 * Note that this method is asynchronous. All that is guaranteed is that an upload attempt will | 286 * Note that this method is asynchronous. All that is guaranteed is that an upload attempt will |
244 * be enqueued. | 287 * be enqueued. |
245 * | 288 * |
246 * @param context The application context, in which to initiate the crash re port upload. | 289 * @param context The application context, in which to initiate the crash re port upload. |
247 * @throws A security excpetion if the caller doesn't have permission to sta rt the upload | 290 * @throws A security excpetion if the caller doesn't have permission to sta rt the upload |
248 * service. This can only happen on KitKat and below, due to a frame work bug. | 291 * service. This can only happen on KitKat and below, due to a frame work bug. |
249 */ | 292 */ |
250 public static void tryUploadCrashDump(Context context, File minidumpFile) | 293 public static void tryUploadCrashDump(Context context, File minidumpFile) |
251 throws SecurityException { | 294 throws SecurityException { |
295 assert !MinidumpUploadService.shouldUseJobSchedulerForUploads(); | |
gsennton
2017/03/13 17:57:17
Should we add this assert in tryUploadAllCrashDump
Ilya Sherman
2017/03/14 02:18:55
Done. tryUploadAllCrashDumps calls this method in
| |
252 CrashFileManager fileManager = new CrashFileManager(context.getCacheDir( )); | 296 CrashFileManager fileManager = new CrashFileManager(context.getCacheDir( )); |
253 Intent intent = new Intent(context, MinidumpUploadService.class); | 297 Intent intent = new Intent(context, MinidumpUploadService.class); |
254 intent.setAction(ACTION_UPLOAD); | 298 intent.setAction(ACTION_UPLOAD); |
255 intent.putExtra(FILE_TO_UPLOAD_KEY, minidumpFile.getAbsolutePath()); | 299 intent.putExtra(FILE_TO_UPLOAD_KEY, minidumpFile.getAbsolutePath()); |
256 intent.putExtra(UPLOAD_LOG_KEY, fileManager.getCrashUploadLogFile().getA bsolutePath()); | 300 intent.putExtra(UPLOAD_LOG_KEY, fileManager.getCrashUploadLogFile().getA bsolutePath()); |
257 context.startService(intent); | 301 context.startService(intent); |
258 } | 302 } |
259 | 303 |
260 /** | 304 /** |
261 * Attempts to upload all minidump files using the given {@link android.cont ent.Context}. | 305 * Attempts to upload all minidump files using the given {@link android.cont ent.Context}. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 File minidumpFile = fileManager.getCrashFileWithLocalId(localId); | 342 File minidumpFile = fileManager.getCrashFileWithLocalId(localId); |
299 if (minidumpFile == null) { | 343 if (minidumpFile == null) { |
300 Log.w(TAG, "Could not find a crash dump with local ID " + localId); | 344 Log.w(TAG, "Could not find a crash dump with local ID " + localId); |
301 return; | 345 return; |
302 } | 346 } |
303 File renamedMinidumpFile = CrashFileManager.trySetForcedUpload(minidumpF ile); | 347 File renamedMinidumpFile = CrashFileManager.trySetForcedUpload(minidumpF ile); |
304 if (renamedMinidumpFile == null) { | 348 if (renamedMinidumpFile == null) { |
305 Log.w(TAG, "Could not rename the file " + minidumpFile.getName() + " for re-upload"); | 349 Log.w(TAG, "Could not rename the file " + minidumpFile.getName() + " for re-upload"); |
306 return; | 350 return; |
307 } | 351 } |
308 MinidumpUploadService.tryUploadCrashDump(context, renamedMinidumpFile); | 352 |
353 if (MinidumpUploadService.shouldUseJobSchedulerForUploads()) { | |
354 MinidumpUploadService.scheduleUploadJob(context); | |
355 } else { | |
356 MinidumpUploadService.tryUploadCrashDump(context, renamedMinidumpFil e); | |
357 } | |
309 } | 358 } |
310 } | 359 } |
OLD | NEW |