summaryrefslogtreecommitdiffstats
path: root/tests/ActivityTests
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-08-07 19:12:33 -0700
committerDianne Hackborn <hackbod@google.com>2012-08-07 19:19:22 -0700
commit7d19e0242faac8017033dabb872cdf1542fa184c (patch)
treeab12d3c6597bc42bc7c0dca10ded546192c5c249 /tests/ActivityTests
parent03ad783c5078c7bd487e47bb2a2af67dfbe89f1a (diff)
downloadframeworks_base-7d19e0242faac8017033dabb872cdf1542fa184c.zip
frameworks_base-7d19e0242faac8017033dabb872cdf1542fa184c.tar.gz
frameworks_base-7d19e0242faac8017033dabb872cdf1542fa184c.tar.bz2
More mult-user API work.
- You can now use android:singleUser with receivers and providers. - New API to send ordered broadcasts as a user. - New Process.myUserHandle() API. For now I am trying out "user handle" as the name for the numbers representing users. Change-Id: I754c713ab172494bb4251bc7a37a17324a2e235e
Diffstat (limited to 'tests/ActivityTests')
-rw-r--r--tests/ActivityTests/AndroidManifest.xml6
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java45
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java66
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java32
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java5
5 files changed, 153 insertions, 1 deletions
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml
index 6f00095..9dfe4a1 100644
--- a/tests/ActivityTests/AndroidManifest.xml
+++ b/tests/ActivityTests/AndroidManifest.xml
@@ -33,5 +33,11 @@
</service>
<receiver android:name="UserTarget">
</receiver>
+ <receiver android:name="SingleUserReceiver"
+ android:singleUser="true" android:exported="true" >
+ </receiver>
+ <provider android:name="SingleUserProvider"
+ android:authorities="com.google.android.test.activity.single_user"
+ android:singleUser="true" android:exported="true" />
</application>
</manifest>
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 bcef2d9..0ec1f13 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -22,16 +22,20 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
+import android.content.ContentProviderClient;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
+import android.os.RemoteException;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ScrollView;
+import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -43,6 +47,18 @@ public class ActivityTestMain extends Activity {
ActivityManager mAm;
+ class BroadcastResultReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Bundle res = getResultExtras(true);
+ int user = res.getInt("user", -1);
+ Toast.makeText(ActivityTestMain.this,
+ "Receiver executed as user "
+ + (user >= 0 ? Integer.toString(user) : "unknown"),
+ Toast.LENGTH_LONG).show();
+ }
+ }
+
private void addThumbnail(LinearLayout container, Bitmap bm,
final ActivityManager.RecentTaskInfo task,
final ActivityManager.TaskThumbnails thumbs, final int subIndex) {
@@ -134,8 +150,35 @@ public class ActivityTestMain extends Activity {
});
menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
+ Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class);
+ sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(),
+ null, Activity.RESULT_OK, null, null);
+ return true;
+ }
+ });
+ menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ ContentProviderClient cpl = getContentResolver().acquireContentProviderClient(
+ SingleUserProvider.AUTHORITY);
+ Bundle res = null;
+ try {
+ res = cpl.call("getuser", null, null);
+ } catch (RemoteException e) {
+ }
+ int user = res != null ? res.getInt("user", -1) : -1;
+ Toast.makeText(ActivityTestMain.this,
+ "Provider executed as user "
+ + (user >= 0 ? Integer.toString(user) : "unknown"),
+ Toast.LENGTH_LONG).show();
+ cpl.release();
+ return true;
+ }
+ });
+ menu.add("Send to user 1!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
- sendBroadcastToUser(intent, 1);
+ sendOrderedBroadcastToUser(intent, 1, new BroadcastResultReceiver(),
+ null, Activity.RESULT_OK, null, null);
return true;
}
});
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
new file mode 100644
index 0000000..83785e4
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
@@ -0,0 +1,66 @@
+/*
+ * 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.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Process;
+
+public class SingleUserProvider extends ContentProvider {
+ static final String AUTHORITY = "com.google.android.test.activity.single_user";
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public Bundle call(String method, String arg, Bundle extras) {
+ Bundle res = new Bundle();
+ res.putInt("user", Process.myUserHandle());
+ return res;
+ }
+}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
new file mode 100644
index 0000000..9295cf4
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
@@ -0,0 +1,32 @@
+/*
+ * 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.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Process;
+
+public class SingleUserReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Bundle res = getResultExtras(true);
+ res.putInt("user", Process.myUserHandle());
+ setResultExtras(res);
+ }
+}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java b/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
index 9890483..9c6a9f1 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
@@ -19,11 +19,16 @@ package com.google.android.test.activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.Bundle;
+import android.os.Process;
import android.util.Log;
public class UserTarget extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("ActivityTest", "Received: " + intent);
+ Bundle res = getResultExtras(true);
+ res.putInt("user", Process.myUserHandle());
+ setResultExtras(res);
}
}