# ComponentCaller

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/app/ComponentCaller#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/ComponentCaller#inhmethods)  

# ComponentCaller

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/ComponentCaller "View this page in Kotlin")\|Java

`
public

final

class
ComponentCaller
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.ComponentCaller |

<br />

*** ** * ** ***

Represents the app that launched the component. See below for the APIs available on the component caller.

**Note** , that in[Build.VERSION_CODES.VANILLA_ICE_CREAM](https://developer.android.com/reference/android/os/Build.VERSION_CODES#VANILLA_ICE_CREAM)only[Activity](https://developer.android.com/reference/android/app/Activity)has access to[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instances.  
**See also:**

- [Activity.getInitialCaller()](https://developer.android.com/reference/android/app/Activity#getInitialCaller())

## Summary

|                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                 ||
|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                | ` `[checkContentUriPermission](https://developer.android.com/reference/android/app/ComponentCaller#checkContentUriPermission(android.net.Uri,%20int))`(`[Uri](https://developer.android.com/reference/android/net/Uri)` uri, int modeFlags) ` Determines whether this component caller had access to a specific content URI at launch time. |
| ` boolean`                                                            | ` `[equals](https://developer.android.com/reference/android/app/ComponentCaller#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                                                                          |
| ` `[String](https://developer.android.com/reference/java/lang/String) | ` `[getPackage](https://developer.android.com/reference/android/app/ComponentCaller#getPackage())`() ` Returns the package name of this component caller.                                                                                                                                                                                   |
| ` int`                                                                | ` `[getUid](https://developer.android.com/reference/android/app/ComponentCaller#getUid())`() ` Returns the uid of this component caller.                                                                                                                                                                                                    |
| ` int`                                                                | ` `[hashCode](https://developer.android.com/reference/android/app/ComponentCaller#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### checkContentUriPermission

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int checkContentUriPermission (Uri uri, 
                int modeFlags)
```

Determines whether this component caller had access to a specific content URI at launch time. Apps can use this API to validate content URIs coming from other apps.

