Rename AudioState to CallAudioState

Deprecate AudioState class and make methods @SystemApi where
necessary to minimize impact to SystemApi
Replace usages of AudioState inside Telecom sub-systems
Fire both onCallAudioStateChanged and onAudioStateChanged callbacks
for backward compatibility
Support both setAudioState and setCallAudioState for all classes

Bug: 21040387
Bug: 21088300
Change-Id: I3ec7b3afdaa344c6d639d1c421f1842d67f7d0f7
diff --git a/telecomm/java/android/telecom/Phone.java b/telecomm/java/android/telecom/Phone.java
index 4cdfd2e..8eb091b 100644
--- a/telecomm/java/android/telecom/Phone.java
+++ b/telecomm/java/android/telecom/Phone.java
@@ -41,10 +41,21 @@
          *
          * @param phone The {@code Phone} calling this method.
          * @param audioState The new {@link AudioState}.
+         *
+         * @deprecated Use {@link #onCallAudioStateChanged(Phone, CallAudioState)} instead.
          */
+        @Deprecated
         public void onAudioStateChanged(Phone phone, AudioState audioState) { }
 
         /**
+         * Called when the audio state changes.
+         *
+         * @param phone The {@code Phone} calling this method.
+         * @param callAudioState The new {@link CallAudioState}.
+         */
+        public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) { }
+
+        /**
          * Called to bring the in-call screen to the foreground. The in-call experience should
          * respond immediately by coming to the foreground to inform the user of the state of
          * ongoing {@code Call}s.
@@ -100,7 +111,7 @@
 
     private final InCallAdapter mInCallAdapter;
 
-    private AudioState mAudioState;
+    private CallAudioState mCallAudioState;
 
     private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
 
@@ -145,10 +156,10 @@
         }
     }
 
-    final void internalAudioStateChanged(AudioState audioState) {
-        if (!Objects.equals(mAudioState, audioState)) {
-            mAudioState = audioState;
-            fireAudioStateChanged(audioState);
+    final void internalCallAudioStateChanged(CallAudioState callAudioState) {
+        if (!Objects.equals(mCallAudioState, callAudioState)) {
+            mCallAudioState = callAudioState;
+            fireCallAudioStateChanged(callAudioState);
         }
     }
 
@@ -271,9 +282,20 @@
      * Obtains the current phone call audio state of the {@code Phone}.
      *
      * @return An object encapsulating the audio state.
+     * @deprecated Use {@link #getCallAudioState()} instead.
      */
+    @Deprecated
     public final AudioState getAudioState() {
-        return mAudioState;
+        return new AudioState(mCallAudioState);
+    }
+
+    /**
+     * Obtains the current phone call audio state of the {@code Phone}.
+     *
+     * @return An object encapsulating the audio state.
+     */
+    public final CallAudioState getCallAudioState() {
+        return mCallAudioState;
     }
 
     private void fireCallAdded(Call call) {
@@ -288,9 +310,10 @@
         }
     }
 
-    private void fireAudioStateChanged(AudioState audioState) {
+    private void fireCallAudioStateChanged(CallAudioState audioState) {
         for (Listener listener : mListeners) {
-            listener.onAudioStateChanged(this, audioState);
+            listener.onCallAudioStateChanged(this, audioState);
+            listener.onAudioStateChanged(this, new AudioState(audioState));
         }
     }