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

Commit 468fef68 authored by Michael Wright's avatar Michael Wright Committed by Android (Google) Code Review
Browse files

Merge "Persist Show IME option." into lmp-dev

parents 8b987196 7b5a96ba
Loading
Loading
Loading
Loading
+7 −0
Original line number 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";

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

@@ -407,17 +409,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    Settings.Secure.ENABLED_INPUT_METHODS), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    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) {
                if (showImeUri.equals(uri)) {
                    updateKeyboardFromSettingsLocked();
                } else {
                    boolean enabledChanged = false;
                    String newEnabled = mSettings.getEnabledInputMethodsStr();
                    if (!mLastEnabled.equals(newEnabled)) {
                        mLastEnabled = newEnabled;
                        enabledChanged = true;
                    }
                updateFromSettingsLocked(enabledChanged);
                    updateInputMethodsFromSettingsLocked(enabledChanged);
                }
            }
        }
    }
@@ -598,16 +608,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private class HardKeyboardListener
            implements WindowManagerService.OnHardKeyboardStatusChangeListener {
        @Override
        public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
            mHandler.sendMessage(mHandler.obtainMessage(
                    MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
        public void onHardKeyboardStatusChange(boolean available) {
            mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED,
                        available ? 1 : 0));
        }

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

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

    void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
        if (enabledMayChange) {
            List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
            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
        // the same enabled IMEs list.
        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) {
@@ -2594,8 +2619,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

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

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

        mSettingsObserver = new SettingsObserver();
        updateShowImeWithHardKeyboard();

        mHoldingScreenWakeLock = mPowerManager.newWakeLock(
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
        mHoldingScreenWakeLock.setReferenceCounted(false);
@@ -7018,7 +7038,6 @@ public class WindowManagerService extends IWindowManager.Stub
            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
                mHardKeyboardAvailable = hardKeyboardAvailable;
                mShowImeWithHardKeyboard = !hardKeyboardAvailable;
                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
            }
@@ -7042,18 +7061,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) {
            return mShowImeWithHardKeyboard;
        }
    }

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

@@ -7065,15 +7078,14 @@ public class WindowManagerService extends IWindowManager.Stub
    }

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

@@ -11056,7 +11068,7 @@ public class WindowManagerService extends IWindowManager.Stub
    }

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

    void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {