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.LOLLIPOP) | |
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 // Note: getBoolean is only available in API level 22, so the data i s serialized via | |
67 // ints instead. | |
68 @Override | |
69 public boolean isClientInMetricsSample() { | |
70 return mPermissions.getInt(IS_CLIENT_IN_METRICS_SAMPLE, 1) == 1; | |
71 } | |
Maria
2017/03/14 19:03:32
nit: I think there should still be newlines betwee
Ilya Sherman
2017/03/15 02:13:34
Done.
| |
72 @Override | |
73 public boolean isNetworkAvailableForCrashUploads() { | |
74 // TODO(isherman): This code should really be shared with the An droid Webview | |
75 // implementation, which tests whether the connection is metered , rather than | |
76 // testing the type of the connection. Implement this change in M59 -- for M58, it's | |
77 // more important to maintain consistency with the previous impl ementation. When | |
78 // changing this, note that forced uploads do *not* require unme tered connections. | |
79 NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkI nfo(); | |
80 if (networkInfo == null || !networkInfo.isConnected()) return fa lse; | |
81 return networkInfo.getType() == ConnectivityManager.TYPE_WIFI | |
82 || networkInfo.getType() == ConnectivityManager.TYPE_ETH ERNET; | |
83 } | |
84 @Override | |
85 public boolean isCrashUploadDisabledByCommandLine() { | |
86 return mPermissions.getInt(IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_L INE, 0) == 1; | |
87 } | |
88 @Override | |
89 public boolean isMetricsUploadPermitted() { | |
90 // This method is already represented by isClientInMetricsSample () and | |
91 // isNetworkAvailableForCrashUploads(), so it's fine to return a dummy value. | |
92 return true; | |
93 } | |
94 @Override | |
95 public boolean isUsageAndCrashReportingPermittedByUser() { | |
96 return PrivacyPreferencesManager.getInstance() | |
97 .isUsageAndCrashReportingPermittedByUser(); | |
98 } | |
99 @Override | |
100 public boolean isUploadEnabledForTests() { | |
101 return mPermissions.getInt(IS_UPLOAD_ENABLED_FOR_TESTS, 0) == 1; | |
102 } | |
103 }; | |
104 } | |
105 | |
106 @Override | |
107 public void prepareToUploadMinidumps(final Runnable startUploads) { | |
108 startUploads.run(); | |
109 } | |
110 | |
111 @Override | |
112 public void recordUploadSuccess(File minidump) { | |
113 MinidumpUploadService.incrementCrashSuccessUploadCount(minidump.getAbsol utePath()); | |
114 } | |
115 | |
116 @Override | |
117 public void recordUploadFailure(File minidump) { | |
118 MinidumpUploadService.incrementCrashFailureUploadCount(minidump.getAbsol utePath()); | |
119 } | |
120 } | |
OLD | NEW |