cmsdk: Return UNKNOWN for impossible sdk ints.

Change-Id: I77a44abba0db223b031d6714c4fd8beb03a43cdc
This commit is contained in:
Adnan Begovic 2015-07-16 14:03:09 -07:00
parent 6714bfe38b
commit 06fc4498e4
2 changed files with 14 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package cyanogenmod.os;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.SparseArray;
/**
@ -84,9 +85,13 @@ public class Build {
/**
* Retrieve the name for the SDK int
* @param sdkInt
* @return name of the SDK int
* @return name of the SDK int, {@link #UNKNOWN) if not known
*/
public static String getNameForSDKInt(int sdkInt) {
return sdkMap.get(sdkInt);
final String name = sdkMap.get(sdkInt);
if (TextUtils.isEmpty(name)) {
return UNKNOWN;
}
return name;
}
}

View File

@ -56,4 +56,11 @@ public class BuildTest extends AndroidTestCase {
}
assertEquals(0, i);
}
@SmallTest
public void testSdkLevelRetrieveNameImpossible() {
String name = Build.getNameForSDKInt(Integer.MAX_VALUE);
assertNotNull(name);
assertEquals(Build.UNKNOWN, name);
}
}