Skip to content

Commit 39218cc

Browse files
authored
Enable spotless on all modules (#587)
* Enable spotless on all modules The `./gradlew spotlessApply` command was failing in the `:watchfacepush:validator` and `:identity:credentialmanager` modules due to incorrect path calculations during the format and apply steps. This was caused by ambiguous source directory configurations in their `build.gradle.kts` files, which led to errors like `NoSuchFileException` and `FileAlreadyExistsException`. This commit resolves these issues by explicitly defining the `sourceSets` in the build scripts for the affected modules. This removes the ambiguity and ensures that Gradle and the Spotless plugin can reliably locate the source files. As a result of this fix, the `apply_spotless.yml` GitHub workflow has been simplified to run a single, project-wide `spotlessApply` command. The `.gitignore` has also been updated to correctly ignore all `build` directories. * Apply Spotless --------- Co-authored-by: cartland <[email protected]>
1 parent d1b418e commit 39218cc

30 files changed

+1001
-784
lines changed

.github/workflows/apply_spotless.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ jobs:
4242
java-version: '17'
4343

4444
- name: Run spotlessApply
45-
run: ./gradlew :compose:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
46-
47-
- name: Run spotlessApply for Wear
48-
run: ./gradlew :wear:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
49-
50-
- name: Run spotlessApply for Misc
51-
run: ./gradlew :misc:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
52-
53-
- name: Run spotlessApply for XR
54-
run: ./gradlew :xr:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
45+
run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
5546

5647
- name: Auto-commit if spotlessApply has changes
5748
uses: stefanzweifel/git-auto-commit-action@v5

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/.idea/modules.xml
77
/.idea/workspace.xml
88
.DS_Store
9-
/build
9+
build
1010
/captures
1111
.externalNativeBuild
1212
.idea/*

identity/credentialmanager/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ android {
3939
buildFeatures {
4040
compose = true
4141
}
42+
sourceSets {
43+
named("main") {
44+
java {
45+
srcDir("src/main/java")
46+
}
47+
}
48+
}
4249
}
4350

4451
dependencies {
Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.example.identity.credentialmanager
218

319
import android.app.Activity
@@ -13,39 +29,39 @@ import androidx.credentials.exceptions.GetCredentialException
1329

1430
// This class is mostly copied from https://github.com/android/identity-samples/blob/main/WebView/CredentialManagerWebView/CredentialManagerHandler.kt.
1531
class CredentialManagerHandler(private val activity: Activity) {
16-
private val mCredMan = CredentialManager.create(activity.applicationContext)
17-
private val TAG = "CredentialManagerHandler"
18-
/**
19-
* Encapsulates the create passkey API for credential manager in a less error-prone manner.
20-
*
21-
* @param request a create public key credential request JSON required by [CreatePublicKeyCredentialRequest].
22-
* @return [CreatePublicKeyCredentialResponse] containing the result of the credential creation.
23-
*/
24-
suspend fun createPasskey(request: String): CreatePublicKeyCredentialResponse {
25-
val createRequest = CreatePublicKeyCredentialRequest(request)
26-
try {
27-
return mCredMan.createCredential(activity, createRequest) as CreatePublicKeyCredentialResponse
28-
} catch (e: CreateCredentialException) {
29-
// For error handling use guidance from https://developer.android.com/training/sign-in/passkeys
30-
Log.i(TAG, "Error creating credential: ErrMessage: ${e.errorMessage}, ErrType: ${e.type}")
31-
throw e
32+
private val mCredMan = CredentialManager.create(activity.applicationContext)
33+
private val TAG = "CredentialManagerHandler"
34+
/**
35+
* Encapsulates the create passkey API for credential manager in a less error-prone manner.
36+
*
37+
* @param request a create public key credential request JSON required by [CreatePublicKeyCredentialRequest].
38+
* @return [CreatePublicKeyCredentialResponse] containing the result of the credential creation.
39+
*/
40+
suspend fun createPasskey(request: String): CreatePublicKeyCredentialResponse {
41+
val createRequest = CreatePublicKeyCredentialRequest(request)
42+
try {
43+
return mCredMan.createCredential(activity, createRequest) as CreatePublicKeyCredentialResponse
44+
} catch (e: CreateCredentialException) {
45+
// For error handling use guidance from https://developer.android.com/training/sign-in/passkeys
46+
Log.i(TAG, "Error creating credential: ErrMessage: ${e.errorMessage}, ErrType: ${e.type}")
47+
throw e
48+
}
3249
}
33-
}
3450

35-
/**
36-
* Encapsulates the get passkey API for credential manager in a less error-prone manner.
37-
*
38-
* @param request a get public key credential request JSON required by [GetCredentialRequest].
39-
* @return [GetCredentialResponse] containing the result of the credential retrieval.
40-
*/
41-
suspend fun getPasskey(request: String): GetCredentialResponse {
42-
val getRequest = GetCredentialRequest(listOf(GetPublicKeyCredentialOption(request, null)))
43-
try {
44-
return mCredMan.getCredential(activity, getRequest)
45-
} catch (e: GetCredentialException) {
46-
// For error handling use guidance from https://developer.android.com/training/sign-in/passkeys
47-
Log.i(TAG, "Error retrieving credential: ${e.message}")
48-
throw e
51+
/**
52+
* Encapsulates the get passkey API for credential manager in a less error-prone manner.
53+
*
54+
* @param request a get public key credential request JSON required by [GetCredentialRequest].
55+
* @return [GetCredentialResponse] containing the result of the credential retrieval.
56+
*/
57+
suspend fun getPasskey(request: String): GetCredentialResponse {
58+
val getRequest = GetCredentialRequest(listOf(GetPublicKeyCredentialOption(request, null)))
59+
try {
60+
return mCredMan.getCredential(activity, getRequest)
61+
} catch (e: GetCredentialException) {
62+
// For error handling use guidance from https://developer.android.com/training/sign-in/passkeys
63+
Log.i(TAG, "Error retrieving credential: ${e.message}")
64+
throw e
65+
}
4966
}
50-
}
5167
}

identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/CredentialProviderDummyActivity.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.example.identity.credentialmanager
218

319
import android.annotation.SuppressLint
@@ -46,7 +62,7 @@ import java.security.spec.ECParameterSpec
4662
import java.security.spec.ECPoint
4763
import java.security.spec.EllipticCurve
4864

49-
class CredentialProviderDummyActivity: FragmentActivity() {
65+
class CredentialProviderDummyActivity : FragmentActivity() {
5066

5167
private val PERSONAL_ACCOUNT_ID: String = ""
5268
private val FAMILY_ACCOUNT_ID: String = ""
@@ -85,7 +101,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
85101

86102
val biometricPrompt = BiometricPrompt(
87103
this,
88-
{ }, // Pass in your own executor
104+
{ }, // Pass in your own executor
89105
object : AuthenticationCallback() {
90106
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
91107
super.onAuthenticationError(errorCode, errString)
@@ -109,7 +125,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
109125

110126
// Generate a credential key pair
111127
val spec = ECGenParameterSpec("secp256r1")
112-
val keyPairGen = KeyPairGenerator.getInstance("EC");
128+
val keyPairGen = KeyPairGenerator.getInstance("EC")
113129
keyPairGen.initialize(spec)
114130
val keyPair = keyPairGen.genKeyPair()
115131

@@ -165,7 +181,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
165181
@RequiresApi(VERSION_CODES.P)
166182
fun appInfoToOrigin(info: CallingAppInfo): String {
167183
val cert = info.signingInfo.apkContentsSigners[0].toByteArray()
168-
val md = MessageDigest.getInstance("SHA-256");
184+
val md = MessageDigest.getInstance("SHA-256")
169185
val certHash = md.digest(cert)
170186
// This is the format for origin
171187
return "android:apk-key-hash:${b64Encode(certHash)}"
@@ -240,7 +256,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
240256
)
241257
)
242258

243-
//Set the final response back
259+
// Set the final response back
244260
val result = Intent()
245261
val response = CreatePasswordResponse()
246262
PendingIntentHandler.setCreateCredentialResponse(result, response)
@@ -300,10 +316,11 @@ class CredentialProviderDummyActivity: FragmentActivity() {
300316

301317
val biometricPrompt = BiometricPrompt(
302318
this,
303-
{ }, // Pass in your own executor
319+
{ }, // Pass in your own executor
304320
object : BiometricPrompt.AuthenticationCallback() {
305321
override fun onAuthenticationError(
306-
errorCode: Int, errString: CharSequence
322+
errorCode: Int,
323+
errString: CharSequence
307324
) {
308325
super.onAuthenticationError(errorCode, errString)
309326
finish()
@@ -330,7 +347,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
330347
packageName = packageName
331348
)
332349

333-
val sig = Signature.getInstance("SHA256withECDSA");
350+
val sig = Signature.getInstance("SHA256withECDSA")
334351
sig.initSign(privateKey)
335352
sig.update(response.dataToSign())
336353
response.signature = sig.sign()
@@ -401,9 +418,7 @@ class CredentialProviderDummyActivity: FragmentActivity() {
401418
}
402419

403420
// [START android_identity_credential_pending_intent]
404-
fun createSettingsPendingIntent(): PendingIntent
405-
// [END android_identity_credential_pending_intent]
406-
{
421+
fun createSettingsPendingIntent(): PendingIntent { // [END android_identity_credential_pending_intent]
407422
return PendingIntent.getBroadcast(this, 0, Intent(), PendingIntent.FLAG_IMMUTABLE)
408423
}
409424

@@ -468,7 +483,7 @@ data class CredentialsInfo(
468483
val passwords: List<PasswordInfo> = listOf()
469484
)
470485

471-
class ECPrivateKeyImpl: ECPrivateKey {
486+
class ECPrivateKeyImpl : ECPrivateKey {
472487
override fun getAlgorithm(): String = ""
473488
override fun getFormat(): String = ""
474489
override fun getEncoded(): ByteArray = byteArrayOf()

0 commit comments

Comments
 (0)