From f06d8698a4a2de1973a25df0c6563bdfcba4eb03 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Thu, 11 Jun 2009 22:32:33 -0700 Subject: [PATCH] Add setting for allowing Google to use location for better search results. --- res/values/strings.xml | 18 ++- res/xml/security_settings.xml | 11 +- src/com/android/settings/SecuritySettings.java | 148 +++++++++++++++++++++++-- 3 files changed, 159 insertions(+), 18 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 26d7588c73..3d1b5d56b6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1130,7 +1130,7 @@ Set options for roaming, networks, APNs - My Location sources + My Location Use wireless networks @@ -1143,9 +1143,19 @@ When locating, accurate to street level (deselect to conserve battery) Locate to street-level (requires more battery plus view of sky) - - - + + Share with Google + + Allow Google to use location for improved search results and other services + + Allow Google to use location for improved search results and other services + + Agree + + Disagree + + + About phone diff --git a/res/xml/security_settings.xml b/res/xml/security_settings.xml index 788aae3d65..8dd9d897b3 100644 --- a/res/xml/security_settings.xml +++ b/res/xml/security_settings.xml @@ -17,11 +17,12 @@ @@ -30,7 +31,13 @@ android:title="@string/location_gps" android:summaryOn="@string/location_street_level" android:summaryOff="@string/location_gps_disabled"/> - + + + diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index ccf360ae5c..41b4148ae2 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -18,10 +18,14 @@ package com.android.settings; import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; import android.content.ContentQueryMap; +import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; +import android.content.pm.PackageManager.NameNotFoundException; import android.database.Cursor; import android.location.LocationManager; import android.net.vpn.VpnManager; @@ -30,20 +34,22 @@ import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceCategory; +import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.provider.Settings; -import android.util.Config; -import android.util.Log; +import android.text.method.LinkMovementMethod; +import android.widget.TextView; + +import com.android.internal.widget.LockPatternUtils; import java.util.Observable; import java.util.Observer; -import com.android.internal.widget.LockPatternUtils; - /** * Gesture lock pattern settings. */ -public class SecuritySettings extends PreferenceActivity { +public class SecuritySettings extends PreferenceActivity implements + DialogInterface.OnDismissListener, DialogInterface.OnClickListener { // Lock Settings @@ -61,10 +67,18 @@ public class SecuritySettings extends PreferenceActivity { private CheckBoxPreference mShowPassword; // Location Settings - + private static final String LOCATION_CATEGORY = "location_category"; private static final String LOCATION_NETWORK = "location_network"; private static final String LOCATION_GPS = "location_gps"; + // Vendor specific + private static final String GSETTINGS_PROVIDER = "com.google.android.providers.settings"; + private static final String USE_LOCATION = "use_location"; + private static final String KEY_DONE_USE_LOCATION = "doneLocation"; + private CheckBoxPreference mUseLocation; + private boolean mOkClicked; + private Dialog mUseLocationDialog; + private CheckBoxPreference mNetwork; private CheckBoxPreference mGps; @@ -89,6 +103,17 @@ public class SecuritySettings extends PreferenceActivity { mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK); mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS); + mUseLocation = (CheckBoxPreference) getPreferenceScreen().findPreference(USE_LOCATION); + + // Vendor specific + try { + if (mUseLocation != null + && getPackageManager().getPackageInfo(GSETTINGS_PROVIDER, 0) == null) { + ((PreferenceGroup)findPreference(LOCATION_CATEGORY)) + .removePreference(mUseLocation); + } + } catch (NameNotFoundException nnfe) { + } updateToggles(); // listen for Location Manager settings changes @@ -98,6 +123,11 @@ public class SecuritySettings extends PreferenceActivity { null); mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null); mContentQueryMap.addObserver(new SettingsObserver()); + boolean doneUseLocation = savedInstanceState != null + && savedInstanceState.getBoolean(KEY_DONE_USE_LOCATION, true); + if (getIntent().getBooleanExtra("SHOW_USE_LOCATION", false) && !doneUseLocation) { + showUseLocationDialog(true); + } } private PreferenceScreen createPreferenceHierarchy() { @@ -199,6 +229,23 @@ public class SecuritySettings extends PreferenceActivity { } @Override + public void onPause() { + if (mUseLocationDialog != null && mUseLocationDialog.isShowing()) { + mUseLocationDialog.dismiss(); + } + mUseLocationDialog = null; + super.onPause(); + } + + @Override + public void onSaveInstanceState(Bundle icicle) { + if (mUseLocationDialog != null && mUseLocationDialog.isShowing()) { + icicle.putBoolean(KEY_DONE_USE_LOCATION, false); + } + super.onSaveInstanceState(icicle); + } + + @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); @@ -218,25 +265,84 @@ public class SecuritySettings extends PreferenceActivity { } else if (preference == mGps) { Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, mGps.isChecked()); + } else if (preference == mUseLocation) { + //normally called on the toggle click + if (mUseLocation.isChecked()) { + showUseLocationDialog(false); + } else { + updateUseLocation(); + } } return false; } + private void showPrivacyPolicy() { + Intent intent = new Intent("android.settings.TERMS"); + startActivity(intent); + } + + private void showUseLocationDialog(boolean force) { + // Show a warning to the user that location data will be shared + mOkClicked = false; + if (force) { + mUseLocation.setChecked(true); + } + /* + Resources res = getResources(); + CharSequence msg = new SpannableString( + res.getText(R.string.use_location_warning_message)); + SpannableString spannable = (SpannableString) msg; + Annotation[] spans = spannable.getSpans(0, spannable.length(), Annotation.class); + if (spans != null && spans.length > 0) { + SpannableStringBuilder builder = new SpannableStringBuilder(spannable); + int start = spannable.getSpanStart(spans[0]); + int end = spannable.getSpanEnd(spans[0]); + ClickableSpan link = new ClickableSpan() { + @Override + public void onClick(View view) { + showPrivacyPolicy(); + } + }; + builder.setSpan(link, start, end, spannable.getSpanFlags(link)); + msg = builder; + } + */ + CharSequence msg = getResources().getText(R.string.use_location_warning_message); + mUseLocationDialog = new AlertDialog.Builder(this).setMessage(msg) + .setTitle(R.string.use_location_title) + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.agree, this) + .setNegativeButton(R.string.disagree, this) + .show(); + ((TextView)mUseLocationDialog.findViewById(android.R.id.message)) + .setMovementMethod(LinkMovementMethod.getInstance()); + mUseLocationDialog.setOnDismissListener(this); + } + /* * Creates toggles for each available location provider */ private void updateToggles() { + ContentResolver res = getContentResolver(); mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled( - getContentResolver(), LocationManager.NETWORK_PROVIDER)); + res, LocationManager.NETWORK_PROVIDER)); mGps.setChecked(Settings.Secure.isLocationProviderEnabled( - getContentResolver(), LocationManager.GPS_PROVIDER)); + res, LocationManager.GPS_PROVIDER)); + mUseLocation.setChecked(Settings.Gservices.getInt(res, + Settings.Gservices.USE_LOCATION_FOR_SERVICES, 2) == 1); } private boolean isToggled(Preference pref) { return ((CheckBoxPreference) pref).isChecked(); } + private void updateUseLocation() { + boolean use = mUseLocation.isChecked(); + Settings.Gservices.putString(getContentResolver(), + Settings.Gservices.USE_LOCATION_FOR_SERVICES, use ? "1" : "0"); + } + /** * For the user to disable keyguard, we first make them verify their @@ -272,15 +378,33 @@ public class SecuritySettings extends PreferenceActivity { * @see #confirmPatternThenDisableAndClear */ @Override - protected void onActivityResult(int requestCode, int resultCode, - Intent data) { + protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); final boolean resultOk = resultCode == Activity.RESULT_OK; - if ((requestCode == CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE) && resultOk) { + if ((requestCode == CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE) + && resultOk) { mLockPatternUtils.setLockPatternEnabled(false); mLockPatternUtils.saveLockPattern(null); } } + + public void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_POSITIVE) { + //updateProviders(); + mOkClicked = true; + } else { + // Reset the toggle + mUseLocation.setChecked(false); + } + updateUseLocation(); + } + + public void onDismiss(DialogInterface dialog) { + // Assuming that onClick gets called first + if (!mOkClicked) { + mUseLocation.setChecked(false); + } + } } -- 2.11.0