Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #19 from zlern2k/master
Browse files Browse the repository at this point in the history
New definitions
  • Loading branch information
SeyelentEco authored Jul 1, 2016
2 parents d590884 + c7a1227 commit 940d5d4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.iml
.DS_Store
/build
.watchmanconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/
package com.facebook.device.yearclass;

import android.content.Context;

import java.util.ArrayList;
import java.util.Collections;

import android.content.Context;

public class YearClass {
// Year definitions
public static final int CLASS_UNKNOWN = -1;
Expand All @@ -22,6 +22,7 @@ public class YearClass {
public static final int CLASS_2012 = 2012;
public static final int CLASS_2013 = 2013;
public static final int CLASS_2014 = 2014;
public static final int CLASS_2015 = 2015;

private static final long MB = 1024 * 1024;
private static final int MHZ_IN_KHZ = 1000;
Expand All @@ -40,7 +41,7 @@ public static int get(Context c) {
if (mYearCategory == null) {
synchronized(YearClass.class) {
if (mYearCategory == null) {
mYearCategory = categorizeByYear(c);
mYearCategory = categorizeByYear2016Method(c);
}
}
}
Expand All @@ -53,6 +54,33 @@ private static void conditionallyAdd(ArrayList<Integer> list, int value) {
}
}

/**
* This formulation of year class smooths out the distribution of devices in the field
* in early 2016 so that the buckets are a bit more even in size and performance metrics
* (specifically app startup time, scrolling perf, animations) are more uniform within
* the buckets than with the 2014 calculations.
*/
private static int categorizeByYear2016Method(Context c) {
long totalRam = DeviceInfo.getTotalMemory(c);
if (totalRam == DeviceInfo.DEVICEINFO_UNKNOWN) {
return categorizeByYear2014Method(c);
}

if (totalRam <= 768 * MB) {
return DeviceInfo.getNumberOfCPUCores() <= 1 ? CLASS_2009 : CLASS_2010;
}
if (totalRam <= 1024 * MB) {
return DeviceInfo.getCPUMaxFreqKHz() < 1300 * MHZ_IN_KHZ ? CLASS_2011 : CLASS_2012;
}
if (totalRam <= 1536 * MB) {
return DeviceInfo.getCPUMaxFreqKHz() < 1800 * MHZ_IN_KHZ ? CLASS_2012 : CLASS_2013;
}
if (totalRam <= 2048 * MB) {
return CLASS_2013;
}
return totalRam <= 3 * 1024 * MB ? CLASS_2014 : CLASS_2015;
}

/**
* Calculates the "best-in-class year" of the device. This represents the top-end or flagship
* devices of that year, not the actual release year of the phone. For example, the Galaxy Duos
Expand All @@ -61,7 +89,7 @@ private static void conditionallyAdd(ArrayList<Integer> list, int value) {
*
* @return The year when this device would have been considered top-of-the-line.
*/
private static int categorizeByYear(Context c) {
private static int categorizeByYear2014Method(Context c) {
ArrayList<Integer> componentYears = new ArrayList<Integer>();
conditionallyAdd(componentYears, getNumCoresYear());
conditionallyAdd(componentYears, getClockSpeedYear());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,44 @@ public class YearClassTest {

@PrepareForTest(DeviceInfo.class)
@Test
public void testGetYearCategory() {
public void testGetYearCategoryS7() {
// CPU, frequency, RAM, and YearClass values from Samsung Galaxy S7 (global edition).
int yearClass = getYearClass(8, 2600000, 3663L * 1024 * 1024);
assertEquals(YearClass.CLASS_2015, yearClass);
}

@PrepareForTest(DeviceInfo.class)
@Test
public void testGetYearCategoryG4() {
// CPU, frequency, RAM, and YearClass values from LG G4.
int yearClass = getYearClass(6, 1824000, 2778L * 1024 * 1024);
assertEquals(YearClass.CLASS_2014, yearClass);
}

@PrepareForTest(DeviceInfo.class)
@Test
public void testGetYearCategoryS5() {
// CPU, frequency, RAM, and YearClass values from Samsung Galaxy S5.
int yearClass = getYearClass(4, 2457600, 1946939392L);
assertEquals(YearClass.CLASS_2013, yearClass);
}

@PrepareForTest(DeviceInfo.class)
@Test
public void testGetYearCategoryGalaxyJ1() {
// CPU, frequency, RAM, and YearClass values from Samsung Galaxy J1.
int yearClass = getYearClass(2, 1248000, 716L * 1024 * 1024);
assertEquals(YearClass.CLASS_2010, yearClass);
}

@PrepareForTest(DeviceInfo.class)
@Test
public void testGetYearCategoryP8lite() {
// CPU, frequency, RAM, and YearClass values from Huawei P8lite.
int yearClass = getYearClass(8, 1200000, 1858L * 1024 * 1024);
assertEquals(YearClass.CLASS_2013, yearClass);
}

@PrepareForTest(DeviceInfo.class)
@Test
public void testEmptyCase() {
Expand Down

0 comments on commit 940d5d4

Please sign in to comment.