diff options
author | Michael Plass <mplass@google.com> | 2020-06-01 17:27:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-06-01 17:27:26 +0000 |
commit | 590b4f71df5ffb5ef17da48e9d73b919de85b002 (patch) | |
tree | cc47505ece3452558fa15770b684a1d9d4cc3c1c | |
parent | ed72be5adfa4dde205917312dfdd240b470882b3 (diff) | |
parent | 330a7ccd895b4047323d4b633e36489daf1f8f4c (diff) |
Merge "Remove WifiScoreCard entries when forgetting a network" into rvc-dev
4 files changed, 81 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/MemoryStoreImpl.java b/service/java/com/android/server/wifi/MemoryStoreImpl.java index 1b819d46d..a15ae8106 100644 --- a/service/java/com/android/server/wifi/MemoryStoreImpl.java +++ b/service/java/com/android/server/wifi/MemoryStoreImpl.java @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.content.Context; import android.net.IpMemoryStore; import android.net.ipmemorystore.Blob; +import android.net.ipmemorystore.NetworkAttributes; import android.net.ipmemorystore.Status; import android.util.Log; @@ -127,6 +128,35 @@ final class MemoryStoreImpl implements WifiScoreCard.MemoryStore { } } + @Override + public void setCluster(String key, String cluster) { + if (mBroken) return; + try { + NetworkAttributes attributes = new NetworkAttributes.Builder() + .setCluster(cluster) + .build(); + mIpMemoryStore.storeNetworkAttributes(key, attributes, status -> { + Log.d(TAG, "Set cluster " + cluster + " for " + key + ": " + status); + }); + } catch (RuntimeException e) { + handleException(e); + } + } + + @Override + public void removeCluster(String cluster) { + if (mBroken) return; + try { + final boolean needWipe = true; + mIpMemoryStore.deleteCluster(cluster, needWipe, (status, deletedRecords) -> { + Log.d(TAG, "Remove cluster " + cluster + ": " + status + + " deleted: " + deletedRecords); + }); + } catch (RuntimeException e) { + handleException(e); + } + } + /** * Starts using IpMemoryStore. */ diff --git a/service/java/com/android/server/wifi/WifiScoreCard.java b/service/java/com/android/server/wifi/WifiScoreCard.java index 346a8febe..ca77e8396 100644 --- a/service/java/com/android/server/wifi/WifiScoreCard.java +++ b/service/java/com/android/server/wifi/WifiScoreCard.java @@ -136,6 +136,10 @@ public class WifiScoreCard { void read(String key, String name, BlobListener blobListener); /** Requests a write, does not wait for completion */ void write(String key, String name, byte[] value); + /** Sets the cluster identifier */ + void setCluster(String key, String cluster); + /** Requests removal of all entries matching the cluster */ + void removeCluster(String cluster); } /** Asynchronous response to a read request */ public interface BlobListener { @@ -249,9 +253,15 @@ public class WifiScoreCard { if (perBssid == mDummyPerBssid) { return new Pair<>(null, null); } - final long groupIdHash = computeHashLong( - perBssid.ssid, mDummyPerBssid.bssid, mL2KeySeed); - return new Pair<>(perBssid.getL2Key(), groupHintFromLong(groupIdHash)); + return new Pair<>(perBssid.getL2Key(), groupHintFromSsid(perBssid.ssid)); + } + + /** + * Computes the GroupHint associated with the given ssid. + */ + public @NonNull String groupHintFromSsid(String ssid) { + final long groupIdHash = computeHashLong(ssid, mDummyPerBssid.bssid, mL2KeySeed); + return groupHintFromLong(groupIdHash); } /** @@ -1447,6 +1457,7 @@ public class WifiScoreCard { Log.e(TAG, "More answers than we expected!"); } } + /** * Handles (when convenient) the arrival of previously stored data. * @@ -1459,7 +1470,6 @@ public class WifiScoreCard { return mPendingReadFromStore.getAndSet(null); } - int idFromLong() { return (int) mHash & 0x7fffffff; } @@ -1552,10 +1562,9 @@ public class WifiScoreCard { return; } mApForNetwork.remove(ssid); + mApForBssid.entrySet().removeIf(entry -> ssid.equals(entry.getValue().ssid)); if (mMemoryStore == null) return; - PerNetwork ans = new PerNetwork(ssid); - byte[] serialized = {}; - mMemoryStore.write(ans.getL2Key(), PER_NETWORK_DATA_NAME, serialized); + mMemoryStore.removeCluster(groupHintFromSsid(ssid)); } void requestReadNetwork(final PerNetwork perNetwork) { @@ -1586,7 +1595,9 @@ public class WifiScoreCard { if (perBssid.changed) { perBssid.finishPendingRead(); byte[] serialized = perBssid.toAccessPoint(/* No BSSID */ true).toByteArray(); + mMemoryStore.setCluster(perBssid.getL2Key(), groupHintFromSsid(perBssid.ssid)); mMemoryStore.write(perBssid.getL2Key(), PER_BSSID_DATA_NAME, serialized); + perBssid.changed = false; count++; bytes += serialized.length; @@ -1606,6 +1617,7 @@ public class WifiScoreCard { if (perNetwork.changed) { perNetwork.finishPendingRead(); byte[] serialized = perNetwork.toNetworkStats().toByteArray(); + mMemoryStore.setCluster(perNetwork.getL2Key(), groupHintFromSsid(perNetwork.ssid)); mMemoryStore.write(perNetwork.getL2Key(), PER_NETWORK_DATA_NAME, serialized); perNetwork.changed = false; count++; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java index 0660e5eec..4e0b5b75e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java @@ -332,6 +332,14 @@ public class WifiHealthMonitorTest extends WifiBaseTest { mKeys.add(key); mBlobs.add(value); } + + @Override + public void setCluster(String key, String cluster) { + } + + @Override + public void removeCluster(String cluster) { + } }); mBlobListeners.get(0).onBlobRetrieved(serialized); @@ -688,11 +696,20 @@ public class WifiHealthMonitorTest extends WifiBaseTest { public void read(String key, String name, WifiScoreCard.BlobListener listener) { mBlobListeners.add(listener); } + @Override public void write(String key, String name, byte[] value) { mKeys.add(key); mBlobs.add(value); } + + @Override + public void setCluster(String key, String cluster) { + } + + @Override + public void removeCluster(String cluster) { + } }); mBlobListeners.get(0).onBlobRetrieved(serialized); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java index e5525c4c7..1ad767c6e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java @@ -688,6 +688,14 @@ public class WifiScoreCardTest extends WifiBaseTest { public void write(String key, String name, byte[] value) { // ignore for now } + @Override + public void setCluster(String key, String cluster) { + // ignore for now + } + @Override + public void removeCluster(String cluster) { + // ignore for now + } }); // Now make some changes @@ -724,6 +732,13 @@ public class WifiScoreCardTest extends WifiBaseTest { mKeys.add(key); mBlobs.add(value); } + @Override + public void setCluster(String key, String cluster) { + } + @Override + public void removeCluster(String cluster) { + // ignore for now + } }); // Make some changes |