aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2012-11-24 10:46:21 -0800
committerGerrit Code Review <gerrit@review.cyanogenmod.com>2012-11-24 10:46:21 -0800
commit4ac8d65b269ea6cedaf4cec91d97fbd7be131eb7 (patch)
tree7187ba32da11d1f59e5d230b01ba475c63c93ee9
parent4ab0701ca2eba12dc26c644b0f16a486cfa17433 (diff)
parentdc4416c0b0be3986cb683cc20c704e475d836423 (diff)
downloadandroid_packages_apps_CMFileManager-4ac8d65b269ea6cedaf4cec91d97fbd7be131eb7.tar.gz
android_packages_apps_CMFileManager-4ac8d65b269ea6cedaf4cec91d97fbd7be131eb7.tar.bz2
android_packages_apps_CMFileManager-4ac8d65b269ea6cedaf4cec91d97fbd7be131eb7.zip
Merge "CMFileManager: Check shell commands on startup" into jellybean
-rw-r--r--res/values/overlay.xml45
-rw-r--r--res/xml/command_list.xml2
-rw-r--r--src/com/cyanogenmod/filemanager/FileManagerApplication.java41
3 files changed, 82 insertions, 6 deletions
diff --git a/res/values/overlay.xml b/res/values/overlay.xml
index 0019965a..1a68d534 100644
--- a/res/values/overlay.xml
+++ b/res/values/overlay.xml
@@ -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>
diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml
index c79aee77..26cd51eb 100644
--- a/res/xml/command_list.xml
+++ b/res/xml/command_list.xml
@@ -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}'" />
diff --git a/src/com/cyanogenmod/filemanager/FileManagerApplication.java b/src/com/cyanogenmod/filemanager/FileManagerApplication.java
index d3ecf9f9..c765ee35 100644
--- a/src/com/cyanogenmod/filemanager/FileManagerApplication.java
+++ b/src/com/cyanogenmod/filemanager/FileManagerApplication.java
@@ -203,9 +203,7 @@ public final class FileManagerApplication extends Application {
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();
@@ -419,4 +417,41 @@ public final class FileManagerApplication extends Application {
}
}
+ /**
+ * 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;
+ }
}