audiohal: Avoid making unneeded calls to HIDL inteface's ::castFrom

Instead of calling '::castFrom' every time a conversion from
IDevice to IPrimaryDevice is needed, make this conversion at
initialization.

This is to avoid additional IPC calls that are required
for 'castFrom'.

Bug: 63142881
Change-Id: Ic4192c729011ce2653772847e83da426116f9e94
Test: audio works
diff --git a/media/libaudiohal/DeviceHalHidl.h b/media/libaudiohal/DeviceHalHidl.h
index 9da02a4..8651b51 100644
--- a/media/libaudiohal/DeviceHalHidl.h
+++ b/media/libaudiohal/DeviceHalHidl.h
@@ -18,11 +18,13 @@
 #define ANDROID_HARDWARE_DEVICE_HAL_HIDL_H
 
 #include <android/hardware/audio/2.0/IDevice.h>
+#include <android/hardware/audio/2.0/IPrimaryDevice.h>
 #include <media/audiohal/DeviceHalInterface.h>
 
 #include "ConversionHelperHidl.h"
 
 using ::android::hardware::audio::V2_0::IDevice;
+using ::android::hardware::audio::V2_0::IPrimaryDevice;
 using ::android::hardware::Return;
 
 namespace android {
@@ -110,6 +112,7 @@
   private:
     friend class DevicesFactoryHalHidl;
     sp<IDevice> mDevice;
+    sp<IPrimaryDevice> mPrimaryDevice;  // Null if it's not a primary device.
 
     // Can not be constructed directly by clients.
     explicit DeviceHalHidl(const sp<IDevice>& device);