summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-08-26 19:56:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-08-26 19:56:26 +0000
commit4610545dd28ebf316704e119572521e97dbbd6bd (patch)
tree10f9e40ccd0d4e82f4db925d03e9b80ef76637fe /tests
parent15741d0e0b859484738e2d165e99f8f686230316 (diff)
parent89ad456ea49cb62615ebdcac83a2515743bbe5fa (diff)
downloadframeworks_base-4610545dd28ebf316704e119572521e97dbbd6bd.zip
frameworks_base-4610545dd28ebf316704e119572521e97dbbd6bd.tar.gz
frameworks_base-4610545dd28ebf316704e119572521e97dbbd6bd.tar.bz2
Merge "Fix issue #16311398: Limit number of documents a process can open" into lmp-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/ActivityTests/AndroidManifest.xml5
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java105
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/DocActivity.java35
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SpamActivity.java31
4 files changed, 173 insertions, 3 deletions
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml
index c0898d3..3fb547d 100644
--- a/tests/ActivityTests/AndroidManifest.xml
+++ b/tests/ActivityTests/AndroidManifest.xml
@@ -31,6 +31,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name="SpamActivity" android:label="Spam!"
+ android:documentLaunchMode="always">
+ </activity>
+ <activity android:name="DocActivity" android:label="Some doc">
+ </activity>
<service android:name="SingleUserService"
android:singleUser="true" android:exported="true">
</service>
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
index 7f3aa77..ea0db56 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -21,6 +21,7 @@ import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
+import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
@@ -29,13 +30,15 @@ import android.content.ContentProviderClient;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.BitmapFactory;
+import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.Message;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.graphics.Bitmap;
-import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -60,6 +63,28 @@ public class ActivityTestMain extends Activity {
ArrayList<ServiceConnection> mConnections = new ArrayList<ServiceConnection>();
+ static final int MSG_SPAM = 1;
+
+ final Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_SPAM: {
+ boolean fg = msg.arg1 != 0;
+ Intent intent = new Intent(ActivityTestMain.this, SpamActivity.class);
+ Bundle options = null;
+ if (fg) {
+ ActivityOptions opts = ActivityOptions.makeLaunchTaskBehindAnimation();
+ options = opts.toBundle();
+ }
+ startActivity(intent, options);
+ scheduleSpam(!fg);
+ } break;
+ }
+ super.handleMessage(msg);
+ }
+ };
+
class BroadcastResultReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
@@ -143,7 +168,8 @@ public class ActivityTestMain extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
- @Override public boolean onMenuItemClick(MenuItem item) {
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this,
R.style.SlowDialog);
builder.setTitle("This is a title");
@@ -316,6 +342,49 @@ public class ActivityTestMain extends Activity {
return true;
}
});
+ menu.add("Open Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ ActivityManager.AppTask task = findDocTask();
+ if (task == null) {
+ Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT
+ | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
+ | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
+ startActivity(intent);
+ } else {
+ task.moveToFront();
+ }
+ return true;
+ }
+ });
+ menu.add("Stack Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ ActivityManager.AppTask task = findDocTask();
+ if (task != null) {
+ ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
+ Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
+ if (recent.id >= 0) {
+ // Stack on top.
+ intent.putExtra(DocActivity.LABEL, "Stacked");
+ task.startActivity(ActivityTestMain.this, intent, null);
+ } else {
+ // Start root activity.
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT
+ | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
+ | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
+ intent.putExtra(DocActivity.LABEL, "New Root");
+ task.startActivity(ActivityTestMain.this, intent, null);
+ }
+ }
+ return true;
+ }
+ });
+ menu.add("Spam!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ scheduleSpam(false);
+ return true;
+ }
+ });
return true;
}
@@ -342,6 +411,12 @@ public class ActivityTestMain extends Activity {
mConnections.clear();
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mHandler.removeMessages(MSG_SPAM);
+ }
+
void addAppRecents(int count) {
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
Intent intent = new Intent(Intent.ACTION_MAIN);
@@ -371,7 +446,31 @@ public class ActivityTestMain extends Activity {
}
}
}
- private View scrollWrap(View view) {
+
+ ActivityManager.AppTask findDocTask() {
+ ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
+ List<ActivityManager.AppTask> tasks = am.getAppTasks();
+ if (tasks != null) {
+ for (int i=0; i<tasks.size(); i++) {
+ ActivityManager.AppTask task = tasks.get(i);
+ ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
+ if (recent.baseIntent != null
+ && recent.baseIntent.getComponent().getClassName().equals(
+ DocActivity.class.getCanonicalName())) {
+ return task;
+ }
+ }
+ }
+ return null;
+ }
+
+ void scheduleSpam(boolean fg) {
+ mHandler.removeMessages(MSG_SPAM);
+ Message msg = mHandler.obtainMessage(MSG_SPAM, fg ? 1 : 0, 0);
+ mHandler.sendMessageDelayed(msg, 500);
+ }
+
+ private View scrollWrap(View view) {
ScrollView scroller = new ScrollView(this);
scroller.addView(view, new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT,
ScrollView.LayoutParams.MATCH_PARENT));
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/DocActivity.java b/tests/ActivityTests/src/com/google/android/test/activity/DocActivity.java
new file mode 100644
index 0000000..6330c79
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/DocActivity.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 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.google.android.test.activity;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.os.Bundle;
+
+public class DocActivity extends Activity {
+ static final String LABEL = "label";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ String label = getIntent().getStringExtra(LABEL);
+ if (label != null) {
+ setTaskDescription(new ActivityManager.TaskDescription(label));
+ setTitle(label);
+ }
+ }
+}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SpamActivity.java b/tests/ActivityTests/src/com/google/android/test/activity/SpamActivity.java
new file mode 100644
index 0000000..e5de559
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SpamActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.google.android.test.activity;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class SpamActivity extends Activity {
+ byte[] mBytes;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // Chew up some RAM -- 8 megs worth.
+ mBytes = new byte[8*1024*1024];
+ }
+}