예제 #1
0
 private static void setNextSignedPreKeyId(Context context, int id) {
   try {
     File nextFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);
     FileOutputStream fout = new FileOutputStream(nextFile);
     fout.write(JsonUtils.toJson(new SignedPreKeyIndex(id)).getBytes());
     fout.close();
   } catch (IOException e) {
     Log.w("PreKeyUtil", e);
   }
 }
예제 #2
0
  private static int getNextSignedPreKeyId(Context context) {
    try {
      File nextFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);

      if (!nextFile.exists()) {
        return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
      } else {
        InputStreamReader reader = new InputStreamReader(new FileInputStream(nextFile));
        SignedPreKeyIndex index = JsonUtils.fromJson(reader, SignedPreKeyIndex.class);
        reader.close();
        return index.nextSignedPreKeyId;
      }
    } catch (IOException e) {
      Log.w("PreKeyUtil", e);
      return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
    }
  }