From 7a3c344d68bb2c710b56df5a0f061b15cc479583 Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:37:21 -0600 Subject: [PATCH] Moved lint rules to .editorconfig for Android Studio (#36302) **Related issue:** Resolves #36202 `./gradlew spotlessCheck` and Android Studio should use the same style rules. The `.editorconfig` Code Style option was enabled by default in my Android Studio. --- android/.editorconfig | 25 +++++++++++++++++++ android/app/build.gradle.kts | 9 +------ .../com/fleetdm/agent/CertificateService.kt | 18 ++++--------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 android/.editorconfig diff --git a/android/.editorconfig b/android/.editorconfig new file mode 100644 index 0000000000..b42a2c4d33 --- /dev/null +++ b/android/.editorconfig @@ -0,0 +1,25 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.{kt,kts}] +ktlint_code_style = android_studio +indent_size = 4 +indent_style = space +max_line_length = 140 + +# Jetpack Compose requires Composable functions to start with uppercase (PascalCase) +ktlint_standard_function-naming = disabled +# Android conventionally uses uppercase TAG constants for logging +ktlint_standard_property-naming = disabled + +# Android Studio IDE settings (prefixed with ij_) +# Allow trailing commas (cleaner diffs + easier reordering) +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +# Import ordering: prioritize Android +ij_kotlin_imports_layout = *,android.**,androidx.**,com.**,org.**,java.**,kotlin.**,kotlinx.**,^ diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 3be040a080..3e075cf486 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -83,14 +83,7 @@ spotless { kotlin { target("**/*.kt") targetExclude("**/build/**/*.kt") - ktlint().editorConfigOverride( - mapOf( - // Jetpack Compose requires Composable functions to start with uppercase (PascalCase) - "ktlint_standard_function-naming" to "disabled", - // Android conventionally uses uppercase TAG constants for logging - "ktlint_standard_property-naming" to "disabled", - ), - ) + ktlint() } kotlinGradle { target("*.gradle.kts") diff --git a/android/app/src/main/java/com/fleetdm/agent/CertificateService.kt b/android/app/src/main/java/com/fleetdm/agent/CertificateService.kt index f441cee88b..b4c4058dc6 100644 --- a/android/app/src/main/java/com/fleetdm/agent/CertificateService.kt +++ b/android/app/src/main/java/com/fleetdm/agent/CertificateService.kt @@ -6,14 +6,13 @@ import android.content.Context import android.content.Intent import android.os.IBinder import android.util.Log +import org.json.JSONObject +import java.security.PrivateKey +import java.security.cert.Certificate import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch -import org.json.JSONObject -import java.security.PrivateKey -import java.security.cert.Certificate -import java.security.cert.X509Certificate /** * Service to handle SCEP enrollment and silent certificate installation using DevicePolicyManager. @@ -35,10 +34,7 @@ class CertificateService : Service() { ) // Structure for SCEP result, holding the key and certificate(s) - data class ScepResult( - val privateKey: PrivateKey, - val certificateChain: Array, - ) + data class ScepResult(val privateKey: PrivateKey, val certificateChain: Array) override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val certDataJson = intent?.getStringExtra("CERT_DATA") @@ -118,11 +114,7 @@ class CertificateService : Service() { * Performs a silent installation of the KeyPair using the delegated CERT_INSTALL scope. * This method requires NO user interaction on modern managed devices (API 18+). */ - private fun installCertificateSilently( - alias: String, - privateKey: PrivateKey, - certificateChain: Array, - ) { + private fun installCertificateSilently(alias: String, privateKey: PrivateKey, certificateChain: Array) { val dpm = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager // The admin component is null because the caller is a DELEGATED application,