Skip to content

Replace util/Log.java with java.util.logging #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -64,29 +67,29 @@ 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;
break;
}
}
} 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));

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -175,7 +178,7 @@ protected static ArrayList<Mount> getMounts() throws Exception {
ArrayList<Mount> mounts = new ArrayList<Mount>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,6 +38,8 @@ public class Shell implements Closeable {
private final List<Command> commands = new ArrayList<Command>();
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";

Expand All @@ -50,7 +53,7 @@ public class Shell implements Closeable {
*/
public static Shell startRootShell(ArrayList<String> 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.
Expand Down Expand Up @@ -84,7 +87,7 @@ public static Shell startRootShell() throws IOException, RootAccessDeniedExcepti
*/
public static Shell startShell(ArrayList<String> 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;
}
Expand All @@ -110,7 +113,7 @@ public static Shell startShell() throws IOException {
*/
public static Shell startCustomShell(String shellPath, ArrayList<String> 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;
Expand All @@ -129,7 +132,7 @@ public static Shell startCustomShell(String shellPath) throws IOException {

private Shell(String shell, ArrayList<String> 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);
Expand Down Expand Up @@ -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);
}
}
};
Expand All @@ -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);
}
}
};
Expand All @@ -198,7 +201,7 @@ private void destroyShellProcess() {
shellProcess.destroy();
}

Log.d(RootCommands.TAG, "Shell destroyed");
LOGGER.log(Level.FINE, "Shell destroyed");
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.sufficientlysecure.rootcommands;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
Expand Down Expand Up @@ -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);
Expand Down
Loading