am abac0cd1: Merge "Add PendingIntent and IntentSender APIs to get user handle." into jb-mr1-dev

* commit 'abac0cd16105c60fdd6c5ce37116c972dc7431bb':
  Add PendingIntent and IntentSender APIs to get user handle.
This commit is contained in:
Dianne Hackborn
2012-08-14 18:27:21 -07:00
committed by Android Git Automerger
3 changed files with 88 additions and 0 deletions

View File

@@ -3870,6 +3870,8 @@ package android.app {
method public android.content.IntentSender getIntentSender();
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 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;
@@ -5986,6 +5988,8 @@ package android.content {
public class IntentSender implements android.os.Parcelable {
method public int describeContents();
method public java.lang.String getTargetPackage();
method public int getTargetUid();
method public int 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;

View File

@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserId;
import android.util.AndroidException;
/**
@@ -616,6 +617,47 @@ public final class PendingIntent implements Parcelable {
}
}
/**
* Return the uid of the application that created this
* PendingIntent, that is the identity under which you will actually be
* sending the Intent. The returned integer is supplied by the system, so
* that an application can not spoof its uid.
*
* @return The uid of the PendingIntent, or -1 if there is
* none associated with it.
*/
public int getTargetUid() {
try {
return ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
} catch (RemoteException e) {
// Should never happen.
return -1;
}
}
/**
* 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
* 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
* none associated with it.
*/
public int getTargetUserHandle() {
try {
int uid = ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
return uid > 0 ? UserId.getUserId(uid) : -1;
} catch (RemoteException e) {
// Should never happen.
return -1;
}
}
/**
* @hide
* Check to verify that this PendingIntent targets a specific package.

View File

@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserId;
import android.util.AndroidException;
@@ -222,6 +223,47 @@ public class IntentSender implements Parcelable {
}
}
/**
* Return the uid of the application that created this
* PendingIntent, that is the identity under which you will actually be
* sending the Intent. The returned integer is supplied by the system, so
* that an application can not spoof its uid.
*
* @return The uid of the PendingIntent, or -1 if there is
* none associated with it.
*/
public int getTargetUid() {
try {
return ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
} catch (RemoteException e) {
// Should never happen.
return -1;
}
}
/**
* 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
* 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
* none associated with it.
*/
public int getTargetUserHandle() {
try {
int uid = ActivityManagerNative.getDefault()
.getUidForIntentSender(mTarget);
return uid > 0 ? UserId.getUserId(uid) : -1;
} catch (RemoteException e) {
// Should never happen.
return -1;
}
}
/**
* Comparison operator on two IntentSender objects, such that true
* is returned then they both represent the same operation from the