def compute_base_score()

in ioXt/uraniborg/scripts/python/risk_analyzer.py [0:0]


  def compute_base_score(self, hubble, normalize):
    """Computes the base score for platforn signature metrics.

    Args:
      hubble: A valid instance of HubbleParser object.
      normalize: A boolean indicating to normalize the score against baseline or
                 not. Typically, this value is set to True when computing score
                 for a target device and False when collecting base score for
                 baseline measurements.

    Returns:
      An int representing the raw score of this metrics
    """
    logger = self.logger

    # first determine platform signature
    platform_signature = hubble.get_platform_signature()

    num_platform_signed_app = 0
    packages = hubble.packages
    whitelist = PackageWhitelists.get_whitelist(hubble.get_oem())
    baseline = BaselinePackages.get_instance(hubble.get_api_level())
    hubble.platform_apps = []
    hubble.system_uid_apps = []
    update_apps = False
    if not self.related_apps and normalize:
      update_apps = True
    for package in packages:
      package_name = package["name"]

      ### do filtering
      if package_name in whitelist.EXCLUDED_PACKAGES:
        logger.debug("^%s is in OEM global whitelist. Excluding...",
                     package_name)
        continue

      if normalize:
        fuzzy_matched_package = PackageWhitelists.package_name_fuzzy_match(
            logger, package_name, baseline.get_platform_signed_packages())
        if fuzzy_matched_package:
          # only discount if the same package was signed using platform
          # signature in GSI's build
          continue

      if platform_signature in package["certIds"]:
        hubble.platform_apps.append(package_name)
        num_platform_signed_app += 1
        logger.debug("+%s is platform signed. Running score: %d", package_name,
                     num_platform_signed_app)

        if package["sharedUserId"] == "android.uid.system":
          hubble.system_uid_apps.append(package_name)

        if not package["hasCode"]:
          # we discount those that has no code, but not remove from our list,
          # because these packages are still signed with platform signature
          # nonetheless.
          num_platform_signed_app -= 1
          logger.debug("-%s but has no code. Running total: %d", package_name,
                       num_platform_signed_app)
        elif update_apps:
          self.related_apps.append(package)
    return num_platform_signed_app