OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 package org.chromium.chrome.browser.crash; |
| 5 |
| 6 import android.annotation.TargetApi; |
| 7 import android.content.Context; |
| 8 import android.net.ConnectivityManager; |
| 9 import android.net.NetworkInfo; |
| 10 import android.os.Build; |
| 11 import android.os.PersistableBundle; |
| 12 |
| 13 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; |
| 14 import org.chromium.components.minidump_uploader.MinidumpUploaderDelegate; |
| 15 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
| 16 |
| 17 import java.io.File; |
| 18 |
| 19 /** |
| 20 * Chrome-specific implementations for minidump uploading logic. |
| 21 */ |
| 22 @TargetApi(Build.VERSION_CODES.M) |
| 23 public class ChromeMinidumpUploaderDelegate implements MinidumpUploaderDelegate
{ |
| 24 // PersistableBundle keys: |
| 25 static final String IS_CLIENT_IN_METRICS_SAMPLE = "isClientInMetricsSample"; |
| 26 static final String IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_LINE = |
| 27 "isCrashUploadDisabledByCommandLine"; |
| 28 static final String IS_UPLOAD_ENABLED_FOR_TESTS = "isUploadEnabledForTests"; |
| 29 |
| 30 /** |
| 31 * The application context in which minidump uploads are running. |
| 32 */ |
| 33 private final Context mContext; |
| 34 |
| 35 /** |
| 36 * The cached crash reporting permissions. These are cached because the uplo
ad job might run |
| 37 * outside of a context in which the original permissions are easily accessi
ble. |
| 38 */ |
| 39 private final PersistableBundle mPermissions; |
| 40 |
| 41 /** |
| 42 * The system connectivity manager service, used to determine the network st
ate. |
| 43 */ |
| 44 private final ConnectivityManager mConnectivityManager; |
| 45 |
| 46 /** |
| 47 * Constructs a new Chrome-specific minidump uploader delegate. |
| 48 * @param context The application context in which minidump uploads are runn
ing. |
| 49 * @param permissions The cached crash reporting permissions. |
| 50 */ |
| 51 ChromeMinidumpUploaderDelegate(Context context, PersistableBundle permission
s) { |
| 52 mContext = context; |
| 53 mPermissions = permissions; |
| 54 mConnectivityManager = |
| 55 (ConnectivityManager) context.getSystemService(Context.CONNECTIV
ITY_SERVICE); |
| 56 } |
| 57 |
| 58 @Override |
| 59 public File getCrashParentDir() { |
| 60 return mContext.getCacheDir(); |
| 61 } |
| 62 |
| 63 @Override |
| 64 public CrashReportingPermissionManager createCrashReportingPermissionManager
() { |
| 65 return new CrashReportingPermissionManager() { |
| 66 @Override |
| 67 public boolean isClientInMetricsSample() { |
| 68 return mPermissions.getBoolean(IS_CLIENT_IN_METRICS_SAMPLE, true
); |
| 69 } |
| 70 |
| 71 @Override |
| 72 public boolean isNetworkAvailableForCrashUploads() { |
| 73 // TODO(isherman): This code should really be shared with the An
droid Webview |
| 74 // implementation, which tests whether the connection is metered
, rather than |
| 75 // testing the type of the connection. Implement this change in
M59 -- for M58, it's |
| 76 // more important to maintain consistency with the previous impl
ementation. When |
| 77 // changing this, note that forced uploads do *not* require unme
tered connections. |
| 78 NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkI
nfo(); |
| 79 if (networkInfo == null || !networkInfo.isConnected()) return fa
lse; |
| 80 return networkInfo.getType() == ConnectivityManager.TYPE_WIFI |
| 81 || networkInfo.getType() == ConnectivityManager.TYPE_ETH
ERNET; |
| 82 } |
| 83 |
| 84 @Override |
| 85 public boolean isCrashUploadDisabledByCommandLine() { |
| 86 return mPermissions.getBoolean(IS_CRASH_UPLOAD_DISABLED_BY_COMMA
ND_LINE, false); |
| 87 } |
| 88 |
| 89 @Override |
| 90 public boolean isMetricsUploadPermitted() { |
| 91 // This method is already represented by isClientInMetricsSample
() and |
| 92 // isNetworkAvailableForCrashUploads(), so it's fine to return a
dummy value. |
| 93 return true; |
| 94 } |
| 95 |
| 96 @Override |
| 97 public boolean isUsageAndCrashReportingPermittedByUser() { |
| 98 return PrivacyPreferencesManager.getInstance() |
| 99 .isUsageAndCrashReportingPermittedByUser(); |
| 100 } |
| 101 |
| 102 @Override |
| 103 public boolean isUploadEnabledForTests() { |
| 104 return mPermissions.getBoolean(IS_UPLOAD_ENABLED_FOR_TESTS, fals
e); |
| 105 } |
| 106 }; |
| 107 } |
| 108 |
| 109 @Override |
| 110 public void prepareToUploadMinidumps(final Runnable startUploads) { |
| 111 startUploads.run(); |
| 112 } |
| 113 |
| 114 @Override |
| 115 public void recordUploadSuccess(File minidump) { |
| 116 MinidumpUploadService.incrementCrashSuccessUploadCount(minidump.getAbsol
utePath()); |
| 117 } |
| 118 |
| 119 @Override |
| 120 public void recordUploadFailure(File minidump) { |
| 121 MinidumpUploadService.incrementCrashFailureUploadCount(minidump.getAbsol
utePath()); |
| 122 } |
| 123 } |
OLD | NEW |