summaryrefslogtreecommitdiffstats
path: root/tests/ActivityTests
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-09-25 14:53:52 -0700
committerDianne Hackborn <hackbod@google.com>2012-09-25 17:14:22 -0700
commit3992645bf333c56669ef2fa19c26b2947884a4f3 (patch)
treee75d77024860894fd438a6926ccd7e3546b737d3 /tests/ActivityTests
parent2fd6cb043901c1bfbf5f566d13522cc3c1c21fb4 (diff)
downloadframeworks_base-3992645bf333c56669ef2fa19c26b2947884a4f3.zip
frameworks_base-3992645bf333c56669ef2fa19c26b2947884a4f3.tar.gz
frameworks_base-3992645bf333c56669ef2fa19c26b2947884a4f3.tar.bz2
More activity tests.
Change-Id: Id381ee2db55b135a0734c193fce44c55ef1cdae6
Diffstat (limited to 'tests/ActivityTests')
-rw-r--r--tests/ActivityTests/AndroidManifest.xml4
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java90
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ServiceUserTarget.java41
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserService.java10
4 files changed, 142 insertions, 3 deletions
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml
index 9dfe4a1..15d075c 100644
--- a/tests/ActivityTests/AndroidManifest.xml
+++ b/tests/ActivityTests/AndroidManifest.xml
@@ -21,6 +21,8 @@
<uses-permission android:name="android.permission.REMOVE_TASKS" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+ <uses-permission android:name="android.permission.MANAGE_USERS" />
<application android:label="ActivityTest">
<activity android:name="ActivityTestMain">
<intent-filter>
@@ -31,6 +33,8 @@
<service android:name="SingleUserService"
android:singleUser="true" android:exported="true">
</service>
+ <service android:name="ServiceUserTarget">
+ </service>
<receiver android:name="UserTarget">
</receiver>
<receiver android:name="SingleUserReceiver"
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 2348e99..f0c3b22 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -16,6 +16,7 @@
package com.google.android.test.activity;
+import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
@@ -31,6 +32,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.os.UserManager;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -41,6 +43,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.Context;
+import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.util.Log;
@@ -51,6 +54,9 @@ public class ActivityTestMain extends Activity {
ActivityManager mAm;
Configuration mOverrideConfig;
+ int mSecondUser;
+
+ ArrayList<ServiceConnection> mConnections = new ArrayList<ServiceConnection>();
class BroadcastResultReceiver extends BroadcastReceiver {
@Override
@@ -122,6 +128,15 @@ public class ActivityTestMain extends Activity {
applyOverrideConfiguration(mOverrideConfig);
}
}
+
+ UserManager um = (UserManager)getSystemService(Context.USER_SERVICE);
+ List<UserInfo> users = um.getUsers();
+ mSecondUser = Integer.MAX_VALUE;
+ for (UserInfo ui : users) {
+ if (ui.id != 0 && mSecondUser > ui.id) {
+ mSecondUser = ui.id;
+ }
+ }
}
@Override
@@ -148,7 +163,12 @@ public class ActivityTestMain extends Activity {
Log.i(TAG, "Service disconnected " + name);
}
};
- bindService(intent, conn, Context.BIND_AUTO_CREATE);
+ if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
+ mConnections.add(conn);
+ } else {
+ Toast.makeText(ActivityTestMain.this, "Failed to bind",
+ Toast.LENGTH_LONG).show();
+ }
return true;
}
});
@@ -185,15 +205,70 @@ public class ActivityTestMain extends Activity {
return true;
}
});
- menu.add("Send to user 1!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
+ sendOrderedBroadcastAsUser(intent, new UserHandle(0), null,
+ new BroadcastResultReceiver(),
+ null, Activity.RESULT_OK, null, null);
+ return true;
+ }
+ });
+ menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener(
+ new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
- sendOrderedBroadcastAsUser(intent, new UserHandle(1), null,
+ sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null,
new BroadcastResultReceiver(),
null, Activity.RESULT_OK, null, null);
return true;
}
});
+ menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
+ ServiceConnection conn = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ Log.i(TAG, "Service connected " + name + " " + service);
+ }
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ Log.i(TAG, "Service disconnected " + name);
+ }
+ };
+ if (bindService(intent, conn, Context.BIND_AUTO_CREATE, 0)) {
+ mConnections.add(conn);
+ } else {
+ Toast.makeText(ActivityTestMain.this, "Failed to bind",
+ Toast.LENGTH_LONG).show();
+ }
+ return true;
+ }
+ });
+ menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener(
+ new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
+ ServiceConnection conn = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ Log.i(TAG, "Service connected " + name + " " + service);
+ }
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ Log.i(TAG, "Service disconnected " + name);
+ }
+ };
+ if (bindService(intent, conn, Context.BIND_AUTO_CREATE, mSecondUser)) {
+ mConnections.add(conn);
+ } else {
+ Toast.makeText(ActivityTestMain.this, "Failed to bind",
+ Toast.LENGTH_LONG).show();
+ }
+ return true;
+ }
+ });
menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
if (mOverrideConfig == null) {
@@ -226,6 +301,15 @@ public class ActivityTestMain extends Activity {
}
}
+ @Override
+ protected void onStop() {
+ super.onStop();
+ for (ServiceConnection conn : mConnections) {
+ unbindService(conn);
+ }
+ mConnections.clear();
+ }
+
private View scrollWrap(View view) {
ScrollView scroller = new ScrollView(this);
scroller.addView(view, new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT,
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/ServiceUserTarget.java b/tests/ActivityTests/src/com/google/android/test/activity/ServiceUserTarget.java
new file mode 100644
index 0000000..a7474ec
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ServiceUserTarget.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 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.Service;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.UserHandle;
+import android.widget.Toast;
+
+public class ServiceUserTarget extends Service {
+ Binder mBinder = new Binder();
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ Toast.makeText(this,
+ "Service created as user " + UserHandle.myUserId(),
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserService.java b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserService.java
index c40582a..e9c340f 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserService.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserService.java
@@ -20,11 +20,21 @@ import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
+import android.os.UserHandle;
+import android.widget.Toast;
public class SingleUserService extends Service {
Binder mBinder = new Binder();
@Override
+ public void onCreate() {
+ super.onCreate();
+ Toast.makeText(this,
+ "Service created as user " + UserHandle.myUserId(),
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
public IBinder onBind(Intent intent) {
return mBinder;
}