summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-01-19 02:22:49 +0100
committerGerrit Code Review <gerrit@review.cyanogenmod.com>2013-01-26 21:26:17 -0800
commit7d1af4cf5075b382ef0b6c87362d61207ebe86e1 (patch)
tree9d7aedd8b5deba8c6ff23c7bc3217baf660e21f8
parentb1d2a4b12a35ff767709d6626732dbc71ec53f16 (diff)
downloadpackages_apps_settings-7d1af4cf5075b382ef0b6c87362d61207ebe86e1.zip
packages_apps_settings-7d1af4cf5075b382ef0b6c87362d61207ebe86e1.tar.gz
packages_apps_settings-7d1af4cf5075b382ef0b6c87362d61207ebe86e1.tar.bz2
Wi-Fi: Manage Wi-Fi AP priorities
AOSP has a basic LRU priority for Wi-Fi networks (last connected has more priority). This changes added the ability of graphically set the priority of any of the configured Wi-Fi networks through Settings -> Wi-Fi -> Advanced Settings -> Wi-Fi priority. Patchset 2: Move WiFiPriority from cyanogenmod folder to wifi folder Remove double quotes in SSID name Patchset 3: Fixed code issues Change-Id: Ief590e799cdb7ef760b631d0b22d9719f867393f Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--res/layout-finger/wifi_network_priority.xml32
-rw-r--r--res/layout-finger/wifi_network_priority_list_item.xml39
-rw-r--r--res/values/strings.xml4
-rw-r--r--res/xml/wifi_advanced_settings.xml8
-rw-r--r--src/com/android/settings/wifi/AdvancedWifiSettings.java5
-rw-r--r--src/com/android/settings/wifi/WifiPriority.java187
6 files changed, 275 insertions, 0 deletions
diff --git a/res/layout-finger/wifi_network_priority.xml b/res/layout-finger/wifi_network_priority.xml
new file mode 100644
index 0000000..fa84083
--- /dev/null
+++ b/res/layout-finger/wifi_network_priority.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:gravity="center_vertical" >
+
+ <com.android.settings.cyanogenmod.TouchInterceptor
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:textSize="18sp"
+ android:drawSelectorOnTop="false"
+ android:fastScrollEnabled="true" />
+
+</LinearLayout>
diff --git a/res/layout-finger/wifi_network_priority_list_item.xml b/res/layout-finger/wifi_network_priority_list_item.xml
new file mode 100644
index 0000000..aa0d873
--- /dev/null
+++ b/res/layout-finger/wifi_network_priority_list_item.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2008, 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.
+*/
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="64dip"
+ android:orientation="vertical">
+
+ <ImageView android:id="@+id/grabber"
+ android:src="@drawable/ic_grabber"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <TextView android:id="@+id/name"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_width="wrap_content"
+ android:paddingLeft="9dip"
+ android:paddingRight="9dip"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee"
+ android:gravity="center_vertical"
+ android:singleLine="true" />
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 62bc4cb..79ebf25 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1492,6 +1492,10 @@
<string name="wifi_setting_countrycode_summary">Specify the region code for Wi-Fi</string>
<!-- Wi-Fi settings screen, error message when the frequency band could not be set [CHAR LIMIT=50]. -->
<string name="wifi_setting_countrycode_error">There was a problem setting the region code.</string>
+ <!-- Wi-Fi settings screen, advanced, title of the item to set the Wi-Fi priority. -->
+ <string name="wifi_setting_priority_title">Wi-Fi priority</string>
+ <!-- Wi-Fi settings screen, setting summary for setting the Wi-Fi priority-->
+ <string name="wifi_setting_priority_summary">Specify the priority of the Wi-Fi networks</string>
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. -->
<string name="wifi_advanced_mac_address_title">MAC address</string>
<!-- Title of the screen to adjust IP settings -->
diff --git a/res/xml/wifi_advanced_settings.xml b/res/xml/wifi_advanced_settings.xml
index 8b85004..083942b 100644
--- a/res/xml/wifi_advanced_settings.xml
+++ b/res/xml/wifi_advanced_settings.xml
@@ -57,6 +57,14 @@
android:entryValues="@array/wifi_countrycode_values"
/>
+ <PreferenceScreen
+ android:key="wifi_priority"
+ android:title="@string/wifi_setting_priority_title"
+ android:summary="@string/wifi_setting_priority_summary"
+ android:persistent="false"
+ android:fragment="com.android.settings.wifi.WifiPriority"
+ />
+
<CheckBoxPreference
android:key="suspend_optimizations"
android:title="@string/wifi_suspend_optimizations"
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index 99b2f10..3777eb2 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -17,6 +17,7 @@
package com.android.settings.wifi;
import android.content.Context;
+import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiWatchdogStateMachine;
@@ -47,6 +48,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
private static final String KEY_SLEEP_POLICY = "sleep_policy";
private static final String KEY_POOR_NETWORK_DETECTION = "wifi_poor_network_detection";
private static final String KEY_SUSPEND_OPTIMIZATIONS = "suspend_optimizations";
+ private static final String KEY_WIFI_PRIORITY = "wifi_priority";
private WifiManager mWifiManager;
@@ -135,6 +137,9 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
sleepPolicyPref.setValue(stringValue);
updateSleepPolicySummary(sleepPolicyPref, stringValue);
}
+
+ Preference wifiPriority = findPreference(KEY_WIFI_PRIORITY);
+ wifiPriority.setEnabled(mWifiManager.isWifiEnabled());
}
private void updateSleepPolicySummary(Preference sleepPolicyPref, String value) {
diff --git a/src/com/android/settings/wifi/WifiPriority.java b/src/com/android/settings/wifi/WifiPriority.java
new file mode 100644
index 0000000..74f997a
--- /dev/null
+++ b/src/com/android/settings/wifi/WifiPriority.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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 android.app.ListFragment;
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.cyanogenmod.TouchInterceptor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class WifiPriority extends ListFragment {
+
+ private final TouchInterceptor.DropListener mDropListener =
+ new TouchInterceptor.DropListener() {
+ public void drop(int from, int to) {
+ if (from == to) return;
+
+ // Sort networks by user selection
+ List<WifiConfiguration> mNetworks = mAdapter.getNetworks();
+ WifiConfiguration o = mNetworks.remove(from);
+ mNetworks.add(to, o);
+
+ // Set the new priorities of the networks
+ int cc = mNetworks.size();
+ for (int i = 0; i < cc; i++) {
+ WifiConfiguration network = mNetworks.get(i);
+ network.priority = cc - i;
+
+ // Update the priority
+ mWifiManager.updateNetwork(network);
+ }
+
+ // Now, save all the Wi-Fi configuration with its new priorities
+ mWifiManager.saveConfiguration();
+
+ // Reload the networks
+ mAdapter.reloadNetworks();
+ mNetworksListView.invalidateViews();
+ }
+ };
+
+ private WifiManager mWifiManager;
+ private TouchInterceptor mNetworksListView;
+ private WifiPriorityAdapter mAdapter;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.wifi_network_priority, null);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ Context ctx = getActivity().getApplicationContext();
+ mWifiManager = (WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);
+
+ // Set the touchable listview
+ mNetworksListView = (TouchInterceptor)getListView();
+ mNetworksListView.setDropListener(mDropListener);
+ mAdapter = new WifiPriorityAdapter(ctx, mWifiManager);
+ setListAdapter(mAdapter);
+ }
+
+ @Override
+ public void onDestroy() {
+ mNetworksListView.setDropListener(null);
+ setListAdapter(null);
+ super.onDestroy();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // Reload the networks
+ mAdapter.reloadNetworks();
+ mNetworksListView.invalidateViews();
+ }
+
+ private class WifiPriorityAdapter extends BaseAdapter {
+
+ private final WifiManager mWifiManager;
+ private final LayoutInflater mInflater;
+ private List<WifiConfiguration> mNetworks;
+
+ public WifiPriorityAdapter(Context ctx, WifiManager wifiManager) {
+ mWifiManager = wifiManager;
+ mInflater = LayoutInflater.from(ctx);
+ reloadNetworks();
+ }
+
+ private void reloadNetworks() {
+ mNetworks = mWifiManager.getConfiguredNetworks();
+ if (mNetworks == null) {
+ mNetworks = new ArrayList<WifiConfiguration>();
+ }
+
+ // Sort network list by priority (or by network id if the priority is the same)
+ Collections.sort(mNetworks, new Comparator<WifiConfiguration>() {
+ @Override
+ public int compare(WifiConfiguration lhs, WifiConfiguration rhs) {
+ // > priority -- > lower position
+ if (lhs.priority < rhs.priority) return 1;
+ if (lhs.priority > rhs.priority) return -1;
+ // < network id -- > lower position
+ if (lhs.networkId < rhs.networkId) return -1;
+ if (lhs.networkId > rhs.networkId) return 1;
+ return 0;
+ }
+ });
+ }
+
+ /**package**/ List<WifiConfiguration> getNetworks() {
+ return mNetworks;
+ }
+
+ @Override
+ public int getCount() {
+ return mNetworks.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mNetworks.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final View v;
+ if (convertView == null) {
+ v = mInflater.inflate(R.layout.order_power_widget_button_list_item, null);
+ } else {
+ v = convertView;
+ }
+
+ WifiConfiguration network = (WifiConfiguration)getItem(position);
+
+ final TextView name = (TextView) v.findViewById(R.id.name);
+ // wpa_suplicant returns the SSID between double quotes. Remove them if are present.
+ name.setText(filterSSID(network.SSID));
+
+ return v;
+ }
+
+ private String filterSSID(String ssid) {
+ // Filter only if has start and end double quotes
+ if (ssid == null || !ssid.startsWith("\"") || !ssid.endsWith("\"")) {
+ return ssid;
+ }
+ return ssid.substring(1, ssid.length()-1);
+ }
+ }
+}