Merge branch 'android-app-links' into 'master'

set up "Android App Links" handling aka "Digital Asset Links"

See merge request fdroid/fdroidclient!626
This commit is contained in:
Hans-Christoph Steiner 2018-01-17 13:23:57 +00:00
commit dd0f791e3f
5 changed files with 41 additions and 26 deletions

View File

@ -301,7 +301,7 @@
<data android:scheme="fdroid.app" /> <data android:scheme="fdroid.app" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
@ -311,20 +311,13 @@
<data android:scheme="https" /> <data android:scheme="https" />
<data android:host="f-droid.org" /> <data android:host="f-droid.org" />
<data android:host="www.f-droid.org" /> <data android:host="www.f-droid.org" />
<data android:host="staging.f-droid.org" />
<data android:pathPrefix="/app/" /> <data android:pathPrefix="/app/" />
</intent-filter> <data android:pathPrefix="/packages/" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="f-droid.org" />
<data android:host="www.f-droid.org" />
<data android:pathPrefix="/repository/browse" /> <data android:pathPrefix="/repository/browse" />
<!-- support localized URLs -->
<data android:pathPattern="/.*/packages/.*" />
<data android:pathPattern="/.*/packages/.*/" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>

View File

@ -409,7 +409,7 @@ public final class Utils {
fis = new FileInputStream(apk); fis = new FileInputStream(apk);
BufferedInputStream bis = new BufferedInputStream(fis); BufferedInputStream bis = new BufferedInputStream(fis);
byte[] dataBytes = new byte[524288]; byte[] dataBytes = new byte[8192];
int nread; int nread;
while ((nread = bis.read(dataBytes)) != -1) { while ((nread = bis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread); md.update(dataBytes, 0, nread);

View File

@ -1,4 +1,5 @@
/* /*
**
** Copyright 2007, The Android Open Source Project ** Copyright 2007, The Android Open Source Project
** Copyright 2015 Daniel Martí <mvdan@mvdan.cc> ** Copyright 2015 Daniel Martí <mvdan@mvdan.cc>
** **
@ -43,7 +44,6 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
@ -67,12 +67,18 @@ import java.util.Set;
* view by instantiating AppSecurityPermissions and invoking getPermissionsView. * view by instantiating AppSecurityPermissions and invoking getPermissionsView.
* <p/> * <p/>
* NOTES: * NOTES:
* Based on AOSP core/java/android/widget/AppSecurityPermissions * Based on AOSP core/java/android/widget/AppSecurityPermissions.java
* latest included commit: a3f68ef2f6811cf72f1282214c0883db5a30901d * latest included commit: a3f68ef2f6811cf72f1282214c0883db5a30901d
* Reviewed against frameworks/base/core/java/android/widget/AppSecurityPermissions.java
* from commit {@code android-8.1.0_r2}
* <p/> * <p/>
* To update this file, Start from latest included commit and include changes * To update this file, Start from latest included commit and include changes
* until the newest commit with care: * until the newest commit with care:
* github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AppSecurityPermissions.java * github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AppSecurityPermissions.java
* <p/>
* This file has a different code style than the rest of fdroidclient because
* it is kept in sync with the file from AOSP. Please maintain the original
* AOSP code style so it is easy to track changes.
*/ */
public class AppSecurityPermissions { public class AppSecurityPermissions {

View File

@ -16,11 +16,9 @@ import android.support.v7.widget.RecyclerView;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
import com.ashokvarma.bottomnavigation.BadgeItem; import com.ashokvarma.bottomnavigation.BadgeItem;
import com.ashokvarma.bottomnavigation.BottomNavigationBar; import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem; import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import org.fdroid.fdroid.AppDetails2; import org.fdroid.fdroid.AppDetails2;
import org.fdroid.fdroid.AppUpdateStatusManager; import org.fdroid.fdroid.AppUpdateStatusManager;
import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus; import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus;
@ -226,18 +224,20 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
} }
switch (host) { switch (host) {
case "f-droid.org": case "f-droid.org":
if (path.startsWith("/repository/browse")) { case "www.f-droid.org":
case "staging.f-droid.org":
if (path.startsWith("/app/") || path.startsWith("/packages/")
|| path.matches("^/[a-z][a-z][a-zA-Z_-]*/packages/.*")) {
// http://f-droid.org/app/packageName
packageName = data.getLastPathSegment();
} else if (path.startsWith("/repository/browse")) {
// http://f-droid.org/repository/browse?fdfilter=search+query // http://f-droid.org/repository/browse?fdfilter=search+query
query = UriCompat.getQueryParameter(data, "fdfilter"); query = UriCompat.getQueryParameter(data, "fdfilter");
// http://f-droid.org/repository/browse?fdid=packageName // http://f-droid.org/repository/browse?fdid=packageName
packageName = UriCompat.getQueryParameter(data, "fdid"); packageName = UriCompat.getQueryParameter(data, "fdid");
} else if (path.startsWith("/app")) { } else if ("/app".equals(data.getPath()) || "/packages".equals(data.getPath())) {
// http://f-droid.org/app/packageName packageName = null;
packageName = data.getLastPathSegment();
if ("app".equals(packageName)) {
packageName = null;
}
} }
break; break;
case "details": case "details":

View File

@ -2,7 +2,6 @@
package org.fdroid.fdroid; package org.fdroid.fdroid;
import android.content.Context; import android.content.Context;
import org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter; import org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -10,6 +9,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import java.io.File;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -174,6 +175,21 @@ public class UtilsTest {
} }
} }
@Test
public void testGetBinaryHash() {
File f = TestUtils.copyResourceToTempFile("largeRepo.xml");
assertEquals("df1754aa4b56c86c06d7842dfd02064f0781c1f740f489d3fc158bb541c8d197",
Utils.getBinaryHash(f, "sha256"));
f = TestUtils.copyResourceToTempFile("masterKeyIndex.jar");
assertEquals("625d5aedcd0499fe04ebab81f3c7ae30c236cee653a914ffb587d890198f3aba",
Utils.getBinaryHash(f, "sha256"));
f = TestUtils.copyResourceToTempFile("index.fdroid.2016-10-30.jar");
assertEquals("c138b503c6475aa749585d0e3ad4dba3546b6d33ec485efd8ac8bd603d93fedb",
Utils.getBinaryHash(f, "sha256"));
f = TestUtils.copyResourceToTempFile("index.fdroid.2016-11-10.jar");
assertEquals("93bea45814fd8955cabb957e7a3f8790d6c568eaa16fa30425c2d26c60490bde",
Utils.getBinaryHash(f, "sha256"));
}
// TODO write tests that work with a Certificate // TODO write tests that work with a Certificate
} }