Can I bundle a binary utility and call it from app? - android

Is it possible to create a app and call a command-line utility from it (bundled with the app), like it could be with a desktop application in linux?
Example:
My app wants to load some files but needs them to be converted, so first it calls an utility with command-line (like "jpgconv -r -t image.png") to create converted copies. Is it technically possible on Android?

What you are trying to do is basically call the Android shell from your application and pass it a binary.
Android's shell doesn't seem to accept Intents, in which case it's not possible, and it's anyway severely limited, which is why most users who need a shell (which is a very small subset of Android users) install a separate shell application, as well as tune their filesystem appropriately.
You could however try to embed your binary using the NDK, since, for exemple, BusyBox is straight C.

Related

Is there a way to get data from sensors from command line?

In Android, I know it's possible to use Runtime.getRuntime().exec(...) to execute native command line on android system like echo or ls.
I wonder if is there is any way to get data from any sensor module (like photo or gps) not from Android API (through Java or Kotlin), but by executing a command line with Runtime.getRuntime().exec(...). Is there a way to do it?
Technically all that the Android framework ( + HAL ) does is communicate via system calls with the kernel.
It would certainly be possible for you to write a binary ( C/C++) that does that communication for you, bypassing the framework.
And then you could call that binary with Runtime.getRuntime().exec(...) ( assuming rooted and have access ).
There aren't many tools to access the sensors like that ( expect maybe some vendors might have for testing). The only thing that comes to mind that you could use to get some information is by calling dumpsys in shell. This will give you lots of info about the current state of the system, and for example some location data as explaind in this answer
You can pack binary executables into your apk and launch them via Runtime.getRuntime().exec(...). Depending on the data you want to read it may be possible to implement an C/C++ program which reads /proc or /dev. If you completely statically link this executable (use i.e. musl libc) you can call it from your android app to read the data you need.

How is /dev/block/bootdevice/by-name created?

I'm switching from busybox to toybox in a customized Yocto.
After the switch I no longer have /dev/block/ populated.
I'd like to learn how /dev/block/bootdevice/by-name is populated?
Is this done by mdev?
The toybox mdev command is still in pending.
However, the /dev/block/bootdevice/by-name seems to be an Android feature which is using toybox irc.
In Android there are a couple of parts to this:
/dev/block/bootdevice is created by an init script, for example init.hardware.rc:
symlink /dev/block/platform/${ro.boot.boot_devices} /dev/block/bootdevice
In this case the ro.boot.boot_devices property is derived from the kernel command line argument set when the kernel image is built by BoardConfig-common.mk:
BOARD_KERNEL_CMDLINE += androidboot.boot_devices=soc/1d84000.ufshc
(All androidboot.* command line options are converted into ro.boot.* properties by init, see ProcessKernelCmdline()).
/dev/block/platform/* links are created by ueventd (which is part of the Android version of init). The function responsible for this is DeviceHandler::GetBlockDeviceSymlinks().
This function is also responsible for creating the /dev/block/platform/*/by-name links based on the partition names supplied by the kernel in the uevent. Not all partition schemes supply a partition name, for example GPT does while a DOS MBR partition table does not.
More recent versions of this function will also create generic links in /dev/block/by-name for partitions on the boot device. The boot device is again identified using the androidboot.boot_devices kernel command line option.

Is any way to get internal html textboxes,buttons names or ids in webview using monkeyrunner in Android

I am using monkeyrunner dump -VF option to list all ids and positions too. Now I need all ids and names of controls in webview control. Is it possible to get it using monkeyrunner or how to fetch those controls too.
First things first, if you are running (as you should) dump from AndroidViewClient >= 4.0.0 you should not use monkeyrunner as the interpreter but python.
Just:
$ ./dump -VF
on an operating system that supports shebang, or
python dump -VF
on a no-so-lucky OS.
dump dumps all the android Views and its properties, so unfortunately it's not possible now to dig inside the WebView, perhaps in the future this feature could be added, but it should rely on different techniques than the ones used to obtain the View hierarchy.

Calling Lua Script From an Android Application

Let me first of all clarify a few things:
I am not trying to run a a Lua script from a command line.
I am not trying to invoke any android functions from Lua
So with that out of the way, here is what I am trying to do.
From an Android Activity invoke directly OR indirectly (JNI/SL4A) a Lua script and get back the results in the activity.
Now looking at documentation for SL4A I see a few drawbacks:
1) I cannot find the documentation saying that it lets one programmatically call Lua.
2) It looks like SL4A might need to install as a separate application (not too seemless).
The only other option I see is to NDK cross compile all of Lua and then try to invoke it in C code in some manner.
You may want to look at my sample project AndroLua. It contains a Lua interpreter embedded directly into an Android application using the Android NDK. Only very small changes were necessary to successfully embed it into the Android application.
In order to actually use Lua from your application, LuaJava is also bundled to allow you to use Lua from Java and the other way round.
Look at the application to see an example how I override the print function to allow an output to a TextView instead of a console.
Update: loading modules
I assume the module you want to load is implemented in Lua. The standard Lua techniques for module loading work as usual - you just have to modify the package.path to your application data directory (or wherever you want to store your scripts/modules).
Imagine that you have a module called hello.lua in the application data directory:
$ adb shell
# cd /data/data/sk.kottman.androlua
# cat hello.lua
module(..., package.seeall)
function greet(name)
print('Hello ' .. name)
end
#
Then try running this code in the interpreter:
-- add the data directory to the module search path
package.path = '/data/data/sk.kottman.androlua/?.lua;'..package.path
-- load the module
require 'hello'
-- run a function, should show "Hello Lua!"
hello.greet('Lua!')

Pull a file from android emulator/device programmatically

I am familiar with adb pull command. Is it possible to pull a file from android device/emulator and saving it in specified location in PC programmatically?
In C, on linux use system() to execute adb (perhaps by its full path) with the appropriate arguments. OSX is probably something quite similar.
On windows... CreateProcess() but that returns before the child is finished, so you may have to spend some time wandering around MSDN to figure out the equivelent of system()

Categories

Resources