Skip to content

Commit

Permalink
Merge branch 'split-tunneling-icon-rendering-crash-droid-607'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jan 24, 2024
2 parents e0307dd + 57d1375 commit 905c922
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
package net.mullvad.mullvadvpn.compose.screen

import android.graphics.Bitmap
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import de.mannodermaus.junit5.compose.createComposeExtension
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
import io.mockk.verify
import net.mullvad.mullvadvpn.applist.AppData
import net.mullvad.mullvadvpn.applist.ApplicationsIconManager
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.SplitTunnelingUiState
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.koin.core.context.loadKoinModules
import org.koin.core.context.unloadKoinModules
import org.koin.dsl.module

@OptIn(ExperimentalTestApi::class)
class SplitTunnelingScreenTest {
@JvmField @RegisterExtension val composeExtension = createComposeExtension()

private val mockBitmap: Bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
private val testModule = module {
single {
mockk<ApplicationsIconManager>().apply {
every { getAppIcon(any()) } returns mockBitmap
}
}
}

@BeforeEach
fun setup() {
MockKAnnotations.init(this)
loadKoinModules(testModule)
}

@AfterEach
fun tearDown() {
unloadKoinModules(testModule)
unmockkAll()
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.graphics.drawable.toBitmapOrNull
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import net.mullvad.mullvadvpn.R
Expand All @@ -42,6 +41,7 @@ import net.mullvad.mullvadvpn.compose.state.SplitTunnelingUiState
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.util.getApplicationIconBitmapOrNull
import net.mullvad.mullvadvpn.viewmodel.SplitTunnelingViewModel
import org.koin.androidx.compose.koinViewModel

Expand Down Expand Up @@ -93,7 +93,7 @@ fun SplitTunneling(navigator: DestinationsNavigator) {
onIncludeAppClick = viewModel::onIncludeAppClick,
onBackClick = navigator::navigateUp,
onResolveIcon = { packageName ->
packageManager.getApplicationIcon(packageName).toBitmapOrNull()
packageManager.getApplicationIconBitmapOrNull(packageName)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Messenger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import net.mullvad.mullvadvpn.BuildConfig
import net.mullvad.mullvadvpn.applist.ApplicationsIconManager
import net.mullvad.mullvadvpn.applist.ApplicationsProvider
import net.mullvad.mullvadvpn.constant.IS_PLAY_BUILD
import net.mullvad.mullvadvpn.dataproxy.MullvadProblemReport
Expand Down Expand Up @@ -67,7 +66,6 @@ import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.qualifier.named
import org.koin.dsl.bind
import org.koin.dsl.module
import org.koin.dsl.onClose

val uiModule = module {
single<SharedPreferences>(named(APP_PREFERENCES_NAME)) {
Expand All @@ -78,7 +76,6 @@ val uiModule = module {
single<String>(named(SELF_PACKAGE_NAME)) { androidContext().packageName }

viewModel { SplitTunnelingViewModel(get(), get(), Dispatchers.Default) }
single { ApplicationsIconManager(get()) } onClose { it?.dispose() }
single { ApplicationsProvider(get(), get(named(SELF_PACKAGE_NAME))) }

single { (messenger: Messenger, dispatcher: EventDispatcher) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.mullvad.mullvadvpn.util

import android.content.pm.PackageManager
import android.graphics.Bitmap
import androidx.core.graphics.drawable.toBitmapOrNull

fun PackageManager.getApplicationIconBitmapOrNull(packageName: String): Bitmap? =
try {
getApplicationIcon(packageName).toBitmapOrNull()
} catch (e: Exception) {
// Name not found is thrown if the application is not installed
// IllegalArgumentException is thrown if the application has an invalid icon
when (e) {
is PackageManager.NameNotFoundException,
is IllegalArgumentException -> null
else -> throw e
}
}

This file was deleted.

0 comments on commit 905c922

Please sign in to comment.