| Index: android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java b/android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java
|
| index f3b994ef35a72f4493662f589bd7f807a26eb0f6..2fb213ae49a08aa86072371e0a8b848513e34315 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java
|
| +++ b/android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java
|
| @@ -15,7 +15,10 @@ import android.os.Binder;
|
| import android.os.Build;
|
| import android.os.IBinder;
|
| import android.os.ParcelFileDescriptor;
|
| +import android.webkit.ValueCallback;
|
|
|
| +import org.chromium.android_webview.PlatformServiceBridge;
|
| +import org.chromium.android_webview.command_line.CommandLineUtil;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.VisibleForTesting;
|
| import org.chromium.components.minidump_uploader.CrashFileManager;
|
| @@ -44,26 +47,93 @@ public class CrashReceiverService extends Service {
|
| private Object mCopyingLock = new Object();
|
| private boolean mIsCopying = false;
|
|
|
| - // same switch as kEnableCrashReporterForTesting in //base/base_switches.h
|
| - static final String CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH =
|
| - "enable-crash-reporter-for-testing";
|
| + private ConsentManager mConsentManager = new ConsentManager();
|
| +
|
| + private static class ConsentManager {
|
| + private static final int CONSENT_NOT_RETURNED = 0;
|
| + private static final int CONSENT_OK = 1;
|
| + private static final int CONSENT_NOT_OK = 2;
|
| +
|
| + private Object mLock = new Object();
|
| + private int mConsentValue = CONSENT_NOT_RETURNED;
|
| +
|
| + private void resetConsentState() {
|
| + synchronized (mLock) {
|
| + mConsentValue = CONSENT_NOT_RETURNED;
|
| + }
|
| + }
|
| +
|
| + private void setConsentValue(boolean ok) {
|
| + synchronized (mLock) {
|
| + assert mConsentValue == CONSENT_NOT_RETURNED;
|
| + mConsentValue = ok ? CONSENT_OK : CONSENT_NOT_OK;
|
| + mLock.notifyAll();
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Wait until a consent value was received, and return that value.
|
| + */
|
| + private boolean getConsentValue() {
|
| + synchronized (mLock) {
|
| + while (mConsentValue == CONSENT_NOT_RETURNED) {
|
| + try {
|
| + mLock.wait();
|
| + } catch (InterruptedException e) {
|
| + break;
|
| + }
|
| + }
|
| + return mConsentValue == CONSENT_OK;
|
| + }
|
| + }
|
| + }
|
|
|
| @Override
|
| public void onCreate() {
|
| super.onCreate();
|
| - SynchronizedWebViewCommandLine.initOnSeparateThread();
|
| + getSynchronizedWebViewCommandLine().initOnSeparateThread();
|
| +
|
| + mConsentManager.resetConsentState();
|
| + PlatformServiceBridge platformServiceBridge = getPlaformServiceBridge();
|
| + if (platformServiceBridge.canUseGms()) {
|
| + platformServiceBridge.queryMetricsSetting(new ValueCallback<Boolean>() {
|
| + @Override
|
| + public void onReceiveValue(Boolean enabled) {
|
| + mConsentManager.setConsentValue(enabled);
|
| + }
|
| + });
|
| + } else {
|
| + mConsentManager.setConsentValue(false);
|
| + }
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + final boolean isCrashCopyingEnabled() {
|
| + if (getSynchronizedWebViewCommandLine().hasSwitch(
|
| + CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH)) {
|
| + return true;
|
| + }
|
| + return mConsentManager.getConsentValue();
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + SynchronizedWebViewCommandLine getSynchronizedWebViewCommandLine() {
|
| + return SynchronizedWebViewCommandLine.getInstance();
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + PlatformServiceBridge getPlaformServiceBridge() {
|
| + return PlatformServiceBridge.getInstance(this);
|
| }
|
|
|
| private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService.Stub() {
|
| @Override
|
| public void transmitCrashes(ParcelFileDescriptor[] fileDescriptors) {
|
| - // TODO(gsennton): replace this check with a check for Android Checkbox when we have
|
| - // access to that value through GmsCore.
|
| - if (!SynchronizedWebViewCommandLine.hasSwitch(
|
| - CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH)) {
|
| + if (!isCrashCopyingEnabled()) {
|
| Log.i(TAG, "Crash reporting is not enabled, bailing!");
|
| return;
|
| }
|
| +
|
| int uid = Binder.getCallingUid();
|
| performMinidumpCopyingSerially(
|
| CrashReceiverService.this, uid, fileDescriptors, true /* scheduleUploads */);
|
|
|