Skip to content

Commit

Permalink
Merge pull request #8589 from cketti/nullability-cleanup
Browse files Browse the repository at this point in the history
Use smart casts to avoid awkward `if` conditions
  • Loading branch information
cketti authored Nov 25, 2024
2 parents 7fe8346 + e3fc456 commit 8906450
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ class SettingsProvider : ContentProvider(), KoinComponent {
val packageInfo = packageManager.getPackageInfo(callerPackage, PackageManager.GET_SIGNATURES)

// We don't expect our callers to have multiple signers, so we don't service such requests.
if (packageInfo.signatures?.size != 1) {
val signatures = packageInfo.signatures
if (signatures == null || signatures.size != 1) {
return null
}

// In case of signature rotation, this will report the oldest used certificate, pretending that the signature
// rotation never took place. We can only rely on our allowlist being up-to-date in this case.
return packageInfo.signatures?.firstOrNull()
return signatures.firstOrNull()
}

@TargetApi(Build.VERSION_CODES.P)
Expand All @@ -164,15 +165,16 @@ class SettingsProvider : ContentProvider(), KoinComponent {
val packageInfo = packageManager.getPackageInfo(callerPackage, PackageManager.GET_SIGNING_CERTIFICATES)

// We don't expect our callers to have multiple signers, so we don't service such requests.
if (packageInfo.signingInfo?.hasMultipleSigners() == true) {
val signingInfo = packageInfo.signingInfo
if (signingInfo == null || signingInfo.hasMultipleSigners()) {
return null
}

// We currently don't support servicing requests from callers that performed certificate rotation.
if (packageInfo.signingInfo?.hasPastSigningCertificates() == true) {
if (signingInfo.hasPastSigningCertificates()) {
return null
}

return packageInfo.signingInfo?.signingCertificateHistory?.firstOrNull()
return signingInfo.signingCertificateHistory?.firstOrNull()
}
}

0 comments on commit 8906450

Please sign in to comment.