diff options
author | Selim Gurun <sgurun@google.com> | 2014-08-23 08:32:09 -0700 |
---|---|---|
committer | Selim Gurun <sgurun@google.com> | 2014-08-23 08:32:09 -0700 |
commit | b56bab1fd4ada2b930009e43e2b03ace59c66f58 (patch) | |
tree | a9ede310a0ad8ad4e3c2aaad4eb9c37f889b6fb9 /src/com | |
parent | b7b686cadf6a07c74672d4e1c3aab30e7d24a545 (diff) | |
download | packages_apps_Settings-b56bab1fd4ada2b930009e43e2b03ace59c66f58.zip packages_apps_Settings-b56bab1fd4ada2b930009e43e2b03ace59c66f58.tar.gz packages_apps_Settings-b56bab1fd4ada2b930009e43e2b03ace59c66f58.tar.bz2 |
Use GoogleSetting to override DRP setting if available
Bug: 12492817
The developer setting will be deprecated and eventually will be
removed after the setting is moved to its new location.
This is the prep work for it.
Change-Id: If0b019b33a544b7d2e659161685fa33ca052f612
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 11dc3c6..76e80e6 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -31,7 +31,9 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; +import android.database.Cursor; import android.hardware.usb.IUsbManager; +import android.net.Uri; import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.BatteryManager; @@ -152,6 +154,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs"; private static final String WEBVIEW_DATA_REDUCTION_PROXY_KEY = "webview_data_reduction_proxy"; + // GoogleSetting name for the data reduction proxy setting. + // Setting type: int ( 0 = disallow, 1 = allow ) + private static final String WEBVIEW_DATA_REDUCTION_PROXY = "use_webview_data_reduction_proxy"; private static final String PROCESS_STATS = "proc_stats"; @@ -165,6 +170,11 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; + // The setting Uri. Used when querying GoogleSettings. + private static final Uri GOOGLE_SETTINGS_CONTENT_URI = Uri.parse("content://com.google.settings/partner"); + private static final String GOOGLE_SETTINGS_COMPONENT = "com.google.android.gms"; + private static final String GOOGLE_SETTINGS_ACTIVITY = ".app.settings.GoogleSettingsActivity"; + private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K private IWindowManager mWindowManager; @@ -369,6 +379,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mAllPrefs.add(mProcessStats); mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY); + mWebViewDataReductionProxy.setOnPreferenceChangeListener( + new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + return handleDataReductionProxyPreferenceChange(); + } + }); } private ListPreference addListPreference(String prefKey) { @@ -1272,6 +1289,50 @@ public class DevelopmentSettings extends SettingsPreferenceFragment getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0); } + // Reads the googlesetting and converts to an int. Throws an exception if GoogleSettings + // provider does not exist or if the setting name cannot be found. + private int getGoogleSettingValue(String name) throws Exception { + String value = null; + Cursor c = null; + try { + ContentResolver resolver = getActivity().getContentResolver(); + c = resolver.query(GOOGLE_SETTINGS_CONTENT_URI, new String[] { "value" }, + "name=?", new String[]{ name }, null); + if (c != null && c.moveToNext()) value = c.getString(0); + } finally { + if (c != null) c.close(); + } + // Throw an exception if value is null. This will indicate that setting is not found. + return Integer.parseInt(value); + } + + private boolean handleDataReductionProxyPreferenceChange() { + int val; + try { + val = getGoogleSettingValue(WEBVIEW_DATA_REDUCTION_PROXY); + } catch (Exception e) { + // Accessing GoogleSettings failed. Use the developer setting. + return true; + } + + Intent i = new Intent(); + i.setClassName(GOOGLE_SETTINGS_COMPONENT, + GOOGLE_SETTINGS_COMPONENT + GOOGLE_SETTINGS_ACTIVITY); + try { + startActivity(i); + } catch (android.content.ActivityNotFoundException ex) { + // We found the GoogleSetting but for some reason activity not found. + // Do our best and put an alert dialog + new AlertDialog.Builder(getActivity()).setMessage( + getActivity().getResources().getString( + R.string.dev_settings_use_google_settings)) + .setPositiveButton(android.R.string.ok, this) + .show(); + } + // Use GoogleSettings to set. + return false; + } + private void writeWebViewDataReductionProxyOptions() { Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, @@ -1282,9 +1343,17 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } private void updateWebViewDataReductionProxyOptions() { - updateCheckBox(mWebViewDataReductionProxy, Settings.Secure.getInt( - getActivity().getContentResolver(), - Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0) != 0); + int val = -1; + try { + val = getGoogleSettingValue(WEBVIEW_DATA_REDUCTION_PROXY); + } catch (Exception e) { + // Accessing GoogleSettings failed. Use the developer setting + } + if (val == -1) { + val = Settings.Secure.getInt(getActivity().getContentResolver(), + Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0); + } + updateCheckBox(mWebViewDataReductionProxy, val != 0); } @Override |