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

Check root availability in background.

This commit is contained in:
Felix Ableitner 2015-05-18 23:15:31 +02:00
parent 98b9029c62
commit 924d033474
2 changed files with 25 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package com.nutomic.syncthingandroid.fragments;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@ -51,6 +52,8 @@ public class SettingsFragment extends PreferenceFragment
private CheckBoxPreference mSyncOnlyWifi;
private Preference mUseRoot;
private PreferenceScreen mOptionsScreen;
private PreferenceScreen mGuiScreen;
@ -117,17 +120,17 @@ public class SettingsFragment extends PreferenceFragment
((SyncthingActivity) getActivity()).registerOnServiceConnectedListener(this);
addPreferencesFromResource(R.xml.app_settings);
PreferenceScreen screen = getPreferenceScreen();
final PreferenceScreen screen = getPreferenceScreen();
mAlwaysRunInBackground = (CheckBoxPreference)
findPreference(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND);
mSyncOnlyCharging = (CheckBoxPreference)
findPreference(SyncthingService.PREF_SYNC_ONLY_CHARGING);
mSyncOnlyWifi = (CheckBoxPreference) findPreference(SyncthingService.PREF_SYNC_ONLY_WIFI);
Preference useRoot = findPreference(SyncthingService.PREF_USE_ROOT);
mUseRoot = 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);
Preference user = screen.findPreference(GUI_USER);
final Preference user = screen.findPreference(GUI_USER);
Preference password = screen.findPreference(GUI_PASSWORD);
Preference sttrace = findPreference(STTRACE);
@ -141,10 +144,8 @@ public class SettingsFragment extends PreferenceFragment
mAlwaysRunInBackground.setOnPreferenceChangeListener(this);
mSyncOnlyCharging.setOnPreferenceChangeListener(this);
mSyncOnlyWifi.setOnPreferenceChangeListener(this);
if (!Shell.SU.available()) {
screen.removePreference(useRoot);
}
useRoot.setOnPreferenceChangeListener(this);
new TestRootTask().execute();
mUseRoot.setOnPreferenceChangeListener(this);
screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(SYNCTHING_RESET).setOnPreferenceClickListener(this);
@ -159,6 +160,21 @@ public class SettingsFragment extends PreferenceFragment
sttrace.setSummary(sp.getString("sttrace", ""));
}
/**
* Enables or disables {@link #mUseRoot} preference depending whether root is available.
*/
private class TestRootTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
return Shell.SU.available();
}
@Override
protected void onPostExecute(Boolean result) {
mUseRoot.setEnabled(result);
}
}
@Override
public void onServiceConnected() {
mSyncthingService = ((SyncthingActivity) getActivity()).getService();

View file

@ -29,7 +29,8 @@
android:key="use_root"
android:title="Sync as root"
android:summary="Run syncthing as superuser"
android:defaultValue="false" />
android:defaultValue="false"
android:enabled="false" />
</PreferenceCategory>