Turn on ADB remotely via USB - android

I'am trying to automate some tests and for that I need to launch some ADB commands. The problem is that I need to do a Factory Data Reset during the tests, and after that the USB Debugging option is disabled.
Do you guys know a way to turn it on without touching the device?

When your development process has progressed to the point of using automated tests - it's a good idea to start using a dedicated development device for testing - the one with an unlocked bootloader and a development Android build loaded.
You can customize such device so it would have USB Debugging enabled by default after FDR and even have your public RSA key preloaded (so your PC will be automatically authenticated by your device).

For obvious security reasons, you can't force-enable USB Debugging on a device.
Plus, if there were a "command" to enable USB Debugging, it would require USB Debugging to be executed.

Related

How to debug application on real device by using WIFI while not being able to use cable at all

My MacBook computer battery is broken and somehow it has not enough power to power device by usb-c adapter so I cannot connect anything and only have to use android emulator. But I need to debug on real device while testing some ocr sdk that obviously don't want to recognize anything in android emulator virtual scene. I asked other question about that but still I am puzzled by this inability to use WIFI for usb debugging because sdk runs fine on my phone but to debug using fabric and APK deployment is really horrible dev experience and productivity.
Is there some way I can setup WIFI debugging without cable at all... Maybe I need to root my device but again how to do it without cable, it seems impossible either way. I feel in like in dead and but still asking question here. I have computer and phone but cannot connect them for debugging by wifi.
Afraid I don't have an easy wireless solution. The closest thing I could find is that android wearables may have a debug over bluetooth feature, but it's built to route through another (wired) android device.
There is likely a feasible wired solution though- you can hook the device to a powered hub and the hub to the computer.
You could also use an adapter of sorts. They were built for printers and such before everything came with wifi and could get a proper wireless setup going without either side realizing they aren't directly connected over USB (OS still knows that some funky usb drivers are loaded and a separate application may need to run to connect), but again more hardware. A decent Wireless "USB Device Server" seems to run ~$100 while wired ones are cheaper, but not as cheap as a powered usb hub.
If you have another machine, you can use it to enable wireless debugging on your Android phone. See https://developer.android.com/studio/command-line/adb#wireless. Once wireless debugging is enabled, you can connect to it from your Mac without using USB. You still need USB for enabling wireless debugging though, but you can do it from a different machine. This should work on all Android phones, root is not required.
Update [2021]:
Things have developed since this question was asked. WiFi Debugging is a first class option now on newer devices. See https://developer.android.com/studio/run/device.html#wireless for details.

Chrome remote debugging, the device is not showing up

I'm trying to debug a Website in Chrome on an Android device. For this I'm following the official remote debugging guide.
Things are working up to 6. Make sure that Discover USB devices is enabled., but then in point 7. Connect your Android device directly to your development machine using a USB cable., the device is not showing up. Also on the device, I do not get the the Allow USB Debugging permission prompt as described in point 8.
The device has USB Debugging enabled, and Windows recognises the device.
I'm able to connect to the device using Android Studio, and then use Chrome remote debugging. But it looks like overkill to install several GigaBytes just to be able to clic ont the Allow USB Debugging permission prompt on the device.
What can I do to launch remote debugging without installing Android Studio ?
If you turn on Developer options on your Android device, you should be able to toggle USB Debugging from there. Download the standalone ADB package or install Android Studio. Run adb server in the command line. Connect it and then the prompt to accept the device's RSA key fingerprint should appear and you should be good to go.
The docs do a better job of showing the step-by-step process https://developers.google.com/web/tools/chrome-devtools/remote-debugging/
P.S. if you'd like to test this multiple times on the same two devices you can click Revoke USB debugging authorizations in the Developer options to revoke all previously connected devices' RSA keys.
For those landing here from Google: my problem was a bad cable shipped with the device (Samsung Galaxy A03). It only charged but did not transfer data. I bought a decent third-party cable and it started working.

Android: Set Pc as an android USB Host device to test android phone app in USB accessory mode

