am 6feaa267
: Merge "Add fastpath for single signature comparison" into klp-modular-dev
* commit '6feaa267a585f22595f846c9e3d09a76dc3db47a': Add fastpath for single signature comparison
This commit is contained in:
@ -2576,15 +2576,41 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two sets of signatures. Returns:
|
||||||
|
* <br />
|
||||||
|
* {@link PackageManager#SIGNATURE_NEITHER_SIGNED}: if both signature sets are null,
|
||||||
|
* <br />
|
||||||
|
* {@link PackageManager#SIGNATURE_FIRST_NOT_SIGNED}: if the first signature set is null,
|
||||||
|
* <br />
|
||||||
|
* {@link PackageManager#SIGNATURE_SECOND_NOT_SIGNED}: if the second signature set is null,
|
||||||
|
* <br />
|
||||||
|
* {@link PackageManager#SIGNATURE_MATCH}: if the two signature sets are identical,
|
||||||
|
* <br />
|
||||||
|
* {@link PackageManager#SIGNATURE_NO_MATCH}: if the two signature sets differ.
|
||||||
|
*/
|
||||||
static int compareSignatures(Signature[] s1, Signature[] s2) {
|
static int compareSignatures(Signature[] s1, Signature[] s2) {
|
||||||
if (s1 == null) {
|
if (s1 == null) {
|
||||||
return s2 == null
|
return s2 == null
|
||||||
? PackageManager.SIGNATURE_NEITHER_SIGNED
|
? PackageManager.SIGNATURE_NEITHER_SIGNED
|
||||||
: PackageManager.SIGNATURE_FIRST_NOT_SIGNED;
|
: PackageManager.SIGNATURE_FIRST_NOT_SIGNED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s2 == null) {
|
if (s2 == null) {
|
||||||
return PackageManager.SIGNATURE_SECOND_NOT_SIGNED;
|
return PackageManager.SIGNATURE_SECOND_NOT_SIGNED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s1.length != s2.length) {
|
||||||
|
return PackageManager.SIGNATURE_NO_MATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since both signature sets are of size 1, we can compare without HashSets.
|
||||||
|
if (s1.length == 1) {
|
||||||
|
return s1[0].equals(s2[0]) ?
|
||||||
|
PackageManager.SIGNATURE_MATCH :
|
||||||
|
PackageManager.SIGNATURE_NO_MATCH;
|
||||||
|
}
|
||||||
|
|
||||||
HashSet<Signature> set1 = new HashSet<Signature>();
|
HashSet<Signature> set1 = new HashSet<Signature>();
|
||||||
for (Signature sig : s1) {
|
for (Signature sig : s1) {
|
||||||
set1.add(sig);
|
set1.add(sig);
|
||||||
|
Reference in New Issue
Block a user