diff --git a/app/build.gradle b/app/build.gradle index aa0b9c58..0984ce8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -95,18 +95,18 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") implementation("androidx.core:core-ktx:1.8.0") - implementation("androidx.activity:activity-ktx:1.5.0") - implementation("androidx.fragment:fragment-ktx:1.5.0") - implementation("androidx.appcompat:appcompat:1.4.2") + implementation("androidx.activity:activity-ktx:1.5.1") + implementation("androidx.fragment:fragment-ktx:1.5.1") + implementation("androidx.appcompat:appcompat:1.5.0-rc01") implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.recyclerview:recyclerview:1.2.1") implementation("com.google.android.material:material:1.6.1") implementation("androidx.window:window:1.0.0") - implementation("androidx.navigation:navigation-fragment-ktx:2.5.0") - implementation("androidx.navigation:navigation-ui-ktx:2.5.0") - implementation("androidx.lifecycle:lifecycle-livedata:2.5.0") - implementation("androidx.lifecycle:lifecycle-common:2.5.0") + implementation("androidx.navigation:navigation-fragment-ktx:2.5.1") + implementation("androidx.navigation:navigation-ui-ktx:2.5.1") + implementation("androidx.lifecycle:lifecycle-livedata:2.5.1") + implementation("androidx.lifecycle:lifecycle-common:2.5.1") implementation("com.afollestad.material-dialogs:core:3.3.0") implementation("com.afollestad.material-dialogs:color:3.3.0") @@ -125,7 +125,7 @@ dependencies { exclude group: "com.android.support" } firebaseImplementation("com.google.firebase:firebase-analytics:21.1.0") - firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.11") + firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.12") firebaseImplementation("com.google.android.gms:play-services-ads:21.1.0") // debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1") diff --git a/app/src/firebase/kotlin/info/dvkr/screenstream/ui/fragment/AdFragment.kt b/app/src/firebase/kotlin/info/dvkr/screenstream/ui/fragment/AdFragment.kt index 5c603482..450b61ee 100644 --- a/app/src/firebase/kotlin/info/dvkr/screenstream/ui/fragment/AdFragment.kt +++ b/app/src/firebase/kotlin/info/dvkr/screenstream/ui/fragment/AdFragment.kt @@ -31,13 +31,16 @@ abstract class AdFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLay else adViewContainer.viewTreeObserver.addOnGlobalLayoutListener( object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { + adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this) + var adWidthPixels = adViewContainer.width.toFloat() - if (adWidthPixels == 0f) adWidthPixels = WindowMetricsCalculator.getOrCreate() - .computeCurrentWindowMetrics(requireActivity()).bounds.width().toFloat() + activity?.let { + if (adWidthPixels == 0f) adWidthPixels = WindowMetricsCalculator.getOrCreate() + .computeCurrentWindowMetrics(it).bounds.width().toFloat() + } ?: return // Not attached to an activity. + val adWidth = (adWidthPixels / resources.displayMetrics.density).toInt() adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(requireContext(), adWidth) - - adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this) loadAd(adViewContainer) } } diff --git a/app/src/main/kotlin/info/dvkr/screenstream/receiver/BootReceiver.kt b/app/src/main/kotlin/info/dvkr/screenstream/receiver/BootReceiver.kt index 3b7eb429..5416a36d 100644 --- a/app/src/main/kotlin/info/dvkr/screenstream/receiver/BootReceiver.kt +++ b/app/src/main/kotlin/info/dvkr/screenstream/receiver/BootReceiver.kt @@ -4,6 +4,7 @@ package info.dvkr.screenstream.receiver import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.os.Build import com.elvishew.xlog.XLog import info.dvkr.screenstream.data.other.getLog import info.dvkr.screenstream.data.settings.SettingsReadOnly @@ -18,15 +19,20 @@ class BootReceiver : BroadcastReceiver(), KoinComponent { private val settingsReadOnly: SettingsReadOnly by inject() override fun onReceive(context: Context, intent: Intent) { - XLog.d(getLog("onReceive", "Invoked")) + XLog.d(getLog("onReceive", "Invoked: (SDK: ${Build.VERSION.SDK_INT}) Intent Action: ${intent.action}")) - if (runBlocking { settingsReadOnly.startOnBootFlow.first().not() }) Runtime.getRuntime().exit(0) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (intent.action != Intent.ACTION_BOOT_COMPLETED) { + Runtime.getRuntime().exit(0) + return + } + } - if ( - intent.action == "android.intent.action.BOOT_COMPLETED" || - intent.action == "android.intent.action.QUICKBOOT_POWERON" - ) { - IntentAction.StartOnBoot.sendToAppService(context) + if (runBlocking { settingsReadOnly.startOnBootFlow.first().not() }) { + Runtime.getRuntime().exit(0) + return } + + IntentAction.StartOnBoot.sendToAppService(context) } } \ No newline at end of file diff --git a/app/src/main/kotlin/info/dvkr/screenstream/service/AppService.kt b/app/src/main/kotlin/info/dvkr/screenstream/service/AppService.kt index bec9a683..5b7a4043 100644 --- a/app/src/main/kotlin/info/dvkr/screenstream/service/AppService.kt +++ b/app/src/main/kotlin/info/dvkr/screenstream/service/AppService.kt @@ -36,8 +36,6 @@ import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withTimeout import org.koin.android.ext.android.inject import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicReference @@ -49,9 +47,15 @@ class AppService : Service() { fun getAppServiceIntent(context: Context): Intent = Intent(context.applicationContext, AppService::class.java) - fun startService(context: Context, intent: Intent) = context.startService(intent) + fun startService(context: Context, intent: Intent) { + runCatching { context.startService(intent) } + .onFailure { XLog.e(getLog("startService", "Failed to start Service"), it) } + } - fun startForeground(context: Context, intent: Intent) = ContextCompat.startForegroundService(context, intent) + fun startForeground(context: Context, intent: Intent) { + runCatching { ContextCompat.startForegroundService(context, intent) } + .onFailure { XLog.e(getLog("startForeground", "Failed to start Foreground Service"), it) } + } } class AppServiceBinder(private val serviceMessageSharedFlow: MutableSharedFlow) : Binder() { diff --git a/app/src/main/kotlin/info/dvkr/screenstream/service/TileActionService.kt b/app/src/main/kotlin/info/dvkr/screenstream/service/TileActionService.kt index b1157a93..609d4d1b 100644 --- a/app/src/main/kotlin/info/dvkr/screenstream/service/TileActionService.kt +++ b/app/src/main/kotlin/info/dvkr/screenstream/service/TileActionService.kt @@ -66,7 +66,7 @@ class TileActionService : TileService() { isBound = false } } - bindService(AppService.getAppServiceIntent(this), serviceConnection!!, Context.BIND_AUTO_CREATE) + serviceConnection?.let { bindService(AppService.getAppServiceIntent(this), it, Context.BIND_AUTO_CREATE) } } else { isStreaming = false updateTile() @@ -80,6 +80,7 @@ class TileActionService : TileService() { coroutineScope?.cancel() coroutineScope = null serviceConnection?.let { unbindService(it) } + serviceConnection = null isBound = false } isStreaming = false