1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.inputmethod; 18 19 import static com.android.settings.keyboard.Flags.keyboardAndTouchpadA11yNewPageEnabled; 20 21 import android.content.Context; 22 import android.view.InputDevice; 23 24 import com.android.settings.core.BasePreferenceController; 25 26 /** Controller that shows and updates the Physical Keyboard a11y preference. */ 27 public class PhysicalKeyboardA11yPreferenceController extends BasePreferenceController { 28 29 PhysicalKeyboardA11yPreferenceController(Context context, String preferenceKey)30 public PhysicalKeyboardA11yPreferenceController(Context context, 31 String preferenceKey) { 32 super(context, preferenceKey); 33 } 34 35 @Override getAvailabilityStatus()36 public int getAvailabilityStatus() { 37 return keyboardAndTouchpadA11yNewPageEnabled() 38 && isAnyHardKeyboardsExist() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 39 } 40 isAnyHardKeyboardsExist()41 private static boolean isAnyHardKeyboardsExist() { 42 for (int deviceId : InputDevice.getDeviceIds()) { 43 final InputDevice device = InputDevice.getDevice(deviceId); 44 if (device != null && !device.isVirtual() && device.isFullKeyboard()) { 45 return true; 46 } 47 } 48 return false; 49 } 50 } 51