Exemplo n.º 1
0
  /**
   * This method tries to guess the best update source for a given app based on its signature.
   *
   * @param pi The PackageInfo object returned by the PackageManager
   * @return An adequate update source for the app, or null if auto-disvocery must take place.
   */
  public static UpdateSource guess_update_source(PackageInfo pi) {
    android.content.pm.Signature[] signs = pi.signatures;
    for (Signature sign : signs) {
      X509Certificate cert;
      try {
        cert =
            (X509Certificate)
                CertificateFactory.getInstance("X509")
                    .generateCertificate(new ByteArrayInputStream(sign.toByteArray()));
      } catch (CertificateException e) {
        Log.v(MainActivity.TAG, "Error while reading " + pi.packageName + "'s certificate.");
        return null;
      }

      String[] details = cert.getSubjectDN().getName().split(",");
      for (UpdateSource us : get_update_sources()) {
        if (us.test_autoselection(pi.packageName, Arrays.asList(details))) {
          return us;
        }
      }
    }
    return null;
  }