OSDN Git Service

Clear names from externally supplied WorkSources to WifiManager (b/10733757)
authorDavid Christie <dnchrist@google.com>
Fri, 20 Sep 2013 17:44:01 +0000 (10:44 -0700)
committerDavid Christie <dnchrist@google.com>
Fri, 20 Sep 2013 18:41:41 +0000 (11:41 -0700)
Change-Id: I36102f13962df2093c1e35fb40081ead647eff32

core/java/android/os/WorkSource.java
wifi/java/android/net/wifi/WifiManager.java

index 30d535b..e66df04 100644 (file)
@@ -103,7 +103,21 @@ public class WorkSource implements Parcelable {
      * @hide
      */
     public void clearNames() {
-        mNames = null;
+        if (mNames != null) {
+            mNames = null;
+            // Clear out any duplicate uids now that we don't have names to disambiguate them.
+            int destIndex = 1;
+            int newNum = mNum;
+            for (int sourceIndex = 1; sourceIndex < mNum; sourceIndex++) {
+                if (mUids[sourceIndex] == mUids[sourceIndex - 1]) {
+                    newNum--;
+                } else {
+                    mUids[destIndex] = mUids[sourceIndex];
+                    destIndex++;
+                }
+            }
+            mNum = newNum;
+        }
     }
 
     /**
index 3223cb3..cfe2a30 100644 (file)
@@ -1867,13 +1867,16 @@ public class WifiManager {
                 boolean changed = true;
                 if (ws == null) {
                     mWorkSource = null;
-                } else if (mWorkSource == null) {
-                    changed = mWorkSource != null;
-                    mWorkSource = new WorkSource(ws);
                 } else {
-                    changed = mWorkSource.diff(ws);
-                    if (changed) {
-                        mWorkSource.set(ws);
+                    ws.clearNames();
+                    if (mWorkSource == null) {
+                        changed = mWorkSource != null;
+                        mWorkSource = new WorkSource(ws);
+                    } else {
+                        changed = mWorkSource.diff(ws);
+                        if (changed) {
+                            mWorkSource.set(ws);
+                        }
                     }
                 }
                 if (changed && mHeld) {