Fully migrated to Kotlin
This commit is contained in:
@@ -29,51 +29,34 @@ import android.os.Bundle
|
||||
*/
|
||||
class Authenticator(context: Context) : AbstractAccountAuthenticator(context) {
|
||||
|
||||
// Editing properties is not supported
|
||||
override fun editProperties(r: AccountAuthenticatorResponse, s: String) = throw UnsupportedOperationException()
|
||||
override fun editProperties(r: AccountAuthenticatorResponse, s: String) =
|
||||
throw UnsupportedOperationException("Editing properties is not supported")
|
||||
|
||||
// Don't add additional accounts
|
||||
@Throws(NetworkErrorException::class)
|
||||
override fun addAccount(
|
||||
r: AccountAuthenticatorResponse,
|
||||
s: String,
|
||||
s2: String,
|
||||
strings: Array<String>,
|
||||
bundle: Bundle) = null
|
||||
override fun addAccount(r: AccountAuthenticatorResponse, s: String, s2: String, strings: Array<String>, bundle: Bundle) = null
|
||||
|
||||
// Ignore attempts to confirm credentials
|
||||
@Throws(NetworkErrorException::class)
|
||||
override fun confirmCredentials(
|
||||
r: AccountAuthenticatorResponse,
|
||||
account: Account,
|
||||
bundle: Bundle) = null
|
||||
override fun confirmCredentials(r: AccountAuthenticatorResponse, account: Account, bundle: Bundle) = null
|
||||
|
||||
// Getting an authentication token is not supported
|
||||
@Throws(NetworkErrorException::class)
|
||||
override fun getAuthToken(
|
||||
r: AccountAuthenticatorResponse,
|
||||
account: Account,
|
||||
s: String,
|
||||
bundle: Bundle) = throw UnsupportedOperationException()
|
||||
override fun getAuthToken(r: AccountAuthenticatorResponse, account: Account, s: String, bundle: Bundle) =
|
||||
throw UnsupportedOperationException("Getting an authentication token is not supported")
|
||||
|
||||
// Getting a label for the auth token is not supported
|
||||
override fun getAuthTokenLabel(s: String) = throw UnsupportedOperationException()
|
||||
override fun getAuthTokenLabel(s: String) =
|
||||
throw UnsupportedOperationException("Getting a label for the auth token is not supported")
|
||||
|
||||
// Updating user credentials is not supported
|
||||
@Throws(NetworkErrorException::class)
|
||||
override fun updateCredentials(
|
||||
r: AccountAuthenticatorResponse,
|
||||
account: Account,
|
||||
s: String, bundle: Bundle) = throw UnsupportedOperationException()
|
||||
override fun updateCredentials(r: AccountAuthenticatorResponse, account: Account, s: String, bundle: Bundle) =
|
||||
throw UnsupportedOperationException("Updating user credentials is not supported")
|
||||
|
||||
// Checking features for the account is not supported
|
||||
@Throws(NetworkErrorException::class)
|
||||
override fun hasFeatures(
|
||||
r: AccountAuthenticatorResponse,
|
||||
account: Account, strings: Array<String>) = throw UnsupportedOperationException()
|
||||
override fun hasFeatures(r: AccountAuthenticatorResponse, account: Account, strings: Array<String>) =
|
||||
throw UnsupportedOperationException("Checking features for the account is not supported")
|
||||
|
||||
companion object {
|
||||
@JvmField val ACCOUNT_SYNC = Account("Bitmessage", "ch.dissem.bitmessage")
|
||||
@JvmField val ACCOUNT_POW = Account("Proof of Work ", "ch.dissem.bitmessage")
|
||||
val ACCOUNT_SYNC = Account("Bitmessage", "ch.dissem.bitmessage")
|
||||
val ACCOUNT_POW = Account("Proof of Work ", "ch.dissem.bitmessage")
|
||||
}
|
||||
}
|
||||
|
@@ -43,11 +43,11 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
private val bmc = Singleton.getBitmessageContext(context)
|
||||
|
||||
override fun onPerformSync(
|
||||
account: Account,
|
||||
extras: Bundle,
|
||||
authority: String,
|
||||
provider: ContentProviderClient,
|
||||
syncResult: SyncResult
|
||||
account: Account,
|
||||
extras: Bundle,
|
||||
authority: String,
|
||||
provider: ContentProviderClient,
|
||||
syncResult: SyncResult
|
||||
) {
|
||||
try {
|
||||
if (account == ACCOUNT_SYNC) {
|
||||
@@ -81,10 +81,10 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
}
|
||||
LOG.info("Synchronization started")
|
||||
bmc.synchronize(
|
||||
trustedNode,
|
||||
Preferences.getTrustedNodePort(context),
|
||||
Preferences.getTimeoutInSeconds(context),
|
||||
true
|
||||
trustedNode,
|
||||
Preferences.getTrustedNodePort(context),
|
||||
Preferences.getTimeoutInSeconds(context),
|
||||
true
|
||||
)
|
||||
LOG.info("Synchronization finished")
|
||||
}
|
||||
@@ -113,12 +113,12 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
val (objectMessage, nonceTrialsPerByte, extraBytes) = powRepo.getItem(initialHash)
|
||||
val target = cryptography().getProofOfWorkTarget(objectMessage, nonceTrialsPerByte, extraBytes)
|
||||
val cryptoMsg = CryptoCustomMessage(
|
||||
ProofOfWorkRequest(identity, initialHash, CALCULATE, target))
|
||||
ProofOfWorkRequest(identity, initialHash, CALCULATE, target))
|
||||
cryptoMsg.signAndEncrypt(identity, signingKey)
|
||||
val response = bmc.send(
|
||||
trustedNode,
|
||||
Preferences.getTrustedNodePort(context),
|
||||
cryptoMsg
|
||||
trustedNode,
|
||||
Preferences.getTrustedNodePort(context),
|
||||
cryptoMsg
|
||||
)
|
||||
if (response.isError) {
|
||||
LOG.error("Server responded with error: ${String(response.getData())}")
|
||||
@@ -140,7 +140,6 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
|
||||
private const val SYNC_FREQUENCY = 15 * 60L // seconds
|
||||
|
||||
@JvmStatic
|
||||
fun startSync(ctx: Context) {
|
||||
// Create account, if it's missing. (Either first run, or user has deleted account.)
|
||||
val account = addAccount(ctx, ACCOUNT_SYNC)
|
||||
@@ -150,7 +149,6 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
ContentResolver.addPeriodicSync(account, AUTHORITY, Bundle(), SYNC_FREQUENCY)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun stopSync(ctx: Context) {
|
||||
// Create account, if it's missing. (Either first run, or user has deleted account.)
|
||||
val account = addAccount(ctx, ACCOUNT_SYNC)
|
||||
@@ -158,7 +156,6 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
ContentResolver.removePeriodicSync(account, AUTHORITY, Bundle())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun startPowSync(ctx: Context) {
|
||||
// Create account, if it's missing. (Either first run, or user has deleted account.)
|
||||
val account = addAccount(ctx, ACCOUNT_POW)
|
||||
@@ -168,7 +165,6 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
|
||||
ContentResolver.addPeriodicSync(account, AUTHORITY, Bundle(), SYNC_FREQUENCY)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun stopPowSync(ctx: Context) {
|
||||
// Create account, if it's missing. (Either first run, or user has deleted account.)
|
||||
val account = addAccount(ctx, ACCOUNT_POW)
|
||||
|
Reference in New Issue
Block a user