diff options
| author | 2017-02-23 21:11:50 +0000 | |
|---|---|---|
| committer | 2017-02-23 21:11:54 +0000 | |
| commit | ff14143cee60a38b17c2610807a0503ba86d0bb2 (patch) | |
| tree | 29b1e1a0821dc63499269f7c160ea78e8c8305d7 | |
| parent | 23830a090929ad776d66e723222e395dcf067f65 (diff) | |
| parent | 1bec44836ed6b29e128849b7be34dc7b2a214e76 (diff) | |
Merge "Take another pass at detecting USB connections."
| -rw-r--r-- | services/core/java/com/android/server/RescueParty.java | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/services/core/java/com/android/server/RescueParty.java b/services/core/java/com/android/server/RescueParty.java index 33351ffc0f77..480b08a77cf7 100644 --- a/services/core/java/com/android/server/RescueParty.java +++ b/services/core/java/com/android/server/RescueParty.java @@ -19,13 +19,9 @@ package com.android.server; import android.content.ContentResolver; import android.content.Context; import android.content.pm.UserInfo; -import android.os.BatteryManager; -import android.os.BatteryProperties; import android.os.Build; -import android.os.IBatteryPropertiesListener; -import android.os.IBatteryPropertiesRegistrar; +import android.os.FileUtils; import android.os.RecoverySystem; -import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; @@ -34,14 +30,12 @@ import android.provider.Settings; import android.text.format.DateUtils; import android.util.ExceptionUtils; import android.util.MathUtils; -import android.util.MutableBoolean; import android.util.Slog; import android.util.SparseArray; import com.android.internal.util.ArrayUtils; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import java.io.File; /** * Utilities to help rescue the system from crash loops. Callers are expected to @@ -325,30 +319,13 @@ public class RescueParty { /** * Hacky test to check if the device has an active USB connection, which is - * a good proxy for someone doing local development work. It uses a low - * level call since we may not have started {@link BatteryManager} yet. + * a good proxy for someone doing local development work. */ private static boolean isUsbActive() { - final MutableBoolean res = new MutableBoolean(false); - final CountDownLatch latch = new CountDownLatch(1); - final IBatteryPropertiesListener listener = new IBatteryPropertiesListener.Stub() { - @Override - public void batteryPropertiesChanged(BatteryProperties props) { - res.value = props.chargerUsbOnline; - latch.countDown(); - } - }; - try { - final IBatteryPropertiesRegistrar bpr = IBatteryPropertiesRegistrar.Stub - .asInterface(ServiceManager.getService("batteryproperties")); - bpr.registerListener(listener); - try { - latch.await(5, TimeUnit.SECONDS); - } finally { - bpr.unregisterListener(listener); - } - return res.value; + final String state = FileUtils + .readTextFile(new File("/sys/class/android_usb/android0/state"), 128, ""); + return "CONFIGURED".equals(state.trim()); } catch (Throwable t) { Slog.w(TAG, "Failed to determine if device was on USB", t); return false; |