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

Bump AGP, Gradle and Kotlin Versions #1563

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("kotlin-kapt")
id("kotlin-android-extensions")
id("com.google.firebase.appdistribution")
id("com.github.triplet.play") version "3.0.0"
id("com.github.triplet.play") version "3.4.0-agp4.2"
id("com.google.gms.google-services")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import io.homeassistant.companion.android.BuildConfig
import io.homeassistant.companion.android.common.data.authentication.AuthenticationRepository
import io.homeassistant.companion.android.common.data.integration.DeviceRegistration
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
import javax.inject.Inject
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import javax.inject.Inject

class LaunchPresenterImpl @Inject constructor(
view: LaunchView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class HighAccuracyLocationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
HIGH_ACCURACY_LOCATION_DISABLE ->
{
HighAccuracyLocationService.stopService(context)
LocationSensorManager.setHighAccuracyModeSetting(context, false)
}
{
HighAccuracyLocationService.stopService(context)
LocationSensorManager.setHighAccuracyModeSetting(context, false)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ class HighAccuracyLocationService : Service() {
longSeconds %= 60
val latDegree = if (latDegrees >= 0) "N" else "S"
val lonDegrees = if (longDegrees >= 0) "E" else "W"
(abs(latDegrees).toString() + "°" + latMinutes + "'" + latSeconds +
(
abs(latDegrees).toString() + "°" + latMinutes + "'" + latSeconds +
"\"" + latDegree + " " + abs(longDegrees) + "°" + longMinutes +
"'" + longSeconds + "\"" + lonDegrees)
"'" + longSeconds + "\"" + lonDegrees
)
} catch (e: java.lang.Exception) {
("" + String.format("%8.5f", latitude) + " " +
String.format("%8.5f", longitude))
(
"" + String.format("%8.5f", latitude) + " " +
String.format("%8.5f", longitude)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ import io.homeassistant.companion.android.util.cancel
import io.homeassistant.companion.android.util.cancelGroupIfNeeded
import io.homeassistant.companion.android.util.getActiveNotification
import io.homeassistant.companion.android.webview.WebViewActivity
import java.net.URL
import java.util.Locale
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.URL
import java.util.Locale
import javax.inject.Inject

class MessagingService : FirebaseMessagingService() {
companion object {
Expand Down Expand Up @@ -135,15 +135,19 @@ class MessagingService : FirebaseMessagingService() {
const val MEDIA_STOP = "stop"

// Command groups
val DEVICE_COMMANDS = listOf(COMMAND_DND, COMMAND_RINGER_MODE, COMMAND_BROADCAST_INTENT,
val DEVICE_COMMANDS = listOf(
COMMAND_DND, COMMAND_RINGER_MODE, COMMAND_BROADCAST_INTENT,
COMMAND_VOLUME_LEVEL, COMMAND_BLUETOOTH, COMMAND_BLE_TRANSMITTER, COMMAND_HIGH_ACCURACY_MODE, COMMAND_ACTIVITY,
COMMAND_WEBVIEW, COMMAND_SCREEN_ON, COMMAND_MEDIA)
COMMAND_WEBVIEW, COMMAND_SCREEN_ON, COMMAND_MEDIA
)
val DND_COMMANDS = listOf(DND_ALARMS_ONLY, DND_ALL, DND_NONE, DND_PRIORITY_ONLY)
val RM_COMMANDS = listOf(RM_NORMAL, RM_SILENT, RM_VIBRATE)
val CHANNEL_VOLUME_STREAM = listOf(ALARM_STREAM, MUSIC_STREAM, NOTIFICATION_STREAM, RING_STREAM)
val ENABLE_COMMANDS = listOf(TURN_OFF, TURN_ON)
val MEDIA_COMMANDS = listOf(MEDIA_FAST_FORWARD, MEDIA_NEXT, MEDIA_PAUSE, MEDIA_PLAY,
MEDIA_PLAY_PAUSE, MEDIA_PREVIOUS, MEDIA_REWIND, MEDIA_STOP)
val MEDIA_COMMANDS = listOf(
MEDIA_FAST_FORWARD, MEDIA_NEXT, MEDIA_PAUSE, MEDIA_PLAY,
MEDIA_PLAY_PAUSE, MEDIA_PREVIOUS, MEDIA_REWIND, MEDIA_STOP
)
}

@Inject
Expand Down Expand Up @@ -235,7 +239,8 @@ class MessagingService : FirebaseMessagingService() {
}
COMMAND_VOLUME_LEVEL -> {
if (!it["channel"].isNullOrEmpty() && it["channel"] in CHANNEL_VOLUME_STREAM &&
!it[TITLE].isNullOrEmpty() && it[TITLE]?.toIntOrNull() != null)
!it[TITLE].isNullOrEmpty() && it[TITLE]?.toIntOrNull() != null
)
handleDeviceCommands(it)
else {
mainScope.launch {
Expand Down Expand Up @@ -354,7 +359,8 @@ class MessagingService : FirebaseMessagingService() {
val maxAlarmVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)
if (tts.isNullOrEmpty())
tts = getString(R.string.tts_no_title)
textToSpeech = TextToSpeech(applicationContext
textToSpeech = TextToSpeech(
applicationContext
) {
if (it == TextToSpeech.SUCCESS) {
val listener = object : UtteranceProgressListener() {
Expand Down Expand Up @@ -454,7 +460,8 @@ class MessagingService : FirebaseMessagingService() {
if (pair[1].isDigitsOnly())
pair[1].toInt()
else if ((pair[1].toLowerCase() == "true") ||
(pair[1].toLowerCase() == "false"))
(pair[1].toLowerCase() == "false")
)
pair[1].toBoolean()
else pair[1]
)
Expand Down Expand Up @@ -542,8 +549,9 @@ class MessagingService : FirebaseMessagingService() {
val powerManager = applicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager
val wakeLock = powerManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK or
PowerManager.ACQUIRE_CAUSES_WAKEUP or
PowerManager.ON_AFTER_RELEASE, "HomeAssistant::NotificationScreenOnWakeLock"
PowerManager.ACQUIRE_CAUSES_WAKEUP or
PowerManager.ON_AFTER_RELEASE,
"HomeAssistant::NotificationScreenOnWakeLock"
)
wakeLock.acquire(1 * 30 * 1000L /*30 seconds */)
wakeLock.release()
Expand Down Expand Up @@ -753,7 +761,8 @@ class MessagingService : FirebaseMessagingService() {
builder.setSound(
RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_ALARM)
?: RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE),
AudioManager.STREAM_ALARM)
AudioManager.STREAM_ALARM
)
} else {
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
}
Expand Down Expand Up @@ -1088,9 +1097,11 @@ class MessagingService : FirebaseMessagingService() {
.setLegacyStreamType(AudioManager.STREAM_ALARM)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
channel.setSound(RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_ALARM)
?: RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE),
audioAttributes)
channel.setSound(
RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_ALARM)
?: RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE),
audioAttributes
)
}

private fun parseVibrationPattern(
Expand Down Expand Up @@ -1133,7 +1144,8 @@ class MessagingService : FirebaseMessagingService() {
private fun requestSystemAlertPermission() {
val intent = Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:$packageName"))
Uri.parse("package:$packageName")
)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
}
Expand Down Expand Up @@ -1255,7 +1267,8 @@ class MessagingService : FirebaseMessagingService() {
if (pair[1].isDigitsOnly())
pair[1].toInt()
else if ((pair[1].toLowerCase() == "true") ||
(pair[1].toLowerCase() == "false"))
(pair[1].toLowerCase() == "false")
)
pair[1].toBoolean()
else pair[1]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
import io.homeassistant.companion.android.util.NotificationActionContentHandler
import io.homeassistant.companion.android.util.cancel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject

class NotificationActionReceiver : BroadcastReceiver() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import io.homeassistant.companion.android.R
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
import io.homeassistant.companion.android.util.cancelGroupIfNeeded
import javax.inject.Inject
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

class NotificationDeleteReceiver : BroadcastReceiver() {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.util.Log
import com.google.firebase.iid.FirebaseInstanceId
import io.homeassistant.companion.android.common.data.integration.DeviceRegistration
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
import javax.inject.Inject
import kotlinx.coroutines.tasks.await
import javax.inject.Inject

class MobileAppIntegrationPresenterImpl @Inject constructor(
view: MobileAppIntegrationView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import io.homeassistant.companion.android.database.sensor.Attribute
import io.homeassistant.companion.android.database.sensor.Setting
import io.homeassistant.companion.android.location.HighAccuracyLocationService
import io.homeassistant.companion.android.util.DisabledLocationHandler
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

class LocationSensorManager : BroadcastReceiver(), SensorManager {

Expand Down Expand Up @@ -540,10 +540,11 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager {

private fun sendLocationUpdate(location: Location, name: String = "", geofenceUpdate: Boolean = false) {
Log.d(
TAG, "Last Location: " +
"\nCoords:(${location.latitude}, ${location.longitude})" +
"\nAccuracy: ${location.accuracy}" +
"\nBearing: ${location.bearing}"
TAG,
"Last Location: " +
"\nCoords:(${location.latitude}, ${location.longitude})" +
"\nAccuracy: ${location.accuracy}" +
"\nBearing: ${location.bearing}"
)
var accuracy = 0
if (location.accuracy.toInt() >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ open class BaseActivity : AppCompatActivity() {
override fun attachBaseContext(newBase: Context) {

DaggerSettingsComponent.builder()
.appComponent((newBase.applicationContext as GraphComponentAccessor).appComponent)
.build()
.inject(this)
.appComponent((newBase.applicationContext as GraphComponentAccessor).appComponent)
.build()
.inject(this)

super.attachBaseContext(lm.getContextWrapper(newBase))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ open class HomeAssistantApplication : Application(), GraphComponentAccessor {
// This should be nearly instantaneous allowing automations to fire immediately when a phone is plugged
// in or unplugged. Updates will also be triggered when the system reports low battery and when it recovers.
registerReceiver(
sensorReceiver, IntentFilter().apply {
sensorReceiver,
IntentFilter().apply {
addAction(Intent.ACTION_BATTERY_LOW)
addAction(Intent.ACTION_BATTERY_OKAY)
addAction(Intent.ACTION_POWER_CONNECTED)
Expand All @@ -54,7 +55,8 @@ open class HomeAssistantApplication : Application(), GraphComponentAccessor {

// This will cause interactive and power save to update upon a state change
registerReceiver(
sensorReceiver, IntentFilter().apply {
sensorReceiver,
IntentFilter().apply {
addAction(Intent.ACTION_SCREEN_OFF)
addAction(Intent.ACTION_SCREEN_ON)
addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)
Expand All @@ -64,7 +66,8 @@ open class HomeAssistantApplication : Application(), GraphComponentAccessor {
// Update doze mode immediately on supported devices
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
registerReceiver(
sensorReceiver, IntentFilter().apply {
sensorReceiver,
IntentFilter().apply {
addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED)
}
)
Expand All @@ -85,7 +88,8 @@ open class HomeAssistantApplication : Application(), GraphComponentAccessor {
)

// Listen for bluetooth state changes
registerReceiver(sensorReceiver,
registerReceiver(
sensorReceiver,
IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Authenticator(context: Context, fragmentActivity: FragmentActivity, callba
}

private val executor = ContextCompat.getMainExecutor(context)
private val biometricPrompt = BiometricPrompt(fragmentActivity, executor,
private val biometricPrompt = BiometricPrompt(
fragmentActivity, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
Expand All @@ -34,7 +35,8 @@ class Authenticator(context: Context, fragmentActivity: FragmentActivity, callba
super.onAuthenticationSucceeded(result)
callback(SUCCESS)
}
})
}
)

fun authenticate(title: String) {
val promptDialog = BiometricPrompt.PromptInfo.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.bluetooth.BluetoothAdapter
import android.bluetooth.le.AdvertiseCallback
import android.bluetooth.le.AdvertiseSettings
import android.content.Context
import java.util.UUID
import org.altbeacon.beacon.Beacon
import org.altbeacon.beacon.BeaconParser
import org.altbeacon.beacon.BeaconTransmitter
import java.util.UUID

object TransmitterManager {
private lateinit var physicalTransmitter: BeaconTransmitter
Expand Down Expand Up @@ -60,25 +60,28 @@ object TransmitterManager {
val beacon = buildBeacon(haTransmitter)
if (!physicalTransmitter.isStarted) {
physicalTransmitter.advertiseTxPowerLevel = getPowerLevel(haTransmitter)
physicalTransmitter.startAdvertising(beacon, object : AdvertiseCallback() {
override fun onStartSuccess(settingsInEffect: AdvertiseSettings) {
haTransmitter.transmitting = true
haTransmitter.state = "Transmitting"
}

override fun onStartFailure(errorCode: Int) {
if (errorCode != ADVERTISE_FAILED_ALREADY_STARTED) {
haTransmitter.uuid = ""
haTransmitter.major = ""
haTransmitter.minor = ""
haTransmitter.state = "Unable to transmit"
haTransmitter.transmitting = false
} else {
physicalTransmitter.startAdvertising(
beacon,
object : AdvertiseCallback() {
override fun onStartSuccess(settingsInEffect: AdvertiseSettings) {
haTransmitter.transmitting = true
haTransmitter.state = "Transmitting"
}

override fun onStartFailure(errorCode: Int) {
if (errorCode != ADVERTISE_FAILED_ALREADY_STARTED) {
haTransmitter.uuid = ""
haTransmitter.major = ""
haTransmitter.minor = ""
haTransmitter.state = "Unable to transmit"
haTransmitter.transmitting = false
} else {
haTransmitter.transmitting = true
haTransmitter.state = "Transmitting"
}
}
}
})
)
}
} else {
stopTransmitting(haTransmitter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class ClimateControl {
val minValue = (entity.attributes["min_temp"] as? Number)?.toFloat() ?: 0f
val maxValue = (entity.attributes["max_temp"] as? Number)?.toFloat() ?: 100f
var currentValue = (entity.attributes["temperature"] as? Number)?.toFloat() ?: (
entity.attributes["current_temperature"] as? Number)?.toFloat() ?: 0f
entity.attributes["current_temperature"] as? Number
)?.toFloat() ?: 0f
// Ensure the current value is never lower than the minimum or higher than the maximum
if (currentValue < minValue)
currentValue = minValue
Expand Down