1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-27 06:41:15 +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 mAlwaysRunInBackground;
private CheckBoxPreference mSyncOnlyCharging; private CheckBoxPreference mSyncOnlyCharging;
private CheckBoxPreference mSyncOnlyWifi; private CheckBoxPreference mSyncOnlyWifi;
private Preference mUseRoot; private CheckBoxPreference mUseRoot;
private PreferenceScreen mOptionsScreen; private PreferenceScreen mOptionsScreen;
private PreferenceScreen mGuiScreen; private PreferenceScreen mGuiScreen;
private SyncthingService mSyncthingService; private SyncthingService mSyncthingService;
@Override @Override
public void onApiChange(SyncthingService.State currentState) { public void onApiChange(SyncthingService.State currentState) {
mOptionsScreen.setEnabled(currentState == SyncthingService.State.ACTIVE); boolean enabled = currentState == SyncthingService.State.ACTIVE;
mGuiScreen.setEnabled(currentState == SyncthingService.State.ACTIVE); mOptionsScreen.setEnabled(enabled);
mGuiScreen.setEnabled(enabled);
mUseRoot.setEnabled(enabled);
if (currentState == SyncthingService.State.ACTIVE) { if (currentState == SyncthingService.State.ACTIVE) {
Preference syncthingVersion = getPreferenceScreen().findPreference(SYNCTHING_VERSION_KEY); Preference syncthingVersion = getPreferenceScreen().findPreference(SYNCTHING_VERSION_KEY);
@ -122,7 +124,7 @@ public class SettingsFragment extends PreferenceFragment
mSyncOnlyCharging = (CheckBoxPreference) mSyncOnlyCharging = (CheckBoxPreference)
findPreference(SyncthingService.PREF_SYNC_ONLY_CHARGING); findPreference(SyncthingService.PREF_SYNC_ONLY_CHARGING);
mSyncOnlyWifi = (CheckBoxPreference) findPreference(SyncthingService.PREF_SYNC_ONLY_WIFI); 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); Preference appVersion = screen.findPreference(APP_VERSION_KEY);
mOptionsScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_OPTIONS_KEY); mOptionsScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_OPTIONS_KEY);
mGuiScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_GUI_KEY); mGuiScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_GUI_KEY);
@ -140,7 +142,6 @@ public class SettingsFragment extends PreferenceFragment
mAlwaysRunInBackground.setOnPreferenceChangeListener(this); mAlwaysRunInBackground.setOnPreferenceChangeListener(this);
mSyncOnlyCharging.setOnPreferenceChangeListener(this); mSyncOnlyCharging.setOnPreferenceChangeListener(this);
mSyncOnlyWifi.setOnPreferenceChangeListener(this); mSyncOnlyWifi.setOnPreferenceChangeListener(this);
new TestRootTask().execute();
mUseRoot.setOnPreferenceChangeListener(this); mUseRoot.setOnPreferenceChangeListener(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);
@ -166,8 +167,14 @@ public class SettingsFragment extends PreferenceFragment
} }
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean haveRoot) {
mUseRoot.setEnabled(result); 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); mSyncOnlyWifi.setChecked(false);
} }
} else if (preference.equals(mUseRoot)) { } else if (preference.equals(mUseRoot)) {
if (!(Boolean) o) if ((Boolean) o) {
new TestRootTask().execute();
return false;
} else {
new Thread(new ChownFilesRunnable()).start(); new Thread(new ChownFilesRunnable()).start();
requireRestart = true; 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();

View file

@ -194,6 +194,9 @@
<!-- Content description for device ID qr code icon --> <!-- Content description for device ID qr code icon -->
<string name="scan_qr_code_description">Scan QR Code</string> <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 --> <!-- WebGuiActivity -->

View file

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