Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove desugaring #62

Merged
merged 9 commits into from
May 20, 2024
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
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[versions]
sentinel = "1.3.3-alpha01"
gradle = "8.3.2"
desugar = "2.0.4"
kotlin = "1.9.22"
coroutines = "1.8.0"
json = "1.5.1"
Expand Down Expand Up @@ -46,8 +45,6 @@ tooltimber = { module = "com.infinum.sentinel:tool-timber", version.ref = "senti

tools-gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }

desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }

kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-core = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
Expand Down
5 changes: 0 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,13 @@ android {
}
}

compileOptions {
coreLibraryDesugaringEnabled true
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
release.java.srcDirs += "src/release/kotlin"
}
}

dependencies {
coreLibraryDesugaring libs.desugar
implementation libs.kotlin.core
implementation libs.androidx.appcompat
implementation libs.androidx.preference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.infinum.sentinel.sample;

import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -34,7 +35,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tools.add(new GooglePlayTool());
tools.add(new ThimbleTool());
tools.add(new TimberTool());
tools.add(new CertificateTool());
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
tools.add(new CertificateTool());
}
Sentinel.watch(tools);

viewBinding.showSentinel.setOnClickListener(v -> Sentinel.show());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.infinum.sentinel.sample

import android.app.Application
import android.os.Build
import com.infinum.sentinel.Sentinel
import com.infinum.sentinel.ui.tools.AppGalleryTool
import com.infinum.sentinel.ui.tools.CertificateTool
Expand All @@ -19,19 +20,23 @@ class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()

Sentinel.watch(
setOf(
ChuckerTool(),
CollarTool(),
DbInspectorTool(),
LeakCanaryTool(),
AppGalleryTool(appId = "102016595"),
GooglePlayTool(),
ThimbleTool(),
TimberTool(allowedTags = listOf("Main")),
CertificateTool(userCertificates = loadDebugCertificates())
)
)
Sentinel.watch(getWatchedTools())
}

private fun getWatchedTools(): Set<Sentinel.Tool> {
val tools = mutableSetOf<Sentinel.Tool>()
tools.add(ChuckerTool())
tools.add(CollarTool())
tools.add(DbInspectorTool())
tools.add(LeakCanaryTool())
tools.add(AppGalleryTool(appId = "102016595"))
tools.add(GooglePlayTool())
tools.add(ThimbleTool())
tools.add(TimberTool(allowedTags = listOf("Main")))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tools.add(CertificateTool(userCertificates = loadDebugCertificates()))
}
return tools
}

