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

Commit c9c87199 authored by Hasib Prince's avatar Hasib Prince Committed by Sayantan Roychowdhury
Browse files

unit test added for app install process

parent 6372b633
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line

plugins {
    id 'com.android.application'
    id 'kotlin-android'
@@ -156,6 +157,8 @@ dependencies {
    testImplementation 'org.mockito:mockito-inline:2.13.0'
    testImplementation "androidx.arch.core:core-testing:2.1.0"

    testImplementation "io.mockk:mockk:1.13.4"

    // Coil and PhotoView
    implementation "io.coil-kt:coil:1.4.0"
    implementation 'com.github.Baseflow:PhotoView:2.3.0'
@@ -190,19 +193,19 @@ dependencies {
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.2"

    // Navigation Components
    def navigation_version = "2.3.5"
    def navigation_version = "2.5.3"
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

    // Hilt
    def hilt_version = '2.40.5'
    def hilt_version = '2.44.2'
    kapt "com.google.dagger:hilt-compiler:$hilt_version"
    implementation "com.google.dagger:hilt-android:$hilt_version"
    implementation 'androidx.hilt:hilt-work:1.0.0'
    kapt 'androidx.hilt:hilt-compiler:1.0.0'

    // Lifecycle Components
    def lifecycle_version = "2.4.0"
    def lifecycle_version = "2.5.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    implementation "android.arch.lifecycle:extensions:1.1.1"
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package foundation.e.apps.api

import android.app.DownloadManager
import android.net.Uri
import foundation.e.apps.OpenForTesting
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -34,6 +35,7 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

@Singleton
@OpenForTesting
class DownloadManager @Inject constructor(
    private val downloadManager: DownloadManager,
    @Named("cacheDir") private val cacheDir: String,
+5 −5
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ import javax.inject.Singleton
class FdroidRepository @Inject constructor(
    private val fdroidApi: FdroidApiInterface,
    private val fdroidDao: FdroidDao,
) {
) : IFdroidRepository {

    companion object {
        const val UNKNOWN = "unknown"
@@ -26,7 +26,7 @@ class FdroidRepository @Inject constructor(
     *
     * Result may be null.
     */
    private suspend fun getFdroidInfo(packageName: String): FdroidEntity? {
    override suspend fun getFdroidInfo(packageName: String): FdroidEntity? {
        return fdroidDao.getFdroidEntityFromPackageName(packageName)
            ?: fdroidApi.getFdroidInfoForPackage(packageName).body()?.let {
                FdroidEntity(packageName, it.authorName).also {
@@ -35,7 +35,7 @@ class FdroidRepository @Inject constructor(
            }
    }

    suspend fun getAuthorName(fusedApp: FusedApp): String {
    override suspend fun getAuthorName(fusedApp: FusedApp): String {
        if (fusedApp.author != UNKNOWN || fusedApp.origin != Origin.CLEANAPK) {
            return fusedApp.author.ifEmpty { UNKNOWN }
        }
@@ -49,14 +49,14 @@ class FdroidRepository @Inject constructor(
        return result?.authorName ?: FdroidEntity.DEFAULT_FDROID_AUTHOR_NAME
    }

    suspend fun isFdroidApplicationSigned(context: Context, packageName: String, apkFilePath: String, signature: String): Boolean {
    override suspend fun isFdroidApplicationSigned(context: Context, packageName: String, apkFilePath: String, signature: String): Boolean {
        if (isFdroidApplication(packageName)) {
            return ApkSignatureManager.verifyFdroidSignature(context, apkFilePath, signature)
        }
        return false
    }

    private suspend fun isFdroidApplication(packageName: String): Boolean {
    override suspend fun isFdroidApplication(packageName: String): Boolean {
        return fdroidApi.getFdroidInfoForPackage(packageName).isSuccessful
    }
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.api.fdroid

import android.content.Context
import foundation.e.apps.api.fdroid.models.FdroidEntity
import foundation.e.apps.api.fused.data.FusedApp

interface IFdroidRepository {
    /**
     * Get Fdroid entity from DB is present.
     * If not present then make an API call, store the fetched result and return the result.
     *
     * Result may be null.
     */
    suspend fun getFdroidInfo(packageName: String): FdroidEntity?

    suspend fun getAuthorName(fusedApp: FusedApp): String

    suspend fun isFdroidApplicationSigned(
        context: Context,
        packageName: String,
        apkFilePath: String,
        signature: String
    ): Boolean

    suspend fun isFdroidApplication(packageName: String): Boolean
}
+1 −1
Original line number Diff line number Diff line
@@ -384,7 +384,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
    }

    private fun setupToolbar(view: View) {
        val startDestination = findNavController().graph.startDestination
        val startDestination = findNavController().graph.startDestinationId
        if (startDestination == R.id.applicationFragment) {
            binding.toolbar.setNavigationOnClickListener {
                val action = ApplicationFragmentDirections.actionApplicationFragmentToHomeFragment()
Loading