From 3cac24167f9b51e4b672ea322affec1bc5575495 Mon Sep 17 00:00:00 2001 From: Weilun Du Date: Fri, 8 Nov 2019 22:26:04 -0800 Subject: [PATCH] [SdkSetup] Set physical keyboard layout Emulator host will set the guest keyboard layout with boot properties based on the host keyboard layout. Also, fixed complaints in setting properties adb_enabled and install_non_market_apps. BUG: 78115103 Merged-In: Iad3750af5383ba27fbf20eb9b26652f037853f1f Change-Id: Iad3750af5383ba27fbf20eb9b26652f037853f1f Signed-off-by: Weilun Du --- apps/SdkSetup/AndroidManifest.xml | 3 +- .../com/android/sdksetup/DefaultActivity.java | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/apps/SdkSetup/AndroidManifest.xml b/apps/SdkSetup/AndroidManifest.xml index 37f5a943b..cab8f3797 100644 --- a/apps/SdkSetup/AndroidManifest.xml +++ b/apps/SdkSetup/AndroidManifest.xml @@ -21,7 +21,8 @@ - + + diff --git a/apps/SdkSetup/src/com/android/sdksetup/DefaultActivity.java b/apps/SdkSetup/src/com/android/sdksetup/DefaultActivity.java index f73364198..69dc8eae9 100644 --- a/apps/SdkSetup/src/com/android/sdksetup/DefaultActivity.java +++ b/apps/SdkSetup/src/com/android/sdksetup/DefaultActivity.java @@ -20,12 +20,16 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; +import android.hardware.input.InputManager; +import android.hardware.input.KeyboardLayout; import android.location.LocationManager; import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemProperties; import android.os.Build; import android.provider.Settings; +import android.view.InputDevice; /** * Entry point for SDK SetupWizard. @@ -39,6 +43,13 @@ public class DefaultActivity extends Activity { // Edit Settings only for Emulator if (Build.IS_EMULATOR) { + // Set physical keyboard layout based on the system property set by emulator host. + String layoutName = SystemProperties.get("qemu.keyboard_layout"); + String deviceName = "qwerty2"; + InputDevice device = getKeyboardDevice(deviceName); + if (device != null && !layoutName.isEmpty()) { + setKeyboardLayout(device, layoutName); + } // Add a persistent setting to allow other apps to know the device has been provisioned. Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); @@ -53,9 +64,9 @@ public class DefaultActivity extends Activity { LocationManager.GPS_PROVIDER); // enable install from non market - Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, 1); + Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 1); - Settings.Secure.putInt(getContentResolver(),Settings.Secure.ADB_ENABLED, 1); + Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, 1); } // remove this activity from the package manager. @@ -66,5 +77,34 @@ public class DefaultActivity extends Activity { // terminate the activity. finish(); } + + private InputDevice getKeyboardDevice(String keyboardDeviceName) { + int[] deviceIds = InputDevice.getDeviceIds(); + + for (int deviceId : deviceIds) { + InputDevice inputDevice = InputDevice.getDevice(deviceId); + if (inputDevice != null + && inputDevice.supportsSource(InputDevice.SOURCE_KEYBOARD) + && inputDevice.getName().equals(keyboardDeviceName)) { + return inputDevice; + } + } + return null; + } + + private void setKeyboardLayout(InputDevice keyboardDevice, String layoutName) { + InputManager im = InputManager.getInstance(); + + KeyboardLayout[] keyboardLayouts = + im.getKeyboardLayoutsForInputDevice(keyboardDevice.getIdentifier()); + + for (KeyboardLayout keyboardLayout : keyboardLayouts) { + if (keyboardLayout.getDescriptor().endsWith(layoutName)) { + im.setCurrentKeyboardLayoutForInputDevice( + keyboardDevice.getIdentifier(), keyboardLayout.getDescriptor()); + return; + } + } + } }