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

Commit 3752fc9e authored by Tarandeep Singh's avatar Tarandeep Singh Committed by Android (Google) Code Review
Browse files

Merge "Optimize calls to IME's onStartInput"

parents 25be4e04 75a92392
Loading
Loading
Loading
Loading
+55 −2
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.XmlSerializer;


import android.Manifest;
import android.Manifest;
import android.annotation.AnyThread;
import android.annotation.BinderThread;
import android.annotation.BinderThread;
import android.annotation.ColorInt;
import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.IntDef;
@@ -110,6 +111,7 @@ import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.ShellCallback;
import android.os.ShellCommand;
import android.os.ShellCommand;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings;
@@ -256,6 +258,44 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private static final String ACTION_SHOW_INPUT_METHOD_PICKER =
    private static final String ACTION_SHOW_INPUT_METHOD_PICKER =
            "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER";
            "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER";


    /**
     * Debug flag for overriding runtime {@link SystemProperties}.
     */
    @AnyThread
    private static final class DebugFlag {
        private static final Object LOCK = new Object();
        private final String mKey;
        @GuardedBy("LOCK")
        private boolean mValue;

        public DebugFlag(String key) {
            mKey = key;
            refresh();
        }

        void refresh() {
            synchronized (LOCK) {
                mValue = SystemProperties.getBoolean(mKey, true);
            }
        }

        boolean value() {
            synchronized (LOCK) {
                return mValue;
            }
        }
    }

    /**
     * Debug flags that can be overridden using "adb shell setprop <key>"
     * Note: These flags are cached. To refresh, run "adb shell ime refresh_debug_properties".
     */
    private static final class DebugFlags {
        static final DebugFlag FLAG_OPTIMIZE_START_INPUT =
                new DebugFlag("debug.optimize_startinput");
    }


    final Context mContext;
    final Context mContext;
    final Resources mRes;
    final Resources mRes;
    final Handler mHandler;
    final Handler mHandler;
@@ -2930,10 +2970,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                }
                }


                if (!didStart && attribute != null) {
                if (!didStart && attribute != null) {
                    if (!DebugFlags.FLAG_OPTIMIZE_START_INPUT.value()
                            || (controlFlags
                                    & InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0) {
                        res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute,
                        res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute,
                                controlFlags, startInputReason);
                                controlFlags, startInputReason);
                    }
                    }
                }
                }
            }
        } finally {
        } finally {
            Binder.restoreCallingIdentity(ident);
            Binder.restoreCallingIdentity(ident);
        }
        }
@@ -4703,6 +4747,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        return mService.handleShellCommandSetInputMethod(this);
                        return mService.handleShellCommandSetInputMethod(this);
                    case "reset":
                    case "reset":
                        return mService.handleShellCommandResetInputMethod(this);
                        return mService.handleShellCommandResetInputMethod(this);
                    case "refresh_debug_properties":
                        return refreshDebugProperties();
                    default:
                    default:
                        getOutPrintWriter().println("Unknown command: " + imeCommand);
                        getOutPrintWriter().println("Unknown command: " + imeCommand);
                        return ShellCommandResult.FAILURE;
                        return ShellCommandResult.FAILURE;
@@ -4712,6 +4758,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            return handleDefaultCommands(cmd);
            return handleDefaultCommands(cmd);
        }
        }


        @BinderThread
        @ShellCommandResult
        private int refreshDebugProperties() {
            DebugFlags.FLAG_OPTIMIZE_START_INPUT.refresh();
            return ShellCommandResult.SUCCESS;
        }

        @BinderThread
        @BinderThread
        @Override
        @Override
        public void onHelp() {
        public void onHelp() {