mirror of
https://github.com/etesync/android
synced 2025-01-23 14:10:54 +00:00
Fix many compilation warnings
Either deprecated usage or kotlin warnings
This commit is contained in:
parent
a7f0144fc8
commit
e39e882c0a
@ -72,8 +72,8 @@ class NotificationHelper(internal val context: Context, internal val notificatio
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun notify(title: String, content: String, bigText: String?, intent: Intent, icon: Int = -1) {
|
||||
var icon = icon
|
||||
fun notify(title: String, content: String, bigText: String?, intent: Intent, _icon: Int = -1) {
|
||||
var icon = _icon
|
||||
createNotificationChannel()
|
||||
val builder = NotificationCompat.Builder(context)
|
||||
val category = if (throwable == null)
|
||||
|
@ -3,7 +3,6 @@ package com.etesync.syncadapter.journalmanager
|
||||
import com.etesync.syncadapter.App
|
||||
import com.etesync.syncadapter.GsonHelper
|
||||
import okhttp3.*
|
||||
import org.apache.commons.codec.Charsets
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.net.HttpURLConnection
|
||||
@ -51,11 +50,11 @@ abstract class BaseManager {
|
||||
var uid: String? = null
|
||||
|
||||
fun getContent(crypto: Crypto.CryptoManager): String {
|
||||
return String(crypto.decrypt(content!!)!!, Charsets.UTF_8)
|
||||
return String(crypto.decrypt(content!!)!!)
|
||||
}
|
||||
|
||||
fun setContent(crypto: Crypto.CryptoManager, content: String) {
|
||||
this.content = crypto.encrypt(content.toByteArray(Charsets.UTF_8))
|
||||
this.content = crypto.encrypt(content.toByteArray())
|
||||
}
|
||||
|
||||
fun calculateHmac(crypto: Crypto.CryptoManager, uuid: String?): ByteArray {
|
||||
@ -63,7 +62,7 @@ abstract class BaseManager {
|
||||
|
||||
try {
|
||||
if (uuid != null) {
|
||||
hashContent.write(uuid.toByteArray(Charsets.UTF_8))
|
||||
hashContent.write(uuid.toByteArray())
|
||||
}
|
||||
|
||||
hashContent.write(content!!)
|
||||
|
@ -37,7 +37,7 @@ object Crypto {
|
||||
fun deriveKey(salt: String, password: String): String {
|
||||
val keySize = 190
|
||||
|
||||
return Base64.encodeToString(SCrypt.generate(password.toByteArray(Charsets.UTF_8), salt.toByteArray(Charsets.UTF_8), 16384, 8, 1, keySize), Base64.NO_WRAP)
|
||||
return Base64.encodeToString(SCrypt.generate(password.toByteArray(), salt.toByteArray(), 16384, 8, 1, keySize), Base64.NO_WRAP)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@ -130,8 +130,8 @@ object Crypto {
|
||||
get() = SecureRandom()
|
||||
|
||||
private fun setDerivedKey(derivedKey: ByteArray?) {
|
||||
cipherKey = hmac256("aes".toByteArray(Charsets.UTF_8), derivedKey)
|
||||
hmacKey = hmac256("hmac".toByteArray(Charsets.UTF_8), derivedKey)
|
||||
cipherKey = hmac256("aes".toByteArray(), derivedKey)
|
||||
hmacKey = hmac256("hmac".toByteArray(), derivedKey)
|
||||
}
|
||||
|
||||
constructor(version: Int, keyPair: AsymmetricKeyPair, encryptedKey: ByteArray) {
|
||||
@ -151,7 +151,7 @@ object Crypto {
|
||||
} else if (version == 1) {
|
||||
derivedKey = Base64.decode(keyBase64, Base64.NO_WRAP)
|
||||
} else {
|
||||
derivedKey = hmac256(salt.toByteArray(Charsets.UTF_8), Base64.decode(keyBase64, Base64.NO_WRAP))
|
||||
derivedKey = hmac256(salt.toByteArray(), Base64.decode(keyBase64, Base64.NO_WRAP))
|
||||
}
|
||||
|
||||
this.version = version.toByte()
|
||||
@ -246,7 +246,7 @@ object Crypto {
|
||||
}
|
||||
|
||||
internal fun sha256(base: String): String {
|
||||
return toHex(sha256(base.toByteArray(Charsets.UTF_8)))
|
||||
return toHex(sha256(base.toByteArray()))
|
||||
}
|
||||
|
||||
private fun sha256(base: ByteArray): ByteArray {
|
||||
|
@ -102,7 +102,7 @@ class LocalAddressBook(
|
||||
// HELPERS
|
||||
|
||||
fun accountName(mainAccount: Account, info: CollectionInfo): String {
|
||||
val displayName = if (info.displayName != null) info.displayName else info.uid
|
||||
val displayName = info.displayName ?: info.uid!!
|
||||
val sb = StringBuilder(displayName)
|
||||
sb.append(" (")
|
||||
.append(mainAccount.name)
|
||||
|
@ -121,7 +121,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
||||
@Throws(CalendarStorageException::class, ContactsStorageException::class, IOException::class)
|
||||
private fun createInviteAttendeesNotification() {
|
||||
for (local in localDirty) {
|
||||
val event = (local as LocalEvent).event
|
||||
val event = local.event
|
||||
|
||||
if (event?.attendees?.isEmpty()!!) {
|
||||
return
|
||||
@ -144,8 +144,8 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
||||
}
|
||||
|
||||
@Throws(IOException::class, ContactsStorageException::class, CalendarStorageException::class)
|
||||
private fun processEvent(newData: Event, localEvent: LocalEvent?): LocalEvent {
|
||||
var localEvent = localEvent
|
||||
private fun processEvent(newData: Event, _localEvent: LocalEvent?): LocalEvent {
|
||||
var localEvent = _localEvent
|
||||
// delete local event, if it exists
|
||||
if (localEvent != null) {
|
||||
App.log.info("Updating " + newData.uid + " in local calendar")
|
||||
|
@ -52,7 +52,7 @@ import java.io.StringReader
|
||||
* Synchronization manager for CardDAV collections; handles contacts and groups.
|
||||
*/
|
||||
class ContactsSyncManager @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class, ContactsStorageException::class)
|
||||
constructor(context: Context, account: Account, settings: AccountSettings, extras: Bundle, authority: String, private val provider: ContentProviderClient, result: SyncResult, localAddressBook: LocalAddressBook, private val remote: HttpUrl) : SyncManager<LocalAddress>(context, account, settings, extras, authority, result, localAddressBook.url!!, CollectionInfo.Type.ADDRESS_BOOK, localAddressBook.mainAccount.name) {
|
||||
constructor(context: Context, account: Account, settings: AccountSettings, extras: Bundle, authority: String, private val provider: ContentProviderClient, result: SyncResult, localAddressBook: LocalAddressBook, private val remote: HttpUrl) : SyncManager<LocalAddress>(context, account, settings, extras, authority, result, localAddressBook.url, CollectionInfo.Type.ADDRESS_BOOK, localAddressBook.mainAccount.name) {
|
||||
|
||||
protected override val syncErrorTitle: String
|
||||
get() = context.getString(R.string.sync_error_contacts, account.name)
|
||||
@ -171,8 +171,8 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
||||
}
|
||||
|
||||
@Throws(IOException::class, ContactsStorageException::class)
|
||||
private fun processContact(newData: Contact, local: LocalAddress?): LocalAddress {
|
||||
var local = local
|
||||
private fun processContact(newData: Contact, _local: LocalAddress?): LocalAddress {
|
||||
var local = _local
|
||||
val uuid = newData.uid
|
||||
// update local contact, if it exists
|
||||
if (local != null) {
|
||||
@ -181,14 +181,14 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
||||
if (local is LocalGroup && newData.group) {
|
||||
// update group
|
||||
val group: LocalGroup = local
|
||||
group!!.eTag = uuid
|
||||
group.eTag = uuid
|
||||
group.update(newData)
|
||||
syncResult.stats.numUpdates++
|
||||
|
||||
} else if (local is LocalContact && !newData.group) {
|
||||
// update contact
|
||||
val contact: LocalContact = local
|
||||
contact!!.eTag = uuid
|
||||
contact.eTag = uuid
|
||||
contact.update(newData)
|
||||
syncResult.stats.numUpdates++
|
||||
|
||||
|
@ -99,8 +99,8 @@ class TasksSyncManager(
|
||||
}
|
||||
}
|
||||
|
||||
private fun processTask(newData: Task, localTask: LocalTask?): LocalTask {
|
||||
var localTask = localTask
|
||||
private fun processTask(newData: Task, _localTask: LocalTask?): LocalTask {
|
||||
var localTask = _localTask
|
||||
// delete local Task, if it exists
|
||||
if (localTask != null) {
|
||||
App.log.info("Updating " + newData.uid + " in local calendar")
|
||||
|
@ -105,7 +105,7 @@ class AboutActivity : BaseActivity() {
|
||||
|
||||
override fun onLoadFinished(loader: Loader<Spanned>, license: Spanned) {
|
||||
if (view != null) {
|
||||
val tv = view!!.findViewById<View>(R.id.license_text) as TextView
|
||||
val tv = view!!.findViewById<View>(R.id.license_text) as TextView?
|
||||
if (tv != null) {
|
||||
tv.autoLinkMask = Linkify.EMAIL_ADDRESSES or Linkify.WEB_URLS
|
||||
tv.text = license
|
||||
|
@ -50,20 +50,19 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
internal var listCardDAV: ListView? = null
|
||||
internal var listTaskDAV: ListView? = null
|
||||
|
||||
private val onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
||||
private val onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, _ ->
|
||||
val list = parent as ListView
|
||||
val adapter = list.adapter as ArrayAdapter<*>
|
||||
val journalEntity = adapter.getItem(position) as JournalEntity
|
||||
val info = journalEntity.getInfo()
|
||||
|
||||
startActivity(ViewCollectionActivity.newIntent(this@AccountActivity, account!!, info))
|
||||
startActivity(ViewCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
|
||||
private val formattedFingerprint: String?
|
||||
get() {
|
||||
var settings: AccountSettings? = null
|
||||
try {
|
||||
settings = AccountSettings(this, account!!)
|
||||
val settings = AccountSettings(this, account)
|
||||
return Crypto.AsymmetricCryptoManager.getPrettyKeyFingerprint(settings.keyPair!!.publicKey)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
@ -76,7 +75,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
account = intent.getParcelableExtra(EXTRA_ACCOUNT)
|
||||
title = account!!.name
|
||||
title = account.name
|
||||
|
||||
setContentView(R.layout.activity_account)
|
||||
|
||||
@ -113,8 +112,8 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
HintManager.setHintSeen(this, HINT_VIEW_COLLECTION, true)
|
||||
}
|
||||
|
||||
if (!SetupUserInfoFragment.hasUserInfo(this, account!!)) {
|
||||
SetupUserInfoFragment.newInstance(account!!).show(supportFragmentManager, null)
|
||||
if (!SetupUserInfoFragment.hasUserInfo(this, account)) {
|
||||
SetupUserInfoFragment.newInstance(account).show(supportFragmentManager, null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +135,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
.setTitle(R.string.account_delete_confirmation_title)
|
||||
.setMessage(R.string.account_delete_confirmation_text)
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setPositiveButton(android.R.string.yes) { dialog, which -> deleteAccount() }
|
||||
.setPositiveButton(android.R.string.yes) { _, _ -> deleteAccount() }
|
||||
.show()
|
||||
R.id.show_fingerprint -> {
|
||||
val view = layoutInflater.inflate(R.layout.fingerprint_alertdialog, null)
|
||||
@ -146,7 +145,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
.setIcon(R.drawable.ic_fingerprint_dark)
|
||||
.setTitle(R.string.show_fingperprint_title)
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.yes) { dialog, which -> }.create()
|
||||
.setPositiveButton(android.R.string.yes) { _, _ -> }.create()
|
||||
dialog.show()
|
||||
}
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
@ -160,17 +159,17 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
R.id.create_calendar -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.CALENDAR
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account!!, info))
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
R.id.create_tasklist -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.TASKS
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account!!, info))
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
R.id.create_addressbook -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.ADDRESS_BOOK
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account!!, info))
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
}
|
||||
return false
|
||||
@ -192,7 +191,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
}
|
||||
|
||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<AccountInfo> {
|
||||
return AccountLoader(this, account!!)
|
||||
return AccountLoader(this, account)
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
@ -211,7 +210,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
listCardDAV!!.isEnabled = !info.carddav!!.refreshing
|
||||
listCardDAV!!.setAlpha(if (info.carddav!!.refreshing) 0.5f else 1f)
|
||||
|
||||
val adapter = CollectionListAdapter(this, account!!)
|
||||
val adapter = CollectionListAdapter(this, account)
|
||||
adapter.addAll(info.carddav!!.journals!!)
|
||||
listCardDAV!!.adapter = adapter
|
||||
listCardDAV!!.onItemClickListener = onItemClickListener
|
||||
@ -227,7 +226,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
listCalDAV!!.isEnabled = !info.caldav!!.refreshing
|
||||
listCalDAV!!.setAlpha(if (info.caldav!!.refreshing) 0.5f else 1f)
|
||||
|
||||
val adapter = CollectionListAdapter(this, account!!)
|
||||
val adapter = CollectionListAdapter(this, account)
|
||||
adapter.addAll(info.caldav!!.journals!!)
|
||||
listCalDAV!!.adapter = adapter
|
||||
listCalDAV!!.onItemClickListener = onItemClickListener
|
||||
@ -243,7 +242,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
listTaskDAV!!.isEnabled = !info.taskdav!!.refreshing
|
||||
listTaskDAV!!.setAlpha(if (info.taskdav!!.refreshing) 0.5f else 1f)
|
||||
|
||||
val adapter = CollectionListAdapter(this, account!!)
|
||||
val adapter = CollectionListAdapter(this, account)
|
||||
adapter.addAll(info.taskdav!!.journals!!)
|
||||
listTaskDAV!!.adapter = adapter
|
||||
listTaskDAV!!.onItemClickListener = onItemClickListener
|
||||
|
@ -54,7 +54,7 @@ class RemoveMemberFragment : DialogFragment() {
|
||||
val journalsManager = JournalManager(httpClient!!, remote!!)
|
||||
val journal = JournalManager.Journal.fakeWithUid(info!!.uid!!)
|
||||
|
||||
val member = JournalManager.Member(memberEmail!!, "placeholder".toByteArray(Charsets.UTF_8))
|
||||
val member = JournalManager.Member(memberEmail!!, "placeholder".toByteArray())
|
||||
journalsManager.deleteMember(journal, member)
|
||||
|
||||
return RemoveResult(null)
|
||||
|
@ -44,11 +44,11 @@ class EncryptionTest {
|
||||
val cryptoManager = Crypto.CryptoManager(1, Helpers.keyBase64, "TestSaltShouldBeJournalId")
|
||||
|
||||
val clearText = "This Is Some Test Cleartext."
|
||||
val cipher = cryptoManager.encrypt(clearText.toByteArray(Charsets.UTF_8))
|
||||
assertEquals(clearText, String(cryptoManager.decrypt(cipher!!)!!, Charsets.UTF_8))
|
||||
val cipher = cryptoManager.encrypt(clearText.toByteArray())
|
||||
assertEquals(clearText, String(cryptoManager.decrypt(cipher!!)!!))
|
||||
|
||||
val expected = "Lz+HUFzh1HdjxuGdQrBwBG1IzHT0ug6mO8fwePSbXtc="
|
||||
assertEquals(expected, Base64.encodeToString(cryptoManager.hmac("Some test data".toByteArray(Charsets.UTF_8)), Base64.NO_WRAP))
|
||||
assertEquals(expected, Base64.encodeToString(cryptoManager.hmac("Some test data".toByteArray()), Base64.NO_WRAP))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -57,11 +57,11 @@ class EncryptionTest {
|
||||
val cryptoManager = Crypto.CryptoManager(2, Helpers.keyBase64, "TestSaltShouldBeJournalId")
|
||||
|
||||
val clearText = "This Is Some Test Cleartext."
|
||||
val cipher = cryptoManager.encrypt(clearText.toByteArray(Charsets.UTF_8))
|
||||
assertEquals(clearText, String(cryptoManager.decrypt(cipher!!)!!, Charsets.UTF_8))
|
||||
val cipher = cryptoManager.encrypt(clearText.toByteArray())
|
||||
assertEquals(clearText, String(cryptoManager.decrypt(cipher!!)!!))
|
||||
|
||||
val expected = "XQ/A0gentOaE98R9wzf3zEIAHj4OH1GF8J4C6JiJupo="
|
||||
assertEquals(expected, Base64.encodeToString(cryptoManager.hmac("Some test data".toByteArray(Charsets.UTF_8)), Base64.NO_WRAP))
|
||||
assertEquals(expected, Base64.encodeToString(cryptoManager.hmac("Some test data".toByteArray()), Base64.NO_WRAP))
|
||||
}
|
||||
|
||||
@Test(expected = Exceptions.VersionTooNewException::class)
|
||||
@ -82,13 +82,13 @@ class EncryptionTest {
|
||||
val keyPair = Crypto.generateKeyPair()
|
||||
val cryptoManager = Crypto.AsymmetricCryptoManager(keyPair!!)
|
||||
|
||||
val clearText = "This Is Some Test Cleartext.".toByteArray(Charsets.UTF_8)
|
||||
val clearText = "This Is Some Test Cleartext.".toByteArray()
|
||||
val cipher = cryptoManager.encrypt(keyPair.publicKey, clearText)
|
||||
val clearText2 = cryptoManager.decrypt(cipher!!)
|
||||
assertArrayEquals(clearText, clearText2)
|
||||
|
||||
// Mostly for coverage. Make sure it's the expected sha256 value.
|
||||
assertEquals("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
|
||||
Hex.toHexString(Crypto.AsymmetricCryptoManager.getKeyFingerprint("a".toByteArray(Charsets.UTF_8))).toLowerCase())
|
||||
Hex.toHexString(Crypto.AsymmetricCryptoManager.getKeyFingerprint("a".toByteArray())).toLowerCase())
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ class ServiceTest {
|
||||
assertArrayEquals(userInfo.getContent(cryptoManager), userInfo2!!.getContent(cryptoManager))
|
||||
|
||||
// Update
|
||||
userInfo.setContent(cryptoManager, "test".toByteArray(Charsets.UTF_8))
|
||||
userInfo.setContent(cryptoManager, "test".toByteArray())
|
||||
manager.update(userInfo)
|
||||
userInfo2 = manager[Helpers.USER]
|
||||
assertNotNull(userInfo2)
|
||||
@ -260,7 +260,7 @@ class ServiceTest {
|
||||
assertEquals(journalManager.listMembers(journal).size.toLong(), 0)
|
||||
|
||||
// Test inviting ourselves
|
||||
val member = JournalManager.Member(Helpers.USER, "test".toByteArray(Charsets.UTF_8))
|
||||
val member = JournalManager.Member(Helpers.USER, "test".toByteArray())
|
||||
try {
|
||||
caught = null
|
||||
journalManager.addMember(journal, member)
|
||||
@ -270,7 +270,7 @@ class ServiceTest {
|
||||
|
||||
assertNotNull(caught)
|
||||
|
||||
val member2 = JournalManager.Member(Helpers.USER2, "test".toByteArray(Charsets.UTF_8))
|
||||
val member2 = JournalManager.Member(Helpers.USER2, "test".toByteArray())
|
||||
journalManager.addMember(journal, member2)
|
||||
assertEquals(journalManager.listMembers(journal).size.toLong(), 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user