Skip to content
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

use native lib dir instead of assets to pack rclone executables #241

Open
wants to merge 2 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
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ["lib"]
}
}
}

repositories {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 2 additions & 46 deletions app/src/main/java/ca/pkay/rcloneexplorer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,15 @@ public void onClick(View v) {
int currentVersionCode = BuildConfig.VERSION_CODE;
String currentVersionName = BuildConfig.VERSION_NAME;

if (!rclone.isRcloneBinaryCreated()) {
new CreateRcloneBinary().execute();
} else if (lastVersionCode < currentVersionCode || !lastVersionName.equals(currentVersionName)) {
if (lastVersionCode < currentVersionCode || !lastVersionName.equals(currentVersionName)) {
// In version code 24 there were changes to app shortcuts
// Remove this in the long future
if (lastVersionCode <= 23) {
AppShortcutsHelper.removeAllAppShortcuts(this);
AppShortcutsHelper.populateAppShortcuts(this, rclone.getRemotes());
}

new CreateRcloneBinary().execute();
startRemotesFragment();

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(getString(R.string.pref_key_version_code), currentVersionCode);
Expand Down Expand Up @@ -513,48 +511,6 @@ public void removeRemoteFromNavDrawer() {
pinRemotesToDrawer();
}

@SuppressLint("StaticFieldLeak")
private class CreateRcloneBinary extends AsyncTask<Void, Void, Boolean> {

private LoadingDialog loadingDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog = new LoadingDialog()
.setTitle(R.string.creating_rclone_binary)
.setCanCancel(false);
loadingDialog.show(getSupportFragmentManager(), "loading dialog");
}

@Override
protected Boolean doInBackground(Void... voids) {
try {
rclone.createRcloneBinary();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}

@Override
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
if (!success) {
Toasty.error(context, getString(R.string.error_creating_rclone_binary), Toast.LENGTH_LONG, true).show();
finish();
System.exit(0);
}
if (loadingDialog.isStateSaved()) {
loadingDialog.dismissAllowingStateLoss();
} else {
loadingDialog.dismiss();
}
startRemotesFragment();
}
}

@SuppressLint("StaticFieldLeak")
private class CopyConfigFile extends AsyncTask<Uri, Void, Boolean> {

Expand Down
45 changes: 1 addition & 44 deletions app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.webkit.MimeTypeMap;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class Rclone {

public Rclone(Context context) {
this.context = context;
this.rclone = context.getFilesDir().getPath() + "/rclone";
this.rclone = context.getApplicationInfo().nativeLibraryDir + "/librclone.so";
this.rcloneConf = context.getFilesDir().getPath() + "/rclone.conf";
log2File = new Log2File(context);
}
Expand Down Expand Up @@ -844,46 +843,4 @@ public void exportConfigFile(Uri uri) throws IOException {
outputStream.flush();
outputStream.close();
}

public boolean isRcloneBinaryCreated() {
String appsFileDir = context.getFilesDir().getPath();
String exeFilePath = appsFileDir + "/rclone";
File file = new File(exeFilePath);
return file.exists() && file.canExecute();
}

public void createRcloneBinary() throws IOException {
String appsFileDir = context.getFilesDir().getPath();
String rcloneArchitecture = null;
String[] supportedABIS = Build.SUPPORTED_ABIS;
if (supportedABIS[0].toUpperCase().contains("ARM")) {
if (supportedABIS[0].contains("64")) {
rcloneArchitecture = "rclone-arm64";
} else {
rcloneArchitecture = "rclone-arm32";
}
} else if (supportedABIS[0].toUpperCase().contains("X86")) {
if (supportedABIS[0].contains("64")) {
rcloneArchitecture = "rclone-x86_32";
} else {
rcloneArchitecture = "rclone-x86_32";
}
} else {
System.exit(1);
}
String exeFilePath = appsFileDir + "/rclone";
InputStream inputStream = context.getAssets().open(rcloneArchitecture);
File outFile = new File(appsFileDir, "rclone");
FileOutputStream fileOutputStream = new FileOutputStream(outFile);

byte[] buffer = new byte[4096];
int offset;
while ((offset = inputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, offset);
}
inputStream.close();
fileOutputStream.close();

Runtime.getRuntime().exec("chmod 0777 " + exeFilePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return;
}

if (!rclone.isRcloneBinaryCreated() || rclone.isConfigEncrypted() || !rclone.isConfigFileCreated() || rclone.getRemotes().isEmpty()) {
if (rclone.isConfigEncrypted() || !rclone.isConfigFileCreated() || rclone.getRemotes().isEmpty()) {
AlertDialog.Builder builder;
if (isDarkTheme) {
builder = new AlertDialog.Builder(this, R.style.DarkDialogTheme);
Expand Down