Merge "Switching to AudioUsage converters in AudioAttributes"
diff --git a/service/Android.bp b/service/Android.bp
index 50944d0..39e1858 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -26,7 +26,6 @@
 
 car_service_sources = [
     "src/**/*.java",
-    ":audio_policy_configuration_V7_0",
     ":statslog-Car-java-gen",
 ]
 
diff --git a/service/src/com/android/car/audio/hal/AudioControlWrapperAidl.java b/service/src/com/android/car/audio/hal/AudioControlWrapperAidl.java
index d06ae8e..c218007 100644
--- a/service/src/com/android/car/audio/hal/AudioControlWrapperAidl.java
+++ b/service/src/com/android/car/audio/hal/AudioControlWrapperAidl.java
@@ -30,8 +30,6 @@
 import java.io.PrintWriter;
 import java.util.Objects;
 
-import audio.policy.configuration.V7_0.AudioUsage;
-
 /**
  * Wrapper for AIDL interface for AudioControl HAL
  */
@@ -91,7 +89,7 @@
                     + ", zoneId " + zoneId + ", focusChange " + focusChange);
         }
         try {
-            String usageName = usageToString(usage);
+            String usageName = AudioAttributes.usageToXsdString(usage);
             mAudioControl.onAudioFocusChange(usageName, zoneId, focusChange);
         } catch (RemoteException e) {
             throw new IllegalStateException("Failed to query IAudioControl#onAudioFocusChange", e);
@@ -159,112 +157,14 @@
         @Override
         public void requestAudioFocus(String usage, int zoneId, int focusGain)
                 throws RemoteException {
-            @AttributeUsage int usageValue = stringToUsage(usage);
+            @AttributeUsage int usageValue = AudioAttributes.xsdStringToUsage(usage);
             mListener.requestAudioFocus(usageValue, zoneId, focusGain);
         }
 
         @Override
         public void abandonAudioFocus(String usage, int zoneId) throws RemoteException {
-            @AttributeUsage int usageValue = stringToUsage(usage);
+            @AttributeUsage int usageValue = AudioAttributes.xsdStringToUsage(usage);
             mListener.abandonAudioFocus(usageValue, zoneId);
         }
     }
-
-    // TODO(b/171572311): Move usageToString and stringToUsage to AudioAttributes
-    private static String usageToString(@AttributeUsage int usage) {
-        switch (usage) {
-            case AudioAttributes.USAGE_UNKNOWN:
-                return AudioUsage.AUDIO_USAGE_UNKNOWN.toString();
-            case AudioAttributes.USAGE_MEDIA:
-                return AudioUsage.AUDIO_USAGE_MEDIA.toString();
-            case AudioAttributes.USAGE_VOICE_COMMUNICATION:
-                return AudioUsage.AUDIO_USAGE_VOICE_COMMUNICATION.toString();
-            case AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING:
-                return AudioUsage.AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING.toString();
-            case AudioAttributes.USAGE_ALARM:
-                return AudioUsage.AUDIO_USAGE_ALARM.toString();
-            case AudioAttributes.USAGE_NOTIFICATION:
-                return AudioUsage.AUDIO_USAGE_NOTIFICATION.toString();
-            case AudioAttributes.USAGE_NOTIFICATION_RINGTONE:
-                return AudioUsage.AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE.toString();
-            case AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY:
-                return AudioUsage.AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY.toString();
-            case AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
-                return AudioUsage.AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE.toString();
-            case AudioAttributes.USAGE_ASSISTANCE_SONIFICATION:
-                return AudioUsage.AUDIO_USAGE_ASSISTANCE_SONIFICATION.toString();
-            case AudioAttributes.USAGE_GAME:
-                return AudioUsage.AUDIO_USAGE_GAME.toString();
-            case AudioAttributes.USAGE_VIRTUAL_SOURCE:
-                return AudioUsage.AUDIO_USAGE_VIRTUAL_SOURCE.toString();
-            case AudioAttributes.USAGE_ASSISTANT:
-                return AudioUsage.AUDIO_USAGE_ASSISTANT.toString();
-            case AudioAttributes.USAGE_CALL_ASSISTANT:
-                return AudioUsage.AUDIO_USAGE_CALL_ASSISTANT.toString();
-            case AudioAttributes.USAGE_EMERGENCY:
-                return AudioUsage.AUDIO_USAGE_EMERGENCY.toString();
-            case AudioAttributes.USAGE_SAFETY:
-                return AudioUsage.AUDIO_USAGE_SAFETY.toString();
-            case AudioAttributes.USAGE_VEHICLE_STATUS:
-                return AudioUsage.AUDIO_USAGE_VEHICLE_STATUS.toString();
-            case AudioAttributes.USAGE_ANNOUNCEMENT:
-                return AudioUsage.AUDIO_USAGE_ANNOUNCEMENT.toString();
-            default:
-                Log.w(TAG, "Unknown usage value " + usage);
-                return AudioUsage.AUDIO_USAGE_UNKNOWN.toString();
-        }
-    }
-
-    private static @AttributeUsage int stringToUsage(String usageName) {
-        AudioUsage usage;
-        try {
-            usage = AudioUsage.valueOf(usageName);
-        } catch (IllegalArgumentException e) {
-            Log.e(TAG, "Usage name not found in AudioUsage enum: " + usageName, e);
-            return AudioAttributes.USAGE_UNKNOWN;
-        }
-
-        switch (usage) {
-            case AUDIO_USAGE_UNKNOWN:
-                return AudioAttributes.USAGE_UNKNOWN;
-            case AUDIO_USAGE_MEDIA:
-                return AudioAttributes.USAGE_MEDIA;
-            case AUDIO_USAGE_VOICE_COMMUNICATION:
-                return AudioAttributes.USAGE_VOICE_COMMUNICATION;
-            case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
-                return AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING;
-            case AUDIO_USAGE_ALARM:
-                return AudioAttributes.USAGE_ALARM;
-            case AUDIO_USAGE_NOTIFICATION:
-                return AudioAttributes.USAGE_NOTIFICATION;
-            case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
-                return AudioAttributes.USAGE_NOTIFICATION_RINGTONE;
-            case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
-                return AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY;
-            case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
-                return AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE;
-            case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
-                return AudioAttributes.USAGE_ASSISTANCE_SONIFICATION;
-            case AUDIO_USAGE_GAME:
-                return AudioAttributes.USAGE_GAME;
-            case AUDIO_USAGE_VIRTUAL_SOURCE:
-                return AudioAttributes.USAGE_VIRTUAL_SOURCE;
-            case AUDIO_USAGE_ASSISTANT:
-                return AudioAttributes.USAGE_ASSISTANT;
-            case AUDIO_USAGE_CALL_ASSISTANT:
-                return AudioAttributes.USAGE_CALL_ASSISTANT;
-            case AUDIO_USAGE_EMERGENCY:
-                return AudioAttributes.USAGE_EMERGENCY;
-            case AUDIO_USAGE_SAFETY:
-                return AudioAttributes.USAGE_SAFETY;
-            case AUDIO_USAGE_VEHICLE_STATUS:
-                return AudioAttributes.USAGE_VEHICLE_STATUS;
-            case AUDIO_USAGE_ANNOUNCEMENT:
-                return AudioAttributes.USAGE_ANNOUNCEMENT;
-            default:
-                Log.w(TAG, "Mapping missing for usage " + usageName);
-                return AudioAttributes.USAGE_UNKNOWN;
-        }
-
-    }
 }
diff --git a/tests/carservice_unit_test/src/com/android/car/audio/hal/AudioControlWrapperAidlTest.java b/tests/carservice_unit_test/src/com/android/car/audio/hal/AudioControlWrapperAidlTest.java
index 4715cab..3613ad0 100644
--- a/tests/carservice_unit_test/src/com/android/car/audio/hal/AudioControlWrapperAidlTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/audio/hal/AudioControlWrapperAidlTest.java
@@ -30,6 +30,7 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.audio.policy.configuration.V7_0.AudioUsage;
 import android.car.test.mocks.AbstractExtendedMockitoTestCase;
 import android.hardware.automotive.audiocontrol.IAudioControl;
 import android.hardware.automotive.audiocontrol.IFocusListener;
@@ -48,8 +49,6 @@
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 
-import audio.policy.configuration.V7_0.AudioUsage;
-
 @RunWith(AndroidJUnit4.class)
 public final class AudioControlWrapperAidlTest extends AbstractExtendedMockitoTestCase {
     private static final String TAG = AudioControlWrapperAidlTest.class.getSimpleName();