forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android Crash Reporting] Componentize MinidumpUploadImpl.java
BUG=694884 TEST=compile, android_webview_test_apk R=gsennton@chromium.org Review-Url: https://codereview.chromium.org/2709163008 Cr-Commit-Position: refs/heads/master@{#454390}
- Loading branch information
1 parent
5c97d3e
commit 375b5de
Showing
7 changed files
with
219 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
android_webview/java/src/org/chromium/android_webview/crash/AwMinidumpUploaderDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.android_webview.crash; | ||
|
||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import android.webkit.ValueCallback; | ||
|
||
import org.chromium.android_webview.PlatformServiceBridge; | ||
import org.chromium.android_webview.command_line.CommandLineUtil; | ||
import org.chromium.base.CommandLine; | ||
import org.chromium.base.ThreadUtils; | ||
import org.chromium.base.VisibleForTesting; | ||
import org.chromium.components.minidump_uploader.MinidumpUploaderDelegate; | ||
import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Android Webview-specific implementations for minidump uploading logic. | ||
*/ | ||
public class AwMinidumpUploaderDelegate implements MinidumpUploaderDelegate { | ||
private final Context mContext; | ||
private final ConnectivityManager mConnectivityManager; | ||
|
||
private boolean mPermittedByUser = false; | ||
|
||
@VisibleForTesting | ||
public AwMinidumpUploaderDelegate(Context context) { | ||
mContext = context; | ||
mConnectivityManager = | ||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
} | ||
|
||
@Override | ||
public File createCrashDir() { | ||
return CrashReceiverService.createWebViewCrashDir(mContext); | ||
} | ||
|
||
@Override | ||
public CrashReportingPermissionManager createCrashReportingPermissionManager() { | ||
return new CrashReportingPermissionManager() { | ||
@Override | ||
public boolean isClientInMetricsSample() { | ||
// We will check whether the client is in the metrics sample before | ||
// generating a minidump - so if no minidump is generated this code will | ||
// never run and we don't need to check whether we are in the sample. | ||
// TODO(gsennton): when we switch to using Finch for this value we should use the | ||
// Finch value here as well. | ||
return true; | ||
} | ||
@Override | ||
public boolean isNetworkAvailableForCrashUploads() { | ||
// JobScheduler will call onStopJob causing our upload to be interrupted when our | ||
// network requirements no longer hold. | ||
// TODO(isherman): This code should really be shared with Chrome. Chrome currently | ||
// checks only whether the network is WiFi (or ethernet) vs. cellular. Most likely, | ||
// Chrome should instead check whether the network is metered, as is done here. | ||
NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); | ||
if (networkInfo == null || !networkInfo.isConnected()) return false; | ||
return !mConnectivityManager.isActiveNetworkMetered(); | ||
} | ||
@Override | ||
public boolean isCrashUploadDisabledByCommandLine() { | ||
return false; | ||
} | ||
/** | ||
* This method is already represented by isClientInMetricsSample() and | ||
* isNetworkAvailableForCrashUploads(). | ||
*/ | ||
@Override | ||
public boolean isMetricsUploadPermitted() { | ||
return true; | ||
} | ||
@Override | ||
public boolean isUsageAndCrashReportingPermittedByUser() { | ||
return mPermittedByUser; | ||
} | ||
@Override | ||
public boolean isUploadEnabledForTests() { | ||
// Note that CommandLine/CommandLineUtil are not thread safe. They are initialized | ||
// on the main thread, but before the current worker thread started - so this thread | ||
// will have seen the initialization of the CommandLine. | ||
return CommandLine.getInstance().hasSwitch( | ||
CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void prepareToUploadMinidumps(final Runnable startUploads) { | ||
createPlatformServiceBridge().queryMetricsSetting(new ValueCallback<Boolean>() { | ||
public void onReceiveValue(Boolean enabled) { | ||
ThreadUtils.assertOnUiThread(); | ||
mPermittedByUser = enabled; | ||
startUploads.run(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Utility method to allow us to test the logic of this class by injecting | ||
* a test-specific PlatformServiceBridge. | ||
*/ | ||
@VisibleForTesting | ||
public PlatformServiceBridge createPlatformServiceBridge() { | ||
return PlatformServiceBridge.getInstance(mContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../android/java/src/org/chromium/components/minidump_uploader/MinidumpUploaderDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.components.minidump_uploader; | ||
|
||
import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Interface for embedder-specific implementations for uploading minidumps. | ||
*/ | ||
public interface MinidumpUploaderDelegate { | ||
/** | ||
* Creates the directory in which the embedder will store its minidumps. | ||
* @return A reference to the created directory, or null if the creation failed. | ||
*/ | ||
File createCrashDir(); | ||
|
||
/** | ||
* Creates the permission manager used to evaluate whether uploading should be allowed. | ||
* @return The permission manager. | ||
*/ | ||
CrashReportingPermissionManager createCrashReportingPermissionManager(); | ||
|
||
/** | ||
* Performs any pre-work necessary for uploading minidumps, then calls the {@param startUploads} | ||
* continuation to initiate uploading the minidumps. | ||
* @param startUploads The continuation to call once any necessary pre-work is completed. | ||
*/ | ||
void prepareToUploadMinidumps(Runnable startUploads); | ||
} |
Oops, something went wrong.