Adb not working after adb shell stop - android

So I think I did something wrong. At first everything was working alright. I was able to see my device when using adb devices and process shell commands. The problem began when I was trying out a faster way to flash my systemimage. I came across a website that had just what I needed. At first I was building my systemimage everytime, but overtime it became too long for minor corrections. So I tried syncing via adb. The commands I was using were adb remount adb shell stop adb sync and adb shell start in that order. One time I forgot to use the adb shell start and from that point on I cannot see my device under adb devices.
My question is could not running adb shell start after stopping it, really break the system that much. Or am I looking for the problem in the wrong place.
Also worth mentioning I am still able to flash systemimages via bootloader so I don't think the problem is usb related.

Well I fixed it. I don't if shell commands were the problem, but flashing everything (not only systemimage) seemed to fix the problem.

Related

adb shell: can't use the ESCAPE key

I want to use vi when running adb shell. Starting "vi" is easy. However, I found that the ESC key doesn't seem to get through to it, so I can't exit insert mode.
More broadly, it doesn't appear that I'm able to send an ESC character to the adb shell at all. I've scanned the web pretty thoroughly and haven't been able to find anyone with a similar problem (much less an answer).
I'm running VRUFNK1 on a Samsung S4. On the PC end I'm running the "adb shell" command from Cygwin under Windows.
Ideas???
UPDATE: Here's are some possible clues.
The adb shell doesn't seem to be the problem. I can capture ESC in a file running
od -cb > file, so ESC seems to be getting to the program being run under the adb shell.
All commands get echoed in my "adb shell" (as if set -v was on, but it isn't).
I notice that input doesn't seem to get sent to adb shell from my cygwin shell in "raw mode" -- i.e., any text I type gets buffered locally until I hit carriage return -- then the entire line gets sent. I'm not sure why that would make ESC ineffective, but certainly vi doesn't expect to be receiving input in quite that manner and perhaps its an indication of something unusual in my environment.
Similar to #1, bash (Bash X) seems to receive it, although echoing from bash is very strange. I can use ESC to enter "edit mode" in my bash shell (Bash X) to scroll through my history (I've run set -o vi), but the experience is very strange. When I hit ESC,k, nothing changes on the screen but my location in the command history goes up one rung (as it should); subsequent presses of 'k' cause a 'k' to be echoed to the screen (instead of the relevant command from my history list). When I finally hit carriage return, the correct command from my history list is executed (!).
UPDATE 2: Progress…
I tried setting the stty value in the "adb shell" to the same as the ones in my cygwin bash shell and that didn't have any effect.
I also tried this: Avoiding escape timeout issues in vim but it didn't help.
I tried this (by reading in from a file using :so <filename>).
Unfortunately, the commands weren't recognized by "vi" (they are actually "vim" commands).
Partial Solution:
Typing a <cr> immediately after the ESC when in "vi" works -- the ESC is accepted and I can exit the editor. It's awkward, and the editing window is still unusable (as if TERM was set to the wrong value), but this is progress.
Also, things work fine when I ssh in. That shell gets started by the telnet server; similar situation as Terminal Emulator directly on the device. Ssh has its own server which then forks off the shell. In the case of the "adb shell", the shell is forked off by /sbin/adbd -- as far as I can tell, there is simply something unusual about that environment. This is a huge step for me -- at least now I have a way to do full screen editing on the device using my PC (rather than editing directly on the S4's tiny screen). Thanks to Jack Palevich for that suggestion.
I can only think of two things to try at this point:
Try running adb shell against someone's device (but the device must be running root, so that I can run Busybox's "vi") (BTW, the version of "vi" is not the problem -- it runs fine from ssh.)
As someone else to run "vi" in "adb shell" on my device, from their host (preferably someone who has succeeded in running "adb shell" and vi somewhere previously.
I'm starting to think that It Simply Doesn't Work.
UPDATE 3: Info from XDA Developers
I found some relevant posts on the XDA Developers forum. It seems to be the case that people have had problems with this for a long time (since at least 2010). I didn't find any solutions.
XDA Link 1
XDA Link 2
XDA Link 3
There is also a paragraph listing various perceived/proposed adb shell bugs that match my experience, here:
Proposed ADB Shell Bugs
You're right - it simply doesn't work under Windows or Cygwin shell. I found that the simplest way to make it work is to use PuTTYTray.
Check my answer in the linked thread for instructions and additional details.
Another solution: Use Windows PowerShell instead of cygwin. Commands like 'o', 'esc', and ':wq' work nicely here.

ADB Command Weird Behavior

I have a question regarding ADB.
I'm sorry about the title of this question as I really don't know how to put a good title to this.
I'm working with many android devices at the moment, and I noticed that on some devices, the following problem occurs.
Say I want to run a shell script (my_script.sh) that is located in the /data/local/tmp/ folder of the phone.
If I do this:
adb shell 'sh /data/local/tmp/my_script.sh &'
nothing happens on the phone.
If I just go into adb shell (by entering adb shell on a terminal) and when I get this prompt:
shell#android:/ $
and then I type in the following:
sh /data/local/tmp/my_script.sh &
everything works just fine.
This happens on only a few of the devices I have. So I'm not able to figure out what exactly I'm doing wrong.
Here is another piece of information that might help someone. If I don't use the "&" at the end (which means I don't run the script in a background process), everything works as well.
The following code gives the correct behavior:
adb shell 'sh /data/local/tmp/my_script.sh'
I'm completely lost, and I'm hoping someone here can help me out.
Thanks in advance!
UPDATE: So this issue has puzzled me for a while, and I spent quite a bit of time investigating this issue. I've noticed another behavior, say I lock the screen (by pressing the power key) and then issue the command:
adb shell 'sh /data/local/tmp/my_script.sh &'
And then unlock the screen, the script will run fine.
This is really the weirdest thing I've encountered in a long time.
I really hope someone can lend a hand here.
I guess you want to daemonize some program to run in the background. But normally the child process will got killed while the parent is gone. In this case, your adb shell is the parent process.
And this behavior is really different from device to device. I just tried it on my phone and found that "&" didn't take any effect, the shell command is still blocked.
I think a better way to handle it is to use standard daemonize approach of linux. Please refer to:
Write a daemonize native program
How to daemonize a script on a generic linux os

screenshot via adb in Amazon Kindle Fire HD

Actually, there is no screencap utility out of box in Amazon Kindle Fire HD. Id'like to install it to /system/bin/ via adb to call from the command line (still via adb) at the moments when I need to have a screenshot and logcat is not enough to attach the to bug description.
There are some descriptions how to use screencap utility for such purpose: http://habrahabr.ru/company/intel/blog/152122/
(see
adb shell screencap /sdcard/screen.png
adb pull /sdcard/screen.png screen.png
adb shell rm /sdcard/screen.png
)
However, it seems that my device uses Android 2.3 Gingerbread, so there is no screencap utility out of box. So, the question are 1) Is there a way to push screencap of other Android versions to /system/bin/ 2) where I can download it online?
Other approaches working with adb shell are welcome.
I don't know exactly if this will help you, but I once happened to find out several other ways of capturing a screenshot. From what I know, they do not depend on the screencap but rather on the ADB daemon. All of them require your device to have USB debugging turned on.
I would really suggest trying this simple utility out: http://www.roman10.net/a-program-for-taking-screenshot-for-android-device-from-command-line/ which essentially reimplements the DDMS screenshot functionality without the whole GUI. It automatically writes it on your computer so there's no need for push/pull. It's pure Java so it's a great bonus.
Scroll down to the download section where you can download just the binary and test it out.
Another method would be to use MonkeyRunner described here: http://developer.android.com/tools/help/monkeyrunner_concepts.html. All you need to do is write a simple script which captures the screen, which is shown on the page from the link.
Unfortunately I don't know if android-tools-adb provides MonkeyRunner.
Another tool is Android Screenshots and Screen Capture: http://sourceforge.net/projects/ashot/
It just needs the Android SDK installed and I suspect it runs on the same principle as DDMS or the first program - from Roman10.
Hope that helps!

