Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dab20723 authored by RoboErik's avatar RoboErik Committed by Mike Lockwood
Browse files

fix setting only usb mode

If you cleared the last usb mode it would fail (and so would setting
it if you started with none). This fixes it to set and unset the
last property correctly.

Change-Id: Ice5be6e57b6ca6b8c9241b0ac62071a3bc72606a
parent 5e64321e
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UEventObserver;
import android.provider.Settings;
@@ -206,6 +207,9 @@ public class UsbDeviceManager {
    }

     private static String addFunction(String functions, String function) {
         if ("none".equals(functions)) {
             return function;
         }
        if (!containsFunction(functions, function)) {
            if (functions.length() > 0) {
                functions += ",";
@@ -222,6 +226,9 @@ public class UsbDeviceManager {
                split[i] = null;
            }
        }
        if (split.length == 1 && split[0] == null) {
            return "none";
        }
        StringBuilder builder = new StringBuilder();
         for (int i = 0; i < split.length; i++) {
            String s = split[i];
@@ -365,11 +372,7 @@ public class UsbDeviceManager {
            for (int i = 0; i < 20; i++) {
                // State transition is done when sys.usb.state is set to the new configuration
                if (state.equals(SystemProperties.get("sys.usb.state"))) return true;
                try {
                    // try again in 50ms
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                }
                SystemClock.sleep(50);
            }
            Slog.e(TAG, "waitForState(" + state + ") FAILED");
            return false;