18 Commits
Author SHA1 Message Date
kalarina c331c317ce Read the saved list state without a default for old versions 2026-10-31 12:00:29 +02:00
kalarina 8f4cd6d7f2 Drop migration of data from old versions 2026-10-31 11:59:09 +02:00
kalarina c929a827c5 Test that unchanged logs and statistics are reused 2026-10-31 11:50:14 +02:00
kalarina caf498d783 Read animated colors and offsets when drawing 2026-10-31 11:50:14 +02:00
kalarina 87723f0a8f Cache chart geometry, labels and date formats 2026-10-31 11:50:14 +02:00
kalarina e3f5906924 Rebuild the Activity log only when it changed 2026-10-31 11:50:14 +02:00
kalarina d58e9cb5f9 Keep storage and image decoding off the main thread at start-up 2026-10-31 11:50:13 +02:00
kalarina 6444a81f95 Encode statistics on the writer thread and read them outside the lock 2026-10-31 11:40:43 +02:00
kalarina 60c43df3c5 Cut allocations on the path of every DNS query 2026-10-31 11:37:55 +02:00
kalarina 3d45f54360 Wake the tunnel reader only for packets and on stop 2026-10-31 11:35:22 +02:00
kalarina d583b73d74 Leave unused library files out of the APK 2026-10-31 11:34:33 +02:00
kalarina b53aa34516 Share repeated UI pieces between screens 2026-10-31 11:34:07 +02:00
kalarina 6c26cb99a6 Remove the baseline profile script 2026-10-31 11:32:16 +02:00
kalarina 907c3aaa46 Use the built-in server list directly 2026-10-31 11:32:10 +02:00
kalarina ee430fa7c0 Remove an unused color and statistics reset 2026-10-31 11:32:10 +02:00
kalarina 509c0b9a86 Remove leftovers of the old Monitor screen 2026-10-31 11:31:49 +02:00
kalarina 03ee32b8b0 Fix missing imports in Activity screen 2026-10-31 10:50:56 +02:00
kalarina 343cbfadb6 Improve Home, Activity and tablet layout
- Content keeps a readable width on tablets; Home and Activity show two
  columns on wide screens
- Home chart: bars per hour or per day, a working 24 h / 7 d switch,
  a message instead of an empty chart, and more height on tall screens
- Company dominance waits for 50 requests and shows whole percents
- Home offers to turn on HaGeZi Pro when no list is on, or blocking
  when it is off
- Tapping the server on Home opens the server list; the ON/OFF switch
  gives haptic feedback
