Update adb command to remove all configs from statsd

Before this change we were only clearing configs from disk.
This change will allow clearing from memory as well. Also,
this change fixes a bug where the iterator moves to the next
element before removing the key from mConfigReceivers

Test: statsd, statsd_test

Change-Id: I9f5e0aced9b89bae7b19ae6d8490c076557fbb08
diff --git a/bin/src/config/ConfigManager.cpp b/bin/src/config/ConfigManager.cpp
index 445ee59..4b7e49a 100644
--- a/bin/src/config/ConfigManager.cpp
+++ b/bin/src/config/ConfigManager.cpp
@@ -102,8 +102,8 @@
         // Remove from map
         if (it->first.GetUid() == uid) {
             removed.push_back(it->first);
-            it = mConfigs.erase(it);
             mConfigReceivers.erase(it->first);
+            it = mConfigs.erase(it);
         } else {
             it++;
         }
@@ -118,6 +118,28 @@
     }
 }
 
+void ConfigManager::RemoveAllConfigs() {
+    vector<ConfigKey> removed;
+
+    for (auto it = mConfigs.begin(); it != mConfigs.end();) {
+        // Remove from map
+        removed.push_back(it->first);
+        auto receiverIt = mConfigReceivers.find(it->first);
+        if (receiverIt != mConfigReceivers.end()) {
+            mConfigReceivers.erase(it->first);
+        }
+        it = mConfigs.erase(it);
+    }
+
+    // Remove separately so if they do anything in the callback they can't mess up our iteration.
+    for (auto& key : removed) {
+        // Tell everyone
+        for (auto& listener : mListeners) {
+            listener->OnConfigRemoved(key);
+        }
+    }
+}
+
 vector<ConfigKey> ConfigManager::GetAllConfigKeys() const {
     vector<ConfigKey> ret;
     for (auto it = mConfigs.cbegin(); it != mConfigs.cend(); ++it) {