Skip to content

Commit f96181f

Browse files
committed
Ensure MainActivity restores using active proxy details after restart
1 parent f6cc97c commit f96181f

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<activity
3939
android:name=".MainActivity"
4040
android:label="@string/app_name"
41-
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
4241
android:launchMode="singleTask">
4342
<intent-filter>
4443
<action android:name="android.intent.action.MAIN" />

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
6363
}
6464

6565
private var mainState: MainState = if (isVpnActive()) MainState.CONNECTED else MainState.DISCONNECTED
66+
6667
// If connected/late-stage connecting, the proxy we're connected/trying to connect to. Otherwise null.
67-
private var currentProxyConfig: ProxyConfig? = null
68+
private var currentProxyConfig: ProxyConfig? = activeVpnConfig()
6869

6970
override fun onCreate(savedInstanceState: Bundle?) {
7071
super.onCreate(savedInstanceState)
@@ -106,12 +107,6 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
106107
}
107108
}
108109

109-
override fun onConfigurationChanged(newConfig: Configuration) {
110-
super.onConfigurationChanged(newConfig)
111-
setContentView(R.layout.main_layout)
112-
updateUi()
113-
}
114-
115110
override fun onResume() {
116111
super.onResume()
117112
Log.d(TAG, "onResume")
@@ -182,12 +177,16 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
182177
disconnect()
183178
}
184179

185-
else -> Log.w(TAG, "Unknown intent. Action ${
180+
intent.action == "android.intent.action.MAIN" -> {
181+
// The app is being opened - nothing to do here
182+
}
183+
184+
else -> Log.w(TAG, "Ignoring unknown intent. Action ${
186185
intent.action
187186
}, data: ${
188187
intent.data
189-
}, ${
190-
if (isRCIntent) "sent as RC intent" else "non-RC"
188+
}${
189+
if (isRCIntent) " (RC)" else ""
191190
}")
192191
}
193192
}

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ fun isVpnActive(): Boolean {
3737
currentService?.isActive() ?: false
3838
}
3939

40+
fun activeVpnConfig(): ProxyConfig? {
41+
return currentService?.proxyConfig
42+
}
43+
4044
class ProxyVpnService : VpnService(), IProtectSocket {
4145

4246
private var app: HttpToolkitApplication? = null
4347

4448
private var localBroadcastManager: LocalBroadcastManager? = null
4549

50+
var proxyConfig: ProxyConfig? = null
51+
private set
52+
4653
private var vpnInterface: ParcelFileDescriptor? = null
4754
private var vpnRunnable: ProxyVpnRunnable? = null
4855

@@ -125,6 +132,7 @@ class ProxyVpnService : VpnService(), IProtectSocket {
125132
}
126133

127134
private fun startVpn(proxyConfig: ProxyConfig) {
135+
this.proxyConfig = proxyConfig
128136
val packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
129137

130138
val packageNames = packages.map { pkg -> pkg.packageName }
@@ -189,7 +197,9 @@ class ProxyVpnService : VpnService(), IProtectSocket {
189197
stopForeground(true)
190198
localBroadcastManager!!.sendBroadcast(Intent(VPN_STOPPED_BROADCAST))
191199
stopSelf()
200+
192201
currentService = null
202+
this.proxyConfig = null
193203
}
194204

195205
fun isActive(): Boolean {

0 commit comments

Comments
 (0)