Merge "Rename LightsManager.setLights to requestLights" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-11 09:06:01 +00:00
committed by Android (Google) Code Review
6 changed files with 41 additions and 21 deletions

View File

@@ -2939,7 +2939,7 @@ package android.hardware.lights {
public final class LightsManager.LightsSession implements java.lang.AutoCloseable {
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void close();
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void setLights(@NonNull android.hardware.lights.LightsRequest);
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void requestLights(@NonNull android.hardware.lights.LightsRequest);
}
public final class LightsRequest {

View File

@@ -1279,7 +1279,7 @@ package android.hardware.lights {
public final class LightsManager.LightsSession implements java.lang.AutoCloseable {
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void close();
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void setLights(@NonNull android.hardware.lights.LightsRequest);
method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_LIGHTS) public void requestLights(@NonNull android.hardware.lights.LightsRequest);
}
public final class LightsRequest {

View File

@@ -37,7 +37,8 @@ public final class Light implements Parcelable {
/**
* Creates a new light with the given data.
*
* @hide */
* @hide
*/
public Light(int id, int ordinal, int type) {
mId = id;
mOrdinal = ordinal;
@@ -76,8 +77,24 @@ public final class Light implements Parcelable {
}
};
@Override
public boolean equals(Object obj) {
if (obj instanceof Light) {
Light light = (Light) obj;
return mId == light.mId && mOrdinal == light.mOrdinal && mType == light.mType;
}
return false;
}
@Override
public int hashCode() {
return mId;
}
/**
* Returns the id of the light.
*
* <p>This is an opaque value used as a unique identifier for the light.
*/
public int getId() {
return mId;
@@ -86,11 +103,9 @@ public final class Light implements Parcelable {
/**
* Returns the ordinal of the light.
*
* <p>This represents the physical order of the lights on the device. The exact values are
* device-dependent, but for example, if there are lights in a row, sorting the Light objects
* by ordinal should match the order in which they appear on the device. If the device has
* 4 lights, the ordinals could be [1, 2, 3, 4] or [0, 10, 20, 30] or any other values that
* have the same sort order.
* <p>This is a sort key that represents the physical order of lights on the device with the
* same type. In the case of multiple lights arranged in a line, for example, the ordinals
* could be [1, 2, 3, 4], or [0, 10, 20, 30], or any other values that have the same sort order.
*/
public int getOrdinal() {
return mOrdinal;

View File

@@ -161,7 +161,7 @@ public final class LightsManager {
* @param request the settings for lights that should change
*/
@RequiresPermission(Manifest.permission.CONTROL_DEVICE_LIGHTS)
public void setLights(@NonNull LightsRequest request) {
public void requestLights(@NonNull LightsRequest request) {
Preconditions.checkNotNull(request);
if (!mClosed) {
try {

View File

@@ -86,7 +86,7 @@ public final class LightsRequest {
* Create a LightsRequest object used to override lights on the device.
*
* <p>The generated {@link LightsRequest} should be used in
* {@link LightsManager.Session#setLights(LightsLightsRequest).
* {@link LightsManager.Session#requestLights(LightsLightsRequest).
*/
public @NonNull LightsRequest build() {
return new LightsRequest(mChanges);

View File

@@ -18,6 +18,11 @@ package com.android.server.lights;
import static android.hardware.lights.LightsRequest.Builder;
import static android.graphics.Color.BLACK;
import static android.graphics.Color.BLUE;
import static android.graphics.Color.GREEN;
import static android.graphics.Color.WHITE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
@@ -92,7 +97,7 @@ public class LightsServiceTest {
// When the session requests to turn 3/4 lights on:
LightsManager.LightsSession session = manager.openSession();
session.setLights(new Builder()
session.requestLights(new Builder()
.setLight(manager.getLights().get(0), new LightState(0xf1))
.setLight(manager.getLights().get(1), new LightState(0xf2))
.setLight(manager.getLights().get(2), new LightState(0xf3))
@@ -114,18 +119,18 @@ public class LightsServiceTest {
Light micLight = manager.getLights().get(0);
// The light should begin by being off.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0x00000000);
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(BLACK);
// When a session commits changes:
LightsManager.LightsSession session = manager.openSession();
session.setLights(new Builder().setLight(micLight, new LightState(0xff00ff00)).build());
session.requestLights(new Builder().setLight(micLight, new LightState(GREEN)).build());
// Then the light should turn on.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0xff00ff00);
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(GREEN);
// When the session goes away:
session.close();
// Then the light should turn off.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0x00000000);
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(BLACK);
}
@Test
@@ -138,15 +143,15 @@ public class LightsServiceTest {
LightsManager.LightsSession session2 = manager.openSession();
// When session1 and session2 both request the same light:
session1.setLights(new Builder().setLight(micLight, new LightState(0xff0000ff)).build());
session2.setLights(new Builder().setLight(micLight, new LightState(0xffffffff)).build());
session1.requestLights(new Builder().setLight(micLight, new LightState(BLUE)).build());
session2.requestLights(new Builder().setLight(micLight, new LightState(WHITE)).build());
// Then session1 should win because it was created first.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0xff0000ff);
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(BLUE);
// When session1 goes away:
session1.close();
// Then session2 should have its request go into effect.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0xffffffff);
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(WHITE);
// When session2 goes away:
session2.close();
@@ -162,10 +167,10 @@ public class LightsServiceTest {
// When the session turns a light on:
LightsManager.LightsSession session = manager.openSession();
session.setLights(new Builder().setLight(micLight, new LightState(0xffffffff)).build());
session.requestLights(new Builder().setLight(micLight, new LightState(WHITE)).build());
// And then the session clears it again:
session.setLights(new Builder().clearLight(micLight).build());
session.requestLights(new Builder().clearLight(micLight).build());
// Then the light should turn back off.
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0);