Skip to content

Commit

Permalink
Update to AGP 7.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Sep 26, 2022
1 parent 2fdb8cf commit f4ebf6c
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 309 deletions.
35 changes: 18 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"

android {
namespace "info.dvkr.screenstream"
compileSdkVersion(33)
buildToolsVersion("33.0.0")

defaultConfig {
applicationId = "info.dvkr.screenstream"
minSdkVersion(21)
targetSdkVersion(33)
versionCode = 31001
versionName = "3.10.1"
versionCode = 31002
versionName = "3.10.2"

// Don't forget to update xml/locales_config.xml
resConfigs 'en', 'ar', 'ca', 'de', 'es', 'fa', 'fr-rFR', 'gl', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-rBR', 'ru', 'sk', 'uk', 'zh', 'zh-rTW'

// https://medium.com/@crafty/no-if-you-do-that-then-you-cant-use-newer-features-on-older-platforms-e-g-fa595333c0a4
vectorDrawables.useSupportLibrary = true
}

Expand Down Expand Up @@ -62,8 +64,8 @@ android {

compileOptions {
coreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

sourceSets {
Expand All @@ -79,36 +81,35 @@ android {
}
packagingOptions {
resources {
excludes += ['META-INF/INDEX.LIST']
excludes += ["META-INF/INDEX.LIST"]
}
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = JavaVersion.VERSION_11.toString()
}

}

dependencies {
// TODO waiting for Android Studio Dolphin release
// https://developer.android.com/about/versions/13/features#core-libraries
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.2")

implementation(project(":data"))

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")

implementation("androidx.core:core-ktx:1.9.0-rc01")
implementation("androidx.activity:activity-ktx:1.6.0-rc01")
implementation("androidx.fragment:fragment-ktx:1.5.2")
implementation("androidx.appcompat:appcompat:1.6.0-beta01")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.activity:activity-ktx:1.6.0")
implementation("androidx.fragment:fragment-ktx:1.5.3")
implementation("androidx.appcompat:appcompat:1.6.0-rc01")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("com.google.android.material:material:1.7.0-rc01")
implementation("androidx.window:window:1.0.0")

implementation("androidx.navigation:navigation-fragment-ktx:2.5.1")
implementation("androidx.navigation:navigation-ui-ktx:2.5.1")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.2")
implementation("androidx.navigation:navigation-ui-ktx:2.5.2")
implementation("androidx.lifecycle:lifecycle-livedata:2.5.1")
implementation("androidx.lifecycle:lifecycle-common:2.5.1")

Expand All @@ -120,7 +121,7 @@ dependencies {
implementation(fileTree("libs/bottomsheets-release.aar"))
// implementation("com.afollestad.material-dialogs:bottomsheets:3.3.0")

implementation("io.insert-koin:koin-android:3.2.0")
implementation("io.insert-koin:koin-android:3.2.2")
implementation("com.github.iamironz:binaryprefs:1.0.1") //Migrating to datastore
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("com.elvishew:xlog:1.11.0")
Expand All @@ -130,7 +131,7 @@ dependencies {
}
firebaseImplementation("com.google.firebase:firebase-analytics:21.1.1")
firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.13")
firebaseImplementation("com.google.android.gms:play-services-ads:21.1.0")
firebaseImplementation("com.google.android.gms:play-services-ads:21.2.0")

// debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="info.dvkr.screenstream"
android:installLocation="auto">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -20,7 +19,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App.DayNight"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning"
tools:targetApi="tiramisu">

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import android.app.Service
import android.content.Context
import android.content.Intent
import android.hardware.display.DisplayManager
import android.os.Binder
import android.os.Build
import android.os.IBinder
import android.os.RemoteException
import android.view.Display
import android.view.LayoutInflater
import android.view.WindowManager
Expand Down Expand Up @@ -52,19 +50,15 @@ class ForegroundService : Service() {
runCatching { context.startService(intent) }
.onFailure { XLog.e(getLog("startService", "Failed to start Service"), it) }
}
}

internal object ForegroundServiceBinder : Binder() {
@JvmStatic
private val serviceMessageSharedFlow = MutableSharedFlow<ServiceMessage>()

@JvmStatic
internal val serviceMessageFlow: SharedFlow<ServiceMessage> = serviceMessageSharedFlow.asSharedFlow()

internal suspend fun sendMessage(serviceMessage: ServiceMessage) = try {
serviceMessageSharedFlow.emit(serviceMessage)
} catch (cause: RemoteException) {
XLog.d(getLog("sendMessage", "Failed to send message: $serviceMessage: $cause"))
XLog.e(getLog("sendMessage", "Failed to send message: $serviceMessage"), cause)
}
@JvmStatic
internal suspend fun sendMessage(serviceMessage: ServiceMessage) = serviceMessageSharedFlow.emit(serviceMessage)
}

private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
Expand All @@ -76,15 +70,7 @@ class ForegroundService : Service() {
private var appStateMachine: AppStateMachine? = null
private var appErrorPrevious: AppError? = null

override fun onBind(intent: Intent?): IBinder {
XLog.e(getLog("onBind"))
return ForegroundServiceBinder
}

override fun onUnbind(intent: Intent?): Boolean {
XLog.e(getLog("onUnbind"))
return super.onUnbind(intent)
}
override fun onBind(intent: Intent?): IBinder? = null

override fun onCreate() {
super.onCreate()
Expand All @@ -101,10 +87,9 @@ class ForegroundService : Service() {
is AppStateMachine.Effect.ConnectionChanged -> Unit // TODO Notify user about restart reason

is AppStateMachine.Effect.PublicState -> {
ForegroundServiceBinder.sendMessage(
sendMessage(
ServiceMessage.ServiceState(
effect.isStreaming, effect.isBusy, effect.waitingForPermission,
effect.netInterfaces, effect.appError
effect.isStreaming, effect.isBusy, effect.waitingForPermission, effect.netInterfaces, effect.appError
)
)

Expand All @@ -116,11 +101,9 @@ class ForegroundService : Service() {
}

is AppStateMachine.Effect.Statistic -> {
if (effect is AppStateMachine.Effect.Statistic.Clients)
ForegroundServiceBinder.sendMessage(ServiceMessage.Clients(effect.clients))
if (effect is AppStateMachine.Effect.Statistic.Clients) sendMessage(ServiceMessage.Clients(effect.clients))

if (effect is AppStateMachine.Effect.Statistic.Traffic)
ForegroundServiceBinder.sendMessage(ServiceMessage.TrafficHistory(effect.traffic))
if (effect is AppStateMachine.Effect.Statistic.Traffic) sendMessage(ServiceMessage.TrafficHistory(effect.traffic))
}
}
}
Expand Down Expand Up @@ -162,7 +145,7 @@ class ForegroundService : Service() {

notificationHelper.hideErrorNotification()
stopForeground(true)
coroutineScope.launch { ForegroundServiceBinder.sendMessage(ServiceMessage.FinishActivity) }
coroutineScope.launch { sendMessage(ServiceMessage.FinishActivity) }
this@ForegroundService.stopSelf()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import android.app.StatusBarManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.graphics.drawable.Icon
import android.os.Build
import android.os.IBinder
import android.os.RemoteException
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
Expand All @@ -19,9 +16,6 @@ import info.dvkr.screenstream.R
import info.dvkr.screenstream.data.other.getLog
import info.dvkr.screenstream.service.helper.IntentAction
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach

@TargetApi(Build.VERSION_CODES.N)
class TileActionService : TileService() {
Expand All @@ -42,61 +36,35 @@ class TileActionService : TileService() {
}

private var coroutineScope: CoroutineScope? = null
private var serviceConnection: ServiceConnection? = null
private var isBound: Boolean = false
private var isStreaming: Boolean = false

override fun onStartListening() {
super.onStartListening()
XLog.d(getLog("onStartListening", " isRunning:${ForegroundService.isRunning}, isBound:$isBound"))
XLog.d(getLog("onStartListening", "isRunning:${ForegroundService.isRunning}"))

if (ForegroundService.isRunning && isBound.not()) {
serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, binder: IBinder) {
XLog.d(this@TileActionService.getLog("onServiceConnected"))

try {
val foregroundServiceBinder = binder as ForegroundService.ForegroundServiceBinder
if (ForegroundService.isRunning) {
coroutineScope?.cancel()

coroutineScope?.cancel()
coroutineScope = CoroutineScope(Job() + Dispatchers.Main.immediate)
coroutineScope!!.launch {
foregroundServiceBinder.serviceMessageFlow
.onEach { serviceMessage ->
XLog.d(this@TileActionService.getLog("onServiceMessage", "$serviceMessage"))
when (serviceMessage) {
is ServiceMessage.ServiceState -> {
isStreaming = serviceMessage.isStreaming; updateTile()
}
is ServiceMessage.FinishActivity -> {
isStreaming = false; updateTile()
}
else -> Unit
}
}
.catch { cause ->
XLog.e(this@TileActionService.getLog("onServiceConnected.serviceMessageFlow: $cause"))
XLog.e(this@TileActionService.getLog("onServiceConnected.serviceMessageFlow"), cause)
}
.collect()
coroutineScope = CoroutineScope(Job() + Dispatchers.Main.immediate).apply {
launch {
ForegroundService.serviceMessageFlow.collect { serviceMessage ->
XLog.d(this@TileActionService.getLog("onServiceMessage", "$serviceMessage"))
when (serviceMessage) {
is ServiceMessage.ServiceState -> {
isStreaming = serviceMessage.isStreaming
updateTile()
}
is ServiceMessage.FinishActivity -> {
isStreaming = false
updateTile()
}
else -> Unit
}
} catch (cause: RemoteException) {
XLog.e(this@TileActionService.getLog("onServiceConnected", "Failed to bind"), cause)
return
}
isBound = true
IntentAction.GetServiceState.sendToAppService(this@TileActionService)
}

override fun onServiceDisconnected(name: ComponentName?) {
XLog.w(this@TileActionService.getLog("onServiceDisconnected"))
coroutineScope?.cancel()
coroutineScope = null
isBound = false
}
}

bindService(ForegroundService.getForegroundServiceIntent(this), serviceConnection!!, Context.BIND_AUTO_CREATE)
IntentAction.GetServiceState.sendToAppService(this@TileActionService)
} else {
isStreaming = false
updateTile()
Expand All @@ -105,15 +73,9 @@ class TileActionService : TileService() {

override fun onStopListening() {
super.onStopListening()
XLog.d(getLog("onStopListening", "Invoked"))
if (isBound) {
coroutineScope?.cancel()
coroutineScope = null
serviceConnection?.let { unbindService(it) }
serviceConnection = null
isBound = false
}
isStreaming = false
XLog.d(getLog("onStopListening"))
coroutineScope?.cancel()
coroutineScope = null
updateTile()
}

Expand Down

0 comments on commit f4ebf6c

Please sign in to comment.