summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Oliver Woodman <olly@google.com> 2022-05-03 19:51:23 +0000
committer Oliver Woodman <olly@google.com> 2022-05-03 19:53:06 +0000
commitd2f1fc4cc17af12938cf33106bc90064d7444633 (patch)
tree236055189bc10bdeab1cef8bc22f0bf783bfeed6
parentf786af32fac456c658232a0d467f864ff94cf137 (diff)
Improve RemoteDisplayProvider documentation and exceptions
Bug: b/211549545 Change-Id: I37866b30879fe9e43f3213c1f2eb25c817f11f03 Tested: Trivial refactor
-rw-r--r--media/lib/remotedisplay/java/com/android/media/remotedisplay/RemoteDisplayProvider.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/media/lib/remotedisplay/java/com/android/media/remotedisplay/RemoteDisplayProvider.java b/media/lib/remotedisplay/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
index 5005c46c47a8..2cba03bc5c57 100644
--- a/media/lib/remotedisplay/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
+++ b/media/lib/remotedisplay/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
@@ -238,13 +238,18 @@ public abstract class RemoteDisplayProvider {
* Adds the specified remote display and notifies the system.
*
* @param display The remote display that was added.
- * @throws IllegalStateException if there is already a display with the same id.
+ * @throws IllegalStateException if the argument is null, or if there is already a display with
+ * the same id.
*/
public void addDisplay(RemoteDisplay display) {
- if (display == null || mDisplays.containsKey(display.getId())) {
- throw new IllegalArgumentException("display");
+ if (display == null) {
+ throw new IllegalArgumentException("display cannot be null");
}
- mDisplays.put(display.getId(), display);
+ String displayId = display.getId();
+ if (mDisplays.containsKey(displayId)) {
+ throw new IllegalArgumentException("display already exists with id: " + displayId);
+ }
+ mDisplays.put(displayId, display);
publishState();
}
@@ -252,11 +257,16 @@ public abstract class RemoteDisplayProvider {
* Updates information about the specified remote display and notifies the system.
*
* @param display The remote display that was added.
- * @throws IllegalStateException if the display was n
+ * @throws IllegalStateException if the argument is null, or if the provider is not aware of the
+ * display.
*/
public void updateDisplay(RemoteDisplay display) {
- if (display == null || mDisplays.get(display.getId()) != display) {
- throw new IllegalArgumentException("display");
+ if (display == null) {
+ throw new IllegalArgumentException("display cannot be null");
+ }
+ String displayId = display.getId();
+ if (mDisplays.get(displayId) != display) {
+ throw new IllegalArgumentException("unexpected display with id: " + displayId);
}
publishState();
}
@@ -265,12 +275,18 @@ public abstract class RemoteDisplayProvider {
* Removes the specified remote display and tells the system about it.
*
* @param display The remote display that was removed.
+ * @throws IllegalStateException if the argument is null, or if the provider is not aware of the
+ * display.
*/
public void removeDisplay(RemoteDisplay display) {
- if (display == null || mDisplays.get(display.getId()) != display) {
- throw new IllegalArgumentException("display");
+ if (display == null) {
+ throw new IllegalArgumentException("display cannot be null");
+ }
+ String displayId = display.getId();
+ if (mDisplays.get(displayId) != display) {
+ throw new IllegalArgumentException("unexpected display with id: " + displayId);
}
- mDisplays.remove(display.getId());
+ mDisplays.remove(displayId);
publishState();
}