1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Added warning dialog for "sync as root".

This commit is contained in:
Felix Ableitner 2015-11-16 13:57:41 +01:00
parent 4b7c299cd2
commit 89d524c70f
2 changed files with 26 additions and 9 deletions

View file

@ -144,7 +144,7 @@ public class SettingsFragment extends PreferenceFragment
mAlwaysRunInBackground.setOnPreferenceChangeListener(this); mAlwaysRunInBackground.setOnPreferenceChangeListener(this);
mSyncOnlyCharging.setOnPreferenceChangeListener(this); mSyncOnlyCharging.setOnPreferenceChangeListener(this);
mSyncOnlyWifi.setOnPreferenceChangeListener(this); mSyncOnlyWifi.setOnPreferenceChangeListener(this);
mUseRoot.setOnPreferenceChangeListener(this); mUseRoot.setOnPreferenceClickListener(this);
screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this); screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this); screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(SYNCTHING_RESET).setOnPreferenceClickListener(this); screen.findPreference(SYNCTHING_RESET).setOnPreferenceClickListener(this);
@ -241,14 +241,6 @@ public class SettingsFragment extends PreferenceFragment
mSyncOnlyCharging.setChecked(false); mSyncOnlyCharging.setChecked(false);
mSyncOnlyWifi.setChecked(false); mSyncOnlyWifi.setChecked(false);
} }
} else if (preference.equals(mUseRoot)) {
if ((Boolean) o) {
new TestRootTask().execute();
return false;
} else {
new Thread(new ChownFilesRunnable()).start();
requireRestart = true;
}
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) { } else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
RestApi.Device old = mSyncthingService.getApi().getLocalDevice(); RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
RestApi.Device updated = new RestApi.Device(); RestApi.Device updated = new RestApi.Device();
@ -320,6 +312,27 @@ public class SettingsFragment extends PreferenceFragment
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) { switch (preference.getKey()) {
case SyncthingService.PREF_USE_ROOT:
if (mUseRoot.isChecked()) {
// Only check preference after dialog was confirmed and root was granted.
mUseRoot.setChecked(false);
new AlertDialog.Builder(getActivity())
.setTitle(R.string.root_dialog_title)
.setMessage(R.string.root_dialog_message)
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new TestRootTask().execute();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
} else {
new Thread(new ChownFilesRunnable()).start();
mSyncthingService.getApi().requireRestart(getActivity());
}
return true;
case EXPORT_CONFIG: case EXPORT_CONFIG:
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setMessage(R.string.dialog_confirm_export) .setMessage(R.string.dialog_confirm_export)

View file

@ -246,6 +246,10 @@ Please report any problems you encounter via Github.</string>
<string name="use_root_summary">Run Syncthing as Superuser</string> <string name="use_root_summary">Run Syncthing as Superuser</string>
<string name="root_dialog_title">Are you sure you want to enable root?</string>
<string name="root_dialog_message">This may cause various problems with Syncthing and with your device. Use at your own risk.</string>
<string name="notification_type_title">Notification</string> <string name="notification_type_title">Notification</string>
<string name="notification_type_summary">Choose the notification type</string> <string name="notification_type_summary">Choose the notification type</string>