Chromium Code Reviews| 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.components.minidump_uploader.MinidumpUploaderDelegate; | |
| 14 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager; | |
| 15 | |
| 16 import java.io.File; | |
| 17 | |
| 18 /** | |
| 19 * Chrome-specific implementations for minidump uploading logic. | |
| 20 */ | |
| 21 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
| 22 public class ChromeMinidumpUploaderDelegate implements MinidumpUploaderDelegate { | |
| 23 // PersistableBundle keys: | |
| 24 static final String IS_CLIENT_IN_METRICS_SAMPLE = "isClientInMetricsSample"; | |
| 25 static final String IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_LINE = | |
| 26 "isCrashUploadDisabledByCommandLine"; | |
| 27 static final String IS_USAGE_AND_CRASH_REPORTING_PERMITTED_BY_USER = | |
| 28 "isUsageAndCrashReportingPermittedByUser"; | |
| 29 static final String IS_UPLOAD_ENABLED_FOR_TESTS = "isUploadEnabledForTests"; | |
| 30 | |
| 31 /** | |
| 32 * The application context in which minidump uploads are running. | |
| 33 */ | |
| 34 private final Context mContext; | |
| 35 | |
| 36 /** | |
| 37 * The cached crash reporting permissions. These are cached because the uplo ad job might run | |
| 38 * outside of a context in which the original permissions are easily accessi ble. | |
| 39 */ | |
| 40 private final PersistableBundle mPermissions; | |
| 41 | |
| 42 /** | |
| 43 * The system connectivity manager service, used to determine the network st ate. | |
| 44 */ | |
| 45 private final ConnectivityManager mConnectivityManager; | |
| 46 | |
| 47 /** | |
| 48 * Constructs a new Chrome-specific minidump uploader delegate. | |
| 49 * @param context The application context in which minidump uploads are runn ing. | |
| 50 * @param permissions The cached crash reporting permissions. | |
| 51 */ | |
| 52 ChromeMinidumpUploaderDelegate(Context context, PersistableBundle permission s) { | |
| 53 mContext = context; | |
| 54 mPermissions = permissions; | |
| 55 mConnectivityManager = | |
| 56 (ConnectivityManager) context.getSystemService(Context.CONNECTIV ITY_SERVICE); | |
| 57 } | |
| 58 | |
| 59 @Override | |
| 60 public File getCacheDir() { | |
| 61 return mContext.getCacheDir(); | |
| 62 } | |
| 63 | |
| 64 @Override | |
| 65 public CrashReportingPermissionManager createCrashReportingPermissionManager () { | |
| 66 return new CrashReportingPermissionManager() { | |
| 67 // Note: getBoolean is only available in API level 22, so the data i s serialized via | |
| 68 // ints instead. | |
| 69 @Override | |
| 70 public boolean isClientInMetricsSample() { | |
| 71 return mPermissions.getInt(IS_CLIENT_IN_METRICS_SAMPLE, 1) == 1; | |
| 72 } | |
| 73 @Override | |
| 74 public boolean isNetworkAvailableForCrashUploads() { | |
| 75 // TODO(isherman): This code should really be shared with the An droid Webview | |
| 76 // implementation, which tests whether the connection is metered , rather than | |
| 77 // testing the type of the connection. Implement this change in M59 -- for M58, it's | |
| 78 // more important to maintain consistency with the previous impl ementation. When | |
| 79 // changing this, note that forced uploads do *not* require unme tered connections. | |
| 80 NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkI nfo(); | |
| 81 if (networkInfo == null || !networkInfo.isConnected()) return fa lse; | |
| 82 return networkInfo.getType() == ConnectivityManager.TYPE_WIFI | |
| 83 || networkInfo.getType() == ConnectivityManager.TYPE_ETH ERNET; | |
| 84 } | |
| 85 @Override | |
| 86 public boolean isCrashUploadDisabledByCommandLine() { | |
| 87 return mPermissions.getInt(IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_L INE, 0) == 1; | |
| 88 } | |
| 89 @Override | |
| 90 public boolean isUsageAndCrashReportingPermittedByUser() { | |
| 91 // TODO(isherman): Is it okay to use a cached value here? Ideall y, we'd only use the | |
| 92 // cached value if Chrome is no longer running -- and update the cached value | |
| 93 // periodically. How hard would that be to implement? | |
|
Ilya Sherman
2017/03/13 03:12:09
Maria and Gustav, WDYT? Do either of you know how
gsennton
2017/03/13 17:57:17
When implementing the usage-and-diagnostics check
Ilya Sherman
2017/03/14 02:18:55
Okay, it does seem like it's safe to directly call
gsennton
2017/03/14 18:17:28
When is PrivacyPreferencesManager being created (t
Maria
2017/03/14 19:03:32
I went and read the documentation. Jobs do run wit
Ilya Sherman
2017/03/15 02:13:34
I think you're both correct, and that makes a lot
| |
| 94 return mPermissions.getInt(IS_USAGE_AND_CRASH_REPORTING_PERMITTE D_BY_USER, 0) == 1; | |
| 95 } | |
| 96 @Override | |
| 97 public boolean isUploadEnabledForTests() { | |
| 98 return mPermissions.getInt(IS_UPLOAD_ENABLED_FOR_TESTS, 0) == 1; | |
| 99 } | |
| 100 }; | |
| 101 } | |
| 102 | |
| 103 @Override | |
| 104 public void prepareToUploadMinidumps(final Runnable startUploads) { | |
| 105 startUploads.run(); | |
| 106 } | |
| 107 } | |
| OLD | NEW |