Skip to content

Commit 3198e22

Browse files
committed
Merge branch 'dev'
2 parents 527c71a + f71a943 commit 3198e22

File tree

5 files changed

+67
-75
lines changed

5 files changed

+67
-75
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
wireguardVersionCode=515
2-
wireguardVersionName=1.0.20250522.1
1+
wireguardVersionCode=516
2+
wireguardVersionName=1.0.20250531.1
33
wireguardPackageName=com.wireguard.android
44

55
# When configured, Gradle will run in incubating parallel mode.

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
agp = "8.10.0"
2+
agp = "8.10.1"
33
kotlin = "2.1.20"
44

55
[libraries]
@@ -11,8 +11,8 @@ androidx-collection = "androidx.collection:collection:1.5.0"
1111
androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.2.1"
1212
androidx-coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.3.0"
1313
androidx-core-ktx = "androidx.core:core-ktx:1.16.0"
14-
androidx-datastore-preferences = "androidx.datastore:datastore-preferences:1.1.6"
15-
androidx-fragment-ktx = "androidx.fragment:fragment-ktx:1.8.6"
14+
androidx-datastore-preferences = "androidx.datastore:datastore-preferences:1.1.7"
15+
androidx-fragment-ktx = "androidx.fragment:fragment-ktx:1.8.7"
1616
androidx-lifecycle-runtime-ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.9.0"
1717
androidx-preference-ktx = "androidx.preference:preference-ktx:1.2.1"
1818
desugarJdkLibs = "com.android.tools:desugar_jdk_libs:2.1.5"

ui/src/main/java/com/wireguard/android/QuickTileService.kt

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,50 @@ class QuickTileService : TileService() {
5252
}
5353

