Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yearclass/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

/**
Expand All @@ -37,6 +47,7 @@ public class YearClass {
* int yearClass = YearClass.get(context);
* </pre>
*/
@Class
public static int get(Context c) {
if (mYearCategory == null) {
synchronized(YearClass.class) {
Expand All @@ -48,7 +59,7 @@ public static int get(Context c) {
return mYearCategory;
}

private static void conditionallyAdd(ArrayList<Integer> list, int value) {
private static void conditionallyAdd(ArrayList<Integer> list, @Class int value) {
if (value != CLASS_UNKNOWN) {
list.add(value);
}
Expand All @@ -60,7 +71,7 @@ private static void conditionallyAdd(ArrayList<Integer> 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);
Expand Down Expand Up @@ -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<Integer> componentYears = new ArrayList<Integer>();
ArrayList<Integer> componentYears = new ArrayList<>();
conditionallyAdd(componentYears, getNumCoresYear());
conditionallyAdd(componentYears, getClockSpeedYear());
conditionallyAdd(componentYears, getRamYear(c));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down