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

Commit 275f9e29 authored by Philip Junker's avatar Philip Junker
Browse files

Add TestApi to suppress other LightsSession clients

Add TestApi LightsManager#openSession(int priority) to allow sorting of
sessions by descending priority. Assuming priority 0 for public API
LightsManager#openSession().

Bug: 185877106
Test: atest LightsManagerTest
Change-Id: I4a2d9f8982119b47cbcbf77ff43377fecb343112
parent 6ba89099
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1232,6 +1232,14 @@ package android.hardware.input {

}

package android.hardware.lights {

  public abstract class LightsManager {
    method @NonNull public abstract android.hardware.lights.LightsManager.LightsSession openSession(int);
  }

}

package android.hardware.soundtrigger {

  public class KeyphraseEnrollmentInfo {
+5 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ class InputDeviceLightsManager extends LightsManager {
        return session;
    }

    @Override
    public @NonNull LightsSession openSession(int priority) {
        throw new UnsupportedOperationException();
    }

    /**
     * Encapsulates a session that can be used to control device lights and represents the lifetime
     * of the requests.
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.hardware.lights.LightState;
interface ILightsManager {
  List<Light> getLights();
  LightState getLightState(int lightId);
  void openSession(in IBinder sessionToken);
  void openSession(in IBinder sessionToken, in int priority);
  void closeSession(in IBinder sessionToken);
  void setLightStates(in IBinder sessionToken, in int[] lightIds, in LightState[] states);
}
+14 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -83,12 +84,25 @@ public abstract class LightsManager {
     */
    public abstract @NonNull LightsSession openSession();

    /**
     *
     * Creates a new {@link LightsSession}
     *
     * @param priority the larger this number, the higher the priority of this session when multiple
     *                 light state requests arrive simultaneously.
     *
     * @hide
     */
    @TestApi
    public abstract @NonNull LightsSession openSession(int priority);

    /**
     * Encapsulates a session that can be used to control device lights and represents the lifetime
     * of the requests.
     */
    public abstract static class LightsSession implements AutoCloseable {
        private final IBinder mToken = new Binder();

        /**
         * Sends a request to modify the states of multiple lights.
         *
+22 −1
Original line number Diff line number Diff line
@@ -102,7 +102,28 @@ public final class SystemLightsManager extends LightsManager {
    public @NonNull LightsSession openSession() {
        try {
            final LightsSession session = new SystemLightsSession();
            mService.openSession(session.getToken());
            mService.openSession(session.getToken(), 0);
            return session;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     *
     * Creates a new {@link LightsSession}
     *
     * @param priority the larger this number, the higher the priority of this session when multiple
     *                 light state requests arrive simultaneously.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.CONTROL_DEVICE_LIGHTS)
    @Override
    public @NonNull LightsSession openSession(int priority) {
        try {
            final LightsSession session = new SystemLightsSession();
            mService.openSession(session.getToken(), priority);
            return session;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
Loading