Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
969c4968
Commit
969c4968
authored
4 years ago
by
Michael Groover
Committed by
Android (Google) Code Review
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Document Signature equals/hash should not include flags" into sc-dev
parents
db07cc30
d8bd3028
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/java/android/content/pm/Signature.java
+4
-0
4 additions, 0 deletions
core/java/android/content/pm/Signature.java
core/tests/coretests/src/android/content/pm/SignatureTest.java
+26
-0
26 additions, 0 deletions
...tests/coretests/src/android/content/pm/SignatureTest.java
with
30 additions
and
0 deletions
core/java/android/content/pm/Signature.java
+
4
−
0
View file @
969c4968
...
...
@@ -256,6 +256,8 @@ public class Signature implements Parcelable {
try
{
if
(
obj
!=
null
)
{
Signature
other
=
(
Signature
)
obj
;
// Note, some classes, such as PackageParser.SigningDetails, rely on equals
// only comparing the mSignature arrays without the flags.
return
this
==
other
||
Arrays
.
equals
(
mSignature
,
other
.
mSignature
);
}
}
catch
(
ClassCastException
e
)
{
...
...
@@ -268,6 +270,8 @@ public class Signature implements Parcelable {
if
(
mHaveHashCode
)
{
return
mHashCode
;
}
// Note, similar to equals some classes rely on the hash code not including
// the flags for Set membership checks.
mHashCode
=
Arrays
.
hashCode
(
mSignature
);
mHaveHashCode
=
true
;
return
mHashCode
;
...
...
This diff is collapsed.
Click to expand it.
core/tests/coretests/src/android/content/pm/SignatureTest.java
+
26
−
0
View file @
969c4968
...
...
@@ -54,6 +54,32 @@ public class SignatureTest extends TestCase {
assertFalse
(
Signature
.
areEffectiveMatch
(
asArray
(
A
,
M
),
asArray
(
A
,
B
)));
}
public
void
testHashCode_doesNotIncludeFlags
()
throws
Exception
{
// Some classes rely on the hash code not including the flags / capabilities for the signer
// to verify Set membership. This test verifies two signers with the same signature but
// different flags have the same hash code.
Signature
signatureAWithAllCaps
=
new
Signature
(
A
.
toCharsString
());
// There are currently 5 capabilities that can be assigned to a previous signer, although
// for the purposes of this test all that matters is that the two flag values are distinct.
signatureAWithAllCaps
.
setFlags
(
31
);
Signature
signatureAWithNoCaps
=
new
Signature
(
A
.
toCharsString
());
signatureAWithNoCaps
.
setFlags
(
0
);
assertEquals
(
signatureAWithAllCaps
.
hashCode
(),
signatureAWithNoCaps
.
hashCode
());
}
public
void
testEquals_doesNotIncludeFlags
()
throws
Exception
{
// Similar to above some classes rely on equals only comparing the signature arrays
// for equality without including the flags. This test verifies two signers with the
// same signature but different flags are still considered equal.
Signature
signatureAWithAllCaps
=
new
Signature
(
A
.
toCharsString
());
signatureAWithAllCaps
.
setFlags
(
31
);
Signature
signatureAWithNoCaps
=
new
Signature
(
A
.
toCharsString
());
signatureAWithNoCaps
.
setFlags
(
0
);
assertEquals
(
signatureAWithAllCaps
,
signatureAWithNoCaps
);
}
private
static
Signature
[]
asArray
(
Signature
...
s
)
{
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment