Commit 7a072f4c authored by Румен Петров's avatar Румен Петров
Browse files

do not install wrapper scrips on Android 10

Also replace bindir with scriptdir and postpone assigment.
parent 11893cf4
......@@ -47,8 +47,8 @@ public class Application extends android.app.Application {
public static File rootdir;
public static File etcdir;
public static File xbindir;
public static File bindir;
public static File libdir;
public static File scriptdir; /*for backward compatibility*/
private boolean installed = false;
private Intent paths_intent;
......@@ -81,7 +81,6 @@ public class Application extends android.app.Application {
rootdir = getFilesDir().getParentFile();
etcdir = new File(rootdir, "etc");
bindir = new File(rootdir, "bin");
libdir = new File(getApplicationInfo().nativeLibraryDir);
xbindir = libdir;
......@@ -118,7 +117,6 @@ public class Application extends android.app.Application {
r = rootdir.setExecutable(true, false) &&
Installer.install_directory(etcdir, false) &&
Installer.install_directory(bindir, true) &&
install_public_directory(piddir);
if (!r) return false;
......@@ -134,6 +132,19 @@ public class Application extends android.app.Application {
}
}
// Andorid 10 does not allow excution from writable directories.
// So terminal application must be version that supports aliases.
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q /* API Level 29 */)
{// clean-up obsolete wrapper scripts
File dir = new File(rootdir, "bin");
if (dir.exists()) {
for (String item : dir.list()) {
new File(dir, item).delete();
}
dir.delete();
}
}
AssetManager am = getAssets();
try {
String asset_path = "etc";
......@@ -160,10 +171,13 @@ public class Application extends android.app.Application {
if (!r) return false;
}
r = Installer.install_wrapper_scripts();
if (!r) return false;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q /* API Level 29 */) {
// Must be after final set of xbindir above.
r = Installer.install_wrapper_scripts();
if (!r) return false;
}
return r;
return true;
}
protected final boolean install_public_directory(File dir) {
......
......@@ -196,6 +196,10 @@ public class Installer {
public static boolean install_wrapper_scripts() {
boolean r;
File bindir = new File(Application.rootdir, "bin");
r = install_directory(bindir, true);
if (!r) return false;
// Note that some ancient Android shell lack test command!
final String[] env_script = {
"#! " + Application._PATH_BSHELL,
......@@ -230,13 +234,13 @@ public class Installer {
Matcher matcher = pattern.matcher(item);
if (!matcher.find()) continue;
r = install_shell_script(shell_script, Application.bindir, matcher.group(1));
r = install_shell_script(shell_script, bindir, matcher.group(1));
if (!r) return false;
}
}
{// openssl command aliases
File openssl = new File(Application.bindir, "openssl");
File openssl = new File(bindir, "openssl");
if (openssl.exists()) {
for (String cmd : openssl_aliases) {
String[] cmd_script = {
......@@ -244,12 +248,13 @@ public class Installer {
"",
openssl.getPath() + " " + cmd + " ${1+\"$@\"}"
};
r = install_shell_script(cmd_script, Application.bindir, cmd);
r = install_shell_script(cmd_script, bindir, cmd);
if (!r) return false;
}
}
}
Application.scriptdir = bindir;
return true;
}
}
......@@ -175,20 +175,24 @@ public class MainActivity extends AppCompatActivity {
}
private void animateExportPath(TextView export_path) {
// No wrapper scripts on Android 10!
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q /* API Level 29 */)
return;
for (int k = 100; k > 0; k--) {
if (Application.bindir != null) break;
if (Application.scriptdir != null) break;
try {
wait(100/*milliseconds*/);
} catch (InterruptedException e) {
//e.printStackTrace();
}
}
if (Application.bindir == null) return;
if (Application.scriptdir == null) return;
{
Resources res = getResources();
String text = res.getString(R.string.export_path, Application.bindir.getPath());
String text = res.getString(R.string.export_path, Application.scriptdir.getPath());
Spanned formatted = compatFromHtml(text);
......
......@@ -38,9 +38,10 @@ public class PathBroadcast extends BroadcastReceiver {
switch (action) {
case ACTION_PATH_PREPEND_BROADCAST: {
if (Application.scriptdir == null) break;
/* The directory we want prepended goes into the result extras */
Bundle result = getResultExtras(true);
result.putString(packageName, Application.bindir.getPath());
result.putString(packageName, Application.scriptdir.getAbsolutePath());
setResultCode(Activity.RESULT_OK);
break;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment