set "Automatically download updates" to default true

But keep "Automatically install updates" default false for devices with
Privileged Extension.
This commit is contained in:
Hans-Christoph Steiner 2019-03-22 23:45:02 +01:00
parent 99591c050c
commit e3cfe3690d
4 changed files with 14 additions and 10 deletions

View File

@ -50,7 +50,6 @@
<SwitchPreference
android:title="@string/update_auto_download"
android:summary="@string/update_auto_download_summary"
android:defaultValue="true"
android:key="updateAutoDownload"/>
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="updateIntervalSeekBarPosition"

View File

@ -32,6 +32,7 @@ import android.support.v7.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.util.Log;
import info.guardianproject.netcipher.NetCipher;
import org.fdroid.fdroid.installer.PrivilegedInstaller;
import org.fdroid.fdroid.net.ConnectivityMonitorService;
import java.net.InetSocketAddress;
@ -69,11 +70,16 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
PreferenceManager.setDefaultValues(context, R.xml.preferences, true);
preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(this);
SharedPreferences.Editor editor = preferences.edit();
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
preferences.edit()
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName())
.apply();
editor.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
}
if (!preferences.contains(PREF_AUTO_DOWNLOAD_INSTALL_UPDATES)) {
editor.putBoolean(PREF_AUTO_DOWNLOAD_INSTALL_UPDATES,
PrivilegedInstaller.isExtensionInstalledCorrectly(context)
!= PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES);
}
editor.apply();
}
public static final String PREF_OVER_WIFI = "overWifi";

View File

@ -50,7 +50,6 @@
<SwitchPreference
android:title="@string/update_auto_download"
android:summary="@string/update_auto_download_summary"
android:defaultValue="false"
android:key="updateAutoDownload"/>
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="updateIntervalSeekBarPosition"

View File

@ -74,16 +74,18 @@ public class PreferencesTest {
* Check that the defaults are being set when using
* {@link PreferenceManager#getDefaultSharedPreferences(Context)}, and that
* the values match. {@link Preferences#Preferences(Context)} sets the
* value of {@link Preferences#PREF_LOCAL_REPO_NAME} dynamically, so there
* is one more preference.
* values of {@link Preferences#PREF_LOCAL_REPO_NAME} and
* {@link Preferences#PREF_AUTO_DOWNLOAD_INSTALL_UPDATES} dynamically, so
* there are two more preferences.
*/
@Test
public void testSetDefaultValues() {
Preferences.setupForTests(CONTEXT);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(CONTEXT);
assertEquals(defaults.getAll().size() + 1, sharedPreferences.getAll().size());
assertEquals(defaults.getAll().size() + 2, sharedPreferences.getAll().size());
assertTrue(sharedPreferences.contains(Preferences.PREF_LOCAL_REPO_NAME));
assertTrue(sharedPreferences.contains(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES));
Map<String, ?> entries = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : defaults.getAll().entrySet()) {
@ -104,8 +106,6 @@ public class PreferencesTest {
Preferences.setupForTests(CONTEXT);
Preferences preferences = Preferences.get();
assertEquals(defaults.getBoolean(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES, false),
preferences.isAutoDownloadEnabled());
assertEquals(defaults.getBoolean(Preferences.PREF_EXPERT, false),
preferences.expertMode());
assertEquals(defaults.getBoolean(Preferences.PREF_FORCE_TOUCH_APPS, false),