Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-14480: Update IntentManager to be able to launch apps #4266

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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