5454
override fun onClick() {
55-
when (val tunnel = tunnel) {
56-
null -> {
57-
val intent = Intent(this, MainActivity::class.java)
58-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
59-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
60-
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
61-
} else {
62-
@Suppress("DEPRECATION")
63-
startActivityAndCollapse(intent)
64-
}
55+
applicationScope.launch {
56+
if (tunnel == null) {
57+
Application.getTunnelManager().getTunnels()
58+
updateTile()
6559
}
66-
else -> {
67-
unlockAndRun {
68-
applicationScope.launch {
69-
try {
70-
tunnel.setStateAsync(Tunnel.State.TOGGLE)
71-
updateTile()
72-
} catch (_: Throwable) {
73-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this@QuickTileService)) {
74-
val permissionIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
75-
permissionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
76-
startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, permissionIntent, PendingIntent.FLAG_IMMUTABLE))
77-
return@launch
60+
when (val tunnel = tunnel) {
61+
null -> {
62+
Log.d(TAG, "No tunnel set, so launching main activity")
63+
val intent = Intent(this@QuickTileService, MainActivity::class.java)
64+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
65+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
66+
startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, intent, PendingIntent.FLAG_IMMUTABLE))
67+
} else {
68+
@Suppress("DEPRECATION")
69+
startActivityAndCollapse(intent)
70+
}
71+
}
72+
73+
else -> {
74+
unlockAndRun {
75+
applicationScope.launch {
76+
try {
77+
tunnel.setStateAsync(Tunnel.State.TOGGLE)
78+
updateTile()
79+
} catch (e: Throwable) {
80+
Log.d(TAG, "Failed to set state, so falling back", e)
81+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this@QuickTileService)) {
82+
Log.d(TAG, "Need overlay permissions")
83+
val permissionIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
84+
permissionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
85+
startActivityAndCollapse(
86+
PendingIntent.getActivity(
87+
this@QuickTileService,
88+
0,
89+
permissionIntent,
90+
PendingIntent.FLAG_IMMUTABLE
91+
)
92+
)
93+
return@launch
94+
}
95+
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
96+
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
97+
startActivity(toggleIntent)
7898
}
79-
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
80-
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
81-
startActivity(toggleIntent)
8299
}
83100
}
84101
}

ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ class TvMainActivity : AppCompatActivity() {
214214
MaterialAlertDialogBuilder(binding.root.context).setMessage(R.string.tv_no_file_picker).setCancelable(false)
215215
.setPositiveButton(android.R.string.ok) { _, _ ->
216216
try {
217-
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://webstoreredirect")))
217+
startActivity(Intent(Intent.ACTION_VIEW).apply {
218+
data = Uri.parse("https://play.google.com/store/apps/details?id=com.cxinventor.file.explorer")
219+
setPackage("com.android.vending")
220+
})
218221
} catch (_: Throwable) {
219222
}
220223
}.show()

ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class QrCodeFromFileScanner(
2929
private val contentResolver: ContentResolver,
3030
private val reader: Reader,
3131
) {
32-
3332
private fun scanBitmapForResult(source: Bitmap): Result {
3433
val width = source.width
3534
val height = source.height
@@ -40,55 +39,28 @@ class QrCodeFromFileScanner(
4039
return reader.decode(bBitmap, mapOf(DecodeHintType.TRY_HARDER to true))
4140
}
4241

43-
private fun downscaleBitmap(source: Bitmap, scaledSize: Int): Bitmap {
44-
45-
val originalWidth = source.width
46-
val originalHeight = source.height
47-
48-
var newWidth = -1
49-
var newHeight = -1
50-
val multFactor: Float
51-
52-
when {
53-
originalHeight > originalWidth -> {
54-
newHeight = scaledSize
55-
multFactor = originalWidth.toFloat() / originalHeight.toFloat()
56-
newWidth = (newHeight * multFactor).toInt()
57-
}
58-
59-
originalWidth > originalHeight -> {
60-
newWidth = scaledSize
61-
multFactor = originalHeight.toFloat() / originalWidth.toFloat()
62-
newHeight = (newWidth * multFactor).toInt()
63-
}
64-
65-
originalHeight == originalWidth -> {
66-
newHeight = scaledSize
67-
newWidth = scaledSize
68-
}
69-
}
70-
return Bitmap.createScaledBitmap(source, newWidth, newHeight, false)
71-
}
72-
7342
private fun doScan(data: Uri): Result {
7443
Log.d(TAG, "Starting to scan an image: $data")
7544
contentResolver.openInputStream(data).use { inputStream ->
76-
val originalBitmap = BitmapFactory.decodeStream(inputStream)
77-
?: throw IllegalArgumentException("Can't decode stream to Bitmap")
78-
79-
return try {
80-
scanBitmapForResult(originalBitmap).also {
81-
Log.d(TAG, "Found result in original image")
45+
var bitmap: Bitmap? = null
46+
var firstException: Throwable? = null
47+
for (i in arrayOf(1, 2, 4, 8, 16, 32, 64, 128)) {
48+
try {
49+
val options = BitmapFactory.Options()
50+
options.inSampleSize = i
51+
bitmap = BitmapFactory.decodeStream(inputStream, null, options)
52+
?: throw IllegalArgumentException("Can't decode stream for bitmap")
53+
return scanBitmapForResult(bitmap)
54+
} catch (e: Throwable) {
55+
bitmap?.recycle()
56+
System.gc()
57+
Log.e(TAG, "Original image scan at scale factor $i finished with error: $e")
58+
if (firstException == null)
59+
firstException = e
8260
}
83-
} catch (e: Exception) {
84-
Log.e(TAG, "Original image scan finished with error: $e, will try downscaled image")
85-
val scaleBitmap = downscaleBitmap(originalBitmap, 500)
86-
scanBitmapForResult(originalBitmap).also { scaleBitmap.recycle() }
87-
} finally {
88-
originalBitmap.recycle()
8961
}
62+
throw Exception(firstException)
9063
}
91-
9264
}
9365

9466
/**

0 commit comments

Comments
 (0)