android: clean up build warnings (#443)

#cleanup

Removed a host of noisy deprecation and unchecked
cast warnings.

Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
pull/444/head
Jonathan Nobels 4 months ago committed by GitHub
parent 66fa3c41a6
commit 26b4635c11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -326,7 +326,7 @@ class App : UninitializedApp(), libtailscale.AppContext {
@Throws( @Throws(
IOException::class, GeneralSecurityException::class, MDMSettings.NoSuchKeyException::class) IOException::class, GeneralSecurityException::class, MDMSettings.NoSuchKeyException::class)
override fun getSyspolicyStringArrayJSONValue(key: String): String { override fun getSyspolicyStringArrayJSONValue(key: String): String {
val list = MDMSettings.allSettingsByKey[key]?.flow?.value as? List<String> val list = MDMSettings.allSettingsByKey[key]?.flow?.value as? List<*>
try { try {
return Json.encodeToString(list) return Json.encodeToString(list)
} catch (e: Exception) { } catch (e: Exception) {

@ -28,8 +28,8 @@ class ShareActivity : ComponentActivity() {
private val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>> = MutableStateFlow(emptyList()) private val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>> = MutableStateFlow(emptyList())
override fun onCreate(state: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(state) super.onCreate(savedInstanceState)
setContent { setContent {
AppTheme { AppTheme {
Surface(color = MaterialTheme.colorScheme.inverseSurface) { // Background for the letterbox Surface(color = MaterialTheme.colorScheme.inverseSurface) { // Background for the letterbox
@ -62,14 +62,14 @@ class ShareActivity : ComponentActivity() {
} }
val act = intent.action val act = intent.action
val uris: List<Uri?>?
uris = val uris: List<Uri?>? =
when (act) { when (act) {
Intent.ACTION_SEND -> { Intent.ACTION_SEND -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)) listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java))
} else { } else {
@Suppress("DEPRECATION")
listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri) listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri)
} }
} }
@ -77,7 +77,7 @@ class ShareActivity : ComponentActivity() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableArrayListExtra<Uri?>(Intent.EXTRA_STREAM, Uri::class.java) intent.getParcelableArrayListExtra<Uri?>(Intent.EXTRA_STREAM, Uri::class.java)
} else { } else {
intent.getParcelableArrayListExtra<Uri?>(Intent.EXTRA_STREAM) @Suppress("DEPRECATION") intent.getParcelableArrayListExtra<Uri?>(Intent.EXTRA_STREAM)
} }
} }
else -> { else -> {

@ -320,6 +320,8 @@ class Request<T>(
// TODO: use the streaming body for performance // TODO: use the streaming body for performance
// An empty body is a perfectly valid response and indicates success // An empty body is a perfectly valid response and indicates success
val respData = resp.bodyBytes() ?: ByteArray(0) val respData = resp.bodyBytes() ?: ByteArray(0)
@Suppress("UNCHECKED_CAST")
val response: Result<T> = val response: Result<T> =
when (responseType) { when (responseType) {
typeOf<String>() -> Result.success(respData.decodeToString() as T) typeOf<String>() -> Result.success(respData.decodeToString() as T)

@ -25,13 +25,14 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class DNSSettingsViewModelFactory() : ViewModelProvider.Factory { class DNSSettingsViewModelFactory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return DNSSettingsViewModel() as T return DNSSettingsViewModel() as T
} }
} }
class DNSSettingsViewModel() : IpnViewModel() { class DNSSettingsViewModel : IpnViewModel() {
val enablementState: StateFlow<DNSEnablementState> = val enablementState: StateFlow<DNSEnablementState> =
MutableStateFlow(DNSEnablementState.NOT_RUNNING) MutableStateFlow(DNSEnablementState.NOT_RUNNING)
val dnsConfig: StateFlow<Tailcfg.DNSConfig?> = MutableStateFlow(null) val dnsConfig: StateFlow<Tailcfg.DNSConfig?> = MutableStateFlow(null)

@ -30,6 +30,7 @@ data class ExitNodePickerNav(
class ExitNodePickerViewModelFactory(private val nav: ExitNodePickerNav) : class ExitNodePickerViewModelFactory(private val nav: ExitNodePickerNav) :
ViewModelProvider.Factory { ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ExitNodePickerViewModel(nav) as T return ExitNodePickerViewModel(nav) as T
} }

@ -23,6 +23,7 @@ class PeerDetailsViewModelFactory(
private val filesDir: File, private val filesDir: File,
private val pingViewModel: PingViewModel private val pingViewModel: PingViewModel
) : ViewModelProvider.Factory { ) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return PeerDetailsViewModel(nodeId, filesDir, pingViewModel) as T return PeerDetailsViewModel(nodeId, filesDir, pingViewModel) as T
} }

@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
class PingViewModelFactory(private val peer: Tailcfg.Node) : ViewModelProvider.Factory { class PingViewModelFactory(private val peer: Tailcfg.Node) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return PingViewModel() as T return PingViewModel() as T
} }

@ -36,13 +36,14 @@ class TaildropViewModelFactory(
private val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>>, private val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>>,
private val applicationScope: CoroutineScope private val applicationScope: CoroutineScope
) : ViewModelProvider.Factory { ) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return TaildropViewModel(requestedTransfers, applicationScope) as T return TaildropViewModel(requestedTransfers, applicationScope) as T
} }
} }
class TaildropViewModel( class TaildropViewModel(
val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>>, private val requestedTransfers: StateFlow<List<Ipn.OutgoingFile>>,
private val applicationScope: CoroutineScope private val applicationScope: CoroutineScope
) : IpnViewModel() { ) : IpnViewModel() {

@ -16,7 +16,8 @@ import com.tailscale.ipn.ui.util.set
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
class TailnetLockSetupViewModelFactory() : ViewModelProvider.Factory { class TailnetLockSetupViewModelFactory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return TailnetLockSetupViewModel() as T return TailnetLockSetupViewModel() as T
} }
@ -24,7 +25,7 @@ class TailnetLockSetupViewModelFactory() : ViewModelProvider.Factory {
data class StatusItem(@StringRes val title: Int, @DrawableRes val icon: Int) data class StatusItem(@StringRes val title: Int, @DrawableRes val icon: Int)
class TailnetLockSetupViewModel() : IpnViewModel() { class TailnetLockSetupViewModel : IpnViewModel() {
val statusItems: StateFlow<List<StatusItem>> = MutableStateFlow(emptyList()) val statusItems: StateFlow<List<StatusItem>> = MutableStateFlow(emptyList())
val nodeKey: StateFlow<String> = MutableStateFlow("unknown") val nodeKey: StateFlow<String> = MutableStateFlow("unknown")

Loading…
Cancel
Save