Skip to content

Commit 177f7ab

Browse files
Merge pull request #11 from andreknieriem/offline-hotspot
Offline hotspot
2 parents 3670963 + 712b231 commit 177f7ab

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ adb shell am start -a android.intent.action.VIEW -d "wirelesshelper://stop"
4848
```
4949

5050
## Changelog
51+
### v.1.0.1
52+
- Fixing offline mode
53+
5154
### v.1.0.0 - First ready version for Playstore!
5255
- Added Deep Links and App Shortcuts for full automation (Samsung Modes & Routines support).
5356
- Added Arabic translation, thanks to @A5H0

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId = "com.andrerinas.wirelesshelper"
1515
minSdk = 21
1616
targetSdk = 36
17-
versionCode = 6
18-
versionName = "1.0.0"
17+
versionCode = 7
18+
versionName = "1.0.1"
1919

2020
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2121
}

app/src/main/java/com/andrerinas/wirelesshelper/connection/AapProxy.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,14 @@ class AapProxy(private val remoteIp: String, private val remotePort: Int = 5288,
8282
try {
8383
while (isRunning) {
8484
val read = input.read(buffer)
85-
if (read == -1) {
86-
Log.i(TAG, "$name: Input reached EOF. Closing bridge.")
87-
break
88-
}
85+
if (read == -1) break
8986
output.write(buffer, 0, read)
9087
output.flush()
9188
}
9289
} catch (e: Exception) {
93-
Log.d(TAG, "$name: Error during pump: ${e.message}")
90+
Log.d(TAG, "$name error: ${e.message}")
9491
} finally {
95-
// If one direction fails, the entire proxy should stop to trigger cleanup
96-
if (isRunning) {
97-
Log.i(TAG, "$name: Triggering global proxy stop.")
98-
stop()
99-
}
92+
if (isRunning) stop()
10093
}
10194
}
10295

@@ -106,4 +99,4 @@ class AapProxy(private val remoteIp: String, private val remotePort: Int = 5288,
10699
serverSocket = null
107100
scope.cancel()
108101
}
109-
}
102+
}

app/src/main/java/com/andrerinas/wirelesshelper/strategy/BaseStrategy.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.andrerinas.wirelesshelper.strategy
22

3-
import android.app.Service
43
import android.content.Context
54
import android.content.Intent
6-
import android.database.Cursor
75
import android.net.ConnectivityManager
86
import android.net.Network
9-
import android.net.Uri
107
import android.os.Build
118
import android.os.Parcelable
129
import android.util.Log
@@ -23,7 +20,6 @@ abstract class BaseStrategy(protected val context: Context, private val scope: C
2320
}
2421

2522
protected val TAG = "HUREV_WIFI"
26-
private val carConnectionUri = Uri.Builder().scheme("content").authority("androidx.car.app.connection").build()
2723
private var activeProxy: AapProxy? = null
2824
var stateListener: StateListener? = null
2925
protected val isLaunching = AtomicBoolean(false)
@@ -40,6 +36,19 @@ abstract class BaseStrategy(protected val context: Context, private val scope: C
4036
const val ACTION_TRIGGER_INTENT = "com.andrerinas.wirelesshelper.ACTION_TRIGGER_INTENT"
4137
}
4238

39+
private fun createFakeNetwork(netId: Int): Network? {
40+
val parcel = android.os.Parcel.obtain()
41+
return try {
42+
parcel.writeInt(netId)
43+
parcel.setDataPosition(0)
44+
Network.CREATOR.createFromParcel(parcel)
45+
} catch (e: Exception) {
46+
null
47+
} finally {
48+
parcel.recycle()
49+
}
50+
}
51+
4352
protected fun launchAndroidAuto(hostIp: String, forceFakeNetwork: Boolean = false) {
4453
if (isLaunching.get()) return
4554
if (!isLaunching.compareAndSet(false, true)) return
@@ -68,7 +77,9 @@ abstract class BaseStrategy(protected val context: Context, private val scope: C
6877
val localPort = proxy.start()
6978

7079
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
71-
val activeNetwork = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) connectivityManager.activeNetwork else null
80+
// FALLBACK TO ID 0 IF OFFLINE
81+
val targetNetwork = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) connectivityManager.activeNetwork else null)
82+
?: createFakeNetwork(0)
7283

7384
val wifiInfo: Parcelable? = try {
7485
val clazz = Class.forName("android.net.wifi.WifiInfo")
@@ -82,11 +93,11 @@ abstract class BaseStrategy(protected val context: Context, private val scope: C
8293
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
8394
putExtra("PARAM_HOST_ADDRESS", "127.0.0.1")
8495
putExtra("PARAM_SERVICE_PORT", localPort)
85-
activeNetwork?.let { putExtra("PARAM_SERVICE_WIFI_NETWORK", it) }
96+
targetNetwork?.let { putExtra("PARAM_SERVICE_WIFI_NETWORK", it) }
8697
wifiInfo?.let { putExtra("wifi_info", it) }
8798
}
8899

89-
Log.i(TAG, "Firing Proxy Intent. LocalPort=$localPort")
100+
Log.i(TAG, "Firing Intent. Host=127.0.0.1, Port=$localPort, Network=$targetNetwork")
90101

91102
// 1. Try via Broadcast (if TransparentTriggerActivity is active)
92103
val broadcastIntent = Intent(ACTION_TRIGGER_INTENT).apply {
@@ -128,4 +139,4 @@ abstract class BaseStrategy(protected val context: Context, private val scope: C
128139
activeProxy = null
129140
isLaunching.set(false)
130141
}
131-
}
142+
}

0 commit comments

Comments
 (0)