diff --git a/mobile/build.gradle b/mobile/build.gradle index 39bd5332..34f90306 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -11,8 +11,8 @@ android { applicationId "nl.jolanrensen.permanentproxy" minSdkVersion 23 targetSdkVersion 29 - versionCode 6 - versionName "3.0" + versionCode 7 + versionName "3.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/wear/build.gradle b/wear/build.gradle index c928938e..adf5c049 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -11,8 +11,8 @@ android { applicationId "nl.jolanrensen.permanentproxy" minSdkVersion 23 targetSdkVersion 29 - versionCode 6 - versionName "3.0" + versionCode 7 + versionName "3.1" } buildTypes { release { @@ -41,7 +41,7 @@ dependencies { implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation "androidx.core:core-ktx:1.2.0-alpha04" + implementation "androidx.core:core-ktx:1.2.0-beta01" implementation 'com.android.support:wear:28.0.0' compileOnly 'com.google.android.wearable:wearable:2.5.0' } diff --git a/wear/release/mobile-release.apk b/wear/release/mobile-release.apk index 2e4188a0..009a7a92 100644 Binary files a/wear/release/mobile-release.apk and b/wear/release/mobile-release.apk differ diff --git a/wear/release/wear-release.aab b/wear/release/wear-release.aab index 80db6b13..e252eadd 100644 Binary files a/wear/release/wear-release.aab and b/wear/release/wear-release.aab differ diff --git a/wear/release/wear-release.apk b/wear/release/wear-release.apk index ab5a2c3c..aa3d58da 100644 Binary files a/wear/release/wear-release.apk and b/wear/release/wear-release.apk differ diff --git a/wear/src/main/java/nl/jolanrensen/permanentproxy/Constants.kt b/wear/src/main/java/nl/jolanrensen/permanentproxy/Constants.kt index afc77b02..b565cf3d 100644 --- a/wear/src/main/java/nl/jolanrensen/permanentproxy/Constants.kt +++ b/wear/src/main/java/nl/jolanrensen/permanentproxy/Constants.kt @@ -104,9 +104,14 @@ object Constants { fun getCurrentIP(callback: (String?) -> Unit) { val process = GlobalScope.launch(Dispatchers.IO) { - callback( - JSONObject(URL("https://api.ipify.org?format=json").readText()).getString("ip") - ) + try { + callback( + JSONObject(URL("https://api.ipify.org?format=json").readText()).getString("ip") + ) + } catch (e: Exception) { + logE("", e) + callback(null) + } } GlobalScope.launch { diff --git a/wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt b/wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt index 21270276..8cd94369 100644 --- a/wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt +++ b/wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt @@ -32,6 +32,8 @@ import kotlin.concurrent.thread class MainActivity : WearableActivity() { var p: SharedPreferences? = null + @Volatile + var currentADBProcess: SendSingleCommand? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -85,10 +87,11 @@ class MainActivity : WearableActivity() { request_permission.setOnClickListener { loading.isVisible = true + loading.requestFocus() thread(start = true) { val logs = arrayListOf() try { - SendSingleCommand( + currentADBProcess = SendSingleCommand( logs = logs, context = this, ip = "localhost", @@ -97,6 +100,7 @@ class MainActivity : WearableActivity() { timeout = 4000, ctrlC = false ) { + currentADBProcess = null logD(it.toString()) runOnUiThread { loading.isVisible = false @@ -111,6 +115,7 @@ class MainActivity : WearableActivity() { } } } catch (e: Exception) { + currentADBProcess = null logE("$logs", e) runOnUiThread { loading.isVisible = false @@ -119,6 +124,10 @@ class MainActivity : WearableActivity() { } } } + + cancel.setOnClickListener { + currentADBProcess?.cancel() + } } private fun setupStatus(wait: Boolean = false): Boolean { @@ -237,24 +246,30 @@ class MainActivity : WearableActivity() { port_input.setOnEditorActionListener { _, actionId, _ -> when (actionId) { IME_ACTION_SEARCH -> { - p!!.edit(commit = true) { - putInt("port", port_input.text.toString().toInt()) - } - logE("port updated to ${port_input.text.toString().toInt()}") - port_input.isVisible = false - - enable_proxy.isEnabled = p!!.getString("address", "")!! != "" - && p!!.getInt("port", -1) != -1 + try { + p!!.edit(commit = true) { + putInt("port", port_input.text.toString().toInt()) + } - // update proxy if already running - if (currentProxy != null) { - startProxy( - p = p!!, - address = p!!.getString("address", "")!!, - port = port_input.text.toString().toInt(), - updateGooglePay = true - ) - setupStatus(wait = true) + logE("port updated to ${port_input.text.toString().toInt()}") + port_input.isVisible = false + + enable_proxy.isEnabled = p!!.getString("address", "")!! != "" + && p!!.getInt("port", -1) != -1 + + // update proxy if already running + if (currentProxy != null) { + startProxy( + p = p!!, + address = p!!.getString("address", "")!!, + port = port_input.text.toString().toInt(), + updateGooglePay = true + ) + setupStatus(wait = true) + } + } catch (e: Exception) { + logE("", e) + toastLong(getString(R.string.valid_port)) } true diff --git a/wear/src/main/java/nl/jolanrensen/permanentproxy/SendSingleCommand.kt b/wear/src/main/java/nl/jolanrensen/permanentproxy/SendSingleCommand.kt index 462298f7..58b0e6af 100644 --- a/wear/src/main/java/nl/jolanrensen/permanentproxy/SendSingleCommand.kt +++ b/wear/src/main/java/nl/jolanrensen/permanentproxy/SendSingleCommand.kt @@ -48,17 +48,23 @@ constructor( ) { private var splitResponses: ArrayList? = null + private var done = false - val pub = File(context.filesDir, "pub.key") - val priv = File(context.filesDir, "priv.key") + private val pub = File(context.filesDir, "pub.key") + private val priv = File(context.filesDir, "priv.key") - var stream: AdbStream - var adb: AdbConnection + private var stream: AdbStream + private var adb: AdbConnection // This implements the AdbBase64 interface required for AdbCrypto - val base64Impl: AdbBase64 + private val base64Impl: AdbBase64 get() = AdbBase64 { encodeBase64String(it) } + // Cancel waiting for responses + fun cancel() { + done = true + } + init { val sock: Socket val crypto: AdbCrypto @@ -128,7 +134,6 @@ constructor( logD("Command sent") var responses = "" - var done = false var timer = 0 logD("Getting responses...") @@ -152,7 +157,7 @@ constructor( while (!done) { delay(1) timer++ - if (timer == timeout) done = true + if (timer >= timeout) done = true } logD("response:\n$responses") @@ -172,6 +177,7 @@ constructor( } GlobalScope.launch { while (!stream.isClosed) { + delay(1) } logD("Stream closed, closing Adb...") @@ -187,6 +193,7 @@ constructor( } GlobalScope.launch { while (!sock.isClosed) { + delay(1) } logD("ADB connection socket closed") callBack(splitResponses) diff --git a/wear/src/main/res/layout/activity_main.xml b/wear/src/main/res/layout/activity_main.xml index c2512303..17b39ceb 100644 --- a/wear/src/main/res/layout/activity_main.xml +++ b/wear/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ + android:textAppearance="@android:style/TextAppearance.Material.Body1" /> + android:textAppearance="@android:style/TextAppearance.Material.Body1" /> + android:minHeight="45dp" + android:text="@string/enable_proxy" + android:textAppearance="@android:style/TextAppearance.Material.Body1" /> + android:visibility="gone" /> - + android:layout_height="match_parent" + android:background="@color/black" + android:visibility="gone" + android:nestedScrollingEnabled="true" + android:paddingStart="16dp" + android:paddingEnd="16dp" + tools:visibility="gone"> - - - + android:orientation="vertical"> + + + + - + + + + + \ No newline at end of file diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index b1af1cc5..2f01eb5c 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -20,7 +20,7 @@ How to enable ADB over Bluetooth? EnableADBBluetoothActivity System -> About and tap the Build number until you are a \"developer\".\nNext, go to Settings -> Developer options and enable \"ADB debugging\" and \"Debug over Bluetooth\".\nFinally start up Permanent Proxy, request permission and press \"Allow\" or \"Always allow this Computer\" if prompted.\nAfter the app has gotten permission, ADB can be turned off again unless you want to disable the proxy.\n\nNow you can get started! Simply enter a proxy address and port, enable it and you\'re done! If you reboot, the proxy will remain.\n\nProxy services can be found online and can be from any country. However, do make sure your proxy works and you completely trust the proxy you chose before you enter it! All the data of your watch might be sent through that proxy, even sensitive data, so act at your own risk.]]> - Requesting permission, this can take a while… \"Allow\" or \"Always allow computer\" if prompted.\nNote: the app works best with WiFi turned OFF. + Requesting permission, this can take a while… \"Allow\" or \"Always allow computer\" if prompted.\n\nNote: the app works best with WiFi turned OFF. Write secure settings permission needed. This can be enabled via ADB over Bluetooth. ADB over Bluetooth is enabled, request permission! Permission granted,\nADB can be turned off. @@ -30,4 +30,6 @@ External IP: N/A Other apps and external IP might take time to update. + Cancel + Error: did you enter a valid port?