Skip to content

Commit 2fdb8cf

Browse files
committedSep 6, 2022
Bug fixes
1 parent e3ee332 commit 2fdb8cf

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed
 

‎app/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId = "info.dvkr.screenstream"
1313
minSdkVersion(21)
1414
targetSdkVersion(33)
15-
versionCode = 31000
16-
versionName = "3.10.0"
15+
versionCode = 31001
16+
versionName = "3.10.1"
1717

1818
// Don't forget to update xml/locales_config.xml
1919
resConfigs 'en', 'ar', 'ca', 'de', 'es', 'fa', 'fr-rFR', 'gl', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-rBR', 'ru', 'sk', 'uk', 'zh', 'zh-rTW'
@@ -98,13 +98,13 @@ dependencies {
9898
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
9999
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
100100

101-
implementation("androidx.core:core-ktx:1.9.0-beta01")
102-
implementation("androidx.activity:activity-ktx:1.6.0-beta01")
101+
implementation("androidx.core:core-ktx:1.9.0-rc01")
102+
implementation("androidx.activity:activity-ktx:1.6.0-rc01")
103103
implementation("androidx.fragment:fragment-ktx:1.5.2")
104104
implementation("androidx.appcompat:appcompat:1.6.0-beta01")
105105
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
106106
implementation("androidx.recyclerview:recyclerview:1.2.1")
107-
implementation("com.google.android.material:material:1.7.0-beta01")
107+
implementation("com.google.android.material:material:1.7.0-rc01")
108108
implementation("androidx.window:window:1.0.0")
109109

110110
implementation("androidx.navigation:navigation-fragment-ktx:2.5.1")
@@ -128,8 +128,8 @@ dependencies {
128128
firebaseImplementation("com.google.android.play:app-update-ktx:2.0.0") {
129129
exclude group: "com.android.support"
130130
}
131-
firebaseImplementation("com.google.firebase:firebase-analytics:21.1.0")
132-
firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.12")
131+
firebaseImplementation("com.google.firebase:firebase-analytics:21.1.1")
132+
firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.13")
133133
firebaseImplementation("com.google.android.gms:play-services-ads:21.1.0")
134134

135135
// debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")

‎app/src/main/kotlin/info/dvkr/screenstream/service/ForegroundService.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,22 @@ class ForegroundService : Service() {
3636
@Volatile
3737
var isRunning: Boolean = false
3838

39+
@JvmStatic
3940
fun getForegroundServiceIntent(context: Context): Intent = Intent(context, ForegroundService::class.java)
4041

42+
@JvmStatic
4143
fun startForeground(context: Context, intent: Intent) {
42-
XLog.e(getLog("startForeground"))
44+
XLog.d(getLog("startForeground", intent.extras?.toString()))
4345
runCatching { ContextCompat.startForegroundService(context, intent) }
4446
.onFailure { XLog.e(getLog("startForeground", "Failed to start Foreground Service"), it) }
4547
}
48+
49+
@JvmStatic
50+
fun startService(context: Context, intent: Intent) {
51+
XLog.d(getLog("startService", intent.extras?.toString()))
52+
runCatching { context.startService(intent) }
53+
.onFailure { XLog.e(getLog("startService", "Failed to start Service"), it) }
54+
}
4655
}
4756

4857
internal object ForegroundServiceBinder : Binder() {

‎app/src/main/kotlin/info/dvkr/screenstream/service/TileActionService.kt

+28-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.content.ServiceConnection
1010
import android.graphics.drawable.Icon
1111
import android.os.Build
1212
import android.os.IBinder
13+
import android.os.RemoteException
1314
import android.service.quicksettings.Tile
1415
import android.service.quicksettings.TileService
1516
import androidx.annotation.RequiresApi
@@ -53,24 +54,35 @@ class TileActionService : TileService() {
5354
serviceConnection = object : ServiceConnection {
5455
override fun onServiceConnected(name: ComponentName?, binder: IBinder) {
5556
XLog.d(this@TileActionService.getLog("onServiceConnected"))
56-
coroutineScope?.cancel()
57-
coroutineScope = CoroutineScope(Job() + Dispatchers.Main.immediate).apply {
58-
launch(CoroutineName("TileActionService.ServiceMessageFlow")) {
59-
(binder as ForegroundService.ForegroundServiceBinder).serviceMessageFlow.onEach { serviceMessage ->
60-
XLog.d(this@TileActionService.getLog("onServiceMessage", "$serviceMessage"))
61-
when (serviceMessage) {
62-
is ServiceMessage.ServiceState -> {
63-
isStreaming = serviceMessage.isStreaming; updateTile()
64-
}
65-
is ServiceMessage.FinishActivity -> {
66-
isStreaming = false; updateTile()
57+
58+
try {
59+
val foregroundServiceBinder = binder as ForegroundService.ForegroundServiceBinder
60+
61+
coroutineScope?.cancel()
62+
coroutineScope = CoroutineScope(Job() + Dispatchers.Main.immediate)
63+
coroutineScope!!.launch {
64+
foregroundServiceBinder.serviceMessageFlow
65+
.onEach { serviceMessage ->
66+
XLog.d(this@TileActionService.getLog("onServiceMessage", "$serviceMessage"))
67+
when (serviceMessage) {
68+
is ServiceMessage.ServiceState -> {
69+
isStreaming = serviceMessage.isStreaming; updateTile()
70+
}
71+
is ServiceMessage.FinishActivity -> {
72+
isStreaming = false; updateTile()
73+
}
74+
else -> Unit
6775
}
68-
else -> Unit
6976
}
70-
}
71-
.catch { cause -> XLog.e(this@TileActionService.getLog("onServiceMessage"), cause) }
77+
.catch { cause ->
78+
XLog.e(this@TileActionService.getLog("onServiceConnected.serviceMessageFlow: $cause"))
79+
XLog.e(this@TileActionService.getLog("onServiceConnected.serviceMessageFlow"), cause)
80+
}
7281
.collect()
7382
}
83+
} catch (cause: RemoteException) {
84+
XLog.e(this@TileActionService.getLog("onServiceConnected", "Failed to bind"), cause)
85+
return
7486
}
7587
isBound = true
7688
IntentAction.GetServiceState.sendToAppService(this@TileActionService)
@@ -83,7 +95,8 @@ class TileActionService : TileService() {
8395
isBound = false
8496
}
8597
}
86-
serviceConnection?.let { bindService(ForegroundService.getForegroundServiceIntent(this), it, Context.BIND_AUTO_CREATE) }
98+
99+
bindService(ForegroundService.getForegroundServiceIntent(this), serviceConnection!!, Context.BIND_AUTO_CREATE)
87100
} else {
88101
isStreaming = false
89102
updateTile()

‎app/src/main/kotlin/info/dvkr/screenstream/service/helper/IntentAction.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ internal sealed class IntentAction : Parcelable {
2727
AppActivity.getAppActivityIntent(context).putExtra(EXTRA_PARCELABLE, this@IntentAction)
2828

2929
internal fun sendToAppService(context: Context) =
30-
ForegroundService.startForeground(context, this.toAppServiceIntent(context))
30+
if (ForegroundService.isRunning)
31+
ForegroundService.startService(context, this.toAppServiceIntent(context))
32+
else
33+
ForegroundService.startForeground(context, this.toAppServiceIntent(context))
3134

3235
@Parcelize object GetServiceState : IntentAction()
3336
@Parcelize object StartStream : IntentAction()

‎data/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies {
2929
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10")
3030

3131
//noinspection KtxExtensionAvailable
32-
implementation("androidx.core:core:1.9.0-beta01")
32+
implementation("androidx.core:core:1.9.0-rc01")
3333
implementation("androidx.window:window:1.0.0")
3434

3535
implementation("io.ktor:ktor-server-cio:2.1.0")

‎data/src/main/kotlin/info/dvkr/screenstream/data/state/AppStateMachineImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class AppStateMachineImpl(
257257
try {
258258
runBlocking(coroutineScope.coroutineContext) { withTimeout(1000) { httpServer.destroy().await() } }
259259
} catch (cause: Throwable) {
260-
XLog.e(getLog("destroy"), cause)
260+
XLog.e(getLog("destroy", cause.toString()))
261261
}
262262
broadcastHelper.stopListening()
263263
connectivityHelper.stopListening()

0 commit comments

Comments
 (0)
Failed to load comments.