Add an experimental webview setting to dev options.

Bug:12492817

Add an experimental webview setting to developer options to enable
data reduction proxy.

Change-Id: I6e0931b39c8dd129622129589ae67352c8396cd2
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 28eaa13..cea89c5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4538,6 +4538,12 @@
     <string name="show_all_anrs_summary">Show App Not Responding dialog
         for background apps</string>
 
+    <!-- UI debug setting: webview data reduction proxy [CHAR LIMIT=25] -->
+    <string name="webview_data_reduction_proxy">Reduce WebView Network Usage</string>
+    <!-- UI debug setting: webview data reduction proxy summary [CHAR LIMIT=150] -->
+    <string name="webview_data_reduction_proxy_summary">Reduce network usage by
+        proxying WebView connections through Google compression servers (Experimental)</string>
+
     <!-- Activity title for network data usage summary. [CHAR LIMIT=25] -->
     <string name="data_usage_summary_title">Data usage</string>
     <!-- Title for option to pick visible time range from a list available usage periods. [CHAR LIMIT=25] -->
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index e9aeae8..ef929b2 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -4,9 +4,9 @@
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
-  
+
           http://www.apache.org/licenses/LICENSE-2.0
-  
+
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,9 +32,9 @@
                 android:targetClass="com.android.settings.SetFullBackupPassword" />
     </PreferenceScreen>
 
-    <CheckBoxPreference 
-        android:key="keep_screen_on" 
-        android:title="@string/keep_screen_on" 
+    <CheckBoxPreference
+        android:key="keep_screen_on"
+        android:title="@string/keep_screen_on"
         android:summary="@string/keep_screen_on_summary"/>
 
     <ListPreference
@@ -286,6 +286,10 @@
             android:title="@string/show_all_anrs"
             android:summary="@string/show_all_anrs_summary"/>
 
+        <CheckBoxPreference
+            android:key="webview_data_reduction_proxy"
+            android:title="@string/webview_data_reduction_proxy"
+            android:summary="@string/webview_data_reduction_proxy_summary"/>
      </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index bbee5e9..328cae9 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -60,6 +60,7 @@
 import android.view.IWindowManager;
 import android.view.View;
 import android.view.accessibility.AccessibilityManager;
+import android.webkit.WebView;
 import android.widget.CompoundButton;
 import android.widget.Switch;
 import android.widget.TextView;
@@ -144,6 +145,8 @@
 
     private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
 
+    private static final String WEBVIEW_DATA_REDUCTION_PROXY_KEY = "webview_data_reduction_proxy";
+
     private static final String PROCESS_STATS = "proc_stats";
 
     private static final String TAG_CONFIRM_ENFORCE = "confirm_enforce";
@@ -209,6 +212,8 @@
 
     private CheckBoxPreference mShowAllANRs;
 
+    private CheckBoxPreference mWebViewDataReductionProxy;
+
     private PreferenceScreen mProcessStats;
 
     private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
@@ -340,6 +345,8 @@
 
         mProcessStats = (PreferenceScreen) findPreference(PROCESS_STATS);
         mAllPrefs.add(mProcessStats);
+
+        mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY);
     }
 
     private ListPreference addListPreference(String prefKey) {
@@ -515,6 +522,7 @@
         updateImmediatelyDestroyActivitiesOptions();
         updateAppProcessLimitOptions();
         updateShowAllANRsOptions();
+        updateWebViewDataReductionProxyOptions();
         updateVerifyAppsOverUsbOptions();
         updateBugreportOptions();
         updateForceRtlOptions();
@@ -1193,6 +1201,20 @@
             getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
     }
 
+    private void writeWebViewDataReductionProxyOptions() {
+        Settings.Secure.putInt(getActivity().getContentResolver(),
+                Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY,
+                mWebViewDataReductionProxy.isChecked() ? 1 : 0);
+        Intent intent = new Intent(WebView.DATA_REDUCTION_PROXY_SETTING_CHANGED);
+        getActivity().sendBroadcast(intent);
+    }
+
+    private void updateWebViewDataReductionProxyOptions() {
+        updateCheckBox(mWebViewDataReductionProxy, Settings.Secure.getInt(
+            getActivity().getContentResolver(),
+            Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0) != 0);
+    }
+
     @Override
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
         if (buttonView == mEnabledSwitch) {
@@ -1309,6 +1331,8 @@
             writeImmediatelyDestroyActivitiesOptions();
         } else if (preference == mShowAllANRs) {
             writeShowAllANRsOptions();
+        } else if (preference == mWebViewDataReductionProxy) {
+            writeWebViewDataReductionProxyOptions();
         } else if (preference == mForceHardwareUi) {
             writeHardwareUiOptions();
         } else if (preference == mForceMsaa) {