OSDN Git Service

Refactor setCurrentFunction and setUsbDataUnlocked into one method
authorJerry Zhang <zhangjerry@google.com>
Wed, 12 Oct 2016 21:42:56 +0000 (14:42 -0700)
committerJerry Zhang <zhangjerry@google.com>
Tue, 24 Jan 2017 21:27:14 +0000 (13:27 -0800)
This allows us to get rid of an extraneous config switch and
simplify some code.

Bug: 31814300
Test: Manually change usb configuration
Change-Id: Id78da530ff485ecd7a915056832eec1dd8c91954
(cherry picked from commit 5d36a177d95184aaa0763d07aa38ff028f5a9b9c)

src/com/android/settings/DevelopmentSettings.java
src/com/android/settings/deviceinfo/UsbBackend.java

index a77f7b1..9815b41 100644 (file)
@@ -1707,11 +1707,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private void writeUsbConfigurationOption(Object newValue) {
         UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
         String function = newValue.toString();
-        manager.setCurrentFunction(function);
         if (function.equals("none")) {
-            manager.setUsbDataUnlocked(false);
+            manager.setCurrentFunction(function, false);
         } else {
-            manager.setUsbDataUnlocked(true);
+            manager.setCurrentFunction(function, true);
         }
     }
 
index cd88709..e648b39 100644 (file)
@@ -101,20 +101,16 @@ public class UsbBackend {
     private void setUsbFunction(int mode) {
         switch (mode) {
             case MODE_DATA_MTP:
-                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP);
-                mUsbManager.setUsbDataUnlocked(true);
+                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);
                 break;
             case MODE_DATA_PTP:
-                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP);
-                mUsbManager.setUsbDataUnlocked(true);
+                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true);
                 break;
             case MODE_DATA_MIDI:
-                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MIDI);
-                mUsbManager.setUsbDataUnlocked(true);
+                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MIDI, true);
                 break;
             default:
-                mUsbManager.setCurrentFunction(null);
-                mUsbManager.setUsbDataUnlocked(false);
+                mUsbManager.setCurrentFunction(null, false);
                 break;
         }
     }