From 26b4635c11c6d5bae44cef1c483c902f23125953 Mon Sep 17 00:00:00 2001 From: Jonathan Nobels Date: Wed, 10 Jul 2024 16:39:54 -0400 Subject: [PATCH] android: clean up build warnings (#443) #cleanup Removed a host of noisy deprecation and unchecked cast warnings. Signed-off-by: Jonathan Nobels --- android/src/main/java/com/tailscale/ipn/App.kt | 2 +- .../src/main/java/com/tailscale/ipn/ShareActivity.kt | 10 +++++----- .../main/java/com/tailscale/ipn/ui/localapi/Client.kt | 2 ++ .../tailscale/ipn/ui/viewModel/DNSSettingsViewModel.kt | 5 +++-- .../ipn/ui/viewModel/ExitNodePickerViewModel.kt | 1 + .../tailscale/ipn/ui/viewModel/PeerDetailsViewModel.kt | 1 + .../com/tailscale/ipn/ui/viewModel/PingViewModel.kt | 1 + .../tailscale/ipn/ui/viewModel/TaildropViewModel.kt | 3 ++- .../ipn/ui/viewModel/TailnetLockSetupViewModel.kt | 5 +++-- 9 files changed, 19 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/tailscale/ipn/App.kt b/android/src/main/java/com/tailscale/ipn/App.kt index 7e81426..a44249a 100644 --- a/android/src/main/java/com/tailscale/ipn/App.kt +++ b/android/src/main/java/com/tailscale/ipn/App.kt @@ -326,7 +326,7 @@ class App : UninitializedApp(), libtailscale.AppContext { @Throws( IOException::class, GeneralSecurityException::class, MDMSettings.NoSuchKeyException::class) override fun getSyspolicyStringArrayJSONValue(key: String): String { - val list = MDMSettings.allSettingsByKey[key]?.flow?.value as? List + val list = MDMSettings.allSettingsByKey[key]?.flow?.value as? List<*> try { return Json.encodeToString(list) } catch (e: Exception) { diff --git a/android/src/main/java/com/tailscale/ipn/ShareActivity.kt b/android/src/main/java/com/tailscale/ipn/ShareActivity.kt index 1dd0eca..64e6302 100644 --- a/android/src/main/java/com/tailscale/ipn/ShareActivity.kt +++ b/android/src/main/java/com/tailscale/ipn/ShareActivity.kt @@ -28,8 +28,8 @@ class ShareActivity : ComponentActivity() { private val requestedTransfers: StateFlow> = MutableStateFlow(emptyList()) - override fun onCreate(state: Bundle?) { - super.onCreate(state) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) setContent { AppTheme { Surface(color = MaterialTheme.colorScheme.inverseSurface) { // Background for the letterbox @@ -62,14 +62,14 @@ class ShareActivity : ComponentActivity() { } val act = intent.action - val uris: List? - uris = + val uris: List? = when (act) { Intent.ACTION_SEND -> { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)) } else { + @Suppress("DEPRECATION") listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri) } } @@ -77,7 +77,7 @@ class ShareActivity : ComponentActivity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java) } else { - intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM) + @Suppress("DEPRECATION") intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM) } } else -> { diff --git a/android/src/main/java/com/tailscale/ipn/ui/localapi/Client.kt b/android/src/main/java/com/tailscale/ipn/ui/localapi/Client.kt index aa3a0ac..810a642 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/localapi/Client.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/localapi/Client.kt @@ -320,6 +320,8 @@ class Request( // TODO: use the streaming body for performance // An empty body is a perfectly valid response and indicates success val respData = resp.bodyBytes() ?: ByteArray(0) + + @Suppress("UNCHECKED_CAST") val response: Result = when (responseType) { typeOf() -> Result.success(respData.decodeToString() as T) diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/DNSSettingsViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/DNSSettingsViewModel.kt index 5de4302..80a95cb 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/DNSSettingsViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/DNSSettingsViewModel.kt @@ -25,13 +25,14 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -class DNSSettingsViewModelFactory() : ViewModelProvider.Factory { +class DNSSettingsViewModelFactory : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return DNSSettingsViewModel() as T } } -class DNSSettingsViewModel() : IpnViewModel() { +class DNSSettingsViewModel : IpnViewModel() { val enablementState: StateFlow = MutableStateFlow(DNSEnablementState.NOT_RUNNING) val dnsConfig: StateFlow = MutableStateFlow(null) diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/ExitNodePickerViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/ExitNodePickerViewModel.kt index fe2a138..0e952b6 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/ExitNodePickerViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/ExitNodePickerViewModel.kt @@ -30,6 +30,7 @@ data class ExitNodePickerNav( class ExitNodePickerViewModelFactory(private val nav: ExitNodePickerNav) : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return ExitNodePickerViewModel(nav) as T } diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/PeerDetailsViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/PeerDetailsViewModel.kt index 7bd6614..e46eb1c 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/PeerDetailsViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/PeerDetailsViewModel.kt @@ -23,6 +23,7 @@ class PeerDetailsViewModelFactory( private val filesDir: File, private val pingViewModel: PingViewModel ) : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return PeerDetailsViewModel(nodeId, filesDir, pingViewModel) as T } diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/PingViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/PingViewModel.kt index 319dc3a..d0ad1f2 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/PingViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/PingViewModel.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow class PingViewModelFactory(private val peer: Tailcfg.Node) : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return PingViewModel() as T } diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/TaildropViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/TaildropViewModel.kt index da745b3..3d55057 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/TaildropViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/TaildropViewModel.kt @@ -36,13 +36,14 @@ class TaildropViewModelFactory( private val requestedTransfers: StateFlow>, private val applicationScope: CoroutineScope ) : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return TaildropViewModel(requestedTransfers, applicationScope) as T } } class TaildropViewModel( - val requestedTransfers: StateFlow>, + private val requestedTransfers: StateFlow>, private val applicationScope: CoroutineScope ) : IpnViewModel() { diff --git a/android/src/main/java/com/tailscale/ipn/ui/viewModel/TailnetLockSetupViewModel.kt b/android/src/main/java/com/tailscale/ipn/ui/viewModel/TailnetLockSetupViewModel.kt index f439efc..f102ac9 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/viewModel/TailnetLockSetupViewModel.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/viewModel/TailnetLockSetupViewModel.kt @@ -16,7 +16,8 @@ import com.tailscale.ipn.ui.util.set import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -class TailnetLockSetupViewModelFactory() : ViewModelProvider.Factory { +class TailnetLockSetupViewModelFactory : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { return TailnetLockSetupViewModel() as T } @@ -24,7 +25,7 @@ class TailnetLockSetupViewModelFactory() : ViewModelProvider.Factory { data class StatusItem(@StringRes val title: Int, @DrawableRes val icon: Int) -class TailnetLockSetupViewModel() : IpnViewModel() { +class TailnetLockSetupViewModel : IpnViewModel() { val statusItems: StateFlow> = MutableStateFlow(emptyList()) val nodeKey: StateFlow = MutableStateFlow("unknown")