Skip to content

Commit

Permalink
v3.1:
Browse files Browse the repository at this point in the history
Fixed no-internet crash bug
Added cancel button to requesting permission to please Google

before:
Proxy can now properly be turned off
Removed on boot setting as that happens automatically
Easier setup and better layout
Live external IP view
Remember: turning off wifi will make it work better!
Added clearer loading screen and easier setup
ADB over Bluetooth only needs to be enabled the first time using the app
Way faster proxy switching using WRITE_SECURE_SETTINGS
  • Loading branch information
Jolanrensen committed Oct 16, 2019
1 parent 1272508 commit c4a32fd
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 67 deletions.
4 changes: 2 additions & 2 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
}
Binary file modified wear/release/mobile-release.apk
Binary file not shown.
Binary file modified wear/release/wear-release.aab
Binary file not shown.
Binary file modified wear/release/wear-release.apk
Binary file not shown.
11 changes: 8 additions & 3 deletions wear/src/main/java/nl/jolanrensen/permanentproxy/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 33 additions & 18 deletions wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -85,10 +87,11 @@ class MainActivity : WearableActivity() {

request_permission.setOnClickListener {
loading.isVisible = true
loading.requestFocus()
thread(start = true) {
val logs = arrayListOf<String>()
try {
SendSingleCommand(
currentADBProcess = SendSingleCommand(
logs = logs,
context = this,
ip = "localhost",
Expand All @@ -97,6 +100,7 @@ class MainActivity : WearableActivity() {
timeout = 4000,
ctrlC = false
) {
currentADBProcess = null
logD(it.toString())
runOnUiThread {
loading.isVisible = false
Expand All @@ -111,6 +115,7 @@ class MainActivity : WearableActivity() {
}
}
} catch (e: Exception) {
currentADBProcess = null
logE("$logs", e)
runOnUiThread {
loading.isVisible = false
Expand All @@ -119,6 +124,10 @@ class MainActivity : WearableActivity() {
}
}
}

cancel.setOnClickListener {
currentADBProcess?.cancel()
}
}

private fun setupStatus(wait: Boolean = false): Boolean {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ constructor(
) {

private var splitResponses: ArrayList<String>? = 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
Expand Down Expand Up @@ -128,7 +134,6 @@ constructor(
logD("Command sent")

var responses = ""
var done = false
var timer = 0

logD("Getting responses...")
Expand All @@ -152,7 +157,7 @@ constructor(
while (!done) {
delay(1)
timer++
if (timer == timeout) done = true
if (timer >= timeout) done = true
}

logD("response:\n$responses")
Expand All @@ -172,6 +177,7 @@ constructor(
}
GlobalScope.launch {
while (!stream.isClosed) {
delay(1)
}
logD("Stream closed, closing Adb...")

Expand All @@ -187,6 +193,7 @@ constructor(
}
GlobalScope.launch {
while (!sock.isClosed) {
delay(1)
}
logD("ADB connection socket closed")
callBack(splitResponses)
Expand Down
84 changes: 51 additions & 33 deletions wear/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -73,8 +72,7 @@
android:gravity="center_vertical"
android:minHeight="45dp"
android:text="@string/show_me_how"
android:textAppearance="@android:style/TextAppearance.Material.Body1"
/>
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

<TextView
android:id="@+id/request_permission"
Expand All @@ -85,31 +83,30 @@
android:gravity="center_vertical"
android:minHeight="45dp"
android:text="@string/request_permission"
android:textAppearance="@android:style/TextAppearance.Material.Body1"
/>
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

<TextView
android:id="@+id/enable_proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:background="?android:attr/selectableItemBackground"
android:minHeight="45dp"
android:enabled="false"
android:gravity="center_vertical"
android:textAppearance="@android:style/TextAppearance.Material.Body1"
android:text="@string/enable_proxy" />
android:minHeight="45dp"
android:text="@string/enable_proxy"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

<TextView
android:id="@+id/disable_proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="?android:attr/selectableItemBackground"
android:enabled="true"
android:gravity="center_vertical"
android:minHeight="45dp"
android:text="@string/disable_proxy"
android:textAppearance="@android:style/TextAppearance.Material.Body1"
android:text="@string/disable_proxy" />
android:visibility="gone" />

<TextView
android:id="@+id/set_proxy_address"
Expand Down Expand Up @@ -155,32 +152,53 @@

</ScrollView>

<RelativeLayout
<ScrollView
android:id="@+id/loading"
android:visibility="gone"
tools:visibility="gone"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/black"
android:visibility="gone"
android:nestedScrollingEnabled="true"
android:paddingStart="16dp"
android:paddingEnd="16dp"
tools:visibility="gone">

<TextView
android:id="@+id/textView"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/requesting_permission"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:foregroundGravity="center" />
android:orientation="vertical">

<TextView
android:layout_marginTop="45dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/requesting_permission"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:foregroundGravity="center"
android:indeterminate="true" />

</RelativeLayout>
<TextView
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginBottom="45dp"
android:background="?android:attr/selectableItemBackground"
android:foregroundGravity="center"
android:gravity="center"
android:minHeight="45dp"
android:text="@string/cancel"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />

</LinearLayout>

</ScrollView>
</androidx.wear.widget.BoxInsetLayout>
4 changes: 3 additions & 1 deletion wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<string name="show_me_how">How to enable ADB over Bluetooth?</string>
<string name="title_activity_enable_adbbluetooth">EnableADBBluetoothActivity</string>
<string name="instructions"><![CDATA[Please read carefully:\nTo get started, first enable the Developer Options of your watch, which can be achieved by going to Settings -> 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.]]></string>
<string name="requesting_permission">Requesting permission, this can take a while… \"Allow\" or \"Always allow computer\" if prompted.\nNote: the app works best with WiFi turned OFF.</string>
<string name="requesting_permission">Requesting permission, this can take a while… \"Allow\" or \"Always allow computer\" if prompted.\n\nNote: the app works best with WiFi turned OFF.</string>
<string name="wss_permission_needed">Write secure settings permission needed. This can be enabled via ADB over Bluetooth.</string>
<string name="request_permission">ADB over Bluetooth is enabled, request permission!</string>
<string name="permission_granted">Permission granted,\nADB can be turned off.</string>
Expand All @@ -30,4 +30,6 @@
<string name="current_ext">External IP:</string>
<string name="NA">N/A</string>
<string name="other_apps">Other apps and external IP might take time to update.</string>
<string name="cancel">Cancel</string>
<string name="valid_port">Error: did you enter a valid port?</string>
</resources>

0 comments on commit c4a32fd

Please sign in to comment.