Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa0e47e0 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add an overlayable config for IME switcher visibility.

Seems that there are two mutually exclusive requests about how IME
switcher visibility should be controlled.
  A. Requests like Bug 19496012.  We should show the IME switcher
     as a quick access to "Show input method" setting when a physical
     keyboard is attached via wireless connections that do not have
     clear connection/disconnection affordance (e.g. Bluetooth
     keyboards).
  B. Requests like Bug 25432652.  We should not have a rule like A
     when a physical keyboard is attached with clear
     connection/disconnection affordance (e.g. USB wired keyboards,
     2-in-1 convertible tables w/ magnetic contacts).

Currently satisfying both requests at the same time is really difficult
because InputDevice does not have such an attribute.  Even with such an
attribute, it's still an open question about how to deal with two or
more keyboards.  As a short term solution, this CL add an overlayable
config so that each device can configure which strategy to apply as the
default behavior.

Bug: 26245853
Change-Id: Id2aef6597916422ea63435ae9c31a9a9b5ddf5b8
parent 9d8ec0f1
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -2507,4 +2507,17 @@


    <!-- True if the device supports Sustained Performance Mode-->
    <!-- True if the device supports Sustained Performance Mode-->
    <bool name="config_sustainedPerformanceModeSupported">false</bool>
    <bool name="config_sustainedPerformanceModeSupported">false</bool>

    <!-- Controls how we deal with externally connected physical keyboards.
         0 - When using this device, it is not clear for users to recognize when the physical
             keyboard is (should be) connected and when it is (should be) disconnected.  Most of
             phones and tablets with Bluetooth keyboard would fall into this category because the
             connected Bluetooth keyboard may or may not be nearby the host device.
         1 - When using this device, it is clear for users to recognize when the physical
             keyboard is (should be) connected and when it is (should be) disconnected.
             Devices with wired USB keyboard is one clear example.  Some 2-in-1 convertible
             tablets with dedicated keyboards may have the same affordance to wired USB keyboard.
    -->
    <integer name="config_externalHardKeyboardBehavior">0</integer>

</resources>
</resources>
+1 −0
Original line number Original line Diff line number Diff line
@@ -1744,6 +1744,7 @@
  <java-symbol type="integer" name="config_defaultNotificationLedOff" />
  <java-symbol type="integer" name="config_defaultNotificationLedOff" />
  <java-symbol type="integer" name="config_defaultNotificationLedOn" />
  <java-symbol type="integer" name="config_defaultNotificationLedOn" />
  <java-symbol type="integer" name="config_deskDockKeepsScreenOn" />
  <java-symbol type="integer" name="config_deskDockKeepsScreenOn" />
  <java-symbol type="integer" name="config_externalHardKeyboardBehavior" />
  <java-symbol type="integer" name="config_lightSensorWarmupTime" />
  <java-symbol type="integer" name="config_lightSensorWarmupTime" />
  <java-symbol type="integer" name="config_lowBatteryCloseWarningBump" />
  <java-symbol type="integer" name="config_lowBatteryCloseWarningBump" />
  <java-symbol type="integer" name="config_lowBatteryWarningLevel" />
  <java-symbol type="integer" name="config_lowBatteryWarningLevel" />
+21 −5
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@


package com.android.server;
package com.android.server;


import static java.lang.annotation.RetentionPolicy.SOURCE;

import com.android.internal.content.PackageMonitor;
import com.android.internal.content.PackageMonitor;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
@@ -37,6 +39,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.XmlSerializer;


import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
@@ -133,6 +136,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
@@ -178,6 +182,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
    private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
    private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";


    @Retention(SOURCE)
    @IntDef({HardKeyboardBehavior.WIRELESS_AFFORDANCE, HardKeyboardBehavior.WIRED_AFFORDANCE})
    private @interface  HardKeyboardBehavior {
        int WIRELESS_AFFORDANCE = 0;
        int WIRED_AFFORDANCE = 1;
    }


    final Context mContext;
    final Context mContext;
    final Resources mRes;
    final Resources mRes;
@@ -462,6 +472,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
    private final IPackageManager mIPackageManager;
    private final IPackageManager mIPackageManager;
    private final String mSlotIme;
    private final String mSlotIme;
    @HardKeyboardBehavior
    private final int mHardKeyboardBehavior;


    class SettingsObserver extends ContentObserver {
    class SettingsObserver extends ContentObserver {
        int mUserId;
        int mUserId;
@@ -854,6 +866,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        mHasFeature = context.getPackageManager().hasSystemFeature(
        mHasFeature = context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_INPUT_METHODS);
                PackageManager.FEATURE_INPUT_METHODS);
        mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime);
        mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime);
        mHardKeyboardBehavior = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_externalHardKeyboardBehavior);


        Bundle extras = new Bundle();
        Bundle extras = new Bundle();
        extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true);
        extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true);
@@ -1712,11 +1726,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        if (isScreenLocked()) return false;
        if (isScreenLocked()) return false;
        if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false;
        if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false;
        if (mWindowManagerInternal.isHardKeyboardAvailable()) {
        if (mWindowManagerInternal.isHardKeyboardAvailable()) {
            if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) {
                // When physical keyboard is attached, we show the ime switcher (or notification if
                // When physical keyboard is attached, we show the ime switcher (or notification if
                // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently
                // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently
                // exists in the IME switcher dialog.  Might be OK to remove this condition once
                // exists in the IME switcher dialog.  Might be OK to remove this condition once
                // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live.
                // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live.
                return true;
                return true;
            }
        } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) {
        } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) {
            return false;
            return false;
        }
        }