Android command list

I have many questions about Android command. I do not know where I should start But, anyway, I have put all question related Android commands. Here ;
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
Can I start and stop application via start and stop command ?
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
NOTE : feel free to reedit the question, if you see meaningless part.
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
A subset exists by default within the system. Things like ls, cd, mkdir, cat etc... are present. You can gain access to a wider range by installing Busy Box on a rooted device, as stated by Zac.
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
The ADB Page is a good place to start. That covers many of the basic ADB and shell commands. It states near the bottom:
"For a complete list of commands and programs, start an emulator instance and use the adb -help command."
So you can use adb -help on an emualator or device to see a full list of the ADB and shell commands (note I think this list will be android specific commands only, it won't include things like cd,ls and other basic unix commands).
Can I start and stop application via start and stop command ?
No, it states on the ADB dev page:
start ........ Starts (restarts) an emulator/device instance.
stop ........ Stops execution of an emulator/device instance.
To start an application you'll use the am utility iirc it will look something like am start com.your.packagename It's been a while though, I might have syntax wrong. The instructions are listend if you issue the am command by itself with no params in a shell.
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
The system prevents applications from rebooting the device unless they are signed with the same key as the OS. When you use the terminal emulator you are restricted to whatever permissions that application has declared. The reboot permission is not granted to any third party applications, so it won't work correctly from any terminals. You could probably do it if your device was rooted and you used su though
EDIT:
Here is another good resource that lists more of the shell commands
There are not many Linux commands included in android, however if you are rooted you can easily install busybox which has a large range of linux commands.
You need to have root access to reboot your device via the command line (to prevent any old app being able to do it)

Is there any way to stop ADB from automatically trying to connect to ANY android device plugged in?

So here's the thing. I use MyPhoneExplorer in USB mode which uses ADB to communicate with the phone. Whenever my phone is connected (using MyPhoneExplorer) and try to test an app in eclipse on my EMULATOR, ADB crashes, rendering both MPE and the emulator useless.
My question is: Is there any way to prevent adb from accessing one phone from multiple sources? (In this case its trying to access the phone for both Eclipse and MPE).
Weird/Confusing question I know, but would really appreciate some help.
I haven't tested this, but how about directing ABD at a given device with this:
adb -s <serialNumber> <command>
http://developer.android.com/guide/developing/tools/adb.html#directingcommands
Use adb devices to find out the serial number of your emulator.
But from what you describe it might be that ADB's device detection that's breaking things.

Categories

Resources