Merge branch 'fixes-and-cleanups' into 'master'

fixes and cleanups related to ongoing DownloaderService work

This includes a fix for bug that @mvdan found in the processing of `Apk.maxSdkVersion`, as well as some cleanups related to the ongoing work in !248 . Indeed a couple of these commits were pulled out of that MR.

See merge request !253
This commit is contained in:
Hans-Christoph Steiner 2016-04-05 15:22:59 +00:00
commit d846e18d7f
12 changed files with 43 additions and 87 deletions

1
.gitignore vendored
View File

@ -16,6 +16,7 @@ build.xml
# Gradle files
.gradle/
build/
gradle.properties
# Local configuration file (sdk path, etc)
local.properties

View File

@ -132,6 +132,7 @@ android {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'src/androidTest/proguard-rules.pro'
}
debug {
testCoverageEnabled = true

16
app/src/androidTest/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,16 @@
-dontwarn android.test.**
-dontwarn android.support.test.**
-dontnote junit.framework.**
-dontnote junit.runner.**
# Uncomment this if you use Mockito
#-dontwarn org.mockito.**
-keep class org.hamcrest.** { *; }
-dontwarn org.hamcrest.**
-keep class org.junit.** { *; }
-dontwarn org.junit.**
-keep class junit.** { *; }
-dontwarn junit.**

View File

@ -106,9 +106,9 @@ public class RepoUpdater {
}
} catch (IOException e) {
if (downloader != null && downloader.getFile() != null) {
if (!downloader.getFile().delete()) {
Log.w(TAG, "Couldn't delete file: " + downloader.getFile().getAbsolutePath());
if (downloader != null && downloader.outputFile != null) {
if (!downloader.outputFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + downloader.outputFile.getAbsolutePath());
}
}
@ -136,7 +136,7 @@ public class RepoUpdater {
// Don't worry about checking the status code for 200. If it was a
// successful download, then we will have a file ready to use:
cacheTag = downloader.getCacheTag();
processDownloadedFile(downloader.getFile());
processDownloadedFile(downloader.outputFile);
}
}

View File

@ -19,7 +19,7 @@ public class Apk extends ValueObject implements Comparable<Apk> {
public String hash;
public String hashType;
public int minSdkVersion; // 0 if unknown
public int maxSdkVersion; // 0 if none
public int maxSdkVersion = Byte.MAX_VALUE; // "infinity" if not set
public Date added;
public Utils.CommaSeparatedList permissions; // null if empty or
// unknown

View File

@ -106,7 +106,7 @@ class DBHelper extends SQLiteOpenHelper {
+ " );";
private static final String DROP_TABLE_INSTALLED_APP = "DROP TABLE " + TABLE_INSTALLED_APP + ";";
private static final int DB_VERSION = 53;
private static final int DB_VERSION = 54;
private final Context context;
@ -291,6 +291,7 @@ class DBHelper extends SQLiteOpenHelper {
recreateInstalledCache(db, oldVersion);
addCredentialsToRepo(db, oldVersion);
addAuthorToApp(db, oldVersion);
useMaxValueInMaxSdkVersion(db, oldVersion);
}
/**
@ -475,6 +476,15 @@ class DBHelper extends SQLiteOpenHelper {
}
}
private void useMaxValueInMaxSdkVersion(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 54) {
Utils.debugLog(TAG, "Converting maxSdkVersion value 0 to " + Byte.MAX_VALUE);
ContentValues values = new ContentValues();
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, Byte.MAX_VALUE);
db.update(TABLE_APK, values, ApkProvider.DataColumns.MAX_SDK_VERSION + " < 1", null);
}
}
/**
* By clearing the etags stored in the repo table, it means that next time the user updates
* their repos (either manually or on a scheduled task), they will update regardless of whether

View File

@ -27,7 +27,6 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import java.io.File;
import java.util.List;
/**
* For Android < 4: Default Installer using the public PackageManager API of
@ -61,11 +60,6 @@ public class DefaultInstaller extends Installer {
}
}
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// not used
}
@Override
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
try {
@ -103,10 +97,4 @@ public class DefaultInstaller extends Installer {
return false;
}
}
@Override
public boolean supportsUnattendedOperations() {
return false;
}
}

View File

@ -29,7 +29,6 @@ import android.net.Uri;
import android.os.Build;
import java.io.File;
import java.util.List;
/**
* For Android >= 4.0: Default Installer using the public PackageManager API of
@ -73,11 +72,6 @@ public class DefaultSdk14Installer extends Installer {
}
}
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// not used
}
@Override
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
try {
@ -129,10 +123,4 @@ public class DefaultSdk14Installer extends Installer {
return false;
}
}
@Override
public boolean supportsUnattendedOperations() {
return false;
}
}

View File

@ -30,7 +30,6 @@ import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity;
import java.io.File;
import java.util.List;
/**
* Abstract Installer class. Also provides static methods to automatically
@ -53,20 +52,9 @@ public abstract class Installer {
private static final long serialVersionUID = -8343133906463328027L;
public AndroidNotCompatibleException() {
}
public AndroidNotCompatibleException(String message) {
super(message);
}
public AndroidNotCompatibleException(Throwable cause) {
super(cause);
}
public AndroidNotCompatibleException(String message, Throwable cause) {
super(message, cause);
}
}
/**
@ -175,18 +163,6 @@ public abstract class Installer {
installPackageInternal(apkFile);
}
public void installPackage(List<File> apkFiles) throws AndroidNotCompatibleException {
// check if files exist...
for (File apkFile : apkFiles) {
if (!apkFile.exists()) {
Log.e(TAG, "Couldn't find file " + apkFile + " to install.");
return;
}
}
installPackageInternal(apkFiles);
}
public void deletePackage(String packageName) throws AndroidNotCompatibleException {
// check if package exists before proceeding...
try {
@ -218,13 +194,8 @@ public abstract class Installer {
protected abstract void installPackageInternal(File apkFile)
throws AndroidNotCompatibleException;
protected abstract void installPackageInternal(List<File> apkFiles)
throws AndroidNotCompatibleException;
protected abstract void deletePackageInternal(String packageName)
throws AndroidNotCompatibleException;
public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data);
public abstract boolean supportsUnattendedOperations();
}

View File

@ -44,7 +44,6 @@ import org.fdroid.fdroid.privileged.views.AppSecurityPermissions;
import org.fdroid.fdroid.privileged.views.InstallConfirmActivity;
import java.io.File;
import java.util.List;
/**
* Installer based on using internal hidden APIs of the Android OS, which are
@ -237,12 +236,6 @@ public class PrivilegedInstaller extends Installer {
Context.BIND_AUTO_CREATE);
}
@Override
protected void installPackageInternal(List<File> apkFiles)
throws AndroidNotCompatibleException {
// not used
}
@Override
protected void deletePackageInternal(final String packageName)
throws AndroidNotCompatibleException {
@ -368,11 +361,6 @@ public class PrivilegedInstaller extends Installer {
}
}
@Override
public boolean supportsUnattendedOperations() {
return false;
}
public static final int INSTALL_REPLACE_EXISTING = 2;
/**

View File

@ -1,7 +1,5 @@
package org.fdroid.fdroid.net;
import android.support.annotation.NonNull;
import org.fdroid.fdroid.Utils;
import java.io.File;
@ -27,11 +25,16 @@ public abstract class Downloader {
private final OutputStream outputStream;
private final File outputFile;
public final File outputFile;
protected final URL sourceUrl;
protected String cacheTag;
/**
* This is meant only to send progress to {@link DownloaderService}. This
* also keeps this class pure Java so that it can be tested on the JVM,
* without requiring an Android device or emulator.
*/
interface DownloaderProgressListener {
void sendProgress(URL sourceUrl, int bytesRead, int totalBytes);
}
@ -78,15 +81,6 @@ public abstract class Downloader {
return cacheTag != null;
}
/**
* Only available if you passed a context object into the constructor
* (rather than an outputStream, which may or may not be associated with
* a file).
*/
public File getFile() {
return outputFile;
}
public abstract boolean hasChanged();
protected abstract int totalDownloadSize();
@ -222,12 +216,12 @@ public abstract class Downloader {
}
@Override
public int read(@NonNull byte[] buffer) throws IOException {
public int read(byte[] buffer) throws IOException {
return toWrap.read(buffer);
}
@Override
public int read(@NonNull byte[] buffer, int byteOffset, int byteCount) throws IOException {
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
return toWrap.read(buffer, byteOffset, byteCount);
}

View File

@ -114,8 +114,7 @@ public class HttpDownloader extends Downloader {
// workaround until NetCipher supports HTTPS SNI
// https://gitlab.com/fdroid/fdroidclient/issues/431
if (connection instanceof HttpsURLConnection
&& "f-droid.org".equals(sourceUrl.getHost())
&& "guardianproject.info".equals(sourceUrl.getHost())) {
&& "f-droid.org".equals(sourceUrl.getHost())) {
((HttpsURLConnection) connection).setSSLSocketFactory(HttpsURLConnection.getDefaultSSLSocketFactory());
}