Separate CPU intensive test from system server

Separate into two activities, as they are unrelated.

Bug: none
Test: run the applications
Change-Id: I390c1351d5e9c3ecdd0b863b7aceac03e735ff58
diff --git a/startop/apps/test/Android.bp b/startop/apps/test/Android.bp
index 2ff26b8..5de7fd2 100644
--- a/startop/apps/test/Android.bp
+++ b/startop/apps/test/Android.bp
@@ -18,7 +18,8 @@
     name: "startop_test_app",
     srcs: [
         "src/ComplexLayoutInflationActivity.java",
-        "src/CPUIntensive.java",
+        "src/CPUIntensiveBenchmarkActivity.java",
+        "src/CPUIntensiveBenchmarks.java",
         "src/EmptyActivity.java",
         "src/FrameLayoutInflationActivity.java",
         "src/LayoutInflationActivity.java",
diff --git a/startop/apps/test/AndroidManifest.xml b/startop/apps/test/AndroidManifest.xml
index ebe2584..b08072e 100644
--- a/startop/apps/test/AndroidManifest.xml
+++ b/startop/apps/test/AndroidManifest.xml
@@ -37,6 +37,18 @@
         </activity>
 
         <activity
+            android:label="CPU Intensive Benchmark Test"
+            android:name=".CPUIntensiveBenchmarkActivity"
+            android:exported="true" >
+
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
             android:label="Empty Activity Layout Test"
             android:name=".EmptyActivity"
             android:exported="true" >
diff --git a/startop/apps/test/src/CPUIntensive.java b/startop/apps/test/src/CPUIntensive.java
deleted file mode 100644
index a411e8c..0000000
--- a/startop/apps/test/src/CPUIntensive.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- *  A threaded CPU intensive class for use in benchmarks.
- */
-
-package com.android.startop.test;
-
-final class CPUIntensive {
-    public static final int THREAD_COUNT = 8;
-    public static final int ARRAY_SIZE = 30000;
-    public static int[][] array = new int[THREAD_COUNT][ARRAY_SIZE];
-
-    static class WorkerThread extends Thread {
-        int mThreadNumber;
-        WorkerThread(int number) {
-            mThreadNumber = number;
-        }
-        public void run() {
-            final int arrayLength = array[mThreadNumber].length;
-            for (int i = 0; i < arrayLength; ++i) {
-                array[mThreadNumber][i] = i * i;
-            }
-            for (int i = 0; i < arrayLength; ++i) {
-                for (int j = 0; j < arrayLength; ++j) {
-                    int swap = array[mThreadNumber][j];
-                    array[mThreadNumber][j] = array[mThreadNumber][(j + i) % arrayLength];
-                    array[mThreadNumber][(j + i) % arrayLength] = swap;
-                }
-            }
-        }
-    };
-
-    public static void doSomeWork(int threadCount) {
-        WorkerThread[] threads = new WorkerThread[threadCount];
-        // Create the threads.
-        for (int i = 0; i < threadCount; ++i) {
-            threads[i] = new WorkerThread(i);
-        }
-        // Start the threads.
-        for (int i = 0; i < threadCount; ++i) {
-            threads[i].start();
-        }
-        // Join the threads.
-        for (int i = 0; i < threadCount; ++i) {
-            try {
-                threads[i].join();
-            } catch (Exception ex) {
-            }
-        }
-    }
-}
-
diff --git a/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java
new file mode 100644
index 0000000..2ec5308
--- /dev/null
+++ b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.startop.test;
+
+import android.os.Bundle;
+
+public class CPUIntensiveBenchmarkActivity extends SystemServerBenchmarkActivity {
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.system_server_benchmark_page);
+
+        mBenchmarkList = findViewById(R.id.benchmark_list);
+
+        CPUIntensiveBenchmarks.initializeBenchmarks(this, this);
+    }
+}
diff --git a/startop/apps/test/src/CPUIntensiveBenchmarks.java b/startop/apps/test/src/CPUIntensiveBenchmarks.java
new file mode 100644
index 0000000..19d0b63
--- /dev/null
+++ b/startop/apps/test/src/CPUIntensiveBenchmarks.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *  A threaded CPU intensive class for use in benchmarks.
+ */
+
+package com.android.startop.test;
+
+import android.app.Activity;
+
+public class CPUIntensiveBenchmarks {
+    public static final int ARRAY_SIZE = 30000;
+    public static int[][] mArray;
+
+    static class WorkerThread extends Thread {
+        int mThreadNumber;
+        WorkerThread(int number) {
+            mThreadNumber = number;
+        }
+        public void run() {
+            final int arrayLength = mArray[mThreadNumber].length;
+            for (int i = 0; i < arrayLength; ++i) {
+                mArray[mThreadNumber][i] = i * i;
+            }
+            for (int i = 0; i < arrayLength; ++i) {
+                for (int j = 0; j < arrayLength; ++j) {
+                    int swap = mArray[mThreadNumber][j];
+                    mArray[mThreadNumber][j] = mArray[mThreadNumber][(j + i) % arrayLength];
+                    mArray[mThreadNumber][(j + i) % arrayLength] = swap;
+                }
+            }
+        }
+    };
+
+    static void doSomeWork(int threadCount) {
+        mArray = new int[threadCount][ARRAY_SIZE];
+        WorkerThread[] threads = new WorkerThread[threadCount];
+        // Create the threads.
+        for (int i = 0; i < threadCount; ++i) {
+            threads[i] = new WorkerThread(i);
+        }
+        // Start the threads.
+        for (int i = 0; i < threadCount; ++i) {
+            threads[i].start();
+        }
+        // Join the threads.
+        for (int i = 0; i < threadCount; ++i) {
+            try {
+                threads[i].join();
+            } catch (Exception ex) {
+            }
+        }
+    }
+
+    // Time limit to run benchmarks in seconds
+    public static final int TIME_LIMIT = 5;
+
+    static void initializeBenchmarks(Activity parent, BenchmarkRunner benchmarks) {
+        benchmarks.addBenchmark("Use 1 thread", () -> {
+            doSomeWork(1);
+        });
+        benchmarks.addBenchmark("Use 2 threads", () -> {
+            doSomeWork(2);
+        });
+        benchmarks.addBenchmark("Use 4 threads", () -> {
+            doSomeWork(4);
+        });
+        benchmarks.addBenchmark("Use 8 threads", () -> {
+            doSomeWork(8);
+        });
+        benchmarks.addBenchmark("Use 16 threads", () -> {
+            doSomeWork(16);
+        });
+    }
+}
diff --git a/startop/apps/test/src/SystemServerBenchmarkActivity.java b/startop/apps/test/src/SystemServerBenchmarkActivity.java
index 75ea69b..6be8df3 100644
--- a/startop/apps/test/src/SystemServerBenchmarkActivity.java
+++ b/startop/apps/test/src/SystemServerBenchmarkActivity.java
@@ -17,28 +17,20 @@
 package com.android.startop.test;
 
 import android.app.Activity;
