Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -55,7 +55,7 @@ android {

defaultConfig {
minSdk = 31
targetSdk = 35 // 29 wifi switch not working
targetSdk = 37
applicationId = "com.anod.car.home.free"

versionCode = 3_41004
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/java/com/anod/car/home/incar/AcceptCallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.os.Build
import android.os.Bundle
import android.telephony.TelephonyManager
import android.view.KeyEvent
import android.view.WindowManager
import info.anodsplace.applog.AppLog
import java.io.IOException

Expand Down Expand Up @@ -68,15 +67,12 @@ class AcceptCallActivity : Activity() {

private fun updateWindowFlags() {
if (keyguardManager!!.isKeyguardLocked) {
window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
setShowWhenLocked(true)
setTurnScreenOn(true)
keyguardManager!!.requestDismissKeyguard(this, null)
} else {
window.clearFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
setShowWhenLocked(false)
setTurnScreenOn(false)
}
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/anod/car/home/incar/ModeDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.content.Context
import android.content.Intent
import androidx.core.content.IntentCompat
import com.anod.car.home.BuildConfig
import com.anod.car.home.getKoin
import com.anod.car.home.utils.Power
Expand Down Expand Up @@ -172,7 +173,7 @@ object ModeDetector {
if (BluetoothDevice.ACTION_ACL_CONNECTED == action) {
val devices = prefs.btDevices
if (devices.isNotEmpty()) {
val device: BluetoothDevice? = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
val device: BluetoothDevice? = IntentCompat.getParcelableExtra(intent, BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java)
if (device != null && devices.containsKey(device.address)) {
sEventState[FLAG_BLUETOOTH] = true
return
Expand All @@ -189,7 +190,7 @@ object ModeDetector {
if (BluetoothDevice.ACTION_ACL_DISCONNECTED == action) {
val devices = prefs.btDevices
if (devices.isNotEmpty()) {
val device: BluetoothDevice? = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
val device: BluetoothDevice? = IntentCompat.getParcelableExtra(intent, BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java)
if (device != null && devices.containsKey(device.address)) {
sEventState[FLAG_BLUETOOTH] = false
return
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/anod/car/home/incar/ModeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.IBinder
import android.os.PowerManager
import android.telephony.PhoneStateListener
import android.telephony.TelephonyManager
import androidx.core.app.ServiceCompat
import com.anod.car.home.appwidget.Provider
import com.anod.car.home.notifications.InCarModeNotificationFactory
import info.anodsplace.applog.AppLog
Expand All @@ -26,7 +27,7 @@ class ModeService : Service(), KoinComponent {
private var forceState: Boolean = false

override fun onDestroy() {
stopForeground(true)
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)

val prefs = get<InCarSettings>()
if (forceState) {
Expand Down
2 changes: 1 addition & 1 deletion baselineProfile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {

defaultConfig {
minSdk = 31
targetSdk = 36
targetSdk = 37

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ plugins {
alias(libs.plugins.baselineprofile) apply false
alias(libs.plugins.compose.compiler) apply false
}

subprojects {
// Robolectric 4.17 on JDK 17+ reflects into jdk.internal.access (FileDescriptor shadow at API 37+).
// The JPMS blocks this by default, so open the package to the forked unit-test JVM.
tasks.withType<Test>().configureEach {
jvmArgs("--add-opens=java.base/jdk.internal.access=ALL-UNNAMED")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package info.anodsplace.carwidget.appwidget

import android.app.Application
import android.content.Context
import android.os.Bundle
import androidx.compose.runtime.Immutable
import androidx.core.os.bundleOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import coil3.ImageLoader
Expand Down Expand Up @@ -58,19 +58,19 @@ class EditWidgetViewModel(
context = application,
title = application.getString(R.string.pref_settings_transparent),
iconRes = skinProperties.settingsButtonRes,
extras = bundleOf("button" to WidgetInterface.WIDGET_BUTTON_SETTINGS)
extras = Bundle().apply { putInt("button", WidgetInterface.WIDGET_BUTTON_SETTINGS) }
),
ChooserEntry(
context = application,
title = application.getString(R.string.pref_incar_transparent),
iconRes = skinProperties.inCarButtonEnterRes,
extras = bundleOf("button" to WidgetInterface.WIDGET_BUTTON_INCAR)
extras = Bundle().apply { putInt("button", WidgetInterface.WIDGET_BUTTON_INCAR) }
),
ChooserEntry(
context = application,
title = application.getString(R.string.hidden),
iconRes = skinProperties.buttonAlternativeHiddenResId,
extras = bundleOf("button" to WidgetInterface.WIDGET_BUTTON_HIDDEN)
extras = Bundle().apply { putInt("button", WidgetInterface.WIDGET_BUTTON_HIDDEN) }
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent.ShortcutIconResource
import android.graphics.Bitmap
import android.net.Uri
import androidx.compose.runtime.Immutable
import androidx.core.content.IntentCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -205,8 +206,10 @@ class ShortcutEditViewModel(
return null
}

// EXTRA_SHORTCUT_ICON_RESOURCE is deprecated by the platform but is still what icon
// packs return; read it with the typed IntentCompat API for correct behavior on API 33+.
@Suppress("DEPRECATION")
val iconResource = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE) as? ShortcutIconResource
val iconResource = IntentCompat.getParcelableExtra(intent, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ShortcutIconResource::class.java)
if (iconResource != null) {
val icon = ShortcutInfoFactory.resolveIconResource(viewState.shortcutId, iconResource, isCustom = true, context)
if (icon != null) {
Expand All @@ -215,7 +218,7 @@ class ShortcutEditViewModel(
}

if (intent.hasExtra("icon")) {
val bitmap: Bitmap? = intent.getParcelableExtra("icon")
val bitmap: Bitmap? = IntentCompat.getParcelableExtra(intent, "icon", Bitmap::class.java)
if (bitmap != null) {
val shortcutIcon = ShortcutIcon.forCustomIcon(viewState.shortcutId, bitmap)
return shortcutIcon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package info.anodsplace.carwidget.content.db

import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

/**
* Verifies [toImageRequest] wires the icon version into Coil's memory cache key so a changed
* icon busts the cache and the shortcut preview refreshes. Generic request extras are ignored
* when Coil computes the cache key, so the version must live in [ImageRequest.memoryCacheKeyExtras].
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [31])
class ShortcutImageRequestUnitTest {

private val context: Context get() = ApplicationProvider.getApplicationContext()

private fun shortcut(): Shortcut = Shortcut(
id = 42L,
position = 0,
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION,
title = "Title",
isCustomIcon = true,
intent = Intent(Intent.ACTION_MAIN)
)

@Test
fun toImageRequest_omitsVersionWhenIconVersionIsDefault() {
val request = shortcut().toImageRequest(context, adaptiveIconStyle = "")
assertFalse(request.memoryCacheKeyExtras.containsKey("version"))
}

@Test
fun toImageRequest_writesIconVersionIntoMemoryCacheKeyExtras() {
val request = shortcut().toImageRequest(context, adaptiveIconStyle = "", iconVersion = 123)
assertEquals("123", request.memoryCacheKeyExtras["version"])
}

@Test
fun toImageRequest_differentIconVersionsProduceDifferentCacheKeyExtras() {
val first = shortcut().toImageRequest(context, adaptiveIconStyle = "", iconVersion = 1)
val second = shortcut().toImageRequest(context, adaptiveIconStyle = "", iconVersion = 2)
assertEquals("1", first.memoryCacheKeyExtras["version"])
assertEquals("2", second.memoryCacheKeyExtras["version"])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.runtime.Immutable
import coil3.Extras
import coil3.request.ImageRequest
import info.anodsplace.carwidget.content.extentions.isDebugBuild
import info.anodsplace.carwidget.content.preferences.WidgetInterface
Expand Down Expand Up @@ -104,7 +103,9 @@ fun Shortcut.toImageRequest(
): ImageRequest = ImageRequest.Builder(context)
.data(iconUri(context.isDebugBuild, adaptiveIconStyle, skinName)).apply {
if (iconVersion != -1) {
extras[Extras.Key("version")] = iconVersion
// Route the version into the memory cache key so a changed icon busts
// Coil's cache. Generic request extras are ignored when computing the key.
memoryCacheKeyExtra("version", iconVersion.toString())
}
}
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.os.Parcelable
import androidx.core.content.IntentCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.toDrawable
import androidx.core.net.toUri
Expand Down Expand Up @@ -48,17 +49,17 @@ class ShortcutIntent(val data: Intent, val isApp: Boolean) {
val hasIntent: Boolean
get() = data.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)
val intent: Intent?
get() = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT)
get() = IntentCompat.getParcelableExtra(data, Intent.EXTRA_SHORTCUT_INTENT, Intent::class.java)
val name: String?
get() = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME)
val icon: Parcelable?
get() = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON)
get() = IntentCompat.getParcelableExtra(data, Intent.EXTRA_SHORTCUT_ICON, Parcelable::class.java)
val iconResource: Parcelable?
get() = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)
get() = IntentCompat.getParcelableExtra(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Parcelable::class.java)
val preferIconResource: Boolean
get() = data.getBooleanExtra(ShortcutExtra.EXTRA_PREFER_ICON_RESOURCE, false)
val pinItemRequest: LauncherApps.PinItemRequest?
get() = data.getParcelableExtra(LauncherApps.EXTRA_PIN_ITEM_REQUEST)
get() = IntentCompat.getParcelableExtra(data, LauncherApps.EXTRA_PIN_ITEM_REQUEST, LauncherApps.PinItemRequest::class.java)
}

object ShortcutInfoFactory {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ profileinstaller = "1.4.1"
window = "1.5.1"
palette = "1.0.0"
annotation = "1.10.0"
robolectric = "4.16.1"
robolectric = "4.17-beta-2"
androidx-test-core = "1.7.0"
nav3Core = "1.1.4"
lifecycleViewmodelNav3 = "2.11.0"
Expand Down