audio policy: fix several device descriptor issues.

- checkOutputsForDevice() should only clear device descriptor attributes
if the device is digital.
- checkInputsForDevice() did not clear device descriptor attributes at all.
- AudioPort::clearCapabilities() and importAudioPort() should not
manage gains as these are device specific.
- importAudioPort() should load a default port config.

Bug: 21990937.
Change-Id: Ida762ed8f9baaabae392cb4291eff1a8d3009751
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index a0de34d..ee25b71 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -3140,8 +3140,11 @@
 {
     audio_devices_t device = devDesc->type();
     sp<SwAudioOutputDescriptor> desc;
-    // erase all current sample rates, formats and channel masks
-    devDesc->clearCapabilities();
+
+    if (audio_device_is_digital(device)) {
+        // erase all current sample rates, formats and channel masks
+        devDesc->clearCapabilities();
+    }
 
     if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
         // first list already open outputs that can be routed to this device
@@ -3433,8 +3436,13 @@
                                                   const String8 address)
 {
     audio_devices_t device = devDesc->type();
-
     sp<AudioInputDescriptor> desc;
+
+    if (audio_device_is_digital(device)) {
+        // erase all current sample rates, formats and channel masks
+        devDesc->clearCapabilities();
+    }
+
     if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
         // first list already open inputs that can be routed to this device
         for (size_t input_index = 0; input_index < mInputs.size(); input_index++) {