I'm trying to use adb to find the precise available disk space on an Android device. I'm using this in a powershell command:
$deviceInfo = adb shell df
$storageDriveArray = $deviceInfo -match 'data'
$storageDriveString = $storageDriveArray | out-string
$splitStorageDriveString = $storageDriveString -split "\s+"
$freeSpaceString = $splitStorageDriveString[3]
adb shell df
works, but doesn't give me enough precision (1.7G will be reported). df on Android doesn't seem to take parameters, so I can't use df -k or similar to get a more precise value.
Is there an alternative way to do this?
I'm quite new to powershell so please excuse any hacky stuff!
Related
I'm new with Android developpemnent but I want to write a SPI driver to connect a SPI IC and then an Android application to send and receive data from and to the IC.
From there, I don't really know where to create the driver (and what it should contain) and how to link an application in top of that. I have a customisable Android kernel (9.0 Pie, APQ8096_LA.UM.7.5.r1-03100-8x96.0_P_v5.0) with all its .dts, .dtsi, .c, and so on. I also got an eval board and the adequate documentation for the mapping.
I googled for a week and didn't found what I was looking for. I learned a bit about the device tree system. Since I have a Snapdragon 820 msm8996, I modified "msm8996-blsp.dtsi" and "msm8996-pinctrl.dtsi".
I had this bit of code:
msm8996-pinctrl.dtsi
&soc {
...
spi_0 {
spi_0_active: spi_0_active {
spi_0 {
pins = "gpio0", "gpio1", "gpio2", "gpio3";
function = "blsp_spi1";
drive-strength = <6>;
bias-disable;
};
};
spi_0_sleep: spi_0_sleep {
spi_0 {
pins = "gpio0", "gpio1", "gpio2", "gpio3";
function = "blsp_spi1";
drive-strength = <6>;
bias-disable;
};
};
};
...
msm8996-blsp.dtsi
&soc {
...
spi_0: spi#7575000 { //QUP Base address for BLSP1_QUP0
compatible = "qcom,spi-qup-v2"; //Manufacturer and Model
#address-cells = <1>;
#size-cells = <0>;
reg-names = "spi_physical", "spi_bam_physical";
reg = <0x07575000 0x600>,
<0x07544000 0x2b000>;
interrupt-names = "spi_irq", "spi_bam_irq";
interrupts = <0 95 0>, <0 238 0>;
spi-max-frequency = <5000000>; //Maximum supported frequency in HZ
qcom,infinite-mode = <0>;
qcom,use-bam; // Enable BAM mode
/* Add BAM pipes */
qcom,bam-consumer-pipe-index = <12>;
qcom,bam-producer-pipe-index = <13>;
qcom,ver-reg-exists;
qcom,master-id = <86>;
qcom,use-pinctrl;
pinctrl-names = "spi_default", "spi_sleep";
pinctrl-0 = <&spi_0_active>;
pinctrl-1 = <&spi_0_sleep>;
clock-names = "iface_clk", "core_clk";
clocks = <&clock_gcc clk_gcc_blsp1_ahb_clk>,
<&clock_gcc clk_gcc_blsp1_qup1_spi_apps_clk>;
status = "enabled";
}
...
I build this kernel with
$ ./build.sh msm8996 -j $(nproc)
I flashed my eval board with fastboot and then I went in adb.
$ adb root
$ adb wait-for-device
$ adb shell
# cd /sys/class/spi_master
# ls
// Nothing here
Considering my spi adress is defined at #7575000, I expected the output to be
# spi_0
Is my code correct to enable it (I'm not good with device tree yet)? If so, why isn't visible with adb and how should I make it visible? What should be the next steps to access this SPI with an Android application?
I searched stackoverflow and so many places, but writing device drivers for Android doesn't seem to be common...
There is no need for you to write a SPI driver for snapdragon it is already in the kernel. Maybe you need to write something to connect it to your device.
The easiest way to expose a spi controller to userspace is by mapping spidev to your device
There must be support for this in your kernel (which is added with the CONFIG_SPI_SPIDEV=y config flag) and in the device tree under the bus
Something like this:
&spi_0 {
spidev#1 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "linux, spidev";
spi-max-frequency = <20000000>;
reg = <1>;
};
};
The device tree is compiled together with the kernel and contains among other things your gpio mappings and DMA configurations so the same kernel can serve multiple boards. Make sure android is using your newly compiled kernel and device tree, sometimes it accidentally builds with one of the prebuilt kernels.
After those steps you should have a /dev/spidev0.0 (or some other number) in /dev
With ioctl complex operations can be used.
To verify if your software have full connection to your SPI bus connect a wire from MOSI to MISO the SPI writeread command will echo the same data it receives - remove the wire and verify there is nothing.
At this point should you start communicate with your sensor, and develop its control software.
In above case I would have started to check the log prints from kernel booting to verify it identifies the hardware correctly and the driver is loaded.
I have a Huawei U8950 phone and use it for Android Development. The problem is that the guys at Huawei has left their debug logs on and my logcat output is always flooded with hundreds of log messages like this:
E/OpenGLRenderer(10525): HUAWEI_DEBUG: glyph's Height = 21, Width = 13, current total allocated size out of MAX(1024) = 17
E/OpenGLRenderer(10525): HUAWEI_DEBUG: glyph's Height = 21, Width = 15, current total allocated size out of MAX(1024) = 16
E/OpenGLRenderer(10525): HUAWEI_DEBUG: glyph's Height = 21, Width = 15, current total allocated size out of MAX(1024) = 32
E/OpenGLRenderer(10525): HUAWEI_DEBUG: glyph's Height = 16, Width = 13, current total allocated size out of MAX(1024) = 16
...
These message are so so many (hundreds or even thousands) and make Eclipse hang (I think because of parsing and coloring) that I don't use it anymore and use adb logcat manually. However in there too I have to deal with them and see and scroll them.
Is there any way to disable them? (Software solutions for filtering them is not good, because the overhead of transferring and processing still remains)
If you install busybox you could do
logcat | busybox grep -v HUAWEI_DEBUG
in adb shell or ssh. Some builds have busybox ,but you will probably need to install it. Thankfully there are tons of apps that drag it along - most terminals do.
I tried to use setprop libc.debug.malloc = 1 to find out leak.
I made an demo program and introduced memory leak in that but the above flag is not able to detect this leak.
I tried below commands:
adb shell setprop libc.debug.malloc 1
adb shell stop
adb shell start
jstring Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env,
jobject thiz) {
int *p = malloc(sizeof(int));
p[1] = 100;
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
Any help would be appreciated.
Thanks
libc.debug.malloc is not valgrind. It tracks native heap allocations, but doesn't really detect leaks directly. It works best in conjuction with DDMS; see this answer for information about using it for native leak chasing (and maybe this older answer).
(Note you can use valgrind on recent versions of Android, but getting it set up can be an adventure.)
FWIW, different levels of libc.debug.malloc are reasonably good at finding use-after-free and buffer overruns:
/* 1 - For memory leak detections.
* 5 - For filling allocated / freed memory with patterns defined by
* CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
* 10 - For adding pre-, and post- allocation stubs in order to detect
* buffer overruns.
For example, if you set libc.debug.malloc = 10 and add a free() call to your example above, you'll likely get a warning message from the library because you set p[1] rather than p[0].
I can read the content of /dev/logo in C,
fd = open("/dev/logo", O_RDONLY);
len = read(fd, logo_addr, 512);
Now I want to do these things using shell command, how to do?
Can I use
$ adb shell cat dev/logo >logo.dev
?
Are you able to use dd? Something like:
dd /dev/logo bs=1 count=512 of=logo.dev
Assuming you need to read 512 bytes of the device.
I found some info on the web:
echo 1 /sys/devices/platform/flashlight.0/leds/flashlight/brightness
But on my Nexus 7 (flashed an AOSP), I couldn't find that directory.
Any idea about which file should I write to? Is this doable?
After ls /sys/devices/platform, I got:
LID
alarm
arm-pmu.0
bcm4330_rfkill
bcmdhd_wlan.1
bluesleep
fiq_debugger.0
fsl-tegra-udc
gpio-keys.0
grouper_misc
leds-gpio
oprofile-perf.0
power
power.0
pwm-backlight
ram_console
reg-dummy
reg-fixed-voltage.1
reg-fixed-voltage.10
reg-fixed-voltage.11
reg-fixed-voltage.2
reg-fixed-voltage.3
reg-fixed-voltage.4
reg-fixed-voltage.6
reg-fixed-voltage.8
regulatory.0
sdhci-tegra.2
sdhci-tegra.3
serial8250
snd-soc-dummy
spdif-dit.0
spdif-dit.1
spi_tegra.0
spi_tegra.3
tegra-ehci.1
tegra-i2c.0
tegra-i2c.1
tegra-i2c.2
tegra-i2c.3
tegra-i2c.4
tegra-nvmap
tegra-otg
tegra-pcm-audio
tegra-se
tegra-snd-rt5640.0
tegra30-ahub
tegra30-dam.0
tegra30-dam.1
tegra30-dam.2
tegra30-hda
tegra30-i2s.1
tegra30-i2s.3
tegra30-i2s.4
tegra30-spdif
tegra_camera
tegra_pwm.0
tegra_rtc
tegra_smmu
tegra_uart.1
tegra_uart.2
tegra_uart.3
tegra_uart.4
tegra_wdt
uevent
There is a new binary shipping with Android Jellybean 4.2, which can be used to directly read/write to the system settings provider, accessible via command line.
For example: in order to increase brightness of the screen, use below command:
adb shell settings put system screen_brightness 200
Read more about SCREEN_BRIGHTNESS Note that the range of values is [0 - 255]
The range of values is not necessarily from 0 - 255. On my OnePlus for example
it ranges from 0-2047. If you want to know yours just set the brightness slider to max and
then type: adb shell settings get system screen_brightness.
You should use the pwm-backlight!
You can use this adb command to set screen brightness
adb shell settings put system screen_brightness 255
and if your device has auto brightness setting then use this command first
adb shell settings put system screen_brightness_mode 0
This did not work for the latest Nexus 7 (2013) for me. But this answer explains the way to find what you are looking for on any version: https://stackoverflow.com/a/13492336
However we need to note that in order to change any of this you need to have root access.