Skip to content

Commit

Permalink
PM-14480: Update IntentManager to be able to launch apps (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-livefront authored Nov 5, 2024
1 parent 202b4de commit 7b2f6a2
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.IntentSender
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
Expand All @@ -27,6 +28,7 @@ import com.x8bit.bitwarden.MainActivity
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.autofill.util.toPendingIntentMutabilityFlag
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
import java.io.File
import java.time.Clock
Expand Down Expand Up @@ -82,7 +84,7 @@ class IntentManagerImpl(
override fun startActivity(intent: Intent) {
try {
context.startActivity(intent)
} catch (e: ActivityNotFoundException) {
} catch (_: ActivityNotFoundException) {
// no-op
}
}
Expand Down Expand Up @@ -115,7 +117,7 @@ class IntentManagerImpl(
}
context.startActivity(intent)
true
} catch (e: ActivityNotFoundException) {
} catch (_: ActivityNotFoundException) {
false
}

Expand All @@ -132,12 +134,28 @@ class IntentManagerImpl(
}

override fun launchUri(uri: Uri) {
val newUri = if (uri.scheme == null) {
uri.buildUpon().scheme("https").build()
if (uri.scheme.equals(other = "androidapp", ignoreCase = true)) {
val packageName = uri.toString().removePrefix(prefix = "androidapp://")
if (isBuildVersionBelow(Build.VERSION_CODES.TIRAMISU)) {
startActivity(createPlayStoreIntent(packageName))
} else {
try {
context
.packageManager
.getLaunchIntentSenderForPackage(packageName)
.sendIntent(context, Activity.RESULT_OK, null, null, null)
} catch (_: IntentSender.SendIntentException) {
startActivity(createPlayStoreIntent(packageName))
}
}
} else {
uri.normalizeScheme()
val newUri = if (uri.scheme == null) {
uri.buildUpon().scheme("https").build()
} else {
uri.normalizeScheme()
}
startActivity(Intent(Intent.ACTION_VIEW, newUri))
}
startActivity(Intent(Intent.ACTION_VIEW, newUri))
}

override fun shareText(text: String) {
Expand Down Expand Up @@ -301,6 +319,15 @@ class IntentManagerImpl(
startActivity(intent)
}

private fun createPlayStoreIntent(packageName: String): Intent {
val playStoreUri = "https://play.google.com/store/apps/details"
.toUri()
.buildUpon()
.appendQueryParameter("id", packageName)
.build()
return Intent(Intent.ACTION_VIEW, playStoreUri)
}

private fun getCameraFileData(): IntentManager.FileData {
val tmpDir = File(context.filesDir, TEMP_CAMERA_IMAGE_DIR)
val file = File(tmpDir, TEMP_CAMERA_IMAGE_NAME)
Expand Down

0 comments on commit 7b2f6a2

Please sign in to comment.