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

Commit 7b5a96ba authored by Michael Wright's avatar Michael Wright
Browse files

Persist Show IME option.

Add a new setting to persist whether to show the IME when a hard
keyboard is connected.

Bug: 14066881
Change-Id: I2237ded850a0d4ab43ca441d0b7df13e0958e630
parent 665366a3
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -3545,6 +3545,13 @@ public final class Settings {
         */
         */
        public static final String DISABLED_SYSTEM_INPUT_METHODS = "disabled_system_input_methods";
        public static final String DISABLED_SYSTEM_INPUT_METHODS = "disabled_system_input_methods";


        /**
         * Whether to show the IME when a hard keyboard is connected. This is a boolean that
         * determines if the IME should be shown when a hard keyboard is attached.
         * @hide
         */
        public static final String SHOW_IME_WITH_HARD_KEYBOARD = "show_ime_with_hard_keyboard";

        /**
        /**
         * Host name and port for global http proxy. Uses ':' seperator for
         * Host name and port for global http proxy. Uses ':' seperator for
         * between host and port.
         * between host and port.
+10 −0
Original line number Original line Diff line number Diff line
@@ -974,6 +974,16 @@ public class InputMethodUtils {
            }
            }
        }
        }


        public boolean isShowImeWithHardKeyboardEnabled() {
                return Settings.Secure.getIntForUser(mResolver,
                        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0, mCurrentUserId) == 1;
        }

        public void setShowImeWithHardKeyboard(boolean show) {
            Settings.Secure.putIntForUser(mResolver, Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
                    show ? 1 : 0, mCurrentUserId);
        }

        public int getCurrentUserId() {
        public int getCurrentUserId() {
            return mCurrentUserId;
            return mCurrentUserId;
        }
        }
+43 −19
Original line number Original line Diff line number Diff line
@@ -66,6 +66,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.InputMethodService;
import android.net.Uri;
import android.os.Binder;
import android.os.Binder;
import android.os.Environment;
import android.os.Environment;
import android.os.Handler;
import android.os.Handler;
@@ -392,6 +393,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private InputMethodInfo[] mIms;
    private InputMethodInfo[] mIms;
    private int[] mSubtypeIds;
    private int[] mSubtypeIds;
    private Locale mLastSystemLocale;
    private Locale mLastSystemLocale;
    private boolean mShowImeWithHardKeyboard;
    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
    private final IPackageManager mIPackageManager;
    private final IPackageManager mIPackageManager;


@@ -407,17 +409,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    Settings.Secure.ENABLED_INPUT_METHODS), false, this);
                    Settings.Secure.ENABLED_INPUT_METHODS), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
                    Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this);
        }
        }


        @Override public void onChange(boolean selfChange) {
        @Override public void onChange(boolean selfChange, Uri uri) {
            final Uri showImeUri =
                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
            synchronized (mMethodMap) {
            synchronized (mMethodMap) {
                if (showImeUri.equals(uri)) {
                    updateKeyboardFromSettingsLocked();
                } else {
                    boolean enabledChanged = false;
                    boolean enabledChanged = false;
                    String newEnabled = mSettings.getEnabledInputMethodsStr();
                    String newEnabled = mSettings.getEnabledInputMethodsStr();
                    if (!mLastEnabled.equals(newEnabled)) {
                    if (!mLastEnabled.equals(newEnabled)) {
                        mLastEnabled = newEnabled;
                        mLastEnabled = newEnabled;
                        enabledChanged = true;
                        enabledChanged = true;
                    }
                    }
                updateFromSettingsLocked(enabledChanged);
                    updateInputMethodsFromSettingsLocked(enabledChanged);
                }
            }
            }
        }
        }
    }
    }
@@ -598,16 +608,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private class HardKeyboardListener
    private class HardKeyboardListener
            implements WindowManagerService.OnHardKeyboardStatusChangeListener {
            implements WindowManagerService.OnHardKeyboardStatusChangeListener {
        @Override
        @Override
        public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
        public void onHardKeyboardStatusChange(boolean available) {
            mHandler.sendMessage(mHandler.obtainMessage(
            mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED,
                    MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
                        available ? 1 : 0));
        }
        }


        public void handleHardKeyboardStatusChange(boolean available,
        public void handleHardKeyboardStatusChange(boolean available) {
                boolean showImeWithHardKeyboard) {
            if (DEBUG) {
            if (DEBUG) {
                Slog.w(TAG, "HardKeyboardStatusChanged: available = " + available
                Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available);
                        + ", showImeWithHardKeyboard= " + showImeWithHardKeyboard);
            }
            }
            synchronized(mMethodMap) {
            synchronized(mMethodMap) {
                if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
                if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
@@ -1657,6 +1665,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }
    }


    void updateFromSettingsLocked(boolean enabledMayChange) {
    void updateFromSettingsLocked(boolean enabledMayChange) {
        updateInputMethodsFromSettingsLocked(enabledMayChange);
        updateKeyboardFromSettingsLocked();
    }

    void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
        if (enabledMayChange) {
        if (enabledMayChange) {
            List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
            List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
            for (int i=0; i<enabled.size(); i++) {
            for (int i=0; i<enabled.size(); i++) {
@@ -1710,6 +1723,18 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        // TODO: Make sure that mSwitchingController and mSettings are sharing the
        // TODO: Make sure that mSwitchingController and mSettings are sharing the
        // the same enabled IMEs list.
        // the same enabled IMEs list.
        mSwitchingController.resetCircularListLocked(mContext);
        mSwitchingController.resetCircularListLocked(mContext);

    }

    public void updateKeyboardFromSettingsLocked() {
        mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
        if (mSwitchingDialog != null
                && mSwitchingDialogTitleView != null
                && mSwitchingDialog.isShowing()) {
            final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
                    com.android.internal.R.id.hard_keyboard_switch);
            hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
        }
    }
    }


    /* package */ void setInputMethodLocked(String id, int subtypeId) {
    /* package */ void setInputMethodLocked(String id, int subtypeId) {
@@ -2594,8 +2619,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub


            // --------------------------------------------------------------
            // --------------------------------------------------------------
            case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
            case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
                mHardKeyboardListener.handleHardKeyboardStatusChange(
                mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1);
                        msg.arg1 == 1, msg.arg2 == 1);
                return true;
                return true;
        }
        }
        return false;
        return false;
