# PackageInfoCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/pm/PackageInfoCompat.java+class:androidx.core.content.pm.PackageInfoCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

<br />

```
class PackageInfoCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/content/pm/PackageInfo.html`.

## Summary

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/content/pm/PackageInfoCompat#getLongVersionCode(android.content.pm.PackageInfo)(info: https://developer.android.com/reference/android/content/pm/PackageInfo.html)` Return `https://developer.android.com/reference/android/R.attr.html#versionCode` and `https://developer.android.com/reference/android/R.attr.html#versionCodeMajor` combined together as a single long value. |
| `java-static (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/content/pm/Signature.html!>` | `https://developer.android.com/reference/kotlin/androidx/core/content/pm/PackageInfoCompat#getSignatures(android.content.pm.PackageManager,java.lang.String)(packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html, packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Retrieve the `https://developer.android.com/reference/android/content/pm/Signature.html` array for the given package. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/content/pm/PackageInfoCompat#hasSignatures(android.content.pm.PackageManager,java.lang.String,java.util.Map<byte[],java.lang.Integer>,boolean)( packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html, packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, certificatesAndType: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(min = 1) (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>, matchExact: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Check if a package on device contains set of a certificates. |

## Public functions

### getLongVersionCode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getLongVersionCode(info: PackageInfo): Long
```

Return `https://developer.android.com/reference/android/R.attr.html#versionCode` and `https://developer.android.com/reference/android/R.attr.html#versionCodeMajor` combined together as a single long value. The `versionCodeMajor` is placed in the upper 32 bits on Android P or newer, otherwise these bits are all set to 0.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageInfo.html#getLongVersionCode()` |   |

### getSignatures

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
java-static fun getSignatures(packageManager: PackageManager, packageName: String): (Mutable)List<Signature!>
```

Retrieve the `https://developer.android.com/reference/android/content/pm/Signature.html` array for the given package. This returns some of certificates, depending on whether the package in question is multi-signed or has signing history.

Security/identity verification should **not** be done with this method. This is only intended to return some array of certificates that correspond to a package.

If verification if required, either use `https://developer.android.com/reference/kotlin/androidx/core/content/pm/PackageInfoCompat#hasSignatures(android.content.pm.PackageManager,java.lang.String,java.util.Map<byte[],java.lang.Integer>,boolean)` or manually verify the set of certificates using `https://developer.android.com/reference/android/content/pm/PackageManager.html#GET_SIGNING_CERTIFICATES` or `https://developer.android.com/reference/android/content/pm/PackageManager.html#GET_SIGNATURES`.

| Parameters |
|---|---|
| `packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html` | The `https://developer.android.com/reference/android/content/pm/PackageManager.html` instance to query against. |
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The package to query the {@param packageManager} for. Query by app UID is only supported by manually choosing a package name returned in `https://developer.android.com/reference/android/content/pm/PackageManager.html#getPackagesForUid(int)`. |

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/content/pm/Signature.html!>` | an array of certificates the app is signed with |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html` | if the package cannot be found through the provided {@param packageManager} |

### hasSignatures

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
java-static fun hasSignatures(
    packageManager: PackageManager,
    packageName: String,
    certificatesAndType: @Size(min = 1) (Mutable)Map<ByteArray<Byte>!, Int!>,
    matchExact: Boolean
): Boolean
```

Check if a package on device contains set of a certificates. Supported types are raw X509 or SHA-256 bytes.

| Parameters |
|---|---|
| `packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html` | The `https://developer.android.com/reference/android/content/pm/PackageManager.html` instance to query against. |
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The package to query the {@param packageManager} for. Query by app UID is only supported by manually choosing a package name returned in `https://developer.android.com/reference/android/content/pm/PackageManager.html#getPackagesForUid(int)`. |
| `certificatesAndType: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(min = 1) (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>` | The bytes of the certificate mapped to the type, either `https://developer.android.com/reference/android/content/pm/PackageManager.html#CERT_INPUT_RAW_X509` or `https://developer.android.com/reference/android/content/pm/PackageManager.html#CERT_INPUT_SHA256`. A single or multiple certificates may be included. |
| `matchExact: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether or not to check for presence of all signatures exactly. If false, then the check will succeed if the query contains a subset of the package certificates. Matching exactly is strongly recommended when running on devices below `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP` due to the fake ID vulnerability that allows a package to be modified to include an unverified signature. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the package is considered signed by the given certificate set, or false otherwise |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html` | if the package cannot be found through the provided {@param packageManager} |