mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 00:01:19 +00:00
Don't disable root in SyncthingRunnable until it is stopped (ref #949)
This commit is contained in:
parent
f6cfab0a5f
commit
328b3ef273
1 changed files with 7 additions and 11 deletions
|
@ -55,6 +55,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
private String[] mCommand;
|
private String[] mCommand;
|
||||||
private final File mLogFile;
|
private final File mLogFile;
|
||||||
private final SharedPreferences mPreferences;
|
private final SharedPreferences mPreferences;
|
||||||
|
private final boolean mUseRoot;
|
||||||
|
|
||||||
public enum Command {
|
public enum Command {
|
||||||
generate, // Generate keys, a config file and immediately exit.
|
generate, // Generate keys, a config file and immediately exit.
|
||||||
|
@ -72,6 +73,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
||||||
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
||||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
mUseRoot = mPreferences.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case generate:
|
case generate:
|
||||||
mCommand = new String[]{ mSyncthingBinary, "-generate", mContext.getFilesDir().toString() };
|
mCommand = new String[]{ mSyncthingBinary, "-generate", mContext.getFilesDir().toString() };
|
||||||
|
@ -98,6 +100,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
mCommand = manualCommand;
|
mCommand = manualCommand;
|
||||||
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
||||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
mUseRoot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,7 +126,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
try {
|
try {
|
||||||
if (wakeLock != null)
|
if (wakeLock != null)
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
ProcessBuilder pb = (useRoot())
|
ProcessBuilder pb = (mUseRoot)
|
||||||
? new ProcessBuilder("su", "-c", TextUtils.join(" ", mCommand))
|
? new ProcessBuilder("su", "-c", TextUtils.join(" ", mCommand))
|
||||||
: new ProcessBuilder(mCommand);
|
: new ProcessBuilder(mCommand);
|
||||||
|
|
||||||
|
@ -215,13 +218,6 @@ public class SyncthingRunnable implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if root is available and enabled in settings.
|
|
||||||
*/
|
|
||||||
private boolean useRoot() {
|
|
||||||
return mPreferences.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the experimental setting for using wake locks has been enabled in settings.
|
* Returns true if the experimental setting for using wake locks has been enabled in settings.
|
||||||
*/
|
*/
|
||||||
|
@ -240,7 +236,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000); // Wait a second before getting the pid
|
Thread.sleep(1000); // Wait a second before getting the pid
|
||||||
nice = Runtime.getRuntime().exec((useRoot()) ? "su" : "sh");
|
nice = Runtime.getRuntime().exec((mUseRoot) ? "su" : "sh");
|
||||||
niceOut = new DataOutputStream(nice.getOutputStream());
|
niceOut = new DataOutputStream(nice.getOutputStream());
|
||||||
niceOut.writeBytes("set `ps | grep libsyncthing.so`\n");
|
niceOut.writeBytes("set `ps | grep libsyncthing.so`\n");
|
||||||
niceOut.writeBytes("ionice $2 be 7\n"); // best-effort, low priority
|
niceOut.writeBytes("ionice $2 be 7\n"); // best-effort, low priority
|
||||||
|
@ -279,7 +275,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
Process ps = null;
|
Process ps = null;
|
||||||
DataOutputStream psOut = null;
|
DataOutputStream psOut = null;
|
||||||
try {
|
try {
|
||||||
ps = Runtime.getRuntime().exec((useRoot()) ? "su" : "sh");
|
ps = Runtime.getRuntime().exec((mUseRoot) ? "su" : "sh");
|
||||||
psOut = new DataOutputStream(ps.getOutputStream());
|
psOut = new DataOutputStream(ps.getOutputStream());
|
||||||
psOut.writeBytes("ps | grep libsyncthing.so\n");
|
psOut.writeBytes("ps | grep libsyncthing.so\n");
|
||||||
psOut.writeBytes("exit\n");
|
psOut.writeBytes("exit\n");
|
||||||
|
@ -317,7 +313,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
Process kill = null;
|
Process kill = null;
|
||||||
DataOutputStream killOut = null;
|
DataOutputStream killOut = null;
|
||||||
try {
|
try {
|
||||||
kill = Runtime.getRuntime().exec((useRoot()) ? "su" : "sh");
|
kill = Runtime.getRuntime().exec((mUseRoot) ? "su" : "sh");
|
||||||
killOut = new DataOutputStream(kill.getOutputStream());
|
killOut = new DataOutputStream(kill.getOutputStream());
|
||||||
if (!force) {
|
if (!force) {
|
||||||
killOut.writeBytes("kill -SIGINT " + id + "\n");
|
killOut.writeBytes("kill -SIGINT " + id + "\n");
|
||||||
|
|
Loading…
Reference in a new issue