I have a question about ADB, does anyone know what is the difference between:
adb shell & adb hell commands?
I'm wondering if except the "hellish" terminal color(only on Linux, in Windows you just get some prefixes) there are any other differences?
Seriously check yourself.
Reading the source:
if(!strcmp(argv[0], "shell") || !strcmp(argv[0], "hell")) {
int r;
int fd;
char h = (argv[0][0] == 'h');
if (h) {
printf("\x1b[41;33m");
fflush(stdout);
}
if(argc < 2) {
D("starting interactive shell\n");
r = interactive_shell();
if (h) {
printf("\x1b[0m");
fflush(stdout);
}
...
if (h) {
printf("\x1b[0m");
fflush(stdout);
}
This code confirms that if the shell or hell command starts with an h, extra control sequences for changing terminal colors are output but nothing else.
As far as i know there is no other difference between the two.
Related
Updates here:
Devices exposing the issue so far (output 160):
Meizu M2 Note; CPU Mediatek MT6753; Android 5.1; Root: NO
Doogee Leo DG280; CPU Mediatek MT6582; Android 4.4.2; Root: NO
============
I have a really weird behavior of a while loop happening on a DooGee Leo LG280.
The output of this loop is 60 on every emulator and phone that I've tested. I can run it 100 times and the result will always be 60.
The code:
public class JavaActivity extends AppCompatActivity {
#Override public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int limitValue = 50;
int result = startWeirdLoop(limitValue);
System.out.println("my weird loop in java " + result);
((TextView)findViewById(R.id.textView)).setText(String.valueOf(result));
}
private int startWeirdLoop(int limitValue) {
int index = 0;
while (index <= limitValue) {
index += 20;
}
return index;
}
}
If you run the same code on the devices listed above, the output is 160.
To let it output the right value (60) there are some things I tried so far:
just add an empty print statement in the loop
hardcode the limitValue in the while by replacing it with 50.
replace Integer to int in the parameter limitValue
flip the condition in the while: while (limitValue >= index)
add 0 to limitValue: while (index <= limitValue + 0)
It really doesn't make sense to me! Why a System.out.println("") should magically fix the result of a while loop? Why hardcoding the parameter should fix it as well? And most importantly, why is this happening only on this device?
It seems that any instruction added into the loop makes the loop work as expected. And this scares me.
Could it be related to the CPU (MediaTek MT6582 ARM Cortex-A7)? To the system version? I don't know but this really pisses me off, because it's happening only on this device and I'm scared it could be on others. I repeat, on emulators and Huawey, LG, Samsung devices works fine.
My only doubt here is somehow related to combination CPU <-> Android Runtime ART. If you have this model of phone or another phone with MT6582, please try to run this code.
Screenshots:
Instrumented test run on the DooGee device (to avoid any layout related issues)
I'm developing a standalone kiosk using an android tablet(iBall running on 4.2.2).Its has the chinese MTK in it.
Suppose when there is no power,then eventually the tab's battery will drain out and have no juice left in it.When the power comes back I want the tab to automatically bootup without any manual intervention.I read online that if we modify the code present in the battery animation file we can achieve this.For the same,I replaced the original code of the battery charging animation file called 'ipod' located at '/system/bin' with :
#!/system/bin/sh
/system/bin/reboot
However,when my tab was shutdown and docked it didnt boot-up,instead it was just stuck at the charging logo.When I replaced the above code with:
/system/bin/reboot
my tab did boot-up when it was shutdown and docked.This means my code was getting stuck at '#!/system/bin/sh' . What could be the reason?
Also,while booting up the tab using the above process I want to boot it up after a delay,for which I used
sleep 20
/system/bin/reboot
but there was no delay in the bootup process(irrespective of the value of sleep that I give)
How do I create this delay ?
PS: I gave 777 permission to the file; owner-root; group-shell.
Kindly assist.Many thanks !
Found the reason my commands were not executing.
The reason was because,I was editing on my notepad++ on windows,until I came across this answer on SO -
" Make sure your text editor is not putting a /r /n and only a /n for every new line. This is typical if you are writing the script on windows.Use notepad++ (windows) and go to edit|EOL convention|UNIX then save it. "
So I changed my convention as per the above answer and ran my code and got the desired result.
I also had the need to make a device (alcatel9002x) autoboot on charger plugged, and come up with a solution replacing the ipod file. It runs the original ipod binary and at the same time, simulate pressing on the power button.
I see the charging animation, but after, it does a "normal" power up.
You probably can do this with a script but I did with with a .c binary.
Solution:
move /sbin/ipod to /sbin/ipod.backup
And use this code as the new binary /sbin/ipod
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
void run_cmd(char *s)
{
FILE *handle;
char buf[64];
size_t readn;
handle = popen(s, "r");
if (handle == NULL) {
return;
}
while ((readn = fread(buf, 1, sizeof(buf), handle)) > 0) {
fwrite(buf, 1, readn, stdout);
}
pclose(handle);
}
int main(void)
{
FILE *handle;
char buf[64];
size_t readn;
pid_t pid = fork();
if (pid == 0)
{
for(int i=0;i<10;i++)
{
run_cmd("/system/bin/sendevent /dev/input/event0 0001 116 1");
run_cmd("/system/bin/sendevent /dev/input/event0 0000 0000 00000000");
run_cmd("/system/bin/sleep 2");
run_cmd("/system/bin/sendevent /dev/input/event0 0001 116 00000000");
run_cmd("/system/bin/sendevent /dev/input/event0 0000 0000 00000000");
sleep(1);
}
}
else
{
run_cmd("/system/bin/sleep 2");
run_cmd("/system/bin/ipod.backup");
}
return 0;
}
I've compiled it with arm-linux-androideabi-gcc.
As I said, you probably can do this in a bash script, but this is how it worked for me.
Don't forget to chmod 667 and chown root:shell the binaries.
In Sony Xperia GO, the file name is "chargemon" and only by renaming it, the task is done (smartphone will be restart after plug in). (maybe other Sony brand smartphones be the same or similar)
I am working on Android platform, and I wonder if it is possible to start an Android app from the kernel source code. For example, at certain point along the linux kernel resume path, I want to start a specific app, say my custom lock screen app. Is that possible?
Edit:
the call_usermodehelper does not work with the "am" utility.
I have code like this in a kernel module:
int result = 0;
char *argv[] = { "/system/bin/am", "start", "-n", "com.twitter.android/com.twitter.applib.HomeTabActivity", NULL};
char *argv[] = {"/system/bin/ls", NULL};
static char *envp[] = {"HOME=/", "PATH=/sbin:/system/sbin:/system/bin:/system/xbin", NULL };
result = call_usermodehelper(argv[0], argv, envp, 1);
but when I insmod, the nothing happens, and result = -8
anyone can help?
I can't speak for certain about Android, but in vanilla Linux, there's a bunch of API's in kmod.h which can do what you want. See this article for details.
I am coding a native application in android and I need to get the default gateway of a device on my application. Here is my current code to get the default gateway.
static int get_default_gateway(char *def_gateway, int buf_size)
{
FILE* pipe;
char buffer[128];
char result[2049];
char cmd[] = "netstat -r | grep ^default | awk '{print $2}'";
pipe = popen(cmd, "r");
if (!pipe) return 1;
memset(result, 0, sizeof(result));
while(!feof(pipe)) {
memset(buffer, 0, sizeof(buffer));
if(fgets(buffer, 128, pipe) != NULL)
{
strcat(result, buffer);
}
}
pclose(pipe);
memset(def_gateway, 0, buf_size);
strncpy (def_gateway, result, buf_size );
return 0;
}
It works on my LG p500 but on some devices it doesn't return anything.
My question is: Does popen() works on android? I read somewhere that it is not included in bionic.
And is there any other method to get the default gateway? I need it to be written in C and not java.
Thank you
Yea, probably popen() should work on any Android. But unfortunately grep and awk - not. Take a look at /proc/net/route - line where Destination equals to 00000000 is your default gateway. Also perhaps you can use NETLINK_ROUTE socket, though I never used it and can't say more.
See also this related question.
I have tried following code snippet to execute the batch of command for sendevent to click the coordinate 44,129 on the emulator. But it is not showing any result. But if i am giving the same batch of command to the shell prompt it is able to click the mentioned coordinate succesfully.
String[] cmmandemulatorarr = {"/system/bin/sendevent /dev/input/event0 3 0 44",
"/system/bin/sendevent /dev/input/event0 3 1 129",
"/system/bin/sendevent /dev/input/event0 1 330 1",
"/system/bin/sendevent /dev/input/event0 0 0 0",
"/system/bin/sendevent /dev/input/event0 1 330 0",
"/system/bin/sendevent /dev/input/event0 0 0 0", };
for (int i = 0; i < cmmandemulatorarr.length; i++) {
Process process =
Runtime.getRuntime().exec(cmmandemulatorarr[i]);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Is there is anything i am missing here or i have to try something else to get click event on some coordinate through the code.
Note :: I am not getting any exception in the log while executing the code which seems that command is executed successfully.
Regards
Pinu
But it is not showing any result.
This is a good thing.
But if i am giving the same batch of command to the shell prompt it is able to click the mentioned coordinate succesfully.
The shell runs with root-level privileges. Your SDK application does not, unless you root your device and arrange to execute your code that way.
Bear in mind that not all devices will have a /system/bin/sendevent command and it can be removed at any time. This is not part of the Android SDK.
i have to try something else to get click event on some coordinate through the code.
This is not possible from the Android SDK for ordinary devices, for obvious security reasons.
Here you have answer. You need to find touch event id with getevent. Sendevent use decimal space, getevent use hex. This code from first "answer" works on 7.0.