Skip to content

Commit

Permalink
v3.2:
Browse files Browse the repository at this point in the history
Fixed no-internet crash bug
Ridiculous the lengths I have to go to to explain Google the app does NOT get stuck but is simply loading...

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 works better!
Added clearer loading screen and easier setup
ADB over Bluetooth only needs to be enabled the first time
Faster proxy switching with WRITE_SECURE_SETTINGS
  • Loading branch information
Jolanrensen committed Oct 17, 2019
1 parent c4a32fd commit 839ee6d
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 102 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 7
versionName "3.1"
versionCode 8
versionName "3.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
4 changes: 2 additions & 2 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 7
versionName "3.1"
versionCode 8
versionName "3.2"
}
buildTypes {
release {
Expand Down
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.
4 changes: 3 additions & 1 deletion wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

<activity
android:name=".EnableADBBluetoothActivity"
android:label="@string/title_activity_enable_adbbluetooth"></activity>
android:label="@string/title_activity_enable_adbbluetooth">
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
Expand All @@ -46,6 +47,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RequestPermissionActivity" />

</application>

Expand Down
63 changes: 17 additions & 46 deletions wear/src/main/java/nl/jolanrensen/permanentproxy/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,26 @@ import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import nl.jolanrensen.permanentproxy.Constants.PORT
import nl.jolanrensen.permanentproxy.Constants.currentProxy
import nl.jolanrensen.permanentproxy.Constants.getCurrentIP
import nl.jolanrensen.permanentproxy.Constants.logD
import nl.jolanrensen.permanentproxy.Constants.logE
import nl.jolanrensen.permanentproxy.Constants.startProxy
import nl.jolanrensen.permanentproxy.Constants.stopProxy
import nl.jolanrensen.permanentproxy.Constants.toastLong
import kotlin.concurrent.thread

class MainActivity : WearableActivity() {

var p: SharedPreferences? = null
@Volatile
var currentADBProcess: SendSingleCommand? = null
private var p: SharedPreferences? = null

val PERMISSION = 23

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

p = getSharedPreferences(packageName, Context.MODE_PRIVATE)


getCurrentIP {
logE("current IP is $it")
runOnUiThread {
Expand Down Expand Up @@ -86,47 +84,12 @@ class MainActivity : WearableActivity() {
}

request_permission.setOnClickListener {
loading.isVisible = true
loading.requestFocus()
thread(start = true) {
val logs = arrayListOf<String>()
try {
currentADBProcess = SendSingleCommand(
logs = logs,
context = this,
ip = "localhost",
port = PORT,
command = "pm grant \\\nnl.jolanrensen.permanentproxy \\\nandroid.permission.WRITE_SECURE_SETTINGS",
timeout = 4000,
ctrlC = false
) {
currentADBProcess = null
logD(it.toString())
runOnUiThread {
loading.isVisible = false
if (checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS")
== PackageManager.PERMISSION_GRANTED
) {
continueSetup()
toastLong(getString(R.string.permission_granted))
} else {
toastLong(getString(R.string.something_wrong))
}
}
}
} catch (e: Exception) {
currentADBProcess = null
logE("$logs", e)
runOnUiThread {
loading.isVisible = false
toastLong(getString(R.string.something_wrong))
}
}
}
}
startActivityForResult(
Intent(this, RequestPermissionActivity::class.java),
PERMISSION

)

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

Expand Down Expand Up @@ -302,4 +265,12 @@ class MainActivity : WearableActivity() {
if (child is ViewGroup) setAllEnabled(child, *except)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when {
requestCode == PERMISSION && resultCode == RESULT_OK -> {
continueSetup()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package nl.jolanrensen.permanentproxy

import android.app.Activity
import android.content.pm.PackageManager
import android.os.Bundle
import android.support.wearable.activity.WearableActivity
import kotlinx.android.synthetic.main.activity_request_permission.*
import nl.jolanrensen.permanentproxy.Constants.logE
import nl.jolanrensen.permanentproxy.Constants.toastLong
import kotlin.concurrent.thread

class RequestPermissionActivity : WearableActivity() {

@Volatile
var currentADBProcess: SendSingleCommand? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_request_permission)

cancel.setOnClickListener {
finish()
}

thread(start = true) {
val logs = arrayListOf<String>()
try {
currentADBProcess = SendSingleCommand(
logs = logs,
context = this,
ip = "localhost",
port = Constants.PORT,
command = "pm grant \\\nnl.jolanrensen.permanentproxy \\\nandroid.permission.WRITE_SECURE_SETTINGS",
timeout = 4000,
ctrlC = false
) {
currentADBProcess = null
Constants.logD(it.toString())
runOnUiThread {
if (checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS")
== PackageManager.PERMISSION_GRANTED
) {
toastLong(getString(R.string.permission_granted))
setResult(Activity.RESULT_OK)
} else {
toastLong(getString(R.string.something_wrong))
}
finish()
}
}
} catch (e: Exception) {
currentADBProcess = null
logE("$logs", e)
runOnUiThread {
toastLong(getString(R.string.something_wrong))
finish()
}
}
}
}

override fun onStop() {
currentADBProcess?.cancel()
logE("requesting permission canceled")
super.onStop()
}
}
52 changes: 1 addition & 51 deletions wear/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:background="@color/black"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:context=".RequestPermissionActivity"
tools:deviceIds="wear">

<ScrollView
Expand Down Expand Up @@ -151,54 +151,4 @@
</LinearLayout>

</ScrollView>

<ScrollView
android:id="@+id/loading"
android:layout_width="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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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" />

<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>
56 changes: 56 additions & 0 deletions wear/src/main/res/layout/activity_request_permission.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".RequestPermissionActivity"
tools:deviceIds="wear">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:paddingStart="16dp"
android:paddingEnd="16dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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" />

<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>

0 comments on commit 839ee6d

Please sign in to comment.