Merge branch 'blank-versionName' into 'master'

handle Blank versionName

Closes #1418

See merge request fdroid/fdroidclient!673
This commit is contained in:
Hans-Christoph Steiner 2018-04-17 20:21:02 +00:00
commit 59ec2a7751
9 changed files with 90 additions and 10 deletions

View File

@ -641,7 +641,13 @@ public class AppDetails2 extends AppCompatActivity
Log.e(TAG, "uninstall aborted with errorMessage: " + errorMessage);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails2.this);
alertBuilder.setTitle(R.string.uninstall_error_notify_title);
Uri uri = intent.getData();
if (uri == null) {
alertBuilder.setTitle(getString(R.string.uninstall_error_notify_title, ""));
} else {
alertBuilder.setTitle(getString(R.string.uninstall_error_notify_title,
uri.getSchemeSpecificPart()));
}
alertBuilder.setMessage(errorMessage);
alertBuilder.setNeutralButton(android.R.string.ok, null);
alertBuilder.create().show();

View File

@ -10,6 +10,7 @@ import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import com.fasterxml.jackson.annotation.JacksonInject;
@ -65,6 +66,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
// these come directly from the index metadata
public String packageName;
@Nullable
public String versionName;
public int versionCode;
public int size; // Size in bytes - 0 means we don't know!

View File

@ -95,7 +95,7 @@ public class DBHelper extends SQLiteOpenHelper {
static final String CREATE_TABLE_APK =
"CREATE TABLE " + ApkTable.NAME + " ( "
+ ApkTable.Cols.APP_ID + " integer not null, "
+ ApkTable.Cols.VERSION_NAME + " text not null, "
+ ApkTable.Cols.VERSION_NAME + " text, "
+ ApkTable.Cols.REPO_ID + " integer not null, "
+ ApkTable.Cols.HASH + " text not null, "
+ ApkTable.Cols.VERSION_CODE + " int not null,"
@ -215,7 +215,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ "primary key(" + ApkAntiFeatureJoinTable.Cols.APK_ID + ", " + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + ") "
+ " );";
protected static final int DB_VERSION = 78;
protected static final int DB_VERSION = 79;
private final Context context;
@ -323,6 +323,16 @@ public class DBHelper extends SQLiteOpenHelper {
addIgnoreVulnPref(db, oldVersion);
addLiberapayID(db, oldVersion);
addUserMirrorsFields(db, oldVersion);
removeNotNullFromVersionName(db, oldVersion);
}
private void removeNotNullFromVersionName(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 79) {
return;
}
Log.i(TAG, "Forcing repo refresh to remove NOT NULL from " + ApkTable.Cols.VERSION_NAME);
resetTransient(db);
}
private void addUserMirrorsFields(SQLiteDatabase db, int oldVersion) {

View File

@ -10,6 +10,7 @@ import android.content.pm.Signature;
import android.net.Uri;
import android.os.Process;
import android.support.annotation.Nullable;
import android.util.Log;
import org.acra.ACRA;
import org.fdroid.fdroid.AppUpdateStatusManager;
import org.fdroid.fdroid.Hasher;
@ -290,6 +291,7 @@ public class InstalledAppProviderService extends IntentService {
* into the database when under test.
*/
static void insertAppIntoDb(Context context, PackageInfo packageInfo, String hashType, String hash) {
Log.d(TAG, "insertAppIntoDb " + packageInfo.packageName);
Uri uri = InstalledAppProvider.getContentUri();
ContentValues contentValues = new ContentValues();
contentValues.put(InstalledAppTable.Cols.Package.NAME, packageInfo.packageName);
@ -307,6 +309,7 @@ public class InstalledAppProviderService extends IntentService {
}
static void deleteAppFromDb(Context context, String packageName) {
Log.d(TAG, "deleteAppFromDb " + packageName);
Uri uri = InstalledAppProvider.getAppUri(packageName);
context.getContentResolver().delete(uri, null, null);
}

View File

@ -357,9 +357,12 @@ public final class LocalRepoManager {
/**
* Helper function to start a tag called "name", fill it with text "text", and then
* end the tag in a more concise manner.
* end the tag in a more concise manner. If "text" is blank, skip the tag entirely.
*/
private void tag(String name, String text) throws IOException {
if (TextUtils.isEmpty(text)) {
return;
}
serializer.startTag("", name).text(text).endTag("", name);
}

View File

@ -4,8 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import org.fdroid.fdroid.Utils;
import android.util.Log;
import org.fdroid.fdroid.data.InstalledAppProviderService;
/**
@ -28,12 +27,12 @@ public class PackageManagerReceiver extends BroadcastReceiver {
InstalledAppProviderService.insert(context, intent.getData());
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
if (TextUtils.equals(context.getPackageName(), intent.getData().getSchemeSpecificPart())) {
Utils.debugLog(TAG, "Ignoring request to remove ourselves from cache.");
Log.i(TAG, "Ignoring request to remove ourselves from cache.");
} else {
InstalledAppProviderService.delete(context, intent.getData());
}
} else {
Utils.debugLog(TAG, "unsupported action: " + action + " " + intent);
Log.i(TAG, "unsupported action: " + action + " " + intent);
}
}
}

View File

@ -50,6 +50,7 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -419,6 +420,8 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
assertEquals(1, apps.length);
assertEquals(1, packages.size());
List<Apk> cacerts = packages.get("info.guardianproject.cacert");
assertEquals(2, cacerts.size());
assertEquals(1488828510109L, repo.timestamp);
assertEquals("GPLv3", apps[0].license);
@ -427,12 +430,16 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
assertNotEquals("secret", field);
}
Apk apk = packages.get("info.guardianproject.cacert").get(0);
Apk apk = cacerts.get(0);
assertEquals("e013db095e8da843fae5ac44be6152e51377ee717e5c8a7b6d913d7720566b5a", apk.hash);
Set<String> packageFields = getFields(apk);
for (String field : packageFields) {
assertNotEquals("secret", field);
}
apk = cacerts.get(1);
assertEquals("2353d1235e8da843fae5ac44be6152e513123e717e5c8a7b6d913d7720566b5a", apk.hash);
assertNull(apk.versionName);
}
private Set<String> getFields(Object instance) {

View File

@ -87,6 +87,56 @@
],
"versionCode": 14,
"versionName": "0.1.8"
},
{
"added": 1400014500000,
"apkName": "Courier-0.0.apk",
"hash": "2353d1235e8da843fae5ac44be6152e513123e717e5c8a7b6d913d7720566b5a",
"hashType": "sha256",
"minSdkVersion": "9",
"nativecode": [
"armeabi",
"x86"
],
"packageName": "info.guardianproject.courier",
"sig": "d70ac6a02b53ebdd1354ea7af7b9ceee",
"size": 16536125,
"targetSdkVersion": "15",
"uses-permission": [
[
"android.permission.READ_EXTERNAL_STORAGE",
null
],
[
"android.permission.INTERNET",
null
],
[
"android.permission.BLUETOOTH",
null
],
[
"android.permission.BLUETOOTH_ADMIN",
null
],
[
"android.permission.VIBRATE",
null
],
[
"android.permission.ACCESS_NETWORK_STATE",
null
],
[
"android.permission.WRITE_EXTERNAL_STORAGE",
null
],
[
"android.permission.ACCESS_WIFI_STATE",
null
]
],
"versionCode": 0
}
]
}

File diff suppressed because one or more lines are too long