Fix keyboard theme selection logic

Bug: 15002666
Change-Id: I5cc52db71ee609edffdb2613e93245e92ac6fc6a
main
Tadashi G. Takaoka 2014-05-16 12:34:23 +09:00
parent 91e4ba742a
commit 3b12718537
2 changed files with 294 additions and 47 deletions

View File

@ -29,8 +29,8 @@ import java.util.Comparator;
public final class KeyboardTheme { public final class KeyboardTheme {
private static final String TAG = KeyboardTheme.class.getSimpleName(); private static final String TAG = KeyboardTheme.class.getSimpleName();
static final String KITKAT_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916"; static final String KLP_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916";
static final String KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509"; static final String LXX_KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509";
static final int THEME_ID_ICS = 0; static final int THEME_ID_ICS = 0;
static final int THEME_ID_KLP = 2; static final int THEME_ID_KLP = 2;
@ -39,9 +39,9 @@ public final class KeyboardTheme {
private static final KeyboardTheme[] KEYBOARD_THEMES = { private static final KeyboardTheme[] KEYBOARD_THEMES = {
new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS, new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS,
VERSION_CODES.ICE_CREAM_SANDWICH), VERSION_CODES.BASE),
new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP, new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP,
VERSION_CODES.KITKAT), VERSION_CODES.ICE_CREAM_SANDWICH),
new KeyboardTheme(THEME_ID_LXX, R.style.KeyboardTheme_LXX, new KeyboardTheme(THEME_ID_LXX, R.style.KeyboardTheme_LXX,
// TODO: Update this constant once the *next* version becomes available. // TODO: Update this constant once the *next* version becomes available.
VERSION_CODES.CUR_DEVELOPMENT), VERSION_CODES.CUR_DEVELOPMENT),
@ -116,22 +116,23 @@ public final class KeyboardTheme {
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs, static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
final int sdkVersion) { final int sdkVersion) {
final String obsoleteIdString = prefs.getString(KITKAT_KEYBOARD_THEME_KEY, null); final String klpThemeIdString = prefs.getString(KLP_KEYBOARD_THEME_KEY, null);
if (obsoleteIdString != null) { if (klpThemeIdString != null) {
// Remove old preference.
prefs.edit().remove(KITKAT_KEYBOARD_THEME_KEY).apply();
if (sdkVersion <= VERSION_CODES.KITKAT) { if (sdkVersion <= VERSION_CODES.KITKAT) {
try { try {
final int themeId = Integer.parseInt(obsoleteIdString); final int themeId = Integer.parseInt(klpThemeIdString);
final KeyboardTheme theme = searchKeyboardThemeById(themeId); final KeyboardTheme theme = searchKeyboardThemeById(themeId);
if (theme != null) { if (theme != null) {
return theme; return theme;
} }
Log.w(TAG, "Unknown keyboard theme in preference: " + obsoleteIdString); Log.w(TAG, "Unknown keyboard theme in KLP preference: " + klpThemeIdString);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
Log.w(TAG, "Illegal keyboard theme in preference: " + obsoleteIdString); Log.w(TAG, "Illegal keyboard theme in KLP preference: " + klpThemeIdString, e);
} }
} }
// Remove old preference.
Log.i(TAG, "Remove KLP keyboard theme preference: " + klpThemeIdString);
prefs.edit().remove(KLP_KEYBOARD_THEME_KEY).apply();
} }
// TODO: This search algorithm isn't optimal if there are many themes. // TODO: This search algorithm isn't optimal if there are many themes.
for (final KeyboardTheme theme : KEYBOARD_THEMES) { for (final KeyboardTheme theme : KEYBOARD_THEMES) {
@ -144,27 +145,43 @@ public final class KeyboardTheme {
public static void saveKeyboardThemeId(final String themeIdString, public static void saveKeyboardThemeId(final String themeIdString,
final SharedPreferences prefs) { final SharedPreferences prefs) {
prefs.edit().putString(KEYBOARD_THEME_KEY, themeIdString).apply(); saveKeyboardThemeId(themeIdString, prefs, getSdkVersion());
}
static String getPreferenceKey(final int sdkVersion) {
if (sdkVersion <= VERSION_CODES.KITKAT) {
return KLP_KEYBOARD_THEME_KEY;
}
return LXX_KEYBOARD_THEME_KEY;
}
static void saveKeyboardThemeId(final String themeIdString, final SharedPreferences prefs,
final int sdkVersion) {
final String prefKey = getPreferenceKey(sdkVersion);
prefs.edit().putString(prefKey, themeIdString).apply();
} }
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) { public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
final int sdkVersion = getSdkVersion(); return getKeyboardTheme(prefs, getSdkVersion());
final String themeIdString = prefs.getString(KEYBOARD_THEME_KEY, null); }
if (themeIdString == null) {
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion) {
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
if (lxxThemeIdString == null) {
return getDefaultKeyboardTheme(prefs, sdkVersion); return getDefaultKeyboardTheme(prefs, sdkVersion);
} }
try { try {
final int themeId = Integer.parseInt(themeIdString); final int themeId = Integer.parseInt(lxxThemeIdString);
final KeyboardTheme theme = searchKeyboardThemeById(themeId); final KeyboardTheme theme = searchKeyboardThemeById(themeId);
if (theme != null) { if (theme != null) {
return theme; return theme;
} }
Log.w(TAG, "Unknown keyboard theme in preference: " + themeIdString); Log.w(TAG, "Unknown keyboard theme in LXX preference: " + lxxThemeIdString);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString); Log.w(TAG, "Illegal keyboard theme in LXX preference: " + lxxThemeIdString, e);
} }
// Remove preference. // Remove preference that contains unknown or illegal theme id.
prefs.edit().remove(KEYBOARD_THEME_KEY).apply(); prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply();
return getDefaultKeyboardTheme(prefs, sdkVersion); return getDefaultKeyboardTheme(prefs, sdkVersion);
} }
} }

View File

@ -26,7 +26,13 @@ import android.test.suitebuilder.annotation.SmallTest;
public class KeyboardThemeTests extends AndroidTestCase { public class KeyboardThemeTests extends AndroidTestCase {
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
// TODO: Remove this constant once the *next* version becomes available.
private static final int VERSION_CODES_LXX = VERSION_CODES.CUR_DEVELOPMENT;
private static final int THEME_ID_NULL = -1; private static final int THEME_ID_NULL = -1;
private static final int THEME_ID_UNKNOWN = -2;
private static final int THEME_ID_ILLEGAL = -3;
private static final String ILLEGAL_THEME_ID_STRING = "ThisCausesNumberFormatExecption";
private static final int THEME_ID_ICS = KeyboardTheme.THEME_ID_ICS; private static final int THEME_ID_ICS = KeyboardTheme.THEME_ID_ICS;
private static final int THEME_ID_KLP = KeyboardTheme.THEME_ID_KLP; private static final int THEME_ID_KLP = KeyboardTheme.THEME_ID_KLP;
private static final int THEME_ID_LXX = KeyboardTheme.THEME_ID_LXX; private static final int THEME_ID_LXX = KeyboardTheme.THEME_ID_LXX;
@ -37,57 +43,281 @@ public class KeyboardThemeTests extends AndroidTestCase {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
} }
/*
* Helper functions.
*/
private static boolean isValidKeyboardThemeId(final int themeId) {
switch (themeId) {
case THEME_ID_ICS:
case THEME_ID_KLP:
case THEME_ID_LXX:
return true;
default:
return false;
}
}
private void setKeyboardThemePreference(final String prefKey, final int themeId) {
final String themeIdString = Integer.toString(themeId);
if (isValidKeyboardThemeId(themeId) || themeId == THEME_ID_UNKNOWN) {
// Set valid theme id to preference.
mPrefs.edit().putString(prefKey, themeIdString).apply();
return;
}
if (themeId == THEME_ID_NULL) {
// Simulate undefined preference.
mPrefs.edit().remove(prefKey).apply();
return;
}
// themeId == THEME_ID_ILLEGAL
// Simulate illegal format theme id in preference.
mPrefs.edit().putString(prefKey, ILLEGAL_THEME_ID_STRING).apply();
}
private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) {
assertEquals(expectedThemeId, KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion).mThemeId);
}
/*
* Test keyboard theme preference on the same platform version and the same keyboard version.
*/
private void assertKeyboardThemePreference(final int sdkVersion, final int oldThemeId,
final int expectedThemeId) {
final String prefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
setKeyboardThemePreference(prefKey, oldThemeId);
assertKeyboardTheme(sdkVersion, expectedThemeId);
}
private void assertKeyboardThemePreferenceOnKlp(final int sdkVersion) {
final int defaultThemeId = THEME_ID_KLP;
assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId);
assertKeyboardThemePreference(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertKeyboardThemePreference(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX, THEME_ID_LXX);
assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId);
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
}
public void testKeyboardThemePreferenceOnKlp() {
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.KITKAT);
}
private void assertKeyboardThemePreferenceOnLxx(final int sdkVersion) {
final int defaultThemeId = THEME_ID_LXX;
assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId);
assertKeyboardThemePreference(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertKeyboardThemePreference(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX, THEME_ID_LXX);
assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId);
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
}
public void testKeyboardThemePreferenceOnLxx() {
assertKeyboardThemePreferenceOnLxx(VERSION_CODES_LXX);
}
/*
* Test default keyboard theme based on the platform version.
*/
private void assertDefaultKeyboardTheme(final int sdkVersion, final int oldThemeId, private void assertDefaultKeyboardTheme(final int sdkVersion, final int oldThemeId,
final int expectedThemeId) { final int expectedThemeId) {
if (oldThemeId == THEME_ID_NULL) { final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY;
mPrefs.edit().remove(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY).apply(); setKeyboardThemePreference(oldPrefKey, oldThemeId);
} else {
final String themeIdString = Integer.toString(oldThemeId);
mPrefs.edit().putString(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY, themeIdString).apply();
}
final KeyboardTheme defaultTheme = final KeyboardTheme defaultTheme =
KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion); KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion);
assertNotNull(defaultTheme); assertNotNull(defaultTheme);
assertEquals(expectedThemeId, defaultTheme.mThemeId); assertEquals(expectedThemeId, defaultTheme.mThemeId);
assertFalse(mPrefs.contains(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY)); if (sdkVersion <= VERSION_CODES.KITKAT) {
// Old preference must be retained if it is valid. Otherwise it must be pruned.
assertEquals(isValidKeyboardThemeId(oldThemeId), mPrefs.contains(oldPrefKey));
return;
}
// Old preference must be removed.
assertFalse(mPrefs.contains(oldPrefKey));
} }
private void assertDefaultKeyboardThemeICS(final int sdkVersion) { private void assertDefaultKeyboardThemeOnKlp(final int sdkVersion) {
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_ICS);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
}
private void assertDefaultKeyboardThemeKLP(final int sdkVersion) {
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_KLP); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_KLP);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP);
} }
private void assertDefaultKeyboardThemeLXX(final int sdkVersion) { public void testDefaultKeyboardThemeOnKlp() {
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.KITKAT);
}
private void assertDefaultKeyboardThemeOnLxx(final int sdkVersion) {
// Forced to switch to LXX theme. // Forced to switch to LXX theme.
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_LXX); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_LXX);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_LXX); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_LXX);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_LXX); assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_LXX);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX);
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX);
} }
public void testDefaultKeyboardThemeICS() { public void testDefaultKeyboardThemeOnLxx() {
assertDefaultKeyboardThemeICS(VERSION_CODES.ICE_CREAM_SANDWICH); assertDefaultKeyboardThemeOnLxx(VERSION_CODES_LXX);
assertDefaultKeyboardThemeICS(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
} }
public void testDefaultKeyboardThemeJB() { /*
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN); * Test keyboard theme preference while upgrading the keyboard that doesn't support LXX theme
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN_MR1); * to the keyboard that supports LXX theme.
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN_MR2); */
private void assertUpgradeKeyboardToLxxOn(final int sdkVersion, final int oldThemeId,
final int expectedThemeId) {
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, oldThemeId);
// Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard".
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion);
assertNotNull(theme);
assertEquals(expectedThemeId, theme.mThemeId);
if (sdkVersion <= VERSION_CODES.KITKAT) {
// New preference must not exist.
assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY));
// Old preference must be retained if it is valid. Otherwise it must be pruned.
assertEquals(isValidKeyboardThemeId(oldThemeId),
mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY));
if (isValidKeyboardThemeId(oldThemeId)) {
// Old preference must have an expected value.
assertEquals(mPrefs.getString(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, null),
Integer.toString(expectedThemeId));
}
return;
}
// Old preference must be removed.
assertFalse(mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY));
// New preference must not exist.
assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY));
} }
public void testDefaultKeyboardThemeKLP() { private void assertUpgradeKeyboardToLxxOnKlp(final int sdkVersion) {
assertDefaultKeyboardThemeKLP(VERSION_CODES.KITKAT); assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_NULL, THEME_ID_KLP);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP);
} }
public void testDefaultKeyboardThemeLXX() { // Upgrading keyboard on I,J and K.
// TODO: Update this constant once the *next* version becomes available. public void testUpgradeKeyboardToLxxOnKlp() {
assertDefaultKeyboardThemeLXX(VERSION_CODES.CUR_DEVELOPMENT); assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.KITKAT);
}
private void assertUpgradeKeyboardToLxxOnLxx(final int sdkVersion) {
// Forced to switch to LXX theme.
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_NULL, THEME_ID_LXX);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ICS, THEME_ID_LXX);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_KLP, THEME_ID_LXX);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX);
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX);
}
// Upgrading keyboard on L.
public void testUpgradeKeyboardToLxxOnLxx() {
assertUpgradeKeyboardToLxxOnLxx(VERSION_CODES_LXX);
}
/*
* Test keyboard theme preference while upgrading platform version.
*/
private void assertUpgradePlatformFromTo(final int oldSdkVersion, final int newSdkVersion,
final int oldThemeId, final int expectedThemeId) {
if (newSdkVersion < oldSdkVersion) {
// No need to test.
return;
}
// Clean up preferences.
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
final String oldPrefKey = KeyboardTheme.getPreferenceKey(oldSdkVersion);
setKeyboardThemePreference(oldPrefKey, oldThemeId);
assertKeyboardTheme(newSdkVersion, expectedThemeId);
}
private void assertUpgradePlatformFromKlpToKlp(final int oldSdkVersion,
final int newSdkVersion) {
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_KLP);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP);
}
private void assertUpgradePlatformToKlpFrom(final int oldSdkVersion) {
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN);
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR1);
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR2);
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.KITKAT);
}
// Update platform from I,J, and K to I,J, and K
public void testUpgradePlatformToKlpFromKlp() {
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN);
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR1);
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR2);
assertUpgradePlatformToKlpFrom(VERSION_CODES.KITKAT);
}
private void assertUpgradePlatformToLxxFrom(final int oldSdkVersion) {
// Forced to switch to LXX theme.
final int newSdkVersion = VERSION_CODES_LXX;
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX);
}
// Update platform from I,J, and K to L
public void testUpgradePlatformToLxx() {
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN);
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR1);
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR2);
assertUpgradePlatformToLxxFrom(VERSION_CODES.KITKAT);
}
// Update platform from L to L.
public void testUpgradePlatformToLxxFromLxx() {
final int oldSdkVersion = VERSION_CODES_LXX;
final int newSdkVersion = VERSION_CODES_LXX;
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_ICS);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_KLP);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX);
assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX);
} }
} }