From 60b59042d1f5a1449de049a7f7adb3d6e40b8b06 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 22 Feb 2016 20:02:27 -0800 Subject: [PATCH] Fix runtime crash on KitKat and prior. This is a follow up CL to the previous CL [1], in which we started calling Window#setNavigationBarColor(int) when the window visibility is changed. One thing we missed is that calling Window#setNavigationBarColor(int) on KitKant or prior devices would result in a runtime crash. Hence with this CL we do not call that method unless the OS version is N or leter, because specifying Color.TRANSPARENT would make sense on N+ devices. [1]: I14d9490e00caa852035a05830e76114cbe6af8f2 6c04339c5aadb5118b0e0a8178b3d569956bbad7 Bug: 22564251 Bug: 27302540 Change-Id: Ib7299dd8c3dad4271f8fac453e690c83bda4a954 --- java/src/com/android/inputmethod/latin/LatinIME.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c2d9f965f..f938b6078 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -33,6 +33,7 @@ import android.content.res.Resources; import android.graphics.Color; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; +import android.os.Build; import android.os.Debug; import android.os.IBinder; import android.os.Message; @@ -54,6 +55,7 @@ import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.annotations.UsedForTesting; +import com.android.inputmethod.compat.BuildCompatUtils; import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils; @@ -1908,7 +1910,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private void setNavigationBarVisibility(final boolean visible) { - // Color.BLACK is ignored and default IME navigation bar color is used. - getWindow().getWindow().setNavigationBarColor(visible ? Color.BLACK : Color.TRANSPARENT); + if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.M) { + // For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar + // transparent. For other colors the system uses the default color. + getWindow().getWindow().setNavigationBarColor( + visible ? Color.BLACK : Color.TRANSPARENT); + } } }