Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4a19be9 authored by Romain Hunault's avatar Romain Hunault 🚴🏻
Browse files

Merge branch 'issue-6' into 'v1-nougat'

Bring back checkState function

See merge request e/os/android_packages_apps_Dialer!11
parents 6e42bdba 5aebd382
Loading
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public final class Licenses {
    for (String entry : entries) {
      int delimiter = entry.indexOf(' ');
      String[] licenseLocation = entry.substring(0, delimiter).split(":");
      Assert.checkState(
      checkState(
          delimiter > 0 && licenseLocation.length == 2,
          "Invalid license meta-data line:\n" + entry);
      long licenseOffset = Long.parseLong(licenseLocation[0]);
@@ -62,6 +62,30 @@ public final class Licenses {
    return licenses;
  }

  /**
   * Ensures the truth of an expression involving the state of the calling instance, but not
   * involving any parameters to the calling method.
   *
   * @param expression a boolean expression
   * @param messageTemplate the message to log, possible with format arguments.
   * @param args optional arguments to be used in the formatted string.
   * @throws IllegalStateException if {@code expression} is false
   */
  public static void checkState(
      boolean expression,String messageTemplate, Object... args) {
    if (!expression) {
      throw new IllegalStateException(format(messageTemplate, args));
    }
  }

  private static String format(String messageTemplate, Object... args) {
    if (messageTemplate == null) {
      return null;
    }
    return String.format(messageTemplate, args);
  }


  /** Return the text of a bundled license file. */
  public static String getLicenseText(Context context, License license) {
    long offset = license.getLicenseOffset();