StrictMode test: add a button for violating in a loop.

Change-Id: I2df9bf175c11e4748fbe0f33a52ee62aac733292
diff --git a/StrictModeTest/res/layout/main.xml b/StrictModeTest/res/layout/main.xml
index 21e5bec..a81f875 100644
--- a/StrictModeTest/res/layout/main.xml
+++ b/StrictModeTest/res/layout/main.xml
@@ -69,6 +69,13 @@
          />
 
       <Button
+         android:id="@+id/write_loop_button"
+         android:layout_width="fill_parent"
+         android:layout_height="wrap_content"
+         android:text="fake write (in a loop)"
+         />
+
+      <Button
          android:id="@+id/read_button"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
diff --git a/StrictModeTest/src/com/android/strictmodetest/StrictModeActivity.java b/StrictModeTest/src/com/android/strictmodetest/StrictModeActivity.java
index d81ad65..8795b85 100644
--- a/StrictModeTest/src/com/android/strictmodetest/StrictModeActivity.java
+++ b/StrictModeTest/src/com/android/strictmodetest/StrictModeActivity.java
@@ -54,6 +54,8 @@
 import android.widget.CheckBox;
 import android.widget.TextView;
 
+import dalvik.system.BlockGuard;
+
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.methods.HttpGet;
@@ -120,6 +122,21 @@
                 }
             });
 
+        final Button writeLoopButton = (Button) findViewById(R.id.write_loop_button);
+        writeLoopButton.setOnClickListener(new View.OnClickListener() {
+                public void onClick(View v) {
+                    long startTime = SystemClock.uptimeMillis();
+                    int iters = 1000;
+                    BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
+                    for (int i = 0; i < iters; ++i) {
+                        policy.onWriteToDisk();
+                    }
+                    long endTime = SystemClock.uptimeMillis();
+                    Log.d(TAG, "Time for " + iters + ": " + (endTime - startTime) + ", avg=" +
+                          (endTime - startTime) / (double) iters);
+                }
+            });
+
         final Button dnsButton = (Button) findViewById(R.id.dns_button);
         dnsButton.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {