From 4799aea23d3fb7f9d18926b67b889385ffdf8689 Mon Sep 17 00:00:00 2001 From: Asmita Poddar Date: Wed, 22 Mar 2023 15:32:36 +0000 Subject: [PATCH] Remove Context from LightsManager constructor Remove context from LightsManager as well as from its derived class: InputDeviceLightsManager. There aren't any usages of mContext in these classes. Hence, InputDeviceLightsManager can be called from InputManagerGlobal without any requirement of context to be passed. The Managers can also be removed from the InputManager class. Bug: b/267758905 Test: Pre-submit Change-Id: Ie89f5b47339d079216f93714718061efb478503a --- .../input/InputDeviceLightsManager.java | 4 +- .../android/hardware/input/InputManager.java | 44 ------------------- .../hardware/input/InputManagerGlobal.java | 15 +++++-- .../hardware/lights/LightsManager.java | 7 +-- .../hardware/lights/SystemLightsManager.java | 1 - core/java/android/view/InputDevice.java | 4 +- 6 files changed, 16 insertions(+), 59 deletions(-) diff --git a/core/java/android/hardware/input/InputDeviceLightsManager.java b/core/java/android/hardware/input/InputDeviceLightsManager.java index f4ee9a21c42cb..e2568e3ee72d1 100644 --- a/core/java/android/hardware/input/InputDeviceLightsManager.java +++ b/core/java/android/hardware/input/InputDeviceLightsManager.java @@ -18,7 +18,6 @@ package android.hardware.input; import android.annotation.NonNull; import android.app.ActivityThread; -import android.content.Context; import android.hardware.lights.Light; import android.hardware.lights.LightState; import android.hardware.lights.LightsManager; @@ -44,8 +43,7 @@ class InputDeviceLightsManager extends LightsManager { // Package name private final String mPackageName; - InputDeviceLightsManager(Context context, int deviceId) { - super(context); + InputDeviceLightsManager(int deviceId) { mGlobal = InputManagerGlobal.getInstance(); mDeviceId = deviceId; mPackageName = ActivityThread.currentPackageName(); diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 8a4a0e40d54a2..e7385b62faa65 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -32,8 +32,6 @@ import android.compat.annotation.ChangeId; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.hardware.BatteryState; -import android.hardware.SensorManager; -import android.hardware.lights.LightsManager; import android.os.Build; import android.os.Handler; import android.os.IBinder; @@ -41,7 +39,6 @@ import android.os.InputEventInjectionSync; import android.os.RemoteException; import android.os.SystemClock; import android.os.Vibrator; -import android.os.VibratorManager; import android.util.Log; import android.view.Display; import android.view.InputDevice; @@ -1310,47 +1307,6 @@ public final class InputManager { return new InputDeviceVibrator(deviceId, vibratorId); } - /** - * Gets a vibrator manager service associated with an input device, always creates a new - * instance. - * @return The vibrator manager, never null. - * @hide - */ - @NonNull - public VibratorManager getInputDeviceVibratorManager(int deviceId) { - return new InputDeviceVibratorManager(deviceId); - } - - /** - * Gets a sensor manager service associated with an input device, always creates a new instance. - * @return The sensor manager, never null. - * @hide - */ - @NonNull - public SensorManager getInputDeviceSensorManager(int deviceId) { - return mGlobal.getInputDeviceSensorManager(deviceId); - } - - /** - * Gets a battery state object associated with an input device, assuming it has one. - * @return The battery, never null. - * @hide - */ - @NonNull - public BatteryState getInputDeviceBatteryState(int deviceId, boolean hasBattery) { - return mGlobal.getInputDeviceBatteryState(deviceId, hasBattery); - } - - /** - * Gets a lights manager associated with an input device, always creates a new instance. - * @return The lights manager, never null. - * @hide - */ - @NonNull - public LightsManager getInputDeviceLightsManager(int deviceId) { - return new InputDeviceLightsManager(getContext(), deviceId); - } - /** * Cancel all ongoing pointer gestures on all displays. * @hide diff --git a/core/java/android/hardware/input/InputManagerGlobal.java b/core/java/android/hardware/input/InputManagerGlobal.java index 31ce7d985b150..701980d5f6f30 100644 --- a/core/java/android/hardware/input/InputManagerGlobal.java +++ b/core/java/android/hardware/input/InputManagerGlobal.java @@ -29,6 +29,7 @@ import android.hardware.input.InputManager.KeyboardBacklightListener; import android.hardware.input.InputManager.OnTabletModeChangedListener; import android.hardware.lights.Light; import android.hardware.lights.LightState; +import android.hardware.lights.LightsManager; import android.hardware.lights.LightsRequest; import android.os.Binder; import android.os.CombinedVibration; @@ -876,7 +877,7 @@ public final class InputManagerGlobal { } /** - * @see InputManager#getInputDeviceSensorManager(int) + * @see InputDevice#getSensorManager() */ @NonNull public SensorManager getInputDeviceSensorManager(int deviceId) { @@ -954,6 +955,14 @@ public final class InputManagerGlobal { } } + /** + * @see InputDevice#getLightsManager() + */ + @NonNull + public LightsManager getInputDeviceLightsManager(int deviceId) { + return new InputDeviceLightsManager(deviceId); + } + /** * Gets a list of light objects associated with an input device. * @return The list of lights, never null. @@ -1032,7 +1041,7 @@ public final class InputManagerGlobal { } /** - * @see InputManager#getInputDeviceVibratorManager(int) + * @see InputDevice#getVibratorManager() */ @NonNull public VibratorManager getInputDeviceVibratorManager(int deviceId) { @@ -1138,7 +1147,7 @@ public final class InputManagerGlobal { } /** - * @see InputManager#getKeyCodeforKeyLocation(int, int) + * @see InputManager#getKeyCodeForKeyLocation(int, int) */ public int getKeyCodeForKeyLocation(int deviceId, int locationKeyCode) { try { diff --git a/core/java/android/hardware/lights/LightsManager.java b/core/java/android/hardware/lights/LightsManager.java index 2d9bc0eb14ab8..b71b7e05667bf 100644 --- a/core/java/android/hardware/lights/LightsManager.java +++ b/core/java/android/hardware/lights/LightsManager.java @@ -25,8 +25,6 @@ import android.content.Context; import android.os.Binder; import android.os.IBinder; -import com.android.internal.util.Preconditions; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; @@ -39,7 +37,6 @@ import java.util.List; public abstract class LightsManager { private static final String TAG = "LightsManager"; - @NonNull private final Context mContext; // These enum values copy the values from {@link com.android.server.lights.LightsManager} // and the light HAL. Since 0-7 are lights reserved for system use, only the microphone light // and following types are available through this API. @@ -62,9 +59,7 @@ public abstract class LightsManager { /** * @hide to prevent subclassing from outside of the framework */ - public LightsManager(Context context) { - mContext = Preconditions.checkNotNull(context); - } + public LightsManager() {} /** * Returns the lights available on the device. diff --git a/core/java/android/hardware/lights/SystemLightsManager.java b/core/java/android/hardware/lights/SystemLightsManager.java index 055a7f43f9ed4..3beb4ba48e167 100644 --- a/core/java/android/hardware/lights/SystemLightsManager.java +++ b/core/java/android/hardware/lights/SystemLightsManager.java @@ -59,7 +59,6 @@ public final class SystemLightsManager extends LightsManager { */ @VisibleForTesting public SystemLightsManager(@NonNull Context context, @NonNull ILightsManager service) { - super(context); mService = Preconditions.checkNotNull(service); } diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index e81aecb23c24b..48fb719279d5f 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -28,7 +28,6 @@ import android.hardware.BatteryState; import android.hardware.SensorManager; import android.hardware.input.HostUsiVersion; import android.hardware.input.InputDeviceIdentifier; -import android.hardware.input.InputManager; import android.hardware.input.InputManagerGlobal; import android.hardware.lights.LightsManager; import android.icu.util.ULocale; @@ -1191,7 +1190,8 @@ public final class InputDevice implements Parcelable { public LightsManager getLightsManager() { synchronized (mMotionRanges) { if (mLightsManager == null) { - mLightsManager = InputManager.getInstance().getInputDeviceLightsManager(mId); + mLightsManager = InputManagerGlobal.getInstance() + .getInputDeviceLightsManager(mId); } } return mLightsManager;