OLD | NEW |
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.content.Context; | 7 import android.content.Context; |
8 import android.net.ConnectivityManager; | 8 import android.net.ConnectivityManager; |
9 import android.net.NetworkInfo; | |
10 import android.webkit.ValueCallback; | 9 import android.webkit.ValueCallback; |
11 | 10 |
12 import org.chromium.android_webview.PlatformServiceBridge; | 11 import org.chromium.android_webview.PlatformServiceBridge; |
13 import org.chromium.android_webview.command_line.CommandLineUtil; | 12 import org.chromium.android_webview.command_line.CommandLineUtil; |
14 import org.chromium.base.CommandLine; | 13 import org.chromium.base.CommandLine; |
15 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
16 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
17 import org.chromium.components.minidump_uploader.MinidumpUploaderDelegate; | 16 import org.chromium.components.minidump_uploader.MinidumpUploaderDelegate; |
18 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; | 17 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
| 18 import org.chromium.components.minidump_uploader.util.NetworkPermissionUtil; |
19 | 19 |
20 import java.io.File; | 20 import java.io.File; |
21 | 21 |
22 /** | 22 /** |
23 * Android Webview-specific implementations for minidump uploading logic. | 23 * Android Webview-specific implementations for minidump uploading logic. |
24 */ | 24 */ |
25 public class AwMinidumpUploaderDelegate implements MinidumpUploaderDelegate { | 25 public class AwMinidumpUploaderDelegate implements MinidumpUploaderDelegate { |
26 private final Context mContext; | 26 private final Context mContext; |
27 private final ConnectivityManager mConnectivityManager; | 27 private final ConnectivityManager mConnectivityManager; |
28 | 28 |
(...skipping 18 matching lines...) Expand all Loading... |
47 public boolean isClientInMetricsSample() { | 47 public boolean isClientInMetricsSample() { |
48 // We will check whether the client is in the metrics sample bef
ore | 48 // We will check whether the client is in the metrics sample bef
ore |
49 // generating a minidump - so if no minidump is generated this c
ode will | 49 // generating a minidump - so if no minidump is generated this c
ode will |
50 // never run and we don't need to check whether we are in the sa
mple. | 50 // never run and we don't need to check whether we are in the sa
mple. |
51 // TODO(gsennton): when we switch to using Finch for this value
we should use the | 51 // TODO(gsennton): when we switch to using Finch for this value
we should use the |
52 // Finch value here as well. | 52 // Finch value here as well. |
53 return true; | 53 return true; |
54 } | 54 } |
55 @Override | 55 @Override |
56 public boolean isNetworkAvailableForCrashUploads() { | 56 public boolean isNetworkAvailableForCrashUploads() { |
57 // JobScheduler will call onStopJob causing our upload to be int
errupted when our | 57 // Note that this is the same critierion that the JobScheduler u
ses to schedule the |
58 // network requirements no longer hold. | 58 // job. JobScheduler will call onStopJob causing our upload to b
e interrupted when |
59 // TODO(isherman): This code should really be shared with Chrome
. Chrome currently | 59 // our network requirements no longer hold. |
60 // checks only whether the network is WiFi (or ethernet) vs. cel
lular. Most likely, | 60 return NetworkPermissionUtil.isNetworkUnmetered(mConnectivityMan
ager); |
61 // Chrome should instead check whether the network is metered, a
s is done here. | |
62 NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkI
nfo(); | |
63 if (networkInfo == null || !networkInfo.isConnected()) return fa
lse; | |
64 return !mConnectivityManager.isActiveNetworkMetered(); | |
65 } | 61 } |
66 @Override | 62 @Override |
67 public boolean isUsageAndCrashReportingPermittedByUser() { | 63 public boolean isUsageAndCrashReportingPermittedByUser() { |
68 return mPermittedByUser; | 64 return mPermittedByUser; |
69 } | 65 } |
70 @Override | 66 @Override |
71 public boolean isUploadEnabledForTests() { | 67 public boolean isUploadEnabledForTests() { |
72 // Note that CommandLine/CommandLineUtil are not thread safe. Th
ey are initialized | 68 // Note that CommandLine/CommandLineUtil are not thread safe. Th
ey are initialized |
73 // on the main thread, but before the current worker thread star
ted - so this thread | 69 // on the main thread, but before the current worker thread star
ted - so this thread |
74 // will have seen the initialization of the CommandLine. | 70 // will have seen the initialization of the CommandLine. |
(...skipping 22 matching lines...) Expand all Loading... |
97 | 93 |
98 /** | 94 /** |
99 * Utility method to allow us to test the logic of this class by injecting | 95 * Utility method to allow us to test the logic of this class by injecting |
100 * a test-specific PlatformServiceBridge. | 96 * a test-specific PlatformServiceBridge. |
101 */ | 97 */ |
102 @VisibleForTesting | 98 @VisibleForTesting |
103 public PlatformServiceBridge createPlatformServiceBridge() { | 99 public PlatformServiceBridge createPlatformServiceBridge() { |
104 return PlatformServiceBridge.getInstance(mContext); | 100 return PlatformServiceBridge.getInstance(mContext); |
105 } | 101 } |
106 } | 102 } |
OLD | NEW |