diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt index 339673949178..5164fe0a3dba 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt @@ -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 @@ -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 @@ -93,7 +93,7 @@ fun SplitTunneling(navigator: DestinationsNavigator) { onIncludeAppClick = viewModel::onIncludeAppClick, onBackClick = navigator::navigateUp, onResolveIcon = { packageName -> - packageManager.getApplicationIcon(packageName).toBitmapOrNull() + packageManager.getApplicationIconBitmapOrNull(packageName) } ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PackageManagerExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PackageManagerExtensions.kt new file mode 100644 index 000000000000..ea8ce1f4e1ec --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PackageManagerExtensions.kt @@ -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 + } + }