@@ -104,6 +104,9 @@ public class AndroidAdbUtil {
104104 /** ADB shell command for getting device property. Could be followed by the property name. */
105105 @ VisibleForTesting static final String ADB_SHELL_GET_PROPERTY = "getprop" ;
106106
107+ /** ADB shell command for getting user id */
108+ @ VisibleForTesting static final String ADB_SHELL_ID = "id" ;
109+
107110 /** ADB shell command for sending key event. Should be followed by the event number. */
108111 @ VisibleForTesting static final String ADB_SHELL_SEND_KEY = "input keyevent" ;
109112
@@ -113,18 +116,12 @@ public class AndroidAdbUtil {
113116 /** ADB shell command for setting device property. Should be followed by the property name. */
114117 @ VisibleForTesting static final String ADB_SHELL_SET_PROPERTY = "setprop" ;
115118
116- /** ADB shell command for becoming root. */
117- @ VisibleForTesting static final String ADB_SHELL_SU = "su" ;
118-
119119 /** Adb shell template of sqlite sql command. Should be filled with the db name and sql. */
120120 @ VisibleForTesting static final String ADB_SHELL_TEMPLATE_SQLITE_SQL = "sqlite3 %s '%s'" ;
121121
122122 /** Default user id for adb shell commands. */
123123 @ VisibleForTesting static final String ADB_SHELL_USER_ID_ALL = "all" ;
124124
125- /** ADB shell command for finding command in $PATH */
126- @ VisibleForTesting static final String ADB_SHELL_WHICH = "which" ;
127-
128125 /** Default timeout for regular command. */
129126 @ VisibleForTesting static final Duration BUGREPORT_TIMEOUT = Duration .ofMinutes (10 );
130127
@@ -767,13 +764,12 @@ public int getIntProperty(String serial, AndroidProperty property)
767764 public boolean isRooted (String serial ) throws MobileHarnessException , InterruptedException {
768765 String output = "" ;
769766 try {
770- output = adb .runShell (serial , ADB_SHELL_WHICH + " " + ADB_SHELL_SU ). trim ( );
767+ output = adb .runShell (serial , ADB_SHELL_ID );
771768 } catch (MobileHarnessException e ) {
772769 throw new MobileHarnessException (
773770 AndroidErrorId .ANDROID_ADB_UTIL_CHECK_ROOT_ERROR , e .getMessage (), e );
774771 }
775- // Unrooted device doesn't generate any message.
776- return !output .isEmpty ();
772+ return output .contains ("uid=0(root)" );
777773 }
778774
779775 /**
0 commit comments