I want to write some basic Linux commands in my Android app (namely ls, rm, cp, chmod with recursive -R option) but I am not sure whether they are available across different versions of the OS and whether they support "-R" or not. From my experience, cp seems to be added to Jelly Bean 4.2. The rest are all available in earlier versions.
May I ask if there is a source or reference for this? (Nothing seems to be available on the official Android site.)
You can always fire up a avd and in adb shell run ls /system/bin and ls /system/xbin, it will show all the commands present.
Related
I read a lot about SELinux, and I would have liked to try and get my hands on a case study for the university.
I have installed various virtual devices on GenyMotion, from Android 6 to Android 9, but nobody owns SElinux: when I do "sestatus" it answers "disabled".
I do not think it's enough to enable it, it seems that the modules must be installed in the kernel, can someone tell me how to do it? I tried but I did not find anything, I'm having a lot of difficulties, it's the first time I do these things.
Thanks to everyone in advance.
Finally I managed to make everything work: I was able to access Selinux information via a terminal in the GenyMotion virtual device. Selinux is already active on devices after version 4.3, there is no need to install it as it said #Martin Zeitler. I explain the solution to the problem (on Linux it works).
The first thing to do is to install a terminal in the virtual device: I have installed Termux. To do this, just download the apk from a site and drag it to the virtual device, the installation will start. Subsequently, it is necessary to provide the SuperUser permissions to the Termux terminal: banally, by opening the terminal, provide the SU command, and the device will ask you if you want to provide SuperUser permissions to the Termux application. When you enter the SU command, it will allow you to browse the folders on your device. With the "ls" command, providing the "-Z" option, you can see the SElinux context of the files. From the terminal, using the "getenforce" command, you can see how Selinux is running. Here you will see other useful commands: https://www.all-things-android.com/content/se-android-commands
Now, you will need to download the tool that allows us to interact with Selinux: setools. https://github.com/pasis/setools-android These tools are written in C, the native language of Android, so you need to download the NDK library to compile them: https://developer.android.com/ndk/downloads/
The first thing to do to compile, is to specify the project path:
export NDK_PROJECT_PATH=/my/project/path . The second step is to specify the makefile:
ndk-build NDK_APPLICATION_MK=/my/project/Makefile.am (for a complete guide: https://software.intel.com/en-us/articles/building-an-android-command-line-application-using-the-ndk-build-tools)
When you have finished compiling, you can send the Setools folder to the virtual device, using the adb program. ./adb push /setool/local/folder /remote/device/folder
(example: ./adb /setool /tmp) Now that you have Setool on your device, you can run the tools in the "/setool/obj/local/x86" folder. Thanks to "sepolicy-inject" you can also add rules to the policies.
Finally, thanks to this guide I realized that Selinux policies are stored in binary format, so it is not possible to interact with them without tools.
https://ge0n0sis.github.io/posts/2015/12/exploring-androids-selinux-kernel-policy/
one cannot "install SE Linux" on Android; because it's already installed and enabled by default since API level 21. you'd need to become user root, in order to access these management commands. this would only be possible on a rooted hardware device - or a rooted emulator image.
... just install CentOS or whatever else security enabled Linux distribution, for a test.
I have a course project that involves setting up a device driver on Android. I have previously worked with device drivers in the Linux kernel and we used two commands to initialize the device and make a node: insmod and mknod
Now when I launched the emulator shell using adb shell, I was able to use insmod but mknod did not work. I have tried to find alternatives but was not lucky.
From what I know, mknod in the Linux kernel lists the device under the /dev directory and allows user programs to read/write to it by using its file ops.
So what is its alternative for Android?
Perhaps, the android device you're using don't have mknod command. It need to be supported from rootfs, usually Android rootfs are built using busybox. Most probably, mknod was dropped from busybox config. Possible option could be, use custom Android image where you've mknod installed.
I have next situation:
I got 2 version of adb and 2 versions of adbd on 2 different devices.
How can i use both versions of adb from my workstation for these 2 devices.
I mean:
1 adb for 1 device.
2 adb for 2 device.
Now i have following situation:
Every time when i run another adb, previous adb server kills and new one starts.
How can I workaround it?
I think you are asking the wrong question. What I think you want is to run two adb commands at once on different phones. Is that correct?
If so what you are looking for is
adb -s DEVICE_SERIAL xxx
where DEVICE_SERIAL is the value shown when you run adb devices and xxx is the command you want to run. Use adb devices for a list of connected devices.
This only requires you to have one version of adb installed, just open up a new terminal and run the command for the different serial numbered device!
If I'm understand the question correctly I believe he's trying to run two different versions of ADB at the same time. If my assumption is correct then here is what you'd want to do.
Lets assume you have adb.1.0.29.exe and adb.1.0.39.exe on the root of the c: drive which were renamed from the adb.exe from the different versions of platform-tools SDK versions they were supplied in.
To run the ADB version contained within adb.1.0.29.exe all you have to do is what the linked articles say BUT be sure to call the proper exe for that version. I used these adb version names as examples. You can name the adb.exe whatever you want.
So you can call adb commands with different versions as follows,
c:\adb.1.0.29.exe -s serial_of_device adb_command
or
c:\adb.1.0.23.exe -s serial_of_device adb_command
Cheers,
-Rob
I'm planning to build an automated system for deploying an Android build to various devices, in order to make development for multiple platforms a bit more comfortable. Is there a way to get the sdk version of a connected device through android shell or adb?
There will be a computer to which several test devices is connected, and I was planning to write a script which will fetch the correct build for each of those from a build-server, install the different apks on their respective devices, launch them and collect log info, to be made available through some other program whose specifications are beside the point.
The point is that I need to know the sdk version each device is running to install the correct apk, and I was hoping I could get this through adb, but I can't seem to find a way to access it short of building a tiny app, compatible with all versions, whose sole purpose would be to output android.os.Build.VERSION.SDK or similar somewhere my script could read it.
you can use this command:
adb shell grep ro.build.version.sdk= system/build.prop
It will output something like this:
ro.build.version.sdk=10
adb shell getprop ro.build.version.sdk
Note #Tim: this works even on phones without grep support on all host OS :-). (i.e. on old phones where toolbox does not support grep you you need to have busybox on your phone).
I also discovered a way to get the exact version of Android e.g. 4.2.2 based on the following web article http://xayon.net/looking-for-android-version-with-adb/ You need to be using a unix-like operating system - Linux and Mac OSX are fine, and windows users can use cygwin or equivalent.
At a command line:
echo version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')|tr -d '[]'
Here is the result for my Nexus 4:
version= 4.2.2
I think you can by accessing the device with adb shell - change directories to position you at system and do a cat of build.prop. Here you will find for instance, ro.build.description=google_sdk-eng 2.2, ro.build.version.release=2.2 etc
It'd be nice to have the "Swiss Army knife" of BusyBox on my emulator. It would also be nice to have full root access. Does anyone have any experience doing this? I'm not familiar with qemu; is this even possible?
Update: The emulator has root by default (accessed via the adb shell command). Does anyone know where I can easily obtain a pre-built busybox binary?
The emulator is not set to secure mode, so it's adb shell should be a root shell.
There are several android builds of busybox, for example cyanogen alternative versions of Android use it to augment toolbox (which is Android's own limited re-implementation of the same concept under a non-gpl license). You should be able to get it from the cyanogen repositories and build it from source, or it's possible that just extracting the binaries from a same-android-version cyanogen update.zip would work (it may be in a compressed file system inside the update though)
There were also some writeups from pioneers who discovered the accidental root shell on the original G1 release and installed quite a bit of debian arm.