Merge "Fix the isHashed value to true for all certificate keys."
diff --git a/core/java/android/content/integrity/AtomicFormula.java b/core/java/android/content/integrity/AtomicFormula.java
index 439d536..d25f413 100644
--- a/core/java/android/content/integrity/AtomicFormula.java
+++ b/core/java/android/content/integrity/AtomicFormula.java
@@ -332,9 +332,12 @@
* Constructs a new {@link StringAtomicFormula} together with handling the necessary
* hashing for the given key.
*
- * <p> The value will be hashed with SHA256 and the hex digest will be computed; for
- * all cases except when the key is PACKAGE_NAME or INSTALLER_NAME and the value
- * is less than 33 characters.
+ * <p> The value will be automatically hashed with SHA256 and the hex digest will be
+ * computed when the key is PACKAGE_NAME or INSTALLER_NAME and the value is more than 32
+ * characters.
+ *
+ * <p> The APP_CERTIFICATES and INSTALLER_CERTIFICATES are always delivered in hashed
+ * form. So the isHashedValue is set to true by default.
*
* @throws IllegalArgumentException if {@code key} cannot be used with string value.
*/
@@ -348,7 +351,10 @@
String.format(
"Key %s cannot be used with StringAtomicFormula", keyToString(key)));
mValue = hashValue(key, value);
- mIsHashedValue = !mValue.equals(value);
+ mIsHashedValue =
+ key == APP_CERTIFICATE || key == INSTALLER_CERTIFICATE
+ ? true
+ : !mValue.equals(value);
}
StringAtomicFormula(Parcel in) {
diff --git a/core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java b/core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java
index 7733559..3273e5d 100644
--- a/core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java
+++ b/core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java
@@ -97,7 +97,7 @@
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(appCert);
- assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
+ assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test
@@ -110,7 +110,7 @@
assertThat(stringAtomicFormula.getKey()).isEqualTo(
AtomicFormula.INSTALLER_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(installerCert);
- assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
+ assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test
diff --git a/core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java b/core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java
index dc03167..75ef1f2 100644
--- a/core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java
+++ b/core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java
@@ -54,7 +54,7 @@
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(appCertificate);
- assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
+ assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test
@@ -82,7 +82,7 @@
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.INSTALLER_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(installerCertificate);
- assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
+ assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test