privileged mode means auto-downloads are actually installs

When the Privileged Extension is working, then enabling the preference
"Automatically download updates" will actually install those updates in the
background.  So the preference should communicate that to the user. So now
it serves as a global "allow background updates"

#16
closes #106
This commit is contained in:
Hans-Christoph Steiner 2016-09-01 17:49:12 +02:00
parent 530144bec6
commit 973174cc7b
5 changed files with 21 additions and 14 deletions

View File

@ -45,7 +45,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String PREF_UPD_INTERVAL = "updateInterval"; public static final String PREF_UPD_INTERVAL = "updateInterval";
public static final String PREF_UPD_WIFI_ONLY = "updateOnWifiOnly"; public static final String PREF_UPD_WIFI_ONLY = "updateOnWifiOnly";
public static final String PREF_UPD_AUTO_DOWNLOAD = "updateAutoDownload"; public static final String PREF_AUTO_DOWNLOAD_INSTALL_UPDATES = "updateAutoDownload";
public static final String PREF_UPD_NOTIFY = "updateNotify"; public static final String PREF_UPD_NOTIFY = "updateNotify";
public static final String PREF_UPD_HISTORY = "updateHistoryDays"; public static final String PREF_UPD_HISTORY = "updateHistoryDays";
public static final String PREF_ROOTED = "rooted"; public static final String PREF_ROOTED = "rooted";
@ -222,7 +222,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public boolean isAutoDownloadEnabled() { public boolean isAutoDownloadEnabled() {
return preferences.getBoolean(PREF_UPD_AUTO_DOWNLOAD, false); return preferences.getBoolean(PREF_AUTO_DOWNLOAD_INSTALL_UPDATES, false);
} }
public boolean isUpdateOnlyOnWifi() { public boolean isUpdateOnlyOnWifi() {

View File

@ -21,7 +21,6 @@ package org.fdroid.fdroid.installer;
import android.content.Context; import android.content.Context;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
@ -46,9 +45,7 @@ public class InstallerFactory {
&& apk.packageName.equals(PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME)) { && apk.packageName.equals(PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME)) {
// special case for "F-Droid Privileged Extension" // special case for "F-Droid Privileged Extension"
installer = new ExtensionInstaller(context); installer = new ExtensionInstaller(context);
} else if (isPrivilegedInstallerEnabled() } else if (PrivilegedInstaller.isDefault(context)) {
&& PrivilegedInstaller.isExtensionInstalledCorrectly(context)
== PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES) {
Utils.debugLog(TAG, "privileged extension correctly installed -> PrivilegedInstaller"); Utils.debugLog(TAG, "privileged extension correctly installed -> PrivilegedInstaller");
installer = new PrivilegedInstaller(context); installer = new PrivilegedInstaller(context);
} else { } else {
@ -57,12 +54,4 @@ public class InstallerFactory {
return installer; return installer;
} }
/**
* Extension has privileged permissions and preference is enabled?
*/
private static boolean isPrivilegedInstallerEnabled() {
return Preferences.get().isPrivilegedInstallerEnabled();
}
} }

View File

@ -30,6 +30,7 @@ import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.privileged.IPrivilegedCallback; import org.fdroid.fdroid.privileged.IPrivilegedCallback;
@ -296,6 +297,14 @@ public class PrivilegedInstaller extends Installer {
return IS_EXTENSION_INSTALLED_YES; return IS_EXTENSION_INSTALLED_YES;
} }
/**
* Extension has privileged permissions and preference is enabled?
*/
public static boolean isDefault(Context context) {
return Preferences.get().isPrivilegedInstallerEnabled()
&& isExtensionInstalledCorrectly(context) == IS_EXTENSION_INSTALLED_YES;
}
@Override @Override
protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri, Apk apk) { protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri, Apk apk) {
sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_STARTED); sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_STARTED);

View File

@ -50,6 +50,7 @@ public class PreferencesFragment extends PreferenceFragment
private static final int REQUEST_INSTALL_ORBOT = 0x1234; private static final int REQUEST_INSTALL_ORBOT = 0x1234;
private CheckBoxPreference enableProxyCheckPref; private CheckBoxPreference enableProxyCheckPref;
private CheckBoxPreference useTorCheckPref; private CheckBoxPreference useTorCheckPref;
private Preference updateAutoDownloadPref;
private Preference updatePrivilegedExtensionPref; private Preference updatePrivilegedExtensionPref;
private long currentKeepCacheTime; private long currentKeepCacheTime;
@ -59,6 +60,7 @@ public class PreferencesFragment extends PreferenceFragment
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
useTorCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_USE_TOR); useTorCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_USE_TOR);
enableProxyCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_ENABLE_PROXY); enableProxyCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_ENABLE_PROXY);
updateAutoDownloadPref = findPreference(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES);
updatePrivilegedExtensionPref = findPreference(Preferences.PREF_UNINSTALL_PRIVILEGED_APP); updatePrivilegedExtensionPref = findPreference(Preferences.PREF_UNINSTALL_PRIVILEGED_APP);
} }
@ -282,6 +284,11 @@ public class PreferencesFragment extends PreferenceFragment
return true; return true;
} }
}); });
if (PrivilegedInstaller.isDefault(getContext())) {
updateAutoDownloadPref.setTitle(R.string.update_auto_install);
updateAutoDownloadPref.setSummary(R.string.update_auto_install_summary);
}
} }
@Override @Override

View File

@ -22,6 +22,8 @@
<string name="automatic_scan_wifi_on">Update app lists automatically only on Wi-Fi</string> <string name="automatic_scan_wifi_on">Update app lists automatically only on Wi-Fi</string>
<string name="update_auto_download">Automatically download updates</string> <string name="update_auto_download">Automatically download updates</string>
<string name="update_auto_download_summary">Download the update files in the background</string> <string name="update_auto_download_summary">Download the update files in the background</string>
<string name="update_auto_install">Automatically install updates</string>
<string name="update_auto_install_summary">Download and install update apps in the background</string>
<string name="notify">Update notifications</string> <string name="notify">Update notifications</string>
<string name="notify_on">Show a notification when updates are available</string> <string name="notify_on">Show a notification when updates are available</string>
<string name="update_history">Update history</string> <string name="update_history">Update history</string>