more volume support

- add master volume only case:
  some H/W can have only single master volume.
  In that case, all volume change will be sent to stream 0.
  TODO: do better handling of master volule only case

- add no_auto_get in vns_policy.xml so that subscription does not
  lead into auto get for some properties

bug: 28175862

Change-Id: I0aa7a8a54385704620c28aaa0f21898bdc1e8164
diff --git a/service/src/com/android/car/CarVolumeControllerFactory.java b/service/src/com/android/car/CarVolumeControllerFactory.java
index b126f0c..f75731d 100644
--- a/service/src/com/android/car/CarVolumeControllerFactory.java
+++ b/service/src/com/android/car/CarVolumeControllerFactory.java
@@ -200,6 +200,7 @@
         private int mSupportedAudioContext;
 
         private boolean mHasExternalMemory;
+        private boolean mMasterVolumeOnly;
 
         @GuardedBy("this")
         private int mCurrentContext = CarVolumeService.DEFAULT_CAR_AUDIO_CONTEXT;
@@ -266,6 +267,11 @@
                     case MSG_UPDATE_HAL:
                         stream = msg.arg1;
                         volume = msg.arg2;
+                        synchronized (CarExternalVolumeController.this) {
+                            if (mMasterVolumeOnly) {
+                                stream = 0;
+                            }
+                        }
                         mHal.setStreamVolume(stream, volume);
                         break;
                     default:
@@ -287,6 +293,7 @@
         void init() {
             mSupportedAudioContext = mHal.getSupportedAudioVolumeContexts();
             mHasExternalMemory = mHal.isExternalAudioVolumePersistent();
+            mMasterVolumeOnly = mHal.isAudioVolumeMasterOnly();
             synchronized (this) {
                 initVolumeLimitLocked();
                 initCurrentVolumeLocked();
@@ -328,7 +335,8 @@
                     int carStream = carContextToCarStream(i);
                     Integer volume = volumesPerCarStream.get(carStream);
                     if (volume == null) {
-                        volume = Integer.valueOf(mHal.getStreamVolume(carStream));
+                        volume = Integer.valueOf(mHal.getStreamVolume(mMasterVolumeOnly ? 0 :
+                            carStream));
                         volumesPerCarStream.put(carStream, volume);
                     }
                     mCurrentCarContextVolume.put(i, volume);
@@ -422,11 +430,14 @@
             synchronized (this) {
                 if (DBG) {
                     Log.d(TAG, "onVolumeChange carStream:" + carStream + " volume: " + volume
-                            + "volumeState: " + volumeState);
+                            + " volumeState: " + volumeState);
                 }
                 // Assume single channel here.
                 int currentLogicalStream = VolumeUtils.carContextToAndroidStream(mCurrentContext);
                 int currentCarStream = carContextToCarStream(mCurrentContext);
+                if (mMasterVolumeOnly) { //for master volume only H/W, always assume current stream
+                    carStream = currentCarStream;
+                }
                 if (currentCarStream == carStream) {
                     mCurrentCarContextVolume.put(mCurrentContext, volume);
                     mHandler.sendMessage(
@@ -537,7 +548,7 @@
                 // Otherwise, we need to tell Hal what the correct volume is for the new context.
                 int currentVolume = mCurrentCarContextVolume.get(primaryFocusContext);
 
-                int carStreamNumber = mSupportedAudioContext == 0 ? primaryFocusPhysicalStream :
+                int carStreamNumber = (mSupportedAudioContext == 0) ? primaryFocusPhysicalStream :
                         primaryFocusContext;
                 if (DBG) {
                     Log.d(TAG, "Change volume from: "
diff --git a/service/src/com/android/car/hal/AudioHalService.java b/service/src/com/android/car/hal/AudioHalService.java
index d60479d..8d650c9 100644
--- a/service/src/com/android/car/hal/AudioHalService.java
+++ b/service/src/com/android/car/hal/AudioHalService.java
@@ -435,6 +435,20 @@
         return isPropertySupportedLocked(VehicleNetworkConsts.VEHICLE_PROPERTY_AUDIO_VOLUME_LIMIT);
     }
 
+    public synchronized boolean isAudioVolumeMasterOnly() {
+        if (!isPropertySupportedLocked(VehicleNetworkConsts.VEHICLE_PROPERTY_AUDIO_VOLUME)) {
+            throw new IllegalStateException("VEHICLE_PROPERTY_AUDIO_VOLUME not supported");
+        }
+        VehiclePropConfig config = mProperties.get(
+                VehicleNetworkConsts.VEHICLE_PROPERTY_AUDIO_VOLUME);
+        if ((config.getConfigArray(1) &
+                VehicleAudioVolumeCapabilityFlag.VEHICLE_AUDIO_VOLUME_CAPABILITY_MASTER_VOLUME_ONLY)
+                != 0) {
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Get the current audio focus state.
      * @return 0: focusState, 1: streams, 2: externalFocus