package com.example.todocloud.helper;

import android.content.Context;

import com.example.todocloud.app.AppController;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.UUID;

public class InstallationIdHelper {

  private static String installationId = null;
  private static final String FILE_NAME = "INSTALLATION_ID";

  /**
   * InstallationId-t olvas ki. Ha még nem létezik az installationId, akkor generáltatja.
   * @return A kiolvasott installationId.
   */
  public synchronized static String getInstallationId() {
    Context context = AppController.getAppContext();
    if (installationId == null) {
      File fInstallationId = new File(context.getFilesDir(), FILE_NAME);
      try {
        if (!fInstallationId.exists()) {
          writeInstallationId(fInstallationId);
        }
        installationId = readInstallationId(fInstallationId);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return installationId;
  }

  /**
   * Új installationId-t generáltat. Regisztráció során előfordulhatnak ütközések, ezek
   * elkerülésére használatos a metódus.
   * @return A generált installationId.
   */
  public synchronized static String getNewInstallationId() {
    Context context = AppController.getAppContext();
    File fInstallationId = new File(context.getFilesDir(), FILE_NAME);
    try {
      writeInstallationId(fInstallationId);
      installationId = readInstallationId(fInstallationId);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return installationId;
  }

  /**
   * InstallationId-t generál és tárol.
   * @param fInstallationId A fájl helye és neve.
   * @throws IOException
   */
  private static void writeInstallationId(File fInstallationId) throws IOException {
    FileOutputStream fileOutputStream = new FileOutputStream(fInstallationId);
    String id = UUID.randomUUID().toString();
    fileOutputStream.write(id.getBytes());
    fileOutputStream.close();
  }

  /**
   * Kiolvassa az installationId-t.
   * @param fInstallationId A fájl helye és neve.
   * @return A kiolvasott installationId.
   * @throws IOException
   */
  private static String readInstallationId(File fInstallationId) throws IOException {
    RandomAccessFile randomAccessFile = new RandomAccessFile(fInstallationId, "r");
    byte[] bytes = new byte[(int) randomAccessFile.length()];
    randomAccessFile.readFully(bytes);
    randomAccessFile.close();
    return new String(bytes);
  }

}

package com.example.todocloud.helper;

import android.content.Context;

import com.example.todocloud.app.AppController;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.UUID;

public class InstallationIdHelper {

  private static String installationId = null;
  private static final String FILE_NAME = "INSTALLATION_ID";

  public synchronized static String getInstallationId() {
    Context context = AppController.getAppContext();
    if (installationId == null) {
      File installationIdDir = context.getFilesDir();
      File installationIdFile = new File(installationIdDir, FILE_NAME);
      try {
        if (!installationIdFile.exists()) {
          writeInstallationId(installationIdFile);
        }
        installationId = readInstallationId(installationIdFile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return installationId;
  }

  public synchronized static String getNewInstallationId() {
    Context context = AppController.getAppContext();
    File installationIdDir = context.getFilesDir();
    File installationIdFile = new File(installationIdDir, FILE_NAME);
    try {
      writeInstallationId(installationIdFile);
      installationId = readInstallationId(installationIdFile);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return installationId;
  }

  private static void writeInstallationId(File installationIdFile) throws IOException {
    String installationIdString = UUID.randomUUID().toString();
    byte[] installationId = installationIdString.getBytes();
    FileOutputStream fileOutputStream = new FileOutputStream(installationIdFile);
    fileOutputStream.write(installationId);
    fileOutputStream.close();
  }

  private static String readInstallationId(File installationIdFile) throws IOException {
    RandomAccessFile randomAccessFile = new RandomAccessFile(installationIdFile, "r");
    int installationIdFileLength = (int) randomAccessFile.length();
    byte[] installationId = new byte[installationIdFileLength];
    randomAccessFile.readFully(installationId);
    randomAccessFile.close();
    return new String(installationId);
  }

}

Simplify InstallationIdHelper class