OSDN Git Service

Separate wifi AP added by applications.
authorSky Faber <skyf@google.com>
Mon, 22 Sep 2014 23:43:04 +0000 (16:43 -0700)
committerVinit Deshpande <vinitd@google.com>
Sat, 27 Sep 2014 02:00:36 +0000 (02:00 +0000)
-Add permission to allow settings to modify all wifi APs
-Add option to show AP owners.

Change-Id: I12943563ef714c4287e13488578f020d136d006d

AndroidManifest.xml
res/values/strings.xml
src/com/android/settings/wifi/AccessPoint.java
src/com/android/settings/wifi/WifiSettings.java

index a2d80b9..b3d8453 100644 (file)
@@ -69,6 +69,7 @@
     <uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
     <uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
     <uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
+    <uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
 
     <application android:label="@string/settings_label"
             android:icon="@mipmap/ic_launcher_settings"
index 54ceb3b..c75da27 100644 (file)
     <string name="wifi_menu_scan">Scan</string>
     <!-- Menu option to Wi-Fi advanced settings -->
     <string name="wifi_menu_advanced">Advanced</string>
+    <!-- Menu option to show app icons instead of WiFi strength [CHAR LIMIT=20]-->
+    <string name="wifi_menu_apps">Show Apps</string>
+    <!-- Menu option to show WiFi strength icons [CHAR LIMIT=20]-->
+    <string name="wifi_menu_apps_strength">Show WiFi Strength</string>
     <!-- Menu option to connect to a Wi-Fi network -->
     <string name="wifi_menu_connect">Connect to network</string>
     <!-- Menu option to delete a Wi-Fi network -->
index dda8d9e..a736e6c 100644 (file)
@@ -19,6 +19,8 @@ package com.android.settings.wifi;
 import com.android.settings.R;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.StateListDrawable;
 import android.net.NetworkInfo.DetailedState;
@@ -286,6 +288,26 @@ class AccessPoint extends Preference {
         }
     }
 
+    public void showAppIcon() {
+        PackageManager pm = getContext().getPackageManager();
+        String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID);
+
+        Drawable drawable = pm.getDefaultActivityIcon();
+        if (mConfig == null) {
+            drawable.setAlpha(0);
+        } else if (mConfig.creatorName.equals(systemName)) {
+            drawable = getContext().getApplicationInfo().loadIcon(pm);
+        } else {
+            try {
+                drawable = pm.getApplicationIcon(mConfig.creatorName);
+            } catch (NameNotFoundException nnfe) {
+                // use default app icon
+            }
+        }
+
+        setIcon(drawable);
+    }
+
     @Override
     public int compareTo(Preference preference) {
         if (!(preference instanceof AccessPoint)) {
index 258c220..3c8ac99 100644 (file)
@@ -102,6 +102,7 @@ public class WifiSettings extends RestrictedSettingsFragment
     private static final int MENU_ID_FORGET = Menu.FIRST + 7;
     private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
     private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
+    private static final int MENU_ID_APPS = Menu.FIRST + 10;
 
     private static final String KEY_ASSISTANT_DISMISS_PLATFORM = "assistant_dismiss_platform";
 
@@ -142,6 +143,9 @@ public class WifiSettings extends RestrictedSettingsFragment
 
     private TextView mEmptyView;
 
+    private boolean showAppIcons = false;
+    private MenuItem showAppMenuItem = null;
+
     // this boolean extra specifies whether to disable the Next button when not connected. Used by
     // account creation outside of setup wizard.
     private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
@@ -420,6 +424,8 @@ public class WifiSettings extends RestrictedSettingsFragment
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        showAppMenuItem = menu.add(Menu.NONE, MENU_ID_APPS, 0, R.string.wifi_menu_apps);
+        showAppMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         ta.recycle();
     }
 
@@ -496,6 +502,16 @@ public class WifiSettings extends RestrictedSettingsFragment
                             null);
                 }
                 return true;
+            case MENU_ID_APPS:
+                showAppIcons = !showAppIcons;
+
+                if (showAppIcons) {
+                    showAppMenuItem.setTitle(R.string.wifi_menu_apps_strength);
+                } else {
+                    showAppMenuItem.setTitle(R.string.wifi_menu_apps);
+                }
+                updateAccessPoints();
+                return true;
         }
         return super.onOptionsItemSelected(item);
     }
@@ -663,6 +679,10 @@ public class WifiSettings extends RestrictedSettingsFragment
                 }
 
                 for (AccessPoint accessPoint : accessPoints) {
+                    if (showAppIcons) {
+                        accessPoint.showAppIcon();
+                    }
+
                     // Ignore access points that are out of range.
                     if (accessPoint.getLevel() != -1) {
                         getPreferenceScreen().addPreference(accessPoint);