Accept 'Force Close' dialog via ADB shell - android

I'm trying to figure out how (or if it's possible) to accept the 'Force Close' dialog via the adb shell when an Android app crashes with a hard error (specifically out_of_memory). I'm hoping to basically loop an app with a bash script, so when it crashes I want to start it running again. The missing step here is that I can't simulate pressing the 'Force Close' button that shows up in the middle of the dialog.
At the same time, the process doesn't seem to actually be running (trying to kill the PID doesn't work), so it's a bit of a weird situation because it seems to have already stopped, but launching it again (via adb shell am ...) just gives me 'current task has been brought to the front'.
Any thoughts would be appreciated!

+1 to DarkXphenomenon for the UncaughtExceptionHandler.
However to kill the process you should use am:
am force-stop: force stop everything associated with <PACKAGE>.
am kill: Kill all processes associated with <PACKAGE>. Only kills.
processes that are safe to kill -- that is, will not impact the user
experience.
for example:
adb shell am force-stop <YOUR.PACKAGE.NAME>

If it is your own app, you can add an UncaughtExceptionHandler and not show the force close dialog. If not, the following might work.
You can also kill the process from adb. (Credit)
adb shell kill $(adb shell ps | grep YOUR.PACKAGE.NAME | awk '{ print $2 }')
After that, you can use adb shell am ... to respawn the process.

Related

Removing App from Recent Apps in android using adb shell command

I want to remove an application from recent apps using shell command. please help me with a working solution.
Thanks
Balaji
You can not remove from the recent but you can kill your application using command line,
kill [options] Kill all processes associated with (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience.
Options are:
--user | all | current: Specify user whose processes to kill; all users if not specified.
http://developer.android.com/tools/help/shell.html for your reference.
I hope this will help you.

How to "warm start" a deep link visit through adb

I am writing a service that opens deep links to Android apps through adb like so:
adb shell am start -W -a android.intent.action.VIEW -d http://www.example.com/deeplinktest com.example.mjohnst.deeplinktest
The above command works correctly:
Starting: Intent { act=android.intent.action.VIEW dat=http://www.example.com/... pkg=com.example.mjohnst.deeplinktest }
Status: ok
Activity: com.example.mjohnst.deeplinktest/.MainActivity
ThisTime: 606
TotalTime: 606
WaitTime: 731
Complete
What I want to do, is have the app already open/warm to any view, and still be able to visit the deep link.
If I have the app open on the emulator and try this, I get this warning:
Warning: Activity not started, its current task has been brought to the front
and the deep link is not visited (the current, non-linked view of the app is brought to the foreground).
Is there any way for me to visit a deep link on an already open app through adb or another interface?
EDIT: I know that there's a -s flag to kill the app before visiting, but this is not what I want. I would like the warm start to provide a performance gain
I discovered that if you start the app via a non-deeplink activity, deep linking "warm" will work.
Used this adb command to start the app:
shell am start -a android.intent.action.VIEW -n {packageName}/{activityName}

How to stop an android application from adb without force-stop or root?

I need to kill an activity (or the whole package) using adb without having root permissions (this rules out kill), while ensuring that the activity can receive an intent afterwards (this rules out force stop).
Edit: I tried kill and am kill (from shell). The former requires root and the latter does not reliably kill the activity that I need to be killed.
run-as <package-name> kill <pid>
Note that run-as is only supported for apps that are signed with debug keys.
I think, kill or stop are not the appropriate words in this situation. If all you want is to leave that application, you can use adb shell input keyevent <KeyEvent.KEYCODE_XX> to emulate key press events. For e.g., following is for Home button:
adb shell input keyevent 3
And following is for Back key:
adb shell input keyevent 4
See KeyEvent for full list of codes.

strace shell command issue in Android

I'm building a monitor app, which runs in background and logs the system calls executed by currently running application using the strace command.
String cmd="strace -p "+processID+" -o /mnt/sdcard/traceFile_"+processID+".txt";
Runtime.getRuntime().exec(cmd);
Here processID is the PID of currently running process which is got from some other method implemented. It logs the system calls of the first app it monitors properly with all executed system call information. But when a new app is started(second one onwards), the processID is updated correctly, but the file traceFile_processID is written as an empty file.
I'm not able to figure out why its happening. Is it because the strace execution of first app monitored still there?? If so how I can execute a ^C to terminate that session and start a new one as in adb shell command prompt?? Plz help me.....
If you want to "^C" as you say, what you're really asking for is how to raise the signal called SIGINT to the given processID. You can do that simply by kill(processID, SIGINT); - this is equivalent to pressing Ctrl-C on the keyboard for the target process.

Shell script run through runtime.exec() behaves differently than if I run it through terminal

I have this snippet of shell script:
am start -n com.android.gallery3d/com.android.gallery3d.app.MovieActivity -d /sdcard/movie.mp4
sleep 5
input keyevent 4
This script basically reads as follow:
1. Open the gallery application to start movie.mp4
2. Sleep 5 seconds
3. Press back key
When I run this script through adb shell, things work out as expected which is the video plays only for the first 5 seconds and then the back key is pressed which essentially quits the gallery app.
However, when I run this though runtime.exec()
The gallery does start, but then nothing else happen. It seems like the system prevents me from running the script when the application is in the background.
Anybody happens to know any work around? Or is there any way to use INTENT to achieve the same result?
Thanks in advance
A script run by an application runs as the application userid, which does not have the extra
debug privileges that the adb shell (running as shell or even root) does.
For security reasons, applications are not supposed to be able to feed fake keystrokes to other applications and especially not to the system itself.
Perhaps instead of backing out of the gallery, you should try to start something else with an Intent.

Categories

Resources