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

Only ask for root permissions once the setting is changed (fixes #457).

This means that the root preference will also be shown to users
that haven't rooted their phone.
This commit is contained in:
Felix Ableitner 2015-09-11 22:36:21 +02:00
parent 3986198fa4
commit 819a3ffc66
3 changed files with 24 additions and 11 deletions

View file

@ -51,15 +51,17 @@ public class SettingsFragment extends PreferenceFragment
private CheckBoxPreference mAlwaysRunInBackground;
private CheckBoxPreference mSyncOnlyCharging;
private CheckBoxPreference mSyncOnlyWifi;
private Preference mUseRoot;
private CheckBoxPreference mUseRoot;
private PreferenceScreen mOptionsScreen;
private PreferenceScreen mGuiScreen;
private SyncthingService mSyncthingService;
@Override
public void onApiChange(SyncthingService.State currentState) {
mOptionsScreen.setEnabled(currentState == SyncthingService.State.ACTIVE);
mGuiScreen.setEnabled(currentState == SyncthingService.State.ACTIVE);
boolean enabled = currentState == SyncthingService.State.ACTIVE;
mOptionsScreen.setEnabled(enabled);
mGuiScreen.setEnabled(enabled);
mUseRoot.setEnabled(enabled);
if (currentState == SyncthingService.State.ACTIVE) {
Preference syncthingVersion = getPreferenceScreen().findPreference(SYNCTHING_VERSION_KEY);
@ -122,7 +124,7 @@ public class SettingsFragment extends PreferenceFragment
mSyncOnlyCharging = (CheckBoxPreference)
findPreference(SyncthingService.PREF_SYNC_ONLY_CHARGING);
mSyncOnlyWifi = (CheckBoxPreference) findPreference(SyncthingService.PREF_SYNC_ONLY_WIFI);
mUseRoot = findPreference(SyncthingService.PREF_USE_ROOT);
mUseRoot = (CheckBoxPreference) findPreference(SyncthingService.PREF_USE_ROOT);
Preference appVersion = screen.findPreference(APP_VERSION_KEY);
mOptionsScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_OPTIONS_KEY);
mGuiScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_GUI_KEY);
@ -140,7 +142,6 @@ public class SettingsFragment extends PreferenceFragment
mAlwaysRunInBackground.setOnPreferenceChangeListener(this);
mSyncOnlyCharging.setOnPreferenceChangeListener(this);
mSyncOnlyWifi.setOnPreferenceChangeListener(this);
new TestRootTask().execute();
mUseRoot.setOnPreferenceChangeListener(this);
screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this);
@ -166,8 +167,14 @@ public class SettingsFragment extends PreferenceFragment
}
@Override
protected void onPostExecute(Boolean result) {
mUseRoot.setEnabled(result);
protected void onPostExecute(Boolean haveRoot) {
if (haveRoot) {
mSyncthingService.getApi().requireRestart(getActivity());
mUseRoot.setChecked(true);
} else {
Toast.makeText(getActivity(), R.string.toast_root_denied, Toast.LENGTH_SHORT)
.show();
}
}
}
@ -235,9 +242,13 @@ public class SettingsFragment extends PreferenceFragment
mSyncOnlyWifi.setChecked(false);
}
} else if (preference.equals(mUseRoot)) {
if (!(Boolean) o)
if ((Boolean) o) {
new TestRootTask().execute();
return false;
} else {
new Thread(new ChownFilesRunnable()).start();
requireRestart = true;
requireRestart = true;
}
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
RestApi.Device updated = new RestApi.Device();

View file

@ -194,6 +194,9 @@
<!-- Content description for device ID qr code icon -->
<string name="scan_qr_code_description">Scan QR Code</string>
<!-- Toast show if we could not get root permissions -->
<string name="toast_root_denied">"Did not get root permissions"</string>
<!-- WebGuiActivity -->

View file

@ -29,8 +29,7 @@
android:key="use_root"
android:title="@string/use_root_title"
android:summary="@string/use_root_summary"
android:defaultValue="false"
android:enabled="false" />
android:defaultValue="false" />
<ListPreference
android:key="notification_type"