use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class AppUpdateStatusService method findApkMatchingHash.
/**
* There could be multiple apks with the same hash, provided by different repositories.
* This method looks for all matching records in the database. It then asks each of these
* {@link Apk} instances where they expect to be downloaded. If they expect to be downloaded
* to {@param apkPath} then that instance is returned.
* <p>
* If no files have a matching hash, or only those which don't belong to the correct repo, then
* this will return null. This method needs to do its own check whether the file exists,
* since files can be deleted from the cache at any time without warning.
*/
@Nullable
private Apk findApkMatchingHash(File apkPath) {
if (!apkPath.canRead()) {
return null;
}
// NOTE: This presumes SHA256 is the only supported hash. It seems like that is an assumption
// in more than one place in the F-Droid client. If this becomes a problem in the future, we
// can query the Apk table for `SELECT DISTINCT hashType FROM fdroid_apk` and then we can just
// try each of the hash types that have been specified in the metadata. Seems a bit overkill
// at the time of writing though.
String hash = Utils.getBinaryHash(apkPath, "sha256");
List<Apk> apksMatchingHash = ApkProvider.Helper.findApksByHash(this, hash);
Utils.debugLog(TAG, "Found " + apksMatchingHash.size() + " apk(s) matching the hash " + hash);
for (Apk apk : apksMatchingHash) {
if (apkPath.equals(ApkCache.getApkDownloadPath(this, Uri.parse(apk.getUrl())))) {
return apk;
}
}
return null;
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class ApkVerifierTest method testWithMinMax.
@Test(expected = ApkVerifier.ApkPermissionUnequalException.class)
public void testWithMinMax() throws ApkVerifier.ApkPermissionUnequalException, ApkVerifier.ApkVerificationException {
Apk apk = new Apk();
apk.packageName = "org.fdroid.permissions.minmax";
apk.targetSdkVersion = 24;
ArrayList<String> permissionsList = new ArrayList<>();
permissionsList.add("android.permission.READ_CALENDAR");
if (Build.VERSION.SDK_INT <= 18) {
permissionsList.add("android.permission.WRITE_EXTERNAL_STORAGE");
}
if (Build.VERSION.SDK_INT >= 23) {
permissionsList.add("android.permission.ACCESS_FINE_LOCATION");
}
apk.requestedPermissions = permissionsList.toArray(new String[permissionsList.size()]);
Uri uri = Uri.fromFile(minMaxApk);
ApkVerifier apkVerifier = new ApkVerifier(instrumentation.getContext(), uri, apk);
apkVerifier.verifyApk();
permissionsList.add("ADDITIONAL_PERMISSION");
apk.requestedPermissions = permissionsList.toArray(new String[permissionsList.size()]);
apkVerifier.verifyApk();
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class ApkVerifierTest method testWithPrefix.
@Test
public void testWithPrefix() {
Apk apk = new Apk();
apk.packageName = "org.fdroid.permissions.sdk14";
apk.targetSdkVersion = 14;
apk.requestedPermissions = new String[] { "android.permission.AUTHENTICATE_ACCOUNTS", "android.permission.MANAGE_ACCOUNTS", "android.permission.READ_PROFILE", "android.permission.WRITE_PROFILE", "android.permission.GET_ACCOUNTS", "android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE", "android.permission.NFC", "android.permission.READ_SYNC_SETTINGS", "android.permission.WRITE_SYNC_SETTINGS", // implied-permission!
"android.permission.WRITE_CALL_LOG", // implied-permission!
"android.permission.READ_CALL_LOG" };
Uri uri = Uri.fromFile(sdk14Apk);
ApkVerifier apkVerifier = new ApkVerifier(instrumentation.getContext(), uri, apk);
try {
apkVerifier.verifyApk();
} catch (ApkVerifier.ApkVerificationException | ApkVerifier.ApkPermissionUnequalException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class AppDetails2 method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case REQUEST_ENABLE_BLUETOOTH:
fdroidApp.sendViaBluetooth(this, resultCode, app.packageName);
break;
case REQUEST_PERMISSION_DIALOG:
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
Apk apk = ApkProvider.Helper.findByUri(this, uri, Schema.ApkTable.Cols.ALL);
startInstall(apk);
}
break;
case REQUEST_UNINSTALL_DIALOG:
if (resultCode == Activity.RESULT_OK) {
startUninstall();
}
break;
}
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class ProperMultiRepoUpdaterTest method assertMainArchiveRepoMetadata.
/**
* + AdAway (org.adaway)
* - Version 2.9.2 (51)
* - Version 2.9.1 (50)
* - Version 2.9 (49)
* - Version 2.8.1 (48)
* - Version 2.8 (47)
* - Version 2.7 (46)
* - Version 2.6 (45)
* - Version 2.3 (42)
* - Version 2.1 (40)
* - Version 1.37 (38)
* - Version 1.36 (37)
* - Version 1.35 (36)
* - Version 1.34 (35)
*/
private void assertMainArchiveRepoMetadata(List<Repo> allRepos) {
Repo repo = findRepo(REPO_ARCHIVE, allRepos);
List<Apk> apks = ApkProvider.Helper.findByRepo(context, repo, Schema.ApkTable.Cols.ALL);
assertEquals("Apks for main archive repo", 13, apks.size());
assertApksExist(apks, "org.adaway", new int[] { 35, 36, 37, 38, 40, 42, 45, 46, 47, 48, 49, 50, 51 });
assertAdAwayMetadata(repo, "Normal");
}
Aggregations