@@ -2684,7 +2708,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            if (!map.containsKey(defaultImiId)) {
            if (!map.containsKey(defaultImiId)) {
                Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
                Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
                if (chooseNewDefaultIMELocked()) {
                if (chooseNewDefaultIMELocked()) {
                    updateFromSettingsLocked(true);
                    updateInputMethodsFromSettingsLocked(true);
                }
                }
            } else {
            } else {
                // Double check that the default IME is certainly enabled.
                // Double check that the default IME is certainly enabled.
@@ -2811,11 +2835,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            ? View.VISIBLE : View.GONE);
                            ? View.VISIBLE : View.GONE);
            final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
            final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
                    com.android.internal.R.id.hard_keyboard_switch);
                    com.android.internal.R.id.hard_keyboard_switch);
            hardKeySwitch.setChecked(mWindowManagerService.isShowImeWithHardKeyboardEnabled());
            hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
            hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                @Override
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    mWindowManagerService.setShowImeWithHardKeyboard(isChecked);
                    mSettings.setShowImeWithHardKeyboard(isChecked);
                    // Ensure that the input method dialog is dismissed when changing
                    // Ensure that the input method dialog is dismissed when changing
                    // the hardware keyboard state.
                    // the hardware keyboard state.
                    hideInputMethodMenu();
                    hideInputMethodMenu();
