From d3863aa6641cd07130e22806d76f42c850a73949 Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Thu, 21 Mar 2013 12:16:52 -0700 Subject: [PATCH] Notify user that scans are still active Bug: 8141918 Change-Id: I115ce2ac57125b8ffbb34245dc25effd4b3bebb0 --- AndroidManifest.xml | 9 ++ res/values/strings.xml | 4 + .../wifi/WifiNotifyScanModeActivity.java | 133 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/com/android/settings/wifi/WifiNotifyScanModeActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 964650c74b7..95798302ac1 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1209,6 +1209,15 @@ + + + + + + + Scanning always available Let Google\'s location service and other apps scan for networks, even when Wi-Fi is off + To improve location accuracy and for other purposes, Google and other apps may scan for nearby networks, even when Wi-Fi is off. If you don\'t want this to happen, go to Advanced > Scanning always available. + Apps may scan for nearby networks, even when Wi-Fi is off. If you don\'t want this to happen, go to Advanced > Scanning always available. + + Don\'t show again Keep Wi\u2011Fi on during sleep diff --git a/src/com/android/settings/wifi/WifiNotifyScanModeActivity.java b/src/com/android/settings/wifi/WifiNotifyScanModeActivity.java new file mode 100644 index 00000000000..3356b060b53 --- /dev/null +++ b/src/com/android/settings/wifi/WifiNotifyScanModeActivity.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.wifi; + +import com.android.settings.R; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.content.Intent; +import android.location.LocationManager; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.provider.Settings; +import android.view.View; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; + +/** + * This activity notifies the user that wifi scans are still available when Wi-Fi is being + * turned off + */ +public class WifiNotifyScanModeActivity extends Activity { + private DialogFragment mDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent = getIntent(); + if (intent != null && intent.getAction() + .equals(WifiManager.ACTION_NOTIFY_SCAN_ALWAYS_AVAILABLE)) { + createDialog(); + } else { + finish(); + return; + } + } + + private void createDialog() { + if (mDialog == null) { + mDialog = AlertDialogFragment.newInstance(); + mDialog.show(getFragmentManager(), "dialog"); + } + } + + private void dismissDialog() { + if (mDialog != null) { + mDialog.dismiss(); + mDialog = null; + } + } + + @Override + public void onPause() { + super.onPause(); + dismissDialog(); + } + + public void onResume() { + super.onResume(); + createDialog(); + } + + void doPositiveButton(boolean checked) { + Settings.Global.putInt(getContentResolver(), + Settings.Global.WIFI_NOTIFY_SCAN_ALWAYS_AVAILABLE, checked ? 0 : 1); + finish(); + } + + public static class AlertDialogFragment extends DialogFragment { + static AlertDialogFragment newInstance() { + AlertDialogFragment frag = new AlertDialogFragment(); + return frag; + } + + public AlertDialogFragment() { + super(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + View checkBoxView = View.inflate(getActivity(), R.layout.wifi_notify_scan_mode, null); + final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox); + final String msg; + if (Settings.Secure.isLocationProviderEnabled(getActivity().getContentResolver(), + LocationManager.NETWORK_PROVIDER)) { + msg = getString(R.string.wifi_scan_notify_text_location_on); + } else { + msg = getString(R.string.wifi_scan_notify_text_location_off); + } + return new AlertDialog.Builder(getActivity()) + .setMessage(msg) + .setView(checkBoxView) + .setPositiveButton(R.string.dlg_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + ((WifiNotifyScanModeActivity) getActivity()).doPositiveButton( + checkBox.isChecked()); + } + } + ) + .setNegativeButton(R.string.dlg_cancel, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + ((WifiNotifyScanModeActivity) getActivity()).finish(); + } + } + ) + .create(); + } + @Override + public void onCancel(DialogInterface dialog) { + ((WifiNotifyScanModeActivity) getActivity()).finish(); + } + } +}