Skip to content
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
84 changes: 71 additions & 13 deletions liveBootAni2/src/main/java/eu/chainfire/liveboot/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.StatFs;
import android.view.Display;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import eu.chainfire.librootjava.AppProcess;
import eu.chainfire.librootjava.Logger;
Expand All @@ -42,7 +46,7 @@
public class Installer {
public enum Mode { SU_D, INIT_D, SU_SU_D, SBIN_SU_D, MAGISK_CORE, MAGISK_ADB, KERNELSU }

private static final int LAST_SCRIPT_UPDATE = 188;
private static final int LAST_SCRIPT_UPDATE = 195;
private static final String[] SYSTEM_SCRIPTS_SU_D = new String[] { "/system/su.d/0000liveboot" };
private static final String[] SYSTEM_SCRIPTS_INIT_D = new String[] { "/system/etc/init.d/0000liveboot" };
private static final String[] SYSTEM_SCRIPTS_SU_SU_D = new String[] { "/su/su.d/0000liveboot" };
Expand Down Expand Up @@ -136,22 +140,64 @@ public static boolean installNeeded(Context context, Mode mode) {
return installNeededVersion(settings) || installNeededData(context) || installNeededScript(context, mode);
}

public static synchronized Point getScreenDimensions() {
private static long getArea(int width, int height) {
return (long) width * (long) height;
}

private static boolean isBetterDimensions(int width, int height, Point currentBest) {
if (width <= 0 || height <= 0) return false;
long candidateArea = getArea(width, height);
long currentArea = getArea(currentBest.x, currentBest.y);
return (candidateArea > currentArea) ||
((candidateArea == currentArea) && ((width > currentBest.x) || ((width == currentBest.x) && (height > currentBest.y))));
}

private static Point getScreenDimensionsFromDisplayManager(Context context) {
Point ret = new Point(0, 0);
try {
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
if (displayManager != null) {
Display defaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
if (defaultDisplay != null) {
Point size = new Point();
defaultDisplay.getRealSize(size);
if (size.x > 0 && size.y > 0) {
ret.set(size.x, size.y);
return ret;
}
}

Display[] displays = displayManager.getDisplays();
if (displays != null) {
for (Display display : displays) {
if (display == null) continue;
Point size = new Point();
display.getRealSize(size);
if (isBetterDimensions(size.x, size.y, ret)) {
ret.set(size.x, size.y);
}
}
}
}
} catch(Exception e) {
Logger.ex(e);
}
return ret;
}

private static Point getScreenDimensionsFromDumpsys() {
Point ret = new Point(0, 0);
Pattern realPattern = Pattern.compile("\\breal\\s+(\\d+)\\s*x\\s*(\\d+)\\b", Pattern.CASE_INSENSITIVE);
try {
List<String> output = Shell.SU.run("dumpsys display | grep -i real | grep -vi overridedisplay");
if (output != null) {
for (String line : output) {
String[] parts = line.split(",");
for (int i = 0; i < parts.length; i++) {
if (parts[i].contains("real")) {
String[] sub = parts[i].split(" ");
for (int j = 0; j < sub.length; j++) {
if (sub[j].equals("real")) {
ret.x = Integer.valueOf(sub[j + 1], 10);
ret.y = Integer.valueOf(sub[j + 3], 10);
}
}
Matcher matcher = realPattern.matcher(line);
while (matcher.find()) {
int width = Integer.parseInt(matcher.group(1), 10);
int height = Integer.parseInt(matcher.group(2), 10);
if (isBetterDimensions(width, height, ret)) {
ret.set(width, height);
}
}
}
Expand All @@ -161,6 +207,17 @@ public static synchronized Point getScreenDimensions() {
}
return ret;
}

public static synchronized Point getScreenDimensions(Context context) {
Point ret = new Point(0, 0);
if (context != null) {
ret = getScreenDimensionsFromDisplayManager(directBootContext(context));
}
if (ret.x <= 0 || ret.y <= 0) {
ret = getScreenDimensionsFromDumpsys();
}
return ret;
}

public static synchronized List<String> getLaunchScript(Context context, boolean boot) {
Settings settings = Settings.getInstance(context);
Expand All @@ -187,9 +244,10 @@ public static synchronized List<String> getLaunchScript(Context context, boolean
if (!settings.LOGCAT_COLORS.get()) params.add("logcatnocolors");
params.add("dmesg=" + ((settings.DMESG.get() && (boot || !haveLogcat)) ? Settings.DMESG_ALL : Settings.DMESG_NONE));
params.add("lines=" + settings.LINES.get());
params.add("suicidedelay=" + settings.SUICIDE_DELAY_MS.get());
if (settings.WORD_WRAP.get()) params.add("wordwrap");
if (settings.SAVE_LOGS.get() && boot) params.add("save");
Point dms = getScreenDimensions();
Point dms = getScreenDimensions(context);
params.add("fallbackwidth=" + dms.x);
params.add("fallbackheight=" + dms.y);
String relocate = AppProcess.shouldAppProcessBeRelocated() ? "/dev" : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public SharedPreferences getPrefs() {
public BooleanSetting DMESG = new BooleanSetting(this, "dmesg", true);

public StringSetting LINES = new StringSetting(this, "lines", "80");
public StringSetting SUICIDE_DELAY_MS = new StringSetting(this, "suicide_delay_ms", "0");
public BooleanSetting WORD_WRAP = new BooleanSetting(this, "word_wrap", true);

public BooleanSetting SAVE_LOGS = new BooleanSetting(this, "save_logs", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.MultiSelectListPreference;
import android.preference.Preference;
Expand All @@ -39,6 +40,7 @@
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.text.InputType;

import eu.chainfire.librootjava.Logger;
import eu.chainfire.libsuperuser.Shell;
Expand All @@ -51,6 +53,8 @@
import java.util.Set;

public class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
private static final int MAX_SUICIDE_DELAY_MS = 60000;

private String APP_TITLE = "";
private SharedPreferences prefs = null;
private Settings settings = null;
Expand All @@ -59,6 +63,7 @@ public class SettingsFragment extends PreferenceFragment implements OnSharedPref
private MultiSelectListPreference prefLogcatBuffers = null;
private ListPreference prefLogcatFormat = null;
private ListPreference prefLines = null;
private EditTextPreference prefSuicideDelay = null;

private InAppPurchases iap = null;
private volatile boolean pro = false;
Expand Down Expand Up @@ -397,6 +402,21 @@ private void disableIfNoRoot(Activity activity, Preference preference, boolean h
}
}

private String normalizeSuicideDelayValue(Object value) {
String normalized = value == null ? settings.SUICIDE_DELAY_MS.defaultValue : String.valueOf(value).trim();
if (normalized.length() == 0) {
normalized = settings.SUICIDE_DELAY_MS.defaultValue;
}
try {
long parsed = Long.parseLong(normalized, 10);
if (parsed < 0) parsed = 0;
if (parsed > MAX_SUICIDE_DELAY_MS) parsed = MAX_SUICIDE_DELAY_MS;
return String.valueOf(parsed);
} catch (Exception e) {
return settings.SUICIDE_DELAY_MS.defaultValue;
}
}

private PreferenceScreen createPreferenceHierarchy(boolean haveRoot) {
final Activity activity = getActivity();
if (activity == null) return null;
Expand Down Expand Up @@ -574,6 +594,21 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
"160"
};
prefLines = Pref.List(activity, catOptions, R.string.settings_lines_title, 0, R.string.settings_lines_title, settings.LINES.name, settings.LINES.defaultValue, lines, lines, true);

prefSuicideDelay = Pref.Edit(activity, catOptions, R.string.settings_suicide_delay_title, 0, R.string.settings_suicide_delay_title, settings.SUICIDE_DELAY_MS.name, settings.SUICIDE_DELAY_MS.defaultValue, InputType.TYPE_CLASS_NUMBER);
prefSuicideDelay.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
EditTextPreference editPreference = (EditTextPreference) preference;
String normalized = normalizeSuicideDelayValue(newValue);
editPreference.setText(normalized);
if (!normalized.equals(String.valueOf(newValue).trim())) {
settings.SUICIDE_DELAY_MS.set(normalized);
return false;
}
return true;
}
});

Pref.Check(activity, catOptions, R.string.settings_wordwrap_title, R.string.settings_wordwrap_description, settings.WORD_WRAP.name, settings.WORD_WRAP.defaultValue);

Expand Down Expand Up @@ -774,7 +809,21 @@ private void updatePrefs(String key) {
));
}
}


if ((key == null) || key.equals(settings.SUICIDE_DELAY_MS.name)) {
String normalized = normalizeSuicideDelayValue(settings.SUICIDE_DELAY_MS.get());
if (!normalized.equals(settings.SUICIDE_DELAY_MS.get())) {
settings.SUICIDE_DELAY_MS.set(normalized);
}
if (prefSuicideDelay != null) {
prefSuicideDelay.setText(normalized);
prefSuicideDelay.setSummary(String.format(Locale.ENGLISH, "%s\n[ %s ms ]",
getString(R.string.settings_suicide_delay_description),
normalized
));
}
}

if (key != null) {
if (activity != null) {
(new Thread(new Runnable() {
Expand Down
Loading