diff --git a/yearclass/build.gradle b/yearclass/build.gradle index 04d6b1b..4437ba4 100644 --- a/yearclass/build.gradle +++ b/yearclass/build.gradle @@ -27,6 +27,7 @@ dependencies { exclude module: 'hamcrest-core' exclude module: 'objenesis' } + compile 'com.android.support:support-annotations:24.2.0' } apply from: rootProject.file('release.gradle') diff --git a/yearclass/src/main/java/com/facebook/device/yearclass/YearClass.java b/yearclass/src/main/java/com/facebook/device/yearclass/YearClass.java index ad07bb7..e16685f 100644 --- a/yearclass/src/main/java/com/facebook/device/yearclass/YearClass.java +++ b/yearclass/src/main/java/com/facebook/device/yearclass/YearClass.java @@ -8,7 +8,10 @@ package com.facebook.device.yearclass; import android.content.Context; +import android.support.annotation.IntDef; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; @@ -27,6 +30,13 @@ public class YearClass { private static final long MB = 1024 * 1024; private static final int MHZ_IN_KHZ = 1000; + @Retention(RetentionPolicy.SOURCE) + @IntDef({CLASS_UNKNOWN, CLASS_2008, CLASS_2009, + CLASS_2010, CLASS_2011, CLASS_2012, + CLASS_2013, CLASS_2014, CLASS_2015}) + public @interface Class { + } + private volatile static Integer mYearCategory; /** @@ -37,6 +47,7 @@ public class YearClass { * int yearClass = YearClass.get(context); * */ + @Class public static int get(Context c) { if (mYearCategory == null) { synchronized(YearClass.class) { @@ -48,7 +59,7 @@ public static int get(Context c) { return mYearCategory; } - private static void conditionallyAdd(ArrayList list, int value) { + private static void conditionallyAdd(ArrayList list, @Class int value) { if (value != CLASS_UNKNOWN) { list.add(value); } @@ -60,7 +71,7 @@ private static void conditionallyAdd(ArrayList list, int value) { * (specifically app startup time, scrolling perf, animations) are more uniform within * the buckets than with the 2014 calculations. */ - private static int categorizeByYear2016Method(Context c) { + private static @Class int categorizeByYear2016Method(Context c) { long totalRam = DeviceInfo.getTotalMemory(c); if (totalRam == DeviceInfo.DEVICEINFO_UNKNOWN) { return categorizeByYear2014Method(c); @@ -89,8 +100,10 @@ private static int categorizeByYear2016Method(Context c) { * * @return The year when this device would have been considered top-of-the-line. */ + @SuppressWarnings("WrongConstant") + @Class private static int categorizeByYear2014Method(Context c) { - ArrayList componentYears = new ArrayList(); + ArrayList componentYears = new ArrayList<>(); conditionallyAdd(componentYears, getNumCoresYear()); conditionallyAdd(componentYears, getClockSpeedYear()); conditionallyAdd(componentYears, getRamYear(c)); @@ -123,6 +136,7 @@ private static int categorizeByYear2014Method(Context c) { * * @return the year in which top-of-the-line phones had the same number of processors as this phone. */ + @Class private static int getNumCoresYear() { int cores = DeviceInfo.getNumberOfCPUCores(); if (cores < 1) return CLASS_UNKNOWN; @@ -151,6 +165,7 @@ private static int getNumCoresYear() { * * @return the year in which top-of-the-line phones had the same clock speed. */ + @Class private static int getClockSpeedYear() { long clockSpeedKHz = DeviceInfo.getCPUMaxFreqKHz(); if (clockSpeedKHz == DeviceInfo.DEVICEINFO_UNKNOWN) return CLASS_UNKNOWN; @@ -185,6 +200,7 @@ private static int getClockSpeedYear() { * * @return the year in which top-of-the-line phones had the same amount of RAM as this phone. */ + @Class private static int getRamYear(Context c) { long totalRam = DeviceInfo.getTotalMemory(c); if (totalRam <= 0) return CLASS_UNKNOWN;