Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a8484c8 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

feat: remove dependency to e browser

parent cb7dfcb6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -819,6 +819,8 @@
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>

        <package android:name="foundation.e.browser" />

        <provider android:authorities="foundation.e.mail.provider.AppContentProvider" />
    </queries>

+0 −1
Original line number Diff line number Diff line
@@ -35,5 +35,4 @@ object Constants {

    const val MURENA_DAV_URL = "https://murena.io/remote.php/dav"

    const val E_BROWSER_PACKAGE_NAME = "foundation.e.browser"
}
+23 −4
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
package at.bitfire.davdroid.network

import android.content.Context
import at.bitfire.davdroid.Constants
import android.content.pm.PackageManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -20,9 +20,13 @@ import java.net.URL
@InstallIn(SingletonComponent::class)
object OAuthModule {

    private const val E_BROWSER_PACKAGE_NAME = "foundation.e.browser"

    @Provides
    fun authorizationService(@ApplicationContext context: Context): AuthorizationService =
        AuthorizationService(context,
    fun authorizationService(@ApplicationContext context: Context): AuthorizationService {
        val isEBrowserInstalled = isInstalled(context, E_BROWSER_PACKAGE_NAME)
        return AuthorizationService(
            context,
            AppAuthConfiguration.Builder()
                .setConnectionBuilder { uri ->
                    val url = URL(uri.toString())
@@ -30,7 +34,22 @@ object OAuthModule {
                        setRequestProperty("User-Agent", HttpClient.UserAgentInterceptor.userAgent)
                    }
                }
                .setBrowserMatcher { it.packageName == Constants.E_BROWSER_PACKAGE_NAME }
                .setBrowserMatcher { browser ->
                    if (isEBrowserInstalled) {
                        browser.packageName == E_BROWSER_PACKAGE_NAME
                    } else {
                        true
                    }
                }
                .build()
        )
    }

    private fun isInstalled(context: Context, packageName: String): Boolean =
        try {
            context.packageManager.getPackageInfo(packageName, 0)
            true
        } catch (_: PackageManager.NameNotFoundException) {
            false
        }
}