diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java index 00d4e2c..052571d 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java @@ -23,13 +23,16 @@ import java.io.LineNumberReader; import java.util.ArrayList; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; import org.sufficientlysecure.rootcommands.command.SimpleCommand; -import org.sufficientlysecure.rootcommands.util.Log; //no modifier, this means it is package-private. Only our internal classes can use this. class Remounter { + private static final Logger LOGGER = Logger.getLogger(Remounter.class.getName()); + private Shell shell; public Remounter(Shell shell) { @@ -64,7 +67,7 @@ protected boolean remount(String file, String mountType) { while (!foundMount) { try { for (Mount mount : getMounts()) { - Log.d(RootCommands.TAG, mount.getMountPoint().toString()); + LOGGER.log(Level.FINE, mount.getMountPoint().toString()); if (file.equals(mount.getMountPoint().toString())) { foundMount = true; @@ -72,21 +75,21 @@ protected boolean remount(String file, String mountType) { } } } catch (Exception e) { - Log.e(RootCommands.TAG, "Exception", e); + LOGGER.log(Level.SEVERE, "Exception", e); return false; } if (!foundMount) { try { file = (new File(file).getParent()).toString(); } catch (Exception e) { - Log.e(RootCommands.TAG, "Exception", e); + LOGGER.log(Level.SEVERE, "Exception", e); return false; } } } Mount mountPoint = findMountPointRecursive(file); - Log.d(RootCommands.TAG, "Remounting " + mountPoint.getMountPoint().getAbsolutePath() + LOGGER.log(Level.FINE, "Remounting " + mountPoint.getMountPoint().getAbsolutePath() + " as " + mountType.toLowerCase(Locale.US)); final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US)); @@ -116,15 +119,15 @@ protected boolean remount(String file, String mountType) { } if (mountPoint != null) { - Log.d(RootCommands.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US)); + LOGGER.log(Level.FINE, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US)); if (mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US))) { - Log.d(RootCommands.TAG, mountPoint.getFlags().toString()); + LOGGER.log(Level.FINE, mountPoint.getFlags().toString()); return true; } else { - Log.d(RootCommands.TAG, mountPoint.getFlags().toString()); + LOGGER.log(Level.FINE, mountPoint.getFlags().toString()); } } else { - Log.d(RootCommands.TAG, "mountPoint is null"); + LOGGER.log(Level.FINE, "mountPoint is null"); } return false; } @@ -143,7 +146,7 @@ private Mount findMountPointRecursive(String file) { } catch (IOException e) { throw new RuntimeException(e); } catch (Exception e) { - Log.e(RootCommands.TAG, "Exception", e); + LOGGER.log(Level.SEVERE, "Exception", e); } return null; } @@ -175,7 +178,7 @@ protected static ArrayList getMounts() throws Exception { ArrayList mounts = new ArrayList(); while ((line = lnr.readLine()) != null) { - Log.d(RootCommands.TAG, line); + LOGGER.log(Level.FINE, line); String[] fields = line.split(" "); mounts.add(new Mount(new File(fields[0]), // device diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java index 2557628..901760d 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java @@ -16,13 +16,14 @@ package org.sufficientlysecure.rootcommands; -import org.sufficientlysecure.rootcommands.util.Log; +import java.util.logging.Level; +import java.util.logging.Logger; public class RootCommands { public static boolean DEBUG = false; public static int DEFAULT_TIMEOUT = 10000; - public static final String TAG = "RootCommands"; + private static final Logger LOGGER = Logger.getLogger(RootCommands.class.getName()); /** * General method to check if user has su binary and accepts root access for this program! @@ -42,7 +43,7 @@ public static boolean rootAccessGiven() { rootShell.close(); } catch (Exception e) { - Log.e(TAG, "Problem while checking for root access!", e); + LOGGER.log(Level.SEVERE, "Problem while checking for root access!", e); } return rootAccess; diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java index f3f0dd9..a6dea09 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java @@ -24,9 +24,10 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import org.sufficientlysecure.rootcommands.command.Command; -import org.sufficientlysecure.rootcommands.util.Log; import org.sufficientlysecure.rootcommands.util.RootAccessDeniedException; import org.sufficientlysecure.rootcommands.util.Utils; @@ -37,6 +38,8 @@ public class Shell implements Closeable { private final List commands = new ArrayList(); private boolean close = false; + private static final Logger LOGGER = Logger.getLogger(Shell.class.getName()); + private static final String LD_LIBRARY_PATH = System.getenv("LD_LIBRARY_PATH"); private static final String token = "F*D^W@#FGF"; @@ -50,7 +53,7 @@ public class Shell implements Closeable { */ public static Shell startRootShell(ArrayList customEnv, String baseDirectory) throws IOException, RootAccessDeniedException { - Log.d(RootCommands.TAG, "Starting Root Shell!"); + LOGGER.log(Level.FINE, "Starting Root Shell!"); // On some versions of Android (ICS) LD_LIBRARY_PATH is unset when using su // We need to pass LD_LIBRARY_PATH over su for some commands to work correctly. @@ -84,7 +87,7 @@ public static Shell startRootShell() throws IOException, RootAccessDeniedExcepti */ public static Shell startShell(ArrayList customEnv, String baseDirectory) throws IOException { - Log.d(RootCommands.TAG, "Starting Shell!"); + LOGGER.log(Level.FINE, "Starting Shell!"); Shell shell = new Shell("sh", customEnv, baseDirectory); return shell; } @@ -110,7 +113,7 @@ public static Shell startShell() throws IOException { */ public static Shell startCustomShell(String shellPath, ArrayList customEnv, String baseDirectory) throws IOException { - Log.d(RootCommands.TAG, "Starting Custom Shell!"); + LOGGER.log(Level.FINE, "Starting Custom Shell!"); Shell shell = new Shell(shellPath, customEnv, baseDirectory); return shell; @@ -129,7 +132,7 @@ public static Shell startCustomShell(String shellPath) throws IOException { private Shell(String shell, ArrayList customEnv, String baseDirectory) throws IOException, RootAccessDeniedException { - Log.d(RootCommands.TAG, "Starting shell: " + shell); + LOGGER.log(Level.FINE, "Starting shell: " + shell); // start shell process! shellProcess = Utils.runWithEnv(shell, customEnv, baseDirectory); @@ -164,7 +167,7 @@ public void run() { try { writeCommands(); } catch (IOException e) { - Log.e(RootCommands.TAG, "IO Exception", e); + LOGGER.log(Level.SEVERE, "IO Exception", e); } } }; @@ -174,9 +177,9 @@ public void run() { try { readOutput(); } catch (IOException e) { - Log.e(RootCommands.TAG, "IOException", e); + LOGGER.log(Level.SEVERE, "IOException", e); } catch (InterruptedException e) { - Log.e(RootCommands.TAG, "InterruptedException", e); + LOGGER.log(Level.SEVERE, "InterruptedException", e); } } }; @@ -198,7 +201,7 @@ private void destroyShellProcess() { shellProcess.destroy(); } - Log.d(RootCommands.TAG, "Shell destroyed"); + LOGGER.log(Level.FINE, "Shell destroyed"); } /** @@ -229,12 +232,12 @@ private void writeCommands() throws IOException { out.write("\nexit 0\n".getBytes()); out.flush(); out.close(); - Log.d(RootCommands.TAG, "Closing shell"); + LOGGER.log(Level.FINE, "Closing shell"); return; } } } catch (InterruptedException e) { - Log.e(RootCommands.TAG, "interrupted while writing command", e); + LOGGER.log(Level.SEVERE, "interrupted while writing command", e); } } @@ -288,7 +291,7 @@ private void readOutput() throws IOException, InterruptedException { } command.processOutput(lineStdOut); } - Log.d(RootCommands.TAG, "Read all output"); + LOGGER.log(Level.FINE, "Read all output"); shellProcess.waitFor(); destroyShellProcess(); diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java index 355e695..a5b2c4a 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java @@ -16,6 +16,7 @@ package org.sufficientlysecure.rootcommands; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.ContentResolver; import android.content.Context; @@ -59,6 +60,7 @@ public void setGPS(boolean value) { /** * TODO: Not ready yet */ + @SuppressLint("MissingPermission") @TargetApi(8) public void reboot() { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java index fe8d2b4..2a4466b 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java @@ -22,14 +22,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.sufficientlysecure.rootcommands.command.ExecutableCommand; import org.sufficientlysecure.rootcommands.command.Command; +import org.sufficientlysecure.rootcommands.command.ExecutableCommand; import org.sufficientlysecure.rootcommands.command.SimpleCommand; import org.sufficientlysecure.rootcommands.util.BrokenBusyboxException; -import org.sufficientlysecure.rootcommands.util.Log; import android.os.StatFs; import android.os.SystemClock; @@ -44,6 +45,9 @@ * */ public class Toolbox { + + private static final Logger LOGGER = Logger.getLogger(Toolbox.class.getName()); + private Shell shell; /** @@ -131,12 +135,12 @@ public void output(int id, String line) { String pid = psMatcher.group(1); // add to pids list pids.add(pid); - Log.d(RootCommands.TAG, "Found pid: " + pid); + LOGGER.log(Level.FINE, "Found pid: " + pid); } else { - Log.d(RootCommands.TAG, "Matching in ps command failed!"); + LOGGER.log(Level.FINE, "Matching in ps command failed!"); } } catch (Exception e) { - Log.e(RootCommands.TAG, "Error with regex!", e); + LOGGER.log(Level.SEVERE, "Error with regex!", e); } } } @@ -161,7 +165,7 @@ public void afterExecution(int id, int exitCode) { */ public boolean killAll(String processName) throws BrokenBusyboxException, TimeoutException, IOException { - Log.d(RootCommands.TAG, "Killing process " + processName); + LOGGER.log(Level.FINE, "Killing process " + processName); PsCommand psCommand = new PsCommand(processName); shell.add(psCommand).waitForFinish(); @@ -179,7 +183,7 @@ public boolean killAll(String processName) throws BrokenBusyboxException, Timeou return false; } } else { - Log.d(RootCommands.TAG, "No pid found! Nothing was killed!"); + LOGGER.log(Level.FINE, "No pid found! Nothing was killed!"); return false; } } @@ -265,7 +269,7 @@ public LsCommand(String file) { // get only filename: this.fileName = (new File(file)).getName(); - Log.d(RootCommands.TAG, "fileName: " + fileName); + LOGGER.log(Level.FINE, "fileName: " + fileName); /** * regex to get pid out of ps line, example: @@ -344,9 +348,9 @@ public void output(int id, String line) { if (permissionMatcher.find()) { permissions = convertPermissions(permissionMatcher.group(1)); - Log.d(RootCommands.TAG, "Found permissions: " + permissions); + LOGGER.log(Level.FINE, "Found permissions: " + permissions); } else { - Log.d(RootCommands.TAG, "Permissions were not found in ls command!"); + LOGGER.log(Level.FINE, "Permissions were not found in ls command!"); } // try to parse for symlink @@ -357,12 +361,12 @@ public void output(int id, String line) { * absolute!!! */ symlink = symlinkMatcher.group(1); - Log.d(RootCommands.TAG, "Symlink found: " + symlink); + LOGGER.log(Level.FINE, "Symlink found: " + symlink); } else { - Log.d(RootCommands.TAG, "No symlink found!"); + LOGGER.log(Level.FINE, "No symlink found!"); } } catch (Exception e) { - Log.e(RootCommands.TAG, "Error with regex!", e); + LOGGER.log(Level.SEVERE, "Error with regex!", e); } } } @@ -385,12 +389,12 @@ public void afterExecution(int id, int exitCode) { */ public String getFilePermissions(String file) throws BrokenBusyboxException, TimeoutException, IOException { - Log.d(RootCommands.TAG, "Checking permissions for " + file); + LOGGER.log(Level.FINE, "Checking permissions for " + file); String permissions = null; if (fileExists(file)) { - Log.d(RootCommands.TAG, file + " was found."); + LOGGER.log(Level.FINE, file + " was found."); LsCommand lsCommand = new LsCommand(file); shell.add(lsCommand).waitForFinish(); @@ -415,7 +419,7 @@ public String getFilePermissions(String file) throws BrokenBusyboxException, Tim */ public boolean setFilePermissions(String file, String permissions) throws BrokenBusyboxException, TimeoutException, IOException { - Log.d(RootCommands.TAG, "Set permissions of " + file + " to " + permissions); + LOGGER.log(Level.FINE, "Set permissions of " + file + " to " + permissions); SimpleCommand chmodCommand = new SimpleCommand("chmod " + permissions + " " + file); shell.add(chmodCommand).waitForFinish(); @@ -441,7 +445,7 @@ public boolean setFilePermissions(String file, String permissions) */ public String getSymlink(String file) throws BrokenBusyboxException, TimeoutException, IOException { - Log.d(RootCommands.TAG, "Find symlink for " + file); + LOGGER.log(Level.FINE, "Find symlink for " + file); String symlink = null; @@ -487,7 +491,7 @@ public boolean copyFile(String source, String destination, boolean remountAsRw, // remount destination as read/write before copying to it if (remountAsRw) { if (!remount(destination, "RW")) { - Log.d(RootCommands.TAG, + LOGGER.log(Level.FINE, "Remounting failed! There is probably no need to remount this partition!"); } } @@ -525,7 +529,7 @@ public boolean copyFile(String source, String destination, boolean remountAsRw, // remount destination back to read only if (remountAsRw) { if (!remount(destination, "RO")) { - Log.d(RootCommands.TAG, + LOGGER.log(Level.FINE, "Remounting failed! There is probably no need to remount this partition!"); } } @@ -572,7 +576,7 @@ public void reboot(int action) throws BrokenBusyboxException, TimeoutException, shell.add(rebootCommand).waitForFinish(); if (rebootCommand.getExitCode() == -1) { - Log.e(RootCommands.TAG, "Reboot failed!"); + LOGGER.log(Level.SEVERE, "Reboot failed!"); } } } @@ -748,7 +752,7 @@ public String getMountedAs(String path) throws Exception { if (mounts != null) { for (Mount mount : mounts) { if (path.contains(mount.getMountPoint().getAbsolutePath())) { - Log.d(RootCommands.TAG, (String) mount.getFlags().toArray()[0]); + LOGGER.log(Level.FINE, (String) mount.getFlags().toArray()[0]); return (String) mount.getFlags().toArray()[0]; } } @@ -781,20 +785,20 @@ public boolean hasEnoughSpaceOnPartition(String target, long size) { long availableBlocks = stat.getAvailableBlocks(); long availableSpace = availableBlocks * blockSize; - Log.i(RootCommands.TAG, "Checking for enough space: Target: " + target + LOGGER.log(Level.INFO, "Checking for enough space: Target: " + target + ", directory: " + directory + " size: " + size + ", availableSpace: " + availableSpace); if (size < availableSpace) { return true; } else { - Log.e(RootCommands.TAG, "Not enough space on partition!"); + LOGGER.log(Level.SEVERE, "Not enough space on partition!"); return false; } } catch (Exception e) { // if new StatFs(directory) fails catch IllegalArgumentException and just return true as // workaround - Log.e(RootCommands.TAG, "Problem while getting available space on partition!", e); + LOGGER.log(Level.SEVERE, "Problem while getting available space on partition!", e); return true; } } diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java index 33e0f19..d1d32ba 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java @@ -20,13 +20,16 @@ import java.io.IOException; import java.io.OutputStream; import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; import org.sufficientlysecure.rootcommands.RootCommands; import org.sufficientlysecure.rootcommands.Shell; import org.sufficientlysecure.rootcommands.util.BrokenBusyboxException; -import org.sufficientlysecure.rootcommands.util.Log; public abstract class Command { + private static final Logger LOGGER = Logger.getLogger(Command.class.getName()); + final String command[]; boolean finished = false; boolean brokenBusyboxDetected = false; @@ -67,7 +70,7 @@ public String getCommand() { sb.append(command[i] + " 2>&1"); sb.append('\n'); } - Log.d(RootCommands.TAG, "Sending command(s): " + sb.toString()); + LOGGER.log(Level.FINE, "Sending command(s): " + sb.toString()); return sb.toString(); } @@ -76,7 +79,7 @@ public void writeCommand(OutputStream out) throws IOException { } public void processOutput(String line) { - Log.d(RootCommands.TAG, "ID: " + id + ", Output: " + line); + LOGGER.log(Level.FINE, "ID: " + id + ", Output: " + line); /* * Try to detect broken toolbox/busybox binaries (see @@ -86,7 +89,7 @@ public void processOutput(String line) { * and chown) in certain directories (e.g. /data/data) */ if (line.contains("Value too large for defined data type")) { - Log.e(RootCommands.TAG, "Busybox is broken with high probability due to line: " + line); + LOGGER.log(Level.SEVERE, "Busybox is broken with high probability due to line: " + line); brokenBusyboxDetected = true; } @@ -97,7 +100,7 @@ public void processOutput(String line) { public abstract void output(int id, String line); public void processAfterExecution(int exitCode) { - Log.d(RootCommands.TAG, "ID: " + id + ", ExitCode: " + exitCode); + LOGGER.log(Level.FINE, "ID: " + id + ", ExitCode: " + exitCode); afterExecution(id, exitCode); } @@ -105,16 +108,14 @@ public void processAfterExecution(int exitCode) { public abstract void afterExecution(int id, int exitCode); public void commandFinished(int id) { - Log.d(RootCommands.TAG, "Command " + id + " finished."); + LOGGER.log(Level.FINE, "Command " + id + " finished."); } - public void setExitCode(int code) { - synchronized (this) { - exitCode = code; - finished = true; - commandFinished(id); - this.notifyAll(); - } + public synchronized void setExitCode(int code) { + exitCode = code; + finished = true; + commandFinished(id); + this.notifyAll(); } /** @@ -125,7 +126,7 @@ public void setExitCode(int code) { public void terminate(String reason) { try { shell.close(); - Log.d(RootCommands.TAG, "Terminating the shell."); + LOGGER.log(Level.FINE, "Terminating the shell."); terminated(reason); } catch (IOException e) { } @@ -133,7 +134,7 @@ public void terminate(String reason) { public void terminated(String reason) { setExitCode(-1); - Log.d(RootCommands.TAG, "Command " + id + " did not finish, because of " + reason); + LOGGER.log(Level.FINE, "Command " + id + " did not finish, because of " + reason); } /** @@ -143,28 +144,26 @@ public void terminated(String reason) { * @throws TimeoutException * @throws BrokenBusyboxException */ - public void waitForFinish() throws TimeoutException, BrokenBusyboxException { - synchronized (this) { - while (!finished) { - try { - this.wait(timeout); - } catch (InterruptedException e) { - Log.e(RootCommands.TAG, "InterruptedException in waitForFinish()", e); - } - - if (!finished) { - finished = true; - terminate("Timeout"); - throw new TimeoutException("Timeout has occurred."); - } + public synchronized void waitForFinish() throws TimeoutException, BrokenBusyboxException { + while (!finished) { + try { + this.wait(timeout); + } catch (InterruptedException e) { + LOGGER.log(Level.SEVERE, "InterruptedException in waitForFinish()", e); } - if (brokenBusyboxDetected) { - throw new BrokenBusyboxException(); + if (!finished) { + finished = true; + terminate("Timeout"); + throw new TimeoutException("Timeout has occurred."); } + } - processAfterExecution(exitCode); + if (brokenBusyboxDetected) { + throw new BrokenBusyboxException(); } + + processAfterExecution(exitCode); } } \ No newline at end of file diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java deleted file mode 100644 index a25fbf4..0000000 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2012 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.sufficientlysecure.rootcommands.util; - -import org.sufficientlysecure.rootcommands.RootCommands; - -/** - * Wraps Android Logging to enable or disable debug output using Constants - * - */ -public final class Log { - - public static void v(String tag, String msg) { - if (RootCommands.DEBUG) { - android.util.Log.v(tag, msg); - } - } - - public static void v(String tag, String msg, Throwable tr) { - if (RootCommands.DEBUG) { - android.util.Log.v(tag, msg, tr); - } - } - - public static void d(String tag, String msg) { - if (RootCommands.DEBUG) { - android.util.Log.d(tag, msg); - } - } - - public static void d(String tag, String msg, Throwable tr) { - if (RootCommands.DEBUG) { - android.util.Log.d(tag, msg, tr); - } - } - - public static void i(String tag, String msg) { - if (RootCommands.DEBUG) { - android.util.Log.i(tag, msg); - } - } - - public static void i(String tag, String msg, Throwable tr) { - if (RootCommands.DEBUG) { - android.util.Log.i(tag, msg, tr); - } - } - - public static void w(String tag, String msg) { - android.util.Log.w(tag, msg); - } - - public static void w(String tag, String msg, Throwable tr) { - android.util.Log.w(tag, msg, tr); - } - - public static void w(String tag, Throwable tr) { - android.util.Log.w(tag, tr); - } - - public static void e(String tag, String msg) { - android.util.Log.e(tag, msg); - } - - public static void e(String tag, String msg, Throwable tr) { - android.util.Log.e(tag, msg, tr); - } - -} diff --git a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java index 87f32bb..c4a5a84 100644 --- a/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java +++ b/libraries/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java @@ -22,10 +22,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Map; - -import org.sufficientlysecure.rootcommands.RootCommands; +import java.util.logging.Level; +import java.util.logging.Logger; public class Utils { + private static final Logger LOGGER = Logger.getLogger(Utils.class.getName()); + /* * The emulator and ADP1 device both have a su binary in /system/xbin/su, but it doesn't allow * apps to use it (su app_29 $ su su: uid 10029 not allowed to su). @@ -49,13 +51,13 @@ public static String getSuPath() { for (String p : BinaryPlaces) { File su = new File(p + "su"); if (su.exists()) { - Log.d(RootCommands.TAG, "su found at: " + p); + LOGGER.log(Level.FINE, "su found at: " + p); return su.getAbsolutePath(); } else { - Log.v(RootCommands.TAG, "No su in: " + p); + LOGGER.log(Level.INFO, "No su in: " + p); } } - Log.d(RootCommands.TAG, "No su found in a well-known location, " + "will just use \"su\"."); + LOGGER.log(Level.FINE, "No su found in a well-known location, " + "will just use \"su\"."); return "su"; }