Running two application/script with a reboot in between without manual Intervention - android

I have two c application running on android
say helloWorld and helloHell . I need to run both but with a reboot in between.
I have adb pushed the applications to a folder in android file system and created two scripts :
helloworld.sh and helloHell.sh
inside helloworld.sh :
./helloworld
reboot
inside helloHell.sh :
./helloHell
reboot
I have written a shell script on the host PC like this :
hell-world.sh
1->adb shell sh helloWorld.sh
2->some calculated delay
3->adb shell sh helloHell.sh
But the problem with this is after running first script (1->) the command hangs(may be due to reboot inside the helloworld.sh) and I have to manually do CTRL+C , and then manually run the second script(2->) once the reboot is over.
I even tried killing after the first script execution(1->) by doing something like this
PID =$!
kill -9 $PID
but invain,
My aim is to run both the applications with a reboot in between with no user intervention in between.The problem here is after the reboot no new command after that will be executed and have to terminate it manually.

Remove reboot from script file & try this
adb shell sh helloWorld.sh
adb shell reboot
# add some delay here
adb shell sh helloHell.sh

Related

How to kill application process?

In my Xamarin.Android application, I have code that handles restoring state after process death (when the OS kills the application to free memory). I want to test this code but I do not know how to simulate when my application process gets killed. I am trying to do it through the terminal. From my platform-tools folder:
drake#Drakes-MacBook-Pro platform-tools % ./adb shell
generic_x86:/ $ am kill com.mycompany.myapp
But this is not working. And I think it is because it is not targeting the OS in my emulator. I was expecting to see "Pixel_C_API_30" instead of "generic_x86". I am on a Mac.
You can use the adb device command to list the device.
If you have multiple devices, you can use -s to specify the device XXX like this: adb -s XXX shell

Android Shell locksettings command from device terminal

Since Oreo there is this fancy locksettings command, that allows you to change the screenlock from adb shell. Now, if I try to run it on my PC everything is working. On my handheld the command will just get an "Aborted." back. Why is that and how can I run the locksettings command from my device?
here is the code for the locksettings command, maybe you can already tell by that:
# Script to start "locksettings" on the device
#
base=/system
export CLASSPATH=$base/framework/locksettings.jar
exec app_process $base/bin com.android.commands.locksettings.LockSettingsCmd "$#"
Download QUTE, a command panel. Start from the first command click and run it. About 10 to 15 commands ran will give enough control over the system. Only because most of the commands are going to fail, unable to run. Then the terminal will suggest you to STACK, for the command code to lock setting. Copy the code and paste it in the terminal. For there your settings should be locked.

Wait for Android emulator to be running before next shell command?

I started an Android emulator using the following shell command:
emulator -avd TEST_AVD
The emulator starts just fine, but the shell script never finishes executing. It just hangs there even after the emulator has completed startup. I have tried with a number of other arguments that I could find, but nothing could quite do what I want it to. How do I know, or stop the shell command, when the emulator is ready to go?
I am setting up our Jenkins CI to use a Jenkinsfile to start the emulator, and then run a series of gradle commands. In short, I'd like to do this:
sh "emulator -avd TEST_AVD"
sh "./gradlew clean test spoon"
However, I don't want to run the gradle tasks until the emulator has finished startup, and I can't figure out how to do that in the terminal.
If you want to do something after you start the emulator you should start it in the background
emulator -avd TEST_AVD &
adb wait-for-device
# other stuff here
adb can wait for a device over a transport to be in a particular state
adb wait-for[-<transport>]-<state>
- wait for device to be in the given state:
device, recovery, sideload, or bootloader
Transport is: usb, local or any [default=any]
To wait until device (or emulator) boots, you can do something like this (as was already answered by Пионерка):
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
Basically:
Wait for device/emulator to be in adb device state
Open shell & sleep in 1 second intervals until the sys.boot_completed property becomes true
If anybody would be interested what Android Studio does, when running emulator, the answer is this class:
If device is online, then it is ready. No need to go to further steps.
Checks system property adb shell getprop dev.bootcomplete until it is equal to 1
For API 23+ devices runs command to unlock screen: adb shell wm dismiss-keyguard
Waits 1 second.

How do I start one shell script as process from another shell script

I want to do this from my script1.sh which is run on host
#!/bin/sh
# adb shell "sh /sdcard/script2.sh &"
script2.sh is on android device inside /sdcard/ folder.
I want script2.sh to keep running on Android. script2.sh has infinite loop.
But above command is not working. script2.sh stops as soon as script1.sh exits.
I have also tried
# adb shell "exec sh /sdcard/script2.sh &"
but this also doesn't work.
In your parent shell script, extract the pid of the child process script2.sh.
and then wait for its completion using the wait system command.
wait <PID>
Refer this link for further details.
adb shell "nohup sh /sdcard/script2.sh &"
Instead of exec you can use nohup. What nohup does is it makes your script2 as child of init process (parent of all processes) as soon as script1 exits.

How to close android application completely using adb or appium or any command line+python

I have tried to close android application using adb command and appium server but it is minimizing the app, not closing. I used below command for closing.
adb shell am force-stop com.package.name
AND if i try this command to kill process then it says,
adb shell kill 21860
Error:Operation omitted
Please let me know any way or command line to close android app completely, not run in background.
Thanks in advance!
I don't want to see in the background application list like below image.
adb shell am force-stop <PACKAGE-NAME>
Force stopS everything associated with <PACKAGE-NAME>
should work since honeycomb
Why not just:
un-installing app (it will stop any service or running process of it):
adb -s <udid> uninstall <appPackage>
and then installing it again:
adb -s <udid> install <apkPath>
Note:
In my case it is not working, because my app need to be registered each time re-installed, and working around it with 3rd app (e.g. Appium) is taking too long.

Categories

Resources