Merge "Rename LightsManager.setLights to requestLights" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a9caa7d016
@@ -2939,7 +2939,7 @@ package android.hardware.lights {
|
|||||||
|
|
||||||
public final class LightsManager.LightsSession implements java.lang.AutoCloseable {
|
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 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 {
|
public final class LightsRequest {
|
||||||
|
|||||||
@@ -1279,7 +1279,7 @@ package android.hardware.lights {
|
|||||||
|
|
||||||
public final class LightsManager.LightsSession implements java.lang.AutoCloseable {
|
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 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 {
|
public final class LightsRequest {
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public final class Light implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Creates a new light with the given data.
|
* Creates a new light with the given data.
|
||||||
*
|
*
|
||||||
* @hide */
|
* @hide
|
||||||
|
*/
|
||||||
public Light(int id, int ordinal, int type) {
|
public Light(int id, int ordinal, int type) {
|
||||||
mId = id;
|
mId = id;
|
||||||
mOrdinal = ordinal;
|
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.
|
* Returns the id of the light.
|
||||||
|
*
|
||||||
|
* <p>This is an opaque value used as a unique identifier for the light.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return mId;
|
return mId;
|
||||||
@@ -86,11 +103,9 @@ public final class Light implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the ordinal of the light.
|
* Returns the ordinal of the light.
|
||||||
*
|
*
|
||||||
* <p>This represents the physical order of the lights on the device. The exact values are
|
* <p>This is a sort key that represents the physical order of lights on the device with the
|
||||||
* device-dependent, but for example, if there are lights in a row, sorting the Light objects
|
* same type. In the case of multiple lights arranged in a line, for example, the ordinals
|
||||||
* by ordinal should match the order in which they appear on the device. If the device has
|
* could be [1, 2, 3, 4], or [0, 10, 20, 30], or any other values that have the same sort order.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
public int getOrdinal() {
|
public int getOrdinal() {
|
||||||
return mOrdinal;
|
return mOrdinal;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public final class LightsManager {
|
|||||||
* @param request the settings for lights that should change
|
* @param request the settings for lights that should change
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.CONTROL_DEVICE_LIGHTS)
|
@RequiresPermission(Manifest.permission.CONTROL_DEVICE_LIGHTS)
|
||||||
public void setLights(@NonNull LightsRequest request) {
|
public void requestLights(@NonNull LightsRequest request) {
|
||||||
Preconditions.checkNotNull(request);
|
Preconditions.checkNotNull(request);
|
||||||
if (!mClosed) {
|
if (!mClosed) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public final class LightsRequest {
|
|||||||
* Create a LightsRequest object used to override lights on the device.
|
* Create a LightsRequest object used to override lights on the device.
|
||||||
*
|
*
|
||||||
* <p>The generated {@link LightsRequest} should be used in
|
* <p>The generated {@link LightsRequest} should be used in
|
||||||
* {@link LightsManager.Session#setLights(LightsLightsRequest).
|
* {@link LightsManager.Session#requestLights(LightsLightsRequest).
|
||||||
*/
|
*/
|
||||||
public @NonNull LightsRequest build() {
|
public @NonNull LightsRequest build() {
|
||||||
return new LightsRequest(mChanges);
|
return new LightsRequest(mChanges);
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ package com.android.server.lights;
|
|||||||
|
|
||||||
import static android.hardware.lights.LightsRequest.Builder;
|
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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -92,7 +97,7 @@ public class LightsServiceTest {
|
|||||||
|
|
||||||
// When the session requests to turn 3/4 lights on:
|
// When the session requests to turn 3/4 lights on:
|
||||||
LightsManager.LightsSession session = manager.openSession();
|
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(0), new LightState(0xf1))
|
||||||
.setLight(manager.getLights().get(1), new LightState(0xf2))
|
.setLight(manager.getLights().get(1), new LightState(0xf2))
|
||||||
.setLight(manager.getLights().get(2), new LightState(0xf3))
|
.setLight(manager.getLights().get(2), new LightState(0xf3))
|
||||||
@@ -114,18 +119,18 @@ public class LightsServiceTest {
|
|||||||
Light micLight = manager.getLights().get(0);
|
Light micLight = manager.getLights().get(0);
|
||||||
|
|
||||||
// The light should begin by being off.
|
// 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:
|
// When a session commits changes:
|
||||||
LightsManager.LightsSession session = manager.openSession();
|
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.
|
// 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:
|
// When the session goes away:
|
||||||
session.close();
|
session.close();
|
||||||
// Then the light should turn off.
|
// Then the light should turn off.
|
||||||
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0x00000000);
|
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,15 +143,15 @@ public class LightsServiceTest {
|
|||||||
LightsManager.LightsSession session2 = manager.openSession();
|
LightsManager.LightsSession session2 = manager.openSession();
|
||||||
|
|
||||||
// When session1 and session2 both request the same light:
|
// When session1 and session2 both request the same light:
|
||||||
session1.setLights(new Builder().setLight(micLight, new LightState(0xff0000ff)).build());
|
session1.requestLights(new Builder().setLight(micLight, new LightState(BLUE)).build());
|
||||||
session2.setLights(new Builder().setLight(micLight, new LightState(0xffffffff)).build());
|
session2.requestLights(new Builder().setLight(micLight, new LightState(WHITE)).build());
|
||||||
// Then session1 should win because it was created first.
|
// 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:
|
// When session1 goes away:
|
||||||
session1.close();
|
session1.close();
|
||||||
// Then session2 should have its request go into effect.
|
// 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:
|
// When session2 goes away:
|
||||||
session2.close();
|
session2.close();
|
||||||
@@ -162,10 +167,10 @@ public class LightsServiceTest {
|
|||||||
|
|
||||||
// When the session turns a light on:
|
// When the session turns a light on:
|
||||||
LightsManager.LightsSession session = manager.openSession();
|
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:
|
// 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.
|
// Then the light should turn back off.
|
||||||
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0);
|
assertThat(manager.getLightState(micLight).getColor()).isEqualTo(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user