Merge "Added error for set zone for uid API" into rvc-qpr-dev
diff --git a/service/src/com/android/car/audio/CarAudioService.java b/service/src/com/android/car/audio/CarAudioService.java
index db081eb..bc67085 100644
--- a/service/src/com/android/car/audio/CarAudioService.java
+++ b/service/src/com/android/car/audio/CarAudioService.java
@@ -892,6 +892,10 @@
*
* @param zoneId The audio zone id
* @param uid The uid to map
+ *
+ * <p><b>Note:</b> Will throw if occupant zone mapping exist, as uid and occupant zone mapping
+ * do not work in conjunction.
+ *
* @return true if the device affinities, for devices in zone, are successfully set
*/
@Override
@@ -905,6 +909,9 @@
+ uid + " mapped to : "
+ zoneId);
+ // If occupant mapping exist uid routing can not be used
+ requiredOccupantZoneMappingDisabledLocked();
+
// Figure out if anything is currently holding focus,
// This will change the focus to transient loss while we are switching zones
Integer currentZoneId = mUidToZoneMap.get(uid);
@@ -985,6 +992,10 @@
/**
* Removes the current mapping of the uid, focus will be lost in zone
* @param uid The uid to remove
+ *
+ * <p><b>Note:</b> Will throw if occupant zone mapping exist, as uid and occupant zone mapping
+ * do not work in conjunction.
+ *
* return true if all the devices affinities currently
* mapped to uid are successfully removed
*/
@@ -993,6 +1004,10 @@
enforcePermission(Car.PERMISSION_CAR_CONTROL_AUDIO_SETTINGS);
requireDynamicRouting();
synchronized (mImplLock) {
+ // Throw so as to not set the wrong expectation,
+ // that routing will be changed if clearZoneIdForUid is called.
+ requiredOccupantZoneMappingDisabledLocked();
+
return checkAndRemoveUidLocked(uid);
}
}
@@ -1083,6 +1098,13 @@
Preconditions.checkState(mUseDynamicRouting, "Dynamic routing is required");
}
+ private void requiredOccupantZoneMappingDisabledLocked() {
+ if (isOccupantZoneMappingAvailableLocked()) {
+ throw new IllegalStateException(
+ "UID based routing is not supported while using occupant zone mapping");
+ }
+ }
+
/**
* @return {@link AudioDevicePort} that handles the given car audio usage.
* Multiple usages may share one {@link AudioDevicePort}
@@ -1123,7 +1145,7 @@
private void handleOccupantZoneUserChanged() {
int driverUserId = mOccupantZoneService.getDriverUserId();
synchronized (mImplLock) {
- if (!isOccupantZoneMappingAvailable()) {
+ if (!isOccupantZoneMappingAvailableLocked()) {
//No occupant zone to audio zone mapping, re-adjust to settings driver.
for (int index = 0; index < mCarAudioZones.length; index++) {
CarAudioZone zone = mCarAudioZones[index];
@@ -1142,7 +1164,7 @@
}
}
- private boolean isOccupantZoneMappingAvailable() {
+ private boolean isOccupantZoneMappingAvailableLocked() {
return mAudioZoneIdToOccupantZoneIdMapping.size() > 0;
}