Exemplo n.º 1
0
    private void tagRepo() throws IOException, LocalRepoKeyStore.InitException {

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

      // max age is an EditTextPreference, which is always a String
      int repoMaxAge =
          Float.valueOf(prefs.getString("max_repo_age_days", DEFAULT_REPO_MAX_AGE_DAYS)).intValue();

      serializer.startTag("", "repo");

      serializer.attribute("", "icon", "blah.png");
      serializer.attribute("", "maxage", String.valueOf(repoMaxAge));
      serializer.attribute(
          "", "name", Preferences.get().getLocalRepoName() + " on " + FDroidApp.ipAddressString);
      serializer.attribute(
          "", "pubkey", Hasher.hex(LocalRepoKeyStore.get(context).getCertificate()));
      long timestamp = System.currentTimeMillis() / 1000L;
      serializer.attribute("", "timestamp", String.valueOf(timestamp));

      tag(
          "description",
          "A local FDroid repo generated from apps installed on "
              + Preferences.get().getLocalRepoName());

      serializer.endTag("", "repo");
    }
Exemplo n.º 2
0
  public void writeIndexJar() throws IOException {
    try {
      new IndexXmlBuilder(context, apps).build(new FileWriter(xmlIndex));
    } catch (Exception e) {
      Log.e(TAG, "Could not write index jar", e);
      Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show();
      return;
    }

    BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned));
    JarOutputStream jo = new JarOutputStream(bo);

    BufferedInputStream bi = new BufferedInputStream(new FileInputStream(xmlIndex));

    JarEntry je = new JarEntry("index.xml");
    jo.putNextEntry(je);

    byte[] buf = new byte[1024];
    int bytesRead;

    while ((bytesRead = bi.read(buf)) != -1) {
      jo.write(buf, 0, bytesRead);
    }

    bi.close();
    jo.close();
    bo.close();

    try {
      LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar);
    } catch (LocalRepoKeyStore.InitException e) {
      throw new IOException("Could not sign index - keystore failed to initialize");
    } finally {
      attemptToDelete(xmlIndexJarUnsigned);
    }
  }