**Note** , in[Build.VERSION_CODES.VANILLA_ICE_CREAM](https://developer.android.com/reference/android/os/Build.VERSION_CODES#VANILLA_ICE_CREAM)only[Activity](https://developer.android.com/reference/android/app/Activity)has access to[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instances.

Before using this method, note the following:

- You must have access to the supplied URI, otherwise it will throw a[SecurityException](https://developer.android.com/reference/java/lang/SecurityException).
- This is not a real time check, i.e. the permissions have been computed at launch time.
- This method will return the correct result for content URIs passed at launch time, specifically the ones from[Intent.getData()](https://developer.android.com/reference/android/content/Intent#getData()),[Intent.EXTRA_STREAM](https://developer.android.com/reference/android/content/Intent#EXTRA_STREAM), and[Intent.getClipData()](https://developer.android.com/reference/android/content/Intent#getClipData())in the intent of`startActivity(intent)`. For others, it will throw an[IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException).

<br />

<br />

|                                                                                                                                                                                  Parameters                                                                                                                                                                                   ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `uri`       | `Uri`: The content uri that is being checked This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                  |
| `modeFlags` | `int`: The access modes to check Value is either`0`or a combination of[Intent.FLAG_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION), and[Intent.FLAG_GRANT_WRITE_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION) <br /> |

|                                                                                                                                                                                                                                                                                                             Returns                                                                                                                                                                                                                                                                                                              ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [PackageManager.PERMISSION_GRANTED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_GRANTED)if this activity caller is allowed to access that uri, or[PackageManager.PERMISSION_DENIED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_DENIED)if it is not Value is[PackageManager.PERMISSION_GRANTED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_GRANTED), or[PackageManager.PERMISSION_DENIED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_DENIED) <br /> |

|                                                                                                                                                                                                                                    Throws                                                                                                                                                                                                                                    ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if uri is a non-content URI or it wasn't passed at launch in[Intent.getData()](https://developer.android.com/reference/android/content/Intent#getData()),[Intent.EXTRA_STREAM](https://developer.android.com/reference/android/content/Intent#EXTRA_STREAM), and[Intent.getClipData()](https://developer.android.com/reference/android/content/Intent#getClipData()) |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)               | if you don't have access to uri                                                                                                                                                                                                                                                                                                                                      |

**See also:**

- [Context.checkContentUriPermissionFull(Uri, int, int, int)](https://developer.android.com/reference/android/content/Context#checkContentUriPermissionFull(android.net.Uri,%20int,%20int,%20int))  

### equals

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean equals (Object obj)
```

Indicates whether some other object is "equal to" this one.

The`equals`method implements an equivalence relation on non-null object references:

- It is*reflexive* : for any non-null reference value`x`,`x.equals(x)`should return`true`.
- It is*symmetric* : for any non-null reference values`x`and`y`,`x.equals(y)`should return`true`if and only if`y.equals(x)`returns`true`.
- It is*transitive* : for any non-null reference values`x`,`y`, and`z`, if`x.equals(y)`returns`true`and`y.equals(z)`returns`true`, then`x.equals(z)`should return`true`.
- It is*consistent* : for any non-null reference values`x`and`y`, multiple invocations of`x.equals(y)`consistently return`true`or consistently return`false`, provided no information used in`equals`comparisons on the objects is modified.
- For any non-null reference value`x`,`x.equals(null)`should return`false`.

An equivalence relation partitions the elements it operates on into*equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

<br />

|                    Parameters                    ||
|-------|-------------------------------------------|
| `obj` | `Object`: This value may be`null`. <br /> |

|                                         Returns                                          ||
|-----------|-------------------------------------------------------------------------------|
| `boolean` | `true`if this object is the same as the obj argument;`false`otherwise. <br /> |

### getPackage

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getPackage ()
```

Returns the package name of this component caller.

**Note** , in[Build.VERSION_CODES.VANILLA_ICE_CREAM](https://developer.android.com/reference/android/os/Build.VERSION_CODES#VANILLA_ICE_CREAM)only[Activity](https://developer.android.com/reference/android/app/Activity)has access to[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instances.

<br />

### Requirements for[Activity](https://developer.android.com/reference/android/app/Activity)callers

In order to receive the calling app's package name, at least one of the following has to be met:

- The calling app must call[ActivityOptions.setShareIdentityEnabled(boolean)](https://developer.android.com/reference/android/app/ActivityOptions#setShareIdentityEnabled(boolean))with a value of`true`and launch this activity with the resulting`ActivityOptions`.
- The launched activity has the same uid as the calling app.
- The launched activity is running in a package that is signed with the same key used to sign the platform (typically only system packages such as Settings will meet this meet this requirement).

These are the same requirements for[getUid()](https://developer.android.com/reference/android/app/ComponentCaller#getUid()); if any of these are met, then these methods can be used to obtain the uid and package name of the calling app. If none are met, then`null`is returned.

Note, even if the above conditions are not met, the calling app's identity may still be available from[Activity.getCallingPackage()](https://developer.android.com/reference/android/app/Activity#getCallingPackage())if this activity was started with`Activity#startActivityForResult`to allow validation of the result's recipient.

<br />

|                                                                                                        Returns                                                                                                         ||
|--------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the package name of the calling app or null if the current component cannot access the identity of the calling app or the caller is invalid <br /> |

**See also:**

- [ActivityOptions.setShareIdentityEnabled(boolean)](https://developer.android.com/reference/android/app/ActivityOptions#setShareIdentityEnabled(boolean))
- [Activity.getLaunchedFromPackage()](https://developer.android.com/reference/android/app/Activity#getLaunchedFromPackage())  

### getUid

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getUid ()
```

Returns the uid of this component caller.

**Note** , in[Build.VERSION_CODES.VANILLA_ICE_CREAM](https://developer.android.com/reference/android/os/Build.VERSION_CODES#VANILLA_ICE_CREAM)only[Activity](https://developer.android.com/reference/android/app/Activity)has access to[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instances.

<br />

### Requirements for[Activity](https://developer.android.com/reference/android/app/Activity)callers

In order to receive the calling app's uid, at least one of the following has to be met:

- The calling app must call[ActivityOptions.setShareIdentityEnabled(boolean)](https://developer.android.com/reference/android/app/ActivityOptions#setShareIdentityEnabled(boolean))with a value of`true`and launch this activity with the resulting`ActivityOptions`.
- The launched activity has the same uid as the calling app.
- The launched activity is running in a package that is signed with the same key used to sign the platform (typically only system packages such as Settings will meet this requirement).

These are the same requirements for[getPackage()](https://developer.android.com/reference/android/app/ComponentCaller#getPackage()); if any of these are met, then these methods can be used to obtain the uid and package name of the calling app. If none are met, then[Process.INVALID_UID](https://developer.android.com/reference/android/os/Process#INVALID_UID)is returned.

Note, even if the above conditions are not met, the calling app's identity may still be available from[Activity.getCallingPackage()](https://developer.android.com/reference/android/app/Activity#getCallingPackage())if this activity was started with`Activity#startActivityForResult`to allow validation of the result's recipient.

<br />

|                                                                                                                 Returns                                                                                                                 ||
|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | the uid of the calling app or[Process.INVALID_UID](https://developer.android.com/reference/android/os/Process#INVALID_UID)if the current component cannot access the identity of the calling app or the caller is invalid <br /> |

**See also:**

- [ActivityOptions.setShareIdentityEnabled(boolean)](https://developer.android.com/reference/android/app/ActivityOptions#setShareIdentityEnabled(boolean))
- [Activity.getLaunchedFromUid()](https://developer.android.com/reference/android/app/Activity#getLaunchedFromUid())  

### hashCode

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by[HashMap](https://developer.android.com/reference/java/util/HashMap).

The general contract of`hashCode`is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the`hashCode`method must consistently return the same integer, provided no information used in`equals`comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce the same integer result.
- It is*not* required that if two objects are unequal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

|                     Returns                      ||
|-------|-------------------------------------------|
| `int` | a hash code value for this object. <br /> |