mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Refactor some code
This commit is contained in:
Generated
+1
@@ -72,6 +72,7 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
/************************************************************************************
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
@@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
**************************************************************************************/
|
||||
*/
|
||||
package com.itsaky.androidide.managers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -36,10 +36,10 @@ public class ToolsManager {
|
||||
private static PreferenceManager prefs;
|
||||
|
||||
public static final int JLS_VERSION = 27;
|
||||
public static final int LOGSENDER_VERSION = 2;
|
||||
public static final int LOG_SENDER_VERSION = 2;
|
||||
|
||||
public static final String KEY_JLS_VERSION = "tools_jlsVersion";
|
||||
public static final String KEY_LOGSENDER_VERSION = "tools_logsenderVersion";
|
||||
public static final String KEY_LOG_SENDER_VERSION = "tools_logsenderVersion";
|
||||
|
||||
public static String ARCH_SPECIFIC_ASSET_DATA_DIR = "data/" + BaseApplication.getArch();
|
||||
public static String COMMON_ASSET_DATA_DIR = "data/common";
|
||||
@@ -55,17 +55,18 @@ public class ToolsManager {
|
||||
|
||||
rewriteProjectData();
|
||||
|
||||
if(onFinish != null)
|
||||
if(onFinish != null) {
|
||||
onFinish.run();
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractLibHooks() {
|
||||
if(!Environment.LIBHOOK.exists()) {
|
||||
ResourceUtils.copyFileFromAssets(getArchSpecificAsset("libhook.so"), Environment.LIBHOOK.getAbsolutePath());
|
||||
if(!Environment.LIB_HOOK.exists()) {
|
||||
ResourceUtils.copyFileFromAssets(getArchSpecificAsset("libhook.so"), Environment.LIB_HOOK.getAbsolutePath());
|
||||
}
|
||||
|
||||
if(!Environment.LIBHOOK2.exists()) {
|
||||
ResourceUtils.copyFileFromAssets(getArchSpecificAsset("libhook2.so"), Environment.LIBHOOK2.getAbsolutePath());
|
||||
if(!Environment.LIB_HOOK2.exists()) {
|
||||
ResourceUtils.copyFileFromAssets(getArchSpecificAsset("libhook2.so"), Environment.LIB_HOOK2.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +80,9 @@ public class ToolsManager {
|
||||
Environment.mkdirIfNotExits(exec.getParentFile());
|
||||
ResourceUtils.copyFileFromAssets(getArchSpecificAsset("busybox"), exec.getAbsolutePath());
|
||||
if(!exec.canExecute()) {
|
||||
exec.setExecutable(true);
|
||||
if (!exec.setExecutable(true)) {
|
||||
LOG.error ("Cannot set busybox executable permissions.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,12 +113,12 @@ public class ToolsManager {
|
||||
|
||||
private static void extractLogsenderIfNeeded() {
|
||||
try {
|
||||
final boolean isOld = LOGSENDER_VERSION > prefs.getInt(KEY_LOGSENDER_VERSION, 0);
|
||||
final boolean isOld = LOG_SENDER_VERSION > prefs.getInt(KEY_LOG_SENDER_VERSION, 0);
|
||||
if(isOld) {
|
||||
final File logsenderZip = new File(Environment.JLS_HOME, "logsender.zip");
|
||||
ResourceUtils.copyFileFromAssets(getCommonAsset("logsender.zip"), logsenderZip.getAbsolutePath());
|
||||
ZipUtils.unzipFile(logsenderZip, Environment.HOME);
|
||||
prefs.putInt(KEY_LOGSENDER_VERSION, LOGSENDER_VERSION);
|
||||
prefs.putInt(KEY_LOG_SENDER_VERSION, LOG_SENDER_VERSION);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error extracting log sender", e);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Installs the bootstraps zip into {@code $SYSROOT}.
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
public class BootstrapInstaller {
|
||||
|
||||
public static void doInstall (final InputStream in) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,9 @@ package com.itsaky.androidide.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.FileIOUtils;
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import java.io.File;
|
||||
@@ -40,12 +43,12 @@ public final class Environment {
|
||||
public static final File ANDROID_HOME;
|
||||
public static final File JLS_HOME;
|
||||
public static final File TMP_DIR;
|
||||
public static final File BINDIR;
|
||||
public static final File LIBDIR;
|
||||
public static final File BIN_DIR;
|
||||
public static final File LIB_DIR;
|
||||
public static final File PROJECTS_DIR;
|
||||
public static final File IDEPROPS;
|
||||
public static final File LIBHOOK;
|
||||
public static final File LIBHOOK2;
|
||||
public static final File IDE_PROPS_FILE;
|
||||
public static final File LIB_HOOK;
|
||||
public static final File LIB_HOOK2;
|
||||
|
||||
public static final File INIT_SCRIPT;
|
||||
public static final File PROJECT_DATA_FILE;
|
||||
@@ -79,13 +82,13 @@ public final class Environment {
|
||||
HOME = mkdirIfNotExits(app.getRootDir());
|
||||
JLS_HOME = mkdirIfNotExits(new File(app.getIDEDataDir(), "jls"));
|
||||
TMP_DIR = mkdirIfNotExits(new File(SYSROOT, "tmp"));
|
||||
BINDIR = mkdirIfNotExits(new File(SYSROOT, "bin"));
|
||||
LIBDIR = mkdirIfNotExits(new File(SYSROOT, "lib"));
|
||||
BIN_DIR = mkdirIfNotExits(new File(SYSROOT, "bin"));
|
||||
LIB_DIR = mkdirIfNotExits(new File(SYSROOT, "lib"));
|
||||
PROJECTS_DIR = mkdirIfNotExits(new File(FileUtil.getExternalStorageDir(), PROJECTS_FOLDER));
|
||||
|
||||
IDEPROPS = new File(SYSROOT, "etc/ide-environment.properties");
|
||||
LIBHOOK = new File(LIBDIR, "libhook.so");
|
||||
LIBHOOK2 = new File(LIBDIR, "libhook2.so");
|
||||
IDE_PROPS_FILE = new File(SYSROOT, "etc/ide-environment.properties");
|
||||
LIB_HOOK = new File(LIB_DIR, "libhook.so");
|
||||
LIB_HOOK2 = new File(LIB_DIR, "libhook2.so");
|
||||
PROJECT_DATA_FILE = new File(TMP_DIR, "ide_project");
|
||||
JLS_JAR = new File(JLS_HOME, "jls.jar");
|
||||
|
||||
@@ -99,9 +102,9 @@ public final class Environment {
|
||||
JAVA_HOME = new File(readProp("JAVA_HOME", DEFAULT_JAVA_HOME));
|
||||
|
||||
JAVA = new File(JAVA_HOME, "bin/java");
|
||||
BUSYBOX = new File(BINDIR, "busybox");
|
||||
SHELL = new File(BINDIR, "sh.sh");
|
||||
BUSYBOX_SH = new File (BINDIR, "sh");
|
||||
BUSYBOX = new File(BIN_DIR, "busybox");
|
||||
SHELL = new File(BIN_DIR, "sh.sh");
|
||||
BUSYBOX_SH = new File (BIN_DIR, "sh");
|
||||
|
||||
if(!JAVA.canExecute()) {
|
||||
JAVA.setExecutable(true);
|
||||
@@ -119,12 +122,13 @@ public final class Environment {
|
||||
System.setProperty("java.home", JAVA_HOME.getAbsolutePath());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Map<String, String> readProperties() {
|
||||
final Map<String, String> props = new HashMap<>();
|
||||
if(IDEPROPS == null || !IDEPROPS.exists()) return props;
|
||||
if(IDE_PROPS_FILE == null || !IDE_PROPS_FILE.exists()) return props;
|
||||
try {
|
||||
Properties p = new Properties();
|
||||
p.load(new StringReader(FileIOUtils.readFile2String(IDEPROPS)));
|
||||
p.load(new StringReader(FileIOUtils.readFile2String(IDE_PROPS_FILE)));
|
||||
for(Map.Entry entry : p.entrySet()) {
|
||||
props.put(entry.getKey() + "", entry.getValue() + "");
|
||||
}
|
||||
@@ -134,7 +138,7 @@ public final class Environment {
|
||||
return props;
|
||||
}
|
||||
|
||||
public static void setBootClasspath(File file) {
|
||||
public static void setBootClasspath(@NonNull File file) {
|
||||
BOOTCLASSPATH = new File(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
@@ -164,20 +168,20 @@ public final class Environment {
|
||||
ENV_VARS.put("SHELL", SHELL.getAbsolutePath());
|
||||
ENV_VARS.put("CONFIG_SHELL", SHELL.getAbsolutePath());
|
||||
ENV_VARS.put("TERM", "screen");
|
||||
|
||||
/**
|
||||
* If LD_LIBRARY_PATH is set, append $SYSROOT/lib to it,
|
||||
* else set it to $SYSROOT/lib
|
||||
*/
|
||||
|
||||
// If LD_LIBRARY_PATH is set, append $SYSROOT/lib to it,
|
||||
// else set it to $SYSROOT/lib
|
||||
String ld = System.getenv("LD_LIBRARY_PATH");
|
||||
if(ld == null || ld.trim().length() <= 0)
|
||||
if(ld == null || ld.trim().length() <= 0) {
|
||||
ld = "";
|
||||
else ld += File.pathSeparator;
|
||||
ld += LIBDIR.getAbsolutePath();
|
||||
} else {
|
||||
ld += File.pathSeparator;
|
||||
}
|
||||
ld += LIB_DIR.getAbsolutePath();
|
||||
ENV_VARS.put("LD_LIBRARY_PATH", ld);
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && BaseApplication.isAarch64()) {
|
||||
ENV_VARS.put("LD_PRELOAD", LIBHOOK.getAbsolutePath());
|
||||
ENV_VARS.put("LD_PRELOAD", LIB_HOOK.getAbsolutePath());
|
||||
}
|
||||
|
||||
addToEnvIfPresent(ENV_VARS, "ANDROID_ART_ROOT");
|
||||
@@ -193,9 +197,7 @@ public final class Environment {
|
||||
ENV_VARS.put("PATH", path);
|
||||
|
||||
for (String key : IDE_PROPS.keySet()) {
|
||||
if (blacklistedVariables().contains(key.trim())) {
|
||||
continue;
|
||||
} else {
|
||||
if (!blacklistedVariables ().contains (key.trim ())) {
|
||||
ENV_VARS.put(key, readProp(key, ""));
|
||||
}
|
||||
}
|
||||
@@ -203,6 +205,7 @@ public final class Environment {
|
||||
return ENV_VARS;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String createPath() {
|
||||
String path = "";
|
||||
path += String.format("%s/bin", JAVA_HOME.getAbsolutePath());
|
||||
@@ -241,7 +244,8 @@ public final class Environment {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String path(File file) {
|
||||
@NonNull
|
||||
public static String path(@NonNull File file) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user