Skip to content

Commit

Permalink
Added warning dialog for "sync as root".
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Nov 16, 2015
1 parent 4b7c299 commit 89d524c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
mAlwaysRunInBackground.setOnPreferenceChangeListener(this);
mSyncOnlyCharging.setOnPreferenceChangeListener(this);
mSyncOnlyWifi.setOnPreferenceChangeListener(this);
mUseRoot.setOnPreferenceChangeListener(this);
mUseRoot.setOnPreferenceClickListener(this);
screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(SYNCTHING_RESET).setOnPreferenceClickListener(this);
Expand Down Expand Up @@ -241,14 +241,6 @@ public boolean onPreferenceChange(Preference preference, Object o) {
mSyncOnlyCharging.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)) {
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
RestApi.Device updated = new RestApi.Device();
Expand Down Expand Up @@ -320,6 +312,27 @@ public void run() {
@Override
public boolean onPreferenceClick(Preference preference) {
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:
new AlertDialog.Builder(getActivity())
.setMessage(R.string.dialog_confirm_export)
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="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_summary">Choose the notification type</string>
Expand Down

0 comments on commit 89d524c

Please sign in to comment.