+28 −16
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ import android.app.StatusBarManager;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
@@ -58,6 +59,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.res.CompatibilityInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Canvas;
@@ -539,6 +541,21 @@ public class WindowManagerService extends IWindowManager.Stub
    boolean mHardKeyboardAvailable;
    boolean mHardKeyboardAvailable;
    boolean mShowImeWithHardKeyboard;
    boolean mShowImeWithHardKeyboard;
    OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
    OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
    SettingsObserver mSettingsObserver;

    private final class SettingsObserver extends ContentObserver {
        public SettingsObserver() {
            super(new Handler());
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this);
        }

        @Override
        public void onChange(boolean selfChange) {
            updateShowImeWithHardKeyboard();
        }
    }


    final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
    final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();


@@ -838,6 +855,9 @@ public class WindowManagerService extends IWindowManager.Stub
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        mContext.registerReceiver(mBroadcastReceiver, filter);
        mContext.registerReceiver(mBroadcastReceiver, filter);


        mSettingsObserver = new SettingsObserver();
        updateShowImeWithHardKeyboard();

        mHoldingScreenWakeLock = mPowerManager.newWakeLock(
        mHoldingScreenWakeLock = mPowerManager.newWakeLock(
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
        mHoldingScreenWakeLock.setReferenceCounted(false);
        mHoldingScreenWakeLock.setReferenceCounted(false);
@@ -7015,7 +7035,6 @@ public class WindowManagerService extends IWindowManager.Stub
            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
                mHardKeyboardAvailable = hardKeyboardAvailable;
                mHardKeyboardAvailable = hardKeyboardAvailable;
                mShowImeWithHardKeyboard = !hardKeyboardAvailable;
                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
            }
            }
@@ -7039,18 +7058,12 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }
    }
    }


    public boolean isShowImeWithHardKeyboardEnabled() {
    public void updateShowImeWithHardKeyboard() {
        boolean showImeWithHardKeyboard = Settings.Secure.getIntForUser(
                mContext.getContentResolver(), Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0,
                mCurrentUserId) == 1;
        synchronized (mWindowMap) {
        synchronized (mWindowMap) {
            return mShowImeWithHardKeyboard;
            mShowImeWithHardKeyboard = showImeWithHardKeyboard;
        }
    }

    public void setShowImeWithHardKeyboard(boolean enabled) {
        synchronized (mWindowMap) {
            if (mShowImeWithHardKeyboard != enabled) {
                mShowImeWithHardKeyboard = enabled;
                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
            }
        }
        }
    }
    }


@@ -7062,15 +7075,14 @@ public class WindowManagerService extends IWindowManager.Stub
    }
    }


    void notifyHardKeyboardStatusChange() {
    void notifyHardKeyboardStatusChange() {
        final boolean available, showImeWithHardKeyboard;
        final boolean available;
        final OnHardKeyboardStatusChangeListener listener;
        final OnHardKeyboardStatusChangeListener listener;
        synchronized (mWindowMap) {
        synchronized (mWindowMap) {
            listener = mHardKeyboardStatusChangeListener;
            listener = mHardKeyboardStatusChangeListener;
            available = mHardKeyboardAvailable;
            available = mHardKeyboardAvailable;
            showImeWithHardKeyboard = mShowImeWithHardKeyboard;
        }
        }
        if (listener != null) {
        if (listener != null) {
            listener.onHardKeyboardStatusChange(available, showImeWithHardKeyboard);
            listener.onHardKeyboardStatusChange(available);
        }
        }
    }
    }


@@ -11053,7 +11065,7 @@ public class WindowManagerService extends IWindowManager.Stub
    }
    }


    public interface OnHardKeyboardStatusChangeListener {
    public interface OnHardKeyboardStatusChangeListener {
        public void onHardKeyboardStatusChange(boolean available, boolean showIme);
        public void onHardKeyboardStatusChange(boolean available);
    }
    }


    void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {
    void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {