1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Fix leftover SyncthingNative instance after update in root mode (fixes #261) (#284)

* Reformat code

* Fix leftover SyncthingNative instance after update in root mode (fixes #261)
This commit is contained in:
Catfriend1 2019-01-27 20:01:18 +01:00 committed by GitHub
parent 78ba036df7
commit e4dae20a3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,20 +6,41 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log;
import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.service.SyncthingRunnable;
import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingService;
import eu.chainfire.libsuperuser.Shell;
public class BootReceiver extends BroadcastReceiver { public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "BootReceiver";
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) && Boolean bootCompleted = intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED);
!intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED)) Boolean packageReplaced = intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED);
if (!bootCompleted && !packageReplaced) {
return; return;
}
if (!startServiceOnBoot(context)) if (packageReplaced) {
if (getPrefUseRoot(context) && Shell.SU.available()) {
/**
* In Root mode, there will be a SyncthingNative process left running after app update.
* See https://github.com/Catfriend1/syncthing-android/issues/261
*/
Log.d(TAG, "ACTION_MY_PACKAGE_REPLACED: Killing leftover SyncthingNative instance if present ...");
new SyncthingRunnable(context, SyncthingRunnable.Command.main).killSyncthing();
}
}
// Check if we should (re)start now.
if (!getPrefStartServiceOnBoot(context)) {
return; return;
}
startServiceCompat(context); startServiceCompat(context);
} }
@ -39,8 +60,13 @@ public class BootReceiver extends BroadcastReceiver {
} }
} }
private static boolean startServiceOnBoot(Context context) { private static boolean getPrefStartServiceOnBoot(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return sp.getBoolean(Constants.PREF_START_SERVICE_ON_BOOT, false); return sp.getBoolean(Constants.PREF_START_SERVICE_ON_BOOT, false);
} }
private static boolean getPrefUseRoot(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return sp.getBoolean(Constants.PREF_USE_ROOT, false);
}
} }