OSDN Git Service

Store as V1.0 reference by default
authorBadhri Jagan Sridharan <badhri@google.com>
Wed, 30 Jan 2019 02:12:18 +0000 (18:12 -0800)
committerBadhri Jagan Sridharan <badhri@google.com>
Wed, 30 Jan 2019 02:42:35 +0000 (18:42 -0800)
Store IUsb as V1.0 instance by default and downcast when
calling V1.2 methods.

Bug: 123498520
Test: Checked dumpsys usb to reflect port status for
V1.0, V1.2, V1.3 implementations.
Change-Id: Id55d930252bff39b3b86283f3b6ab33a5e935b24

services/usb/java/com/android/server/usb/UsbPortManager.java

index 50e4faa..ae05750 100644 (file)
@@ -41,11 +41,11 @@ import android.hardware.usb.ParcelableUsbPort;
 import android.hardware.usb.UsbManager;
 import android.hardware.usb.UsbPort;
 import android.hardware.usb.UsbPortStatus;
+import android.hardware.usb.V1_0.IUsb;
 import android.hardware.usb.V1_0.PortRole;
 import android.hardware.usb.V1_0.PortRoleType;
 import android.hardware.usb.V1_0.Status;
 import android.hardware.usb.V1_1.PortStatus_1_1;
-import android.hardware.usb.V1_2.IUsb;
 import android.hardware.usb.V1_2.IUsbCallback;
 import android.hardware.usb.V1_2.PortStatus;
 import android.hidl.manager.V1_0.IServiceManager;
@@ -320,9 +320,12 @@ public class UsbPortManager {
 
         try {
             // Oneway call into the hal
-            mProxy.enableContaminantPresenceDetection(portId, enable);
+            android.hardware.usb.V1_2.IUsb proxy = (android.hardware.usb.V1_2.IUsb) mProxy;
+            proxy.enableContaminantPresenceDetection(portId, enable);
         } catch (RemoteException e) {
-            logAndPrintException(null, "Failed to set contaminant detection", e);
+            logAndPrintException(pw, "Failed to set contaminant detection", e);
+        } catch (ClassCastException e) {
+            logAndPrintException(pw, "Method only applicable to V1.2 or above implementation", e);
         }
     }