Skip to content

Commit

Permalink
Fix up
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Nijmeh <tylernij@gmail.com>
  • Loading branch information
tytydraco committed Mar 25, 2023
1 parent e11b862 commit 87e8f3c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 62 deletions.
28 changes: 12 additions & 16 deletions app/src/main/java/com/draco/ladb/utils/ADB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class ADB(private val context: Context) {

private val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)

private val adbPath = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
"${context.applicationInfo.nativeLibraryDir}/libadb12.so"
else
"${context.applicationInfo.nativeLibraryDir}/libadb.so"
private val adbPath = "${context.applicationInfo.nativeLibraryDir}/libadb.so"
private val scriptPath = "${context.getExternalFilesDir(null)}/script.sh"

/**
Expand Down Expand Up @@ -92,23 +89,21 @@ class ADB(private val context: Context) {
/* Only do wireless debugging steps on compatible versions */
if (secureSettingsGranted) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !isWirelessDebuggingEnabled()) {
debug("Enabling wireless debugging...")
Settings.Global.putInt(
context.contentResolver,
"adb_wifi_enabled",
1
)

Thread.sleep(3_000)
Thread.sleep(2_000)
} else if (!isUSBDebuggingEnabled()) {
debug("Enabling USB debugging...")
Settings.Global.putInt(
context.contentResolver,
Settings.Global.ADB_ENABLED,
1
)

Thread.sleep(3_000)
Thread.sleep(2_000)
}
}

Expand All @@ -131,23 +126,19 @@ class ADB(private val context: Context) {
}
}

debug("Starting ADB server...")
adb(false, listOf("start-server")).waitFor()
debug("Waiting for device to connect...")
debug("This may take up to 2 minutes")
val waitProcess = adb(false, listOf("wait-for-device")).waitFor(2, TimeUnit.MINUTES)
debug("This may take a minute")
val waitProcess = adb(false, listOf("wait-for-device")).waitFor(1, TimeUnit.MINUTES)
if (!waitProcess) {
debug("Could not detect any devices")
debug("Fix 1) Toggle Wi-Fi or reboot")
debug("Fix 2) Re-enter pairing information (More -> Factory Reset)")
debug("To try again, restart the server (More -> Restart)")
debug("Your device didn't connect to LADB")
debug("If a reboot doesn't work, please contact support")

tryingToPair = false
return false
}
}

debug("Shelling into device")
shellProcess = if (autoShell) {
val argList = if (Build.SUPPORTED_ABIS[0] == "arm64-v8a")
listOf("-t", "1", "shell")
Expand Down Expand Up @@ -219,6 +210,11 @@ class ADB(private val context: Context) {
/* Continue once finished pairing (or 10s elapses) */
pairShell.waitFor(10, TimeUnit.SECONDS)
pairShell.destroyForcibly().waitFor()

val killShell = adb(false, listOf("kill-server"))
killShell.waitFor(3, TimeUnit.SECONDS)
killShell.destroyForcibly()

return pairShell.exitValue() == 0
}

Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/com/draco/ladb/views/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.draco.ladb.views

import android.content.ComponentName
import android.content.Intent
import android.net.Uri
import android.os.Bundle
Expand Down Expand Up @@ -49,7 +48,6 @@ class MainActivity : AppCompatActivity() {
.setView(R.layout.dialog_pair)
.setPositiveButton(R.string.pair, null)
.setNegativeButton(R.string.help, null)
.setNeutralButton(R.string.settings, null)

binding.command.setOnKeyListener { _, keyCode, keyEvent ->
if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_DOWN) {
Expand Down Expand Up @@ -165,28 +163,6 @@ class MainActivity : AppCompatActivity() {
}
}

getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
val intent = Intent(Intent.ACTION_MAIN).setComponent(
ComponentName(
"com.android.settings",
"com.android.settings.Settings\$DevelopmentSettingsDashboardActivity"
)
)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT)

try {
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
Snackbar.make(
binding.output,
getString(R.string.snackbar_intent_failed),
Snackbar.LENGTH_SHORT
)
.show()
}
}

getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.tutorial_url)))
try {
Expand Down
Binary file removed app/src/main/jniLibs/arm64-v8a/libadb12.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/armeabi-v7a/libadb12.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/x86/libadb12.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/x86_64/libadb12.so
Binary file not shown.
11 changes: 1 addition & 10 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<string name="developer_url">https://www.github.com/tytydraco</string>
<string name="source_url">https://www.github.com/tytydraco/LADB</string>
<string name="contact_url">mailto:tylernij+LADB@gmail.com</string>
<string name="contact_url">mailto:tnnijmeh@gmail.com</string>
<string name="tutorial_url">https://www.xda-developers.com/debloat-your-phone-run-adb-shell-commands-no-root-no-pc</string>

<string name="paired_key">paired</string>
Expand Down Expand Up @@ -70,15 +70,6 @@
<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 devices. It will last until the next reboot. Connect the device to a PC and type: adb tcpip 5555</string>

<string name="error_more_than_one_title">More than one device connected</string>
<string name="error_more_than_one_summary">This error can often, it can be fixed by rebooting the device. Another possible way to fix this for Android 10 users and below is to enable Airplane Mode before launching the app. Remember that after rebooting the device, Wireless Debugging may turn off and need to be turned on again.</string>

<string name="error_pairing_client_title">Unable to start pairing client</string>
<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\" by default. See the \"Pair &amp; shell\" toggle.</string>

<string name="developer_title">Developer</string>
<string name="developer_summary">Tyler Nijmeh</string>
<string name="developer_key">developer</string>
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/xml/help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@
android:icon="@drawable/ic_baseline_error_24"
android:summary="@string/error_no_wireless_debugging_summary"
android:title="@string/error_no_wireless_debugging_title" />
<Preference
android:icon="@drawable/ic_baseline_error_24"
android:summary="@string/error_more_than_one_summary"
android:title="@string/error_more_than_one_title" />
<Preference
android:icon="@drawable/ic_baseline_error_24"
android:summary="@string/error_pairing_client_summary"
android:title="@string/error_pairing_client_title" />
<Preference
android:icon="@drawable/ic_baseline_error_24"
android:summary="@string/error_inaccessible_summary"
android:title="@string/error_inaccessible_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/about">
<Preference
Expand Down

0 comments on commit 87e8f3c

Please sign in to comment.