diff options
| -rw-r--r-- | api/current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/app/PendingIntent.java | 42 | ||||
| -rw-r--r-- | core/java/android/content/IntentSender.java | 42 |
3 files changed, 88 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 2235ece22ccc..6a32efedfd63 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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; diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index 8adc8a2625af..c320ee399606 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -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; /** @@ -617,6 +618,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. */ diff --git a/core/java/android/content/IntentSender.java b/core/java/android/content/IntentSender.java index 4db4bdca3657..961864564be5 100644 --- a/core/java/android/content/IntentSender.java +++ b/core/java/android/content/IntentSender.java @@ -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; @@ -223,6 +224,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 * same package. |