mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(common): do not hardcode package name in Environment class
This is required so that we can use the Env class in androidTest (which have a different package name).
This commit is contained in:
@@ -57,7 +57,6 @@ public class IDEDocumentsProvider extends DocumentsProvider {
|
||||
|
||||
private static final String ALL_MIME_TYPES = "*/*";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(IDEDocumentsProvider.class);
|
||||
private static final File BASE_DIR = getBaseDir();
|
||||
// The default columns to return information about a root if no specific
|
||||
// columns are requested in a query.
|
||||
private static final String[] DEFAULT_ROOT_PROJECTION =
|
||||
@@ -84,12 +83,12 @@ public class IDEDocumentsProvider extends DocumentsProvider {
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private static File getBaseDir() {
|
||||
if (Environment.HOME != null) {
|
||||
return Environment.HOME;
|
||||
private File getBaseDir() {
|
||||
if (Environment.HOME == null) {
|
||||
Environment.init(getContext());
|
||||
}
|
||||
|
||||
return new File(Environment.DEFAULT_HOME);
|
||||
return Environment.HOME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,9 +141,9 @@ public class IDEDocumentsProvider extends DocumentsProvider {
|
||||
|
||||
final MatrixCursor.RowBuilder row = result.newRow();
|
||||
LOG.debug("queryRoots() before all add");
|
||||
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
|
||||
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(getBaseDir()));
|
||||
LOG.debug("queryRoots() before all add, 1");
|
||||
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR));
|
||||
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(getBaseDir()));
|
||||
LOG.debug("queryRoots() before all add, 2");
|
||||
row.add(Root.COLUMN_SUMMARY, null);
|
||||
LOG.debug("queryRoots() before all add, 3");
|
||||
@@ -156,7 +155,7 @@ public class IDEDocumentsProvider extends DocumentsProvider {
|
||||
LOG.debug("queryRoots() before all add, 5");
|
||||
row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
|
||||
LOG.debug("queryRoots() before all add, 6");
|
||||
row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
|
||||
row.add(Root.COLUMN_AVAILABLE_BYTES, getBaseDir().getFreeSpace());
|
||||
LOG.debug("queryRoots() before all add, 7");
|
||||
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
|
||||
LOG.debug("queryRoots() before all add");
|
||||
|
||||
@@ -52,7 +52,7 @@ public class BaseApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
instance = this;
|
||||
Environment.init();
|
||||
Environment.init(this);
|
||||
super.onCreate();
|
||||
|
||||
mPrefsManager = new PreferenceManager(this);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.itsaky.androidide.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -33,12 +34,6 @@ import java.util.UUID;
|
||||
public final class Environment {
|
||||
|
||||
public static final String PROJECTS_FOLDER = "AndroidIDEProjects";
|
||||
public static final String DEFAULT_ROOT = "/data/data/com.itsaky.androidide/files";
|
||||
public static final String DEFAULT_HOME = DEFAULT_ROOT + "/home";
|
||||
private static final String DEFAULT_ANDROID_HOME = DEFAULT_HOME + "/android-sdk";
|
||||
public static final String DEFAULT_PREFIX = DEFAULT_ROOT + "/usr";
|
||||
public static final String DEFAULT_JAVA_HOME = DEFAULT_PREFIX + "/opt/openjdk";
|
||||
private static final String ANDROIDIDE_PROJECT_CACHE_DIR = ".androidide";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
|
||||
public static File ROOT;
|
||||
public static File PREFIX;
|
||||
@@ -67,10 +62,10 @@ public final class Environment {
|
||||
public static File BASH_SHELL;
|
||||
public static File LOGIN_SHELL;
|
||||
|
||||
public static void init() {
|
||||
ROOT = mkdirIfNotExits(new File(DEFAULT_ROOT));
|
||||
PREFIX = mkdirIfNotExits(new File(DEFAULT_PREFIX));
|
||||
HOME = mkdirIfNotExits(new File(DEFAULT_HOME));
|
||||
public static void init(Context context) {
|
||||
ROOT = context.getFilesDir();
|
||||
PREFIX = mkdirIfNotExits(new File(ROOT, "usr"));
|
||||
HOME = mkdirIfNotExits(new File(ROOT, "home"));
|
||||
ANDROIDIDE_HOME = mkdirIfNotExits(new File(HOME, ".androidide"));
|
||||
TMP_DIR = mkdirIfNotExits(new File(PREFIX, "tmp"));
|
||||
BIN_DIR = mkdirIfNotExits(new File(PREFIX, "bin"));
|
||||
@@ -86,8 +81,8 @@ public final class Environment {
|
||||
INIT_SCRIPT = new File(mkdirIfNotExits(new File(ANDROIDIDE_HOME, "init")), "init.gradle");
|
||||
GRADLE_USER_HOME = new File(HOME, ".gradle");
|
||||
|
||||
ANDROID_HOME = new File(DEFAULT_ANDROID_HOME);
|
||||
JAVA_HOME = new File(DEFAULT_JAVA_HOME);
|
||||
ANDROID_HOME = new File(HOME, "android-sdk");
|
||||
JAVA_HOME = new File(PREFIX, "opt/openjdk");
|
||||
|
||||
JAVA = new File(JAVA_HOME, "bin/java");
|
||||
BASH_SHELL = new File(BIN_DIR, "bash");
|
||||
@@ -109,7 +104,7 @@ public final class Environment {
|
||||
|
||||
public static void setExecutable(@NonNull final File file) {
|
||||
if (!file.setExecutable(true)) {
|
||||
LOG.error("Unable to set executable permissions to file", file);
|
||||
LOG.error("Unable to set executable permissions to file: {}", file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +131,7 @@ public final class Environment {
|
||||
}
|
||||
|
||||
public static File getProjectCacheDir(File projectDir) {
|
||||
return new File(projectDir, ANDROIDIDE_PROJECT_CACHE_DIR);
|
||||
return new File(projectDir, ".androidide");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
+2
-1
@@ -44,7 +44,8 @@ dependencyResolutionManagement {
|
||||
"jdk-compiler",
|
||||
"jdk-jdeps",
|
||||
"jdt",
|
||||
"layoutlib-api"
|
||||
"layoutlib-api",
|
||||
"logback-core"
|
||||
),
|
||||
|
||||
"build-deps-common" to arrayOf(
|
||||
|
||||
Reference in New Issue
Block a user