Skip to content

Commit

Permalink
CMFileManager: Check shell commands on startup
Browse files Browse the repository at this point in the history
This change improved the detection of CM rooted devices with support for all the
commands used by CMFM. In case of one of this command was not detected, the app start
in chrooted-java mode (with limited support).

Change-Id: Ie0f61d74f9619f476ea517c1b3c03ec453e033f3
  • Loading branch information
jruesga committed Nov 19, 2012
1 parent 463b0da commit dc4416c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
45 changes: 43 additions & 2 deletions res/values/overlay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,49 @@
<!-- The system directory -->
<string name="system_dir" translatable="false">/system</string>

<!-- The su binary -->
<string name="su_binary" translatable="false">/system/xbin/su</string>
<!-- The shell commands used by this application. All of this commands should
exist to allow the use of a shell console (and access to root). If any
of this commands are not present in the system, then app will start in
non-rooted mode and with a java console.
-->
<string name="shell_required_commands" translatable="false">
/system/bin/cat,
/system/bin/chmod,
/system/bin/chown,
/system/bin/dd,
/system/bin/df,
/system/bin/gzip,
/system/bin/id,
/system/bin/kill,
/system/bin/ln,
/system/bin/ls,
/system/bin/mkdir,
/system/bin/mount,
/system/bin/mv,
/system/bin/ps,
/system/bin/rm,
/system/bin/sh,
/system/xbin/awk,
/system/xbin/bunzip2,
/system/xbin/bzip2,
/system/xbin/cp,
/system/xbin/cut,
/system/xbin/dirname,
/system/xbin/echo,
/system/xbin/find,
/system/xbin/grep,
/system/xbin/groups,
/system/xbin/gunzip,
/system/xbin/pwd,
/system/xbin/readlink,
/system/xbin/su,
/system/xbin/tar,
/system/xbin/uncompress,
/system/xbin/unlzma,
/system/xbin/unxz,
/system/xbin/unzip,
/system/xbin/xargs
</string>

<!-- The mounts file -->
<string name="mounts_file" translatable="false">/proc/mounts</string>
Expand Down
2 changes: 1 addition & 1 deletion res/xml/command_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<command commandId="mountpointinfo" commandPath="/system/bin/cat" commandArgs="/proc/mounts" />

<!-- List/Find/Info -->
<command commandId="ls" commandPath="cd" commandArgs="%1$s &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -v -e '^l' || true; } &amp;&amp; echo '>SIMLINKS>' &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -e '^l' || true; } &amp;&amp; echo '>SIMLINKS_DATA>' &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f &amp;&amp; /system/bin/ls -F %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | { /system/xbin/xargs -r /system/bin/ls -ald || echo; }" />
<command commandId="ls" commandPath="cd" commandArgs="%1$s &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -v -e '^l' || true; } &amp;&amp; /system/xbin/echo '>SIMLINKS>' &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -e '^l' || true; } &amp;&amp; /system/xbin/echo '>SIMLINKS_DATA>' &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | /system/xbin/awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f &amp;&amp; /system/bin/ls -F %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | /system/xbin/awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f | /system/xbin/awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | { /system/xbin/xargs -r /system/bin/ls -ald || /system/xbin/echo; }" />
<command commandId="fileinfo" commandPath="/system/bin/ls" commandArgs="-ald %1$s" />
<command commandId="find" commandPath="/system/xbin/find" commandArgs="%1$s \\( -name %2$s -o -name %3$s -o -name %4$s -o -name %5$s -o -name %6$s \\) -exec /system/xbin/echo {} \\; -exec /system/bin/ls -ald {} \\;" />
<command commandId="quickfoldersearch" commandPath="/system/bin/ls" commandArgs="-aFd %1$s.* %1$s* | /system/xbin/grep -e '^d' -e '^ld' | /system/xbin/awk '{print $2}'" />
Expand Down
41 changes: 38 additions & 3 deletions src/com/cyanogenmod/filemanager/FileManagerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ private void register() {
sIsDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));

// Check if the device is rooted
sIsDeviceRooted =
new File(getString(R.string.su_binary)).exists() &&
getSystemProperty("ro.cm.version") != null; //$NON-NLS-1$
sIsDeviceRooted = areShellCommandsPresent();

// Register the notify broadcast receiver
IntentFilter filter = new IntentFilter();
Expand Down Expand Up @@ -419,4 +417,41 @@ private static void readSystemProperties() {
}
}

/**
* Method that check if all shell commands are present in the device
*
* @return boolean Check if the device has all of the shell commands
*/
private boolean areShellCommandsPresent() {
try {
String shellCommands = getString(R.string.shell_required_commands);
String[] commands = shellCommands.split(","); //$NON-NLS-1$
int cc = commands.length;
if (cc == 0) {
//???
Log.w(TAG, "No shell commands."); //$NON-NLS-1$
return false;
}
for (int i = 0; i < cc; i++) {
String c = commands[i].trim();
if (c.length() == 0) continue;
File cmd = new File(c);
if (!cmd.exists() || !cmd.isFile()) {
Log.w(TAG,
String.format(
"Command %s not found. Exists: %s; IsFile: %s.", //$NON-NLS-1$
c,
String.valueOf(cmd.exists()),
String.valueOf(cmd.isFile())));
return false;
}
}
// All commands are present
return true;
} catch (Exception e) {
Log.e(TAG,
"Failed to read shell commands.", e); //$NON-NLS-1$
}
return false;
}
}

0 comments on commit dc4416c

Please sign in to comment.