diff options
3 files changed, 65 insertions, 11 deletions
diff --git a/core/java/android/hardware/input/input_framework.aconfig b/core/java/android/hardware/input/input_framework.aconfig index a3aaca5132da..0c89059a475a 100644 --- a/core/java/android/hardware/input/input_framework.aconfig +++ b/core/java/android/hardware/input/input_framework.aconfig @@ -88,6 +88,17 @@ flag { } flag { + name: "input_manager_lifecycle_support" + namespace: "input" + description: "Add support for Lifecycle support in input manager" + bug: "362473586" + is_fixed_read_only: true + metadata { + purpose: PURPOSE_BUGFIX + } +} + +flag { namespace: "input_native" name: "manage_key_gestures" description: "Manage key gestures through Input APIs" diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index e5b077d23bec..dcc95e2e39e3 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -19,6 +19,7 @@ package com.android.server.input; import static android.Manifest.permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW; import static android.content.PermissionChecker.PERMISSION_GRANTED; import static android.content.PermissionChecker.PID_UNKNOWN; +import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.provider.DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT; import static android.view.KeyEvent.KEYCODE_UNKNOWN; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; @@ -136,6 +137,7 @@ import com.android.internal.util.DumpUtils; import com.android.internal.util.Preconditions; import com.android.server.DisplayThread; import com.android.server.LocalServices; +import com.android.server.SystemService; import com.android.server.Watchdog; import com.android.server.input.InputManagerInternal.LidSwitchCallback; import com.android.server.input.debug.FocusEventDebugView; @@ -3396,6 +3398,37 @@ public class InputManagerService extends IInputManager.Stub } } + /** + * {@link SystemService} used to publish and manage the lifecycle of {@link InputManagerService} + */ + public static final class Lifecycle extends SystemService { + + private final InputManagerService mService; + + public Lifecycle(@NonNull Context context) { + super(context); + mService = new InputManagerService(context); + } + + @Override + public void onStart() { + publishBinderService(Context.INPUT_SERVICE, mService, + /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL); + } + + @Override + public void onBootPhase(int phase) { + // Called on ActivityManager thread. + if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { + mService.systemRunning(); + } + } + + public InputManagerService getService() { + return mService; + } + } + private final class LocalService extends InputManagerInternal { @Override public void setDisplayViewports(List<DisplayViewport> viewports) { diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 980fcac051cb..82d49fcac305 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -27,6 +27,7 @@ import static android.system.OsConstants.O_CLOEXEC; import static android.system.OsConstants.O_RDONLY; import static android.view.Display.DEFAULT_DISPLAY; +import static com.android.hardware.input.Flags.inputManagerLifecycleSupport; import static com.android.server.utils.TimingsTraceAndSlog.SYSTEM_SERVER_TIMING_TAG; import static com.android.tradeinmode.flags.Flags.enableTradeInMode; @@ -1654,7 +1655,12 @@ public final class SystemServer implements Dumpable { t.traceEnd(); t.traceBegin("StartInputManagerService"); - inputManager = new InputManagerService(context); + if (inputManagerLifecycleSupport()) { + inputManager = mSystemServiceManager.startService( + InputManagerService.Lifecycle.class).getService(); + } else { + inputManager = new InputManagerService(context); + } t.traceEnd(); t.traceBegin("DeviceStateManagerService"); @@ -1675,8 +1681,10 @@ public final class SystemServer implements Dumpable { ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PROTO); - ServiceManager.addService(Context.INPUT_SERVICE, inputManager, - /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL); + if (!inputManagerLifecycleSupport()) { + ServiceManager.addService(Context.INPUT_SERVICE, inputManager, + /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL); + } t.traceEnd(); t.traceBegin("SetWindowManagerService"); @@ -3350,16 +3358,18 @@ public final class SystemServer implements Dumpable { reportWtf("Notifying NetworkTimeService running", e); } t.traceEnd(); - t.traceBegin("MakeInputManagerServiceReady"); - try { - // TODO(BT) Pass parameter to input manager - if (inputManagerF != null) { - inputManagerF.systemRunning(); + if (!inputManagerLifecycleSupport()) { + t.traceBegin("MakeInputManagerServiceReady"); + try { + // TODO(BT) Pass parameter to input manager + if (inputManagerF != null) { + inputManagerF.systemRunning(); + } + } catch (Throwable e) { + reportWtf("Notifying InputManagerService running", e); } - } catch (Throwable e) { - reportWtf("Notifying InputManagerService running", e); + t.traceEnd(); } - t.traceEnd(); t.traceBegin("MakeTelephonyRegistryReady"); try { if (telephonyRegistryF != null) { |