Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5b6094e authored by Tao Bao's avatar Tao Bao Committed by Gerrit Code Review
Browse files

Merge "releasetools: Sanity check the build fingerprint."

parents e430f765 c4011cd7
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -299,6 +299,9 @@ class BuildInfo(object):
          that it always uses the first dict to calculate the fingerprint or the
          device name. The rest would be used for asserting OEM properties only
          (e.g. one package can be installed on one of these devices).

    Raises:
      ValueError: On invalid inputs.
    """
    self.info_dict = info_dict
    self.oem_dicts = oem_dicts
@@ -313,6 +316,13 @@ class BuildInfo(object):
    self._device = self.GetOemProperty("ro.product.device")
    self._fingerprint = self.CalculateFingerprint()

    # Sanity check the build fingerprint.
    if (' ' in self._fingerprint or
        any(ord(ch) > 127 for ch in self._fingerprint)):
      raise ValueError(
          'Invalid build fingerprint: "{}". See the requirement in Android CDD '
          '3.2.2. Build Parameters.'.format(self._fingerprint))

  @property
  def is_ab(self):
    return self._is_ab
+8 −0
Original line number Diff line number Diff line
@@ -174,6 +174,14 @@ class BuildInfoTest(test_utils.ReleaseToolsTestCase):
    self.assertRaises(AssertionError, BuildInfo,
                      self.TEST_INFO_DICT_USES_OEM_PROPS, None)

  def test_init_badFingerprint(self):
    info_dict = copy.deepcopy(self.TEST_INFO_DICT)
    info_dict['build.prop']['ro.build.fingerprint'] = 'bad fingerprint'
    self.assertRaises(ValueError, BuildInfo, info_dict, None)

    info_dict['build.prop']['ro.build.fingerprint'] = 'bad\x80fingerprint'
    self.assertRaises(ValueError, BuildInfo, info_dict, None)

  def test___getitem__(self):
    target_info = BuildInfo(self.TEST_INFO_DICT, None)
    self.assertEqual('value1', target_info['property1'])