IMM#isStylusHandwritingAvailableAsUser, IMM#getEnabledInputMethodListAsUser, and IMM#getEnabledInputMethodSubtypeListAsUser use now UserHandle instead of userId. These internal APIs are used in Settings and are updated. Test: atest android.view.inputmethod.cts.installtests.MultiUserTest Fix: 283765791 Change-Id: Iedb301fbe26810f2101cbb2669b8be95b87a3e7f
126 lines
4.5 KiB
Java
126 lines
4.5 KiB
Java
/*
|
|
* Copyright (C) 2023 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.android.settings.inputmethod;
|
|
|
|
import android.content.Context;
|
|
import android.hardware.input.InputDeviceIdentifier;
|
|
import android.hardware.input.InputManager;
|
|
import android.hardware.input.KeyboardLayout;
|
|
import android.os.UserHandle;
|
|
import android.view.InputDevice;
|
|
import android.view.inputmethod.InputMethodInfo;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.view.inputmethod.InputMethodSubtype;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Utilities of keyboard settings
|
|
*/
|
|
public class NewKeyboardSettingsUtils {
|
|
|
|
static final String EXTRA_TITLE = "keyboard_layout_picker_title";
|
|
static final String EXTRA_USER_ID = "user_id";
|
|
static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
|
static final String EXTRA_INPUT_METHOD_INFO = "input_method_info";
|
|
static final String EXTRA_INPUT_METHOD_SUBTYPE = "input_method_subtype";
|
|
|
|
static boolean isTouchpad() {
|
|
for (int deviceId : InputDevice.getDeviceIds()) {
|
|
final InputDevice device = InputDevice.getDevice(deviceId);
|
|
if (device == null) {
|
|
continue;
|
|
}
|
|
if ((device.getSources() & InputDevice.SOURCE_TOUCHPAD)
|
|
== InputDevice.SOURCE_TOUCHPAD) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static List<String> getSuitableImeLabels(Context context, InputMethodManager imm, int userId) {
|
|
List<String> suitableInputMethodInfoLabels = new ArrayList<>();
|
|
List<InputMethodInfo> infoList = imm.getEnabledInputMethodListAsUser(UserHandle.of(userId));
|
|
for (InputMethodInfo info : infoList) {
|
|
List<InputMethodSubtype> subtypes =
|
|
imm.getEnabledInputMethodSubtypeList(info, true);
|
|
for (InputMethodSubtype subtype : subtypes) {
|
|
if (subtype.isSuitableForPhysicalKeyboardLayoutMapping()) {
|
|
suitableInputMethodInfoLabels.add(
|
|
info.loadLabel(context.getPackageManager()).toString());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return suitableInputMethodInfoLabels;
|
|
}
|
|
|
|
static class KeyboardInfo {
|
|
CharSequence mSubtypeLabel;
|
|
String mLayout;
|
|
InputMethodInfo mInputMethodInfo;
|
|
InputMethodSubtype mInputMethodSubtype;
|
|
|
|
KeyboardInfo(
|
|
CharSequence subtypeLabel,
|
|
String layout,
|
|
InputMethodInfo inputMethodInfo,
|
|
InputMethodSubtype inputMethodSubtype) {
|
|
mSubtypeLabel = subtypeLabel;
|
|
mLayout = layout;
|
|
mInputMethodInfo = inputMethodInfo;
|
|
mInputMethodSubtype = inputMethodSubtype;
|
|
}
|
|
|
|
String getPrefId() {
|
|
return mInputMethodInfo.getId() + "_" + mInputMethodSubtype.hashCode();
|
|
}
|
|
|
|
CharSequence getSubtypeLabel() {
|
|
return mSubtypeLabel;
|
|
}
|
|
|
|
String getLayout() {
|
|
return mLayout;
|
|
}
|
|
|
|
InputMethodInfo getInputMethodInfo() {
|
|
return mInputMethodInfo;
|
|
}
|
|
|
|
InputMethodSubtype getInputMethodSubtype() {
|
|
return mInputMethodSubtype;
|
|
}
|
|
}
|
|
|
|
static InputDevice getInputDevice(InputManager im, InputDeviceIdentifier identifier) {
|
|
return im.getInputDeviceByDescriptor(identifier.getDescriptor());
|
|
}
|
|
|
|
static KeyboardLayout[] getKeyboardLayouts(InputManager inputManager, int userId,
|
|
InputDeviceIdentifier identifier, InputMethodInfo info, InputMethodSubtype subtype) {
|
|
return inputManager.getKeyboardLayoutListForInputDevice(identifier, userId, info, subtype);
|
|
}
|
|
|
|
static String getKeyboardLayout(InputManager inputManager, int userId,
|
|
InputDeviceIdentifier identifier, InputMethodInfo info, InputMethodSubtype subtype) {
|
|
return inputManager.getKeyboardLayoutForInputDevice(identifier, userId, info, subtype);
|
|
}
|
|
}
|