Update ktlint to 1.5.0.

This commit is contained in:
jeffrey-signal
2025-12-05 09:48:22 -06:00
committed by GitHub
parent cc381513ef
commit 109fc7f1fa
24 changed files with 1254 additions and 385 deletions

View File

@@ -78,7 +78,7 @@ wire {
}
ktlint {
version.set("1.2.1")
version.set("1.5.0")
}
android {

View File

@@ -162,7 +162,9 @@ class DatabaseAttachment : Attachment {
override fun equals(other: Any?): Boolean {
return other != null &&
other is DatabaseAttachment && other.attachmentId == attachmentId && other.uri == uri
other is DatabaseAttachment &&
other.attachmentId == attachmentId &&
other.uri == uri
}
override fun hashCode(): Int {

View File

@@ -48,22 +48,19 @@ class SystemEmojiDrawable(emoji: CharSequence) : Drawable() {
companion object {
private val textPaint: TextPaint = TextPaint()
private fun getStaticLayout(emoji: CharSequence): StaticLayout =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
private fun getStaticLayout(emoji: CharSequence): StaticLayout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StaticLayout.Builder.obtain(emoji, 0, emoji.length, textPaint, Int.MAX_VALUE).build()
} else {
@Suppress("DEPRECATION")
StaticLayout(emoji, textPaint, Int.MAX_VALUE, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
}
private fun getProcessedEmoji(emoji: CharSequence): CharSequence =
try {
private fun getProcessedEmoji(emoji: CharSequence): CharSequence = try {
EmojiCompat.get().process(emoji) ?: emoji
} catch (e: IllegalStateException) {
emoji
}
private fun StaticLayout.getBounds(): RectF =
RectF(getLineLeft(0), 0f, getLineRight(0), getLineDescent(0) - getLineAscent(0).toFloat())
private fun StaticLayout.getBounds(): RectF = RectF(getLineLeft(0), 0f, getLineRight(0), getLineDescent(0) - getLineAscent(0).toFloat())
}
}

View File

@@ -36,14 +36,11 @@ sealed class DSLSettingsText {
}
companion object {
fun from(@StringRes stringId: Int, @ColorInt textColor: Int): DSLSettingsText =
FromResource(stringId, listOf(ColorModifier(textColor)))
fun from(@StringRes stringId: Int, @ColorInt textColor: Int): DSLSettingsText = FromResource(stringId, listOf(ColorModifier(textColor)))
fun from(@StringRes stringId: Int, vararg modifiers: Modifier): DSLSettingsText =
FromResource(stringId, modifiers.toList())
fun from(@StringRes stringId: Int, vararg modifiers: Modifier): DSLSettingsText = FromResource(stringId, modifiers.toList())
fun from(charSequence: CharSequence, vararg modifiers: Modifier): DSLSettingsText =
FromCharSequence(charSequence, modifiers.toList())
fun from(charSequence: CharSequence, vararg modifiers: Modifier): DSLSettingsText = FromCharSequence(charSequence, modifiers.toList())
}
interface Modifier {

View File

@@ -267,7 +267,8 @@ class BackupStateObserver(
Log.d(TAG, "[getNetworkBackupState][subscriptionStateMismatchDetected] No purchase found in Google Play Billing: $purchaseResult")
false
}
} || SignalStore.backup.backupTierInternalOverride == MessageBackupTier.PAID
} ||
SignalStore.backup.backupTierInternalOverride == MessageBackupTier.PAID
Log.d(TAG, "[getNetworkBackupState][subscriptionStateMismatchDetected] googlePlayBillingSubscriptionIsActiveAndWillRenew: $googlePlayBillingSubscriptionIsActiveAndWillRenew")

View File

@@ -75,8 +75,7 @@ class ChangeNumberRepository(
return accountManager.whoAmI
}
suspend fun ensureDecryptionsDrained(timeout: Duration = 15.seconds) =
withTimeoutOrNull(timeout) {
suspend fun ensureDecryptionsDrained(timeout: Duration = 15.seconds) = withTimeoutOrNull(timeout) {
suspendCancellableCoroutine {
val drainedListener = object : Runnable {
override fun run() {

View File

@@ -140,7 +140,8 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
)
private fun canEnableNotifications(): Boolean {
val areNotificationsDisabledBySystem = Build.VERSION.SDK_INT >= 26 && (
val areNotificationsDisabledBySystem = Build.VERSION.SDK_INT >= 26 &&
(
!NotificationChannels.getInstance().isMessageChannelEnabled ||
!NotificationChannels.getInstance().isMessagesChannelGroupEnabled ||
!NotificationChannels.getInstance().areNotificationsEnabled()

View File

@@ -50,7 +50,8 @@ object InAppDonations {
InAppPaymentType.ONE_TIME_GIFT -> true
InAppPaymentType.RECURRING_DONATION -> true
InAppPaymentType.RECURRING_BACKUP -> false
} && !LocaleRemoteConfig.isPayPalDisabled()
} &&
!LocaleRemoteConfig.isPayPalDisabled()
}
/**

View File

@@ -178,12 +178,10 @@ class ChatColors(
}
@JvmStatic
fun forGradient(id: Id, linearGradient: LinearGradient): ChatColors =
ChatColors(id, linearGradient, null)
fun forGradient(id: Id, linearGradient: LinearGradient): ChatColors = ChatColors(id, linearGradient, null)
@JvmStatic
fun forColor(id: Id, @ColorInt color: Int): ChatColors =
ChatColors(id, null, color)
fun forColor(id: Id, @ColorInt color: Int): ChatColors = ChatColors(id, null, color)
}
sealed class Id(val longValue: Long) : Parcelable {

View File

@@ -423,7 +423,8 @@ object SvrRepository {
false
}
newToken = newToken || if (Svr3Migration.shouldWriteToSvr2) {
newToken = newToken ||
if (Svr3Migration.shouldWriteToSvr2) {
val credentials: AuthCredentials = svr2.authorization()
SignalStore.svr.appendSvr2AuthTokenToList(credentials.asBasic())
} else {

View File

@@ -110,8 +110,7 @@ object RegistrationRepository {
/**
* Retrieve the FCM token from the Firebase service.
*/
suspend fun getFcmToken(context: Context): String? =
withContext(Dispatchers.Default) {
suspend fun getFcmToken(context: Context): String? = withContext(Dispatchers.Default) {
FcmUtil.getToken(context).orElse(null)
}
@@ -147,8 +146,7 @@ object RegistrationRepository {
* Queries, and creates if needed, the local profile key.
*/
@JvmStatic
suspend fun getProfileKey(e164: String): ProfileKey =
withContext(Dispatchers.IO) {
suspend fun getProfileKey(e164: String): ProfileKey = withContext(Dispatchers.IO) {
// TODO [regv2]: make creation more explicit instead of hiding it in this getter
val recipientTable = SignalDatabase.recipients
val recipient = recipientTable.getByE164(e164)
@@ -168,8 +166,7 @@ object RegistrationRepository {
* Takes a server response from a successful registration and persists the relevant data.
*/
@JvmStatic
suspend fun registerAccountLocally(context: Context, data: LocalRegistrationMetadata) =
withContext(Dispatchers.IO) {
suspend fun registerAccountLocally(context: Context, data: LocalRegistrationMetadata) = withContext(Dispatchers.IO) {
Log.v(TAG, "registerAccountLocally()")
if (data.linkedDeviceInfo != null) {
SignalStore.account.deviceId = data.linkedDeviceInfo.deviceId
@@ -299,8 +296,7 @@ object RegistrationRepository {
return PinHashUtil.verifyLocalPinHash(pinHash, pin)
}
suspend fun fetchMasterKeyFromSvrRemote(pin: String, svr2Credentials: AuthCredentials?, svr3Credentials: Svr3Credentials?): MasterKey =
withContext(Dispatchers.IO) {
suspend fun fetchMasterKeyFromSvrRemote(pin: String, svr2Credentials: AuthCredentials?, svr3Credentials: Svr3Credentials?): MasterKey = withContext(Dispatchers.IO) {
val credentialSet = SvrAuthCredentialSet(svr2Credentials = svr2Credentials, svr3Credentials = svr3Credentials)
val masterKey = SvrRepository.restoreMasterKeyPreRegistration(credentialSet, pin)
return@withContext masterKey
@@ -309,8 +305,7 @@ object RegistrationRepository {
/**
* Validates a session ID.
*/
private suspend fun validateSession(context: Context, sessionId: String, e164: String, password: String): RegistrationSessionCheckResult =
withContext(Dispatchers.IO) {
private suspend fun validateSession(context: Context, sessionId: String, e164: String, password: String): RegistrationSessionCheckResult = withContext(Dispatchers.IO) {
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password).registrationApi
Log.d(TAG, "Validating registration session with service.")
val registrationSessionResult = api.getRegistrationSessionStatus(sessionId)
@@ -320,8 +315,7 @@ object RegistrationRepository {
/**
* Initiates a new registration session on the service.
*/
suspend fun createSession(context: Context, e164: String, password: String, mcc: String?, mnc: String?): RegistrationSessionCreationResult =
withContext(Dispatchers.IO) {
suspend fun createSession(context: Context, e164: String, password: String, mcc: String?, mnc: String?): RegistrationSessionCreationResult = withContext(Dispatchers.IO) {
Log.d(TAG, "About to create a registration session…")
val fcmToken: String? = FcmUtil.getToken(context).orElse(null)
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password).registrationApi
@@ -379,8 +373,7 @@ object RegistrationRepository {
/**
* Asks the service to send a verification code through one of our supported channels (SMS, phone call).
*/
suspend fun requestSmsCode(context: Context, sessionId: String, e164: String, password: String, mode: E164VerificationMode): VerificationCodeRequestResult =
withContext(Dispatchers.IO) {
suspend fun requestSmsCode(context: Context, sessionId: String, e164: String, password: String, mode: E164VerificationMode): VerificationCodeRequestResult = withContext(Dispatchers.IO) {
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password).registrationApi
val codeRequestResult = api.requestSmsVerificationCode(sessionId, Locale.getDefault(), mode.isSmsRetrieverSupported, mode.transport)
@@ -391,8 +384,7 @@ object RegistrationRepository {
/**
* Submits the user-entered verification code to the service.
*/
suspend fun submitVerificationCode(context: Context, sessionId: String, registrationData: RegistrationData): VerificationCodeRequestResult =
withContext(Dispatchers.IO) {
suspend fun submitVerificationCode(context: Context, sessionId: String, registrationData: RegistrationData): VerificationCodeRequestResult = withContext(Dispatchers.IO) {
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, registrationData.e164, SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.password).registrationApi
val result = api.verifyAccount(sessionId = sessionId, verificationCode = registrationData.code)
return@withContext VerificationCodeRequestResult.from(result)
@@ -401,15 +393,13 @@ object RegistrationRepository {
/**
* Submits the solved captcha token to the service.
*/
suspend fun submitCaptchaToken(context: Context, e164: String, password: String, sessionId: String, captchaToken: String): VerificationCodeRequestResult =
withContext(Dispatchers.IO) {
suspend fun submitCaptchaToken(context: Context, e164: String, password: String, sessionId: String, captchaToken: String): VerificationCodeRequestResult = withContext(Dispatchers.IO) {
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password).registrationApi
val captchaSubmissionResult = api.submitCaptchaToken(sessionId = sessionId, captchaToken = captchaToken)
return@withContext VerificationCodeRequestResult.from(captchaSubmissionResult)
}
suspend fun requestAndVerifyPushToken(context: Context, sessionId: String, e164: String, password: String) =
withContext(Dispatchers.IO) {
suspend fun requestAndVerifyPushToken(context: Context, sessionId: String, e164: String, password: String) = withContext(Dispatchers.IO) {
val fcmToken = getFcmToken(context)
val accountManager = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password)
val pushChallenge = PushChallengeRequest.getPushChallengeBlocking(accountManager, sessionId, Optional.ofNullable(fcmToken), PUSH_REQUEST_TIMEOUT).orElse(null)
@@ -420,8 +410,7 @@ object RegistrationRepository {
/**
* Submit the necessary assets as a verified account so that the user can actually use the service.
*/
suspend fun registerAccount(context: Context, sessionId: String?, registrationData: RegistrationData, pin: String? = null, masterKeyProducer: MasterKeyProducer? = null): RegisterAccountResult =
withContext(Dispatchers.IO) {
suspend fun registerAccount(context: Context, sessionId: String?, registrationData: RegistrationData, pin: String? = null, masterKeyProducer: MasterKeyProducer? = null): RegisterAccountResult = withContext(Dispatchers.IO) {
Log.v(TAG, "registerAccount()")
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, registrationData.e164, SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.password).registrationApi
@@ -539,8 +528,7 @@ object RegistrationRepository {
}
}
private suspend fun createSessionAndBlockForPushChallenge(accountManager: RegistrationApi, fcmToken: String, mcc: String?, mnc: String?): NetworkResult<RegistrationSessionMetadataResponse> =
withContext(Dispatchers.IO) {
private suspend fun createSessionAndBlockForPushChallenge(accountManager: RegistrationApi, fcmToken: String, mcc: String?, mnc: String?): NetworkResult<RegistrationSessionMetadataResponse> = withContext(Dispatchers.IO) {
// TODO [regv2]: do not use event bus nor latch
val subscriber = PushTokenChallengeSubscriber()
val eventBus = EventBus.getDefault()
@@ -575,8 +563,7 @@ object RegistrationRepository {
}
}
suspend fun hasValidSvrAuthCredentials(context: Context, e164: String, password: String): BackupAuthCheckResult =
withContext(Dispatchers.IO) {
suspend fun hasValidSvrAuthCredentials(context: Context, e164: String, password: String): BackupAuthCheckResult = withContext(Dispatchers.IO) {
val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password).registrationApi
val svr3Result = SignalStore.svr.svr3AuthTokens

View File

@@ -102,7 +102,9 @@ class ContactRecordProcessor(
if (!hasAci && !hasPni) {
Log.w(TAG, "Found a ContactRecord with neither an ACI nor a PNI -- marking as invalid.")
return true
} else if (selfAci != null && selfAci == remote.proto.signalAci ||
} else if (
selfAci != null &&
selfAci == remote.proto.signalAci ||
(selfPni != null && selfPni == remote.proto.signalPni) ||
(selfE164 != null && remote.proto.e164.isNotBlank() && remote.proto.e164 == selfE164)
) {

View File

@@ -309,7 +309,8 @@ class FullSignalAudioManager(context: Context, eventListener: EventListener?) :
}
val needBluetoothAudioStart = signalBluetoothManager.state == SignalBluetoothManager.State.AVAILABLE &&
(userSelectedAudioDevice == AudioDevice.NONE || userSelectedAudioDevice == AudioDevice.BLUETOOTH || autoSwitchToBluetooth) && !androidAudioManager.isBluetoothScoOn
(userSelectedAudioDevice == AudioDevice.NONE || userSelectedAudioDevice == AudioDevice.BLUETOOTH || autoSwitchToBluetooth) &&
!androidAudioManager.isBluetoothScoOn
val needBluetoothAudioStop = (signalBluetoothManager.state == SignalBluetoothManager.State.CONNECTED || signalBluetoothManager.state == SignalBluetoothManager.State.CONNECTING) &&
(userSelectedAudioDevice != AudioDevice.NONE && userSelectedAudioDevice != AudioDevice.BLUETOOTH)

View File

@@ -171,8 +171,7 @@ class EmojiJsonParserTest {
private fun uriFactory(sprite: String, format: String) = Uri.parse("file:///$sprite")
private fun EmojiPageModel.isSameAs(other: EmojiPageModel) =
this.javaClass == other.javaClass &&
private fun EmojiPageModel.isSameAs(other: EmojiPageModel) = this.javaClass == other.javaClass &&
this.emoji == other.emoji &&
this.iconAttr == other.iconAttr &&
this.spriteUri == other.spriteUri

View File

@@ -14,6 +14,5 @@ class GiphyMp4PlaybackControllerRangeComparatorTest {
Assert.assertArrayEquals(expected, sorted)
}
private fun createComparator(start: Int, end: Int): GiphyMp4PlaybackController.RangeComparator =
GiphyMp4PlaybackController.RangeComparator(start, end)
private fun createComparator(start: Int, end: Int): GiphyMp4PlaybackController.RangeComparator = GiphyMp4PlaybackController.RangeComparator(start, end)
}

View File

@@ -3,5 +3,5 @@ plugins {
}
ktlint {
version.set("1.2.1")
version.set("1.5.0")
}

View File

@@ -21,7 +21,7 @@ kotlin {
// NOTE: For now, in order to run ktlint on this project, you have to manually run ./gradlew :build-logic:tools:ktlintFormat
// Gotta figure out how to get it auto-included in the normal ./gradlew ktlintFormat
ktlint {
version.set("1.2.1")
version.set("1.5.0")
}
dependencies {

View File

@@ -39,8 +39,7 @@ object IconButtons {
disabledContainerColor: Color = Color.Transparent,
disabledContentColor: Color =
contentColor.copy(alpha = 0.38f)
): IconButtonColors =
IconButtonColors(
): IconButtonColors = IconButtonColors(
containerColor = containerColor,
contentColor = contentColor,
disabledContainerColor = disabledContainerColor,
@@ -56,8 +55,7 @@ object IconButtons {
contentColor.copy(alpha = 0.38f),
checkedContainerColor: Color = Color.Transparent,
checkedContentColor: Color = MaterialTheme.colorScheme.primary
): IconToggleButtonColors =
IconToggleButtonColors(
): IconToggleButtonColors = IconToggleButtonColors(
containerColor = containerColor,
contentColor = contentColor,
disabledContainerColor = disabledContainerColor,

View File

@@ -127,5 +127,4 @@ suspend fun AwaitPointerEventScope.awaitLongPressOrCancellation(
}
}
private fun PointerEvent.isPointerUp(pointerId: PointerId): Boolean =
changes.fastFirstOrNull { it.id == pointerId }?.pressed != true
private fun PointerEvent.isPointerUp(pointerId: PointerId): Boolean = changes.fastFirstOrNull { it.id == pointerId }?.pressed != true

View File

@@ -62,8 +62,7 @@ class ResultEventBus {
/**
* Provides a flow for the given resultKey.
*/
inline fun <reified T> getResultFlow(resultKey: String = T::class.toString()) =
channelMap[resultKey]?.receiveAsFlow()
inline fun <reified T> getResultFlow(resultKey: String = T::class.toString()) = channelMap[resultKey]?.receiveAsFlow()
/**
* Sends a result into the channel associated with the given resultKey.

View File

@@ -72,7 +72,8 @@ fun setupWebView(
webview.evaluateJavascript("editor.setValue($originalContent, -1);", null)
}
copyButton.setOnClickListener { // In Signal app, use Util.writeTextToClipboard(context, value) instead
copyButton.setOnClickListener {
// In Signal app, use Util.writeTextToClipboard(context, value) instead
webview.evaluateJavascript("editor.getValue();") { value ->
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(context.getString(R.string.app_name), value)

View File

@@ -22,7 +22,7 @@ accompanist = "0.28.0"
nanohttpd = "2.3.1"
navigation-safe-args-gradle-plugin = "2.8.5"
protobuf-gradle-plugin = "0.9.0"
ktlint = "12.1.1"
ktlint = "14.0.1"
ui-test-junit4 = "1.9.4"
[plugins]

File diff suppressed because it is too large Load Diff

View File

@@ -69,7 +69,7 @@ afterEvaluate {
}
ktlint {
version.set("1.2.1")
version.set("1.5.0")
filter {
exclude { entry ->