|
27 | 27 | import android.os.IBinder; |
28 | 28 | import android.os.Parcel; |
29 | 29 | import android.os.Parcelable; |
| 30 | +import android.os.UserId; |
30 | 31 | import android.util.AndroidException; |
31 | 32 |
|
32 | 33 |
|
@@ -222,6 +223,47 @@ public String getTargetPackage() { |
222 | 223 | } |
223 | 224 | } |
224 | 225 |
|
| 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 | + |
225 | 267 | /** |
226 | 268 | * Comparison operator on two IntentSender objects, such that true |
227 | 269 | * is returned then they both represent the same operation from the |
|
0 commit comments