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

Commit 0cc7ae50 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

feat: remove strict dependency to e browser

Remove dependency to e browser, but use it when it is present though.
parent cb7dfcb6
Loading
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"
}
+33 −12
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@
package at.bitfire.davdroid.network

import android.content.Context
import at.bitfire.davdroid.Constants
import android.content.pm.PackageManager
import android.os.Build
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -20,17 +21,37 @@ 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,
            AppAuthConfiguration.Builder()
    fun authorizationService(@ApplicationContext context: Context): AuthorizationService {
        val builder = AppAuthConfiguration.Builder()
            .setConnectionBuilder { uri ->
                val url = URL(uri.toString())
                (url.openConnection() as HttpURLConnection).apply {
                    setRequestProperty("User-Agent", HttpClient.UserAgentInterceptor.userAgent)
                }
            }
                .setBrowserMatcher { it.packageName == Constants.E_BROWSER_PACKAGE_NAME }
                .build()
        )

        if (isInstalled(context, E_BROWSER_PACKAGE_NAME)) {
            builder.setBrowserMatcher { browser ->
                browser.packageName == E_BROWSER_PACKAGE_NAME
            }
        }

        return AuthorizationService(context, builder.build())
    }

    private fun isInstalled(context: Context, packageName: String): Boolean =
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                context.packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
            } else {
                @Suppress("DEPRECATION")
                context.packageManager.getPackageInfo(packageName, 0)
            }
            true
        } catch (_: PackageManager.NameNotFoundException) {
            false
        }
}