Coverage Summary for Class: ActivityManagerImpl (cloud.mindbox.mobile_sdk.inapp.presentation)

Class Method, % Branch, % Line, % Instruction, %
ActivityManagerImpl 100% (3/3) 100% (4/4) 100% (11/11) 100% (52/52)
ActivityManagerImpl$tryOpenDeepLink$1 100% (1/1) 62.5% (5/8) 100% (12/12) 96.7% (59/61)
ActivityManagerImpl$tryOpenDeepLink$2 0% (0/1) 0% (0/1) 0% (0/2)
Total 80% (4/5) 75% (9/12) 95.8% (23/24) 96.5% (111/115)


 package cloud.mindbox.mobile_sdk.inapp.presentation
 
 import android.content.Context
 import android.content.Intent
 import android.content.pm.PackageManager
 import android.net.Uri
 import cloud.mindbox.mobile_sdk.inapp.domain.interfaces.interactors.CallbackInteractor
 import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
 
 internal class ActivityManagerImpl(
     private val callbackInteractor: CallbackInteractor,
     private val context: Context
 ) : ActivityManager {
 
     override fun tryOpenUrl(url: String): Boolean {
         try {
             Intent(Intent.ACTION_VIEW, Uri.parse(url)).also { intent ->
                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                 return if (callbackInteractor.isValidUrl(url) && intent.resolveActivity(context.packageManager) != null) {
                     context.startActivity(intent)
                     true
                 } else {
                     false
                 }
             }
         } catch (e: Exception) {
             return false
         }
     }
 
     override fun tryOpenDeepLink(deepLink: String): Boolean =
         LoggingExceptionHandler.runCatching(
             block = {
                 val intent = Intent(Intent.ACTION_VIEW, Uri.parse(deepLink)).apply {
                     addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                 }
                 if (intent.resolveActivity(context.packageManager) != null) {
                     if (intent.resolveActivityInfo(
                             context.packageManager,
                             PackageManager.MATCH_ALL
                         )?.exported == false
                     ) {
                         intent.`package` = context.packageName
                     }
                     context.startActivity(intent)
                     true
                 } else {
                     false
                 }
             },
             defaultValue = {
                 false
             }
         )
 }