I am creating an app (running in USB accessory mode) that will recognise when a specially made device (that I am also working on) is plugged in and connect to it.
I have written code in the app for this recognition to happen but now need to test it and the specially made device is not made yet.
So, I was wanting to test my app by somehow setting my PC up to be recognised as a usb host device that my phone can connect to, I spent a long time googling and looking for a way to do this or a different way to test this but came up empty.
How do I set my PC up in this way to test my app or what would be a good way to test this automatic usb connecting?
Thank you kindly,
EDIT:
Even the name of a cheap device that runs in android usb host mode would be sufficient as I could still just plug that into my device to check if it is working.
I think your question is how to emulate USB Host mode with the Emulator and setting up a bridge with an emulated device on the PC. This is not possible (yet).
See Emulator documentation. In the "What's not supported section" it is said that virtual hardware is not supported for USB.

How to mass install software to Samsung Galaxy Tab 10.1

our company bought 50 Samsung Galaxy Tabs for corporate use.
Before these can be delivered to users we must install some company labeled programs in to them.
We thought the easiest way to do this would be through ADB but it needs the USB debugging to be enabled. Is there a better and faster way to do it than enable it on each device one by one? Is it possible to enable USB debugging from PC using some program or piece of code while connected with USB cable?
The ideal solution would be that we connect multiple devices via USB to one PC and run installation script that enables USB debugging, runs installations, disables USB debugging and finally shuts down the devices. How would you do this?
Br,
Tupe
Is there a better and faster way to do it than enable it on each device one by one?
Have several people enable it on each device one by one in parallel.
Is it possible to enable USB debugging from PC using some program or piece of code while connected with USB cable?
Fortunately, no, as that would be a security hole.
The ideal solution would be that we connect multiple devices via USB to one PC and run installation script that enables USB debugging, runs installations, disables USB debugging and finally shuts down the devices.
Under your plan, a piece of Windows malware could detect that an Android device is plugged in and install Android malware on that device. After all, if your "installation script" can do it, so can the malware.
How would you do this?
Host the APK on an internal Web server, generate a short URL to it, check the "allow non-Market installs" on the device, and fire up that URL in the browser on the device. This presumes that you plan on updating the app (e.g., bug fixes) and that you aren't planning on going through your whole USB cable process for each of those updates. In that case, you need to get the Web server configured for APK files and have the "allow non-Market installs" checkbox checked anyway, so you may as well do that as part of the initial device setup.
Is it possible to enable USB debugging from PC using some program or piece of code while connected with USB cable?
Hopefully not. If this were possible any piece of hardware that you plugged your device into could do some very nasty things to it without any chance for you to intervene.
I've done some large installs like that. I've not found one technique to be the end all be all.
I would suggest host your apk file online somewhere make a shortened (easy to type) url to it.
Then on the devices open up browser and type the url. That will download your apk, when you click the download complete in the notifications it will start the install.
Note: You will have to turn on "Allow install from unknown" in settings. The fastest way I think is just do the download and press the apk, this will throw up a dialog that has a button you can press to take you right to the correct settings page to turn this on. But bad news is that after you turn it on the install won't resume automatically. So you either have to find the apk with file explorer, or go back to browser and download a new copy of it. I would guess the latter might be quicker, albeit messier.

Using My Android as a USB Device

I've been able to find a few posts on StackOverflow about how to control USB devices using an Android phone -- which I understand is impossible (The Android being a USB device and all.)
However, I would be perfectly happy to set up my application to communicate with the other computer (a Linux host) as a USB device. (Like a really expensive mouse...)
Does anybody have information about how to set up an Android app/phone to use the USB connection and exchange data with a host computer. Obviously, it already works at some level -- it's how Eclipse and Android SDK/debugger do what they do, but I'm still looking for some way to do this in an application.
(My current phone, BTW, is a Droid Incredible.)
Thanks,
R.
Basically you'd need to install the USB device driver and the ADB toolsuite from the SDK, either that or reverse engineer their functionality and build it into something else.
Then you enable USB debugging on the phone.
And then you can do something like an adb port forward to allow an application on the pc to connect to a network socket listener on the phone. Note that connections cannot be made in the other direction, but once a connection is made it is bidirectional.
If your version of android supports tethering over USB, you could also leverage that to implicitly create a network between the PC and the phone, at which point you can make connections in either direction. Just make sure nothing starts accidentally pumping lots of data through the phone's mobile network!
(Many android phones actually can experimentally function as USB hosts, but you have to compile new drivers into the kernel, install the new version, and make up a cable to provide USB power to the device as the phone cannot. Also you lose the ADB over USB channel which makes debugging a pain)

Categories

Resources