Skip to content

Commit abac0cd

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Add PendingIntent and IntentSender APIs to get user handle." into jb-mr1-dev
2 parents 34743ac + c750127 commit abac0cd

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

api/current.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,8 @@ package android.app {
38703870
method public android.content.IntentSender getIntentSender();
38713871
method public static android.app.PendingIntent getService(android.content.Context, int, android.content.Intent, int);
38723872
method public java.lang.String getTargetPackage();
3873+
method public int getTargetUid();
3874+
method public int getTargetUserHandle();
38733875
method public static android.app.PendingIntent readPendingIntentOrNullFromParcel(android.os.Parcel);
38743876
method public void send() throws android.app.PendingIntent.CanceledException;
38753877
method public void send(int) throws android.app.PendingIntent.CanceledException;
@@ -5986,6 +5988,8 @@ package android.content {
59865988
public class IntentSender implements android.os.Parcelable {
59875989
method public int describeContents();
59885990
method public java.lang.String getTargetPackage();
5991+
method public int getTargetUid();
5992+
method public int getTargetUserHandle();
59895993
method public static android.content.IntentSender readIntentSenderOrNullFromParcel(android.os.Parcel);
59905994
method public void sendIntent(android.content.Context, int, android.content.Intent, android.content.IntentSender.OnFinished, android.os.Handler) throws android.content.IntentSender.SendIntentException;
59915995
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;

core/java/android/app/PendingIntent.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.os.IBinder;
2828
import android.os.Parcel;
2929
import android.os.Parcelable;
30+
import android.os.UserId;
3031
import android.util.AndroidException;
3132

3233
/**
@@ -616,6 +617,47 @@ public String getTargetPackage() {
616617
}
617618
}
618619

620+
/**
621+
* Return the uid of the application that created this
622+
* PendingIntent, that is the identity under which you will actually be
623+
* sending the Intent. The returned integer is supplied by the system, so
624+
* that an application can not spoof its uid.
625+
*
626+
* @return The uid of the PendingIntent, or -1 if there is
627+
* none associated with it.
628+
*/
629+
public int getTargetUid() {
630+
try {
631+
return ActivityManagerNative.getDefault()
632+
.getUidForIntentSender(mTarget);
633+
} catch (RemoteException e) {
634+
// Should never happen.
635+
return -1;
636+
}
637+
}
638+
639+
/**
640+
* Return the user handle of the application that created this
641+
* PendingIntent, that is the user under which you will actually be
642+
* sending the Intent. The returned integer is supplied by the system, so
643+
* that an application can not spoof its user. See
644+
* {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
645+
* more explanation of user handles.
646+
*
647+
* @return The user handle of the PendingIntent, or -1 if there is
648+
* none associated with it.
649+
*/
650+
public int getTargetUserHandle() {
651+
try {
652+
int uid = ActivityManagerNative.getDefault()
653+
.getUidForIntentSender(mTarget);
654+
return uid > 0 ? UserId.getUserId(uid) : -1;
655+
} catch (RemoteException e) {
656+
// Should never happen.
657+
return -1;
658+
}
659+
}
660+
619661
/**
620662
* @hide
621663
* Check to verify that this PendingIntent targets a specific package.

core/java/android/content/IntentSender.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.os.IBinder;
2828
import android.os.Parcel;
2929
import android.os.Parcelable;
30+
import android.os.UserId;
3031
import android.util.AndroidException;
3132

3233

@@ -222,6 +223,47 @@ public String getTargetPackage() {
222223
}
223224
}
224225

226+
/**
227+
* Return the uid of the application that created this
228+
* PendingIntent, that is the identity under which you will actually be
229+
* sending the Intent. The returned integer is supplied by the system, so
230+
* that an application can not spoof its uid.
231+
*
232+
* @return The uid of the PendingIntent, or -1 if there is
233+
* none associated with it.
234+
*/
235+
public int getTargetUid() {
236+
try {
237+
return ActivityManagerNative.getDefault()
238+
.getUidForIntentSender(mTarget);
239+
} catch (RemoteException e) {
240+
// Should never happen.
241+
return -1;
242+
}
243+
}
244+
245+
/**
246+
* Return the user handle of the application that created this
247+
* PendingIntent, that is the user under which you will actually be
248+
* sending the Intent. The returned integer is supplied by the system, so
249+
* that an application can not spoof its user. See
250+
* {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
251+
* more explanation of user handles.
252+
*
253+
* @return The user handle of the PendingIntent, or -1 if there is
254+
* none associated with it.
255+
*/
256+
public int getTargetUserHandle() {
257+
try {
258+
int uid = ActivityManagerNative.getDefault()
259+
.getUidForIntentSender(mTarget);
260+
return uid > 0 ? UserId.getUserId(uid) : -1;
261+
} catch (RemoteException e) {
262+
// Should never happen.
263+
return -1;
264+
}
265+
}
266+
225267
/**
226268
* Comparison operator on two IntentSender objects, such that true
227269
* is returned then they both represent the same operation from the

0 commit comments

Comments
 (0)