summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-08-16 16:42:52 -0700
committerDianne Hackborn <hackbod@google.com>2012-08-17 10:36:08 -0700
commit79af1dd54c16cde063152922b42c96d72ae9eca8 (patch)
tree142abf0037d20841712e88d65febcbbd92dd5561
parentf1b995f9d049cb5c7225b3b17f09369237a83ca2 (diff)
downloadframeworks_base-79af1dd54c16cde063152922b42c96d72ae9eca8.zip
frameworks_base-79af1dd54c16cde063152922b42c96d72ae9eca8.tar.gz
frameworks_base-79af1dd54c16cde063152922b42c96d72ae9eca8.tar.bz2
Switch public APIs to use new UserHandle class for identifying users.
Gets rid of "yet another integer" confusion. Change-Id: Id07ea7307aea7c62f0087c6663a1f1c08e2e5dee
-rw-r--r--api/current.txt27
-rw-r--r--core/java/android/accounts/AccountManagerService.java2
-rw-r--r--core/java/android/app/ContextImpl.java18
-rw-r--r--core/java/android/app/PendingIntent.java10
-rw-r--r--core/java/android/content/Context.java17
-rw-r--r--core/java/android/content/ContextWrapper.java17
-rw-r--r--core/java/android/content/IntentSender.java10
-rw-r--r--core/java/android/os/Process.java6
-rw-r--r--core/java/android/os/UserHandle.java126
-rw-r--r--core/java/android/os/UserManager.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/SearchPanelView.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java3
-rw-r--r--policy/src/com/android/internal/policy/impl/LockScreen.java2
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java4
-rw-r--r--services/java/com/android/server/AppWidgetServiceImpl.java10
-rw-r--r--test-runner/src/android/test/mock/MockContext.java5
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java3
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java4
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java3
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java3
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java5
23 files changed, 206 insertions, 80 deletions
diff --git a/api/current.txt b/api/current.txt
index 84132c2..b489dfd 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -3872,7 +3872,7 @@ package android.app {
method public static android.app.PendingIntent getService(android.content.Context, int, android.content.Intent, int);
method public java.lang.String getTargetPackage();
method public int getTargetUid();
- method public int getTargetUserHandle();
+ method public android.os.UserHandle getTargetUserHandle();
method public static android.app.PendingIntent readPendingIntentOrNullFromParcel(android.os.Parcel);
method public void send() throws android.app.PendingIntent.CanceledException;
method public void send(int) throws android.app.PendingIntent.CanceledException;
@@ -5324,10 +5324,10 @@ package android.content {
method public abstract void revokeUriPermission(android.net.Uri, int);
method public abstract void sendBroadcast(android.content.Intent);
method public abstract void sendBroadcast(android.content.Intent, java.lang.String);
- method public abstract void sendBroadcastToUser(android.content.Intent, int);
+ method public abstract void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle);
method public abstract void sendOrderedBroadcast(android.content.Intent, java.lang.String);
method public abstract void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
- method public abstract void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
+ method public abstract void sendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public abstract void sendStickyBroadcast(android.content.Intent);
method public abstract void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public abstract void setTheme(int);
@@ -5461,10 +5461,10 @@ package android.content {
method public void revokeUriPermission(android.net.Uri, int);
method public void sendBroadcast(android.content.Intent);
method public void sendBroadcast(android.content.Intent, java.lang.String);
- method public void sendBroadcastToUser(android.content.Intent, int);
+ method public void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle);
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String);
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
- method public void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
+ method public void sendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public void sendStickyBroadcast(android.content.Intent);
method public void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public void setTheme(int);
@@ -5990,7 +5990,7 @@ package android.content {
method public int describeContents();
method public java.lang.String getTargetPackage();
method public int getTargetUid();
- method public int getTargetUserHandle();
+ method public android.os.UserHandle getTargetUserHandle();
method public static android.content.IntentSender readIntentSenderOrNullFromParcel(android.os.Parcel);
method public void sendIntent(android.content.Context, int, android.content.Intent, android.content.IntentSender.OnFinished, android.os.Handler) throws android.content.IntentSender.SendIntentException;
method public void sendIntent(android.content.Context, int, android.content.Intent, android.content.IntentSender.OnFinished, android.os.Handler, java.lang.String) throws android.content.IntentSender.SendIntentException;
@@ -16302,7 +16302,7 @@ package android.os {
method public static final int myPid();
method public static final int myTid();
method public static final int myUid();
- method public static final int myUserHandle();
+ method public static final android.os.UserHandle myUserHandle();
method public static final void sendSignal(int, int);
method public static final void setThreadPriority(int, int) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
method public static final void setThreadPriority(int) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
@@ -16457,6 +16457,15 @@ package android.os {
ctor public TransactionTooLargeException();
}
+ public final class UserHandle implements android.os.Parcelable {
+ ctor public UserHandle(android.os.Parcel);
+ method public int describeContents();
+ method public static android.os.UserHandle readFromParcel(android.os.Parcel);
+ method public void writeToParcel(android.os.Parcel, int);
+ method public static void writeToParcel(android.os.UserHandle, android.os.Parcel);
+ field public static final android.os.Parcelable.Creator CREATOR;
+ }
+
public class UserManager {
method public java.lang.String getUserName();
method public boolean supportsMultipleUsers();
@@ -21206,10 +21215,10 @@ package android.test.mock {
method public void revokeUriPermission(android.net.Uri, int);
method public void sendBroadcast(android.content.Intent);
method public void sendBroadcast(android.content.Intent, java.lang.String);
- method public void sendBroadcastToUser(android.content.Intent, int);
+ method public void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle);
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String);
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
- method public void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
+ method public void sendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public void sendStickyBroadcast(android.content.Intent);
method public void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
method public void setTheme(int);
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java
index d61d9da..7a9f285 100644
--- a/core/java/android/accounts/AccountManagerService.java
+++ b/core/java/android/accounts/AccountManagerService.java
@@ -900,7 +900,7 @@ public class AccountManagerService
private void sendAccountsChangedBroadcast(int userId) {
Log.i(TAG, "the accounts changed, sending broadcast of "
+ ACCOUNTS_CHANGED_INTENT.getAction());
- mContext.sendBroadcastToUser(ACCOUNTS_CHANGED_INTENT, userId);
+ mContext.sendBroadcastAsUser(ACCOUNTS_CHANGED_INTENT, new UserHandle(userId));
}
public void clearPassword(Account account) {
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index ed4f0a7..08947a4 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -906,12 +906,13 @@ class ContextImpl extends Context {
/** @hide */
@Override
- public void startActivityAsUser(Intent intent, int userId) {
+ public void startActivityAsUser(Intent intent, UserHandle user) {
try {
ActivityManagerNative.getDefault().startActivityAsUser(
mMainThread.getApplicationThread(), intent,
intent.resolveTypeIfNeeded(getContentResolver()),
- null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, null, null, userId);
+ null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, null, null,
+ user.getIdentifier());
} catch (RemoteException re) {
}
}
@@ -931,12 +932,13 @@ class ContextImpl extends Context {
/** @hide */
@Override
- public void startActivityAsUser(Intent intent, Bundle options, int userId) {
+ public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) {
try {
ActivityManagerNative.getDefault().startActivityAsUser(
mMainThread.getApplicationThread(), intent,
intent.resolveTypeIfNeeded(getContentResolver()),
- null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, null, options, userId);
+ null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, null, options,
+ user.getIdentifier());
} catch (RemoteException re) {
}
}
@@ -1062,19 +1064,19 @@ class ContextImpl extends Context {
}
@Override
- public void sendBroadcastToUser(Intent intent, int userHandle) {
+ public void sendBroadcastAsUser(Intent intent, UserHandle user) {
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
try {
intent.setAllowFds(false);
ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(),
intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, false,
- userHandle);
+ user.getIdentifier());
} catch (RemoteException e) {
}
}
@Override
- public void sendOrderedBroadcastToUser(Intent intent, int userHandle,
+ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras) {
IIntentReceiver rd = null;
@@ -1100,7 +1102,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, rd,
initialCode, initialData, initialExtras, null,
- true, false, userHandle);
+ true, false, user.getIdentifier());
} catch (RemoteException e) {
}
}
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index f638f7e..a57c516 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -639,22 +639,22 @@ public final class PendingIntent implements Parcelable {
/**
* Return the user handle of the application that created this
* PendingIntent, that is the user under which you will actually be
- * sending the Intent. The returned integer is supplied by the system, so
+ * sending the Intent. The returned UserHandle is supplied by the system, so
* that an application can not spoof its user. See
* {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
* more explanation of user handles.
*
- * @return The user handle of the PendingIntent, or -1 if there is
+ * @return The user handle of the PendingIntent, or null if there is
* none associated with it.
*/
- public int getTargetUserHandle() {
+ public UserHandle getTargetUserHandle() {
try {
int uid = ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
- return uid > 0 ? UserHandle.getUserId(uid) : -1;
+ return uid > 0 ? new UserHandle(UserHandle.getUserId(uid)) : null;
} catch (RemoteException e) {
// Should never happen.
- return -1;
+ return null;
}
}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index a90142a..a70bf6c 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -32,6 +32,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.os.UserHandle;
import android.util.AttributeSet;
import java.io.File;
@@ -855,11 +856,11 @@ public abstract class Context {
* Same as {@link #startActivity(Intent)}, but for a specific user. It requires holding
* the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
* @param intent The description of the activity to start.
- * @param userId The user id of the user to start this activity for.
+ * @param user The UserHandle of the user to start this activity for.
* @throws ActivityNotFoundException
* @hide
*/
- public void startActivityAsUser(Intent intent, int userId) {
+ public void startActivityAsUser(Intent intent, UserHandle user) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
@@ -898,11 +899,11 @@ public abstract class Context {
* May be null if there are no options. See {@link android.app.ActivityOptions}
* for how to build the Bundle supplied here; there are no supported definitions
* for building it manually.
- * @param userId The user id of the user to start this activity for.
+ * @param user The UserHandle of the user to start this activity for.
* @throws ActivityNotFoundException
* @hide
*/
- public void startActivityAsUser(Intent intent, Bundle options, int userId) {
+ public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
@@ -1119,10 +1120,10 @@ public abstract class Context {
* requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
* permission.
* @param intent The intent to broadcast
- * @param userHandle User to send the intent to.
+ * @param user UserHandle to send the intent to.
* @see #sendBroadcast(Intent)
*/
- public abstract void sendBroadcastToUser(Intent intent, int userHandle);
+ public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
/**
* Same as
@@ -1136,7 +1137,7 @@ public abstract class Context {
*
* @param intent The Intent to broadcast; all receivers matching this
* Intent will receive the broadcast.
- * @param userHandle User to send the intent to.
+ * @param user UserHandle to send the intent to.
* @param resultReceiver Your own BroadcastReceiver to treat as the final
* receiver of the broadcast.
* @param scheduler A custom Handler with which to schedule the
@@ -1151,7 +1152,7 @@ public abstract class Context {
*
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
*/
- public abstract void sendOrderedBroadcastToUser(Intent intent, int userHandle,
+ public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras);
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index fdf60ab..75842be 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -30,6 +30,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.os.UserHandle;
import java.io.File;
import java.io.FileInputStream;
@@ -279,8 +280,8 @@ public class ContextWrapper extends Context {
/** @hide */
@Override
- public void startActivityAsUser(Intent intent, int userId) {
- mBase.startActivityAsUser(intent, userId);
+ public void startActivityAsUser(Intent intent, UserHandle user) {
+ mBase.startActivityAsUser(intent, user);
}
@Override
@@ -290,8 +291,8 @@ public class ContextWrapper extends Context {
/** @hide */
@Override
- public void startActivityAsUser(Intent intent, Bundle options, int userId) {
- mBase.startActivityAsUser(intent, options, userId);
+ public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) {
+ mBase.startActivityAsUser(intent, options, user);
}
@Override
@@ -347,15 +348,15 @@ public class ContextWrapper extends Context {
}
@Override
- public void sendBroadcastToUser(Intent intent, int userHandle) {
- mBase.sendBroadcastToUser(intent, userHandle);
+ public void sendBroadcastAsUser(Intent intent, UserHandle user) {
+ mBase.sendBroadcastAsUser(intent, user);
}
@Override
- public void sendOrderedBroadcastToUser(Intent intent, int userHandle,
+ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras) {
- mBase.sendOrderedBroadcastToUser(intent, userHandle, resultReceiver,
+ mBase.sendOrderedBroadcastAsUser(intent, user, resultReceiver,
scheduler, initialCode, initialData, initialExtras);
}
diff --git a/core/java/android/content/IntentSender.java b/core/java/android/content/IntentSender.java
index 1801488..079241a 100644
--- a/core/java/android/content/IntentSender.java
+++ b/core/java/android/content/IntentSender.java
@@ -245,22 +245,22 @@ public class IntentSender implements Parcelable {
/**
* Return the user handle of the application that created this
* PendingIntent, that is the user under which you will actually be
- * sending the Intent. The returned integer is supplied by the system, so
+ * sending the Intent. The returned UserHandle is supplied by the system, so
* that an application can not spoof its user. See
* {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
* more explanation of user handles.
*
- * @return The user handle of the PendingIntent, or -1 if there is
+ * @return The user handle of the PendingIntent, or null if there is
* none associated with it.
*/
- public int getTargetUserHandle() {
+ public UserHandle getTargetUserHandle() {
try {
int uid = ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
- return uid > 0 ? UserHandle.getUserId(uid) : -1;
+ return uid > 0 ? new UserHandle(UserHandle.getUserId(uid)) : null;
} catch (RemoteException e) {
// Should never happen.
- return -1;
+ return null;
}
}
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 0553384..3513bdc 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -655,13 +655,13 @@ public class Process {
public static final native int myUid();
/**
- * Returns the identifier of this process's user handle. This is the
+ * Returns this process's user handle. This is the
* user the process is running under. It is distinct from
* {@link #myUid()} in that a particular user will have multiple
* distinct apps running under it each with their own uid.
*/
- public static final int myUserHandle() {
- return UserHandle.getUserId(myUid());
+ public static final UserHandle myUserHandle() {
+ return new UserHandle(UserHandle.getUserId(myUid()));
}
/**
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 577a8c6..0843d85 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -18,31 +18,33 @@ package android.os;
/**
* Representation of a user on the device.
- * @hide
*/
-public final class UserHandle {
+public final class UserHandle implements Parcelable {
/**
- * Range of IDs allocated for a user.
- *
- * @hide
+ * @hide Range of uids allocated for a user.
*/
public static final int PER_USER_RANGE = 100000;
- /** A user id to indicate all users on the device */
+ /** @hide A user id to indicate all users on the device */
public static final int USER_ALL = -1;
- /** A user id to indicate the currently active user */
+ /** @hide A user id to indicate the currently active user */
public static final int USER_CURRENT = -2;
- /** A user id constant to indicate the "owner" user of the device */
+ /** @hide An undefined user id */
+ public static final int USER_NULL = -10000;
+
+ /** @hide A user id constant to indicate the "owner" user of the device */
public static final int USER_OWNER = 0;
/**
- * Enable multi-user related side effects. Set this to false if there are problems with single
- * user usecases.
- * */
+ * @hide Enable multi-user related side effects. Set this to false if
+ * there are problems with single user use-cases.
+ */
public static final boolean MU_ENABLED = true;
+ final int mHandle;
+
/**
* Checks to see if the user id is the same for the two uids, i.e., they belong to the same
* user.
@@ -64,11 +66,13 @@ public final class UserHandle {
return getAppId(uid1) == getAppId(uid2);
}
+ /** @hide */
public static final boolean isIsolated(int uid) {
uid = getAppId(uid);
return uid >= Process.FIRST_ISOLATED_UID && uid <= Process.LAST_ISOLATED_UID;
}
+ /** @hide */
public static boolean isApp(int uid) {
if (uid > 0) {
uid = UserHandle.getAppId(uid);
@@ -90,6 +94,7 @@ public final class UserHandle {
}
}
+ /** @hide */
public static final int getCallingUserId() {
return getUserId(Binder.getCallingUid());
}
@@ -117,8 +122,107 @@ public final class UserHandle {
/**
* Returns the user id of the current process
* @return user id of the current process
+ * @hide
*/
public static final int myUserId() {
return getUserId(Process.myUid());
}
+
+ /** @hide */
+ public UserHandle(int h) {
+ mHandle = h;
+ }
+
+ /** @hide */
+ public int getIdentifier() {
+ return mHandle;
+ }
+
+ @Override
+ public String toString() {
+ return "UserHandle{" + mHandle + "}";
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ try {
+ if (obj != null) {
+ UserHandle other = (UserHandle)obj;
+ return mHandle == other.mHandle;
+ }
+ } catch (ClassCastException e) {
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return mHandle;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(mHandle);
+ }
+
+ /**
+ * Write a UserHandle to a Parcel, handling null pointers. Must be
+ * read with {@link #readFromParcel(Parcel)}.
+ *
+ * @param h The UserHandle to be written.
+ * @param out The Parcel in which the UserHandle will be placed.
+ *
+ * @see #readFromParcel(Parcel)
+ */
+ public static void writeToParcel(UserHandle h, Parcel out) {
+ if (h != null) {
+ h.writeToParcel(out, 0);
+ } else {
+ out.writeInt(USER_NULL);
+ }
+ }
+
+ /**
+ * Read a UserHandle from a Parcel that was previously written
+ * with {@link #writeToParcel(UserHandle, Parcel)}, returning either
+ * a null or new object as appropriate.
+ *
+ * @param in The Parcel from which to read the UserHandle
+ * @return Returns a new UserHandle matching the previously written
+ * object, or null if a null had been written.
+ *
+ * @see #writeToParcel(UserHandle, Parcel)
+ */
+ public static UserHandle readFromParcel(Parcel in) {
+ int h = in.readInt();
+ return h != USER_NULL ? new UserHandle(h) : null;
+ }
+
+ public static final Parcelable.Creator<UserHandle> CREATOR
+ = new Parcelable.Creator<UserHandle>() {
+ public UserHandle createFromParcel(Parcel in) {
+ return new UserHandle(in);
+ }
+
+ public UserHandle[] newArray(int size) {
+ return new UserHandle[size];
+ }
+ };
+
+ /**
+ * Instantiate a new UserHandle from the data in a Parcel that was
+ * previously written with {@link #writeToParcel(Parcel, int)}. Note that you
+ * must not use this with data written by
+ * {@link #writeToParcel(UserHandle, Parcel)} since it is not possible
+ * to handle a null UserHandle here.
+ *
+ * @param in The Parcel containing the previously written UserHandle,
+ * positioned at the location in the buffer where it was written.
+ */
+ public UserHandle(Parcel in) {
+ mHandle = in.readInt();
+ }
}
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 93da44a..0338ee7 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -51,7 +51,7 @@ public class UserManager {
* @hide
* */
public int getUserHandle() {
- return Process.myUserHandle();
+ return UserHandle.myUserId();
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/SearchPanelView.java b/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
index a2f43fd..281f25f 100644
--- a/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
@@ -82,7 +82,8 @@ public class SearchPanelView extends FrameLayout implements
R.anim.search_launch_enter, R.anim.search_launch_exit,
getHandler(), this);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivityAsUser(intent, opts.toBundle(), UserHandle.USER_CURRENT);
+ mContext.startActivityAsUser(intent, opts.toBundle(),
+ new UserHandle(UserHandle.USER_CURRENT));
} catch (ActivityNotFoundException e) {
Slog.w(TAG, "Activity not found for " + intent.getAction());
onAnimationStarted();
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index 7d36152..7738f81 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -790,7 +790,8 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
| Intent.FLAG_ACTIVITY_TASK_ON_HOME
| Intent.FLAG_ACTIVITY_NEW_TASK);
if (DEBUG) Log.v(TAG, "Starting activity " + intent);
- context.startActivityAsUser(intent, opts.toBundle(), UserHandle.USER_CURRENT);
+ context.startActivityAsUser(intent, opts.toBundle(),
+ new UserHandle(UserHandle.USER_CURRENT));
}
if (usingDrawingCache) {
holder.thumbnailViewImage.setDrawingCacheEnabled(false);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index a20576f..49e4760 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -1783,7 +1783,8 @@ public class PhoneStatusBar extends BaseStatusBar {
} catch (RemoteException e) {
}
v.getContext().startActivityAsUser(new Intent(Settings.ACTION_SETTINGS)
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), UserHandle.USER_CURRENT);
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+ new UserHandle(UserHandle.USER_CURRENT));
animateCollapse();
}
};
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java
index ffe69e2..c45ac3f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java
@@ -119,7 +119,8 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
// ----------------------------
private void onClickSettings() {
getContext().startActivityAsUser(new Intent(Settings.ACTION_SETTINGS)
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), UserHandle.USER_CURRENT);
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+ new UserHandle(UserHandle.USER_CURRENT));
getStatusBarManager().collapse();
}
}
diff --git a/policy/src/com/android/internal/policy/impl/LockScreen.java b/policy/src/com/android/internal/policy/impl/LockScreen.java
index 5f5c105..91b5ca1 100644
--- a/policy/src/com/android/internal/policy/impl/LockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/LockScreen.java
@@ -354,7 +354,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
Log.w(TAG, "can't dismiss keyguard on launch");
}
try {
- mContext.startActivityAsUser(intent, UserHandle.USER_CURRENT);
+ mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
}
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 40db612..737df7f 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -2066,7 +2066,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (searchManager != null) {
searchManager.stopSearch();
}
- mContext.startActivityAsUser(intent, UserHandle.USER_CURRENT);
+ mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
} catch (ActivityNotFoundException e) {
Slog.w(TAG, "No activity to handle assist long press action.", e);
}
@@ -2081,7 +2081,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
| Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
- mContext.startActivityAsUser(intent, UserHandle.USER_CURRENT);
+ mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
} catch (ActivityNotFoundException e) {
Slog.w(TAG, "No activity to handle assist action.", e);
}
diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java
index 5250dfc..539e561 100644
--- a/services/java/com/android/server/AppWidgetServiceImpl.java
+++ b/services/java/com/android/server/AppWidgetServiceImpl.java
@@ -499,7 +499,7 @@ class AppWidgetServiceImpl {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
intent.setComponent(p.info.provider);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
- mContext.sendBroadcastToUser(intent, mUserId);
+ mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
if (p.instances.size() == 0) {
// cancel the future updates
cancelBroadcasts(p);
@@ -507,7 +507,7 @@ class AppWidgetServiceImpl {
// send the broacast saying that the provider is not in use any more
intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED);
intent.setComponent(p.info.provider);
- mContext.sendBroadcastToUser(intent, mUserId);
+ mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
}
}
}
@@ -880,7 +880,7 @@ class AppWidgetServiceImpl {
intent.setComponent(p.info.provider);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
- mContext.sendBroadcastToUser(intent, mUserId);
+ mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
}
}
@@ -1205,7 +1205,7 @@ class AppWidgetServiceImpl {
void sendEnableIntentLocked(Provider p) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED);
intent.setComponent(p.info.provider);
- mContext.sendBroadcastToUser(intent, mUserId);
+ mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
}
void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) {
@@ -1213,7 +1213,7 @@ class AppWidgetServiceImpl {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
intent.setComponent(p.info.provider);
- mContext.sendBroadcastToUser(intent, mUserId);
+ mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
}
}
diff --git a/test-runner/src/android/test/mock/MockContext.java b/test-runner/src/android/test/mock/MockContext.java
index 36f2c14..02d0b45 100644
--- a/test-runner/src/android/test/mock/MockContext.java
+++ b/test-runner/src/android/test/mock/MockContext.java
@@ -38,6 +38,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.os.UserHandle;
import java.io.File;
import java.io.FileInputStream;
@@ -304,12 +305,12 @@ public class MockContext extends Context {
}
@Override
- public void sendBroadcastToUser(Intent intent, int userId) {
+ public void sendBroadcastAsUser(Intent intent, UserHandle user) {
throw new UnsupportedOperationException();
}
@Override
- public void sendOrderedBroadcastToUser(Intent intent, int userId,
+ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras) {
throw new UnsupportedOperationException();
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 0577dbb..9599b19 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -30,6 +30,7 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -187,7 +188,7 @@ public class ActivityTestMain extends Activity {
menu.add("Send to user 1!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
- sendOrderedBroadcastToUser(intent, 1, new BroadcastResultReceiver(),
+ sendOrderedBroadcastAsUser(intent, new UserHandle(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
index 83785e4..1e7b8f4 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
@@ -21,7 +21,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Process;
+import android.os.UserHandle;
public class SingleUserProvider extends ContentProvider {
static final String AUTHORITY = "com.google.android.test.activity.single_user";
@@ -60,7 +60,7 @@ public class SingleUserProvider extends ContentProvider {
@Override
public Bundle call(String method, String arg, Bundle extras) {
Bundle res = new Bundle();
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
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
index 9295cf4..8afa478 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
@@ -21,12 +21,13 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
+import android.os.UserHandle;
public class SingleUserReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle res = getResultExtras(true);
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
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 9c6a9f1..47539a1 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
+import android.os.UserHandle;
import android.util.Log;
public class UserTarget extends BroadcastReceiver {
@@ -28,7 +29,7 @@ public class UserTarget extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.i("ActivityTest", "Received: " + intent);
Bundle res = getResultExtras(true);
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
setResultExtras(res);
}
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 292e4fc..943357a 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -61,6 +61,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
+import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
@@ -1193,12 +1194,12 @@ public final class BridgeContext extends Context {
}
@Override
- public void sendBroadcastToUser(Intent intent, int userId) {
+ public void sendBroadcastAsUser(Intent intent, UserHandle user) {
// pass
}
@Override
- public void sendOrderedBroadcastToUser(Intent intent, int userId,
+ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras) {
// pass