Merge branch 'random-fixes-from-downloaderservice-hacking' into 'master'

Random fixes from DownloaderService hacking

Here are some random fixes that I did in the process of the DownloaderService refactoring.  I don't think anything should be controversial.  Thanks for your rapid code reviews recently @mvdan :)

See merge request !245
This commit is contained in:
Daniel Martí 2016-03-31 10:43:13 +00:00
commit 41d54f7e92
11 changed files with 31 additions and 27 deletions

View File

@ -40,7 +40,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) { if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
preferences.edit() preferences.edit()
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName()) .putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName())
.commit(); .apply();
} }
} }
@ -113,7 +113,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setPrivilegedInstallerEnabled(boolean enable) { public void setPrivilegedInstallerEnabled(boolean enable) {
preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).commit(); preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).apply();
} }
public boolean isFirstTime() { public boolean isFirstTime() {
@ -121,7 +121,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setFirstTime(boolean firstTime) { public void setFirstTime(boolean firstTime) {
preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).commit(); preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).apply();
} }
public boolean isPostPrivilegedInstall() { public boolean isPostPrivilegedInstall() {
@ -129,7 +129,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setPostPrivilegedInstall(boolean postInstall) { public void setPostPrivilegedInstall(boolean postInstall) {
preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall).commit(); preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall).apply();
} }
public boolean shouldCacheApks() { public boolean shouldCacheApks() {
@ -149,7 +149,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setShowNfcDuringSwap(boolean show) { public void setShowNfcDuringSwap(boolean show) {
preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show).commit(); preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show).apply();
} }
public boolean expertMode() { public boolean expertMode() {

View File

@ -406,7 +406,7 @@ public class UpdateService extends IntentService implements ProgressListener {
SharedPreferences.Editor e = prefs.edit(); SharedPreferences.Editor e = prefs.edit();
e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis()); e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
e.commit(); e.apply();
if (errorRepos == 0) { if (errorRepos == 0) {
if (changes) { if (changes) {

View File

@ -11,6 +11,12 @@ import org.fdroid.fdroid.data.SanitizedFile;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/**
* This class works only with {@link SanitizedFile} instances to enforce
* filtering of the file names from files downloaded from the internet.
* This helps prevent things like SQL injection, shell command injection
* and other attacks based on putting various characters into filenames.
*/
public class FileCompat extends Compatibility { public class FileCompat extends Compatibility {
private static final String TAG = "FileCompat"; private static final String TAG = "FileCompat";

View File

@ -40,7 +40,7 @@ public abstract class Downloader {
protected abstract InputStream getDownloadersInputStream() throws IOException; protected abstract InputStream getDownloadersInputStream() throws IOException;
protected abstract void close() throws IOException; protected abstract void close();
Downloader(URL url, File destFile) Downloader(URL url, File destFile)
throws FileNotFoundException, MalformedURLException { throws FileNotFoundException, MalformedURLException {
@ -117,11 +117,6 @@ public abstract class Downloader {
} }
/** /**
* In a synchronous download (the usual usage of the Downloader interface),
* you will not be able to interrupt this because the thread will block
* after you have called download(). However if you use the AsyncDownloadWrapper,
* then it will use this mechanism to cancel the download.
*
* After every network operation that could take a while, we will check if an * After every network operation that could take a while, we will check if an
* interrupt occured during that blocking operation. The goal is to ensure we * interrupt occured during that blocking operation. The goal is to ensure we
* don't move onto another slow, network operation if we have cancelled the * don't move onto another slow, network operation if we have cancelled the

View File

@ -1,5 +1,7 @@
package org.fdroid.fdroid.net; package org.fdroid.fdroid.net;
import org.fdroid.fdroid.Utils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -10,22 +12,23 @@ import java.net.URL;
public class LocalFileDownloader extends Downloader { public class LocalFileDownloader extends Downloader {
private InputStream inputStream;
LocalFileDownloader(URL url, File destFile) throws FileNotFoundException, MalformedURLException { LocalFileDownloader(URL url, File destFile) throws FileNotFoundException, MalformedURLException {
super(url, destFile); super(url, destFile);
} }
private File getFileToDownload() {
return new File(sourceUrl.getPath());
}
@Override @Override
protected InputStream getDownloadersInputStream() throws IOException { protected InputStream getDownloadersInputStream() throws IOException {
return new FileInputStream(getFileToDownload()); inputStream = new FileInputStream(new File(sourceUrl.getPath()));
return inputStream;
} }
@Override @Override
protected void close() throws IOException { protected void close() {
// Do nothing. if (inputStream != null) {
Utils.closeQuietly(inputStream);
}
} }
@Override @Override

View File

@ -141,7 +141,7 @@ public abstract class AppListFragment extends ListFragment implements
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false); boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
if (!hasTriedEmptyUpdate) { if (!hasTriedEmptyUpdate) {
Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update."); Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update.");
prefs.edit().putBoolean(triedEmptyUpdate, true).commit(); prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
UpdateService.updateNow(getActivity()); UpdateService.updateNow(getActivity());
return true; return true;
} }

View File

@ -230,7 +230,7 @@ public class AvailableAppsFragment extends AppListFragment implements
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
SharedPreferences.Editor e = p.edit(); SharedPreferences.Editor e = p.edit();
e.putString(CATEGORY_KEY, currentCategory); e.putString(CATEGORY_KEY, currentCategory);
e.commit(); e.apply();
} }
@Override @Override

View File

@ -204,13 +204,13 @@ public class PreferencesFragment extends PreferenceFragment
// privileged permission are granted, i.e. the extension is installed correctly // privileged permission are granted, i.e. the extension is installed correctly
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, true); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, true);
editor.commit(); editor.apply();
pref.setChecked(true); pref.setChecked(true);
} else { } else {
// privileged permission not available // privileged permission not available
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
editor.commit(); editor.apply();
pref.setChecked(false); pref.setChecked(false);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
@ -248,7 +248,7 @@ public class PreferencesFragment extends PreferenceFragment
} else { } else {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
editor.commit(); editor.apply();
pref.setChecked(false); pref.setChecked(false);
} }

View File

@ -108,7 +108,7 @@
<string name="proxy_port_summary">Määritä välityspalvelimesi porttinumero (esim. 8118)</string> <string name="proxy_port_summary">Määritä välityspalvelimesi porttinumero (esim. 8118)</string>
<string name="repos_unchanged">Yhdessäkään säilössä ei ole pakettipäivityksiä</string> <string name="repos_unchanged">Yhdessäkään säilössä ei ole pakettipäivityksiä</string>
<string name="all_other_repos_fine">Muut säilöt eivät luoneet virheitä.</string> <string name="all_other_repos_fine">Muut säilöt eivät luoneet virheitä.</string>
<string name="global_error_updating_repos">Päivityksenaikainen virhe:</string> <string name="global_error_updating_repos">Päivityksenaikainen virhe: %s</string>
<string name="theme">Teema</string> <string name="theme">Teema</string>
<string name="unverified">Vahvistamaton</string> <string name="unverified">Vahvistamaton</string>
<string name="repo_not_yet_updated">Tätä säilöä ei ole vielä käytetty. <string name="repo_not_yet_updated">Tätä säilöä ei ole vielä käytetty.

View File

@ -63,7 +63,7 @@
<string name="status_connecting_to_repo">Jungiamasi prie <string name="status_connecting_to_repo">Jungiamasi prie
%1$s</string> %1$s</string>
<string name="repos_unchanged">Įjungtose saugyklose nėra nieko naujo</string> <string name="repos_unchanged">Įjungtose saugyklose nėra nieko naujo</string>
<string name="global_error_updating_repos">Klaida naujinant:</string> <string name="global_error_updating_repos">Klaida naujinant: %s</string>
<string name="theme">Tema</string> <string name="theme">Tema</string>
<string name="repo_num_apps">Programų kiekis</string> <string name="repo_num_apps">Programų kiekis</string>
<string name="repo_description">Aprašymas</string> <string name="repo_description">Aprašymas</string>

View File

@ -184,7 +184,7 @@
<string name="local_repo_running">F-Droid已准备好交换应用</string> <string name="local_repo_running">F-Droid已准备好交换应用</string>
<string name="touch_to_configure_local_repo">触摸可查看详细信息以及允许其他人与你交换应用程序。</string> <string name="touch_to_configure_local_repo">触摸可查看详细信息以及允许其他人与你交换应用程序。</string>
<string name="adding_apks_format">正在添加 s 到软件源…</string> <string name="adding_apks_format">正在添加 %s 到软件源…</string>
<string name="writing_index_jar">正在写入已签名的索引文件index.jar</string> <string name="writing_index_jar">正在写入已签名的索引文件index.jar</string>
<string name="failed_to_create_index">创建软件源索引失败!</string> <string name="failed_to_create_index">创建软件源索引失败!</string>
<string name="linking_apks">正在链接APK到软件源……</string> <string name="linking_apks">正在链接APK到软件源……</string>