Skip to content

Commit cc8cb9c

Browse files
authored
Merge branch 'tytydraco:main' into main
2 parents 9f16487 + 243269d commit cc8cb9c

File tree

16 files changed

+130
-61
lines changed

16 files changed

+130
-61
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ copy of the Program in return for a fee.
621621
18. Distribution
622622

623623
This term supersedes prior and subsequent distribution restrictions.
624-
Under no circumstances shall this project be reuploaded to APK-distribution
625-
websites, including (but not limited to) the Google Play Store.
624+
Under no circumstances shall this project be uploaded to the Google Play Store
625+
by anyone except for the original developer.
626626

627627
END OF TERMS AND CONDITIONS
628628

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Still not working? Try this:
2727
9. Open LADB
2828

2929
# Credit
30-
Thanks to Surge1223 for precompiling ADB for the ARM/ARM64 architecture.
30+
Thanks to Surge1223 for compiling ADB for the ARM/ARM64 architecture.
3131

3232
# License
33-
While this project is GPLv3 licensed, I would like to add an additional parameter: no recompilations of the app are to be placed on the Google Play Store or any alternative APK-providing websites.
33+
While this project is GPLv3 licensed, I would like to add an additional parameter: please do not publish unofficial (user) LADB builds to the Google Play Store.
3434

3535
Still confused? Email me at [email protected].

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ plugins {
55
}
66

