Skip to content

Commit

Permalink
Merge branch 'tytydraco:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kairusds authored Oct 30, 2021
2 parents 9f16487 + 243269d commit cc8cb9c
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 61 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ copy of the Program in return for a fee.
18. Distribution

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

END OF TERMS AND CONDITIONS

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Still not working? Try this:
9. Open LADB

# Credit
Thanks to Surge1223 for precompiling ADB for the ARM/ARM64 architecture.
Thanks to Surge1223 for compiling ADB for the ARM/ARM64 architecture.

# License
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.
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.

Still confused? Email me at [email protected].
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ plugins {
}

android {
compileSdkVersion 30
compileSdk 31

defaultConfig {
applicationId "com.draco.ladb"
minSdkVersion 26
targetSdkVersion 30
versionCode 25
versionName "1.5.1"
minSdk 26
targetSdk 31
versionCode 28
versionName "1.7"

ndk {
abiFilters 'arm64-v8a', 'armeabi-v7a'
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.draco.ladb"
android:installLocation="internalOnly">

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

<application
android:allowBackup="false"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LADB"
android:extractNativeLibs="true">
android:extractNativeLibs="true"
tools:targetApi="m">
<activity android:name=".views.MainActivity"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreference
import androidx.preference.*
import com.draco.ladb.R
import com.draco.ladb.utils.ADB
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
Expand Down Expand Up @@ -36,7 +33,7 @@ class HelpPreferenceFragment : PreferenceFragmentCompat() {
/* Unpair server and client */
with(PreferenceManager.getDefaultSharedPreferences(context).edit()) {
putBoolean(getString(R.string.paired_key), false)
apply()
commit()
}

adb.reset()
Expand All @@ -53,7 +50,7 @@ class HelpPreferenceFragment : PreferenceFragmentCompat() {
}

else -> {
if (preference !is SwitchPreference) {
if (preference !is SwitchPreference && preference !is EditTextPreference) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(preference.title)
.setMessage(preference.summary)
Expand Down
69 changes: 43 additions & 26 deletions app/src/main/java/com/draco/ladb/utils/ADB.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.draco.ladb.utils

import android.content.Context
import android.os.Build
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
Expand All @@ -12,6 +13,7 @@ import kotlinx.coroutines.launch
import java.io.File
import java.io.IOException
import java.io.PrintStream
import java.lang.NumberFormatException

class ADB(private val context: Context) {
companion object {
Expand Down Expand Up @@ -53,6 +55,18 @@ class ADB(private val context: Context) {
*/
private var shellProcess: Process? = null

/**
* Returns the user buffer size if valid, else the default
*/
fun getOutputBufferSize(): Int {
val userValue = sharedPrefs.getString(context.getString(R.string.buffer_size_key), "16384")!!
return try {
Integer.parseInt(userValue)
} catch (_: NumberFormatException) {
MAX_OUTPUT_BUFFER_SIZE
}
}

/**
* Decide how to initialize the shellProcess variable
*/
Expand All @@ -61,47 +75,50 @@ class ADB(private val context: Context) {
return

val autoShell = sharedPrefs.getBoolean(context.getString(R.string.auto_shell_key), true)
if (autoShell)
initializeADBShell()
else
initializeShell()
val autoPair = sharedPrefs.getBoolean(context.getString(R.string.auto_pair_key), true)
val startupCommand = sharedPrefs.getString(context.getString(R.string.startup_command_key), "echo 'Success! ※\\(^o^)/※'")!!

initializeADBShell(autoShell, autoPair, startupCommand)
}

/**
* Scan and make a connection to a wireless device
*/
private fun initializeADBShell() {
debug("Starting ADB client")
adb(false, listOf("start-server"))?.waitFor()
debug("Waiting for device to be found")
adb(false, listOf("wait-for-device"))?.waitFor()

debug("Shelling into device")
val process = adb(true, listOf("-t", "1", "shell"))
if (process == null) {
debug("Failed to open shell connection")
return
private fun initializeADBShell(autoShell: Boolean, autoPair: Boolean, startupCommand: String) {
if (autoPair) {
debug("Starting ADB client")
adb(false, listOf("start-server"))?.waitFor()
debug("Waiting for device respond (max 5m)")
adb(false, listOf("wait-for-device"))?.waitFor()
}
shellProcess = process
sendToShellProcess("echo 'Success! ※\\(^o^)/※'")
_ready.postValue(true)

startShellDeathThread()
}

/**
* Make a local shell instance
*/
private fun initializeShell() {
debug("Shelling into device")
val process = shell(true, listOf("sh", "-l"))
val process = if (autoShell && autoPair) {
val argList = if (Build.SUPPORTED_ABIS[0] == "arm64-v8a")
listOf("-t", "1", "shell")
else
listOf("shell")
adb(true, argList)
} else
shell(true, listOf("sh", "-l"))

if (process == null) {
debug("Failed to open shell connection")
return
}
shellProcess = process

sendToShellProcess("alias adb=\"$adbPath\"")
sendToShellProcess("echo 'Success! ※\\(^o^)/※'")

if (autoShell && autoPair)
sendToShellProcess("echo 'NOTE: Dropped into ADB shell automatically'")
else
sendToShellProcess("echo 'NOTE: In unprivileged shell, not ADB shell'")

if (startupCommand.isNotEmpty())
sendToShellProcess(startupCommand)

_ready.postValue(true)

startShellDeathThread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
private val _outputText = MutableLiveData<String>()
val outputText: LiveData<String> = _outputText

var checker: PiracyChecker? = null
private var checker: PiracyChecker? = null
private val sharedPreferences = application
.applicationContext
.getSharedPreferences(
Expand Down Expand Up @@ -128,7 +128,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
* Read the content of the ABD output file
*/
private fun readOutputFile(file: File): String {
val out = ByteArray(ADB.MAX_OUTPUT_BUFFER_SIZE)
val out = ByteArray(adb.getOutputBufferSize())

synchronized(file) {
if (!file.exists())
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/draco/ladb/views/HelpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.draco.ladb.views

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.draco.ladb.R
import com.draco.ladb.fragments.HelpPreferenceFragment

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/draco/ladb/views/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class MainActivity : AppCompatActivity() {
/* Held when pairing */
private var pairingLatch = CountDownLatch(0)

private var lastCommand = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -59,6 +61,7 @@ class MainActivity : AppCompatActivity() {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (event.action == KeyEvent.ACTION_DOWN) {
val text = command.text.toString()
lastCommand = text
command.text = null
lifecycleScope.launch(Dispatchers.IO) {
viewModel.adb.sendToShellProcess(text)
Expand Down Expand Up @@ -172,6 +175,11 @@ class MainActivity : AppCompatActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.last_command -> {
command.setText(lastCommand)
command.setSelection(lastCommand.length)
true
}
R.id.help -> {
val intent = Intent(this, HelpActivity::class.java)
startActivity(intent)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_restore_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
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"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|text"
android:inputType="textFilter"
android:hint="@string/command_hint"
android:enabled="false"
android:id="@+id/command" />
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/last_command"
android:title="@string/last_command"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_baseline_restore_24dp" />
<item
android:id="@+id/share"
android:title="@string/share"
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

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

<string name="last_command">Last command</string>
<string name="help">Help</string>
<string name="share">Share</string>
<string name="clear">Clear screen</string>

<string name="snackbar_intent_failed">Failed to share log</string>
<string name="snackbar_file_opened">Executing script from file</string>
<string name="dismiss">Dismiss</string>
<string name="reset">Reset</string>
<string name="okay">Okay</string>

<string name="developer_url">https://www.github.com/tytydraco</string>
Expand All @@ -27,7 +27,7 @@
<string name="pair_title">Pairing information</string>
<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>

<string name="actions">Actions</string>
<string name="settings">Settings</string>
<string name="troubleshooting">Troubleshooting</string>
<string name="about">About</string>

Expand All @@ -37,13 +37,25 @@

<string name="auto_shell_title">Auto ADB Shell</string>
<string name="auto_shell_summary">Automatically enter the ADB shell</string>
<string name="auto_shell_key">no_adb</string>
<string name="auto_shell_key">auto_shell</string>

<string name="auto_pair_title">Auto pair</string>
<string name="auto_pair_summary">Attempt to automatically pair with ADB and wait for device to connect</string>
<string name="auto_pair_key">auto_pair</string>

<string name="buffer_size_title">Buffer size</string>
<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>
<string name="buffer_size_key">buffer_size</string>

<string name="startup_command_title">Startup command</string>
<string name="startup_command_summary">The command to run once the shell has begun</string>
<string name="startup_command_key">startup_command</string>

<string name="tutorial_title">Tutorial</string>
<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>

<string name="error_waiting_title">Stuck on \"Waiting\"</string>
<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>
<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>

<string name="error_no_wireless_debugging_title">No \"Wireless Debugging\" toggle</string>
<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>
Expand All @@ -55,7 +67,7 @@
<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>

<string name="error_inaccessible_title">Inaccessible or not found</string>
<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>
<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>

<string name="error_failed_to_find_title">Failed to find ADB server binary</string>
<string name="error_failed_to_find_summary">The ADB server binary was never extracted from the application files. Try reinstalling the application.</string>
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/res/xml/help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:title="@string/actions">
android:title="@string/settings">
<Preference
android:icon="@drawable/ic_baseline_refresh_24"
android:title="@string/reset_title"
Expand All @@ -13,7 +13,26 @@
android:title="@string/auto_shell_title"
android:summary="@string/auto_shell_summary"
android:key="@string/auto_shell_key"
android:dependency="@string/auto_pair_key"
android:defaultValue="true"/>
<SwitchPreference
android:icon="@drawable/ic_baseline_home_repair_service_24"
android:title="@string/auto_pair_title"
android:summary="@string/auto_pair_summary"
android:key="@string/auto_pair_key"
android:defaultValue="true"/>
<EditTextPreference
android:icon="@drawable/ic_baseline_home_repair_service_24"
android:title="@string/buffer_size_title"
android:summary="@string/buffer_size_summary"
android:key="@string/buffer_size_key"
android:defaultValue="16384"/>
<EditTextPreference
android:icon="@drawable/ic_baseline_home_repair_service_24"
android:title="@string/startup_command_title"
android:summary="@string/startup_command_summary"
android:key="@string/startup_command_key"
android:defaultValue="echo 'Success! ※\\(^o^)/※'"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/troubleshooting">
Expand Down
Loading

0 comments on commit cc8cb9c

Please sign in to comment.