diff options
| author | 2022-08-19 16:34:29 +0000 | |
|---|---|---|
| committer | 2022-08-19 16:34:29 +0000 | |
| commit | f5c4aa1267b5903f9957c68ef6d5a3a47aba7c78 (patch) | |
| tree | 419e2db717bff64ea0d759ad11b1291f9ca2a9a3 /location/java | |
| parent | 8b492aefc85a1a62d2b6d36b18359f691d207552 (diff) | |
| parent | b219baa01494f49a217000716e902315214105ae (diff) | |
Merge "Refactor listener multiplexer"
Diffstat (limited to 'location/java')
| -rw-r--r-- | location/java/android/location/util/identity/CallerIdentity.java | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/location/java/android/location/util/identity/CallerIdentity.java b/location/java/android/location/util/identity/CallerIdentity.java index ade0ea40e157..2f8d92b06f03 100644 --- a/location/java/android/location/util/identity/CallerIdentity.java +++ b/location/java/android/location/util/identity/CallerIdentity.java @@ -124,15 +124,22 @@ public final class CallerIdentity { packageName, attributionTag, listenerId); } + // in some tests these constants are loaded too early leading to an "incorrect" view of the + // current pid and uid. load lazily to prevent this problem in tests. + private static class Loader { + private static final int MY_UID = Process.myUid(); + private static final int MY_PID = Process.myPid(); + } + private final int mUid; private final int mPid; private final String mPackageName; - private final @Nullable String mAttributionTag; + @Nullable private final String mAttributionTag; - private final @Nullable String mListenerId; + @Nullable private final String mListenerId; private CallerIdentity(int uid, int pid, String packageName, @Nullable String attributionTag, @Nullable String listenerId) { @@ -181,6 +188,24 @@ public final class CallerIdentity { return mUid == Process.SYSTEM_UID; } + /** Returns true if this identity represents the same user this code is running in. */ + public boolean isMyUser() { + return UserHandle.getUserId(mUid) == UserHandle.getUserId(Loader.MY_UID); + } + + /** Returns true if this identity represents the same uid this code is running in. */ + public boolean isMyUid() { + return mUid == Loader.MY_UID; + } + + /** + * Returns true if this identity represents the same process this code is running in. Returns + * false if the identity process is unknown. + */ + public boolean isMyProcess() { + return mPid == Loader.MY_PID; + } + /** * Adds this identity to the worksource supplied, or if not worksource is supplied, creates a * new worksource representing this identity. |