77
android {
8-
compileSdkVersion 30
8+
compileSdk 31
99

1010
defaultConfig {
1111
applicationId "com.draco.ladb"
12-
minSdkVersion 26
13-
targetSdkVersion 30
14-
versionCode 25
15-
versionName "1.5.1"
12+
minSdk 26
13+
targetSdk 31
14+
versionCode 28
15+
versionName "1.7"
1616

1717
ndk {
1818
abiFilters 'arm64-v8a', 'armeabi-v7a'

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.draco.ladb"
45
android:installLocation="internalOnly">
56

67
<uses-permission android:name="android.permission.INTERNET" />
78

89
<application
9-
android:allowBackup="false"
10+
android:allowBackup="true"
1011
android:icon="@mipmap/ic_launcher"
1112
android:label="@string/app_name"
1213
android:roundIcon="@mipmap/ic_launcher_round"
1314
android:supportsRtl="true"
1415
android:theme="@style/Theme.LADB"
15-
android:extractNativeLibs="true">
16+
android:extractNativeLibs="true"
17+
tools:targetApi="m">
1618
<activity android:name=".views.MainActivity"
1719
android:exported="true">
1820
<intent-filter>

app/src/main/java/com/draco/ladb/fragments/HelpPreferenceFragment.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import android.content.Intent
55
import android.net.Uri
66
import android.os.Bundle
77
import androidx.lifecycle.lifecycleScope
8-
import androidx.preference.Preference
9-
import androidx.preference.PreferenceFragmentCompat
10-
import androidx.preference.PreferenceManager
11-
import androidx.preference.SwitchPreference
8+
import androidx.preference.*
129
import com.draco.ladb.R
1310
import com.draco.ladb.utils.ADB
1411
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
@@ -36,7 +33,7 @@ class HelpPreferenceFragment : PreferenceFragmentCompat() {
3633
/* Unpair server and client */
3734
with(PreferenceManager.getDefaultSharedPreferences(context).edit()) {
3835
putBoolean(getString(R.string.paired_key), false)
39-
apply()
36+
commit()
4037
}
4138

4239
adb.reset()
@@ -53,7 +50,7 @@ class HelpPreferenceFragment : PreferenceFragmentCompat() {
5350
}
5451

5552
else -> {
56-
if (preference !is SwitchPreference) {
53+
if (preference !is SwitchPreference && preference !is EditTextPreference) {
5754
MaterialAlertDialogBuilder(requireContext())
5855
.setTitle(preference.title)
5956
.setMessage(preference.summary)

app/src/main/java/com/draco/ladb/utils/ADB.kt

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.draco.ladb.utils
22

33
import android.content.Context
4+
import android.os.Build
45
import androidx.lifecycle.LiveData
56
import androidx.lifecycle.MutableLiveData
67
import androidx.preference.PreferenceManager
@@ -12,6 +13,7 @@ import kotlinx.coroutines.launch
1213
import java.io.File
1314
import java.io.IOException
1415
import java.io.PrintStream
16+
import java.lang.NumberFormatException
1517

1618
class ADB(private val context: Context) {
1719
companion object {
@@ -53,6 +55,18 @@ class ADB(private val context: Context) {
5355
*/
5456
private var shellProcess: Process? = null
5557

58+
/**
59+
* Returns the user buffer size if valid, else the default
60+
*/
61+
fun getOutputBufferSize(): Int {
62+
val userValue = sharedPrefs.getString(context.getString(R.string.buffer_size_key), "16384")!!
63+
return try {
64+
Integer.parseInt(userValue)
65+
} catch (_: NumberFormatException) {
66+
MAX_OUTPUT_BUFFER_SIZE
67+
}
68+
}
69+
5670
/**
5771
* Decide how to initialize the shellProcess variable
5872
*/
@@ -61,47 +75,50 @@ class ADB(private val context: Context) {
6175
return
6276

6377
val autoShell = sharedPrefs.getBoolean(context.getString(R.string.auto_shell_key), true)
64-
if (autoShell)
65-
initializeADBShell()
66-
else
67-
initializeShell()
78+
val autoPair = sharedPrefs.getBoolean(context.getString(R.string.auto_pair_key), true)
79+
val startupCommand = sharedPrefs.getString(context.getString(R.string.startup_command_key), "echo 'Success! ※\\(^o^)/※'")!!
80+
81+
initializeADBShell(autoShell, autoPair, startupCommand)
6882
}
6983

7084
/**
7185
* Scan and make a connection to a wireless device
7286
*/
73-
private fun initializeADBShell() {
74-
debug("Starting ADB client")
75-
adb(false, listOf("start-server"))?.waitFor()
76-
debug("Waiting for device to be found")
77-
adb(false, listOf("wait-for-device"))?.waitFor()
78-
79-
debug("Shelling into device")
80-
val process = adb(true, listOf("-t", "1", "shell"))
81-
if (process == null) {
82-
debug("Failed to open shell connection")
83-
return
87+
private fun initializeADBShell(autoShell: Boolean, autoPair: Boolean, startupCommand: String) {
88+
if (autoPair) {
89+
debug("Starting ADB client")
90+
adb(false, listOf("start-server"))?.waitFor()
91+
debug("Waiting for device respond (max 5m)")
92+
adb(false, listOf("wait-for-device"))?.waitFor()
8493
}
85-
shellProcess = process
86-
sendToShellProcess("echo 'Success! ※\\(^o^)/※'")
87-
_ready.postValue(true)
8894

89-
startShellDeathThread()
90-
}
9195

92-
/**
93-
* Make a local shell instance
94-
*/
95-
private fun initializeShell() {
9696
debug("Shelling into device")
97-
val process = shell(true, listOf("sh", "-l"))
97+
val process = if (autoShell && autoPair) {
98+
val argList = if (Build.SUPPORTED_ABIS[0] == "arm64-v8a")
99+
listOf("-t", "1", "shell")
100+
else
101+
listOf("shell")
102+
adb(true, argList)
103+
} else
104+
shell(true, listOf("sh", "-l"))
105+
98106
if (process == null) {
99107
debug("Failed to open shell connection")
100108
return
101109
}
102110
shellProcess = process
111+
103112
sendToShellProcess("alias adb=\"$adbPath\"")
104-
sendToShellProcess("echo 'Success! ※\\(^o^)/※'")
113+
114+
if (autoShell && autoPair)
115+
sendToShellProcess("echo 'NOTE: Dropped into ADB shell automatically'")
116+
else
117+
sendToShellProcess("echo 'NOTE: In unprivileged shell, not ADB shell'")
118+
119+
if (startupCommand.isNotEmpty())
120+
sendToShellProcess(startupCommand)
121+
105122
_ready.postValue(true)
106123

107124
startShellDeathThread()

app/src/main/java/com/draco/ladb/viewmodels/MainActivityViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
2626
private val _outputText = MutableLiveData<String>()
2727
val outputText: LiveData<String> = _outputText
2828

29-
var checker: PiracyChecker? = null
29+
private var checker: PiracyChecker? = null
3030
private val sharedPreferences = application
3131
.applicationContext
3232
.getSharedPreferences(
@@ -128,7 +128,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
128128
* Read the content of the ABD output file
129129
*/
130130
private fun readOutputFile(file: File): String {
131-
val out = ByteArray(ADB.MAX_OUTPUT_BUFFER_SIZE)
131+
val out = ByteArray(adb.getOutputBufferSize())
132132

133133
synchronized(file) {
134134
if (!file.exists())

app/src/main/java/com/draco/ladb/views/HelpActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.draco.ladb.views
22

33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
5-
import androidx.lifecycle.ViewModelProvider
65
import com.draco.ladb.R
76
import com.draco.ladb.fragments.HelpPreferenceFragment
87

app/src/main/java/com/draco/ladb/views/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class MainActivity : AppCompatActivity() {
4040
/* Held when pairing */
4141
private var pairingLatch = CountDownLatch(0)
4242

43+
private var lastCommand = ""
44+
4345
override fun onCreate(savedInstanceState: Bundle?) {
4446
super.onCreate(savedInstanceState)
4547
setContentView(R.layout.activity_main)
@@ -59,6 +61,7 @@ class MainActivity : AppCompatActivity() {
5961
if (keyCode == KeyEvent.KEYCODE_ENTER) {
6062
if (event.action == KeyEvent.ACTION_DOWN) {
6163
val text = command.text.toString()
64+
lastCommand = text
6265
command.text = null
6366
lifecycleScope.launch(Dispatchers.IO) {
6467
viewModel.adb.sendToShellProcess(text)
@@ -172,6 +175,11 @@ class MainActivity : AppCompatActivity() {
172175

173176
override fun onOptionsItemSelected(item: MenuItem): Boolean {
174177
return when (item.itemId) {
178+
R.id.last_command -> {
179+
command.setText(lastCommand)
180+
command.setSelection(lastCommand.length)
181+
true
182+
}
175183
R.id.help -> {
176184
val intent = Intent(this, HelpActivity::class.java)
177185
startActivity(intent)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M13,3c-4.97,0-9,4.03-9,9H1l4,3.99L9,12H6c0-3.87,3.13-7,7-7s7,3.13,7,7-3.13,7-7,7c-1.93,0-3.68-.79-4.94-2.06l-1.42,1.42C8.27,19.99,10.51,21,13,21c4.97,0,9-4.03,9-9s-4.03-9-9-9zm-1,5v5l4.25,2.52.77-1.28-3.52-2.09V8z"/>
10+
</vector>

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<com.google.android.material.textfield.TextInputEditText
4141
android:layout_width="match_parent"
4242
android:layout_height="wrap_content"
43-
android:inputType="textNoSuggestions|text"
43+
android:inputType="textFilter"
4444
android:hint="@string/command_hint"
4545
android:enabled="false"
4646
android:id="@+id/command" />

app/src/main/res/menu/main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/last_command"
6+
android:title="@string/last_command"
7+
app:showAsAction="ifRoom"
8+
android:icon="@drawable/ic_baseline_restore_24dp" />
49
<item
510
android:id="@+id/share"
611
android:title="@string/share"

app/src/main/res/values/strings.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
<string name="command_hint">Shell command</string>
55

6+
<string name="last_command">Last command</string>
67
<string name="help">Help</string>
78
<string name="share">Share</string>
89
<string name="clear">Clear screen</string>
910

1011
<string name="snackbar_intent_failed">Failed to share log</string>
1112
<string name="snackbar_file_opened">Executing script from file</string>
1213
<string name="dismiss">Dismiss</string>
13-
<string name="reset">Reset</string>
1414
<string name="okay">Okay</string>
1515

1616
<string name="developer_url">https://www.github.com/tytydraco</string>
@@ -27,7 +27,7 @@
2727
<string name="pair_title">Pairing information</string>
2828
<string name="pair_message">You can find the port and the 6-digit pairing code here: Settings -> Developer Settings -> Wireless Debugging. Open LADB and Settings using <b>Split Screen</b> to prevent the code from changing.</string>
2929

30-
<string name="actions">Actions</string>
30+
<string name="settings">Settings</string>
3131
<string name="troubleshooting">Troubleshooting</string>
3232
<string name="about">About</string>
3333

@@ -37,13 +37,25 @@
3737

3838
<string name="auto_shell_title">Auto ADB Shell</string>
3939
<string name="auto_shell_summary">Automatically enter the ADB shell</string>
40-
<string name="auto_shell_key">no_adb</string>
40+
<string name="auto_shell_key">auto_shell</string>
41+
42+
<string name="auto_pair_title">Auto pair</string>
43+
<string name="auto_pair_summary">Attempt to automatically pair with ADB and wait for device to connect</string>
44+
<string name="auto_pair_key">auto_pair</string>
45+
46+
<string name="buffer_size_title">Buffer size</string>
47+
<string name="buffer_size_summary">The size of the screen output buffer. Increasing this value will show more output on the screen at once at the cost of performance. (Default: 16384)</string>
48+
<string name="buffer_size_key">buffer_size</string>
49+
50+
<string name="startup_command_title">Startup command</string>
51+
<string name="startup_command_summary">The command to run once the shell has begun</string>
52+
<string name="startup_command_key">startup_command</string>
4153

4254
<string name="tutorial_title">Tutorial</string>
4355
<string name="tutorial_summary">The initial steps to setup LADB are as follows. First, enable Developer Settings by tapping on the Build Number rapidly. Next, enter Developer Settings and enable Wireless Debugging. Next, enable USB Debugging. <b>It must occur in this order for some devices</b>. Restart LADB and grant it permission when it asks.</string>
4456

4557
<string name="error_waiting_title">Stuck on \"Waiting\"</string>
46-
<string name="error_waiting_summary">This is the most common issue. First, make sure you follow the Tutorial steps. Then, try first restarting the app. If the issue is still occurring, reboot the device.</string>
58+
<string name="error_waiting_summary">This is the most common issue. First, make sure you follow the Tutorial steps. Then, try clearing the app data and restarting the app. If the issue is still occurring, reboot the device.</string>
4759

4860
<string name="error_no_wireless_debugging_title">No \"Wireless Debugging\" toggle</string>
4961
<string name="error_no_wireless_debugging_summary">Your device does not natively support Wireless Debugging, which is required by LADB. Alternatively, you can use a PC to enable this feature, even on unsupported features. It will last until the next reboot. Connect the device and type: adb tcpip 5555</string>
@@ -55,7 +67,7 @@
5567
<string name="error_pairing_client_summary">The most likely scenario for this error is an incorrectly entered port or pairing code. The port should always be followed by the colon. For example, 50123. The pairing code is six digits, it is the number that is on its own.</string>
5668

5769
<string name="error_inaccessible_title">Inaccessible or not found</string>
58-
<string name="error_inaccessible_summary">You have most likely written a command that is not valid. Remember, LADB is the equivalent of having already ran \"adb shell\".</string>
70+
<string name="error_inaccessible_summary">You have most likely written a command that is not valid. Remember, LADB is the equivalent of having already ran \"adb shell\" by default. See the Auto ADB Shell toggle.</string>
5971

6072
<string name="error_failed_to_find_title">Failed to find ADB server binary</string>
6173
<string name="error_failed_to_find_summary">The ADB server binary was never extracted from the application files. Try reinstalling the application.</string>

app/src/main/res/xml/help.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44
<PreferenceCategory
5-
android:title="@string/actions">
5+
android:title="@string/settings">
66
<Preference
77
android:icon="@drawable/ic_baseline_refresh_24"
88
android:title="@string/reset_title"
@@ -13,7 +13,26 @@
1313
android:title="@string/auto_shell_title"
1414
android:summary="@string/auto_shell_summary"
1515
android:key="@string/auto_shell_key"
16+
android:dependency="@string/auto_pair_key"
1617
android:defaultValue="true"/>
18+
<SwitchPreference
19+
android:icon="@drawable/ic_baseline_home_repair_service_24"
20+
android:title="@string/auto_pair_title"
21+
android:summary="@string/auto_pair_summary"
22+
android:key="@string/auto_pair_key"
23+
android:defaultValue="true"/>
24+
<EditTextPreference
25+
android:icon="@drawable/ic_baseline_home_repair_service_24"
26+
android:title="@string/buffer_size_title"
27+
android:summary="@string/buffer_size_summary"
28+
android:key="@string/buffer_size_key"
29+
android:defaultValue="16384"/>
30+
<EditTextPreference
31+
android:icon="@drawable/ic_baseline_home_repair_service_24"
32+
android:title="@string/startup_command_title"
33+
android:summary="@string/startup_command_summary"
34+
android:key="@string/startup_command_key"
35+
android:defaultValue="echo 'Success! ※\\(^o^)/※'"/>
1736
</PreferenceCategory>
1837
<PreferenceCategory
1938
android:title="@string/troubleshooting">

0 commit comments

Comments
 (0)