2026-10-31 10:18:57 +02:00
45 changed files with 91 additions and 393 deletions
-28
View File
@@ -1,28 +0,0 @@
---
name: Bug report
about: Something doesn't work as expected
title: "[Bug] "
---
**What happened**
**Steps to reproduce**
1.
2.
3.
**What you expected**
**Environment**
- App version:
- Installed from: Gitea / GitHub / F-Droid / Google Play
- Device and Android version:
- DoH server in use:
- Network: Wi-Fi / mobile data
**Screenshots or logs** (optional — please remove domains you don't want to share)
-5
View File
@@ -1,5 +0,0 @@
blank_issues_enabled: true
contact_links:
- name: Main repository on git.skysparkle.cc
url: https://git.skysparkle.cc/kalarina/Sparkledns
about: This GitHub repository is a mirror. Issues are welcome here and on Gitea.
@@ -1,15 +0,0 @@
---
name: DoH server or blocklist
about: Suggest a DoH server or blocklist preset
title: "[Preset] "
---
- Type: DoH server / blocklist
- Name:
- URL:
- Homepage or documentation:
- Privacy policy (DoH servers) or license (blocklists):
- Donation page (DoH servers, optional):
- [ ] DoH server: public and supports RFC 8484
- [ ] Blocklist: public and actively maintained
-18
View File
@@ -1,18 +0,0 @@
---
name: Feature request
about: Suggest an idea that fits the app
title: "[Feature] "
---
<!-- Please check the "Out of scope" list in CONTRIBUTING.md before opening this. -->
**What problem does this solve**
**Proposed solution**
**Alternatives you considered**
- [ ] I'd like to implement this myself
-12
View File
@@ -1,12 +0,0 @@
---
name: Translation fix
about: Report a wrong or awkward translation
title: "[Translation] "
---
<!-- Currently supported: English, Russian. For a new language, open a feature request first. -->
- Language:
- Screen or place in the app:
- Current text:
- Suggested text:
-17
View File
@@ -1,17 +0,0 @@
## What does this change
## Related issue
Closes #
## Checklist
- [ ] Discussed in an issue first (not needed for small fixes)
- [ ] `./gradlew assembleDebug` builds
- [ ] Tested on a device or emulator (Android version: )
- [ ] DNS queries only go to the selected DoH server
- [ ] No ads, analytics, trackers or Google Play Services / Firebase dependencies
- [ ] New strings added to `values/strings.xml` (missing translations noted below)
- [ ] Screenshots added for UI changes
- [ ] I agree that my contribution is licensed under GPL-3.0-or-later
+3 -8
View File
@@ -9,12 +9,6 @@
A local VPN that captures only DNS traffic and sends every query to the DoH server you choose (RFC 8484). Everything else goes through your normal connection.
</p>
> [!IMPORTANT]
> **SparkleDNS is coming to Google Play!** The app is now in closed testing there ahead of the public release. Ideas, wishes and suggestions for improvement are very welcome — send them wherever is easiest for you: an issue on [Gitea](https://git.skysparkle.cc/kalarina/Sparkledns/issues) or [GitHub](https://github.com/kalarina-bit/Sparkledns/issues), or an email to [cuken107@proton.me](mailto:cuken107@proton.me).
> [!NOTE]
> **Looking for designers!** SparkleDNS is looking for volunteer designers to help with icons, logos, animations, cover art (store graphics) and UI design. This is unpaid help for an open-source project. If you're interested, write to [cuken107@proton.me](mailto:cuken107@proton.me).
<p align="center">
<a href="https://github.com/kalarina-bit/Sparkledns/releases/latest"><img src="https://img.shields.io/github/v/release/kalarina-bit/Sparkledns?style=for-the-badge&label=release&labelColor=1b1b1b&color=2e7d32" alt="Latest release"></a>
</p>
@@ -27,9 +21,10 @@
</p>
<p align="center">
<img src="assets/screenshots/1-private-dns-left.png" width="160" alt="Private DNS in one tap"><img src="assets/screenshots/2-private-dns-right.png" width="160" alt="You're protected">
<img src="assets/screenshots/1-private-dns-control.png" width="160" alt="Private DNS control">
<img src="assets/screenshots/2-protected.png" width="160" alt="You're protected">
<img src="assets/screenshots/3-see-every-request.png" width="160" alt="See every request">
<img src="assets/screenshots/4-block-ads-and-trackers.png" width="160" alt="Block ads and trackers">
<img src="assets/screenshots/4-block-more-noise.png" width="160" alt="Block more noise">
</p>
> [!TIP]
+2 -2
View File
@@ -13,8 +13,8 @@ android {
targetSdk = 36
// Single source of truth: the About screen reads these through BuildConfig.
// Kept as plain literals so F-Droid can detect new versions. Code = major * 10000 + minor * 100 + patch.
versionCode = 10103
versionName = "1.1.3"
versionCode = 10101
versionName = "1.1.1"
}
buildTypes {
@@ -81,28 +81,6 @@ private val OtherColor = Palette.Track
private class Slice(val label: String, val share: Float, val color: Color)
// One row of the log: every query for a domain, shown by its newest one. A data class, so a
// rebuilt list with the same groups counts as unchanged.
private data class DomainGroup(val latest: QueryEntry, val types: List<Int>, val count: Int)
// The log is newest first, so the first entry of a domain is its newest one and the groups come
// out in the order their domains were last asked for. Names differ only in letter case when a
// resolver randomizes it, so they are compared in lower case.
private fun groupByDomain(entries: List<QueryEntry>): List<DomainGroup> {
class Builder(val latest: QueryEntry) {
val types = LinkedHashSet<Int>()
var count = 0
}
val groups = LinkedHashMap<String, Builder>()
for (entry in entries) {
val group = groups.getOrPut(entry.domain.lowercase(Locale.ROOT)) { Builder(entry) }
group.types += entry.type
group.count++
}
// Types in numeric order: A, then AAAA, then HTTPS
return groups.values.map { DomainGroup(it.latest, it.types.sorted(), it.count) }
}
@Composable
fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
val context = LocalContext.current
@@ -123,13 +101,12 @@ fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
val statsVersion by StatsStore.version.collectAsStateWithLifecycle()
LaunchedEffect(period, statsVersion) { summary = StatsStore.summary(period.hours) }
// Filtered and grouped by domain again only when the log, the filter or the search changes,
// and the list below is updated only when the result differs: new entries that the filter
// hides change nothing
// Filtered again only when the log, the filter or the search changes, and the list below is
// updated only when the result differs: new entries that the filter hides change nothing
val visible by remember {
derivedStateOf(structuralEqualityPolicy()) {
val term = search.trim()
val matching = entries.filter { e ->
entries.filter { e ->
val matchesFilter = when (filter) {
ActivityFilter.ALL -> true
ActivityFilter.BLOCKED -> e.status == QueryStatus.BLOCKED
@@ -138,7 +115,6 @@ fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
}
matchesFilter && (term.isEmpty() || e.domain.contains(term, ignoreCase = true))
}
groupByDomain(matching)
}
}
val canClear by remember { derivedStateOf { entries.isNotEmpty() } }
@@ -202,19 +178,11 @@ fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
)
}
}
// Keyed by domain, so a new query for a domain moves its row to the top instead of adding one
itemsIndexed(
visible,
key = { _, group -> "domain:" + group.latest.domain.lowercase(Locale.ROOT) },
contentType = { _, _ -> "query" },
) { index, group ->
val entry = group.latest
itemsIndexed(visible, key = { _, entry -> entry.id }, contentType = { _, _ -> "query" }) { index, entry ->
val blockedByMe = entry.domain in customSet
QueryRow(
modifier = Modifier.animateItem(),
entry = entry,
types = group.types,
count = group.count,
first = index == 0,
blockedByMe = blockedByMe,
onBlock = { toggleBlock(entry.domain, unblock = false) },
@@ -238,7 +206,7 @@ fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
) {
ActivityHeader(period) { period = it }
ActivityStats(summary, Modifier.padding(top = 20.dp))
CompanyCard(summary, entries, Modifier.padding(top = 20.dp))
CompanyCard(summary, Modifier.padding(top = 20.dp))
}
LazyColumn(
modifier = Modifier
@@ -255,7 +223,7 @@ fun ActivityScreen(bottomPadding: Dp, modifier: Modifier = Modifier) {
) {
item(key = "header") { ActivityHeader(period) { period = it } }
item(key = "stats") { ActivityStats(summary, Modifier.padding(top = 20.dp)) }
item(key = "companies") { CompanyCard(summary, entries, Modifier.padding(top = 20.dp)) }
item(key = "companies") { CompanyCard(summary, Modifier.padding(top = 20.dp)) }
log()
}
}
@@ -366,9 +334,9 @@ private fun LogSearch(
private const val MIN_COMPANY_REQUESTS = 50L
@Composable
private fun CompanyCard(summary: StatsSummary, recent: List<QueryEntry>, modifier: Modifier = Modifier) {
private fun CompanyCard(summary: StatsSummary, modifier: Modifier = Modifier) {
val other = stringResource(R.string.companies_other)
val slices = remember(summary, recent, other) { companySlices(summary, recent, other) }
val slices = remember(summary, other) { companySlices(summary, other) }
Column(
modifier = modifier
.fillMaxWidth()
@@ -430,32 +398,17 @@ private fun percentLabel(share: Float): String {
return if (percent < 1f) "<1%" else "${Math.round(percent)}%"
}
// Shares of the known companies over the period. The statistics keep no domains, so the share
// left over is split by the names of the recent queries to other domains, from the log in memory.
// Then the four largest slices and everything else; empty slices are left out.
private fun companySlices(summary: StatsSummary, recent: List<QueryEntry>, otherLabel: String): List<Slice> {
// The four companies with most requests, then everything else; empty slices are left out
private fun companySlices(summary: StatsSummary, otherLabel: String): List<Slice> {
if (summary.total == 0L) return emptyList()
val shares = HashMap<String, Float>()
for (company in Company.entries) {
val count = summary.companies[company.ordinal]
if (count > 0) shares[company.label] = count.toFloat() / summary.total
}
val unknownShare = (1f - shares.values.sum()).coerceAtLeast(0f)
val names = HashMap<String, Int>()
var unknownCount = 0
for (entry in recent) {
if (Companies.of(entry.domain) != null) continue
unknownCount++
Companies.nameOf(entry.domain)?.let { names.merge(it, 1, Int::plus) }
}
// Queries without a name (local names, reverse lookups) stay in the rest
if (unknownCount > 0) {
for ((name, count) in names) shares.merge(name, unknownShare * count / unknownCount, Float::plus)
}
val slices = shares.entries
.sortedByDescending { it.value }
val top = Company.entries
.map { it to summary.companies[it.ordinal] }
.filter { it.second > 0 }
.sortedByDescending { it.second }
.take(SliceColors.size)
.mapIndexed { index, (label, share) -> Slice(label, share, SliceColors[index]) }
val slices = top.mapIndexed { index, (company, count) ->
Slice(company.label, count.toFloat() / summary.total, SliceColors[index])
}
val rest = (1f - slices.sumOf { it.share.toDouble() }.toFloat()).coerceAtLeast(0f)
return if (rest >= 0.005f) slices + Slice(otherLabel, rest, OtherColor) else slices
}
@@ -489,8 +442,6 @@ private fun Donut(slices: List<Slice>, modifier: Modifier = Modifier) {
private fun QueryRow(
modifier: Modifier,
entry: QueryEntry,
types: List<Int>,
count: Int,
first: Boolean,
blockedByMe: Boolean,
onBlock: () -> Unit,
@@ -510,9 +461,6 @@ private fun QueryRow(
QueryStatus.BLOCKED -> stringResource(if (blockedByMe) R.string.bl_my else R.string.tab_blocklist)
QueryStatus.FAILED -> stringResource(R.string.status_failed)
}
// "A, AAAA, HTTPS · ×3 · 256 ms"; the status and time are those of the newest query
val typeNames = types.joinToString(", ") { DnsMessage.typeName(it) }
val summary = if (count > 1) "$typeNames · ×$count · $detail" else "$typeNames · $detail"
Box(modifier.fillMaxWidth()) {
Column {
@@ -544,7 +492,7 @@ private fun QueryRow(
overflow = TextOverflow.Ellipsis,
)
Text(
summary,
"${DnsMessage.typeName(entry.type)} · $detail",
color = Palette.Fg3,
fontSize = 12.sp,
maxLines = 1,
@@ -49,18 +49,14 @@ object AutoUpdate {
class BlocklistUpdateJob : JobService() {
override fun onStartJob(params: JobParameters): Boolean {
Thread({
// A failed download is retried later with the system's back-off
val retry = try {
!Blocklist.updateAllNow(applicationContext)
val ok = try {
Blocklist.updateAllNow(applicationContext)
} catch (e: Exception) {
Log.w("SparkleDNS", "Blocklist update failed", e)
true
} catch (e: OutOfMemoryError) {
// Must not take the VPN down with it; retrying would only run out of memory again
Log.e("SparkleDNS", "Blocklist update ran out of memory", e)
false
}
jobFinished(params, retry)
// A failed run is retried later with the system's back-off
jobFinished(params, !ok)
}, "blocklist-update").start()
return true
}
@@ -20,7 +20,6 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.nio.LongBuffer
import java.nio.channels.FileChannel
import java.security.MessageDigest
import java.util.concurrent.TimeUnit
@@ -29,8 +28,7 @@ import java.util.concurrent.TimeUnit
data class RemoteList(val url: String, val count: Int, val updated: Long, val enabled: Boolean = true)
// Blocks a domain together with all its subdomains. Changes apply instantly, no reconnect needed.
// Domains are kept as sorted 64-bit hashes in files that are memory-mapped, not read into the heap:
// lists with millions of entries cost page cache, not app memory, so low-end phones cope too.
// Domains are kept as sorted 64-bit hashes: about 8 bytes per entry, so million-entry lists fit easily.
object Blocklist {
const val ALL_LISTS = "*"
@@ -62,7 +60,7 @@ object Blocklist {
// Downloaded lists and own domains are kept apart, so editing a few own domains
// does not rebuild a set that can hold millions of entries
@Volatile
private var listHashes: LongBuffer = EMPTY_SET
private var listHashes = LongArray(0)
@Volatile
private var customHashes = LongArray(0)
@@ -225,12 +223,7 @@ object Blocklist {
}
private fun reloadListHashes(store: BlocklistStore) {
try {
listHashes = store.mergedHashes(_lists.value.filter { it.enabled })
} catch (e: IOException) {
// Out of storage: the lists in use stay active until the next change
Log.w("SparkleDNS", "Cannot merge blocklists", e)
}
listHashes = mergeSorted(_lists.value.filter { it.enabled }.map { store.loadListHashes(it.url) })
_total.value = unionSize(listHashes, customHashes)
}
@@ -243,13 +236,13 @@ object Blocklist {
// True when the name or one of its parent domains is in either sorted hash set. Runs for every
// query, so trailing dots are skipped by index rather than trimmed off a copy of the name.
internal fun isBlockedIn(name: String, lists: LongBuffer, custom: LongArray): Boolean {
if (lists.limit() == 0 && custom.isEmpty()) return false
internal fun isBlockedIn(name: String, lists: LongArray, custom: LongArray): Boolean {
if (lists.isEmpty() && custom.isEmpty()) return false
val end = nameEnd(name)
var start = 0
while (true) {
val hash = DomainHash.of(name, start, end)
if (lists.containsSorted(hash) || custom.binarySearch(hash) >= 0) return true
if (lists.binarySearch(hash) >= 0 || custom.binarySearch(hash) >= 0) return true
val dot = name.indexOf('.', start)
if (dot < 0 || dot >= end) return false
start = dot + 1
@@ -263,59 +256,37 @@ internal fun nameEnd(name: String): Int {
return end
}
internal val EMPTY_SET: LongBuffer = LongBuffer.wrap(LongArray(0))
// Binary search by absolute index, so several threads can read the same buffer at once
internal fun LongBuffer.containsSorted(value: Long): Boolean {
var low = 0
var high = limit() - 1
while (low <= high) {
val mid = (low + high) ushr 1
val v = get(mid)
when {
v < value -> low = mid + 1
v > value -> high = mid - 1
else -> return true
}
}
return false
}
// Number of distinct entries in both sorted sets; the custom set is small
internal fun unionSize(lists: LongBuffer, custom: LongArray): Int =
lists.limit() + custom.count { !lists.containsSorted(it) }
internal fun unionSize(lists: LongArray, custom: LongArray): Int =
lists.size + custom.count { lists.binarySearch(it) < 0 }
// Merges sorted, duplicate-free sets in one pass and hands each value to [emit] once, in order.
// Only the read positions are kept in memory, so inputs and output can be files of any size.
internal fun mergeSortedInto(parts: List<LongBuffer>, emit: (Long) -> Unit): Int {
val sets = parts.filter { it.limit() > 0 }
val pos = IntArray(sets.size)
var count = 0
while (true) {
var min = 0L
var found = false
for (i in sets.indices) {
if (pos[i] < sets[i].limit()) {
val v = sets[i].get(pos[i])
if (!found || v < min) {
min = v
found = true
}
}
}
if (!found) return count
for (i in sets.indices) if (pos[i] < sets[i].limit() && sets[i].get(pos[i]) == min) pos[i]++
emit(min)
count++
}
}
// In-memory variant for small sets; inputs that are not sorted yet are sorted first
// Merges sorted, duplicate-free arrays in linear time instead of sorting their concatenation
internal fun mergeSorted(parts: List<LongArray>): LongArray {
val sorted = parts.map { LongBuffer.wrap(if (it.isSortedUnique()) it else it.copyOf().sortUnique()) }
val out = LongList()
mergeSortedInto(sorted) { out.add(it) }
return out.toArray()
var arrays = parts.filter { it.isNotEmpty() }.map { if (it.isSortedUnique()) it else it.copyOf().sortUnique() }
if (arrays.isEmpty()) return LongArray(0)
while (arrays.size > 1) {
arrays = arrays.chunked(2).map { if (it.size == 2) mergeTwo(it[0], it[1]) else it[0] }
}
return arrays[0]
}
private fun mergeTwo(a: LongArray, b: LongArray): LongArray {
val out = LongArray(a.size + b.size)
var i = 0
var j = 0
var n = 0
while (i < a.size && j < b.size) {
val x = a[i]
val y = b[j]
when {
x < y -> { out[n++] = x; i++ }
x > y -> { out[n++] = y; j++ }
else -> { out[n++] = x; i++; j++ }
}
}
while (i < a.size) out[n++] = a[i++]
while (j < b.size) out[n++] = b[j++]
return if (n == out.size) out else out.copyOf(n)
}
private fun LongArray.isSortedUnique(): Boolean {
@@ -349,20 +320,6 @@ private class LongList {
}
fun toArray(): LongArray = data.copyOf(size)
// Sorts the filled part in place and drops duplicates, without copying; returns the new size
fun sortUnique(): Int {
if (size < 2) return size
java.util.Arrays.sort(data, 0, size)
var n = 1
for (i in 1 until size) if (data[i] != data[n - 1]) data[n++] = data[i]
size = n
return n
}
fun writeTo(out: DataOutputStream) {
for (i in 0 until size) out.writeLong(data[i])
}
}
// Sorts in place and drops duplicates
@@ -418,42 +375,17 @@ private class BlocklistStore(context: Context) {
sp.edit().putString("lists", array.toString()).commit()
}
fun loadListHashes(url: String): LongBuffer = map(binFile(url)) ?: EMPTY_SET
// One list is used as it is; several are merged into one file, which is reused at the next
// start as long as the switched-on lists have not changed
fun mergedHashes(lists: List<RemoteList>): LongBuffer {
if (lists.size < 2) {
mergedFile.delete()
return lists.firstOrNull()?.let { loadListHashes(it.url) } ?: EMPTY_SET
}
val signature = hash(lists.sortedBy { it.url }.joinToString("\n") { "${it.url} ${it.count} ${it.updated}" })
if (sp.getString(MERGED_KEY, null) == signature) map(mergedFile)?.let { return it }
val parts = lists.map { loadListHashes(it.url) }
val tmp = File.createTempFile("merged_", ".tmp", dir)
try {
DataOutputStream(BufferedOutputStream(FileOutputStream(tmp), 64 * 1024)).use { out ->
mergeSortedInto(parts) { out.writeLong(it) }
}
if (!tmp.renameTo(mergedFile)) throw IOException("Cannot save lists")
} finally {
tmp.delete()
}
sp.edit().putString(MERGED_KEY, signature).commit()
return map(mergedFile) ?: EMPTY_SET
}
// The mapping stays valid after the file is replaced or deleted, so readers are never cut off
private fun map(file: File): LongBuffer? {
if (!file.exists()) return null
fun loadListHashes(url: String): LongArray {
val file = binFile(url)
if (!file.exists()) return LongArray(0)
return runCatching {
FileInputStream(file).use { stream ->
val channel = stream.channel
val bytes = channel.size() / 8 * 8
if (bytes == 0L) EMPTY_SET else channel.map(FileChannel.MapMode.READ_ONLY, 0, bytes).asLongBuffer()
val result = LongArray((channel.size() / 8).toInt())
channel.map(FileChannel.MapMode.READ_ONLY, 0, result.size * 8L).asLongBuffer().get(result)
result
}
}.getOrNull()
}.getOrDefault(LongArray(0))
}
fun deleteListFile(url: String) {
@@ -483,23 +415,22 @@ private class BlocklistStore(context: Context) {
parsed.add(DomainHash.of(domain))
}
}
// Sorted inside the download buffer: a list with millions of entries is never copied
val count = parsed.sortUnique()
if (count == 0) throw IOException("No domains found")
write(url, parsed)
val result = parsed.toArray().sortUnique()
if (result.isEmpty()) throw IOException("No domains found")
write(url, result)
sp.edit()
.putOrRemove(etagKey(url), response.header("ETag"))
.putOrRemove(modifiedKey(url), response.header("Last-Modified"))
.apply()
return RemoteList(url, count, System.currentTimeMillis())
return RemoteList(url, result.size, System.currentTimeMillis())
}
}
private fun write(url: String, data: LongList) {
private fun write(url: String, data: LongArray) {
val tmp = File.createTempFile("list_", ".tmp", dir)
try {
DataOutputStream(BufferedOutputStream(FileOutputStream(tmp), 64 * 1024)).use { out ->
data.writeTo(out)
data.forEach { out.writeLong(it) }
}
if (!tmp.renameTo(binFile(url))) throw IOException("Cannot save list")
} finally {
@@ -514,14 +445,12 @@ private class BlocklistStore(context: Context) {
if (value == null) remove(key) else putString(key, value)
private fun binFile(url: String) = File(dir, "list_${hash(url)}.bin")
private val mergedFile get() = File(dir, "merged.bin")
private fun hash(url: String) = MessageDigest.getInstance("SHA-256").digest(url.toByteArray())
.take(8).joinToString("") { "%02x".format(it) }
companion object {
const val MAX_LIST_DOMAINS = 4_000_000
private const val MERGED_KEY = "merged"
val client: OkHttpClient by lazy {
Http.client.newBuilder()
@@ -1,6 +1,5 @@
package cc.skysparkle.sparkledns
import java.util.Locale
import java.util.TreeMap
// The position of each company is saved in StatsStore: add new ones at the end only
@@ -22,12 +21,6 @@ enum class Company(val label: String) {
object Companies {
private const val GOOGLE_PREFIX = "google."
// Second-level labels that belong to a country's suffix: example.co.uk, example.com.br
private val COUNTRY_SECOND_LEVELS = setOf("co", "com", "net", "org", "gov", "edu", "ac", "or", "ne", "go")
// Names that are not public sites: reverse lookups and local networks
private val PRIVATE_TLDS = setOf("arpa", "local", "lan", "home", "internal", "localhost")
// Hashes of the domains, sorted, with the company of each at the same index: this runs for
// every query, and parent domains are looked up by hash without copying the name
private val hashes: LongArray
@@ -100,16 +93,4 @@ object Companies {
}
return null
}
// A readable name for a domain of no known company, taken from its main label:
// "cdn.example.co.uk" gives "Example". Null for IP addresses, local names and bare labels.
fun nameOf(name: String): String? {
val labels = name.lowercase(Locale.ROOT).split('.').filter { it.isNotEmpty() }
if (labels.size < 2) return null
val tld = labels.last()
if (tld in PRIVATE_TLDS || tld.all { it.isDigit() }) return null
var index = labels.size - 2
if (tld.length == 2 && labels.size >= 3 && labels[index] in COUNTRY_SECOND_LEVELS) index--
return labels[index].replaceFirstChar { it.titlecase(Locale.ROOT) }
}
}
@@ -25,12 +25,10 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
@@ -56,13 +54,7 @@ class MainActivity : ComponentActivity() {
AppLogo.preload(this)
enableEdgeToEdge()
setContent {
MaterialTheme(colorScheme = AppColors) {
// There is no Surface at the root, so text and icons without an explicit color
// would fall back to black and disappear on the dark background
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) {
AppShell()
}
}
MaterialTheme(colorScheme = AppColors) { AppShell() }
}
}
}
@@ -24,7 +24,6 @@ object Providers {
),
DohProvider(
"quad9", "Quad9", "https://dns.quad9.net/dns-query", listOf("9.9.9.9", "149.112.112.112"),
http3 = true,
policy = "https://quad9.net/service/privacy/",
donate = "https://quad9.net/donate/",
),
@@ -44,12 +43,6 @@ object Providers {
policy = "https://ffmuc.net/dns-privacy/",
donate = "https://spende.ffmuc.net/",
),
DohProvider(
"dnsforge", "dnsforge.de", "https://blank.dnsforge.de/dns-query",
listOf("78.47.71.194", "138.199.149.249"),
policy = "https://adminforge.de/datenschutz/",
donate = "https://adminforge.de/unterstuetzen/",
),
)
// The project's own server stays the default whatever order the list uses
+1 -1
View File
@@ -100,7 +100,7 @@
<string name="tab_activity">Aktivität</string>
<string name="tab_settings">Einstellungen</string>
<string name="companies_title">Anteil der Konzerne</string>
<string name="companies_desc">Welcher Anteil deiner Anfragen an die größten Konzerne und andere Websites geht.</string>
<string name="companies_desc">Welcher Anteil deiner Anfragen an die größten Konzerne geht.</string>
<string name="companies_other">Andere</string>
<string name="recent_title">Letzte Anfragen</string>
<string name="filter">Filter</string>
+1 -1
View File
@@ -100,7 +100,7 @@
<string name="tab_activity">アクティビティ</string>
<string name="tab_settings">設定</string>
<string name="companies_title">企業の占有率</string>
<string name="companies_desc">リクエストのうち大手企業やその他のサイトに送られる割合です。</string>
<string name="companies_desc">リクエストのうち大手企業に送られる割合です。</string>
<string name="companies_other">その他</string>
<string name="recent_title">最近のアクティビティ</string>
<string name="filter">フィルター</string>
+1 -1
View File
@@ -100,7 +100,7 @@
<string name="tab_activity">Veikla</string>
<string name="tab_settings">Nustatymai</string>
<string name="companies_title">Įmonių dalis</string>
<string name="companies_desc">Kokia jūsų užklausų dalis tenka didžiausioms įmonėms ir kitoms svetainėms.</string>
<string name="companies_desc">Kokia jūsų užklausų dalis tenka didžiausioms įmonėms.</string>
<string name="companies_other">Kitos</string>
<string name="recent_title">Naujausios užklausos</string>
<string name="filter">Filtras</string>
+1 -1
View File
@@ -100,7 +100,7 @@
<string name="tab_activity">Активность</string>
<string name="tab_settings">Настройки</string>
<string name="companies_title">Доля компаний</string>
<string name="companies_desc">Какая часть ваших запросов уходит крупнейшим компаниям и другим сайтам.</string>
<string name="companies_desc">Какая часть ваших запросов уходит крупнейшим компаниям.</string>
<string name="companies_other">Другие</string>
<string name="recent_title">Последние запросы</string>
<string name="filter">Фильтр</string>
+1 -1
View File
@@ -100,7 +100,7 @@
<string name="tab_activity">活动</string>
<string name="tab_settings">设置</string>
<string name="companies_title">公司占比</string>
<string name="companies_desc">你的请求中发往大公司和其他网站的比例。</string>
<string name="companies_desc">你的请求中发往大公司的比例。</string>
<string name="companies_other">其他</string>
<string name="recent_title">最近活动</string>
<string name="filter">筛选</string>
+1 -1
View File
@@ -101,7 +101,7 @@
<string name="tab_activity">Activity</string>
<string name="tab_settings">Settings</string>
<string name="companies_title">Company dominance</string>
<string name="companies_desc">Share of your requests that go to the biggest companies and other sites.</string>
<string name="companies_desc">Share of your requests that go to the biggest companies.</string>
<string name="companies_other">Other</string>
<string name="recent_title">Recent activity</string>
<string name="filter">Filter</string>
@@ -5,17 +5,14 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.nio.LongBuffer
class BlocklistMatchTest {
private fun set(vararg domains: String) = domains.map { DomainHash.of(it) }.sorted().toLongArray()
private fun buf(vararg domains: String) = LongBuffer.wrap(set(*domains))
private fun buf(values: LongArray) = LongBuffer.wrap(values)
@Test
fun blocksDomainsAndTheirSubdomains() {
val lists = buf("ads.example.com")
val lists = set("ads.example.com")
val custom = set("tracker.net")
assertTrue(isBlockedIn("ads.example.com", lists, custom))
@@ -24,12 +21,12 @@ class BlocklistMatchTest {
assertFalse(isBlockedIn("example.com", lists, custom))
assertFalse(isBlockedIn("badads.example.com", lists, custom))
assertFalse(isBlockedIn("tracker.network", lists, custom))
assertFalse(isBlockedIn("ads.example.com", EMPTY_SET, LongArray(0)))
assertFalse(isBlockedIn("ads.example.com", LongArray(0), LongArray(0)))
}
@Test
fun skipsTrailingDots() {
val lists = buf("example.com")
val lists = set("example.com")
assertTrue(isBlockedIn("www.example.com..", lists, LongArray(0)))
assertFalse(isBlockedIn("example.org.", lists, LongArray(0)))
@@ -54,28 +51,8 @@ class BlocklistMatchTest {
@Test
fun countsEntriesInBothSetsOnce() {
assertEquals(5, unionSize(buf(longArrayOf(1, 2, 3, 4)), longArrayOf(2, 5)))
assertEquals(2, unionSize(EMPTY_SET, longArrayOf(2, 5)))
assertEquals(4, unionSize(buf(longArrayOf(1, 2, 3, 4)), LongArray(0)))
}
@Test
fun streamsMergedValuesInOrderOnce() {
val out = ArrayList<Long>()
val count = mergeSortedInto(
listOf(buf(longArrayOf(-5, 1, 4, 9)), buf(longArrayOf(1, 2, 9, 12)), EMPTY_SET, buf(longArrayOf(12, 40)))
) { out.add(it) }
assertEquals(listOf(-5L, 1, 2, 4, 9, 12, 40), out)
assertEquals(7, count)
assertEquals(0, mergeSortedInto(emptyList()) { out.add(it) })
}
@Test
fun findsValuesInSortedBuffer() {
val values = buf(longArrayOf(Long.MIN_VALUE, -3, 0, 7, Long.MAX_VALUE))
listOf(Long.MIN_VALUE, -3L, 0L, 7L, Long.MAX_VALUE).forEach { assertTrue(values.containsSorted(it)) }
listOf(-4L, 1L, 8L).forEach { assertFalse(values.containsSorted(it)) }
assertFalse(EMPTY_SET.containsSorted(0))
assertEquals(5, unionSize(longArrayOf(1, 2, 3, 4), longArrayOf(2, 5)))
assertEquals(2, unionSize(LongArray(0), longArrayOf(2, 5)))
assertEquals(4, unionSize(longArrayOf(1, 2, 3, 4), LongArray(0)))
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 667 KiB

After

Width:  |  Height:  |  Size: 575 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

@@ -1,6 +1,6 @@
• DNS läuft bei unerwarteten Paketen weiter; fällt der Tunnel aus, schaltet sich das VPN ab, statt DNS still zu blockieren
• Anfragen erholen sich schneller nach einem WLAN-Mobilfunk-Wechsel und in langsamen Netzen
• Weniger Hintergrundarbeit: ausgeblendete Bildschirme werden nicht mehr aktualisiert
• Blocklisten werden nur bei Änderungen neu geladen
• DNS funktioniert weiter, wenn ein unerwartetes Paket ankommt; fällt der Tunnel aus, schaltet sich das VPN ab, statt DNS still zu blockieren
• Anfragen erholen sich schneller nach einem Wechsel zwischen WLAN und Mobilfunk und in langsamen Netzen
• Weniger Arbeit im Hintergrund: ausgeblendete Bildschirme werden nicht mehr aktualisiert
• Blocklisten werden nur noch erneut geladen, wenn sie sich geändert haben
• Schärfere App-Symbole, kleinere App
• Doppeltipp auf „Verbinden“ verbindet nicht doppelt; voller Speicher führt nicht mehr zum Absturz
• Ein Doppeltipp auf „Verbinden“ verbindet nicht mehr doppelt; voller Speicher lässt die App nicht mehr abstürzen
@@ -1 +0,0 @@
• Quad9 verbindet sich unter Android 14 und neuer jetzt über HTTP/3 (QUIC)
@@ -1,2 +0,0 @@
• Die letzte Aktivität zeigt eine Zeile pro Domain mit allen abgefragten Typen (A, AAAA, HTTPS) und der Anzahl der Anfragen
• Der Anteil der Konzerne nennt jetzt auch andere Websites, statt alle unter Andere zusammenzufassen
@@ -1 +0,0 @@
• Quad9 now connects over HTTP/3 (QUIC) on Android 14 and newer
@@ -1,2 +0,0 @@
• Recent activity shows one row per domain with all requested types (A, AAAA, HTTPS) and the number of queries
• Company dominance names other sites instead of grouping them all as Other
Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 KiB

After

Width:  |  Height:  |  Size: 584 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 667 KiB

After

Width:  |  Height:  |  Size: 575 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

After

Width:  |  Height:  |  Size: 513 KiB

@@ -1 +0,0 @@
• Android 14 以降では Quad9 に HTTP/3(QUIC)で接続
@@ -1,2 +0,0 @@
• 最近のアクティビティはドメインごとに 1 行で表示し、要求されたすべての種類(A、AAAA、HTTPS)とクエリ数を表示
• 企業の占有率で、その他のサイトもまとめずに名前で表示
@@ -1 +0,0 @@
• Quad9 dabar jungiasi per HTTP/3 (QUIC) Android 14 ir naujesnėse versijose
@@ -1,2 +0,0 @@
• Naujausia veikla rodo vieną eilutę kiekvienam domenui su visais užklaustais tipais (A, AAAA, HTTPS) ir užklausų skaičiumi
• Įmonių dalyje kitos svetainės dabar rodomos pavadinimais, o ne sujungiamos į „Kitos“
@@ -1 +0,0 @@
• Quad9 теперь подключается по HTTP/3 (QUIC) на Android 14 и новее
@@ -1,2 +0,0 @@
• Последняя активность показывает одну строку на домен со всеми запрошенными типами (A, AAAA, HTTPS) и числом запросов
• В «Доле компаний» остальные сайты показываются по названиям, а не объединяются в «Другие»
@@ -1 +0,0 @@
• 在 Android 14 及更高版本上,Quad9 现通过 HTTP/3(QUIC)连接
@@ -1,2 +0,0 @@
• 最近活动按域名每行显示一条,包含所有请求类型(A、AAAA、HTTPS)及查询次数
• 公司占比中的其他网站现在按名称显示,不再全部归入“其他”