private fun loadDebugCertificates(): List<X509Certificate> {
Expand Down
2 changes: 0 additions & 2 deletions sentinel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ android {
disable "RtlEnabled", "VectorPath"
}
compileOptions {
coreLibraryDesugaringEnabled true
}
kotlinOptions {
freeCompilerArgs += [
Expand Down Expand Up @@ -89,7 +88,6 @@ dokkaJavadoc {
}

dependencies {
coreLibraryDesugaring libs.desugar
implementation libs.kotlin.core
implementation libs.kotlin.json
implementation libs.coroutines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.infinum.sentinel.data.models.local
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.temporal.ChronoUnit
import com.infinum.sentinel.utils.ChronoUnit

@Entity(tableName = "certificate_monitor")
internal data class CertificateMonitorEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.infinum.sentinel.data.models.raw

import android.os.Build
import androidx.annotation.RequiresApi
import com.infinum.sentinel.data.models.raw.certificates.FingerprintData
import com.infinum.sentinel.data.models.raw.certificates.PublicKeyData
import com.infinum.sentinel.data.models.raw.certificates.SignatureData
Expand All @@ -9,6 +11,7 @@ import java.time.ZoneId
import java.time.temporal.ChronoUnit
import java.util.Date

@RequiresApi(Build.VERSION_CODES.O)
internal data class CertificateData(
val publicKey: PublicKeyData,
val serialNumber: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.infinum.sentinel.data.sources.raw.collectors

import android.os.Build
import com.infinum.sentinel.data.models.raw.CertificateData
import com.infinum.sentinel.data.models.raw.certificates.CertificateType
import com.infinum.sentinel.data.models.raw.certificates.FingerprintData
Expand Down Expand Up @@ -39,34 +40,37 @@ internal class CertificateCollector(
)

private fun asCertificateData(certificates: List<X509Certificate>): List<CertificateData> =
certificates.map {
CertificateData(
publicKey = PublicKeyData(
algorithm = it.publicKey.algorithm,
size = when (it.publicKey.algorithm) {
"RSA" -> (it.publicKey as RSAPublicKey).modulus.bitLength()
"DSA" -> (it.publicKey as DSAPublicKey).params.p.bitLength() // Or P or Q or G?
"EC" -> (it.publicKey as ECPublicKey).params.order.bitLength() // Or curve or cofactor?
else -> it.publicKey.encoded.size * DEFAULT_PUBLIC_KEY_SIZE_MULTIPLIER // wild guess
}
),
serialNumber = it.serialNumber.toString(SERIAL_NUMBER_RADIX),
version = it.version,
signature = SignatureData(
algorithmName = it.sigAlgName,
algorithmOID = it.sigAlgOID
),
issuerData = it.issuerDN.name.asASN(),
subjectData = it.subjectDN.name.asASN(),
startDate = it.notBefore,
endDate = it.notAfter,
fingerprint = FingerprintData(
md5 = fingerprint(it, "MD5")?.lowercase(),
sha1 = fingerprint(it, "SHA1")?.lowercase(),
sha256 = fingerprint(it, "SHA-256")?.lowercase()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) emptyList()
else {
certificates.map {
CertificateData(
publicKey = PublicKeyData(
algorithm = it.publicKey.algorithm,
size = when (it.publicKey.algorithm) {
"RSA" -> (it.publicKey as RSAPublicKey).modulus.bitLength()
"DSA" -> (it.publicKey as DSAPublicKey).params.p.bitLength() // Or P or Q or G?
"EC" -> (it.publicKey as ECPublicKey).params.order.bitLength() // Or curve or cofactor?
else -> it.publicKey.encoded.size * DEFAULT_PUBLIC_KEY_SIZE_MULTIPLIER // wild guess
}
),
serialNumber = it.serialNumber.toString(SERIAL_NUMBER_RADIX),
version = it.version,
signature = SignatureData(
algorithmName = it.sigAlgName,
algorithmOID = it.sigAlgOID
),
issuerData = it.issuerDN.name.asASN(),
subjectData = it.subjectDN.name.asASN(),
startDate = it.notBefore,
endDate = it.notAfter,
fingerprint = FingerprintData(
md5 = fingerprint(it, "MD5")?.lowercase(),
sha1 = fingerprint(it, "SHA1")?.lowercase(),
sha256 = fingerprint(it, "SHA-256")?.lowercase()
)
)
)
}.toList().sortedBy { it.title?.lowercase() }
}.toList().sortedBy { it.title?.lowercase() }
}

@Throws(
NoSuchAlgorithmException::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.infinum.sentinel.di.component
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Build
import android.text.format.Formatter
import com.google.android.material.snackbar.Snackbar
import com.infinum.sentinel.R
Expand Down Expand Up @@ -255,6 +256,7 @@ internal abstract class DomainComponent(
}

private fun initializeCertificateMonitor() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
scope.launch {
withContext(Dispatchers.IO) {
val monitorEntity = certificateMonitor.load(CertificateMonitorParameters()).first()
Expand Down Expand Up @@ -339,22 +341,27 @@ internal abstract class DomainComponent(
context.enableShakeTrigger()?.let {
entity.enabled = it
}

TriggerType.FOREGROUND ->
context.enableForegroundTrigger()?.let {
entity.enabled = it
}

TriggerType.PROXIMITY ->
context.enableProximityTrigger()?.let {
entity.enabled = it
}

TriggerType.USB_CONNECTED ->
context.enableUsbConnectedTrigger()?.let {
entity.enabled = it
}

TriggerType.AIRPLANE_MODE_ON ->
context.enableAirplaneModeOnTrigger()?.let {
entity.enabled = it
}

else -> null
}?.let {
triggers.save(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.infinum.sentinel.extensions

import android.os.Build
import androidx.annotation.RequiresApi
import java.time.temporal.ChronoUnit

@RequiresApi(Build.VERSION_CODES.O)
@Suppress("CyclomaticComplexMethod")
internal fun ChronoUnit.toSentinelChronoUnit(): com.infinum.sentinel.utils.ChronoUnit =
when (this) {
ChronoUnit.NANOS -> com.infinum.sentinel.utils.ChronoUnit.NANOS
ChronoUnit.MICROS -> com.infinum.sentinel.utils.ChronoUnit.MICROS
ChronoUnit.MILLIS -> com.infinum.sentinel.utils.ChronoUnit.MILLIS
ChronoUnit.SECONDS -> com.infinum.sentinel.utils.ChronoUnit.SECONDS
ChronoUnit.MINUTES -> com.infinum.sentinel.utils.ChronoUnit.MINUTES
ChronoUnit.HOURS -> com.infinum.sentinel.utils.ChronoUnit.HOURS
ChronoUnit.HALF_DAYS -> com.infinum.sentinel.utils.ChronoUnit.HALF_DAYS
ChronoUnit.DAYS -> com.infinum.sentinel.utils.ChronoUnit.DAYS
ChronoUnit.WEEKS -> com.infinum.sentinel.utils.ChronoUnit.WEEKS
ChronoUnit.MONTHS -> com.infinum.sentinel.utils.ChronoUnit.MONTHS
ChronoUnit.YEARS -> com.infinum.sentinel.utils.ChronoUnit.YEARS
ChronoUnit.DECADES -> com.infinum.sentinel.utils.ChronoUnit.DECADES
ChronoUnit.CENTURIES -> com.infinum.sentinel.utils.ChronoUnit.CENTURIES
ChronoUnit.MILLENNIA -> com.infinum.sentinel.utils.ChronoUnit.MILLENNIA
ChronoUnit.ERAS -> com.infinum.sentinel.utils.ChronoUnit.ERAS
ChronoUnit.FOREVER -> com.infinum.sentinel.utils.ChronoUnit.FOREVER
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.infinum.sentinel.ui.certificates

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.infinum.sentinel.R
import com.infinum.sentinel.data.models.local.CertificateMonitorEntity
import com.infinum.sentinel.data.models.raw.CertificateData
import com.infinum.sentinel.databinding.SentinelItemCertificateBinding
import com.infinum.sentinel.utils.toJavaChronoUnit
import java.time.temporal.ChronoUnit

@RequiresApi(Build.VERSION_CODES.O)
internal class CertificateViewHolder(
private val binding: SentinelItemCertificateBinding
) : RecyclerView.ViewHolder(binding.root) {
Expand All @@ -24,7 +28,7 @@ internal class CertificateViewHolder(
if (
certificate.isValidIn(
settings?.expireInAmount ?: 0,
settings?.expireInUnit ?: ChronoUnit.DAYS
settings?.expireInUnit?.toJavaChronoUnit() ?: ChronoUnit.DAYS
)
) {
R.color.sentinel_primary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.infinum.sentinel.ui.certificates

import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.annotation.RestrictTo
import com.infinum.sentinel.ui.shared.base.BaseChildActivity

@RestrictTo(RestrictTo.Scope.LIBRARY)
@RequiresApi(Build.VERSION_CODES.O)
internal class CertificatesActivity : BaseChildActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.infinum.sentinel.ui.certificates

import android.os.Build
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.ListAdapter
import com.infinum.sentinel.data.models.local.CertificateMonitorEntity
import com.infinum.sentinel.data.models.raw.CertificateData
import com.infinum.sentinel.databinding.SentinelItemCertificateBinding

@RequiresApi(Build.VERSION_CODES.O)
internal class CertificatesAdapter(
private val onListChanged: () -> Unit,
private val onClick: (CertificateData) -> Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.infinum.sentinel.ui.certificates

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.annotation.RequiresApi
import androidx.annotation.RestrictTo
import androidx.core.view.isGone
import androidx.core.view.isVisible
Expand All @@ -18,6 +20,7 @@ import com.infinum.sentinel.ui.shared.delegates.viewBinding
import com.infinum.sentinel.ui.shared.edgefactories.bounce.BounceEdgeEffectFactory

@RestrictTo(RestrictTo.Scope.LIBRARY)
@RequiresApi(Build.VERSION_CODES.O)
internal class CertificatesFragment :
BaseChildFragment<CertificatesState, CertificatesEvent>(R.layout.sentinel_fragment_certificates) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.infinum.sentinel.ui.certificates.details

import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.annotation.RestrictTo
import com.infinum.sentinel.ui.shared.base.BaseChildActivity

@RestrictTo(RestrictTo.Scope.LIBRARY)
@RequiresApi(Build.VERSION_CODES.O)
internal class CertificateDetailsActivity : BaseChildActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Loading
Loading