Skip to content

Commit

Permalink
AW: remove obsolete check for Safe Browsing user-opt-out
Browse files Browse the repository at this point in the history
This removes obsolete code in open source. This setting doesn't actually
exist on AOSP devices (it's a Google setting), and this wasn't a
reliable way of checking it.

Instead, we check SafetyNetClient#isVerifyAppsEnabled() within private
code. This has been implemented in internal CL #391708

Bug: 701621, 700606
Test: Manual - toggled the setting on/off, testing on L-O devices
Change-Id: I46c728cb4b553ae07c6383246df279d05102879b
Reviewed-on: https://chromium-review.googlesource.com/529710
Reviewed-by: Selim Gurun <sgurun@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478447}
  • Loading branch information
ntfschr-chromium authored and Commit Bot committed Jun 9, 2017
1 parent 06187f5 commit dc6020d
Showing 1 changed file with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

package org.chromium.android_webview;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.provider.Settings;

import org.chromium.base.CommandLine;
import org.chromium.base.Log;
Expand All @@ -26,25 +22,15 @@ public class AwSafeBrowsingConfigHelper {
private static final String OPT_IN_META_DATA_STR = "android.webkit.WebView.EnableSafeBrowsing";

public static void maybeInitSafeBrowsingFromSettings(final Context appContext) {
if (AwSafeBrowsingConfigHelper.shouldEnableSafeBrowsingSupport(appContext)) {
// Assume safebrowsing on by default initially.
if (CommandLine.getInstance().hasSwitch(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
|| appHasOptedIn(appContext)) {
// Assume safebrowsing on by default initially. If GMS is available, we later use
// isVerifyAppsEnabled() to check if "Scan device for security threats" has been checked
// by the user.
AwContentsStatics.setSafeBrowsingEnabled(true);
// Fetch Android settings related to safe-browsing in the background.
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
AwContentsStatics.setSafeBrowsingEnabled(
isScanDeviceForSecurityThreatsEnabled(appContext));
}
});
}
}

private static boolean shouldEnableSafeBrowsingSupport(Context appContext) {
return CommandLine.getInstance().hasSwitch(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
|| appHasOptedIn(appContext);
}

private static boolean appHasOptedIn(Context appContext) {
try {
ApplicationInfo info = appContext.getPackageManager().getApplicationInfo(
Expand All @@ -63,14 +49,6 @@ private static boolean appHasOptedIn(Context appContext) {
}
}

@SuppressLint("NewApi") // android.provider.Settings.Global#getInt requires API level 17
private static boolean isScanDeviceForSecurityThreatsEnabled(Context applicationContext) {
// Determine if the "Scan device for security threats" functionality is enabled in
// Android->System->Google->Security settings.
ContentResolver contentResolver = applicationContext.getContentResolver();
return Settings.Secure.getInt(contentResolver, "package_verifier_user_consent", 1) > 0;
}

// Not meant to be instantiated.
private AwSafeBrowsingConfigHelper() {}
}

0 comments on commit dc6020d

Please sign in to comment.