Commit da81482b authored by Ricki Hirner's avatar Ricki Hirner

lint

parent f453d069
......@@ -24,6 +24,7 @@ import at.bitfire.davdroid.ui.DebugInfoActivity
import at.bitfire.davdroid.ui.NotificationUtils
import java.util.logging.Level
import kotlin.concurrent.thread
import kotlin.system.exitProcess
@Suppress("unused")
class App: MultiDexApplication(), Thread.UncaughtExceptionHandler {
......@@ -92,7 +93,7 @@ class App: MultiDexApplication(), Thread.UncaughtExceptionHandler {
intent.putExtra(DebugInfoActivity.KEY_THROWABLE, e)
startActivity(intent)
System.exit(1)
exitProcess(1)
}
}
......@@ -3,6 +3,7 @@ package at.bitfire.davdroid
import android.content.ContentProviderClient
import android.os.Build
@Suppress("DEPRECATION")
fun ContentProviderClient.closeCompat() {
if (Build.VERSION.SDK_INT >= 24)
close()
......
......@@ -150,9 +150,9 @@ class DavService: android.app.Service() {
/**
* Checks if the given URL defines home sets and adds them to the home set list.
*
* @throws IOException
* @throws java.io.IOException
* @throws HttpException
* @throws DavException
* @throws at.bitfire.dav4jvm.exception.DavException
*/
fun queryHomeSets(client: OkHttpClient, url: HttpUrl, recurse: Boolean = true) {
val related = mutableSetOf<HttpUrl>()
......
......@@ -51,14 +51,18 @@ object DavUtils {
get the active DNS servers). */
val connectivity = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeLink = connectivity.getLinkProperties(connectivity.activeNetwork)
val simpleResolvers = activeLink.dnsServers.map {
Logger.log.fine("Using DNS server ${it.hostAddress}")
val resolver = SimpleResolver()
resolver.setAddress(it)
resolver
}
val resolver = ExtendedResolver(simpleResolvers.toTypedArray())
lookup.setResolver(resolver)
if (activeLink != null) {
// get DNS servers of active network link and set them for dnsjava so that it can send SRV queries
val simpleResolvers = activeLink.dnsServers.map {
Logger.log.fine("Using DNS server ${it.hostAddress}")
val resolver = SimpleResolver()
resolver.setAddress(it)
resolver
}
val resolver = ExtendedResolver(simpleResolvers.toTypedArray())
lookup.setResolver(resolver)
} else
Logger.log.severe("Couldn't determine DNS servers, dnsjava queries (SRV/TXT records) won't work")
}
}
......
......@@ -13,12 +13,12 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.util.Log
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.FileProvider
import androidx.preference.PreferenceManager
import at.bitfire.davdroid.R
import at.bitfire.davdroid.ui.AppSettingsActivity
import at.bitfire.davdroid.ui.NotificationUtils
......@@ -32,7 +32,7 @@ object Logger : SharedPreferences.OnSharedPreferenceChangeListener {
private const val LOG_TO_FILE = "log_to_file"
val log = java.util.logging.Logger.getLogger("davx5")!!
val log = java.util.logging.Logger.getLogger("davx5")
private lateinit var context: Context
private lateinit var preferences: SharedPreferences
......
......@@ -69,9 +69,9 @@ data class Collection(
val url = UrlUtils.withTrailingSlash(dav.href)
val type: String = dav[ResourceType::class.java]?.let { resourceType ->
when {
resourceType.types.contains(ResourceType.ADDRESSBOOK) -> Collection.TYPE_ADDRESSBOOK
resourceType.types.contains(ResourceType.CALENDAR) -> Collection.TYPE_CALENDAR
resourceType.types.contains(ResourceType.SUBSCRIBED) -> Collection.TYPE_WEBCAL
resourceType.types.contains(ResourceType.ADDRESSBOOK) -> TYPE_ADDRESSBOOK
resourceType.types.contains(ResourceType.CALENDAR) -> TYPE_CALENDAR
resourceType.types.contains(ResourceType.SUBSCRIBED) -> TYPE_WEBCAL
else -> null
}
} ?: return null
......@@ -97,15 +97,15 @@ data class Collection(
var supportsVJOURNAL: Boolean? = null
var source: HttpUrl? = null
when (type) {
Collection.TYPE_ADDRESSBOOK -> {
TYPE_ADDRESSBOOK -> {
dav[AddressbookDescription::class.java]?.let { description = it.description }
}
Collection.TYPE_CALENDAR, Collection.TYPE_WEBCAL -> {
TYPE_CALENDAR, TYPE_WEBCAL -> {
dav[CalendarDescription::class.java]?.let { description = it.description }
dav[CalendarColor::class.java]?.let { color = it.color }
dav[CalendarTimezone::class.java]?.let { timezone = it.vTimeZone }
if (type == Collection.TYPE_CALENDAR) {
if (type == TYPE_CALENDAR) {
supportsVEVENT = true
supportsVTODO = true
supportsVJOURNAL = true
......
......@@ -2,7 +2,10 @@ package at.bitfire.davdroid.model
import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.room.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
@Dao
interface CollectionDao: SyncableDao<Collection> {
......
package at.bitfire.davdroid.model
import androidx.room.PrimaryKey
abstract class IdEntity {
abstract var id: Long
}
\ No newline at end of file
package at.bitfire.davdroid.model
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
......
......@@ -339,7 +339,7 @@ class LocalAddressBook(
val values = ContentValues(1)
values.put(Groups.TITLE, title)
val uri = provider.insert(syncAdapterURI(Groups.CONTENT_URI), values)
val uri = provider.insert(syncAdapterURI(Groups.CONTENT_URI), values) ?: throw RemoteException("Couldn't create contact group")
return ContentUris.parseId(uri)
}
......
......@@ -14,7 +14,6 @@ import android.content.ContentProviderOperation
import android.content.ContentUris
import android.content.ContentValues
import android.net.Uri
import android.provider.CalendarContract
import android.provider.CalendarContract.*
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.DavUtils
......@@ -79,7 +78,7 @@ class LocalCalendar private constructor(
}
values.put(Calendars.ALLOWED_REMINDERS, "${Reminders.METHOD_ALERT},${Reminders.METHOD_EMAIL}")
values.put(Calendars.ALLOWED_AVAILABILITY, "${Reminders.AVAILABILITY_TENTATIVE},${Reminders.AVAILABILITY_FREE},${Reminders.AVAILABILITY_BUSY}")
values.put(Calendars.ALLOWED_ATTENDEE_TYPES, "${CalendarContract.Attendees.TYPE_OPTIONAL},${CalendarContract.Attendees.TYPE_REQUIRED},${CalendarContract.Attendees.TYPE_RESOURCE}")
values.put(Calendars.ALLOWED_ATTENDEE_TYPES, "${Attendees.TYPE_OPTIONAL},${Attendees.TYPE_REQUIRED},${Attendees.TYPE_RESOURCE}")
return values
}
}
......
......@@ -93,7 +93,7 @@ class LocalContact: AndroidContact, LocalAddress {
override fun updateFlags(flags: Int) {
val values = ContentValues(1)
values.put(LocalContact.COLUMN_FLAGS, flags)
values.put(COLUMN_FLAGS, flags)
addressBook.provider!!.update(rawContactSyncURI(), values, null, null)
this.flags = flags
......
......@@ -10,7 +10,6 @@ package at.bitfire.davdroid.resource
import android.content.ContentProviderOperation
import android.content.ContentValues
import android.provider.CalendarContract
import android.provider.CalendarContract.Events
import at.bitfire.davdroid.BuildConfig
import at.bitfire.ical4android.*
......@@ -24,9 +23,9 @@ class LocalEvent: AndroidEvent, LocalResource<Event> {
ICalendar.prodId = ProdId("+//IDN bitfire.at//${BuildConfig.userAgent}/${BuildConfig.VERSION_NAME} ical4j/" + Constants.ical4jVersion)
}
const val COLUMN_ETAG = CalendarContract.Events.SYNC_DATA1
const val COLUMN_FLAGS = CalendarContract.Events.SYNC_DATA2
const val COLUMN_SEQUENCE = CalendarContract.Events.SYNC_DATA3
const val COLUMN_ETAG = Events.SYNC_DATA1
const val COLUMN_FLAGS = Events.SYNC_DATA2
const val COLUMN_SEQUENCE = Events.SYNC_DATA3
}
override var fileName: String? = null
......@@ -72,9 +71,9 @@ class LocalEvent: AndroidEvent, LocalResource<Event> {
builder .withValue(Events.UID_2445, event.uid)
.withValue(COLUMN_SEQUENCE, eventToBuild.sequence)
.withValue(CalendarContract.Events.DIRTY, 0)
.withValue(CalendarContract.Events.DELETED, 0)
.withValue(LocalEvent.COLUMN_FLAGS, flags)
.withValue(Events.DIRTY, 0)
.withValue(Events.DELETED, 0)
.withValue(COLUMN_FLAGS, flags)
if (buildException)
builder .withValue(Events.ORIGINAL_SYNC_ID, fileName)
......@@ -106,7 +105,7 @@ class LocalEvent: AndroidEvent, LocalResource<Event> {
override fun clearDirty(eTag: String?) {
val values = ContentValues(2)
values.put(CalendarContract.Events.DIRTY, 0)
values.put(Events.DIRTY, 0)
values.put(COLUMN_ETAG, eTag)
values.put(COLUMN_SEQUENCE, event!!.sequence)
calendar.provider.update(eventSyncURI(), values, null, null)
......
......@@ -200,7 +200,7 @@ class LocalGroup: AndroidGroup, LocalAddress {
override fun updateFlags(flags: Int) {
val values = ContentValues(1)
values.put(LocalGroup.COLUMN_FLAGS, flags)
values.put(COLUMN_FLAGS, flags)
addressBook.provider!!.update(groupSyncUri(), values, null, null)
this.flags = flags
......
......@@ -258,7 +258,7 @@ class AccountSettings(
* SEQUENCE and should not be used for the eTag.
*/
private fun update_7_8() {
TaskProvider.acquire(context, TaskProvider.ProviderName.OpenTasks)?.use { provider ->
TaskProvider.acquire(context, OpenTasks)?.use { provider ->
// ETag is now in sync_version instead of sync1
// UID is now in _uid instead of sync2
provider.client.query(TaskProvider.syncAdapterUri(provider.tasksUri(), account),
......
......@@ -76,7 +76,7 @@ class SharedPreferencesProvider(
override fun isWritable(key: String) =
Pair(true, true)
Pair(first = true, second = true)
private fun<T> putValue(key: String, value: T?, writer: (SharedPreferences.Editor, T) -> Unit): Boolean {
return if (value == null)
......
......@@ -80,7 +80,7 @@ class AccountAuthenticatorService: Service(), OnAccountsUpdateListener {
}
override fun onBind(intent: Intent?) =
accountAuthenticator.iBinder.takeIf { intent?.action == android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT }
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }
override fun onAccountsUpdated(accounts: Array<out Account>?) {
......
......@@ -12,6 +12,7 @@ import android.content.ContentProvider
import android.content.ContentValues
import android.net.Uri
@Suppress("ImplicitNullableNothingType")
class AddressBookProvider: ContentProvider() {
override fun onCreate() = false
......
......@@ -150,23 +150,22 @@ class ContactsSyncManager(
else
SyncAlgorithm.PROPFIND_REPORT
override fun processLocallyDeleted(): Boolean {
if (readOnly) {
for (group in localCollection.findDeletedGroups()) {
Logger.log.warning("Restoring locally deleted group (read-only address book!)")
useLocal(group) { it.resetDeleted() }
}
override fun processLocallyDeleted() =
if (readOnly) {
for (group in localCollection.findDeletedGroups()) {
Logger.log.warning("Restoring locally deleted group (read-only address book!)")
useLocal(group) { it.resetDeleted() }
}
for (contact in localCollection.findDeletedContacts()) {
Logger.log.warning("Restoring locally deleted contact (read-only address book!)")
useLocal(contact) { it.resetDeleted() }
}
for (contact in localCollection.findDeletedContacts()) {
Logger.log.warning("Restoring locally deleted contact (read-only address book!)")
useLocal(contact) { it.resetDeleted() }
}
return false
} else
// mirror deletions to remote collection (DELETE)
return super.processLocallyDeleted()
}
false
} else
// mirror deletions to remote collection (DELETE)
super.processLocallyDeleted()
override fun uploadDirty(): Boolean {
if (readOnly) {
......
......@@ -26,7 +26,7 @@ class NullAuthenticatorService: Service() {
}
override fun onBind(intent: Intent?) =
accountAuthenticator.iBinder.takeIf { intent?.action == android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT }
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }
private class AccountAuthenticator(
......
......@@ -115,7 +115,7 @@ class AccountSettingsActivity: AppCompatActivity() {
override fun onSettingsChanged() = reload()
fun reload() {
private fun reload() {
val accountSettings = AccountSettings(requireActivity(), account)
// preference group: authentication
......
......@@ -62,7 +62,7 @@ class CreateCalendarActivity: AppCompatActivity(), ColorPickerDialogListener {
binding.lifecycleOwner = this
binding.model = model
binding.color.setOnClickListener { _ ->
binding.color.setOnClickListener {
ColorPickerDialog.newBuilder()
.setShowAlphaSlider(false)
.setColor((color.background as ColorDrawable).color)
......@@ -163,7 +163,7 @@ class CreateCalendarActivity: AppCompatActivity(), ColorPickerDialogListener {
context: Context
): ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, android.R.id.text1) {
val tz = TimeZone.getAvailableIDs()
val tz = TimeZone.getAvailableIDs()!!
override fun getFilter(): Filter {
return object: Filter() {
......
......@@ -142,13 +142,13 @@ class DebugInfoActivity: AppCompatActivity() {
// exception details
val throwable = extras?.getSerializable(KEY_THROWABLE) as Throwable?
if (throwable is HttpException) {
throwable.request?.let {
text.append("\nHTTP REQUEST:\n$it\n")
throwable.request?.let { request ->
text.append("\nHTTP REQUEST:\n$request\n")
throwable.requestBody?.let { text.append(it) }
text.append("\n\n")
}
throwable.response?.let {
text.append("HTTP RESPONSE:\n$it\n")
throwable.response?.let { response ->
text.append("HTTP RESPONSE:\n$response\n")
throwable.responseBody?.let { text.append(it) }
text.append("\n\n")
}
......
......@@ -60,16 +60,16 @@ class StartupDialogFragment: DialogFragment() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && settings.getBoolean(HINT_BATTERY_OPTIMIZATIONS) != false) {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
if (!powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID))
dialogs.add(StartupDialogFragment.instantiate(Mode.BATTERY_OPTIMIZATIONS))
dialogs.add(instantiate(Mode.BATTERY_OPTIMIZATIONS))
}
// vendor-specific auto-start information
if (autostartManufacturers.contains(Build.MANUFACTURER.toLowerCase()) && settings.getBoolean(HINT_AUTOSTART_PERMISSIONS) != false)
dialogs.add(StartupDialogFragment.instantiate(Mode.AUTOSTART_PERMISSIONS))
dialogs.add(instantiate(Mode.AUTOSTART_PERMISSIONS))
// OpenTasks information
if (!LocalTaskList.tasksProviderAvailable(context) && settings.getBoolean(HINT_OPENTASKS_NOT_INSTALLED) != false)
dialogs.add(StartupDialogFragment.instantiate(Mode.OPENTASKS_NOT_INSTALLED))
dialogs.add(instantiate(Mode.OPENTASKS_NOT_INSTALLED))
return dialogs.reversed()
}
......@@ -91,8 +91,7 @@ class StartupDialogFragment: DialogFragment() {
val settings = Settings.getInstance(requireActivity())
val activity = requireActivity()
val mode = Mode.valueOf(arguments!!.getString(ARGS_MODE)!!)
return when (mode) {
return when (Mode.valueOf(arguments!!.getString(ARGS_MODE)!!)) {
Mode.AUTOSTART_PERMISSIONS ->
AlertDialog.Builder(activity)
.setIcon(R.drawable.ic_error_dark)
......
......@@ -317,14 +317,14 @@ class AccountActivity: AppCompatActivity() {
private var usesCalendars: Boolean? = null
init {
addSource(needContactPermissions, Observer {
addSource(needContactPermissions) {
usesContacts = it
calculate()
})
addSource(needCalendarPermissions, Observer {
}
addSource(needCalendarPermissions) {
usesCalendars = it
calculate()
})
}
}
fun calculate() {
......
package at.bitfire.davdroid.ui.account
import android.content.Intent
import android.os.Bundle
import android.view.*
import at.bitfire.davdroid.R
import at.bitfire.davdroid.model.Collection
......
......@@ -202,9 +202,9 @@ abstract class CollectionsFragment: Fragment(), SwipeRefreshLayout.OnRefreshList
private val db = AppDatabase.getInstance(application)
private val executor = Executors.newSingleThreadExecutor()
lateinit var accountModel: AccountActivity.Model
private lateinit var accountModel: AccountActivity.Model
val serviceId = MutableLiveData<Long>()
lateinit var collectionType: String
private lateinit var collectionType: String
val collections: LiveData<PagedList<Collection>> =
Transformations.switchMap(serviceId) { service ->
......
......@@ -38,7 +38,7 @@ class WebcalFragment: CollectionsFragment() {
override val noCollectionsStringId = R.string.account_no_webcals
lateinit var webcalModel: WebcalModel
private lateinit var webcalModel: WebcalModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......
......@@ -43,7 +43,7 @@ class DavResourceFinder(
override fun toString() = wellKnownName
}
val log = Logger.getLogger("davdroid.DavResourceFinder")!!
val log = Logger.getLogger("davdroid.DavResourceFinder")
private val logBuffer = StringHandler()
init {
log.level = Level.FINEST
......
......@@ -7,8 +7,8 @@
~ http://www.gnu.org/licenses/gpl.html
-->
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="true" tools:ignore="InsecureBaseConfiguration">
<trust-anchors>
<certificates src="system"/>
<certificates src="user"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment