Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id("com.android.application")
id("kotlin-parcelize")
kotlin("android")
kotlin("plugin.serialization") version("1.9.0")
kotlin("plugin.serialization") version "1.9.0"
}

fun gitVersionCode(): Int {
Expand All @@ -21,7 +21,10 @@ fun gitVersionCode(): Int {
commandLine = arrayListOf("git", "rev-list", "--count", "HEAD")
}

return result.standardOutput.asText.get().trimEnd().toInt()
return result.standardOutput.asText
.get()
.trimEnd()
.toInt()
}

fun gitVersionName(): String {
Expand All @@ -30,7 +33,10 @@ fun gitVersionName(): String {
commandLine = arrayListOf("git", "describe", "--tags", "--always")
}

return result.standardOutput.asText.get().trimEnd().replace("-g", "-")
return result.standardOutput.asText
.get()
.trimEnd()
.replace("-g", "-")
}

java {
Expand Down Expand Up @@ -118,15 +124,19 @@ abstract class ReadmePermsCheckTask : DefaultTask() {
@TaskAction
fun execute() {
val permNodes =
XmlParser(false, false).parse(
File(manifestDir.singleFile, "AndroidManifest.xml"),
).get("uses-permission") as NodeList
XmlParser(false, false)
.parse(
File(manifestDir.singleFile, "AndroidManifest.xml"),
).get("uses-permission") as NodeList

val manifestPerms =
permNodes.map { perm ->
(perm as Node).attribute("android:name").toString()
.removePrefix("android.permission.")
}.filter { !it.startsWith(applicationId.get()) }
permNodes
.map { perm ->
(perm as Node)
.attribute("android:name")
.toString()
.removePrefix("android.permission.")
}.filter { !it.startsWith(applicationId.get()) }

val permLine = Regex("""^ - `([A-Z_]+)` \\$""")
val readmePerms =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ class TestUtils {
Context.APP_OPS_SERVICE,
) as AppOpsManager

val permAllowed = fun(): Boolean {
return appOps.unsafeCheckOpNoThrow(
val permAllowed = fun(): Boolean =
appOps.unsafeCheckOpNoThrow(
"android:manage_external_storage",
Process.myUid(),
context.packageName,
) == AppOpsManager.MODE_ALLOWED
}

if (permAllowed() == enabled) {
return
}

InstrumentationRegistry.getInstrumentation().uiAutomation
InstrumentationRegistry
.getInstrumentation()
.uiAutomation
.executeShellCommand(
"appops set ${context.packageName} " +
"MANAGE_EXTERNAL_STORAGE " +
Expand All @@ -65,13 +66,17 @@ class TestUtils {
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (enabled) {
InstrumentationRegistry.getInstrumentation().uiAutomation
InstrumentationRegistry
.getInstrumentation()
.uiAutomation
.grantRuntimePermission(
context.packageName,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
)
} else {
InstrumentationRegistry.getInstrumentation().uiAutomation
InstrumentationRegistry
.getInstrumentation()
.uiAutomation
.revokeRuntimePermission(
context.packageName,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import com.joaomgcd.taskerpluginlibrary.runner.TaskerPluginResultSucess
import com.nerdoftheherd.tasker.rsync.config.DbclientConfig
import com.nerdoftheherd.tasker.rsync.output.CommandOutput

class DbclientRunner(private val timeoutOverride: Int? = null) :
TaskerPluginRunnerAction<DbclientConfig, CommandOutput>() {
class DbclientRunner(
private val timeoutOverride: Int? = null,
) : TaskerPluginRunnerAction<DbclientConfig, CommandOutput>() {
override val notificationProperties get() =
NotificationProperties(
iconResId = R.drawable.ic_notification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

package com.nerdoftheherd.tasker.rsync

class RsyncArgExtractor(args: List<String>) {
class RsyncArgExtractor(
args: List<String>,
) {
val paths = ArrayList<String>()
var remoteSrcOrDest: Boolean = false
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import com.nerdoftheherd.tasker.rsync.config.RsyncConfig
import com.nerdoftheherd.tasker.rsync.output.CommandOutput
import java.io.File

class RsyncRunner(private val timeoutOverride: Int? = null) :
TaskerPluginRunnerAction<RsyncConfig, CommandOutput>() {
class RsyncRunner(
private val timeoutOverride: Int? = null,
) : TaskerPluginRunnerAction<RsyncConfig, CommandOutput>() {
override val notificationProperties get() =
NotificationProperties(
iconResId = R.drawable.ic_notification,
Expand Down Expand Up @@ -72,7 +73,8 @@ class RsyncRunner(private val timeoutOverride: Int? = null) :
}
} else {
externalPaths +=
Environment.getExternalStorageDirectory()
Environment
.getExternalStorageDirectory()
.absolutePath
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,15 @@ class UpdateNotifier {
} else {
@Suppress("DEPRECATION")
Notification.Builder(context)
}
.setSmallIcon(R.drawable.ic_notification)
}.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(
context.getString(R.string.update_available),
)
.setContentText(
).setContentText(
context.getString(
R.string.update_notif_text,
info.version,
),
)
.setContentIntent(updatePI)
).setContentIntent(updatePI)

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
@Suppress("DEPRECATION")
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/nerdoftheherd/tasker/rsync/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class Utils {
const val ERROR_MISSING_STORAGE_PERMISSION = 101
const val KEY_FILENAME = "id_dropbear"

fun privateKeyFile(context: Context): File {
return File(context.filesDir, KEY_FILENAME)
}
fun privateKeyFile(context: Context): File =
File(context.filesDir, KEY_FILENAME)
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/nerdoftheherd/tasker/rsync/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import kotlinx.parcelize.Parcelize
import java.util.Objects

@Parcelize
class Version(private val value: String) : Parcelable {
class Version(
private val value: String,
) : Parcelable {
@IgnoredOnParcel
private val numParts: List<Int>

Expand Down Expand Up @@ -57,9 +59,7 @@ class Version(private val value: String) : Parcelable {

override fun hashCode() = Objects.hash(value)

override fun toString(): String {
return value
}
override fun toString(): String = value

companion object {
private val verPattern =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ data class VersionInfo(

if (info == null) {
val data =
httpConn.inputStream.bufferedReader()
httpConn.inputStream
.bufferedReader()
.use(BufferedReader::readText)

info = ignoreUnknownJson.decodeFromString<VersionInfo>(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ class DbclientConfigActivity :
this.checkForUpdates ?: if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
) {
context.packageManager.getInstallSourceInfo(
context.packageName,
).packageSource != PackageInstaller.PACKAGE_SOURCE_STORE
context.packageManager
.getInstallSourceInfo(
context.packageName,
).packageSource != PackageInstaller.PACKAGE_SOURCE_STORE
} else {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ class RsyncConfigActivity :
this.checkForUpdates ?: if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
) {
context.packageManager.getInstallSourceInfo(
context.packageName,
).packageSource != PackageInstaller.PACKAGE_SOURCE_STORE
context.packageManager
.getInstallSourceInfo(
context.packageName,
).packageSource != PackageInstaller.PACKAGE_SOURCE_STORE
} else {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class UpdateActivity : AppCompatActivity() {
}
}

private suspend fun download(): File {
return withContext(Dispatchers.IO) {
private suspend fun download(): File =
withContext(Dispatchers.IO) {
val conn = info.download.openConnection() as HttpURLConnection
conn.connect()

Expand All @@ -104,5 +104,4 @@ class UpdateActivity : AppCompatActivity() {
stream.close()
file
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.nerdoftheherd.tasker.rsync.DbclientRunner
import com.nerdoftheherd.tasker.rsync.config.DbclientConfig
import com.nerdoftheherd.tasker.rsync.output.CommandOutput

class DbclientHelper(config: TaskerPluginConfig<DbclientConfig>) :
TaskerPluginConfigHelper<DbclientConfig, CommandOutput, DbclientRunner>(
class DbclientHelper(
config: TaskerPluginConfig<DbclientConfig>,
) : TaskerPluginConfigHelper<DbclientConfig, CommandOutput, DbclientRunner>(
config,
) {
override val runnerClass = DbclientRunner::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigHelperNoOutput
import com.nerdoftheherd.tasker.rsync.PrivateKeyRunner
import com.nerdoftheherd.tasker.rsync.config.PrivateKeyConfig

class PrivateKeyHelper(config: TaskerPluginConfig<PrivateKeyConfig>) :
TaskerPluginConfigHelperNoOutput<PrivateKeyConfig, PrivateKeyRunner>(
class PrivateKeyHelper(
config: TaskerPluginConfig<PrivateKeyConfig>,
) : TaskerPluginConfigHelperNoOutput<PrivateKeyConfig, PrivateKeyRunner>(
config,
) {
override val runnerClass = PrivateKeyRunner::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigNoInput
import com.nerdoftheherd.tasker.rsync.PublicKeyRunner
import com.nerdoftheherd.tasker.rsync.output.PublicKeyOutput

class PublicKeyHelper(config: TaskerPluginConfigNoInput) :
TaskerPluginConfigHelperNoInput<PublicKeyOutput, PublicKeyRunner>(config) {
class PublicKeyHelper(
config: TaskerPluginConfigNoInput,
) : TaskerPluginConfigHelperNoInput<PublicKeyOutput, PublicKeyRunner>(config) {
override val runnerClass = PublicKeyRunner::class.java
override val outputClass = PublicKeyOutput::class.java
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.nerdoftheherd.tasker.rsync.RsyncRunner
import com.nerdoftheherd.tasker.rsync.config.RsyncConfig
import com.nerdoftheherd.tasker.rsync.output.CommandOutput

class RsyncHelper(config: TaskerPluginConfig<RsyncConfig>) :
TaskerPluginConfigHelper<RsyncConfig, CommandOutput, RsyncRunner>(config) {
class RsyncHelper(
config: TaskerPluginConfig<RsyncConfig>,
) : TaskerPluginConfigHelper<RsyncConfig, CommandOutput, RsyncRunner>(config) {
override val runnerClass = RsyncRunner::class.java
override val inputClass = RsyncConfig::class.java
override val outputClass = CommandOutput::class.java
Expand Down
16 changes: 6 additions & 10 deletions app/src/test/java/com/nerdoftheherd/tasker/rsync/FakeAtomicFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import android.util.AtomicFile
import java.io.File
import java.io.FileOutputStream

class FakeAtomicFile(private val baseFile: File) : AtomicFile(baseFile) {
override fun getBaseFile(): File {
return baseFile
}
class FakeAtomicFile(
private val baseFile: File,
) : AtomicFile(baseFile) {
override fun getBaseFile(): File = baseFile

override fun readFully(): ByteArray {
return baseFile.readBytes()
}
override fun readFully(): ByteArray = baseFile.readBytes()

override fun startWrite(): FileOutputStream {
return baseFile.outputStream()
}
override fun startWrite(): FileOutputStream = baseFile.outputStream()

override fun finishWrite(str: FileOutputStream?) {
str?.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL

class MockHttpURLConnection(private val responseData: String?) :
HttpURLConnection(URL("http://example.com/")) {
class MockHttpURLConnection(
private val responseData: String?,
) : HttpURLConnection(URL("http://example.com/")) {
var requestWasMade = false
private set

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
}

plugins {
id("org.jlleitschuh.gradle.ktlint") version "12.3.0"
id("org.jlleitschuh.gradle.ktlint") version "13.0.0"
}

allprojects {
Expand Down