OSDN Git Service

Add DataUnit to clarify SI-vs-IEC units.
authorJeff Sharkey <jsharkey@android.com>
Fri, 19 Jan 2018 00:56:51 +0000 (09:56 +0900)
committerJeff Sharkey <jsharkey@android.com>
Fri, 19 Jan 2018 00:56:53 +0000 (09:56 +0900)
Improve docs and propose it as public API.

Test: builds, boots
Bug: 70915728
Change-Id: I9b55601e9eb8c069eeccd5f8f5e64fb34e336fd2

api/current.txt
core/java/android/util/DataUnit.java

index 06f3b2a..43c6ab1 100644 (file)
@@ -44081,6 +44081,18 @@ package android.util {
     field public static final deprecated boolean RELEASE = true;
   }
 
+  public class DataUnit extends java.lang.Enum {
+    method public long toBytes(long);
+    method public static android.util.DataUnit valueOf(java.lang.String);
+    method public static final android.util.DataUnit[] values();
+    enum_constant public static final android.util.DataUnit GIBIBYTES;
+    enum_constant public static final android.util.DataUnit GIGABYTES;
+    enum_constant public static final android.util.DataUnit KIBIBYTES;
+    enum_constant public static final android.util.DataUnit KILOBYTES;
+    enum_constant public static final android.util.DataUnit MEBIBYTES;
+    enum_constant public static final android.util.DataUnit MEGABYTES;
+  }
+
   public class DebugUtils {
     method public static boolean isObjectSelected(java.lang.Object);
   }
index 3cc1bd8..ea4266e 100644 (file)
@@ -20,12 +20,15 @@ import java.time.temporal.ChronoUnit;
 import java.util.concurrent.TimeUnit;
 
 /**
- * Constants for common byte-related units. Note that both SI and IEC units are
- * supported, and you'll need to pick the correct one for your use-case.
+ * A {@code DataUnit} represents data sizes at a given unit of granularity and
+ * provides utility methods to convert across units.
+ * <p>
+ * Note that both SI units (powers of 10) and IEC units (powers of 2) are
+ * supported, and you'll need to pick the correct one for your use-case. For
+ * example, Wikipedia defines a "kilobyte" as an SI unit of 1000 bytes, and a
+ * "kibibyte" as an IEC unit of 1024 bytes.
  * <p>
  * This design is mirrored after {@link TimeUnit} and {@link ChronoUnit}.
- *
- * @hide
  */
 public enum DataUnit {
     KILOBYTES { @Override public long toBytes(long v) { return v * 1_000; } },