From cdee83a6147bf1601424d5451c30f0dfb8d0e2a6 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 26 Jan 2017 15:29:16 -0700 Subject: [PATCH] Disable RescueParty in debug/lab environments. We need to strike a balance between rescuing devices of real users in the field, while also not interfering with debugging or testing use-cases. This change uses "charging via USB" as a signal that the device is under active development, or is in a lab environment. We could try checking for an adb connection, but UsbDebuggingManager isn't started until much later in the boot, so BatteryManager is our best chance of detecting this case. Note that we continue to always recover "user" builds, and we never recover "eng" builds. Test: builds, boots, skips when plugged in over USB Bug: 34722552 Change-Id: Ib095482a2ed84e8c5dfb3c71d5f9b88457c2b5e6 --- core/java/android/os/Build.java | 7 ++++-- .../java/com/android/server/RescueParty.java | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index 80ecf9789c7b0..817cb5bb9add3 100644 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -883,8 +883,11 @@ public class Build { SystemProperties.getInt("ro.debuggable", 0) == 1; /** {@hide} */ - public static final boolean IS_ENG = - "eng".equals(getString("ro.build.type")); + public static final boolean IS_ENG = "eng".equals(TYPE); + /** {@hide} */ + public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE); + /** {@hide} */ + public static final boolean IS_USER = "user".equals(TYPE); /** * Whether this build is running inside a container. diff --git a/services/core/java/com/android/server/RescueParty.java b/services/core/java/com/android/server/RescueParty.java index d51e96ad78fb4..f078acfd27a1e 100644 --- a/services/core/java/com/android/server/RescueParty.java +++ b/services/core/java/com/android/server/RescueParty.java @@ -19,6 +19,8 @@ package com.android.server; import android.content.ContentResolver; import android.content.Context; import android.content.pm.UserInfo; +import android.os.BatteryManager; +import android.os.BatteryManagerInternal; import android.os.Build; import android.os.RecoverySystem; import android.os.SystemClock; @@ -65,7 +67,25 @@ public class RescueParty { private static SparseArray sApps = new SparseArray<>(); private static boolean isDisabled() { - return Build.IS_ENG || SystemProperties.getBoolean(PROP_DISABLE_RESCUE, false); + // We're disabled on all engineering devices + if (Build.IS_ENG) return true; + + // We're disabled on userdebug devices connected over USB, since that's + // a decent signal that someone is actively trying to debug the device, + // or that it's in a lab environment. + if (Build.IS_USERDEBUG) { + try { + if (LocalServices.getService(BatteryManagerInternal.class) + .getPlugType() == BatteryManager.BATTERY_PLUGGED_USB) { + return true; + } else { + } + } catch (Throwable ignored) { + } + } + + // One last-ditch check + return SystemProperties.getBoolean(PROP_DISABLE_RESCUE, false); } /**