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

Updates for Android 12 #1807

Merged
merged 3 commits into from
Oct 21, 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
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
defaultConfig {
applicationId = "io.homeassistant.companion.android"
minSdk = 21
targetSdk = 30
targetSdk = 31

versionName = System.getenv("VERSION") ?: "LOCAL"
versionCode = System.getenv("VERSION_CODE")?.toIntOrNull() ?: 1
Expand Down Expand Up @@ -165,7 +165,7 @@ dependencies {
"fullImplementation"("io.sentry:sentry-android:5.2.3")
"fullImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2")

implementation("androidx.work:work-runtime-ktx:2.6.0")
implementation("androidx.work:work-runtime-ktx:2.7.0")
implementation("androidx.biometric:biometric:1.1.0")
implementation("androidx.webkit:webkit:1.4.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class HighAccuracyLocationService : Service() {
action = HighAccuracyLocationReceiver.HIGH_ACCURACY_LOCATION_DISABLE
}

val disablePendingIntent = PendingIntent.getBroadcast(context, 0, disableIntent, 0)
val disablePendingIntent = PendingIntent.getBroadcast(context, 0, disableIntent, PendingIntent.FLAG_MUTABLE)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved

notificationBuilder = NotificationCompat.Builder(context, channelID)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
Expand Down Expand Up @@ -184,7 +184,7 @@ class HighAccuracyLocationService : Service() {
private fun getLocationUpdateIntent(): PendingIntent {
val intent = Intent(this, LocationSensorManager::class.java)
intent.action = LocationSensorManager.ACTION_PROCESS_LOCATION
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved
}

@SuppressLint("MissingPermission")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class MessagingService : FirebaseMessagingService() {
this,
messageId,
contentIntent,
PendingIntent.FLAG_CANCEL_CURRENT
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
JBassett marked this conversation as resolved.
Show resolved Hide resolved
)
builder.setContentIntent(contentPendingIntent)
}
Expand All @@ -728,7 +728,7 @@ class MessagingService : FirebaseMessagingService() {
this,
messageId,
deleteIntent,
PendingIntent.FLAG_CANCEL_CURRENT
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
JBassett marked this conversation as resolved.
Show resolved Hide resolved
)
builder.setDeleteIntent(deletePendingIntent)
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ class MessagingService : FirebaseMessagingService() {
this,
(notificationAction.title.hashCode() + System.currentTimeMillis()).toInt(),
actionIntent,
0
PendingIntent.FLAG_IMMUTABLE
)

val icon =
Expand All @@ -1046,7 +1046,7 @@ class MessagingService : FirebaseMessagingService() {
this,
0,
actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
JBassett marked this conversation as resolved.
Show resolved Hide resolved
)
val action: NotificationCompat.Action = NotificationCompat.Action.Builder(R.drawable.ic_baseline_reply_24, notificationAction.title, replyPendingIntent)
.addRemoteInput(remoteInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class NotificationActionReceiver : BroadcastReceiver() {
FIRE_EVENT -> fireEvent(notificationAction, onComplete, onFailure)
OPEN_URI -> NotificationActionContentHandler.openUri(context, notificationAction.uri, onComplete)
}

// Make sure the notification shade closes
context.sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
}

private fun fireEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class ActivitySensorManager : BroadcastReceiver(), SensorManager {
private fun getActivityPendingIntent(context: Context): PendingIntent {
val intent = Intent(context, ActivitySensorManager::class.java)
intent.action = ACTION_UPDATE_ACTIVITY
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved
}

private fun getSleepPendingIntent(context: Context): PendingIntent {
val intent = Intent(context, ActivitySensorManager::class.java)
intent.action = ACTION_SLEEP_ACTIVITY
return PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved
}

private fun handleActivityUpdate(intent: Intent, context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager {
return
}

if (geofencingEvent.triggeringLocation == null) {
Log.d(TAG, "Geofence event is null")
return
}

val validGeofencingEvents = listOf(Geofence.GEOFENCE_TRANSITION_ENTER, Geofence.GEOFENCE_TRANSITION_EXIT)
if (geofencingEvent.geofenceTransition in validGeofencingEvents) {
val zoneStatusEvent = when (geofencingEvent.geofenceTransition) {
Expand Down Expand Up @@ -637,7 +642,7 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager {
private fun getLocationUpdateIntent(isGeofence: Boolean): PendingIntent {
val intent = Intent(latestContext, LocationSensorManager::class.java)
intent.action = if (isGeofence) ACTION_PROCESS_GEO else ACTION_PROCESS_LOCATION
return PendingIntent.getBroadcast(latestContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(latestContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved
}

private fun createLocationRequest(): LocationRequest {
Expand Down Expand Up @@ -842,17 +847,31 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager {
get() = R.string.sensor_name_location

override fun requiredPermissions(sensorId: String): Array<String> {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.BLUETOOTH
)
} else {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.BLUETOOTH
)
return when {
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) -> {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_CONNECT
)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved
}
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) -> {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH
)
}
else -> {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH
)
}
}
}

Expand Down