[Physical Keyboard] Null check before using layout descriptor

If descriptor is null, pass null to LayoutSelectedCallback.onSelected to
get default layout preview image.

Bug: 396006944
Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled
Test: atest
packages/apps/Settings/tests/robotests/src/com/android/settings/inputmethod/

Change-Id: I6b454a5f0b95c571cac15258977aab5ee12d4327
This commit is contained in:
shaoweishen
2025-03-12 05:04:02 +00:00
parent a0e0065766
commit c1438d80f4
2 changed files with 18 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
@@ -48,10 +49,10 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
mKeyboardLayoutSelectedCallback =
new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() {
@Override
public void onSelected(KeyboardLayout keyboardLayout) {
public void onSelected(@Nullable KeyboardLayout keyboardLayout) {
if (mInputManager != null
&& mKeyboardLayoutPreview != null
&& mKeyboardLayoutPreviewText != null && keyboardLayout != null) {
&& mKeyboardLayoutPreviewText != null) {
Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview(
keyboardLayout,
DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT);
@@ -60,9 +61,12 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
mKeyboardLayoutPreviewText.setVisibility(
previewDrawable == null ? GONE : VISIBLE);
if (previewDrawable != null) {
mKeyboardLayoutPreviewText.setText(keyboardLayout.getLabel());
mKeyboardLayoutPreview.setImageDrawable(previewDrawable);
}
mKeyboardLayoutPreviewText.setText(
keyboardLayout != null ? keyboardLayout.getLabel()
: requireContext().getString(
R.string.keyboard_default_layout));
}
}
};