-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle exceptions when getting app icon in SplitTunnelingScreen
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PackageManagerExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |