From dc4416c0b0be3986cb683cc20c704e475d836423 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Tue, 20 Nov 2012 00:17:36 +0100 Subject: CMFileManager: Check shell commands on startup 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 --- res/values/overlay.xml | 45 +++++++++++++++++++++- res/xml/command_list.xml | 2 +- .../filemanager/FileManagerApplication.java | 41 ++++++++++++++++++-- 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 @@ /system - - /system/xbin/su + + + /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 + /proc/mounts 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 @@ - + 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; + } } -- cgit v1.2.3