-import android.app.ActivityManager;
-import android.content.ComponentName;
 import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.AsyncTask;
 import android.os.Bundle;
-import android.view.ViewGroup;
 import android.widget.Button;
 import android.widget.GridLayout;
 import android.widget.TextView;
 
 public class SystemServerBenchmarkActivity extends Activity implements BenchmarkRunner {
-    private GridLayout benchmarkList;
+    protected GridLayout mBenchmarkList;
 
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.system_server_benchmark_page);
 
-        benchmarkList = findViewById(R.id.benchmark_list);
+        mBenchmarkList = findViewById(R.id.benchmark_list);
 
         SystemServerBenchmarks.initializeBenchmarks(this, this);
     }
@@ -49,7 +41,7 @@
      * @param name A short name that shows up in the UI or benchmark results
      */
     public void addBenchmark(CharSequence name, Runnable thunk) {
-        Context context = benchmarkList.getContext();
+        Context context = mBenchmarkList.getContext();
         Button button = new Button(context);
         TextView mean = new TextView(context);
         TextView stdev = new TextView(context);
@@ -68,8 +60,8 @@
             });
         });
 
-        benchmarkList.addView(button);
-        benchmarkList.addView(mean);
-        benchmarkList.addView(stdev);
+        mBenchmarkList.addView(button);
+        mBenchmarkList.addView(mean);
+        mBenchmarkList.addView(stdev);
     }
 }
diff --git a/startop/apps/test/src/SystemServerBenchmarks.java b/startop/apps/test/src/SystemServerBenchmarks.java
index 5918503..25b43f4 100644
--- a/startop/apps/test/src/SystemServerBenchmarks.java
+++ b/startop/apps/test/src/SystemServerBenchmarks.java
@@ -60,22 +60,6 @@
         benchmarks.addBenchmark("Empty", () -> {
         });
 
-        benchmarks.addBenchmark("CPU Intensive (1 thread)", () -> {
-            CPUIntensive.doSomeWork(1);
-        });
-
-        benchmarks.addBenchmark("CPU Intensive (2 thread)", () -> {
-            CPUIntensive.doSomeWork(2);
-        });
-
-        benchmarks.addBenchmark("CPU Intensive (4 thread)", () -> {
-            CPUIntensive.doSomeWork(4);
-        });
-
-        benchmarks.addBenchmark("CPU Intensive (8 thread)", () -> {
-            CPUIntensive.doSomeWork(8);
-        });
-
         PackageManager pm = parent.getPackageManager();
         benchmarks.addBenchmark("getInstalledApplications", () -> {
             pm.getInstalledApplications(PackageManager.MATCH_SYSTEM_ONLY);